summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp1
-rw-r--r--korganizer/journalentry.cpp61
-rw-r--r--korganizer/journalentry.h5
-rw-r--r--korganizer/kojournalview.cpp110
-rw-r--r--korganizer/kojournalview.h10
-rw-r--r--korganizer/koviewmanager.cpp7
-rw-r--r--korganizer/koviewmanager.h1
-rw-r--r--libkcal/calendar.h1
-rw-r--r--libkcal/calendarlocal.cpp14
-rw-r--r--libkcal/calendarlocal.h1
10 files changed, 173 insertions, 38 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index a62145a..697093e 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,3537 +1,3538 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Requires the Qt and KDE widget libraries, available at no cost at 4 Requires the Qt and KDE widget libraries, available at no cost at
5 http://www.troll.no and http://www.kde.org respectively 5 http://www.troll.no and http://www.kde.org respectively
6 6
7 Copyright (c) 1997, 1998, 1999 7 Copyright (c) 1997, 1998, 1999
8 Preston Brown (preton.brown@yale.edu) 8 Preston Brown (preton.brown@yale.edu)
9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl) 9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl)
10 Ian Dawes (iadawes@globalserve.net) 10 Ian Dawes (iadawes@globalserve.net)
11 Laszlo Boloni (boloni@cs.purdue.edu) 11 Laszlo Boloni (boloni@cs.purdue.edu)
12 12
13 Copyright (c) 2000, 2001, 2002 13 Copyright (c) 2000, 2001, 2002
14 Cornelius Schumacher <schumacher@kde.org> 14 Cornelius Schumacher <schumacher@kde.org>
15 15
16 This program is free software; you can redistribute it and/or modify 16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by 17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or 18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version. 19 (at your option) any later version.
20 20
21 This program is distributed in the hope that it will be useful, 21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
24 GNU General Public License for more details. 24 GNU General Public License for more details.
25 25
26 You should have received a copy of the GNU General Public License 26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software 27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#include <stdlib.h> 31#include <stdlib.h>
32 32
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qradiobutton.h> 34#include <qradiobutton.h>
35#include <qbuttongroup.h> 35#include <qbuttongroup.h>
36#include <qlayout.h> 36#include <qlayout.h>
37#include <qclipboard.h> 37#include <qclipboard.h>
38#include <qcursor.h> 38#include <qcursor.h>
39#include <qmessagebox.h> 39#include <qmessagebox.h>
40#include <qprogressbar.h> 40#include <qprogressbar.h>
41#include <qmultilineedit.h> 41#include <qmultilineedit.h>
42#include <qtimer.h> 42#include <qtimer.h>
43#include <qwidgetstack.h> 43#include <qwidgetstack.h>
44#include <qptrlist.h> 44#include <qptrlist.h>
45#include <qregexp.h> 45#include <qregexp.h>
46#include <qgroupbox.h> 46#include <qgroupbox.h>
47#include <qfile.h> 47#include <qfile.h>
48#include <qdir.h> 48#include <qdir.h>
49#ifndef KORG_NOSPLITTER 49#ifndef KORG_NOSPLITTER
50#include <qsplitter.h> 50#include <qsplitter.h>
51#endif 51#endif
52 52
53#include <kglobal.h> 53#include <kglobal.h>
54#include <kdebug.h> 54#include <kdebug.h>
55#include <kstandarddirs.h> 55#include <kstandarddirs.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57#include <kmessagebox.h> 57#include <kmessagebox.h>
58#include <knotifyclient.h> 58#include <knotifyclient.h>
59#include <kconfig.h> 59#include <kconfig.h>
60 60
61#include <libkdepim/ksyncprefsdialog.h> 61#include <libkdepim/ksyncprefsdialog.h>
62#include <krun.h> 62#include <krun.h>
63#include <kdirwatch.h> 63#include <kdirwatch.h>
64#include <libkdepim/kdatepicker.h> 64#include <libkdepim/kdatepicker.h>
65#include <libkdepim/ksyncprofile.h> 65#include <libkdepim/ksyncprofile.h>
66#include <libkdepim/kpimglobalprefs.h> 66#include <libkdepim/kpimglobalprefs.h>
67 67
68#include <libkcal/vcaldrag.h> 68#include <libkcal/vcaldrag.h>
69#include <libkcal/icaldrag.h> 69#include <libkcal/icaldrag.h>
70#include <libkcal/icalformat.h> 70#include <libkcal/icalformat.h>
71#include <libkcal/vcalformat.h> 71#include <libkcal/vcalformat.h>
72#include <libkcal/scheduler.h> 72#include <libkcal/scheduler.h>
73#include <libkcal/calendarlocal.h> 73#include <libkcal/calendarlocal.h>
74#include <libkcal/journal.h> 74#include <libkcal/journal.h>
75#include <libkcal/calfilter.h> 75#include <libkcal/calfilter.h>
76#include <libkcal/attendee.h> 76#include <libkcal/attendee.h>
77#include <libkcal/dndfactory.h> 77#include <libkcal/dndfactory.h>
78#include <libkcal/freebusy.h> 78#include <libkcal/freebusy.h>
79#include <libkcal/filestorage.h> 79#include <libkcal/filestorage.h>
80#include <libkcal/calendarresources.h> 80#include <libkcal/calendarresources.h>
81#include <libkcal/qtopiaformat.h> 81#include <libkcal/qtopiaformat.h>
82#include "../kalarmd/alarmdialog.h" 82#include "../kalarmd/alarmdialog.h"
83 83
84#ifndef DESKTOP_VERSION 84#ifndef DESKTOP_VERSION
85#include <libkcal/sharpformat.h> 85#include <libkcal/sharpformat.h>
86#include <externalapphandler.h> 86#include <externalapphandler.h>
87#endif 87#endif
88#include <libkcal/phoneformat.h> 88#include <libkcal/phoneformat.h>
89#ifndef KORG_NOMAIL 89#ifndef KORG_NOMAIL
90#include "komailclient.h" 90#include "komailclient.h"
91#endif 91#endif
92#ifndef KORG_NOPRINTER 92#ifndef KORG_NOPRINTER
93#include "calprinter.h" 93#include "calprinter.h"
94#endif 94#endif
95#ifndef KORG_NOPLUGINS 95#ifndef KORG_NOPLUGINS
96#include "kocore.h" 96#include "kocore.h"
97#endif 97#endif
98#include "koeventeditor.h" 98#include "koeventeditor.h"
99#include "kotodoeditor.h" 99#include "kotodoeditor.h"
100#include "koprefs.h" 100#include "koprefs.h"
101#include "koeventviewerdialog.h" 101#include "koeventviewerdialog.h"
102#include "publishdialog.h" 102#include "publishdialog.h"
103#include "kofilterview.h" 103#include "kofilterview.h"
104#include "koglobals.h" 104#include "koglobals.h"
105#include "koviewmanager.h" 105#include "koviewmanager.h"
106#include "koagendaview.h" 106#include "koagendaview.h"
107#include "kodialogmanager.h" 107#include "kodialogmanager.h"
108#include "outgoingdialog.h" 108#include "outgoingdialog.h"
109#include "incomingdialog.h" 109#include "incomingdialog.h"
110#include "datenavigatorcontainer.h" 110#include "datenavigatorcontainer.h"
111#include "statusdialog.h" 111#include "statusdialog.h"
112#include "kdatenavigator.h" 112#include "kdatenavigator.h"
113#include "kotodoview.h" 113#include "kotodoview.h"
114#include "datenavigator.h" 114#include "datenavigator.h"
115#include "resourceview.h" 115#include "resourceview.h"
116#include "navigatorbar.h" 116#include "navigatorbar.h"
117#include "searchdialog.h" 117#include "searchdialog.h"
118#include "mainwindow.h" 118#include "mainwindow.h"
119 119
120#include "calendarview.h" 120#include "calendarview.h"
121#ifndef DESKTOP_VERSION 121#ifndef DESKTOP_VERSION
122#include <qtopia/alarmserver.h> 122#include <qtopia/alarmserver.h>
123#endif 123#endif
124#ifndef _WIN32_ 124#ifndef _WIN32_
125#include <stdlib.h> 125#include <stdlib.h>
126#include <stdio.h> 126#include <stdio.h>
127#include <unistd.h> 127#include <unistd.h>
128#else 128#else
129#include <qprocess.h> 129#include <qprocess.h>
130#endif 130#endif
131 131
132#ifdef DESKTOP_VERSION 132#ifdef DESKTOP_VERSION
133#include <kabc/stdaddressbook.h> 133#include <kabc/stdaddressbook.h>
134#endif 134#endif
135using namespace KOrg; 135using namespace KOrg;
136using namespace KCal; 136using namespace KCal;
137extern int globalFlagBlockAgenda; 137extern int globalFlagBlockAgenda;
138extern int globalFlagBlockStartup; 138extern int globalFlagBlockStartup;
139 139
140 140
141MissedAlarmTextBrowser::MissedAlarmTextBrowser(QWidget *parent, QPtrList<Incidence> alarms,QDateTime start ) : QTextBrowser(parent) 141MissedAlarmTextBrowser::MissedAlarmTextBrowser(QWidget *parent, QPtrList<Incidence> alarms,QDateTime start ) : QTextBrowser(parent)
142 142
143{ 143{
144 mAlarms = alarms; 144 mAlarms = alarms;
145 viewport()->setBackgroundColor( QColor( 255, 255, 255 ) ); 145 viewport()->setBackgroundColor( QColor( 255, 255, 255 ) );
146 QString mText = "<table width=\"100%\">\n"; 146 QString mText = "<table width=\"100%\">\n";
147 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>"; 147 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>";
148#ifdef DESKTOP_VERSION 148#ifdef DESKTOP_VERSION
149 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h2>"; 149 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h2>";
150#else 150#else
151 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h3>"; 151 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h3>";
152#endif 152#endif
153 // mText += "<img src=\""; 153 // mText += "<img src=\"";
154 // mText += ipath; 154 // mText += ipath;
155 // mText += "\">"; 155 // mText += "\">";
156 //mEventDate = QDate::currentDate(); 156 //mEventDate = QDate::currentDate();
157#ifdef DESKTOP_VERSION 157#ifdef DESKTOP_VERSION
158 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h2>"; 158 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h2>";
159#else 159#else
160 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h3>"; 160 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h3>";
161#endif 161#endif
162 //mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>"; 162 //mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>";
163 163
164 Incidence * inc = getNextInc( start ); 164 Incidence * inc = getNextInc( start );
165 int time = 0; 165 int time = 0;
166 //mText += "<table>"; 166 //mText += "<table>";
167 while ( inc ) { 167 while ( inc ) {
168 QDateTime dt ; 168 QDateTime dt ;
169 QString tempText = "<a "; 169 QString tempText = "<a ";
170 bool ok; 170 bool ok;
171 dt = inc->getNextOccurence( start, &ok ); 171 dt = inc->getNextOccurence( start, &ok );
172 if ( !ok ) continue; 172 if ( !ok ) continue;
173 if ( inc->typeID() == eventID ) { 173 if ( inc->typeID() == eventID ) {
174 tempText += "href=\"event:"; 174 tempText += "href=\"event:";
175 } else if ( inc->typeID() == todoID ) { 175 } else if ( inc->typeID() == todoID ) {
176 tempText += "href=\"todo:"; 176 tempText += "href=\"todo:";
177 } 177 }
178 tempText += inc->uid() + "\">"; 178 tempText += inc->uid() + "\">";
179 if ( inc->typeID() == todoID ) 179 if ( inc->typeID() == todoID )
180 tempText += i18n("Todo: "); 180 tempText += i18n("Todo: ");
181 if ( inc->summary().length() > 0 ) 181 if ( inc->summary().length() > 0 )
182 tempText += inc->summary(); 182 tempText += inc->summary();
183 else 183 else
184 tempText += i18n("-no summary-"); 184 tempText += i18n("-no summary-");
185 QString timestr; 185 QString timestr;
186 if (!inc->doesFloat()) 186 if (!inc->doesFloat())
187 timestr = KGlobal::locale()->formatDateTime( dt, KOPrefs::instance()->mShortDateInViewer) +": "; 187 timestr = KGlobal::locale()->formatDateTime( dt, KOPrefs::instance()->mShortDateInViewer) +": ";
188 else 188 else
189 timestr = KGlobal::locale()->formatDate( dt.date() , KOPrefs::instance()->mShortDateInViewer) +": "; 189 timestr = KGlobal::locale()->formatDate( dt.date() , KOPrefs::instance()->mShortDateInViewer) +": ";
190 if ( dt.date() < QDate::currentDate() && time == 0 ) { 190 if ( dt.date() < QDate::currentDate() && time == 0 ) {
191 mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>"; 191 mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>";
192 mText += "<table>"; 192 mText += "<table>";
193 time = 1; 193 time = 1;
194 } 194 }
195 if ( dt.date() == QDate::currentDate() && time <= 1 ) { 195 if ( dt.date() == QDate::currentDate() && time <= 1 ) {
196 if ( time > 0 ) 196 if ( time > 0 )
197 mText +="</table>"; 197 mText +="</table>";
198 mText += "</td></tr>\n<tr bgcolor=\"#FFDC64\"><td>"; 198 mText += "</td></tr>\n<tr bgcolor=\"#FFDC64\"><td>";
199 mText += "<table>"; 199 mText += "<table>";
200 time = 2; 200 time = 2;
201 201
202 } 202 }
203 if ( dt.date() > QDate::currentDate() && time <= 2 ) { 203 if ( dt.date() > QDate::currentDate() && time <= 2 ) {
204 if ( time > 0 ) 204 if ( time > 0 )
205 mText +="</table>"; 205 mText +="</table>";
206 mText += "</td></tr>\n<tr bgcolor=\"#6AFF6A\"><td>"; 206 mText += "</td></tr>\n<tr bgcolor=\"#6AFF6A\"><td>";
207 mText += "<table>"; 207 mText += "<table>";
208 time = 3; 208 time = 3;
209 } 209 }
210 mText +="<tr><td><b>"; 210 mText +="<tr><td><b>";
211 mText += timestr; 211 mText += timestr;
212 mText += "</b></td><td>"; 212 mText += "</b></td><td>";
213 mText += tempText; 213 mText += tempText;
214 mText += "</td></tr>\n"; 214 mText += "</td></tr>\n";
215 inc = getNextInc( start ); 215 inc = getNextInc( start );
216 } 216 }
217 mText +="</table>"; 217 mText +="</table>";
218 setText( mText ); 218 setText( mText );
219} 219}
220 220
221MissedAlarmTextBrowser::~MissedAlarmTextBrowser() 221MissedAlarmTextBrowser::~MissedAlarmTextBrowser()
222{ 222{
223 //qDebug("delete MissedAlarmTextBrowser::~MissedAlarmTextBrowser() "); 223 //qDebug("delete MissedAlarmTextBrowser::~MissedAlarmTextBrowser() ");
224} 224}
225Incidence * MissedAlarmTextBrowser::getNextInc( QDateTime start ) 225Incidence * MissedAlarmTextBrowser::getNextInc( QDateTime start )
226{ 226{
227 QDateTime dt ; 227 QDateTime dt ;
228 Incidence * retInc; 228 Incidence * retInc;
229 Incidence * inc = mAlarms.first(); 229 Incidence * inc = mAlarms.first();
230 if ( inc == 0 ) 230 if ( inc == 0 )
231 return 0; 231 return 0;
232 bool ok; 232 bool ok;
233 dt = inc->getNextOccurence( start, &ok ); 233 dt = inc->getNextOccurence( start, &ok );
234 if ( ! ok ) return 0; 234 if ( ! ok ) return 0;
235 QDateTime dtn ; 235 QDateTime dtn ;
236 retInc = inc; 236 retInc = inc;
237 inc = mAlarms.next(); 237 inc = mAlarms.next();
238 while ( inc ) { 238 while ( inc ) {
239 dtn = inc->getNextOccurence( start, &ok ); 239 dtn = inc->getNextOccurence( start, &ok );
240 if ( ! ok ) return 0; 240 if ( ! ok ) return 0;
241 if ( dtn < dt ) { 241 if ( dtn < dt ) {
242 dt = dtn; 242 dt = dtn;
243 retInc = inc; 243 retInc = inc;
244 } 244 }
245 inc = mAlarms.next(); 245 inc = mAlarms.next();
246 } 246 }
247 mAlarms.remove( retInc ); 247 mAlarms.remove( retInc );
248 return retInc; 248 return retInc;
249 249
250} 250}
251void MissedAlarmTextBrowser::setSource(const QString & n) 251void MissedAlarmTextBrowser::setSource(const QString & n)
252{ 252{
253 if (n.startsWith("event:")) { 253 if (n.startsWith("event:")) {
254#ifdef DESKTOP_VERSION 254#ifdef DESKTOP_VERSION
255 emit showIncidence(n.mid(8)); 255 emit showIncidence(n.mid(8));
256#else 256#else
257 emit showIncidence(n.mid(6)); 257 emit showIncidence(n.mid(6));
258#endif 258#endif
259 return; 259 return;
260 } else if (n.startsWith("todo:")) { 260 } else if (n.startsWith("todo:")) {
261#ifdef DESKTOP_VERSION 261#ifdef DESKTOP_VERSION
262 emit showIncidence(n.mid(7)); 262 emit showIncidence(n.mid(7));
263#else 263#else
264 emit showIncidence(n.mid(5)); 264 emit showIncidence(n.mid(5));
265#endif 265#endif
266 return; 266 return;
267 } 267 }
268} 268}
269 269
270 270
271class KOBeamPrefs : public QDialog 271class KOBeamPrefs : public QDialog
272{ 272{
273 public: 273 public:
274 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : 274 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) :
275 QDialog( parent, name, true ) 275 QDialog( parent, name, true )
276 { 276 {
277 setCaption( i18n("Beam Options") ); 277 setCaption( i18n("Beam Options") );
278 QVBoxLayout* lay = new QVBoxLayout( this ); 278 QVBoxLayout* lay = new QVBoxLayout( this );
279 lay->setSpacing( 3 ); 279 lay->setSpacing( 3 );
280 lay->setMargin( 3 ); 280 lay->setMargin( 3 );
281 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); 281 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this );
282 lay->addWidget( format ); 282 lay->addWidget( format );
283 format->setExclusive ( true ) ; 283 format->setExclusive ( true ) ;
284 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); 284 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this );
285 lay->addWidget( time ); time->setExclusive ( true ) ; 285 lay->addWidget( time ); time->setExclusive ( true ) ;
286 vcal = new QRadioButton(" vCalendar ", format ); 286 vcal = new QRadioButton(" vCalendar ", format );
287 ical = new QRadioButton(" iCalendar ", format ); 287 ical = new QRadioButton(" iCalendar ", format );
288 vcal->setChecked( true ); 288 vcal->setChecked( true );
289 tz = new QRadioButton(i18n(" With timezone "), time ); 289 tz = new QRadioButton(i18n(" With timezone "), time );
290 local = new QRadioButton(i18n(" Local time "), time ); 290 local = new QRadioButton(i18n(" Local time "), time );
291 tz->setChecked( true ); 291 tz->setChecked( true );
292 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); 292 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this );
293 lay->addWidget( ok ); 293 lay->addWidget( ok );
294 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 294 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
295 lay->addWidget( cancel ); 295 lay->addWidget( cancel );
296 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 296 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
297 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 297 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
298 resize( 200, 200 ); 298 resize( 200, 200 );
299 } 299 }
300 300
301 bool beamVcal() { return vcal->isChecked(); } 301 bool beamVcal() { return vcal->isChecked(); }
302 bool beamLocal() { return local->isChecked(); } 302 bool beamLocal() { return local->isChecked(); }
303private: 303private:
304 QRadioButton* vcal, *ical, *local, *tz; 304 QRadioButton* vcal, *ical, *local, *tz;
305}; 305};
306class KOCatPrefs : public QDialog 306class KOCatPrefs : public QDialog
307{ 307{
308 public: 308 public:
309 KOCatPrefs( QWidget *parent=0, const char *name=0 ) : 309 KOCatPrefs( QWidget *parent=0, const char *name=0 ) :
310 QDialog( parent, name, true ) 310 QDialog( parent, name, true )
311 { 311 {
312 setCaption( i18n("Manage new Categories") ); 312 setCaption( i18n("Manage new Categories") );
313 QVBoxLayout* lay = new QVBoxLayout( this ); 313 QVBoxLayout* lay = new QVBoxLayout( this );
314 lay->setSpacing( 3 ); 314 lay->setSpacing( 3 );
315 lay->setMargin( 3 ); 315 lay->setMargin( 3 );
316 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this ); 316 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this );
317 lay->addWidget( lab ); 317 lay->addWidget( lab );
318 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); 318 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this );
319 lay->addWidget( format ); 319 lay->addWidget( format );
320 format->setExclusive ( true ) ; 320 format->setExclusive ( true ) ;
321 addCatBut = new QRadioButton(i18n("Add to category list"), format ); 321 addCatBut = new QRadioButton(i18n("Add to category list"), format );
322 new QRadioButton(i18n("Remove from Events/Todos"), format ); 322 new QRadioButton(i18n("Remove from Events/Todos"), format );
323 addCatBut->setChecked( true ); 323 addCatBut->setChecked( true );
324 QPushButton * ok = new QPushButton( i18n("OK"), this ); 324 QPushButton * ok = new QPushButton( i18n("OK"), this );
325 lay->addWidget( ok ); 325 lay->addWidget( ok );
326 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 326 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
327 lay->addWidget( cancel ); 327 lay->addWidget( cancel );
328 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 328 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
329 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 329 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
330 resize( 200, 200 ); 330 resize( 200, 200 );
331 } 331 }
332 332
333 bool addCat() { return addCatBut->isChecked(); } 333 bool addCat() { return addCatBut->isChecked(); }
334private: 334private:
335 QRadioButton* addCatBut; 335 QRadioButton* addCatBut;
336}; 336};
337 337
338 338
339 339
340CalendarView::CalendarView( CalendarResources *calendar, 340CalendarView::CalendarView( CalendarResources *calendar,
341 QWidget *parent, const char *name ) 341 QWidget *parent, const char *name )
342 : CalendarViewBase( parent, name ), 342 : CalendarViewBase( parent, name ),
343 mCalendar( calendar ), 343 mCalendar( calendar ),
344 mResourceManager( calendar->resourceManager() ) 344 mResourceManager( calendar->resourceManager() )
345{ 345{
346 346
347 mEventEditor = 0; 347 mEventEditor = 0;
348 mTodoEditor = 0; 348 mTodoEditor = 0;
349 349
350 init(); 350 init();
351} 351}
352 352
353CalendarView::CalendarView( Calendar *calendar, 353CalendarView::CalendarView( Calendar *calendar,
354 QWidget *parent, const char *name ) 354 QWidget *parent, const char *name )
355 : CalendarViewBase( parent, name ), 355 : CalendarViewBase( parent, name ),
356 mCalendar( calendar ), 356 mCalendar( calendar ),
357 mResourceManager( 0 ) 357 mResourceManager( 0 )
358{ 358{
359 359
360 mEventEditor = 0; 360 mEventEditor = 0;
361 mTodoEditor = 0; 361 mTodoEditor = 0;
362 init(); 362 init();
363} 363}
364 364
365void CalendarView::init() 365void CalendarView::init()
366{ 366{
367 mNextAlarmDateTime = QDateTime::currentDateTime(); 367 mNextAlarmDateTime = QDateTime::currentDateTime();
368 setFocusPolicy ( NoFocus ); 368 setFocusPolicy ( NoFocus );
369 mViewerCallerIsSearchDialog = false; 369 mViewerCallerIsSearchDialog = false;
370 mBlockShowDates = false; 370 mBlockShowDates = false;
371 beamDialog = new KOBeamPrefs(); 371 beamDialog = new KOBeamPrefs();
372 mDatePickerMode = 0; 372 mDatePickerMode = 0;
373 mCurrentSyncDevice = ""; 373 mCurrentSyncDevice = "";
374 writeLocale(); 374 writeLocale();
375 mViewManager = new KOViewManager( this ); 375 mViewManager = new KOViewManager( this );
376 mDialogManager = new KODialogManager( this ); 376 mDialogManager = new KODialogManager( this );
377 mEventViewerDialog = 0; 377 mEventViewerDialog = 0;
378 mModified = false; 378 mModified = false;
379 mReadOnly = false; 379 mReadOnly = false;
380 mSelectedIncidence = 0; 380 mSelectedIncidence = 0;
381 mCalPrinter = 0; 381 mCalPrinter = 0;
382 mFilters.setAutoDelete(true); 382 mFilters.setAutoDelete(true);
383 383
384 mCalendar->registerObserver( this ); 384 mCalendar->registerObserver( this );
385 // TODO: Make sure that view is updated, when calendar is changed. 385 // TODO: Make sure that view is updated, when calendar is changed.
386 386
387 mStorage = new FileStorage( mCalendar ); 387 mStorage = new FileStorage( mCalendar );
388 mNavigator = new DateNavigator( this, "datevav", mViewManager ); 388 mNavigator = new DateNavigator( this, "datevav", mViewManager );
389 389
390 QBoxLayout *topLayout = (QBoxLayout*)layout(); 390 QBoxLayout *topLayout = (QBoxLayout*)layout();
391#ifndef KORG_NOSPLITTER 391#ifndef KORG_NOSPLITTER
392 // create the main layout frames. 392 // create the main layout frames.
393 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); 393 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner");
394 topLayout->addWidget(mPanner); 394 topLayout->addWidget(mPanner);
395 395
396 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, 396 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner,
397 "CalendarView::LeftFrame"); 397 "CalendarView::LeftFrame");
398 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); 398 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize);
399 399
400 mDateNavigator = new DateNavigatorContainer( mLeftSplitter, 400 mDateNavigator = new DateNavigatorContainer( mLeftSplitter,
401 "CalendarView::DateNavigator" ); 401 "CalendarView::DateNavigator" );
402 402
403 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); 403 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize);
404 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); 404 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2");
405 mTodoList->setNavigator( mNavigator ); 405 mTodoList->setNavigator( mNavigator );
406 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); 406 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView");
407 407
408#ifdef KORG_NORESOURCEVIEW 408#ifdef KORG_NORESOURCEVIEW
409 mResourceView = 0; 409 mResourceView = 0;
410#else 410#else
411 if ( mResourceManager ) { 411 if ( mResourceManager ) {
412 mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); 412 mResourceView = new ResourceView( mResourceManager, mLeftSplitter );
413 mResourceView->updateView(); 413 mResourceView->updateView();
414 connect( mResourceView, SIGNAL( resourcesChanged() ), 414 connect( mResourceView, SIGNAL( resourcesChanged() ),
415 SLOT( updateView() ) ); 415 SLOT( updateView() ) );
416 } else { 416 } else {
417 mResourceView = 0; 417 mResourceView = 0;
418 } 418 }
419#endif 419#endif
420 QWidget *rightBox = new QWidget( mPanner ); 420 QWidget *rightBox = new QWidget( mPanner );
421 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 421 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
422 422
423 mRightFrame = new QWidgetStack( rightBox ); 423 mRightFrame = new QWidgetStack( rightBox );
424 rightLayout->addWidget( mRightFrame, 1 ); 424 rightLayout->addWidget( mRightFrame, 1 );
425 425
426 mLeftFrame = mLeftSplitter; 426 mLeftFrame = mLeftSplitter;
427#else 427#else
428 //QWidget *mainBox = new QWidget( this ); 428 //QWidget *mainBox = new QWidget( this );
429 //QWidget *leftFrame = new QWidget( mainBox ); 429 //QWidget *leftFrame = new QWidget( mainBox );
430 //QBoxLayout * mainBoxLayout; 430 //QBoxLayout * mainBoxLayout;
431 if ( KOPrefs::instance()->mVerticalScreen ) { 431 if ( KOPrefs::instance()->mVerticalScreen ) {
432 //mainBoxLayout = new QVBoxLayout(mainBox); 432 //mainBoxLayout = new QVBoxLayout(mainBox);
433 //leftFrameLayout = new QHBoxLayout(leftFrame ); 433 //leftFrameLayout = new QHBoxLayout(leftFrame );
434 mMainFrame = new KDGanttMinimizeSplitter( Qt::Vertical, this ); 434 mMainFrame = new KDGanttMinimizeSplitter( Qt::Vertical, this );
435 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 435 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
436 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, mMainFrame);; 436 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, mMainFrame);;
437 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 437 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
438 } else { 438 } else {
439 //mainBoxLayout = new QHBoxLayout(mainBox); 439 //mainBoxLayout = new QHBoxLayout(mainBox);
440 //leftFrameLayout = new QVBoxLayout(leftFrame ); 440 //leftFrameLayout = new QVBoxLayout(leftFrame );
441 mMainFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 441 mMainFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
442 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Left); 442 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Left);
443 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Vertical, mMainFrame); 443 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Vertical, mMainFrame);
444 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 444 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
445 } 445 }
446 mMainFrame->setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) ); 446 mMainFrame->setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) );
447 //QBoxLayout * leftFrameLayout; 447 //QBoxLayout * leftFrameLayout;
448 topLayout->addWidget( mMainFrame ); 448 topLayout->addWidget( mMainFrame );
449 //mainBoxLayout->addWidget (mLeftFrame); 449 //mainBoxLayout->addWidget (mLeftFrame);
450 mDateNavigator = new DateNavigatorContainer( mLeftFrame, 450 mDateNavigator = new DateNavigatorContainer( mLeftFrame,
451 "CalendarView::DateNavigator" ); 451 "CalendarView::DateNavigator" );
452#if 0 452#if 0
453 // FIXME 453 // FIXME
454 mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE, 454 mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE,
455 "CalendarView::DateNavigator", QDate::currentDate()); 455 "CalendarView::DateNavigator", QDate::currentDate());
456#endif 456#endif
457 // mDateNavigator->blockSignals( true ); 457 // mDateNavigator->blockSignals( true );
458 //leftFrameLayout->addWidget( mDateNavigator ); 458 //leftFrameLayout->addWidget( mDateNavigator );
459 mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall"); 459 mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall");
460 mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView"); 460 mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView");
461 mCalEditView = new KOCalEditView(mLeftFrame,"CalendarView::CaleditView"); 461 mCalEditView = new KOCalEditView(mLeftFrame,"CalendarView::CaleditView");
462 connect( mCalEditView, SIGNAL( calendarEnabled (int,bool) ),mCalendar, SLOT( setCalendarEnabled(int,bool)) ); 462 connect( mCalEditView, SIGNAL( calendarEnabled (int,bool) ),mCalendar, SLOT( setCalendarEnabled(int,bool)) );
463 connect( mCalEditView, SIGNAL( alarmEnabled(int,bool) ),mCalendar, SLOT( setAlarmEnabled(int,bool)) ); 463 connect( mCalEditView, SIGNAL( alarmEnabled(int,bool) ),mCalendar, SLOT( setAlarmEnabled(int,bool)) );
464 connect( mCalEditView, SIGNAL( calendarReadonly(int,bool) ),mCalendar, SLOT( setReadOnly(int,bool)) ); 464 connect( mCalEditView, SIGNAL( calendarReadonly(int,bool) ),mCalendar, SLOT( setReadOnly(int,bool)) );
465 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mCalendar, SLOT( setDefaultCalendar(int)) ); 465 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mCalendar, SLOT( setDefaultCalendar(int)) );
466 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mViewManager, SLOT( setDefaultCalendar(int)) );
466 connect( mCalEditView, SIGNAL( removeCalendar(int) ),mCalendar, SLOT( setCalendarRemove(int)) ); 467 connect( mCalEditView, SIGNAL( removeCalendar(int) ),mCalendar, SLOT( setCalendarRemove(int)) );
467 connect( mCalEditView, SIGNAL( calendarAdded(int) ),this, SLOT( addCalendarId(int)) ); 468 connect( mCalEditView, SIGNAL( calendarAdded(int) ),this, SLOT( addCalendarId(int)) );
468 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateView()) ); 469 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateView()) );
469 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateUnmanagedViews()) ); 470 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateUnmanagedViews()) );
470 mTodoList->setNavigator( mNavigator ); 471 mTodoList->setNavigator( mNavigator );
471#if 0 472#if 0
472 if ( QApplication::desktop()->width() < 480 ) { 473 if ( QApplication::desktop()->width() < 480 ) {
473 leftFrameLayout->addWidget(mFilterView); 474 leftFrameLayout->addWidget(mFilterView);
474 leftFrameLayout->addWidget(mTodoList, 2 ); 475 leftFrameLayout->addWidget(mTodoList, 2 );
475 476
476 } else { 477 } else {
477 leftFrameLayout->addWidget(mTodoList,2 ); 478 leftFrameLayout->addWidget(mTodoList,2 );
478 leftFrameLayout->addWidget(mFilterView ); 479 leftFrameLayout->addWidget(mFilterView );
479 } 480 }
480#endif 481#endif
481 mFilterView->hide(); 482 mFilterView->hide();
482 mCalEditView->hide(); 483 mCalEditView->hide();
483 QWidget *rightBox = new QWidget( mMainFrame ); 484 QWidget *rightBox = new QWidget( mMainFrame );
484 //mainBoxLayout->addWidget ( rightBox, 10 ); 485 //mainBoxLayout->addWidget ( rightBox, 10 );
485 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 486 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
486 mRightFrame = new QWidgetStack( rightBox ); 487 mRightFrame = new QWidgetStack( rightBox );
487 rightLayout->addWidget( mRightFrame, 10 ); 488 rightLayout->addWidget( mRightFrame, 10 );
488 489
489 //mLeftFrame = (QWidget *)leftFrame; 490 //mLeftFrame = (QWidget *)leftFrame;
490 if ( KOPrefs::instance()->mVerticalScreen ) { 491 if ( KOPrefs::instance()->mVerticalScreen ) {
491 //mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() ); 492 //mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() );
492 //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() ); 493 //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() );
493 //mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); 494 //mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() );
494 //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); 495 //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() );
495 } else { 496 } else {
496 //mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() ); 497 //mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() );
497 //mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); 498 //mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() );
498 //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); 499 //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() );
499 } 500 }
500 if ( !KOPrefs::instance()->mShowDateNavigator) 501 if ( !KOPrefs::instance()->mShowDateNavigator)
501 mDateNavigator->hide(); 502 mDateNavigator->hide();
502 //qDebug("Calendarview Size %d %d ", width(), height()); 503 //qDebug("Calendarview Size %d %d ", width(), height());
503#endif 504#endif
504 505
505 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 506 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
506 SLOT( showDates( const KCal::DateList & ) ) ); 507 SLOT( showDates( const KCal::DateList & ) ) );
507 508
508 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 509 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
509 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 510 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
510 511
511 512
512 513
513 connect( mDateNavigator, SIGNAL( showMonth( const QDate & ) ), 514 connect( mDateNavigator, SIGNAL( showMonth( const QDate & ) ),
514 mViewManager, SLOT( showMonth( const QDate & ) ) ); 515 mViewManager, SLOT( showMonth( const QDate & ) ) );
515 516
516 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), 517 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ),
517 mNavigator, SLOT( selectWeek( const QDate & ) ) ); 518 mNavigator, SLOT( selectWeek( const QDate & ) ) );
518 519
519 connect( mDateNavigator, SIGNAL( goPrevYear() ), 520 connect( mDateNavigator, SIGNAL( goPrevYear() ),
520 mNavigator, SLOT( selectPreviousYear() ) ); 521 mNavigator, SLOT( selectPreviousYear() ) );
521 connect( mDateNavigator, SIGNAL( goNextYear() ), 522 connect( mDateNavigator, SIGNAL( goNextYear() ),
522 mNavigator, SLOT( selectNextYear() ) ); 523 mNavigator, SLOT( selectNextYear() ) );
523 connect( mDateNavigator, SIGNAL( goPrevMonth() ), 524 connect( mDateNavigator, SIGNAL( goPrevMonth() ),
524 mNavigator, SLOT( selectPreviousMonth() ) ); 525 mNavigator, SLOT( selectPreviousMonth() ) );
525 connect( mDateNavigator, SIGNAL( goNextMonth() ), 526 connect( mDateNavigator, SIGNAL( goNextMonth() ),
526 mNavigator, SLOT( selectNextMonth() ) ); 527 mNavigator, SLOT( selectNextMonth() ) );
527 528
528 connect( mDateNavigator, SIGNAL( goPrevious() ), 529 connect( mDateNavigator, SIGNAL( goPrevious() ),
529 mNavigator, SLOT( selectPrevious() ) ); 530 mNavigator, SLOT( selectPrevious() ) );
530 connect( mDateNavigator, SIGNAL( goNext() ), 531 connect( mDateNavigator, SIGNAL( goNext() ),
531 mNavigator, SLOT( selectNext() ) ); 532 mNavigator, SLOT( selectNext() ) );
532 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), 533 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ),
533 mNavigator, SLOT( slotMonthSelect( int ) ) ); 534 mNavigator, SLOT( slotMonthSelect( int ) ) );
534 535
535 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 536 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
536 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 537 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
537#if 0 538#if 0
538 connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ), 539 connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ),
539 SLOT( incidenceAdded( Incidence *) ) ); 540 SLOT( incidenceAdded( Incidence *) ) );
540#endif 541#endif
541 // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); 542 // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView()));
542 543
543 connect( this, SIGNAL( configChanged() ), 544 connect( this, SIGNAL( configChanged() ),
544 mDateNavigator, SLOT( updateConfig() ) ); 545 mDateNavigator, SLOT( updateConfig() ) );
545 546
546 connect( mTodoList, SIGNAL( newTodoSignal() ), 547 connect( mTodoList, SIGNAL( newTodoSignal() ),
547 SLOT( newTodo() ) ); 548 SLOT( newTodo() ) );
548 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), 549 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ),
549 SLOT( newSubTodo( Todo * ) ) ); 550 SLOT( newSubTodo( Todo * ) ) );
550 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), 551 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ),
551 SLOT( editTodo( Todo * ) ) ); 552 SLOT( editTodo( Todo * ) ) );
552 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), 553 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ),
553 SLOT( showTodo( Todo *) ) ); 554 SLOT( showTodo( Todo *) ) );
554 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), 555 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ),
555 SLOT( deleteTodo( Todo *) ) ); 556 SLOT( deleteTodo( Todo *) ) );
556 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); 557 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) );
557 connect( mTodoList, SIGNAL( purgeCompletedSignal() ), 558 connect( mTodoList, SIGNAL( purgeCompletedSignal() ),
558 SLOT( purgeCompleted() ) ); 559 SLOT( purgeCompleted() ) );
559 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), 560 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ),
560 SIGNAL( todoModified( Todo *, int ) ) ); 561 SIGNAL( todoModified( Todo *, int ) ) );
561 562
562 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), 563 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ),
563 this, SLOT ( cloneIncidence( Incidence * ) ) ); 564 this, SLOT ( cloneIncidence( Incidence * ) ) );
564 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), 565 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ),
565 this, SLOT (cancelIncidence( Incidence * ) ) ); 566 this, SLOT (cancelIncidence( Incidence * ) ) );
566 567
567 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), 568 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ),
568 this, SLOT ( moveIncidence( Incidence * ) ) ); 569 this, SLOT ( moveIncidence( Incidence * ) ) );
569 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), 570 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ),
570 this, SLOT ( beamIncidence( Incidence * ) ) ); 571 this, SLOT ( beamIncidence( Incidence * ) ) );
571 572
572 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), 573 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ),
573 this, SLOT ( todo_unsub( Todo * ) ) ); 574 this, SLOT ( todo_unsub( Todo * ) ) );
574 575
575 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), 576 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ),
576 this, SLOT ( todo_resub( Todo *,Todo * ) ) ); 577 this, SLOT ( todo_resub( Todo *,Todo * ) ) );
577 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, 578 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList,
578 SLOT( updateTodo( Todo *, int ) ) ); 579 SLOT( updateTodo( Todo *, int ) ) );
579 connect( this, SIGNAL( todoModified( Todo *, int )), this, 580 connect( this, SIGNAL( todoModified( Todo *, int )), this,
580 SLOT( changeTodoDisplay( Todo *, int ) ) ); 581 SLOT( changeTodoDisplay( Todo *, int ) ) );
581 582
582 583
583 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); 584 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) );
584 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); 585 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) );
585 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); 586 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) );
586 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); 587 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) );
587 588
588 589
589 590
590 591
591 592
592 connect(QApplication::clipboard(),SIGNAL(dataChanged()), 593 connect(QApplication::clipboard(),SIGNAL(dataChanged()),
593 SLOT(checkClipboard())); 594 SLOT(checkClipboard()));
594 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), 595 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ),
595 SLOT( processTodoListSelection( Incidence * ) ) ); 596 SLOT( processTodoListSelection( Incidence * ) ) );
596 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); 597 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
597 598
598 // kdDebug() << "CalendarView::CalendarView() done" << endl; 599 // kdDebug() << "CalendarView::CalendarView() done" << endl;
599 600
600 mDateFrame = new QVBox(0,0,WType_Popup); 601 mDateFrame = new QVBox(0,0,WType_Popup);
601 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 602 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
602 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 603 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
603 mDateFrame->setLineWidth(3); 604 mDateFrame->setLineWidth(3);
604 mDateFrame->hide(); 605 mDateFrame->hide();
605 mDateFrame->setCaption( i18n( "Pick a date to display")); 606 mDateFrame->setCaption( i18n( "Pick a date to display"));
606 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); 607 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() );
607 608
608 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); 609 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate)));
609 610
610 mEventEditor = mDialogManager->getEventEditor(); 611 mEventEditor = mDialogManager->getEventEditor();
611 mTodoEditor = mDialogManager->getTodoEditor(); 612 mTodoEditor = mDialogManager->getTodoEditor();
612 613
613 mFlagEditDescription = false; 614 mFlagEditDescription = false;
614 615
615 mSuspendTimer = new QTimer( this ); 616 mSuspendTimer = new QTimer( this );
616 mAlarmTimer = new QTimer( this ); 617 mAlarmTimer = new QTimer( this );
617 mRecheckAlarmTimer = new QTimer( this ); 618 mRecheckAlarmTimer = new QTimer( this );
618 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); 619 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) );
619 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 620 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
620 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 621 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
621 mAlarmDialog = new AlarmDialog( this ); 622 mAlarmDialog = new AlarmDialog( this );
622 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 623 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
623 mAlarmDialog->setServerNotification( false ); 624 mAlarmDialog->setServerNotification( false );
624 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 625 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
625 626
626 627
627#ifndef DESKTOP_VERSION 628#ifndef DESKTOP_VERSION
628//US listen for arriving address resultsets 629//US listen for arriving address resultsets
629 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), 630 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)),
630 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); 631 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)));
631#endif 632#endif
632 mDateNavigator->setCalendar( mCalendar ); 633 mDateNavigator->setCalendar( mCalendar );
633} 634}
634 635
635 636
636CalendarView::~CalendarView() 637CalendarView::~CalendarView()
637{ 638{
638 // kdDebug() << "~CalendarView()" << endl; 639 // kdDebug() << "~CalendarView()" << endl;
639 //qDebug("CalendarView::~CalendarView() "); 640 //qDebug("CalendarView::~CalendarView() ");
640 delete mDialogManager; 641 delete mDialogManager;
641 delete mViewManager; 642 delete mViewManager;
642 delete mStorage; 643 delete mStorage;
643 delete mDateFrame ; 644 delete mDateFrame ;
644 delete beamDialog; 645 delete beamDialog;
645 delete mEventViewerDialog; 646 delete mEventViewerDialog;
646 //kdDebug() << "~CalendarView() done" << endl; 647 //kdDebug() << "~CalendarView() done" << endl;
647} 648}
648void CalendarView::checkAlarms() 649void CalendarView::checkAlarms()
649{ 650{
650 KConfig *config = KOGlobals::config(); 651 KConfig *config = KOGlobals::config();
651 config->setGroup( "AppRun" ); 652 config->setGroup( "AppRun" );
652 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 653 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
653 int daysto = dt.daysTo( QDate::currentDate() ); 654 int daysto = dt.daysTo( QDate::currentDate() );
654 int days = config->readNumEntry( "LatestProgramStopDays" , daysto); 655 int days = config->readNumEntry( "LatestProgramStopDays" , daysto);
655 dt = dt.addDays( days ); 656 dt = dt.addDays( days );
656 int secto = dt.secsTo( QDateTime::currentDateTime() ); 657 int secto = dt.secsTo( QDateTime::currentDateTime() );
657 int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30; 658 int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30;
658 //qDebug("KO: Reading program stop %d ", secs); 659 //qDebug("KO: Reading program stop %d ", secs);
659 //secs -= ( 3600 * 24*3 ); // debug only 660 //secs -= ( 3600 * 24*3 ); // debug only
660 QDateTime latest = dt.addSecs ( secs ); 661 QDateTime latest = dt.addSecs ( secs );
661 qDebug("KO: Last termination on %s ", latest.toString().latin1()); 662 qDebug("KO: Last termination on %s ", latest.toString().latin1());
662 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 663 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
663 QPtrList<Incidence> el = mCalendar->rawIncidences(); 664 QPtrList<Incidence> el = mCalendar->rawIncidences();
664 QPtrList<Incidence> al; 665 QPtrList<Incidence> al;
665 Incidence* inL = el.first(); 666 Incidence* inL = el.first();
666 QDateTime cur = QDateTime::currentDateTime().addSecs(-59); 667 QDateTime cur = QDateTime::currentDateTime().addSecs(-59);
667 qDebug("KO: Checking alarm until %s ", cur.toString().latin1()); 668 qDebug("KO: Checking alarm until %s ", cur.toString().latin1());
668 while ( inL ) { 669 while ( inL ) {
669 bool ok = false; 670 bool ok = false;
670 int offset = 0; 671 int offset = 0;
671 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ; 672 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ;
672 if ( ok ) { 673 if ( ok ) {
673 //qDebug("OK %s",next.toString().latin1()); 674 //qDebug("OK %s",next.toString().latin1());
674 if ( next < cur ) { 675 if ( next < cur ) {
675 al.append( inL ); 676 al.append( inL );
676 //qDebug("found missed alarm: %s ", inL->summary().latin1() ); 677 //qDebug("found missed alarm: %s ", inL->summary().latin1() );
677 } 678 }
678 } 679 }
679 inL = el.next(); 680 inL = el.next();
680 } 681 }
681 if ( al.count() ) { 682 if ( al.count() ) {
682 QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop ); 683 QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop );
683 dia->setCaption( i18n("KO/Pi: Missing alarms!") ); 684 dia->setCaption( i18n("KO/Pi: Missing alarms!") );
684 QVBoxLayout* lay = new QVBoxLayout( dia ); 685 QVBoxLayout* lay = new QVBoxLayout( dia );
685 lay->setSpacing( 0 ); 686 lay->setSpacing( 0 );
686 lay->setMargin( 0 ); 687 lay->setMargin( 0 );
687 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest ); 688 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest );
688 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); 689 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) ));
689 lay->addWidget( matb ); 690 lay->addWidget( matb );
690 if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) { 691 if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) {
691 int wid = 210; 692 int wid = 210;
692 int x = QApplication::desktop()->width() - wid - 7; 693 int x = QApplication::desktop()->width() - wid - 7;
693 int y = QApplication::desktop()->height() - wid - 70; 694 int y = QApplication::desktop()->height() - wid - 70;
694 dia->setGeometry ( x,y,wid,wid); 695 dia->setGeometry ( x,y,wid,wid);
695 } else { 696 } else {
696 int si = 220; 697 int si = 220;
697 if ( QApplication::desktop()->width() > 470 ) 698 if ( QApplication::desktop()->width() > 470 )
698 si = 400; 699 si = 400;
699 dia->resize(si,si/2); 700 dia->resize(si,si/2);
700 } 701 }
701 dia->setBackgroundColor( QColor( 255, 255, 255 ) ); 702 dia->setBackgroundColor( QColor( 255, 255, 255 ) );
702 dia->show(); 703 dia->show();
703 704
704 } 705 }
705} 706}
706void CalendarView::showDay( QDate d ) 707void CalendarView::showDay( QDate d )
707{ 708{
708 dateNavigator()->blockSignals( true ); 709 dateNavigator()->blockSignals( true );
709 dateNavigator()->selectDate( d ); 710 dateNavigator()->selectDate( d );
710 dateNavigator()->blockSignals( false ); 711 dateNavigator()->blockSignals( false );
711 mViewManager->showDayView(); 712 mViewManager->showDayView();
712 //dateNavigator()->selectDate( d ); 713 //dateNavigator()->selectDate( d );
713} 714}
714void CalendarView::timerAlarm() 715void CalendarView::timerAlarm()
715{ 716{
716 //qDebug("CalendarView::timerAlarm() "); 717 //qDebug("CalendarView::timerAlarm() ");
717 computeAlarm(mAlarmNotification ); 718 computeAlarm(mAlarmNotification );
718} 719}
719 720
720void CalendarView::suspendAlarm() 721void CalendarView::suspendAlarm()
721{ 722{
722 //qDebug(" CalendarView::suspendAlarm() "); 723 //qDebug(" CalendarView::suspendAlarm() ");
723 computeAlarm(mSuspendAlarmNotification ); 724 computeAlarm(mSuspendAlarmNotification );
724 725
725} 726}
726 727
727void CalendarView::startAlarm( QString mess , QString filename) 728void CalendarView::startAlarm( QString mess , QString filename)
728{ 729{
729 730
730 topLevelWidget()->showNormal(); 731 topLevelWidget()->showNormal();
731 topLevelWidget()->setActiveWindow(); 732 topLevelWidget()->setActiveWindow();
732 topLevelWidget()->raise(); 733 topLevelWidget()->raise();
733 734
734 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 735 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
735 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); 736 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) );
736 737
737} 738}
738 739
739void CalendarView::checkNextTimerAlarm() 740void CalendarView::checkNextTimerAlarm()
740{ 741{
741 mCalendar->checkAlarmForIncidence( 0, true ); 742 mCalendar->checkAlarmForIncidence( 0, true );
742} 743}
743 744
744void CalendarView::computeAlarm( QString msg ) 745void CalendarView::computeAlarm( QString msg )
745{ 746{
746 747
747 QString mess = msg; 748 QString mess = msg;
748 QString mAlarmMessage = mess.mid( 9 ); 749 QString mAlarmMessage = mess.mid( 9 );
749 QString filename = MainWindow::resourcePath(); 750 QString filename = MainWindow::resourcePath();
750 filename += "koalarm.wav"; 751 filename += "koalarm.wav";
751 QString tempfilename; 752 QString tempfilename;
752 if ( mess.left( 13 ) == "suspend_alarm") { 753 if ( mess.left( 13 ) == "suspend_alarm") {
753 bool error = false; 754 bool error = false;
754 int len = mess.mid( 13 ).find("+++"); 755 int len = mess.mid( 13 ).find("+++");
755 if ( len < 2 ) 756 if ( len < 2 )
756 error = true; 757 error = true;
757 else { 758 else {
758 tempfilename = mess.mid( 13, len ); 759 tempfilename = mess.mid( 13, len );
759 if ( !QFile::exists( tempfilename ) ) 760 if ( !QFile::exists( tempfilename ) )
760 error = true; 761 error = true;
761 } 762 }
762 if ( ! error ) { 763 if ( ! error ) {
763 filename = tempfilename; 764 filename = tempfilename;
764 } 765 }
765 mAlarmMessage = mess.mid( 13+len+3 ); 766 mAlarmMessage = mess.mid( 13+len+3 );
766 //qDebug("suspend file %s ",tempfilename.latin1() ); 767 //qDebug("suspend file %s ",tempfilename.latin1() );
767 startAlarm( mAlarmMessage, filename); 768 startAlarm( mAlarmMessage, filename);
768 return; 769 return;
769 } 770 }
770 if ( mess.left( 11 ) == "timer_alarm") { 771 if ( mess.left( 11 ) == "timer_alarm") {
771 //mTimerTime = 0; 772 //mTimerTime = 0;
772 startAlarm( mess.mid( 11 ), filename ); 773 startAlarm( mess.mid( 11 ), filename );
773 return; 774 return;
774 } 775 }
775 if ( mess.left( 10 ) == "proc_alarm") { 776 if ( mess.left( 10 ) == "proc_alarm") {
776 bool error = false; 777 bool error = false;
777 int len = mess.mid( 10 ).find("+++"); 778 int len = mess.mid( 10 ).find("+++");
778 if ( len < 2 ) 779 if ( len < 2 )
779 error = true; 780 error = true;
780 else { 781 else {
781 tempfilename = mess.mid( 10, len ); 782 tempfilename = mess.mid( 10, len );
782 if ( !QFile::exists( tempfilename ) ) 783 if ( !QFile::exists( tempfilename ) )
783 error = true; 784 error = true;
784 } 785 }
785 if ( error ) { 786 if ( error ) {
786 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 787 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
787 mAlarmMessage += mess.mid( 10+len+3+9 ); 788 mAlarmMessage += mess.mid( 10+len+3+9 );
788 } else { 789 } else {
789 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 790 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
790 //qDebug("-----system command %s ",tempfilename.latin1() ); 791 //qDebug("-----system command %s ",tempfilename.latin1() );
791#ifndef _WIN32_ 792#ifndef _WIN32_
792 if ( vfork () == 0 ) { 793 if ( vfork () == 0 ) {
793 execl ( tempfilename.latin1(), 0 ); 794 execl ( tempfilename.latin1(), 0 );
794 return; 795 return;
795 } 796 }
796#else 797#else
797 QProcess* p = new QProcess(); 798 QProcess* p = new QProcess();
798 p->addArgument( tempfilename.latin1() ); 799 p->addArgument( tempfilename.latin1() );
799 p->start(); 800 p->start();
800 return; 801 return;
801#endif 802#endif
802 803
803 return; 804 return;
804 } 805 }
805 806
806 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 807 //qDebug("+++++++system command %s ",tempfilename.latin1() );
807 } 808 }
808 if ( mess.left( 11 ) == "audio_alarm") { 809 if ( mess.left( 11 ) == "audio_alarm") {
809 bool error = false; 810 bool error = false;
810 int len = mess.mid( 11 ).find("+++"); 811 int len = mess.mid( 11 ).find("+++");
811 if ( len < 2 ) 812 if ( len < 2 )
812 error = true; 813 error = true;
813 else { 814 else {
814 tempfilename = mess.mid( 11, len ); 815 tempfilename = mess.mid( 11, len );
815 if ( !QFile::exists( tempfilename ) ) 816 if ( !QFile::exists( tempfilename ) )
816 error = true; 817 error = true;
817 } 818 }
818 if ( ! error ) { 819 if ( ! error ) {
819 filename = tempfilename; 820 filename = tempfilename;
820 } 821 }
821 mAlarmMessage = mess.mid( 11+len+3+9 ); 822 mAlarmMessage = mess.mid( 11+len+3+9 );
822 //qDebug("audio file command %s ",tempfilename.latin1() ); 823 //qDebug("audio file command %s ",tempfilename.latin1() );
823 } 824 }
824 if ( mess.left( 9 ) == "cal_alarm") { 825 if ( mess.left( 9 ) == "cal_alarm") {
825 mAlarmMessage = mess.mid( 9 ) ; 826 mAlarmMessage = mess.mid( 9 ) ;
826 } 827 }
827 828
828 startAlarm( mAlarmMessage, filename ); 829 startAlarm( mAlarmMessage, filename );
829 830
830 831
831} 832}
832 833
833void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 834void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
834{ 835{
835 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 836 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
836 837
837 mSuspendAlarmNotification = noti; 838 mSuspendAlarmNotification = noti;
838 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 839 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
839 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 840 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
840 mSuspendTimer->start( ms , true ); 841 mSuspendTimer->start( ms , true );
841 842
842} 843}
843 844
844void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 845void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
845{ 846{
846 mNextAlarmDateTime = qdt; 847 mNextAlarmDateTime = qdt;
847 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 848 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
848 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 849 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
849#ifndef DESKTOP_VERSION 850#ifndef DESKTOP_VERSION
850 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() ); 851 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() );
851#endif 852#endif
852 return; 853 return;
853 } 854 }
854 int maxSec; 855 int maxSec;
855 //maxSec = 5; //testing only 856 //maxSec = 5; //testing only
856 maxSec = 86400+3600; // one day+1hour 857 maxSec = 86400+3600; // one day+1hour
857 mAlarmNotification = noti; 858 mAlarmNotification = noti;
858 int sec = QDateTime::currentDateTime().secsTo( qdt ); 859 int sec = QDateTime::currentDateTime().secsTo( qdt );
859 if ( sec > maxSec ) { 860 if ( sec > maxSec ) {
860 mRecheckAlarmTimer->start( maxSec * 1000 ); 861 mRecheckAlarmTimer->start( maxSec * 1000 );
861 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 862 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
862 return; 863 return;
863 } else { 864 } else {
864 mRecheckAlarmTimer->stop(); 865 mRecheckAlarmTimer->stop();
865 } 866 }
866 //qDebug("Alarm timer started with secs: %d ", sec); 867 //qDebug("Alarm timer started with secs: %d ", sec);
867 mAlarmTimer->start( sec *1000 , true ); 868 mAlarmTimer->start( sec *1000 , true );
868 869
869} 870}
870// called by mRecheckAlarmTimer to get next alarm 871// called by mRecheckAlarmTimer to get next alarm
871// we need this, because a QTimer has only a max range of 25 days 872// we need this, because a QTimer has only a max range of 25 days
872void CalendarView::recheckTimerAlarm() 873void CalendarView::recheckTimerAlarm()
873{ 874{
874 mAlarmTimer->stop(); 875 mAlarmTimer->stop();
875 mRecheckAlarmTimer->stop(); 876 mRecheckAlarmTimer->stop();
876 mCalendar->checkAlarmForIncidence( 0, true ); 877 mCalendar->checkAlarmForIncidence( 0, true );
877} 878}
878void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 879void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
879{ 880{
880 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 881 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
881 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 882 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
882#ifndef DESKTOP_VERSION 883#ifndef DESKTOP_VERSION
883 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 884 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
884#endif 885#endif
885 return; 886 return;
886 } 887 }
887 mAlarmTimer->stop(); 888 mAlarmTimer->stop();
888} 889}
889void CalendarView::selectWeekNum ( int num ) 890void CalendarView::selectWeekNum ( int num )
890{ 891{
891 dateNavigator()->blockSignals( true ); 892 dateNavigator()->blockSignals( true );
892 dateNavigator()->selectWeek( num ); 893 dateNavigator()->selectWeek( num );
893 dateNavigator()->blockSignals( false ); 894 dateNavigator()->blockSignals( false );
894 mViewManager->showWeekView(); 895 mViewManager->showWeekView();
895} 896}
896KOViewManager *CalendarView::viewManager() 897KOViewManager *CalendarView::viewManager()
897{ 898{
898 return mViewManager; 899 return mViewManager;
899} 900}
900 901
901KODialogManager *CalendarView::dialogManager() 902KODialogManager *CalendarView::dialogManager()
902{ 903{
903 return mDialogManager; 904 return mDialogManager;
904} 905}
905 906
906QDate CalendarView::startDate() 907QDate CalendarView::startDate()
907{ 908{
908 DateList dates = mNavigator->selectedDates(); 909 DateList dates = mNavigator->selectedDates();
909 910
910 return dates.first(); 911 return dates.first();
911} 912}
912 913
913QDate CalendarView::endDate() 914QDate CalendarView::endDate()
914{ 915{
915 DateList dates = mNavigator->selectedDates(); 916 DateList dates = mNavigator->selectedDates();
916 917
917 return dates.last(); 918 return dates.last();
918} 919}
919 920
920 921
921void CalendarView::createPrinter() 922void CalendarView::createPrinter()
922{ 923{
923#ifndef KORG_NOPRINTER 924#ifndef KORG_NOPRINTER
924 if (!mCalPrinter) { 925 if (!mCalPrinter) {
925 mCalPrinter = new CalPrinter(this, mCalendar); 926 mCalPrinter = new CalPrinter(this, mCalendar);
926 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 927 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
927 } 928 }
928#endif 929#endif
929} 930}
930 931
931 932
932//KOPrefs::instance()->mWriteBackFile 933//KOPrefs::instance()->mWriteBackFile
933//KOPrefs::instance()->mWriteBackExistingOnly 934//KOPrefs::instance()->mWriteBackExistingOnly
934 935
935// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 936// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
936// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 937// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
937// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 938// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
938// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 939// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
939// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 940// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
940// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 941// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
941 942
942int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 943int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
943{ 944{
944 945
945 // 0 equal 946 // 0 equal
946 // 1 take local 947 // 1 take local
947 // 2 take remote 948 // 2 take remote
948 // 3 cancel 949 // 3 cancel
949 QDateTime lastSync = mLastCalendarSync; 950 QDateTime lastSync = mLastCalendarSync;
950 QDateTime localMod = local->lastModified(); 951 QDateTime localMod = local->lastModified();
951 QDateTime remoteMod = remote->lastModified(); 952 QDateTime remoteMod = remote->lastModified();
952 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 953 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
953 bool remCh, locCh; 954 bool remCh, locCh;
954 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 955 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
955 //if ( remCh ) 956 //if ( remCh )
956 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 957 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
957 locCh = ( localMod > mLastCalendarSync ); 958 locCh = ( localMod > mLastCalendarSync );
958 if ( !remCh && ! locCh ) { 959 if ( !remCh && ! locCh ) {
959 //qDebug("both not changed "); 960 //qDebug("both not changed ");
960 lastSync = localMod.addDays(1); 961 lastSync = localMod.addDays(1);
961 if ( mode <= SYNC_PREF_ASK ) 962 if ( mode <= SYNC_PREF_ASK )
962 return 0; 963 return 0;
963 } else { 964 } else {
964 if ( locCh ) { 965 if ( locCh ) {
965 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 966 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
966 lastSync = localMod.addDays( -1 ); 967 lastSync = localMod.addDays( -1 );
967 if ( !remCh ) 968 if ( !remCh )
968 remoteMod = ( lastSync.addDays( -1 ) ); 969 remoteMod = ( lastSync.addDays( -1 ) );
969 } else { 970 } else {
970 //qDebug(" not loc changed "); 971 //qDebug(" not loc changed ");
971 lastSync = localMod.addDays( 1 ); 972 lastSync = localMod.addDays( 1 );
972 if ( remCh ) 973 if ( remCh )
973 remoteMod =( lastSync.addDays( 1 ) ); 974 remoteMod =( lastSync.addDays( 1 ) );
974 975
975 } 976 }
976 } 977 }
977 full = true; 978 full = true;
978 if ( mode < SYNC_PREF_ASK ) 979 if ( mode < SYNC_PREF_ASK )
979 mode = SYNC_PREF_ASK; 980 mode = SYNC_PREF_ASK;
980 } else { 981 } else {
981 if ( localMod == remoteMod ) 982 if ( localMod == remoteMod )
982 // if ( local->revision() == remote->revision() ) 983 // if ( local->revision() == remote->revision() )
983 return 0; 984 return 0;
984 985
985 } 986 }
986 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 987 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
987 988
988 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 989 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
989 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 990 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
990 //full = true; //debug only 991 //full = true; //debug only
991 if ( full ) { 992 if ( full ) {
992 bool equ = false; 993 bool equ = false;
993 if ( local->typeID() == eventID ) { 994 if ( local->typeID() == eventID ) {
994 equ = (*((Event*) local) == *((Event*) remote)); 995 equ = (*((Event*) local) == *((Event*) remote));
995 } 996 }
996 else if ( local->typeID() == todoID ) 997 else if ( local->typeID() == todoID )
997 equ = (*((Todo*) local) == (*(Todo*) remote)); 998 equ = (*((Todo*) local) == (*(Todo*) remote));
998 else if ( local->typeID() == journalID ) 999 else if ( local->typeID() == journalID )
999 equ = (*((Journal*) local) == *((Journal*) remote)); 1000 equ = (*((Journal*) local) == *((Journal*) remote));
1000 if ( equ ) { 1001 if ( equ ) {
1001 //qDebug("equal "); 1002 //qDebug("equal ");
1002 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1003 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1003 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 1004 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
1004 } 1005 }
1005 if ( mode < SYNC_PREF_FORCE_LOCAL ) 1006 if ( mode < SYNC_PREF_FORCE_LOCAL )
1006 return 0; 1007 return 0;
1007 1008
1008 }//else //debug only 1009 }//else //debug only
1009 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 1010 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
1010 } 1011 }
1011 int result; 1012 int result;
1012 bool localIsNew; 1013 bool localIsNew;
1013 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); 1014 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() );
1014 1015
1015 1016
1016 // ************************************************ 1017 // ************************************************
1017 // ************************************************ 1018 // ************************************************
1018 // ************************************************ 1019 // ************************************************
1019 // We may have that lastSync > remoteMod AND lastSync > localMod 1020 // We may have that lastSync > remoteMod AND lastSync > localMod
1020 // BUT remoteMod != localMod 1021 // BUT remoteMod != localMod
1021 1022
1022 1023
1023 if ( full && mode < SYNC_PREF_NEWEST ) 1024 if ( full && mode < SYNC_PREF_NEWEST )
1024 mode = SYNC_PREF_ASK; 1025 mode = SYNC_PREF_ASK;
1025 1026
1026 switch( mode ) { 1027 switch( mode ) {
1027 case SYNC_PREF_LOCAL: 1028 case SYNC_PREF_LOCAL:
1028 if ( lastSync > remoteMod ) 1029 if ( lastSync > remoteMod )
1029 return 1; 1030 return 1;
1030 if ( lastSync > localMod ) 1031 if ( lastSync > localMod )
1031 return 2; 1032 return 2;
1032 return 1; 1033 return 1;
1033 break; 1034 break;
1034 case SYNC_PREF_REMOTE: 1035 case SYNC_PREF_REMOTE:
1035 if ( lastSync > localMod ) 1036 if ( lastSync > localMod )
1036 return 2; 1037 return 2;
1037 if ( lastSync > remoteMod ) 1038 if ( lastSync > remoteMod )
1038 return 1; 1039 return 1;
1039 return 2; 1040 return 2;
1040 break; 1041 break;
1041 case SYNC_PREF_NEWEST: 1042 case SYNC_PREF_NEWEST:
1042 if ( localMod >= remoteMod ) 1043 if ( localMod >= remoteMod )
1043 return 1; 1044 return 1;
1044 else 1045 else
1045 return 2; 1046 return 2;
1046 break; 1047 break;
1047 case SYNC_PREF_ASK: 1048 case SYNC_PREF_ASK:
1048 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1049 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1049 if ( lastSync > remoteMod && lastSync > localMod) 1050 if ( lastSync > remoteMod && lastSync > localMod)
1050 return 0; 1051 return 0;
1051 if ( lastSync > remoteMod ) 1052 if ( lastSync > remoteMod )
1052 return 1; 1053 return 1;
1053 if ( lastSync > localMod ) 1054 if ( lastSync > localMod )
1054 return 2; 1055 return 2;
1055 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1056 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1056 localIsNew = localMod >= remoteMod; 1057 localIsNew = localMod >= remoteMod;
1057 if ( localIsNew ) 1058 if ( localIsNew )
1058 getEventViewerDialog()->setColorMode( 1 ); 1059 getEventViewerDialog()->setColorMode( 1 );
1059 else 1060 else
1060 getEventViewerDialog()->setColorMode( 2 ); 1061 getEventViewerDialog()->setColorMode( 2 );
1061 getEventViewerDialog()->setIncidence(local); 1062 getEventViewerDialog()->setIncidence(local);
1062 if ( localIsNew ) 1063 if ( localIsNew )
1063 getEventViewerDialog()->setColorMode( 2 ); 1064 getEventViewerDialog()->setColorMode( 2 );
1064 else 1065 else
1065 getEventViewerDialog()->setColorMode( 1 ); 1066 getEventViewerDialog()->setColorMode( 1 );
1066 getEventViewerDialog()->addIncidence(remote); 1067 getEventViewerDialog()->addIncidence(remote);
1067 getEventViewerDialog()->setColorMode( 0 ); 1068 getEventViewerDialog()->setColorMode( 0 );
1068 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 1069 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
1069 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 1070 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
1070 getEventViewerDialog()->showMe(); 1071 getEventViewerDialog()->showMe();
1071 result = getEventViewerDialog()->executeS( localIsNew ); 1072 result = getEventViewerDialog()->executeS( localIsNew );
1072 return result; 1073 return result;
1073 1074
1074 break; 1075 break;
1075 case SYNC_PREF_FORCE_LOCAL: 1076 case SYNC_PREF_FORCE_LOCAL:
1076 return 1; 1077 return 1;
1077 break; 1078 break;
1078 case SYNC_PREF_FORCE_REMOTE: 1079 case SYNC_PREF_FORCE_REMOTE:
1079 return 2; 1080 return 2;
1080 break; 1081 break;
1081 1082
1082 default: 1083 default:
1083 // SYNC_PREF_TAKE_BOTH not implemented 1084 // SYNC_PREF_TAKE_BOTH not implemented
1084 break; 1085 break;
1085 } 1086 }
1086 return 0; 1087 return 0;
1087} 1088}
1088Event* CalendarView::getLastSyncEvent() 1089Event* CalendarView::getLastSyncEvent()
1089{ 1090{
1090 Event* lse; 1091 Event* lse;
1091 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 1092 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
1092 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 1093 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
1093 if (!lse) { 1094 if (!lse) {
1094 lse = new Event(); 1095 lse = new Event();
1095 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 1096 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
1096 QString sum = ""; 1097 QString sum = "";
1097 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 1098 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
1098 sum = "E: "; 1099 sum = "E: ";
1099 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 1100 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
1100 lse->setDtStart( mLastCalendarSync ); 1101 lse->setDtStart( mLastCalendarSync );
1101 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1102 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1102 lse->setCategories( i18n("SyncEvent") ); 1103 lse->setCategories( i18n("SyncEvent") );
1103 lse->setReadOnly( true ); 1104 lse->setReadOnly( true );
1104 mCalendar->addEvent( lse ); 1105 mCalendar->addEvent( lse );
1105 } 1106 }
1106 1107
1107 return lse; 1108 return lse;
1108 1109
1109} 1110}
1110 1111
1111// we check, if the to delete event has a id for a profile 1112// we check, if the to delete event has a id for a profile
1112// if yes, we set this id in the profile to delete 1113// if yes, we set this id in the profile to delete
1113void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 1114void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
1114{ 1115{
1115 if ( lastSync.count() == 0 ) { 1116 if ( lastSync.count() == 0 ) {
1116 //qDebug(" lastSync.count() == 0"); 1117 //qDebug(" lastSync.count() == 0");
1117 return; 1118 return;
1118 } 1119 }
1119 if ( toDelete->typeID() == journalID ) 1120 if ( toDelete->typeID() == journalID )
1120 return; 1121 return;
1121 1122
1122 Event* eve = lastSync.first(); 1123 Event* eve = lastSync.first();
1123 1124
1124 while ( eve ) { 1125 while ( eve ) {
1125 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 1126 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
1126 if ( !id.isEmpty() ) { 1127 if ( !id.isEmpty() ) {
1127 QString des = eve->description(); 1128 QString des = eve->description();
1128 QString pref = "e"; 1129 QString pref = "e";
1129 if ( toDelete->typeID() == todoID ) 1130 if ( toDelete->typeID() == todoID )
1130 pref = "t"; 1131 pref = "t";
1131 des += pref+ id + ","; 1132 des += pref+ id + ",";
1132 eve->setReadOnly( false ); 1133 eve->setReadOnly( false );
1133 eve->setDescription( des ); 1134 eve->setDescription( des );
1134 //qDebug("setdes %s ", des.latin1()); 1135 //qDebug("setdes %s ", des.latin1());
1135 eve->setReadOnly( true ); 1136 eve->setReadOnly( true );
1136 } 1137 }
1137 eve = lastSync.next(); 1138 eve = lastSync.next();
1138 } 1139 }
1139 1140
1140} 1141}
1141void CalendarView::checkExternalId( Incidence * inc ) 1142void CalendarView::checkExternalId( Incidence * inc )
1142{ 1143{
1143 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 1144 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
1144 checkExternSyncEvent( lastSync, inc ); 1145 checkExternSyncEvent( lastSync, inc );
1145 1146
1146} 1147}
1147bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 1148bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
1148{ 1149{
1149 bool syncOK = true; 1150 bool syncOK = true;
1150 int addedEvent = 0; 1151 int addedEvent = 0;
1151 int addedEventR = 0; 1152 int addedEventR = 0;
1152 int deletedEventR = 0; 1153 int deletedEventR = 0;
1153 int deletedEventL = 0; 1154 int deletedEventL = 0;
1154 int changedLocal = 0; 1155 int changedLocal = 0;
1155 int changedRemote = 0; 1156 int changedRemote = 0;
1156 int filteredIN = 0; 1157 int filteredIN = 0;
1157 int filteredOUT = 0; 1158 int filteredOUT = 0;
1158 //QPtrList<Event> el = local->rawEvents(); 1159 //QPtrList<Event> el = local->rawEvents();
1159 Event* eventR; 1160 Event* eventR;
1160 QString uid; 1161 QString uid;
1161 int take; 1162 int take;
1162 Event* eventL; 1163 Event* eventL;
1163 Event* eventRSync; 1164 Event* eventRSync;
1164 Event* eventLSync; 1165 Event* eventLSync;
1165 clearAllViews(); 1166 clearAllViews();
1166 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 1167 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
1167 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 1168 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
1168 bool fullDateRange = false; 1169 bool fullDateRange = false;
1169 local->resetTempSyncStat(); 1170 local->resetTempSyncStat();
1170 mLastCalendarSync = QDateTime::currentDateTime(); 1171 mLastCalendarSync = QDateTime::currentDateTime();
1171 if ( mSyncManager->syncWithDesktop() ) { 1172 if ( mSyncManager->syncWithDesktop() ) {
1172 remote->resetPilotStat(1); 1173 remote->resetPilotStat(1);
1173 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1174 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1174 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 1175 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
1175 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 1176 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
1176 } else { 1177 } else {
1177 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 1178 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
1178 } 1179 }
1179 } 1180 }
1180 QDateTime modifiedCalendar = mLastCalendarSync; 1181 QDateTime modifiedCalendar = mLastCalendarSync;
1181 eventLSync = getLastSyncEvent(); 1182 eventLSync = getLastSyncEvent();
1182 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 1183 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
1183 if ( eventR ) { 1184 if ( eventR ) {
1184 eventRSync = (Event*) eventR->clone(); 1185 eventRSync = (Event*) eventR->clone();
1185 remote->deleteEvent(eventR ); 1186 remote->deleteEvent(eventR );
1186 1187
1187 } else { 1188 } else {
1188 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 1189 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
1189 eventRSync = (Event*)eventLSync->clone(); 1190 eventRSync = (Event*)eventLSync->clone();
1190 } else { 1191 } else {
1191 fullDateRange = true; 1192 fullDateRange = true;
1192 eventRSync = new Event(); 1193 eventRSync = new Event();
1193 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 1194 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
1194 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 1195 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
1195 eventRSync->setDtStart( mLastCalendarSync ); 1196 eventRSync->setDtStart( mLastCalendarSync );
1196 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1197 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1197 eventRSync->setCategories( i18n("SyncEvent") ); 1198 eventRSync->setCategories( i18n("SyncEvent") );
1198 } 1199 }
1199 } 1200 }
1200 if ( eventLSync->dtStart() == mLastCalendarSync ) 1201 if ( eventLSync->dtStart() == mLastCalendarSync )
1201 fullDateRange = true; 1202 fullDateRange = true;
1202 1203
1203 if ( ! fullDateRange ) { 1204 if ( ! fullDateRange ) {
1204 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 1205 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
1205 1206
1206 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 1207 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
1207 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 1208 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
1208 fullDateRange = true; 1209 fullDateRange = true;
1209 } 1210 }
1210 } 1211 }
1211 if ( mSyncManager->syncWithDesktop() ) { 1212 if ( mSyncManager->syncWithDesktop() ) {
1212 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 1213 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
1213 } 1214 }
1214 if ( fullDateRange ) 1215 if ( fullDateRange )
1215 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 1216 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
1216 else 1217 else
1217 mLastCalendarSync = eventLSync->dtStart(); 1218 mLastCalendarSync = eventLSync->dtStart();
1218 // for resyncing if own file has changed 1219 // for resyncing if own file has changed
1219 if ( mCurrentSyncDevice == "deleteaftersync" ) { 1220 if ( mCurrentSyncDevice == "deleteaftersync" ) {
1220 mLastCalendarSync = loadedFileVersion; 1221 mLastCalendarSync = loadedFileVersion;
1221 //qDebug("setting mLastCalendarSync "); 1222 //qDebug("setting mLastCalendarSync ");
1222 } 1223 }
1223 //qDebug("*************************** "); 1224 //qDebug("*************************** ");
1224 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1225 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1225 QPtrList<Incidence> er = remote->rawIncidences(); 1226 QPtrList<Incidence> er = remote->rawIncidences();
1226 Incidence* inR = er.first(); 1227 Incidence* inR = er.first();
1227 Incidence* inL; 1228 Incidence* inL;
1228 QProgressBar bar( er.count(),0 ); 1229 QProgressBar bar( er.count(),0 );
1229 bar.setCaption (i18n("Syncing - close to abort!") ); 1230 bar.setCaption (i18n("Syncing - close to abort!") );
1230 1231
1231 // ************** setting up filter ************* 1232 // ************** setting up filter *************
1232 CalFilter *filterIN = 0; 1233 CalFilter *filterIN = 0;
1233 CalFilter *filterOUT = 0; 1234 CalFilter *filterOUT = 0;
1234 CalFilter *filter = mFilters.first(); 1235 CalFilter *filter = mFilters.first();
1235 while(filter) { 1236 while(filter) {
1236 if ( filter->name() == mSyncManager->mFilterInCal ) 1237 if ( filter->name() == mSyncManager->mFilterInCal )
1237 filterIN = filter; 1238 filterIN = filter;
1238 if ( filter->name() == mSyncManager->mFilterOutCal ) 1239 if ( filter->name() == mSyncManager->mFilterOutCal )
1239 filterOUT = filter; 1240 filterOUT = filter;
1240 filter = mFilters.next(); 1241 filter = mFilters.next();
1241 } 1242 }
1242 int w = 300; 1243 int w = 300;
1243 if ( QApplication::desktop()->width() < 320 ) 1244 if ( QApplication::desktop()->width() < 320 )
1244 w = 220; 1245 w = 220;
1245 int h = bar.sizeHint().height() ; 1246 int h = bar.sizeHint().height() ;
1246 int dw = QApplication::desktop()->width(); 1247 int dw = QApplication::desktop()->width();
1247 int dh = QApplication::desktop()->height(); 1248 int dh = QApplication::desktop()->height();
1248 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1249 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1249 bar.show(); 1250 bar.show();
1250 int modulo = (er.count()/10)+1; 1251 int modulo = (er.count()/10)+1;
1251 int incCounter = 0; 1252 int incCounter = 0;
1252 while ( inR ) { 1253 while ( inR ) {
1253 if ( ! bar.isVisible() ) 1254 if ( ! bar.isVisible() )
1254 return false; 1255 return false;
1255 if ( incCounter % modulo == 0 ) 1256 if ( incCounter % modulo == 0 )
1256 bar.setProgress( incCounter ); 1257 bar.setProgress( incCounter );
1257 ++incCounter; 1258 ++incCounter;
1258 uid = inR->uid(); 1259 uid = inR->uid();
1259 bool skipIncidence = false; 1260 bool skipIncidence = false;
1260 if ( uid.left(15) == QString("last-syncEvent-") ) 1261 if ( uid.left(15) == QString("last-syncEvent-") )
1261 skipIncidence = true; 1262 skipIncidence = true;
1262 QString idS; 1263 QString idS;
1263 qApp->processEvents(); 1264 qApp->processEvents();
1264 if ( !skipIncidence ) { 1265 if ( !skipIncidence ) {
1265 inL = local->incidence( uid ); 1266 inL = local->incidence( uid );
1266 if ( inL ) { // maybe conflict - same uid in both calendars 1267 if ( inL ) { // maybe conflict - same uid in both calendars
1267 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1268 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1268 //qDebug("take %d %s ", take, inL->summary().latin1()); 1269 //qDebug("take %d %s ", take, inL->summary().latin1());
1269 if ( take == 3 ) 1270 if ( take == 3 )
1270 return false; 1271 return false;
1271 if ( take == 1 ) {// take local ********************** 1272 if ( take == 1 ) {// take local **********************
1272 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1273 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1273 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1274 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1274 else 1275 else
1275 idS = inR->IDStr(); 1276 idS = inR->IDStr();
1276 remote->deleteIncidence( inR ); 1277 remote->deleteIncidence( inR );
1277 inR = inL->clone(); 1278 inR = inL->clone();
1278 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1279 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1279 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1280 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1280 inR->setIDStr( idS ); 1281 inR->setIDStr( idS );
1281 remote->addIncidence( inR ); 1282 remote->addIncidence( inR );
1282 if ( mSyncManager->syncWithDesktop() ) 1283 if ( mSyncManager->syncWithDesktop() )
1283 inR->setPilotId( 2 ); 1284 inR->setPilotId( 2 );
1284 ++changedRemote; 1285 ++changedRemote;
1285 } else {// take remote ********************** 1286 } else {// take remote **********************
1286 idS = inL->IDStr(); 1287 idS = inL->IDStr();
1287 int pid = inL->pilotId(); 1288 int pid = inL->pilotId();
1288 local->deleteIncidence( inL ); 1289 local->deleteIncidence( inL );
1289 inL = inR->clone(); 1290 inL = inR->clone();
1290 if ( mSyncManager->syncWithDesktop() ) 1291 if ( mSyncManager->syncWithDesktop() )
1291 inL->setPilotId( pid ); 1292 inL->setPilotId( pid );
1292 inL->setIDStr( idS ); 1293 inL->setIDStr( idS );
1293 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1294 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1294 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1295 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1295 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1296 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1296 } 1297 }
1297 local->addIncidence( inL ); 1298 local->addIncidence( inL );
1298 ++changedLocal; 1299 ++changedLocal;
1299 } 1300 }
1300 } 1301 }
1301 } else { // no conflict ********** add or delete remote 1302 } else { // no conflict ********** add or delete remote
1302 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1303 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1303 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1304 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1304 QString des = eventLSync->description(); 1305 QString des = eventLSync->description();
1305 QString pref = "e"; 1306 QString pref = "e";
1306 if ( inR->typeID() == todoID ) 1307 if ( inR->typeID() == todoID )
1307 pref = "t"; 1308 pref = "t";
1308 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1309 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1309 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1310 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1310 //remote->deleteIncidence( inR ); 1311 //remote->deleteIncidence( inR );
1311 ++deletedEventR; 1312 ++deletedEventR;
1312 } else { 1313 } else {
1313 inR->setLastModified( modifiedCalendar ); 1314 inR->setLastModified( modifiedCalendar );
1314 inL = inR->clone(); 1315 inL = inR->clone();
1315 inL->setIDStr( ":" ); 1316 inL->setIDStr( ":" );
1316 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1317 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1317 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1318 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1318 local->addIncidence( inL ); 1319 local->addIncidence( inL );
1319 ++addedEvent; 1320 ++addedEvent;
1320 1321
1321 } 1322 }
1322 } else { 1323 } else {
1323 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1324 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1324 inR->setLastModified( modifiedCalendar ); 1325 inR->setLastModified( modifiedCalendar );
1325 inL = inR->clone(); 1326 inL = inR->clone();
1326 inL->setIDStr( ":" ); 1327 inL->setIDStr( ":" );
1327 local->addIncidence( inL ); 1328 local->addIncidence( inL );
1328 ++addedEvent; 1329 ++addedEvent;
1329 1330
1330 } else { 1331 } else {
1331 checkExternSyncEvent(eventRSyncSharp, inR); 1332 checkExternSyncEvent(eventRSyncSharp, inR);
1332 remote->deleteIncidence( inR ); 1333 remote->deleteIncidence( inR );
1333 ++deletedEventR; 1334 ++deletedEventR;
1334 } 1335 }
1335 } 1336 }
1336 } else { 1337 } else {
1337 ++filteredIN; 1338 ++filteredIN;
1338 } 1339 }
1339 } 1340 }
1340 } 1341 }
1341 inR = er.next(); 1342 inR = er.next();
1342 } 1343 }
1343 QPtrList<Incidence> el = local->rawIncidences(); 1344 QPtrList<Incidence> el = local->rawIncidences();
1344 inL = el.first(); 1345 inL = el.first();
1345 modulo = (el.count()/10)+1; 1346 modulo = (el.count()/10)+1;
1346 bar.setCaption (i18n("Add / remove events") ); 1347 bar.setCaption (i18n("Add / remove events") );
1347 bar.setTotalSteps ( el.count() ) ; 1348 bar.setTotalSteps ( el.count() ) ;
1348 bar.show(); 1349 bar.show();
1349 incCounter = 0; 1350 incCounter = 0;
1350 1351
1351 while ( inL ) { 1352 while ( inL ) {
1352 1353
1353 qApp->processEvents(); 1354 qApp->processEvents();
1354 if ( ! bar.isVisible() ) 1355 if ( ! bar.isVisible() )
1355 return false; 1356 return false;
1356 if ( incCounter % modulo == 0 ) 1357 if ( incCounter % modulo == 0 )
1357 bar.setProgress( incCounter ); 1358 bar.setProgress( incCounter );
1358 ++incCounter; 1359 ++incCounter;
1359 uid = inL->uid(); 1360 uid = inL->uid();
1360 bool skipIncidence = false; 1361 bool skipIncidence = false;
1361 if ( uid.left(15) == QString("last-syncEvent-") ) 1362 if ( uid.left(15) == QString("last-syncEvent-") )
1362 skipIncidence = true; 1363 skipIncidence = true;
1363 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) 1364 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID )
1364 skipIncidence = true; 1365 skipIncidence = true;
1365 if ( !skipIncidence ) { 1366 if ( !skipIncidence ) {
1366 inR = remote->incidence( uid ); 1367 inR = remote->incidence( uid );
1367 if ( ! inR ) { 1368 if ( ! inR ) {
1368 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1369 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1369 // no conflict ********** add or delete local 1370 // no conflict ********** add or delete local
1370 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1371 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1371 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1372 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1372 checkExternSyncEvent(eventLSyncSharp, inL); 1373 checkExternSyncEvent(eventLSyncSharp, inL);
1373 local->deleteIncidence( inL ); 1374 local->deleteIncidence( inL );
1374 ++deletedEventL; 1375 ++deletedEventL;
1375 } else { 1376 } else {
1376 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1377 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1377 inL->removeID(mCurrentSyncDevice ); 1378 inL->removeID(mCurrentSyncDevice );
1378 ++addedEventR; 1379 ++addedEventR;
1379 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1380 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1380 inL->setLastModified( modifiedCalendar ); 1381 inL->setLastModified( modifiedCalendar );
1381 inR = inL->clone(); 1382 inR = inL->clone();
1382 inR->setIDStr( ":" ); 1383 inR->setIDStr( ":" );
1383 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1384 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1384 remote->addIncidence( inR ); 1385 remote->addIncidence( inR );
1385 } 1386 }
1386 } 1387 }
1387 } else { 1388 } else {
1388 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1389 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1389 checkExternSyncEvent(eventLSyncSharp, inL); 1390 checkExternSyncEvent(eventLSyncSharp, inL);
1390 local->deleteIncidence( inL ); 1391 local->deleteIncidence( inL );
1391 ++deletedEventL; 1392 ++deletedEventL;
1392 } else { 1393 } else {
1393 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1394 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1394 ++addedEventR; 1395 ++addedEventR;
1395 inL->setLastModified( modifiedCalendar ); 1396 inL->setLastModified( modifiedCalendar );
1396 inR = inL->clone(); 1397 inR = inL->clone();
1397 inR->setIDStr( ":" ); 1398 inR->setIDStr( ":" );
1398 remote->addIncidence( inR ); 1399 remote->addIncidence( inR );
1399 } 1400 }
1400 } 1401 }
1401 } 1402 }
1402 } else { 1403 } else {
1403 ++filteredOUT; 1404 ++filteredOUT;
1404 } 1405 }
1405 } 1406 }
1406 } 1407 }
1407 inL = el.next(); 1408 inL = el.next();
1408 } 1409 }
1409 int delFut = 0; 1410 int delFut = 0;
1410 int remRem = 0; 1411 int remRem = 0;
1411 if ( mSyncManager->mWriteBackInFuture ) { 1412 if ( mSyncManager->mWriteBackInFuture ) {
1412 er = remote->rawIncidences(); 1413 er = remote->rawIncidences();
1413 remRem = er.count(); 1414 remRem = er.count();
1414 inR = er.first(); 1415 inR = er.first();
1415 QDateTime dt; 1416 QDateTime dt;
1416 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1417 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1417 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1418 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1418 while ( inR ) { 1419 while ( inR ) {
1419 if ( inR->typeID() == todoID ) { 1420 if ( inR->typeID() == todoID ) {
1420 Todo * t = (Todo*)inR; 1421 Todo * t = (Todo*)inR;
1421 if ( t->hasDueDate() ) 1422 if ( t->hasDueDate() )
1422 dt = t->dtDue(); 1423 dt = t->dtDue();
1423 else 1424 else
1424 dt = cur.addSecs( 62 ); 1425 dt = cur.addSecs( 62 );
1425 } 1426 }
1426 else if (inR->typeID() == eventID ) { 1427 else if (inR->typeID() == eventID ) {
1427 bool ok; 1428 bool ok;
1428 dt = inR->getNextOccurence( cur, &ok ); 1429 dt = inR->getNextOccurence( cur, &ok );
1429 if ( !ok ) 1430 if ( !ok )
1430 dt = cur.addSecs( -62 ); 1431 dt = cur.addSecs( -62 );
1431 } 1432 }
1432 else 1433 else
1433 dt = inR->dtStart(); 1434 dt = inR->dtStart();
1434 if ( dt < cur || dt > end ) { 1435 if ( dt < cur || dt > end ) {
1435 remote->deleteIncidence( inR ); 1436 remote->deleteIncidence( inR );
1436 ++delFut; 1437 ++delFut;
1437 } 1438 }
1438 inR = er.next(); 1439 inR = er.next();
1439 } 1440 }
1440 } 1441 }
1441 bar.hide(); 1442 bar.hide();
1442 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1443 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1443 eventLSync->setReadOnly( false ); 1444 eventLSync->setReadOnly( false );
1444 eventLSync->setDtStart( mLastCalendarSync ); 1445 eventLSync->setDtStart( mLastCalendarSync );
1445 eventRSync->setDtStart( mLastCalendarSync ); 1446 eventRSync->setDtStart( mLastCalendarSync );
1446 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1447 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1447 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1448 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1448 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1449 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1449 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1450 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1450 eventLSync->setReadOnly( true ); 1451 eventLSync->setReadOnly( true );
1451 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1452 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1452 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1453 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1453 remote->addEvent( eventRSync ); 1454 remote->addEvent( eventRSync );
1454 else 1455 else
1455 delete eventRSync; 1456 delete eventRSync;
1456 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1457 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1457 QString mes; 1458 QString mes;
1458 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT ); 1459 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT );
1459 QString delmess; 1460 QString delmess;
1460 if ( delFut ) { 1461 if ( delFut ) {
1461 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut); 1462 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut);
1462 mes += delmess; 1463 mes += delmess;
1463 } 1464 }
1464 mes = i18n("Local calendar changed!\n") +mes; 1465 mes = i18n("Local calendar changed!\n") +mes;
1465 mCalendar->checkAlarmForIncidence( 0, true ); 1466 mCalendar->checkAlarmForIncidence( 0, true );
1466 qDebug( mes ); 1467 qDebug( mes );
1467 if ( mSyncManager->mShowSyncSummary ) { 1468 if ( mSyncManager->mShowSyncSummary ) {
1468 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1469 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1469 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1470 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1470 qDebug("KO: WB cancelled "); 1471 qDebug("KO: WB cancelled ");
1471 mSyncManager->mWriteBackFile = false; 1472 mSyncManager->mWriteBackFile = false;
1472 return syncOK; 1473 return syncOK;
1473 } 1474 }
1474 } 1475 }
1475 return syncOK; 1476 return syncOK;
1476} 1477}
1477 1478
1478void CalendarView::setSyncDevice( QString s ) 1479void CalendarView::setSyncDevice( QString s )
1479{ 1480{
1480 mCurrentSyncDevice= s; 1481 mCurrentSyncDevice= s;
1481} 1482}
1482void CalendarView::setSyncName( QString s ) 1483void CalendarView::setSyncName( QString s )
1483{ 1484{
1484 mCurrentSyncName= s; 1485 mCurrentSyncName= s;
1485} 1486}
1486bool CalendarView::syncCalendar(QString filename, int mode) 1487bool CalendarView::syncCalendar(QString filename, int mode)
1487{ 1488{
1488 //qDebug("syncCalendar %s ", filename.latin1()); 1489 //qDebug("syncCalendar %s ", filename.latin1());
1489 mGlobalSyncMode = SYNC_MODE_NORMAL; 1490 mGlobalSyncMode = SYNC_MODE_NORMAL;
1490 CalendarLocal* calendar = new CalendarLocal(); 1491 CalendarLocal* calendar = new CalendarLocal();
1491 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1492 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1492 FileStorage* storage = new FileStorage( calendar ); 1493 FileStorage* storage = new FileStorage( calendar );
1493 bool syncOK = false; 1494 bool syncOK = false;
1494 storage->setFileName( filename ); 1495 storage->setFileName( filename );
1495 // qDebug("loading ... "); 1496 // qDebug("loading ... ");
1496 if ( storage->load() ) { 1497 if ( storage->load() ) {
1497 getEventViewerDialog()->setSyncMode( true ); 1498 getEventViewerDialog()->setSyncMode( true );
1498 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1499 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1499 getEventViewerDialog()->setSyncMode( false ); 1500 getEventViewerDialog()->setSyncMode( false );
1500 if ( syncOK ) { 1501 if ( syncOK ) {
1501 if ( mSyncManager->mWriteBackFile ) 1502 if ( mSyncManager->mWriteBackFile )
1502 { 1503 {
1503 storage->setSaveFormat( new ICalFormat() ); 1504 storage->setSaveFormat( new ICalFormat() );
1504 storage->save(); 1505 storage->save();
1505 } 1506 }
1506 } 1507 }
1507 setModified( true ); 1508 setModified( true );
1508 } 1509 }
1509 delete storage; 1510 delete storage;
1510 delete calendar; 1511 delete calendar;
1511 if ( syncOK ) 1512 if ( syncOK )
1512 updateView(); 1513 updateView();
1513 return syncOK; 1514 return syncOK;
1514} 1515}
1515 1516
1516void CalendarView::syncExternal( int mode ) 1517void CalendarView::syncExternal( int mode )
1517{ 1518{
1518 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1519 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1519 1520
1520 qApp->processEvents(); 1521 qApp->processEvents();
1521 CalendarLocal* calendar = new CalendarLocal(); 1522 CalendarLocal* calendar = new CalendarLocal();
1522 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1523 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1523 bool syncOK = false; 1524 bool syncOK = false;
1524 bool loadSuccess = false; 1525 bool loadSuccess = false;
1525 PhoneFormat* phoneFormat = 0; 1526 PhoneFormat* phoneFormat = 0;
1526 emit tempDisableBR(true); 1527 emit tempDisableBR(true);
1527#ifndef DESKTOP_VERSION 1528#ifndef DESKTOP_VERSION
1528 SharpFormat* sharpFormat = 0; 1529 SharpFormat* sharpFormat = 0;
1529 if ( mode == 0 ) { // sharp 1530 if ( mode == 0 ) { // sharp
1530 sharpFormat = new SharpFormat () ; 1531 sharpFormat = new SharpFormat () ;
1531 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1532 loadSuccess = sharpFormat->load( calendar, mCalendar );
1532 1533
1533 } else 1534 } else
1534#endif 1535#endif
1535 if ( mode == 1 ) { // phone 1536 if ( mode == 1 ) { // phone
1536 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1537 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1537 mSyncManager->mPhoneDevice, 1538 mSyncManager->mPhoneDevice,
1538 mSyncManager->mPhoneConnection, 1539 mSyncManager->mPhoneConnection,
1539 mSyncManager->mPhoneModel); 1540 mSyncManager->mPhoneModel);
1540 loadSuccess = phoneFormat->load( calendar,mCalendar); 1541 loadSuccess = phoneFormat->load( calendar,mCalendar);
1541 1542
1542 } else { 1543 } else {
1543 emit tempDisableBR(false); 1544 emit tempDisableBR(false);
1544 return; 1545 return;
1545 } 1546 }
1546 if ( loadSuccess ) { 1547 if ( loadSuccess ) {
1547 getEventViewerDialog()->setSyncMode( true ); 1548 getEventViewerDialog()->setSyncMode( true );
1548 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1549 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1549 getEventViewerDialog()->setSyncMode( false ); 1550 getEventViewerDialog()->setSyncMode( false );
1550 qApp->processEvents(); 1551 qApp->processEvents();
1551 if ( syncOK ) { 1552 if ( syncOK ) {
1552 if ( mSyncManager->mWriteBackFile ) 1553 if ( mSyncManager->mWriteBackFile )
1553 { 1554 {
1554 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1555 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1555 Incidence* inc = iL.first(); 1556 Incidence* inc = iL.first();
1556 if ( phoneFormat ) { 1557 if ( phoneFormat ) {
1557 while ( inc ) { 1558 while ( inc ) {
1558 inc->removeID(mCurrentSyncDevice); 1559 inc->removeID(mCurrentSyncDevice);
1559 inc = iL.next(); 1560 inc = iL.next();
1560 } 1561 }
1561 } 1562 }
1562#ifndef DESKTOP_VERSION 1563#ifndef DESKTOP_VERSION
1563 if ( sharpFormat ) 1564 if ( sharpFormat )
1564 sharpFormat->save(calendar); 1565 sharpFormat->save(calendar);
1565#endif 1566#endif
1566 if ( phoneFormat ) 1567 if ( phoneFormat )
1567 phoneFormat->save(calendar); 1568 phoneFormat->save(calendar);
1568 iL = calendar->rawIncidences(); 1569 iL = calendar->rawIncidences();
1569 inc = iL.first(); 1570 inc = iL.first();
1570 Incidence* loc; 1571 Incidence* loc;
1571 while ( inc ) { 1572 while ( inc ) {
1572 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1573 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1573 loc = mCalendar->incidence(inc->uid() ); 1574 loc = mCalendar->incidence(inc->uid() );
1574 if ( loc ) { 1575 if ( loc ) {
1575 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1576 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1576 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1577 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1577 } 1578 }
1578 } 1579 }
1579 inc = iL.next(); 1580 inc = iL.next();
1580 } 1581 }
1581 Incidence* lse = getLastSyncEvent(); 1582 Incidence* lse = getLastSyncEvent();
1582 if ( lse ) { 1583 if ( lse ) {
1583 lse->setReadOnly( false ); 1584 lse->setReadOnly( false );
1584 lse->setDescription( "" ); 1585 lse->setDescription( "" );
1585 lse->setReadOnly( true ); 1586 lse->setReadOnly( true );
1586 } 1587 }
1587 } 1588 }
1588 } else { 1589 } else {
1589 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1590 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1590 } 1591 }
1591 setModified( true ); 1592 setModified( true );
1592 } else { 1593 } else {
1593 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1594 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1594 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1595 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1595 question, i18n("Ok")) ; 1596 question, i18n("Ok")) ;
1596 1597
1597 } 1598 }
1598 delete calendar; 1599 delete calendar;
1599 updateView(); 1600 updateView();
1600 emit tempDisableBR(false); 1601 emit tempDisableBR(false);
1601 return ;//syncOK; 1602 return ;//syncOK;
1602 1603
1603} 1604}
1604 1605
1605bool CalendarView::importBday() 1606bool CalendarView::importBday()
1606{ 1607{
1607#ifndef KORG_NOKABC 1608#ifndef KORG_NOKABC
1608 1609
1609#ifdef DESKTOP_VERSION 1610#ifdef DESKTOP_VERSION
1610 int curCal = mCalendar->defaultCalendar(); 1611 int curCal = mCalendar->defaultCalendar();
1611 int bd = mCalEditView->getBirtdayID(); 1612 int bd = mCalEditView->getBirtdayID();
1612 if ( bd == 0 ) 1613 if ( bd == 0 )
1613 return false; 1614 return false;
1614 mCalendar->setDefaultCalendar( bd ); 1615 mCalendar->setDefaultCalendar( bd );
1615 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1616 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1616 KABC::AddressBook::Iterator it; 1617 KABC::AddressBook::Iterator it;
1617 int count = 0; 1618 int count = 0;
1618 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1619 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1619 ++count; 1620 ++count;
1620 } 1621 }
1621 QProgressBar bar(count,0 ); 1622 QProgressBar bar(count,0 );
1622 int w = 300; 1623 int w = 300;
1623 if ( QApplication::desktop()->width() < 320 ) 1624 if ( QApplication::desktop()->width() < 320 )
1624 w = 220; 1625 w = 220;
1625 int h = bar.sizeHint().height() ; 1626 int h = bar.sizeHint().height() ;
1626 int dw = QApplication::desktop()->width(); 1627 int dw = QApplication::desktop()->width();
1627 int dh = QApplication::desktop()->height(); 1628 int dh = QApplication::desktop()->height();
1628 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1629 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1629 bar.show(); 1630 bar.show();
1630 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1631 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1631 qApp->processEvents(); 1632 qApp->processEvents();
1632 count = 0; 1633 count = 0;
1633 int addCount = 0; 1634 int addCount = 0;
1634 KCal::Attendee* a = 0; 1635 KCal::Attendee* a = 0;
1635 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1636 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1636 if ( ! bar.isVisible() ) 1637 if ( ! bar.isVisible() )
1637 return false; 1638 return false;
1638 bar.setProgress( count++ ); 1639 bar.setProgress( count++ );
1639 qApp->processEvents(); 1640 qApp->processEvents();
1640 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1641 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1641 if ( (*it).birthday().date().isValid() ){ 1642 if ( (*it).birthday().date().isValid() ){
1642 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1643 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1643 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1644 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1644 ++addCount; 1645 ++addCount;
1645 } 1646 }
1646 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1647 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1647 if ( anni.isValid() ){ 1648 if ( anni.isValid() ){
1648 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1649 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1649 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1650 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1650 ++addCount; 1651 ++addCount;
1651 } 1652 }
1652 } 1653 }
1653 mCalendar->setDefaultCalendar( curCal ); 1654 mCalendar->setDefaultCalendar( curCal );
1654 updateView(); 1655 updateView();
1655 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1656 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1656#else //DESKTOP_VERSION 1657#else //DESKTOP_VERSION
1657 1658
1658 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1659 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1659 // the result should now arrive through method insertBirthdays 1660 // the result should now arrive through method insertBirthdays
1660 1661
1661#endif //DESKTOP_VERSION 1662#endif //DESKTOP_VERSION
1662 1663
1663#endif //KORG_NOKABC 1664#endif //KORG_NOKABC
1664 1665
1665 1666
1666 return true; 1667 return true;
1667} 1668}
1668 1669
1669// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1670// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1670void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1671void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1671 const QStringList& anniversaryList, const QStringList& realNameList, 1672 const QStringList& anniversaryList, const QStringList& realNameList,
1672 const QStringList& emailList, const QStringList& assembledNameList, 1673 const QStringList& emailList, const QStringList& assembledNameList,
1673 const QStringList& uidList) 1674 const QStringList& uidList)
1674{ 1675{
1675 1676
1676 //qDebug("KO::CalendarView::insertBirthdays"); 1677 //qDebug("KO::CalendarView::insertBirthdays");
1677 if (uid == this->name()) 1678 if (uid == this->name())
1678 { 1679 {
1679 int curCal = mCalendar->defaultCalendar(); 1680 int curCal = mCalendar->defaultCalendar();
1680 int bd = mCalEditView->getBirtdayID(); 1681 int bd = mCalEditView->getBirtdayID();
1681 if ( bd == 0 ) 1682 if ( bd == 0 )
1682 return; 1683 return;
1683 mCalendar->setDefaultCalendar( bd ); 1684 mCalendar->setDefaultCalendar( bd );
1684 1685
1685 1686
1686 int count = birthdayList.count(); 1687 int count = birthdayList.count();
1687 int addCount = 0; 1688 int addCount = 0;
1688 KCal::Attendee* a = 0; 1689 KCal::Attendee* a = 0;
1689 1690
1690 //qDebug("CalView 1 %i", count); 1691 //qDebug("CalView 1 %i", count);
1691 1692
1692 QProgressBar bar(count,0 ); 1693 QProgressBar bar(count,0 );
1693 int w = 300; 1694 int w = 300;
1694 if ( QApplication::desktop()->width() < 320 ) 1695 if ( QApplication::desktop()->width() < 320 )
1695 w = 220; 1696 w = 220;
1696 int h = bar.sizeHint().height() ; 1697 int h = bar.sizeHint().height() ;
1697 int dw = QApplication::desktop()->width(); 1698 int dw = QApplication::desktop()->width();
1698 int dh = QApplication::desktop()->height(); 1699 int dh = QApplication::desktop()->height();
1699 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1700 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1700 bar.show(); 1701 bar.show();
1701 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1702 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1702 qApp->processEvents(); 1703 qApp->processEvents();
1703 1704
1704 QDate birthday; 1705 QDate birthday;
1705 QDate anniversary; 1706 QDate anniversary;
1706 QString realName; 1707 QString realName;
1707 QString email; 1708 QString email;
1708 QString assembledName; 1709 QString assembledName;
1709 QString uid; 1710 QString uid;
1710 bool ok = true; 1711 bool ok = true;
1711 for ( int i = 0; i < count; i++) 1712 for ( int i = 0; i < count; i++)
1712 { 1713 {
1713 if ( ! bar.isVisible() ) 1714 if ( ! bar.isVisible() )
1714 return; 1715 return;
1715 bar.setProgress( i ); 1716 bar.setProgress( i );
1716 qApp->processEvents(); 1717 qApp->processEvents();
1717 1718
1718 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1719 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1719 if (!ok) { 1720 if (!ok) {
1720 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1721 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1721 } 1722 }
1722 1723
1723 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1724 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1724 if (!ok) { 1725 if (!ok) {
1725 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1726 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1726 } 1727 }
1727 realName = realNameList[i]; 1728 realName = realNameList[i];
1728 email = emailList[i]; 1729 email = emailList[i];
1729 assembledName = assembledNameList[i]; 1730 assembledName = assembledNameList[i];
1730 uid = uidList[i]; 1731 uid = uidList[i];
1731 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); 1732 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() );
1732 1733
1733 if ( birthday.isValid() ){ 1734 if ( birthday.isValid() ){
1734 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1735 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1735 KCal::Attendee::ReqParticipant,uid) ; 1736 KCal::Attendee::ReqParticipant,uid) ;
1736 if ( addAnniversary( birthday, assembledName, a, true ) ) 1737 if ( addAnniversary( birthday, assembledName, a, true ) )
1737 ++addCount; 1738 ++addCount;
1738 } 1739 }
1739 1740
1740 if ( anniversary.isValid() ){ 1741 if ( anniversary.isValid() ){
1741 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1742 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1742 KCal::Attendee::ReqParticipant,uid) ; 1743 KCal::Attendee::ReqParticipant,uid) ;
1743 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1744 if ( addAnniversary( anniversary, assembledName, a, false ) )
1744 ++addCount; 1745 ++addCount;
1745 } 1746 }
1746 } 1747 }
1747 1748
1748 mCalendar->setDefaultCalendar( curCal ); 1749 mCalendar->setDefaultCalendar( curCal );
1749 updateView(); 1750 updateView();
1750 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1751 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1751 1752
1752 } 1753 }
1753 1754
1754} 1755}
1755 1756
1756 1757
1757 1758
1758bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1759bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1759{ 1760{
1760 //qDebug("addAnni "); 1761 //qDebug("addAnni ");
1761 Event * ev = new Event(); 1762 Event * ev = new Event();
1762 ev->setOrganizer(KOPrefs::instance()->email()); 1763 ev->setOrganizer(KOPrefs::instance()->email());
1763 if ( a ) { 1764 if ( a ) {
1764 ev->addAttendee( a ); 1765 ev->addAttendee( a );
1765 } 1766 }
1766 QString kind; 1767 QString kind;
1767 if ( birthday ) { 1768 if ( birthday ) {
1768 kind = i18n( "Birthday" ); 1769 kind = i18n( "Birthday" );
1769 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 1770 ev->setSummary( name + " (" + QString::number(date.year()) +")");
1770 } 1771 }
1771 else { 1772 else {
1772 kind = i18n( "Anniversary" ); 1773 kind = i18n( "Anniversary" );
1773 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 1774 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
1774 } 1775 }
1775 ev->setCategories( kind ); 1776 ev->setCategories( kind );
1776 ev->setDtStart( QDateTime(date) ); 1777 ev->setDtStart( QDateTime(date) );
1777 ev->setDtEnd( QDateTime(date) ); 1778 ev->setDtEnd( QDateTime(date) );
1778 ev->setFloats( true ); 1779 ev->setFloats( true );
1779 Recurrence * rec = ev->recurrence(); 1780 Recurrence * rec = ev->recurrence();
1780 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1781 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1781 rec->addYearlyNum( date.month() ); 1782 rec->addYearlyNum( date.month() );
1782 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1783 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1783 delete ev; 1784 delete ev;
1784 return false; 1785 return false;
1785 } 1786 }
1786 return true; 1787 return true;
1787 1788
1788} 1789}
1789bool CalendarView::importQtopia( const QString &categories, 1790bool CalendarView::importQtopia( const QString &categories,
1790 const QString &datebook, 1791 const QString &datebook,
1791 const QString &todolist ) 1792 const QString &todolist )
1792{ 1793{
1793 1794
1794 QtopiaFormat qtopiaFormat; 1795 QtopiaFormat qtopiaFormat;
1795 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1796 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1796 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1797 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1797 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1798 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1798 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1799 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1799 1800
1800 updateView(); 1801 updateView();
1801 return true; 1802 return true;
1802 1803
1803#if 0 1804#if 0
1804 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1805 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1805 mCurrentSyncDevice = "qtopia-XML"; 1806 mCurrentSyncDevice = "qtopia-XML";
1806 if ( mSyncManager->mAskForPreferences ) 1807 if ( mSyncManager->mAskForPreferences )
1807 edit_sync_options(); 1808 edit_sync_options();
1808 qApp->processEvents(); 1809 qApp->processEvents();
1809 CalendarLocal* calendar = new CalendarLocal(); 1810 CalendarLocal* calendar = new CalendarLocal();
1810 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1811 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1811 bool syncOK = false; 1812 bool syncOK = false;
1812 QtopiaFormat qtopiaFormat; 1813 QtopiaFormat qtopiaFormat;
1813 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1814 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1814 bool loadOk = true; 1815 bool loadOk = true;
1815 if ( !categories.isEmpty() ) 1816 if ( !categories.isEmpty() )
1816 loadOk = qtopiaFormat.load( calendar, categories ); 1817 loadOk = qtopiaFormat.load( calendar, categories );
1817 if ( loadOk && !datebook.isEmpty() ) 1818 if ( loadOk && !datebook.isEmpty() )
1818 loadOk = qtopiaFormat.load( calendar, datebook ); 1819 loadOk = qtopiaFormat.load( calendar, datebook );
1819 if ( loadOk && !todolist.isEmpty() ) 1820 if ( loadOk && !todolist.isEmpty() )
1820 loadOk = qtopiaFormat.load( calendar, todolist ); 1821 loadOk = qtopiaFormat.load( calendar, todolist );
1821 1822
1822 if ( loadOk ) { 1823 if ( loadOk ) {
1823 getEventViewerDialog()->setSyncMode( true ); 1824 getEventViewerDialog()->setSyncMode( true );
1824 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1825 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1825 getEventViewerDialog()->setSyncMode( false ); 1826 getEventViewerDialog()->setSyncMode( false );
1826 qApp->processEvents(); 1827 qApp->processEvents();
1827 if ( syncOK ) { 1828 if ( syncOK ) {
1828 if ( mSyncManager->mWriteBackFile ) 1829 if ( mSyncManager->mWriteBackFile )
1829 { 1830 {
1830 // write back XML file 1831 // write back XML file
1831 1832
1832 } 1833 }
1833 setModified( true ); 1834 setModified( true );
1834 } 1835 }
1835 } else { 1836 } else {
1836 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1837 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1837 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1838 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1838 question, i18n("Ok")) ; 1839 question, i18n("Ok")) ;
1839 } 1840 }
1840 delete calendar; 1841 delete calendar;
1841 updateView(); 1842 updateView();
1842 return syncOK; 1843 return syncOK;
1843 1844
1844 1845
1845#endif 1846#endif
1846 1847
1847} 1848}
1848 1849
1849void CalendarView::setSyncEventsReadOnly() 1850void CalendarView::setSyncEventsReadOnly()
1850{ 1851{
1851 mCalendar->setSyncEventsReadOnly(); 1852 mCalendar->setSyncEventsReadOnly();
1852} 1853}
1853 1854
1854bool CalendarView::loadCalendars() 1855bool CalendarView::loadCalendars()
1855{ 1856{
1856 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 1857 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
1857 KopiCalendarFile * cal = calendars.first(); 1858 KopiCalendarFile * cal = calendars.first();
1858 mCalendar->setDefaultCalendar( 1 ); 1859 mCalendar->setDefaultCalendar( 1 );
1859 openCalendar( MainWindow::defaultFileName(), false ); 1860 openCalendar( MainWindow::defaultFileName(), false );
1860 cal = calendars.next(); 1861 cal = calendars.next();
1861 while ( cal ) { 1862 while ( cal ) {
1862 addCalendar( cal ); 1863 addCalendar( cal );
1863 cal = calendars.next(); 1864 cal = calendars.next();
1864 } 1865 }
1865 restoreCalendarSettings(); 1866 restoreCalendarSettings();
1866 return true; 1867 return true;
1867} 1868}
1868bool CalendarView::restoreCalendarSettings() 1869bool CalendarView::restoreCalendarSettings()
1869{ 1870{
1870 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 1871 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
1871 KopiCalendarFile * cal = calendars.first(); 1872 KopiCalendarFile * cal = calendars.first();
1872 while ( cal ) { 1873 while ( cal ) {
1873 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); 1874 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled );
1874 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); 1875 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled );
1875 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); 1876 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly );
1876 if ( cal->isStandard ) 1877 if ( cal->isStandard )
1877 mCalendar->setDefaultCalendar( cal->mCalNumber ); 1878 mCalendar->setDefaultCalendar( cal->mCalNumber );
1878 cal = calendars.next(); 1879 cal = calendars.next();
1879 } 1880 }
1880 setSyncEventsReadOnly(); 1881 setSyncEventsReadOnly();
1881 mCalendar->reInitAlarmSettings(); 1882 mCalendar->reInitAlarmSettings();
1882 updateUnmanagedViews(); 1883 updateUnmanagedViews();
1883 updateView(); 1884 updateView();
1884 return true; 1885 return true;
1885} 1886}
1886void CalendarView::addCalendarId( int id ) 1887void CalendarView::addCalendarId( int id )
1887{ 1888{
1888 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); 1889 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id );
1889 addCalendar( cal ); 1890 addCalendar( cal );
1890} 1891}
1891bool CalendarView::addCalendar( KopiCalendarFile * cal ) 1892bool CalendarView::addCalendar( KopiCalendarFile * cal )
1892{ 1893{
1893 cal->mErrorOnLoad = false; 1894 cal->mErrorOnLoad = false;
1894 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { 1895 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) {
1895 cal->mLoadDt = QDateTime::currentDateTime(); 1896 cal->mLoadDt = QDateTime::currentDateTime();
1896 return true; 1897 return true;
1897 } 1898 }
1898 qDebug("KO: Error adding calendar file %1 ",cal->mFileName.latin1() ); 1899 qDebug("KO: Error adding calendar file %1 ",cal->mFileName.latin1() );
1899 KMessageBox::error(this,i18n("Error loading calendar file\n%1.").arg(cal->mFileName)); 1900 KMessageBox::error(this,i18n("Error loading calendar file\n%1.").arg(cal->mFileName));
1900 cal->mErrorOnLoad = true; 1901 cal->mErrorOnLoad = true;
1901 return false; 1902 return false;
1902} 1903}
1903bool CalendarView::openCalendar(QString filename, bool merge) 1904bool CalendarView::openCalendar(QString filename, bool merge)
1904{ 1905{
1905 1906
1906 if (filename.isEmpty()) { 1907 if (filename.isEmpty()) {
1907 return false; 1908 return false;
1908 } 1909 }
1909 1910
1910 if (!QFile::exists(filename)) { 1911 if (!QFile::exists(filename)) {
1911 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1912 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1912 return false; 1913 return false;
1913 } 1914 }
1914 1915
1915 globalFlagBlockAgenda = 1; 1916 globalFlagBlockAgenda = 1;
1916 clearAllViews(); 1917 clearAllViews();
1917 if (!merge) { 1918 if (!merge) {
1918 mViewManager->setDocumentId( filename ); 1919 mViewManager->setDocumentId( filename );
1919 mCalendar->close(); 1920 mCalendar->close();
1920 } 1921 }
1921 mStorage->setFileName( filename ); 1922 mStorage->setFileName( filename );
1922 1923
1923 if ( mStorage->load() ) { 1924 if ( mStorage->load() ) {
1924 if ( merge ) ;//setModified( true ); 1925 if ( merge ) ;//setModified( true );
1925 else { 1926 else {
1926 //setModified( true ); 1927 //setModified( true );
1927 mViewManager->setDocumentId( filename ); 1928 mViewManager->setDocumentId( filename );
1928 mDialogManager->setDocumentId( filename ); 1929 mDialogManager->setDocumentId( filename );
1929 mTodoList->setDocumentId( filename ); 1930 mTodoList->setDocumentId( filename );
1930 } 1931 }
1931 globalFlagBlockAgenda = 2; 1932 globalFlagBlockAgenda = 2;
1932 // if ( getLastSyncEvent() ) 1933 // if ( getLastSyncEvent() )
1933 // getLastSyncEvent()->setReadOnly( true ); 1934 // getLastSyncEvent()->setReadOnly( true );
1934 mCalendar->reInitAlarmSettings(); 1935 mCalendar->reInitAlarmSettings();
1935 setSyncEventsReadOnly(); 1936 setSyncEventsReadOnly();
1936 updateUnmanagedViews(); 1937 updateUnmanagedViews();
1937 updateView(); 1938 updateView();
1938 if ( filename != MainWindow::defaultFileName() ) { 1939 if ( filename != MainWindow::defaultFileName() ) {
1939 saveCalendar( MainWindow::defaultFileName() ); 1940 saveCalendar( MainWindow::defaultFileName() );
1940 } else { 1941 } else {
1941 QFileInfo finf ( MainWindow::defaultFileName()); 1942 QFileInfo finf ( MainWindow::defaultFileName());
1942 if ( finf.exists() ) { 1943 if ( finf.exists() ) {
1943 setLoadedFileVersion( finf.lastModified () ); 1944 setLoadedFileVersion( finf.lastModified () );
1944 } 1945 }
1945 } 1946 }
1946 return true; 1947 return true;
1947 } else { 1948 } else {
1948 // while failing to load, the calendar object could 1949 // while failing to load, the calendar object could
1949 // have become partially populated. Clear it out. 1950 // have become partially populated. Clear it out.
1950 if ( !merge ) { 1951 if ( !merge ) {
1951 mCalendar->close(); 1952 mCalendar->close();
1952 mViewManager->setDocumentId( filename ); 1953 mViewManager->setDocumentId( filename );
1953 mDialogManager->setDocumentId( filename ); 1954 mDialogManager->setDocumentId( filename );
1954 mTodoList->setDocumentId( filename ); 1955 mTodoList->setDocumentId( filename );
1955 } 1956 }
1956 1957
1957 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1958 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1958 1959
1959 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 1960 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
1960 globalFlagBlockAgenda = 2; 1961 globalFlagBlockAgenda = 2;
1961 mCalendar->reInitAlarmSettings(); 1962 mCalendar->reInitAlarmSettings();
1962 setSyncEventsReadOnly(); 1963 setSyncEventsReadOnly();
1963 updateUnmanagedViews(); 1964 updateUnmanagedViews();
1964 updateView(); 1965 updateView();
1965 } 1966 }
1966 return false; 1967 return false;
1967} 1968}
1968void CalendarView::showOpenError() 1969void CalendarView::showOpenError()
1969{ 1970{
1970 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 1971 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
1971} 1972}
1972void CalendarView::setLoadedFileVersion(QDateTime dt) 1973void CalendarView::setLoadedFileVersion(QDateTime dt)
1973{ 1974{
1974 loadedFileVersion = dt; 1975 loadedFileVersion = dt;
1975} 1976}
1976bool CalendarView::checkFileChanged(QString fn) 1977bool CalendarView::checkFileChanged(QString fn)
1977{ 1978{
1978 QFileInfo finf ( fn ); 1979 QFileInfo finf ( fn );
1979 if ( !finf.exists() ) 1980 if ( !finf.exists() )
1980 return true; 1981 return true;
1981 QDateTime dt = finf.lastModified (); 1982 QDateTime dt = finf.lastModified ();
1982 if ( dt <= loadedFileVersion ) 1983 if ( dt <= loadedFileVersion )
1983 return false; 1984 return false;
1984 return true; 1985 return true;
1985 1986
1986} 1987}
1987void CalendarView::watchSavedFile() 1988void CalendarView::watchSavedFile()
1988{ 1989{
1989 QFileInfo finf ( MainWindow::defaultFileName()); 1990 QFileInfo finf ( MainWindow::defaultFileName());
1990 if ( !finf.exists() ) 1991 if ( !finf.exists() )
1991 return; 1992 return;
1992 QDateTime dt = finf.lastModified (); 1993 QDateTime dt = finf.lastModified ();
1993 if ( dt < loadedFileVersion ) { 1994 if ( dt < loadedFileVersion ) {
1994 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 1995 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
1995 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 1996 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
1996 return; 1997 return;
1997 } 1998 }
1998 loadedFileVersion = dt; 1999 loadedFileVersion = dt;
1999} 2000}
2000bool CalendarView::checkAllFileVersions() 2001bool CalendarView::checkAllFileVersions()
2001{ 2002{
2002 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2003 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2003 KopiCalendarFile * cal = calendars.first(); 2004 KopiCalendarFile * cal = calendars.first();
2004 mCalendar->setDefaultCalendar( 1 ); 2005 mCalendar->setDefaultCalendar( 1 );
2005 mCalendar->setDefaultCalendarEnabledOnly(); 2006 mCalendar->setDefaultCalendarEnabledOnly();
2006 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2007 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2007 if ( !checkFileVersion(MainWindow::defaultFileName())) { 2008 if ( !checkFileVersion(MainWindow::defaultFileName())) {
2008 restoreCalendarSettings(); 2009 restoreCalendarSettings();
2009 return false; 2010 return false;
2010 } 2011 }
2011 } 2012 }
2012 cal = calendars.next(); 2013 cal = calendars.next();
2013 QDateTime storeTemp = loadedFileVersion; 2014 QDateTime storeTemp = loadedFileVersion;
2014 while ( cal ) { 2015 while ( cal ) {
2015 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2016 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2016 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2017 mCalendar->setDefaultCalendar( cal->mCalNumber );
2017 mCalendar->setDefaultCalendarEnabledOnly(); 2018 mCalendar->setDefaultCalendarEnabledOnly();
2018 loadedFileVersion = cal->mLoadDt.addSecs( 15 ); 2019 loadedFileVersion = cal->mLoadDt.addSecs( 15 );
2019 if ( !checkFileVersion(cal->mFileName )) { 2020 if ( !checkFileVersion(cal->mFileName )) {
2020 loadedFileVersion = storeTemp; 2021 loadedFileVersion = storeTemp;
2021 restoreCalendarSettings(); 2022 restoreCalendarSettings();
2022 return false; 2023 return false;
2023 } 2024 }
2024 } 2025 }
2025 cal = calendars.next(); 2026 cal = calendars.next();
2026 } 2027 }
2027 loadedFileVersion = storeTemp; 2028 loadedFileVersion = storeTemp;
2028 return true; 2029 return true;
2029} 2030}
2030bool CalendarView::checkFileVersion(QString fn) 2031bool CalendarView::checkFileVersion(QString fn)
2031{ 2032{
2032 QFileInfo finf ( fn ); 2033 QFileInfo finf ( fn );
2033 if ( !finf.exists() ) 2034 if ( !finf.exists() )
2034 return true; 2035 return true;
2035 QDateTime dt = finf.lastModified (); 2036 QDateTime dt = finf.lastModified ();
2036 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); 2037 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1());
2037 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); 2038 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1());
2038 if ( dt <= loadedFileVersion ) 2039 if ( dt <= loadedFileVersion )
2039 return true; 2040 return true;
2040 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\n on disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(fn).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , 2041 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\n on disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(fn).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
2041 i18n("KO/Pi Warning"),i18n("Overwrite"), 2042 i18n("KO/Pi Warning"),i18n("Overwrite"),
2042 i18n("Sync+save")); 2043 i18n("Sync+save"));
2043 2044
2044 if ( km == KMessageBox::Cancel ) 2045 if ( km == KMessageBox::Cancel )
2045 return false; 2046 return false;
2046 if ( km == KMessageBox::Yes ) 2047 if ( km == KMessageBox::Yes )
2047 return true; 2048 return true;
2048 2049
2049 setSyncDevice("deleteaftersync" ); 2050 setSyncDevice("deleteaftersync" );
2050 mSyncManager->mAskForPreferences = true; 2051 mSyncManager->mAskForPreferences = true;
2051 mSyncManager->mSyncAlgoPrefs = 3; 2052 mSyncManager->mSyncAlgoPrefs = 3;
2052 mSyncManager->mWriteBackFile = false; 2053 mSyncManager->mWriteBackFile = false;
2053 mSyncManager->mWriteBackExistingOnly = false; 2054 mSyncManager->mWriteBackExistingOnly = false;
2054 mSyncManager->mShowSyncSummary = false; 2055 mSyncManager->mShowSyncSummary = false;
2055 syncCalendar( fn, 3 ); 2056 syncCalendar( fn, 3 );
2056 Event * e = getLastSyncEvent(); 2057 Event * e = getLastSyncEvent();
2057 if ( e ) 2058 if ( e )
2058 mCalendar->deleteEvent( e ); 2059 mCalendar->deleteEvent( e );
2059 return true; 2060 return true;
2060} 2061}
2061bool CalendarView::saveCalendars() 2062bool CalendarView::saveCalendars()
2062{ 2063{
2063 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2064 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2064 KopiCalendarFile * cal = calendars.first(); 2065 KopiCalendarFile * cal = calendars.first();
2065 mCalendar->setDefaultCalendar( 1 ); 2066 mCalendar->setDefaultCalendar( 1 );
2066 mCalendar->setDefaultCalendarEnabledOnly(); 2067 mCalendar->setDefaultCalendarEnabledOnly();
2067 saveCalendar( MainWindow::defaultFileName() ); 2068 saveCalendar( MainWindow::defaultFileName() );
2068 cal = calendars.next(); 2069 cal = calendars.next();
2069 while ( cal ) { 2070 while ( cal ) {
2070 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2071 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2071 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2072 mCalendar->setDefaultCalendar( cal->mCalNumber );
2072 mCalendar->setDefaultCalendarEnabledOnly(); 2073 mCalendar->setDefaultCalendarEnabledOnly();
2073 if ( saveCalendar( cal->mFileName ) ) 2074 if ( saveCalendar( cal->mFileName ) )
2074 cal->mLoadDt = QDateTime::currentDateTime(); 2075 cal->mLoadDt = QDateTime::currentDateTime();
2075 } 2076 }
2076 cal = calendars.next(); 2077 cal = calendars.next();
2077 } 2078 }
2078 restoreCalendarSettings(); 2079 restoreCalendarSettings();
2079 return true; 2080 return true;
2080} 2081}
2081bool CalendarView::saveCalendar( QString filename ) 2082bool CalendarView::saveCalendar( QString filename )
2082{ 2083{
2083 2084
2084 // Store back all unsaved data into calendar object 2085 // Store back all unsaved data into calendar object
2085 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 2086 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
2086 if ( mViewManager->currentView() ) 2087 if ( mViewManager->currentView() )
2087 mViewManager->currentView()->flushView(); 2088 mViewManager->currentView()->flushView();
2088 2089
2089 2090
2090 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 2091 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
2091 mStorage->setSaveFormat( new ICalFormat() ); 2092 mStorage->setSaveFormat( new ICalFormat() );
2092 mStorage->setFileName( filename ); 2093 mStorage->setFileName( filename );
2093 bool success; 2094 bool success;
2094 success = mStorage->save(); 2095 success = mStorage->save();
2095 if ( !success ) { 2096 if ( !success ) {
2096 return false; 2097 return false;
2097 } 2098 }
2098 if ( filename == MainWindow::defaultFileName() ) { 2099 if ( filename == MainWindow::defaultFileName() ) {
2099 setLoadedFileVersion( lfv ); 2100 setLoadedFileVersion( lfv );
2100 watchSavedFile(); 2101 watchSavedFile();
2101 } 2102 }
2102 return true; 2103 return true;
2103} 2104}
2104 2105
2105void CalendarView::closeCalendar() 2106void CalendarView::closeCalendar()
2106{ 2107{
2107 2108
2108 // child windows no longer valid 2109 // child windows no longer valid
2109 clearAllViews(); 2110 clearAllViews();
2110 emit closingDown(); 2111 emit closingDown();
2111 2112
2112 mCalendar->close(); 2113 mCalendar->close();
2113 setModified(false); 2114 setModified(false);
2114 updateView(); 2115 updateView();
2115} 2116}
2116 2117
2117void CalendarView::archiveCalendar() 2118void CalendarView::archiveCalendar()
2118{ 2119{
2119 mDialogManager->showArchiveDialog(); 2120 mDialogManager->showArchiveDialog();
2120} 2121}
2121 2122
2122 2123
2123void CalendarView::readSettings() 2124void CalendarView::readSettings()
2124{ 2125{
2125 2126
2126 2127
2127 // mViewManager->showAgendaView(); 2128 // mViewManager->showAgendaView();
2128 QString str; 2129 QString str;
2129 //qDebug("CalendarView::readSettings() "); 2130 //qDebug("CalendarView::readSettings() ");
2130 // read settings from the KConfig, supplying reasonable 2131 // read settings from the KConfig, supplying reasonable
2131 // defaults where none are to be found 2132 // defaults where none are to be found
2132 KConfig *config = KOGlobals::config(); 2133 KConfig *config = KOGlobals::config();
2133#ifndef KORG_NOSPLITTER 2134#ifndef KORG_NOSPLITTER
2134 config->setGroup("KOrganizer Geometry"); 2135 config->setGroup("KOrganizer Geometry");
2135 2136
2136 QValueList<int> sizes = config->readIntListEntry("Separator1"); 2137 QValueList<int> sizes = config->readIntListEntry("Separator1");
2137 if (sizes.count() != 2) { 2138 if (sizes.count() != 2) {
2138 sizes << mDateNavigator->minimumSizeHint().width(); 2139 sizes << mDateNavigator->minimumSizeHint().width();
2139 sizes << 300; 2140 sizes << 300;
2140 } 2141 }
2141 mPanner->setSizes(sizes); 2142 mPanner->setSizes(sizes);
2142 2143
2143 sizes = config->readIntListEntry("Separator2"); 2144 sizes = config->readIntListEntry("Separator2");
2144 if ( ( mResourceView && sizes.count() == 4 ) || 2145 if ( ( mResourceView && sizes.count() == 4 ) ||
2145 ( !mResourceView && sizes.count() == 3 ) ) { 2146 ( !mResourceView && sizes.count() == 3 ) ) {
2146 mLeftSplitter->setSizes(sizes); 2147 mLeftSplitter->setSizes(sizes);
2147 } 2148 }
2148#endif 2149#endif
2149 globalFlagBlockAgenda = 1; 2150 globalFlagBlockAgenda = 1;
2150 mViewManager->showAgendaView(); 2151 mViewManager->showAgendaView();
2151 //mViewManager->readSettings( config ); 2152 //mViewManager->readSettings( config );
2152 mTodoList->restoreLayout(config,QString("Todo Layout")); 2153 mTodoList->restoreLayout(config,QString("Todo Layout"));
2153 readFilterSettings(config); 2154 readFilterSettings(config);
2154 2155
2155#ifdef DESKTOP_VERSION 2156#ifdef DESKTOP_VERSION
2156 config->setGroup("WidgetLayout"); 2157 config->setGroup("WidgetLayout");
2157 QStringList list; 2158 QStringList list;
2158 list = config->readListEntry("MainLayout"); 2159 list = config->readListEntry("MainLayout");
2159 int x,y,w,h; 2160 int x,y,w,h;
2160 if ( ! list.isEmpty() ) { 2161 if ( ! list.isEmpty() ) {
2161 x = list[0].toInt(); 2162 x = list[0].toInt();
2162 y = list[1].toInt(); 2163 y = list[1].toInt();
2163 w = list[2].toInt(); 2164 w = list[2].toInt();
2164 h = list[3].toInt(); 2165 h = list[3].toInt();
2165 KApplication::testCoords( &x,&y,&w,&h ); 2166 KApplication::testCoords( &x,&y,&w,&h );
2166 topLevelWidget()->setGeometry(x,y,w,h); 2167 topLevelWidget()->setGeometry(x,y,w,h);
2167 2168
2168 } else { 2169 } else {
2169 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 2170 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
2170 } 2171 }
2171 list = config->readListEntry("EditEventLayout"); 2172 list = config->readListEntry("EditEventLayout");
2172 if ( ! list.isEmpty() ) { 2173 if ( ! list.isEmpty() ) {
2173 x = list[0].toInt(); 2174 x = list[0].toInt();
2174 y = list[1].toInt(); 2175 y = list[1].toInt();
2175 w = list[2].toInt(); 2176 w = list[2].toInt();
2176 h = list[3].toInt(); 2177 h = list[3].toInt();
2177 KApplication::testCoords( &x,&y,&w,&h ); 2178 KApplication::testCoords( &x,&y,&w,&h );
2178 mEventEditor->setGeometry(x,y,w,h); 2179 mEventEditor->setGeometry(x,y,w,h);
2179 2180
2180 } 2181 }
2181 list = config->readListEntry("EditTodoLayout"); 2182 list = config->readListEntry("EditTodoLayout");
2182 if ( ! list.isEmpty() ) { 2183 if ( ! list.isEmpty() ) {
2183 x = list[0].toInt(); 2184 x = list[0].toInt();
2184 y = list[1].toInt(); 2185 y = list[1].toInt();
2185 w = list[2].toInt(); 2186 w = list[2].toInt();
2186 h = list[3].toInt(); 2187 h = list[3].toInt();
2187 KApplication::testCoords( &x,&y,&w,&h ); 2188 KApplication::testCoords( &x,&y,&w,&h );
2188 mTodoEditor->setGeometry(x,y,w,h); 2189 mTodoEditor->setGeometry(x,y,w,h);
2189 2190
2190 } 2191 }
2191 list = config->readListEntry("ViewerLayout"); 2192 list = config->readListEntry("ViewerLayout");
2192 if ( ! list.isEmpty() ) { 2193 if ( ! list.isEmpty() ) {
2193 x = list[0].toInt(); 2194 x = list[0].toInt();
2194 y = list[1].toInt(); 2195 y = list[1].toInt();
2195 w = list[2].toInt(); 2196 w = list[2].toInt();
2196 h = list[3].toInt(); 2197 h = list[3].toInt();
2197 KApplication::testCoords( &x,&y,&w,&h ); 2198 KApplication::testCoords( &x,&y,&w,&h );
2198 getEventViewerDialog()->setGeometry(x,y,w,h); 2199 getEventViewerDialog()->setGeometry(x,y,w,h);
2199 } 2200 }
2200#endif 2201#endif
2201 config->setGroup( "Views" ); 2202 config->setGroup( "Views" );
2202 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 2203 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
2203 2204
2204 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame"); 2205 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame");
2205 2206
2206 int resetval = 0; 2207 int resetval = 0;
2207 int maxVal = 0; 2208 int maxVal = 0;
2208 if (sizes.count() != 3) { 2209 if (sizes.count() != 3) {
2209 if ( KOPrefs::instance()->mVerticalScreen ) { 2210 if ( KOPrefs::instance()->mVerticalScreen ) {
2210 resetval = mDateNavigator->sizeHint().width()+2; 2211 resetval = mDateNavigator->sizeHint().width()+2;
2211 } else { 2212 } else {
2212 resetval = mDateNavigator->sizeHint().height()+2; 2213 resetval = mDateNavigator->sizeHint().height()+2;
2213 } 2214 }
2214 } 2215 }
2215 if ( resetval ) { 2216 if ( resetval ) {
2216 sizes.clear(); 2217 sizes.clear();
2217 if ( KOPrefs::instance()->mVerticalScreen ) { 2218 if ( KOPrefs::instance()->mVerticalScreen ) {
2218 maxVal = QApplication::desktop()->width() -10; 2219 maxVal = QApplication::desktop()->width() -10;
2219 } else { 2220 } else {
2220 maxVal = QApplication::desktop()->height()-10; 2221 maxVal = QApplication::desktop()->height()-10;
2221 } 2222 }
2222 sizes << resetval; 2223 sizes << resetval;
2223 if ( maxVal < resetval + resetval) 2224 if ( maxVal < resetval + resetval)
2224 resetval = maxVal - resetval; 2225 resetval = maxVal - resetval;
2225 sizes << resetval; 2226 sizes << resetval;
2226 sizes << 100; 2227 sizes << 100;
2227 } 2228 }
2228 mLeftFrame->setSizes(sizes); 2229 mLeftFrame->setSizes(sizes);
2229 sizes = config->readIntListEntry("Main Splitter Frame"); 2230 sizes = config->readIntListEntry("Main Splitter Frame");
2230 resetval = 0; 2231 resetval = 0;
2231 maxVal = 0; 2232 maxVal = 0;
2232 if (sizes.count() != 2) { 2233 if (sizes.count() != 2) {
2233 if ( !KOPrefs::instance()->mVerticalScreen ) { 2234 if ( !KOPrefs::instance()->mVerticalScreen ) {
2234 resetval = mDateNavigator->sizeHint().width()+2; 2235 resetval = mDateNavigator->sizeHint().width()+2;
2235 } else { 2236 } else {
2236 resetval = mDateNavigator->sizeHint().height()+2; 2237 resetval = mDateNavigator->sizeHint().height()+2;
2237 } 2238 }
2238 } 2239 }
2239 if ( resetval ) { 2240 if ( resetval ) {
2240 sizes.clear(); 2241 sizes.clear();
2241 if ( !KOPrefs::instance()->mVerticalScreen ) { 2242 if ( !KOPrefs::instance()->mVerticalScreen ) {
2242 maxVal = QApplication::desktop()->width() -10; 2243 maxVal = QApplication::desktop()->width() -10;
2243 } else { 2244 } else {
2244 maxVal = QApplication::desktop()->height()-10; 2245 maxVal = QApplication::desktop()->height()-10;
2245 } 2246 }
2246 sizes << resetval; 2247 sizes << resetval;
2247 if ( maxVal < resetval + resetval) 2248 if ( maxVal < resetval + resetval)
2248 resetval = maxVal - resetval; 2249 resetval = maxVal - resetval;
2249 sizes << resetval; 2250 sizes << resetval;
2250 } 2251 }
2251 mMainFrame->setSizes(sizes); 2252 mMainFrame->setSizes(sizes);
2252 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 2253 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
2253 else if ( dateCount == 7 ) mNavigator->selectWeek(); 2254 else if ( dateCount == 7 ) mNavigator->selectWeek();
2254 else mNavigator->selectDates( dateCount ); 2255 else mNavigator->selectDates( dateCount );
2255 // mViewManager->readSettings( config ); 2256 // mViewManager->readSettings( config );
2256 updateConfig(); 2257 updateConfig();
2257 globalFlagBlockAgenda = 2; 2258 globalFlagBlockAgenda = 2;
2258 mViewManager->readSettings( config ); 2259 mViewManager->readSettings( config );
2259 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) ); 2260 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) );
2260} 2261}
2261 2262
2262 2263
2263void CalendarView::writeSettings() 2264void CalendarView::writeSettings()
2264{ 2265{
2265 // kdDebug() << "CalendarView::writeSettings" << endl; 2266 // kdDebug() << "CalendarView::writeSettings" << endl;
2266 2267
2267 KConfig *config = KOGlobals::config(); 2268 KConfig *config = KOGlobals::config();
2268 2269
2269 mViewManager->writeSettings( config ); 2270 mViewManager->writeSettings( config );
2270 mTodoList->saveLayout(config,QString("Todo Layout")); 2271 mTodoList->saveLayout(config,QString("Todo Layout"));
2271 mDialogManager->writeSettings( config ); 2272 mDialogManager->writeSettings( config );
2272 //KOPrefs::instance()->usrWriteConfig(); 2273 //KOPrefs::instance()->usrWriteConfig();
2273 KOPrefs::instance()->writeConfig(); 2274 KOPrefs::instance()->writeConfig();
2274 2275
2275 writeFilterSettings(config); 2276 writeFilterSettings(config);
2276 config->setGroup( "AppRun" ); 2277 config->setGroup( "AppRun" );
2277 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 2278 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
2278 int days = dt.daysTo( QDate::currentDate() ); 2279 int days = dt.daysTo( QDate::currentDate() );
2279 dt = dt.addDays( days ); 2280 dt = dt.addDays( days );
2280 int secs = dt.secsTo( QDateTime::currentDateTime() ); 2281 int secs = dt.secsTo( QDateTime::currentDateTime() );
2281 config->writeEntry( "LatestProgramStopDays", days ); 2282 config->writeEntry( "LatestProgramStopDays", days );
2282 config->writeEntry( "LatestProgramStopSecs", secs ); 2283 config->writeEntry( "LatestProgramStopSecs", secs );
2283 //qDebug("KO: Writing stop time: %d ", secs); 2284 //qDebug("KO: Writing stop time: %d ", secs);
2284 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 2285 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
2285 //QDateTime latest = dt.addSecs ( secs ); 2286 //QDateTime latest = dt.addSecs ( secs );
2286 //qDebug("KO: Termination on %s ", latest.toString().latin1()); 2287 //qDebug("KO: Termination on %s ", latest.toString().latin1());
2287 config->setGroup( "Views" ); 2288 config->setGroup( "Views" );
2288 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 2289 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
2289 2290
2290#if 0 2291#if 0
2291 qDebug("********************* "); 2292 qDebug("********************* ");
2292 qDebug("Testcode secsto "); 2293 qDebug("Testcode secsto ");
2293 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) ); 2294 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) );
2294 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) ); 2295 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) );
2295 int secsto = dt_nodaylight.secsTo( dt_daylight ); 2296 int secsto = dt_nodaylight.secsTo( dt_daylight );
2296 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto ); 2297 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto );
2297 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() ); 2298 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() );
2298 qDebug("dt daylight %s ",dt_daylight.toString().latin1() ); 2299 qDebug("dt daylight %s ",dt_daylight.toString().latin1() );
2299 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() ); 2300 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() );
2300 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600); 2301 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600);
2301 qDebug("********************* testcode end"); 2302 qDebug("********************* testcode end");
2302 2303
2303#endif 2304#endif
2304 2305
2305 QValueList<int> listINT = mLeftFrame->sizes(); 2306 QValueList<int> listINT = mLeftFrame->sizes();
2306 config->writeEntry("Left Splitter Frame",listINT); 2307 config->writeEntry("Left Splitter Frame",listINT);
2307 QValueList<int> listINT2 = mMainFrame->sizes(); 2308 QValueList<int> listINT2 = mMainFrame->sizes();
2308 config->writeEntry("Main Splitter Frame",listINT2); 2309 config->writeEntry("Main Splitter Frame",listINT2);
2309#ifdef DESKTOP_VERSION 2310#ifdef DESKTOP_VERSION
2310 config->setGroup("WidgetLayout"); 2311 config->setGroup("WidgetLayout");
2311 QStringList list ;//= config->readListEntry("MainLayout"); 2312 QStringList list ;//= config->readListEntry("MainLayout");
2312 int x,y,w,h; 2313 int x,y,w,h;
2313 QWidget* wid; 2314 QWidget* wid;
2314 wid = topLevelWidget(); 2315 wid = topLevelWidget();
2315 x = wid->geometry().x(); 2316 x = wid->geometry().x();
2316 y = wid->geometry().y(); 2317 y = wid->geometry().y();
2317 w = wid->width(); 2318 w = wid->width();
2318 h = wid->height(); 2319 h = wid->height();
2319 list.clear(); 2320 list.clear();
2320 list << QString::number( x ); 2321 list << QString::number( x );
2321 list << QString::number( y ); 2322 list << QString::number( y );
2322 list << QString::number( w ); 2323 list << QString::number( w );
2323 list << QString::number( h ); 2324 list << QString::number( h );
2324 config->writeEntry("MainLayout",list ); 2325 config->writeEntry("MainLayout",list );
2325 2326
2326 wid = mEventEditor; 2327 wid = mEventEditor;
2327 x = wid->geometry().x(); 2328 x = wid->geometry().x();
2328 y = wid->geometry().y(); 2329 y = wid->geometry().y();
2329 w = wid->width(); 2330 w = wid->width();
2330 h = wid->height(); 2331 h = wid->height();
2331 list.clear(); 2332 list.clear();
2332 list << QString::number( x ); 2333 list << QString::number( x );
2333 list << QString::number( y ); 2334 list << QString::number( y );
2334 list << QString::number( w ); 2335 list << QString::number( w );
2335 list << QString::number( h ); 2336 list << QString::number( h );
2336 config->writeEntry("EditEventLayout",list ); 2337 config->writeEntry("EditEventLayout",list );
2337 2338
2338 wid = mTodoEditor; 2339 wid = mTodoEditor;
2339 x = wid->geometry().x(); 2340 x = wid->geometry().x();
2340 y = wid->geometry().y(); 2341 y = wid->geometry().y();
2341 w = wid->width(); 2342 w = wid->width();
2342 h = wid->height(); 2343 h = wid->height();
2343 list.clear(); 2344 list.clear();
2344 list << QString::number( x ); 2345 list << QString::number( x );
2345 list << QString::number( y ); 2346 list << QString::number( y );
2346 list << QString::number( w ); 2347 list << QString::number( w );
2347 list << QString::number( h ); 2348 list << QString::number( h );
2348 config->writeEntry("EditTodoLayout",list ); 2349 config->writeEntry("EditTodoLayout",list );
2349 wid = getEventViewerDialog(); 2350 wid = getEventViewerDialog();
2350 x = wid->geometry().x(); 2351 x = wid->geometry().x();
2351 y = wid->geometry().y(); 2352 y = wid->geometry().y();
2352 w = wid->width(); 2353 w = wid->width();
2353 h = wid->height(); 2354 h = wid->height();
2354 list.clear(); 2355 list.clear();
2355 list << QString::number( x ); 2356 list << QString::number( x );
2356 list << QString::number( y ); 2357 list << QString::number( y );
2357 list << QString::number( w ); 2358 list << QString::number( w );
2358 list << QString::number( h ); 2359 list << QString::number( h );
2359 config->writeEntry("ViewerLayout",list ); 2360 config->writeEntry("ViewerLayout",list );
2360 wid = mDialogManager->getSearchDialog(); 2361 wid = mDialogManager->getSearchDialog();
2361 if ( wid ) { 2362 if ( wid ) {
2362 x = wid->geometry().x(); 2363 x = wid->geometry().x();
2363 y = wid->geometry().y(); 2364 y = wid->geometry().y();
2364 w = wid->width(); 2365 w = wid->width();
2365 h = wid->height(); 2366 h = wid->height();
2366 list.clear(); 2367 list.clear();
2367 list << QString::number( x ); 2368 list << QString::number( x );
2368 list << QString::number( y ); 2369 list << QString::number( y );
2369 list << QString::number( w ); 2370 list << QString::number( w );
2370 list << QString::number( h ); 2371 list << QString::number( h );
2371 config->writeEntry("SearchLayout",list ); 2372 config->writeEntry("SearchLayout",list );
2372 } 2373 }
2373#endif 2374#endif
2374 2375
2375 2376
2376 config->sync(); 2377 config->sync();
2377} 2378}
2378 2379
2379void CalendarView::readFilterSettings(KConfig *config) 2380void CalendarView::readFilterSettings(KConfig *config)
2380{ 2381{
2381 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 2382 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
2382 2383
2383 mFilters.clear(); 2384 mFilters.clear();
2384 2385
2385 config->setGroup("General"); 2386 config->setGroup("General");
2386 QStringList filterList = config->readListEntry("CalendarFilters"); 2387 QStringList filterList = config->readListEntry("CalendarFilters");
2387 2388
2388 QStringList::ConstIterator it = filterList.begin(); 2389 QStringList::ConstIterator it = filterList.begin();
2389 QStringList::ConstIterator end = filterList.end(); 2390 QStringList::ConstIterator end = filterList.end();
2390 while(it != end) { 2391 while(it != end) {
2391 // kdDebug() << " filter: " << (*it) << endl; 2392 // kdDebug() << " filter: " << (*it) << endl;
2392 2393
2393 CalFilter *filter; 2394 CalFilter *filter;
2394 filter = new CalFilter(*it); 2395 filter = new CalFilter(*it);
2395 config->setGroup("Filter_" + (*it).utf8()); 2396 config->setGroup("Filter_" + (*it).utf8());
2396 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 2397 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
2397 filter->setCriteria(config->readNumEntry("Criteria",0)); 2398 filter->setCriteria(config->readNumEntry("Criteria",0));
2398 filter->setCategoryList(config->readListEntry("CategoryList")); 2399 filter->setCategoryList(config->readListEntry("CategoryList"));
2399 mFilters.append(filter); 2400 mFilters.append(filter);
2400 2401
2401 ++it; 2402 ++it;
2402 } 2403 }
2403 2404
2404 if (mFilters.count() == 0) { 2405 if (mFilters.count() == 0) {
2405 CalFilter *filter = new CalFilter(i18n("Default")); 2406 CalFilter *filter = new CalFilter(i18n("Default"));
2406 mFilters.append(filter); 2407 mFilters.append(filter);
2407 } 2408 }
2408 mFilterView->updateFilters(); 2409 mFilterView->updateFilters();
2409 config->setGroup("FilterView"); 2410 config->setGroup("FilterView");
2410 2411
2411 mFilterView->blockSignals(true); 2412 mFilterView->blockSignals(true);
2412 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 2413 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
2413 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 2414 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
2414 mFilterView->blockSignals(false); 2415 mFilterView->blockSignals(false);
2415 // We do it manually to avoid it being done twice by the above calls 2416 // We do it manually to avoid it being done twice by the above calls
2416 updateFilter(); 2417 updateFilter();
2417} 2418}
2418 2419
2419void CalendarView::writeFilterSettings(KConfig *config) 2420void CalendarView::writeFilterSettings(KConfig *config)
2420{ 2421{
2421 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 2422 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
2422 2423
2423 QStringList filterList; 2424 QStringList filterList;
2424 2425
2425 CalFilter *filter = mFilters.first(); 2426 CalFilter *filter = mFilters.first();
2426 while(filter) { 2427 while(filter) {
2427 // kdDebug() << " fn: " << filter->name() << endl; 2428 // kdDebug() << " fn: " << filter->name() << endl;
2428 filterList << filter->name(); 2429 filterList << filter->name();
2429 config->setGroup("Filter_" + filter->name().utf8()); 2430 config->setGroup("Filter_" + filter->name().utf8());
2430 config->writeEntry("Criteria",filter->criteria()); 2431 config->writeEntry("Criteria",filter->criteria());
2431 config->writeEntry("CategoryList",filter->categoryList()); 2432 config->writeEntry("CategoryList",filter->categoryList());
2432 filter = mFilters.next(); 2433 filter = mFilters.next();
2433 } 2434 }
2434 config->setGroup("General"); 2435 config->setGroup("General");
2435 config->writeEntry("CalendarFilters",filterList); 2436 config->writeEntry("CalendarFilters",filterList);
2436 2437
2437 config->setGroup("FilterView"); 2438 config->setGroup("FilterView");
2438 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 2439 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
2439 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 2440 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
2440} 2441}
2441 2442
2442 2443
2443void CalendarView::goToday() 2444void CalendarView::goToday()
2444{ 2445{
2445 if ( mViewManager->currentView()->isMonthView() ) 2446 if ( mViewManager->currentView()->isMonthView() )
2446 mNavigator->selectTodayMonth(); 2447 mNavigator->selectTodayMonth();
2447 else 2448 else
2448 mNavigator->selectToday(); 2449 mNavigator->selectToday();
2449} 2450}
2450 2451
2451void CalendarView::goNext() 2452void CalendarView::goNext()
2452{ 2453{
2453 mNavigator->selectNext(); 2454 mNavigator->selectNext();
2454} 2455}
2455 2456
2456void CalendarView::goPrevious() 2457void CalendarView::goPrevious()
2457{ 2458{
2458 mNavigator->selectPrevious(); 2459 mNavigator->selectPrevious();
2459} 2460}
2460void CalendarView::goNextMonth() 2461void CalendarView::goNextMonth()
2461{ 2462{
2462 mNavigator->selectNextMonth(); 2463 mNavigator->selectNextMonth();
2463} 2464}
2464 2465
2465void CalendarView::goPreviousMonth() 2466void CalendarView::goPreviousMonth()
2466{ 2467{
2467 mNavigator->selectPreviousMonth(); 2468 mNavigator->selectPreviousMonth();
2468} 2469}
2469void CalendarView::writeLocale() 2470void CalendarView::writeLocale()
2470{ 2471{
2471 //KPimGlobalPrefs::instance()->setGlobalConfig(); 2472 //KPimGlobalPrefs::instance()->setGlobalConfig();
2472#if 0 2473#if 0
2473 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); 2474 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime );
2474 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); 2475 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday );
2475 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); 2476 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate );
2476 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); 2477 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage );
2477 QString dummy = KOPrefs::instance()->mUserDateFormatLong; 2478 QString dummy = KOPrefs::instance()->mUserDateFormatLong;
2478 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); 2479 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") ));
2479 dummy = KOPrefs::instance()->mUserDateFormatShort; 2480 dummy = KOPrefs::instance()->mUserDateFormatShort;
2480 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 2481 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
2481 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, 2482 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving,
2482 KOPrefs::instance()->mDaylightsavingStart, 2483 KOPrefs::instance()->mDaylightsavingStart,
2483 KOPrefs::instance()->mDaylightsavingEnd ); 2484 KOPrefs::instance()->mDaylightsavingEnd );
2484 KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId ); 2485 KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId );
2485#endif 2486#endif
2486} 2487}
2487void CalendarView::updateConfig() 2488void CalendarView::updateConfig()
2488{ 2489{
2489 writeLocale(); 2490 writeLocale();
2490 if ( KOPrefs::instance()->mUseAppColors ) 2491 if ( KOPrefs::instance()->mUseAppColors )
2491 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 2492 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
2492 emit configChanged(); 2493 emit configChanged();
2493 mTodoList->updateConfig(); 2494 mTodoList->updateConfig();
2494 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 2495 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
2495 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2496 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2496 // To make the "fill window" configurations work 2497 // To make the "fill window" configurations work
2497 //mViewManager->raiseCurrentView(); 2498 //mViewManager->raiseCurrentView();
2498} 2499}
2499 2500
2500 2501
2501void CalendarView::eventChanged(Event *event) 2502void CalendarView::eventChanged(Event *event)
2502{ 2503{
2503 changeEventDisplay(event,KOGlobals::EVENTEDITED); 2504 changeEventDisplay(event,KOGlobals::EVENTEDITED);
2504 //updateUnmanagedViews(); 2505 //updateUnmanagedViews();
2505} 2506}
2506 2507
2507void CalendarView::eventAdded(Event *event) 2508void CalendarView::eventAdded(Event *event)
2508{ 2509{
2509 changeEventDisplay(event,KOGlobals::EVENTADDED); 2510 changeEventDisplay(event,KOGlobals::EVENTADDED);
2510} 2511}
2511 2512
2512void CalendarView::eventToBeDeleted(Event *) 2513void CalendarView::eventToBeDeleted(Event *)
2513{ 2514{
2514 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 2515 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
2515} 2516}
2516 2517
2517void CalendarView::eventDeleted() 2518void CalendarView::eventDeleted()
2518{ 2519{
2519 changeEventDisplay(0,KOGlobals::EVENTDELETED); 2520 changeEventDisplay(0,KOGlobals::EVENTDELETED);
2520} 2521}
2521void CalendarView::changeTodoDisplay(Todo *which, int action) 2522void CalendarView::changeTodoDisplay(Todo *which, int action)
2522{ 2523{
2523 changeIncidenceDisplay((Incidence *)which, action); 2524 changeIncidenceDisplay((Incidence *)which, action);
2524 mDateNavigator->updateView(); //LR 2525 mDateNavigator->updateView(); //LR
2525 //mDialogManager->updateSearchDialog(); 2526 //mDialogManager->updateSearchDialog();
2526 2527
2527 if (which) { 2528 if (which) {
2528 mViewManager->updateWNview(); 2529 mViewManager->updateWNview();
2529 //mTodoList->updateView(); 2530 //mTodoList->updateView();
2530 } 2531 }
2531 2532
2532} 2533}
2533 2534
2534void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 2535void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
2535{ 2536{
2536 updateUnmanagedViews(); 2537 updateUnmanagedViews();
2537 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 2538 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
2538 if ( action == KOGlobals::EVENTDELETED ) { //delete 2539 if ( action == KOGlobals::EVENTDELETED ) { //delete
2539 mCalendar->checkAlarmForIncidence( 0, true ); 2540 mCalendar->checkAlarmForIncidence( 0, true );
2540 if ( mEventViewerDialog ) 2541 if ( mEventViewerDialog )
2541 mEventViewerDialog->hide(); 2542 mEventViewerDialog->hide();
2542 } 2543 }
2543 else 2544 else
2544 mCalendar->checkAlarmForIncidence( which , false ); 2545 mCalendar->checkAlarmForIncidence( which , false );
2545} 2546}
2546 2547
2547// most of the changeEventDisplays() right now just call the view's 2548// most of the changeEventDisplays() right now just call the view's
2548// total update mode, but they SHOULD be recoded to be more refresh-efficient. 2549// total update mode, but they SHOULD be recoded to be more refresh-efficient.
2549void CalendarView::changeEventDisplay(Event *which, int action) 2550void CalendarView::changeEventDisplay(Event *which, int action)
2550{ 2551{
2551 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 2552 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
2552 changeIncidenceDisplay((Incidence *)which, action); 2553 changeIncidenceDisplay((Incidence *)which, action);
2553 mDateNavigator->updateView(); 2554 mDateNavigator->updateView();
2554 //mDialogManager->updateSearchDialog(); 2555 //mDialogManager->updateSearchDialog();
2555 2556
2556 if (which) { 2557 if (which) {
2557 // If there is an event view visible update the display 2558 // If there is an event view visible update the display
2558 mViewManager->currentView()->changeEventDisplay(which,action); 2559 mViewManager->currentView()->changeEventDisplay(which,action);
2559 // TODO: check, if update needed 2560 // TODO: check, if update needed
2560 // if (which->getTodoStatus()) { 2561 // if (which->getTodoStatus()) {
2561 mTodoList->updateView(); 2562 mTodoList->updateView();
2562 // } 2563 // }
2563 } else { 2564 } else {
2564 mViewManager->currentView()->updateView(); 2565 mViewManager->currentView()->updateView();
2565 } 2566 }
2566} 2567}
2567 2568
2568 2569
2569void CalendarView::updateTodoViews() 2570void CalendarView::updateTodoViews()
2570{ 2571{
2571 mTodoList->updateView(); 2572 mTodoList->updateView();
2572 mViewManager->currentView()->updateView(); 2573 mViewManager->currentView()->updateView();
2573 2574
2574} 2575}
2575 2576
2576 2577
2577void CalendarView::updateView(const QDate &start, const QDate &end) 2578void CalendarView::updateView(const QDate &start, const QDate &end)
2578{ 2579{
2579 mTodoList->updateView(); 2580 mTodoList->updateView();
2580 mViewManager->updateView(start, end); 2581 mViewManager->updateView(start, end);
2581 //mDateNavigator->updateView(); 2582 //mDateNavigator->updateView();
2582} 2583}
2583 2584
2584void CalendarView::clearAllViews() 2585void CalendarView::clearAllViews()
2585{ 2586{
2586 mTodoList->clearList(); 2587 mTodoList->clearList();
2587 mViewManager->clearAllViews(); 2588 mViewManager->clearAllViews();
2588 SearchDialog * sd = mDialogManager->getSearchDialog(); 2589 SearchDialog * sd = mDialogManager->getSearchDialog();
2589 if ( sd ) { 2590 if ( sd ) {
2590 KOListView* kol = sd->listview(); 2591 KOListView* kol = sd->listview();
2591 if ( kol ) 2592 if ( kol )
2592 kol->clearList(); 2593 kol->clearList();
2593 } 2594 }
2594} 2595}
2595void CalendarView::updateView() 2596void CalendarView::updateView()
2596{ 2597{
2597 DateList tmpList = mNavigator->selectedDates(); 2598 DateList tmpList = mNavigator->selectedDates();
2598 2599
2599 if ( KOPrefs::instance()->mHideNonStartedTodos ) 2600 if ( KOPrefs::instance()->mHideNonStartedTodos )
2600 mTodoList->updateView(); 2601 mTodoList->updateView();
2601 // We assume that the navigator only selects consecutive days. 2602 // We assume that the navigator only selects consecutive days.
2602 updateView( tmpList.first(), tmpList.last() ); 2603 updateView( tmpList.first(), tmpList.last() );
2603} 2604}
2604 2605
2605void CalendarView::updateUnmanagedViews() 2606void CalendarView::updateUnmanagedViews()
2606{ 2607{
2607 mDateNavigator->updateDayMatrix(); 2608 mDateNavigator->updateDayMatrix();
2608} 2609}
2609 2610
2610int CalendarView::msgItemDelete(const QString name) 2611int CalendarView::msgItemDelete(const QString name)
2611{ 2612{
2612 return KMessageBox::warningContinueCancel(this,name +"\n\n"+ 2613 return KMessageBox::warningContinueCancel(this,name +"\n\n"+
2613 i18n("This item will be\npermanently deleted."), 2614 i18n("This item will be\npermanently deleted."),
2614 i18n("KO/Pi Confirmation"),i18n("Delete")); 2615 i18n("KO/Pi Confirmation"),i18n("Delete"));
2615} 2616}
2616 2617
2617 2618
2618void CalendarView::edit_cut() 2619void CalendarView::edit_cut()
2619{ 2620{
2620 Event *anEvent=0; 2621 Event *anEvent=0;
2621 2622
2622 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2623 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2623 2624
2624 if (mViewManager->currentView()->isEventView()) { 2625 if (mViewManager->currentView()->isEventView()) {
2625 if ( incidence && incidence->typeID() == eventID ) { 2626 if ( incidence && incidence->typeID() == eventID ) {
2626 anEvent = static_cast<Event *>(incidence); 2627 anEvent = static_cast<Event *>(incidence);
2627 } 2628 }
2628 } 2629 }
2629 2630
2630 if (!anEvent) { 2631 if (!anEvent) {
2631 KNotifyClient::beep(); 2632 KNotifyClient::beep();
2632 return; 2633 return;
2633 } 2634 }
2634 DndFactory factory( mCalendar ); 2635 DndFactory factory( mCalendar );
2635 factory.cutIncidence(anEvent); 2636 factory.cutIncidence(anEvent);
2636 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2637 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2637} 2638}
2638 2639
2639void CalendarView::edit_copy() 2640void CalendarView::edit_copy()
2640{ 2641{
2641 Event *anEvent=0; 2642 Event *anEvent=0;
2642 2643
2643 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2644 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2644 2645
2645 if (mViewManager->currentView()->isEventView()) { 2646 if (mViewManager->currentView()->isEventView()) {
2646 if ( incidence && incidence->typeID() == eventID ) { 2647 if ( incidence && incidence->typeID() == eventID ) {
2647 anEvent = static_cast<Event *>(incidence); 2648 anEvent = static_cast<Event *>(incidence);
2648 } 2649 }
2649 } 2650 }
2650 2651
2651 if (!anEvent) { 2652 if (!anEvent) {
2652 KNotifyClient::beep(); 2653 KNotifyClient::beep();
2653 return; 2654 return;
2654 } 2655 }
2655 DndFactory factory( mCalendar ); 2656 DndFactory factory( mCalendar );
2656 factory.copyIncidence(anEvent); 2657 factory.copyIncidence(anEvent);
2657} 2658}
2658 2659
2659void CalendarView::edit_paste() 2660void CalendarView::edit_paste()
2660{ 2661{
2661 QDate date = mNavigator->selectedDates().first(); 2662 QDate date = mNavigator->selectedDates().first();
2662 2663
2663 DndFactory factory( mCalendar ); 2664 DndFactory factory( mCalendar );
2664 Event *pastedEvent = (Event *)factory.pasteIncidence( date ); 2665 Event *pastedEvent = (Event *)factory.pasteIncidence( date );
2665 2666
2666 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2667 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2667} 2668}
2668void CalendarView::edit_global_options() 2669void CalendarView::edit_global_options()
2669{ 2670{
2670 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId; 2671 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId;
2671 emit save(); 2672 emit save();
2672 emit saveStopTimer(); 2673 emit saveStopTimer();
2673 mDialogManager->showGlobalOptionsDialog(); 2674 mDialogManager->showGlobalOptionsDialog();
2674 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) { 2675 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) {
2675 emit saveStopTimer(); 2676 emit saveStopTimer();
2676 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto shift the time of the events?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"), 2677 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto shift the time of the events?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"),
2677 i18n("Timezone settings"),i18n("Reload"))) { 2678 i18n("Timezone settings"),i18n("Reload"))) {
2678 qDebug("KO: TZ reload cancelled "); 2679 qDebug("KO: TZ reload cancelled ");
2679 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2680 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2680 return; 2681 return;
2681 } 2682 }
2682 qDebug("KO: Timezone change "); 2683 qDebug("KO: Timezone change ");
2683 loadCalendars(); 2684 loadCalendars();
2684 setModified(true); 2685 setModified(true);
2685 } 2686 }
2686 else 2687 else
2687 qDebug("KO: No tz change "); 2688 qDebug("KO: No tz change ");
2688} 2689}
2689void CalendarView::edit_options() 2690void CalendarView::edit_options()
2690{ 2691{
2691 mDialogManager->showOptionsDialog(); 2692 mDialogManager->showOptionsDialog();
2692} 2693}
2693 2694
2694 2695
2695void CalendarView::slotSelectPickerDate( QDate d) 2696void CalendarView::slotSelectPickerDate( QDate d)
2696{ 2697{
2697 mDateFrame->hide(); 2698 mDateFrame->hide();
2698 if ( mDatePickerMode == 1 ) { 2699 if ( mDatePickerMode == 1 ) {
2699 mNavigator->slotDaySelect( d ); 2700 mNavigator->slotDaySelect( d );
2700 } else if ( mDatePickerMode == 2 ) { 2701 } else if ( mDatePickerMode == 2 ) {
2701 if ( mMoveIncidence->typeID() == todoID ) { 2702 if ( mMoveIncidence->typeID() == todoID ) {
2702 Todo * to = (Todo *) mMoveIncidence; 2703 Todo * to = (Todo *) mMoveIncidence;
2703 QTime tim; 2704 QTime tim;
2704 int len = 0; 2705 int len = 0;
2705 if ( to->hasStartDate() && to->hasDueDate() ) 2706 if ( to->hasStartDate() && to->hasDueDate() )
2706 len = to->dtStart().secsTo( to->dtDue()); 2707 len = to->dtStart().secsTo( to->dtDue());
2707 if ( to->hasDueDate() ) 2708 if ( to->hasDueDate() )
2708 tim = to->dtDue().time(); 2709 tim = to->dtDue().time();
2709 else { 2710 else {
2710 tim = QTime ( 0,0,0 ); 2711 tim = QTime ( 0,0,0 );
2711 to->setFloats( true ); 2712 to->setFloats( true );
2712 to->setHasDueDate( true ); 2713 to->setHasDueDate( true );
2713 } 2714 }
2714 QDateTime dt ( d,tim ); 2715 QDateTime dt ( d,tim );
2715 to->setDtDue( dt ); 2716 to->setDtDue( dt );
2716 2717
2717 if ( to->hasStartDate() ) { 2718 if ( to->hasStartDate() ) {
2718 if ( len>0 ) 2719 if ( len>0 )
2719 to->setDtStart(to->dtDue().addSecs( -len )); 2720 to->setDtStart(to->dtDue().addSecs( -len ));
2720 else 2721 else
2721 if (to->dtStart() > to->dtDue() ) 2722 if (to->dtStart() > to->dtDue() )
2722 to->setDtStart(to->dtDue().addDays( -3 )); 2723 to->setDtStart(to->dtDue().addDays( -3 ));
2723 } 2724 }
2724 2725
2725 todoChanged( to ); 2726 todoChanged( to );
2726 } else { 2727 } else {
2727 if ( mMoveIncidence->doesRecur() ) { 2728 if ( mMoveIncidence->doesRecur() ) {
2728#if 0 2729#if 0
2729 // PENDING implement this 2730 // PENDING implement this
2730 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate ); 2731 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate );
2731 mCalendar()->addIncidence( newInc ); 2732 mCalendar()->addIncidence( newInc );
2732 if ( mMoveIncidence->typeID() == todoID ) 2733 if ( mMoveIncidence->typeID() == todoID )
2733 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED ); 2734 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED );
2734 else 2735 else
2735 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED); 2736 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED);
2736 mMoveIncidence = newInc; 2737 mMoveIncidence = newInc;
2737 2738
2738#endif 2739#endif
2739 } 2740 }
2740 QTime tim = mMoveIncidence->dtStart().time(); 2741 QTime tim = mMoveIncidence->dtStart().time();
2741 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 2742 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
2742 QDateTime dt ( d,tim ); 2743 QDateTime dt ( d,tim );
2743 mMoveIncidence->setDtStart( dt ); 2744 mMoveIncidence->setDtStart( dt );
2744 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 2745 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
2745 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 2746 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
2746 } 2747 }
2747 2748
2748 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 2749 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
2749 } 2750 }
2750} 2751}
2751 2752
2752void CalendarView::removeCategories() 2753void CalendarView::removeCategories()
2753{ 2754{
2754 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2755 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2755 QStringList catList = KOPrefs::instance()->mCustomCategories; 2756 QStringList catList = KOPrefs::instance()->mCustomCategories;
2756 QStringList catIncList; 2757 QStringList catIncList;
2757 QStringList newCatList; 2758 QStringList newCatList;
2758 Incidence* inc = incList.first(); 2759 Incidence* inc = incList.first();
2759 int i; 2760 int i;
2760 int count = 0; 2761 int count = 0;
2761 while ( inc ) { 2762 while ( inc ) {
2762 newCatList.clear(); 2763 newCatList.clear();
2763 catIncList = inc->categories() ; 2764 catIncList = inc->categories() ;
2764 for( i = 0; i< catIncList.count(); ++i ) { 2765 for( i = 0; i< catIncList.count(); ++i ) {
2765 if ( catList.contains (catIncList[i])) 2766 if ( catList.contains (catIncList[i]))
2766 newCatList.append( catIncList[i] ); 2767 newCatList.append( catIncList[i] );
2767 } 2768 }
2768 newCatList.sort(); 2769 newCatList.sort();
2769 inc->setCategories( newCatList.join(",") ); 2770 inc->setCategories( newCatList.join(",") );
2770 inc = incList.next(); 2771 inc = incList.next();
2771 } 2772 }
2772} 2773}
2773 2774
2774int CalendarView::addCategories() 2775int CalendarView::addCategories()
2775{ 2776{
2776 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2777 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2777 QStringList catList = KOPrefs::instance()->mCustomCategories; 2778 QStringList catList = KOPrefs::instance()->mCustomCategories;
2778 QStringList catIncList; 2779 QStringList catIncList;
2779 Incidence* inc = incList.first(); 2780 Incidence* inc = incList.first();
2780 int i; 2781 int i;
2781 int count = 0; 2782 int count = 0;
2782 while ( inc ) { 2783 while ( inc ) {
2783 catIncList = inc->categories() ; 2784 catIncList = inc->categories() ;
2784 for( i = 0; i< catIncList.count(); ++i ) { 2785 for( i = 0; i< catIncList.count(); ++i ) {
2785 if ( !catList.contains (catIncList[i])) { 2786 if ( !catList.contains (catIncList[i])) {
2786 catList.append( catIncList[i] ); 2787 catList.append( catIncList[i] );
2787 //qDebug("add cat %s ", catIncList[i].latin1()); 2788 //qDebug("add cat %s ", catIncList[i].latin1());
2788 ++count; 2789 ++count;
2789 } 2790 }
2790 } 2791 }
2791 inc = incList.next(); 2792 inc = incList.next();
2792 } 2793 }
2793 catList.sort(); 2794 catList.sort();
2794 KOPrefs::instance()->mCustomCategories = catList; 2795 KOPrefs::instance()->mCustomCategories = catList;
2795 return count; 2796 return count;
2796} 2797}
2797 2798
2798void CalendarView::manageCategories() 2799void CalendarView::manageCategories()
2799{ 2800{
2800 KOCatPrefs* cp = new KOCatPrefs(); 2801 KOCatPrefs* cp = new KOCatPrefs();
2801 cp->show(); 2802 cp->show();
2802 int w =cp->sizeHint().width() ; 2803 int w =cp->sizeHint().width() ;
2803 int h = cp->sizeHint().height() ; 2804 int h = cp->sizeHint().height() ;
2804 int dw = QApplication::desktop()->width(); 2805 int dw = QApplication::desktop()->width();
2805 int dh = QApplication::desktop()->height(); 2806 int dh = QApplication::desktop()->height();
2806 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2807 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2807 if ( !cp->exec() ) { 2808 if ( !cp->exec() ) {
2808 delete cp; 2809 delete cp;
2809 return; 2810 return;
2810 } 2811 }
2811 int count = 0; 2812 int count = 0;
2812 if ( cp->addCat() ) { 2813 if ( cp->addCat() ) {
2813 count = addCategories(); 2814 count = addCategories();
2814 if ( count ) { 2815 if ( count ) {
2815 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 2816 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
2816 writeSettings(); 2817 writeSettings();
2817 } else 2818 } else
2818 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! ")); 2819 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! "));
2819 } else { 2820 } else {
2820 removeCategories(); 2821 removeCategories();
2821 updateView(); 2822 updateView();
2822 } 2823 }
2823 delete cp; 2824 delete cp;
2824} 2825}
2825 2826
2826void CalendarView::beamIncidence(Incidence * Inc) 2827void CalendarView::beamIncidence(Incidence * Inc)
2827{ 2828{
2828 QPtrList<Incidence> delSel ; 2829 QPtrList<Incidence> delSel ;
2829 delSel.append(Inc); 2830 delSel.append(Inc);
2830 beamIncidenceList( delSel ); 2831 beamIncidenceList( delSel );
2831} 2832}
2832void CalendarView::beamCalendar() 2833void CalendarView::beamCalendar()
2833{ 2834{
2834 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 2835 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
2835 //qDebug("beamCalendar() "); 2836 //qDebug("beamCalendar() ");
2836 beamIncidenceList( delSel ); 2837 beamIncidenceList( delSel );
2837} 2838}
2838void CalendarView::beamFilteredCalendar() 2839void CalendarView::beamFilteredCalendar()
2839{ 2840{
2840 QPtrList<Incidence> delSel = mCalendar->incidences(); 2841 QPtrList<Incidence> delSel = mCalendar->incidences();
2841 //qDebug("beamFilteredCalendar() "); 2842 //qDebug("beamFilteredCalendar() ");
2842 beamIncidenceList( delSel ); 2843 beamIncidenceList( delSel );
2843} 2844}
2844void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 2845void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
2845{ 2846{
2846 if ( beamDialog->exec () == QDialog::Rejected ) 2847 if ( beamDialog->exec () == QDialog::Rejected )
2847 return; 2848 return;
2848#ifdef DESKTOP_VERSION 2849#ifdef DESKTOP_VERSION
2849 QString fn = locateLocal( "tmp", "kopibeamfile" ); 2850 QString fn = locateLocal( "tmp", "kopibeamfile" );
2850#else 2851#else
2851 QString fn = "/tmp/kopibeamfile"; 2852 QString fn = "/tmp/kopibeamfile";
2852#endif 2853#endif
2853 QString mes; 2854 QString mes;
2854 bool createbup = true; 2855 bool createbup = true;
2855 if ( createbup ) { 2856 if ( createbup ) {
2856 QString description = "\n"; 2857 QString description = "\n";
2857 CalendarLocal* cal = new CalendarLocal(); 2858 CalendarLocal* cal = new CalendarLocal();
2858 if ( beamDialog->beamLocal() ) 2859 if ( beamDialog->beamLocal() )
2859 cal->setLocalTime(); 2860 cal->setLocalTime();
2860 else 2861 else
2861 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2862 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2862 Incidence *incidence = delSel.first(); 2863 Incidence *incidence = delSel.first();
2863 bool addText = false; 2864 bool addText = false;
2864 if ( delSel.count() < 10 ) 2865 if ( delSel.count() < 10 )
2865 addText = true; 2866 addText = true;
2866 else { 2867 else {
2867 description.sprintf(i18n(" %d items?"),delSel.count() ); 2868 description.sprintf(i18n(" %d items?"),delSel.count() );
2868 } 2869 }
2869 while ( incidence ) { 2870 while ( incidence ) {
2870 Incidence *in = incidence->clone(); 2871 Incidence *in = incidence->clone();
2871 if ( ! in->summary().isEmpty() ) { 2872 if ( ! in->summary().isEmpty() ) {
2872 in->setDescription(""); 2873 in->setDescription("");
2873 } else { 2874 } else {
2874 in->setSummary( in->description().left(20)); 2875 in->setSummary( in->description().left(20));
2875 in->setDescription(""); 2876 in->setDescription("");
2876 } 2877 }
2877 if ( addText ) 2878 if ( addText )
2878 description += in->summary() + "\n"; 2879 description += in->summary() + "\n";
2879 cal->addIncidence( in ); 2880 cal->addIncidence( in );
2880 incidence = delSel.next(); 2881 incidence = delSel.next();
2881 } 2882 }
2882 if ( beamDialog->beamVcal() ) { 2883 if ( beamDialog->beamVcal() ) {
2883 fn += ".vcs"; 2884 fn += ".vcs";
2884 FileStorage storage( cal, fn, new VCalFormat ); 2885 FileStorage storage( cal, fn, new VCalFormat );
2885 storage.save(); 2886 storage.save();
2886 } else { 2887 } else {
2887 fn += ".ics"; 2888 fn += ".ics";
2888 FileStorage storage( cal, fn, new ICalFormat( ) ); 2889 FileStorage storage( cal, fn, new ICalFormat( ) );
2889 storage.save(); 2890 storage.save();
2890 } 2891 }
2891 delete cal; 2892 delete cal;
2892 mes = i18n("KO/Pi: Ready for beaming"); 2893 mes = i18n("KO/Pi: Ready for beaming");
2893 topLevelWidget()->setCaption(mes); 2894 topLevelWidget()->setCaption(mes);
2894 KApplication::convert2latin1( fn ); 2895 KApplication::convert2latin1( fn );
2895#ifndef DESKTOP_VERSION 2896#ifndef DESKTOP_VERSION
2896 Ir *ir = new Ir( this ); 2897 Ir *ir = new Ir( this );
2897 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 2898 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
2898 ir->send( fn, description, "text/x-vCalendar" ); 2899 ir->send( fn, description, "text/x-vCalendar" );
2899#endif 2900#endif
2900 } 2901 }
2901} 2902}
2902void CalendarView::beamDone( Ir *ir ) 2903void CalendarView::beamDone( Ir *ir )
2903{ 2904{
2904#ifndef DESKTOP_VERSION 2905#ifndef DESKTOP_VERSION
2905 delete ir; 2906 delete ir;
2906#endif 2907#endif
2907 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); 2908 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") );
2908 topLevelWidget()->raise(); 2909 topLevelWidget()->raise();
2909} 2910}
2910 2911
2911void CalendarView::moveIncidence(Incidence * inc ) 2912void CalendarView::moveIncidence(Incidence * inc )
2912{ 2913{
2913 if ( !inc ) return; 2914 if ( !inc ) return;
2914 showDatePickerPopup(); 2915 showDatePickerPopup();
2915 mDatePickerMode = 2; 2916 mDatePickerMode = 2;
2916 mMoveIncidence = inc ; 2917 mMoveIncidence = inc ;
2917 QDate da; 2918 QDate da;
2918 if ( mMoveIncidence->typeID() == todoID ) { 2919 if ( mMoveIncidence->typeID() == todoID ) {
2919 Todo * to = (Todo *) mMoveIncidence; 2920 Todo * to = (Todo *) mMoveIncidence;
2920 if ( to->hasDueDate() ) 2921 if ( to->hasDueDate() )
2921 da = to->dtDue().date(); 2922 da = to->dtDue().date();
2922 else 2923 else
2923 da = QDate::currentDate(); 2924 da = QDate::currentDate();
2924 } else { 2925 } else {
2925 da = mMoveIncidence->dtStart().date(); 2926 da = mMoveIncidence->dtStart().date();
2926 } 2927 }
2927 //PENDING set date for recurring incidence to date of recurrence 2928 //PENDING set date for recurring incidence to date of recurrence
2928 //mMoveIncidenceOldDate; 2929 //mMoveIncidenceOldDate;
2929 mDatePicker->setDate( da ); 2930 mDatePicker->setDate( da );
2930} 2931}
2931void CalendarView::showDatePickerPopup() 2932void CalendarView::showDatePickerPopup()
2932{ 2933{
2933 if ( mDateFrame->isVisible() ) 2934 if ( mDateFrame->isVisible() )
2934 mDateFrame->hide(); 2935 mDateFrame->hide();
2935 else { 2936 else {
2936 int offX = 0, offY = 0; 2937 int offX = 0, offY = 0;
2937#ifdef DESKTOP_VERSION 2938#ifdef DESKTOP_VERSION
2938 int w =mDatePicker->sizeHint().width() ; 2939 int w =mDatePicker->sizeHint().width() ;
2939 int h = mDatePicker->sizeHint().height() ; 2940 int h = mDatePicker->sizeHint().height() ;
2940 int dw = topLevelWidget()->width(); 2941 int dw = topLevelWidget()->width();
2941 int dh = topLevelWidget()->height(); 2942 int dh = topLevelWidget()->height();
2942 offX = topLevelWidget()->x(); 2943 offX = topLevelWidget()->x();
2943 offY = topLevelWidget()->y(); 2944 offY = topLevelWidget()->y();
2944#else 2945#else
2945 int w =mDatePicker->sizeHint().width() ; 2946 int w =mDatePicker->sizeHint().width() ;
2946 int h = mDatePicker->sizeHint().height() ; 2947 int h = mDatePicker->sizeHint().height() ;
2947 int dw = QApplication::desktop()->width(); 2948 int dw = QApplication::desktop()->width();
2948 int dh = QApplication::desktop()->height(); 2949 int dh = QApplication::desktop()->height();
2949#endif 2950#endif
2950 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h ); 2951 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h );
2951 mDateFrame->show(); 2952 mDateFrame->show();
2952 } 2953 }
2953} 2954}
2954void CalendarView::showDatePicker( ) 2955void CalendarView::showDatePicker( )
2955{ 2956{
2956 showDatePickerPopup(); 2957 showDatePickerPopup();
2957 mDatePickerMode = 1; 2958 mDatePickerMode = 1;
2958 mDatePicker->setDate( mNavigator->selectedDates().first() ); 2959 mDatePicker->setDate( mNavigator->selectedDates().first() );
2959} 2960}
2960 2961
2961void CalendarView::showEventEditor() 2962void CalendarView::showEventEditor()
2962{ 2963{
2963#ifdef DESKTOP_VERSION 2964#ifdef DESKTOP_VERSION
2964 int x,y,w,h; 2965 int x,y,w,h;
2965 x = mEventEditor->geometry().x(); 2966 x = mEventEditor->geometry().x();
2966 y = mEventEditor->geometry().y(); 2967 y = mEventEditor->geometry().y();
2967 w = mEventEditor->width(); 2968 w = mEventEditor->width();
2968 h = mEventEditor->height(); 2969 h = mEventEditor->height();
2969 mEventEditor->show(); 2970 mEventEditor->show();
2970 mEventEditor->setGeometry(x,y,w,h); 2971 mEventEditor->setGeometry(x,y,w,h);
2971#else 2972#else
2972 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) { 2973 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) {
2973 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 2974 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
2974 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() ); 2975 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() );
2975 qApp->processEvents(); 2976 qApp->processEvents();
2976 delete mEventEditor; 2977 delete mEventEditor;
2977 mEventEditor = mDialogManager->getEventEditor(); 2978 mEventEditor = mDialogManager->getEventEditor();
2978 topLevelWidget()->setCaption( i18n("") ); 2979 topLevelWidget()->setCaption( i18n("") );
2979 } 2980 }
2980 mEventEditor->showMaximized(); 2981 mEventEditor->showMaximized();
2981#endif 2982#endif
2982} 2983}
2983void CalendarView::showTodoEditor() 2984void CalendarView::showTodoEditor()
2984{ 2985{
2985#ifdef DESKTOP_VERSION 2986#ifdef DESKTOP_VERSION
2986 int x,y,w,h; 2987 int x,y,w,h;
2987 x = mTodoEditor->geometry().x(); 2988 x = mTodoEditor->geometry().x();
2988 y = mTodoEditor->geometry().y(); 2989 y = mTodoEditor->geometry().y();
2989 w = mTodoEditor->width(); 2990 w = mTodoEditor->width();
2990 h = mTodoEditor->height(); 2991 h = mTodoEditor->height();
2991 mTodoEditor->show(); 2992 mTodoEditor->show();
2992 mTodoEditor->setGeometry(x,y,w,h); 2993 mTodoEditor->setGeometry(x,y,w,h);
2993#else 2994#else
2994 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) { 2995 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) {
2995 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 2996 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
2996 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() ); 2997 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() );
2997 qApp->processEvents(); 2998 qApp->processEvents();
2998 delete mTodoEditor; 2999 delete mTodoEditor;
2999 mTodoEditor = mDialogManager->getTodoEditor(); 3000 mTodoEditor = mDialogManager->getTodoEditor();
3000 topLevelWidget()->setCaption( i18n("") ); 3001 topLevelWidget()->setCaption( i18n("") );
3001 } 3002 }
3002 mTodoEditor->showMaximized(); 3003 mTodoEditor->showMaximized();
3003#endif 3004#endif
3004} 3005}
3005 3006
3006void CalendarView::cloneIncidence() 3007void CalendarView::cloneIncidence()
3007{ 3008{
3008 Incidence *incidence = currentSelection(); 3009 Incidence *incidence = currentSelection();
3009 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3010 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3010 if ( incidence ) { 3011 if ( incidence ) {
3011 cloneIncidence(incidence); 3012 cloneIncidence(incidence);
3012 } 3013 }
3013} 3014}
3014void CalendarView::moveIncidence() 3015void CalendarView::moveIncidence()
3015{ 3016{
3016 Incidence *incidence = currentSelection(); 3017 Incidence *incidence = currentSelection();
3017 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3018 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3018 if ( incidence ) { 3019 if ( incidence ) {
3019 moveIncidence(incidence); 3020 moveIncidence(incidence);
3020 } 3021 }
3021} 3022}
3022void CalendarView::beamIncidence() 3023void CalendarView::beamIncidence()
3023{ 3024{
3024 Incidence *incidence = currentSelection(); 3025 Incidence *incidence = currentSelection();
3025 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3026 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3026 if ( incidence ) { 3027 if ( incidence ) {
3027 beamIncidence(incidence); 3028 beamIncidence(incidence);
3028 } 3029 }
3029} 3030}
3030void CalendarView::toggleCancelIncidence() 3031void CalendarView::toggleCancelIncidence()
3031{ 3032{
3032 Incidence *incidence = currentSelection(); 3033 Incidence *incidence = currentSelection();
3033 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3034 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3034 if ( incidence ) { 3035 if ( incidence ) {
3035 cancelIncidence(incidence); 3036 cancelIncidence(incidence);
3036 } 3037 }
3037} 3038}
3038 3039
3039 3040
3040void CalendarView::cancelIncidence(Incidence * inc ) 3041void CalendarView::cancelIncidence(Incidence * inc )
3041{ 3042{
3042 inc->setCancelled( ! inc->cancelled() ); 3043 inc->setCancelled( ! inc->cancelled() );
3043 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 3044 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
3044 updateView(); 3045 updateView();
3045} 3046}
3046void CalendarView::cloneIncidence(Incidence * orgInc ) 3047void CalendarView::cloneIncidence(Incidence * orgInc )
3047{ 3048{
3048 Incidence * newInc = orgInc->clone(); 3049 Incidence * newInc = orgInc->clone();
3049 newInc->recreate(); 3050 newInc->recreate();
3050 3051
3051 if ( newInc->typeID() == todoID ) { 3052 if ( newInc->typeID() == todoID ) {
3052 Todo* t = (Todo*) newInc; 3053 Todo* t = (Todo*) newInc;
3053 bool cloneSub = false; 3054 bool cloneSub = false;
3054 if ( orgInc->relations().count() ) { 3055 if ( orgInc->relations().count() ) {
3055 int result = KMessageBox::warningYesNoCancel(this, 3056 int result = KMessageBox::warningYesNoCancel(this,
3056 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( newInc->summary().left ( 25 ) ), 3057 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( newInc->summary().left ( 25 ) ),
3057 i18n("Todo has subtodos"), 3058 i18n("Todo has subtodos"),
3058 i18n("Yes"), 3059 i18n("Yes"),
3059 i18n("No")); 3060 i18n("No"));
3060 3061
3061 if ( result == KMessageBox::Cancel ) { 3062 if ( result == KMessageBox::Cancel ) {
3062 delete t; 3063 delete t;
3063 return; 3064 return;
3064 } 3065 }
3065 if (result == KMessageBox::Yes) cloneSub = true; 3066 if (result == KMessageBox::Yes) cloneSub = true;
3066 } 3067 }
3067 showTodoEditor(); 3068 showTodoEditor();
3068 mTodoEditor->editTodo( t ); 3069 mTodoEditor->editTodo( t );
3069 if ( mTodoEditor->exec() ) { 3070 if ( mTodoEditor->exec() ) {
3070 if ( cloneSub ) { 3071 if ( cloneSub ) {
3071 orgInc->cloneRelations( t ); 3072 orgInc->cloneRelations( t );
3072 mCalendar->addIncidenceBranch( t ); 3073 mCalendar->addIncidenceBranch( t );
3073 updateView(); 3074 updateView();
3074 3075
3075 } else { 3076 } else {
3076 mCalendar->addTodo( t ); 3077 mCalendar->addTodo( t );
3077 updateView(); 3078 updateView();
3078 } 3079 }
3079 } else { 3080 } else {
3080 delete t; 3081 delete t;
3081 } 3082 }
3082 } 3083 }
3083 else { 3084 else {
3084 Event* e = (Event*) newInc; 3085 Event* e = (Event*) newInc;
3085 showEventEditor(); 3086 showEventEditor();
3086 mEventEditor->editEvent( e ); 3087 mEventEditor->editEvent( e );
3087 if ( mEventEditor->exec() ) { 3088 if ( mEventEditor->exec() ) {
3088 mCalendar->addEvent( e ); 3089 mCalendar->addEvent( e );
3089 updateView(); 3090 updateView();
3090 } else { 3091 } else {
3091 delete e; 3092 delete e;
3092 } 3093 }
3093 } 3094 }
3094 setActiveWindow(); 3095 setActiveWindow();
3095} 3096}
3096 3097
3097void CalendarView::newEvent() 3098void CalendarView::newEvent()
3098{ 3099{
3099 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 3100 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
3100 KOAgendaView *aView = mViewManager->agendaView(); 3101 KOAgendaView *aView = mViewManager->agendaView();
3101 if (aView) { 3102 if (aView) {
3102 if (aView->selectionStart().isValid()) { 3103 if (aView->selectionStart().isValid()) {
3103 if (aView->selectedIsAllDay()) { 3104 if (aView->selectedIsAllDay()) {
3104 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 3105 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
3105 } else { 3106 } else {
3106 newEvent(aView->selectionStart(),aView->selectionEnd()); 3107 newEvent(aView->selectionStart(),aView->selectionEnd());
3107 } 3108 }
3108 return; 3109 return;
3109 } 3110 }
3110 } 3111 }
3111 3112
3112 QDate date = mNavigator->selectedDates().first(); 3113 QDate date = mNavigator->selectedDates().first();
3113 QDateTime current = QDateTime::currentDateTime(); 3114 QDateTime current = QDateTime::currentDateTime();
3114 if ( date <= current.date() ) { 3115 if ( date <= current.date() ) {
3115 int hour = current.time().hour() +1; 3116 int hour = current.time().hour() +1;
3116 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 3117 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
3117 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 3118 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
3118 } else 3119 } else
3119 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 3120 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
3120 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 3121 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
3121 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 3122 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
3122} 3123}
3123 3124
3124void CalendarView::newEvent(QDateTime fh) 3125void CalendarView::newEvent(QDateTime fh)
3125{ 3126{
3126 newEvent(fh, 3127 newEvent(fh,
3127 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 3128 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
3128} 3129}
3129 3130
3130void CalendarView::newEvent(QDate dt) 3131void CalendarView::newEvent(QDate dt)
3131{ 3132{
3132 newEvent(QDateTime(dt, QTime(0,0,0)), 3133 newEvent(QDateTime(dt, QTime(0,0,0)),
3133 QDateTime(dt, QTime(0,0,0)), true); 3134 QDateTime(dt, QTime(0,0,0)), true);
3134} 3135}
3135void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint) 3136void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint)
3136{ 3137{
3137 newEvent(fromHint, toHint, false); 3138 newEvent(fromHint, toHint, false);
3138} 3139}
3139void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 3140void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
3140{ 3141{
3141 3142
3142 showEventEditor(); 3143 showEventEditor();
3143 mEventEditor->newEvent(fromHint,toHint,allDay); 3144 mEventEditor->newEvent(fromHint,toHint,allDay);
3144 if ( mFilterView->filtersEnabled() ) { 3145 if ( mFilterView->filtersEnabled() ) {
3145 CalFilter *filter = mFilterView->selectedFilter(); 3146 CalFilter *filter = mFilterView->selectedFilter();
3146 if (filter && filter->showCategories()) { 3147 if (filter && filter->showCategories()) {
3147 mEventEditor->setCategories(filter->categoryList().join(",") ); 3148 mEventEditor->setCategories(filter->categoryList().join(",") );
3148 } 3149 }
3149 if ( filter ) 3150 if ( filter )
3150 mEventEditor->setSecrecy( filter->getSecrecy() ); 3151 mEventEditor->setSecrecy( filter->getSecrecy() );
3151 } 3152 }
3152 mEventEditor->exec(); 3153 mEventEditor->exec();
3153 setActiveWindow(); 3154 setActiveWindow();
3154} 3155}
3155void CalendarView::todoAdded(Todo * t) 3156void CalendarView::todoAdded(Todo * t)
3156{ 3157{
3157 3158
3158 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 3159 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
3159 updateTodoViews(); 3160 updateTodoViews();
3160} 3161}
3161void CalendarView::todoChanged(Todo * t) 3162void CalendarView::todoChanged(Todo * t)
3162{ 3163{
3163 emit todoModified( t, 4 ); 3164 emit todoModified( t, 4 );
3164 // updateTodoViews(); 3165 // updateTodoViews();
3165} 3166}
3166void CalendarView::todoToBeDeleted(Todo *) 3167void CalendarView::todoToBeDeleted(Todo *)
3167{ 3168{
3168 //qDebug("todoToBeDeleted(Todo *) "); 3169 //qDebug("todoToBeDeleted(Todo *) ");
3169 updateTodoViews(); 3170 updateTodoViews();
3170} 3171}
3171void CalendarView::todoDeleted() 3172void CalendarView::todoDeleted()
3172{ 3173{
3173 //qDebug(" todoDeleted()"); 3174 //qDebug(" todoDeleted()");
3174 updateTodoViews(); 3175 updateTodoViews();
3175} 3176}
3176 3177
3177 3178
3178void CalendarView::newTodoDateTime( QDateTime dt, bool allday ) 3179void CalendarView::newTodoDateTime( QDateTime dt, bool allday )
3179{ 3180{
3180 showTodoEditor(); 3181 showTodoEditor();
3181 mTodoEditor->newTodo(dt,0,allday); 3182 mTodoEditor->newTodo(dt,0,allday);
3182 if ( mFilterView->filtersEnabled() ) { 3183 if ( mFilterView->filtersEnabled() ) {
3183 CalFilter *filter = mFilterView->selectedFilter(); 3184 CalFilter *filter = mFilterView->selectedFilter();
3184 if (filter && filter->showCategories()) { 3185 if (filter && filter->showCategories()) {
3185 mTodoEditor->setCategories(filter->categoryList().join(",") ); 3186 mTodoEditor->setCategories(filter->categoryList().join(",") );
3186 } 3187 }
3187 if ( filter ) 3188 if ( filter )
3188 mTodoEditor->setSecrecy( filter->getSecrecy() ); 3189 mTodoEditor->setSecrecy( filter->getSecrecy() );
3189 } 3190 }
3190 mTodoEditor->exec(); 3191 mTodoEditor->exec();
3191 setActiveWindow(); 3192 setActiveWindow();
3192} 3193}
3193 3194
3194void CalendarView::newTodo() 3195void CalendarView::newTodo()
3195{ 3196{
3196 newTodoDateTime( QDateTime(),true ); 3197 newTodoDateTime( QDateTime(),true );
3197} 3198}
3198 3199
3199void CalendarView::newSubTodo() 3200void CalendarView::newSubTodo()
3200{ 3201{
3201 Todo *todo = selectedTodo(); 3202 Todo *todo = selectedTodo();
3202 if ( todo ) newSubTodo( todo ); 3203 if ( todo ) newSubTodo( todo );
3203} 3204}
3204 3205
3205void CalendarView::newSubTodo(Todo *parentEvent) 3206void CalendarView::newSubTodo(Todo *parentEvent)
3206{ 3207{
3207 3208
3208 showTodoEditor(); 3209 showTodoEditor();
3209 mTodoEditor->newTodo(QDateTime(),parentEvent,true); 3210 mTodoEditor->newTodo(QDateTime(),parentEvent,true);
3210 mTodoEditor->exec(); 3211 mTodoEditor->exec();
3211 setActiveWindow(); 3212 setActiveWindow();
3212} 3213}
3213 3214
3214void CalendarView::newFloatingEvent() 3215void CalendarView::newFloatingEvent()
3215{ 3216{
3216 DateList tmpList = mNavigator->selectedDates(); 3217 DateList tmpList = mNavigator->selectedDates();
3217 QDate date = tmpList.first(); 3218 QDate date = tmpList.first();
3218 3219
3219 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 3220 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
3220 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 3221 QDateTime( date, QTime( 12, 0, 0 ) ), true );
3221} 3222}
3222 3223
3223 3224
3224void CalendarView::editEvent( Event *event ) 3225void CalendarView::editEvent( Event *event )
3225{ 3226{
3226 3227
3227 if ( !event ) return; 3228 if ( !event ) return;
3228 if ( event->isReadOnly() ) { 3229 if ( event->isReadOnly() ) {
3229 showEvent( event ); 3230 showEvent( event );
3230 return; 3231 return;
3231 } 3232 }
3232 showEventEditor(); 3233 showEventEditor();
3233 mEventEditor->editEvent( event , mFlagEditDescription); 3234 mEventEditor->editEvent( event , mFlagEditDescription);
3234 mEventEditor->exec(); 3235 mEventEditor->exec();
3235 setActiveWindow(); 3236 setActiveWindow();
3236 3237
3237} 3238}
3238void CalendarView::editJournal( Journal *jour ) 3239void CalendarView::editJournal( Journal *jour )
3239{ 3240{
3240 if ( !jour ) return; 3241 if ( !jour ) return;
3241 mDialogManager->hideSearchDialog(); 3242 mDialogManager->hideSearchDialog();
3242 mViewManager->showJournalView(); 3243 mViewManager->showJournalView();
3243 mNavigator->slotDaySelect( jour->dtStart().date() ); 3244 mNavigator->slotDaySelect( jour->dtStart().date() );
3244} 3245}
3245void CalendarView::editTodo( Todo *todo ) 3246void CalendarView::editTodo( Todo *todo )
3246{ 3247{
3247 if ( !todo ) return; 3248 if ( !todo ) return;
3248 3249
3249 if ( todo->isReadOnly() ) { 3250 if ( todo->isReadOnly() ) {
3250 showTodo( todo ); 3251 showTodo( todo );
3251 return; 3252 return;
3252 } 3253 }
3253 showTodoEditor(); 3254 showTodoEditor();
3254 mTodoEditor->editTodo( todo ,mFlagEditDescription); 3255 mTodoEditor->editTodo( todo ,mFlagEditDescription);
3255 mTodoEditor->exec(); 3256 mTodoEditor->exec();
3256 setActiveWindow(); 3257 setActiveWindow();
3257 3258
3258} 3259}
3259 3260
3260KOEventViewerDialog* CalendarView::getEventViewerDialog() 3261KOEventViewerDialog* CalendarView::getEventViewerDialog()
3261{ 3262{
3262 if ( !mEventViewerDialog ) { 3263 if ( !mEventViewerDialog ) {
3263 mEventViewerDialog = new KOEventViewerDialog(0); 3264 mEventViewerDialog = new KOEventViewerDialog(0);
3264 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 3265 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
3265 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 3266 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
3266 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 3267 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
3267 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 3268 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
3268 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 3269 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
3269 viewManager(), SLOT( showAgendaView( bool ) ) ); 3270 viewManager(), SLOT( showAgendaView( bool ) ) );
3270 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()), 3271 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()),
3271 this, SLOT( slotViewerClosed() ) ); 3272 this, SLOT( slotViewerClosed() ) );
3272 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ), 3273 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ),
3273 this, SLOT( todoChanged(Todo *) ) ); 3274 this, SLOT( todoChanged(Todo *) ) );
3274 mEventViewerDialog->resize( 640, 480 ); 3275 mEventViewerDialog->resize( 640, 480 );
3275 3276
3276 } 3277 }
3277 return mEventViewerDialog; 3278 return mEventViewerDialog;
3278} 3279}
3279void CalendarView::showEvent(Event *event) 3280void CalendarView::showEvent(Event *event)
3280{ 3281{
3281 getEventViewerDialog()->setEvent(event); 3282 getEventViewerDialog()->setEvent(event);
3282 getEventViewerDialog()->showMe(); 3283 getEventViewerDialog()->showMe();
3283} 3284}
3284 3285
3285void CalendarView::showTodo(Todo *event) 3286void CalendarView::showTodo(Todo *event)
3286{ 3287{
3287 getEventViewerDialog()->setTodo(event); 3288 getEventViewerDialog()->setTodo(event);
3288 getEventViewerDialog()->showMe(); 3289 getEventViewerDialog()->showMe();
3289} 3290}
3290void CalendarView::showJournal( Journal *jour ) 3291void CalendarView::showJournal( Journal *jour )
3291{ 3292{
3292 getEventViewerDialog()->setJournal(jour); 3293 getEventViewerDialog()->setJournal(jour);
3293 getEventViewerDialog()->showMe(); 3294 getEventViewerDialog()->showMe();
3294 3295
3295} 3296}
3296// void CalendarView::todoModified (Todo *event, int changed) 3297// void CalendarView::todoModified (Todo *event, int changed)
3297// { 3298// {
3298// // if (mDialogList.find (event) != mDialogList.end ()) { 3299// // if (mDialogList.find (event) != mDialogList.end ()) {
3299// // kdDebug() << "Todo modified and open" << endl; 3300// // kdDebug() << "Todo modified and open" << endl;
3300// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 3301// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
3301// // temp->modified (changed); 3302// // temp->modified (changed);
3302 3303
3303// // } 3304// // }
3304 3305
3305// mViewManager->updateView(); 3306// mViewManager->updateView();
3306// } 3307// }
3307 3308
3308void CalendarView::appointment_show() 3309void CalendarView::appointment_show()
3309{ 3310{
3310 Event *anEvent = 0; 3311 Event *anEvent = 0;
3311 3312
3312 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3313 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3313 3314
3314 if (mViewManager->currentView()->isEventView()) { 3315 if (mViewManager->currentView()->isEventView()) {
3315 if ( incidence && incidence->typeID() == eventID ) { 3316 if ( incidence && incidence->typeID() == eventID ) {
3316 anEvent = static_cast<Event *>(incidence); 3317 anEvent = static_cast<Event *>(incidence);
3317 } 3318 }
3318 } 3319 }
3319 3320
3320 if (!anEvent) { 3321 if (!anEvent) {
3321 KNotifyClient::beep(); 3322 KNotifyClient::beep();
3322 return; 3323 return;
3323 } 3324 }
3324 3325
3325 showEvent(anEvent); 3326 showEvent(anEvent);
3326} 3327}
3327 3328
3328void CalendarView::appointment_edit() 3329void CalendarView::appointment_edit()
3329{ 3330{
3330 Event *anEvent = 0; 3331 Event *anEvent = 0;
3331 3332
3332 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3333 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3333 3334
3334 if (mViewManager->currentView()->isEventView()) { 3335 if (mViewManager->currentView()->isEventView()) {
3335 if ( incidence && incidence->typeID() == eventID ) { 3336 if ( incidence && incidence->typeID() == eventID ) {
3336 anEvent = static_cast<Event *>(incidence); 3337 anEvent = static_cast<Event *>(incidence);
3337 } 3338 }
3338 } 3339 }
3339 3340
3340 if (!anEvent) { 3341 if (!anEvent) {
3341 KNotifyClient::beep(); 3342 KNotifyClient::beep();
3342 return; 3343 return;
3343 } 3344 }
3344 3345
3345 editEvent(anEvent); 3346 editEvent(anEvent);
3346} 3347}
3347 3348
3348void CalendarView::appointment_delete() 3349void CalendarView::appointment_delete()
3349{ 3350{
3350 Event *anEvent = 0; 3351 Event *anEvent = 0;
3351 3352
3352 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3353 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3353 3354
3354 if (mViewManager->currentView()->isEventView()) { 3355 if (mViewManager->currentView()->isEventView()) {
3355 if ( incidence && incidence->typeID() == eventID ) { 3356 if ( incidence && incidence->typeID() == eventID ) {
3356 anEvent = static_cast<Event *>(incidence); 3357 anEvent = static_cast<Event *>(incidence);
3357 } 3358 }
3358 } 3359 }
3359 3360
3360 if (!anEvent) { 3361 if (!anEvent) {
3361 KNotifyClient::beep(); 3362 KNotifyClient::beep();
3362 return; 3363 return;
3363 } 3364 }
3364 3365
3365 deleteEvent(anEvent); 3366 deleteEvent(anEvent);
3366} 3367}
3367 3368
3368void CalendarView::todo_resub( Todo * parent, Todo * sub ) 3369void CalendarView::todo_resub( Todo * parent, Todo * sub )
3369{ 3370{
3370 if (!sub) return; 3371 if (!sub) return;
3371 if ( sub->relatedTo() == parent ) 3372 if ( sub->relatedTo() == parent )
3372 return; 3373 return;
3373 sub->setRelatedTo(parent); 3374 sub->setRelatedTo(parent);
3374 sub->updated(); 3375 sub->updated();
3375 setModified(true); 3376 setModified(true);
3376 updateView(); 3377 updateView();
3377} 3378}
3378void CalendarView::todo_unsub(Todo *anTodo ) 3379void CalendarView::todo_unsub(Todo *anTodo )
3379{ 3380{
3380 todo_resub( 0, anTodo ); 3381 todo_resub( 0, anTodo );
3381} 3382}
3382 3383
3383void CalendarView::deleteTodo(Todo *todo) 3384void CalendarView::deleteTodo(Todo *todo)
3384{ 3385{
3385 if (!todo) { 3386 if (!todo) {
3386 KNotifyClient::beep(); 3387 KNotifyClient::beep();
3387 return; 3388 return;
3388 } 3389 }
3389 if (KOPrefs::instance()->mConfirm) { 3390 if (KOPrefs::instance()->mConfirm) {
3390 QString text = todo->summary().left(20); 3391 QString text = todo->summary().left(20);
3391 if (!todo->relations().isEmpty()) { 3392 if (!todo->relations().isEmpty()) {
3392 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!"); 3393 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!");
3393 3394
3394 } 3395 }
3395 switch (msgItemDelete(text)) { 3396 switch (msgItemDelete(text)) {
3396 case KMessageBox::Continue: // OK 3397 case KMessageBox::Continue: // OK
3397 bool deleteT = false; 3398 bool deleteT = false;
3398 if (!todo->relations().isEmpty()) { 3399 if (!todo->relations().isEmpty()) {
3399 deleteT = removeCompletedSubTodos( todo ); 3400 deleteT = removeCompletedSubTodos( todo );
3400 } 3401 }
3401 // deleteT == true: todo already deleted in removeCompletedSubTodos 3402 // deleteT == true: todo already deleted in removeCompletedSubTodos
3402 if ( !deleteT ) { 3403 if ( !deleteT ) {
3403 checkExternalId( todo ); 3404 checkExternalId( todo );
3404 calendar()->deleteTodo(todo); 3405 calendar()->deleteTodo(todo);
3405 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3406 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3406 updateView(); 3407 updateView();
3407 } 3408 }
3408 break; 3409 break;
3409 } // switch 3410 } // switch
3410 } else { 3411 } else {
3411 checkExternalId( todo ); 3412 checkExternalId( todo );
3412 mCalendar->deleteTodo(todo); 3413 mCalendar->deleteTodo(todo);
3413 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3414 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3414 updateView(); 3415 updateView();
3415 } 3416 }
3416 3417
3417 emit updateSearchDialog(); 3418 emit updateSearchDialog();
3418} 3419}
3419void CalendarView::deleteJournal(Journal *jour) 3420void CalendarView::deleteJournal(Journal *jour)
3420{ 3421{
3421 if (!jour) { 3422 if (!jour) {
3422 KNotifyClient::beep(); 3423 KNotifyClient::beep();
3423 return; 3424 return;
3424 } 3425 }
3425 if (KOPrefs::instance()->mConfirm) { 3426 if (KOPrefs::instance()->mConfirm) {
3426 switch (msgItemDelete( jour->description().left(20))) { 3427 switch (msgItemDelete( jour->description().left(20))) {
3427 case KMessageBox::Continue: // OK 3428 case KMessageBox::Continue: // OK
3428 calendar()->deleteJournal(jour); 3429 calendar()->deleteJournal(jour);
3429 updateView(); 3430 updateView();
3430 break; 3431 break;
3431 } // switch 3432 } // switch
3432 } else { 3433 } else {
3433 calendar()->deleteJournal(jour);; 3434 calendar()->deleteJournal(jour);;
3434 updateView(); 3435 updateView();
3435 } 3436 }
3436 emit updateSearchDialog(); 3437 emit updateSearchDialog();
3437} 3438}
3438 3439
3439void CalendarView::deleteEvent(Event *anEvent) 3440void CalendarView::deleteEvent(Event *anEvent)
3440{ 3441{
3441 if (!anEvent) { 3442 if (!anEvent) {
3442 KNotifyClient::beep(); 3443 KNotifyClient::beep();
3443 return; 3444 return;
3444 } 3445 }
3445 3446
3446 if (anEvent->recurrence()->doesRecur()) { 3447 if (anEvent->recurrence()->doesRecur()) {
3447 QDate itemDate = mViewManager->currentSelectionDate(); 3448 QDate itemDate = mViewManager->currentSelectionDate();
3448 int km; 3449 int km;
3449 if (!itemDate.isValid()) { 3450 if (!itemDate.isValid()) {
3450 //kdDebug() << "Date Not Valid" << endl; 3451 //kdDebug() << "Date Not Valid" << endl;
3451 if (KOPrefs::instance()->mConfirm) { 3452 if (KOPrefs::instance()->mConfirm) {
3452 km = KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) + 3453 km = KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) +
3453 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 3454 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
3454 i18n("KO/Pi Confirmation"),i18n("Delete All")); 3455 i18n("KO/Pi Confirmation"),i18n("Delete All"));
3455 if ( km == KMessageBox::Continue ) 3456 if ( km == KMessageBox::Continue )
3456 km = KMessageBox::No; // No = all below 3457 km = KMessageBox::No; // No = all below
3457 } else 3458 } else
3458 km = KMessageBox::No; 3459 km = KMessageBox::No;
3459 } else { 3460 } else {
3460 km = KMessageBox::warningYesNoCancel(this,anEvent->summary().left(25) + 3461 km = KMessageBox::warningYesNoCancel(this,anEvent->summary().left(25) +
3461 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 3462 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
3462 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 3463 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
3463 i18n("KO/Pi Confirmation"),i18n("Current"), 3464 i18n("KO/Pi Confirmation"),i18n("Current"),
3464 i18n("All")); 3465 i18n("All"));
3465 } 3466 }
3466 switch(km) { 3467 switch(km) {
3467 3468
3468 case KMessageBox::No: // Continue // all 3469 case KMessageBox::No: // Continue // all
3469 //qDebug("KMessageBox::No "); 3470 //qDebug("KMessageBox::No ");
3470 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3471 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3471 schedule(Scheduler::Cancel,anEvent); 3472 schedule(Scheduler::Cancel,anEvent);
3472 3473
3473 checkExternalId( anEvent); 3474 checkExternalId( anEvent);
3474 mCalendar->deleteEvent(anEvent); 3475 mCalendar->deleteEvent(anEvent);
3475 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 3476 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
3476 break; 3477 break;
3477 3478
3478 // Disabled because it does not work 3479 // Disabled because it does not work
3479 //#if 0 3480 //#if 0
3480 case KMessageBox::Yes: // just this one 3481 case KMessageBox::Yes: // just this one
3481 //QDate qd = mNavigator->selectedDates().first(); 3482 //QDate qd = mNavigator->selectedDates().first();
3482 //if (!qd.isValid()) { 3483 //if (!qd.isValid()) {
3483 // kdDebug() << "no date selected, or invalid date" << endl; 3484 // kdDebug() << "no date selected, or invalid date" << endl;
3484 // KNotifyClient::beep(); 3485 // KNotifyClient::beep();
3485 // return; 3486 // return;
3486 //} 3487 //}
3487 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 3488 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
3488 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 3489 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
3489 anEvent->addExDate(itemDate); 3490 anEvent->addExDate(itemDate);
3490 int duration = anEvent->recurrence()->duration(); 3491 int duration = anEvent->recurrence()->duration();
3491 if ( duration > 0 ) { 3492 if ( duration > 0 ) {
3492 anEvent->recurrence()->setDuration( duration - 1 ); 3493 anEvent->recurrence()->setDuration( duration - 1 );
3493 } 3494 }
3494 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 3495 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
3495 } 3496 }
3496 break; 3497 break;
3497 //#endif 3498 //#endif
3498 } // switch 3499 } // switch
3499 } else { 3500 } else {
3500 if (KOPrefs::instance()->mConfirm) { 3501 if (KOPrefs::instance()->mConfirm) {
3501 switch (KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) + 3502 switch (KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) +
3502 i18n("\nAre you sure you want\nto delete this event?"), 3503 i18n("\nAre you sure you want\nto delete this event?"),
3503 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 3504 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
3504 case KMessageBox::Continue: // OK 3505 case KMessageBox::Continue: // OK
3505 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3506 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3506 schedule(Scheduler::Cancel,anEvent); 3507 schedule(Scheduler::Cancel,anEvent);
3507 checkExternalId( anEvent); 3508 checkExternalId( anEvent);
3508 mCalendar->deleteEvent(anEvent); 3509 mCalendar->deleteEvent(anEvent);
3509 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3510 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3510 break; 3511 break;
3511 } // switch 3512 } // switch
3512 } else { 3513 } else {
3513 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3514 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3514 schedule(Scheduler::Cancel,anEvent); 3515 schedule(Scheduler::Cancel,anEvent);
3515 checkExternalId( anEvent); 3516 checkExternalId( anEvent);
3516 mCalendar->deleteEvent(anEvent); 3517 mCalendar->deleteEvent(anEvent);
3517 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3518 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3518 } 3519 }
3519 } // if-else 3520 } // if-else
3520 emit updateSearchDialog(); 3521 emit updateSearchDialog();
3521} 3522}
3522 3523
3523bool CalendarView::deleteEvent(const QString &uid) 3524bool CalendarView::deleteEvent(const QString &uid)
3524{ 3525{
3525 Event *ev = mCalendar->event(uid); 3526 Event *ev = mCalendar->event(uid);
3526 if (ev) { 3527 if (ev) {
3527 deleteEvent(ev); 3528 deleteEvent(ev);
3528 return true; 3529 return true;
3529 } else { 3530 } else {
3530 return false; 3531 return false;
3531 } 3532 }
3532} 3533}
3533 3534
3534/*****************************************************************************/ 3535/*****************************************************************************/
3535 3536
3536void CalendarView::action_mail() 3537void CalendarView::action_mail()
3537{ 3538{
diff --git a/korganizer/journalentry.cpp b/korganizer/journalentry.cpp
index c19a5ca..7274849 100644
--- a/korganizer/journalentry.cpp
+++ b/korganizer/journalentry.cpp
@@ -1,250 +1,287 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24// 24//
25// Journal Entry 25// Journal Entry
26 26
27#include <qlabel.h> 27#include <qlabel.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#include <qvbox.h> 29#include <qvbox.h>
30#include <qfile.h> 30#include <qfile.h>
31#include <qdir.h> 31#include <qdir.h>
32#include <qtextstream.h> 32#include <qtextstream.h>
33#include <qtextcodec.h> 33#include <qtextcodec.h>
34#include <qpixmap.h> 34#include <qpixmap.h>
35#include <qpushbutton.h> 35#include <qpushbutton.h>
36#include <qapplication.h> 36#include <qapplication.h>
37 37
38#include <kdebug.h> 38#include <kdebug.h>
39#include <kglobal.h> 39#include <kglobal.h>
40#include <klocale.h> 40#include <klocale.h>
41#include <ktextedit.h> 41#include <ktextedit.h>
42#include <kfiledialog.h> 42#include <kfiledialog.h>
43#include <kmessagebox.h> 43#include <kmessagebox.h>
44#include "koprefs.h" 44#include "koprefs.h"
45 45
46#include <libkcal/journal.h> 46#include <libkcal/journal.h>
47#include <libkcal/calendarresources.h> 47#include <libkcal/calendarresources.h>
48#include <libkcal/resourcecalendar.h> 48#include <libkcal/resourcecalendar.h>
49#include <kresources/resourceselectdialog.h> 49#include <kresources/resourceselectdialog.h>
50 50
51#include "journalentry.h" 51#include "journalentry.h"
52//#include "journalentry.moc" 52//#include "journalentry.moc"
53#ifndef DESKTOP_VERSION 53#ifndef DESKTOP_VERSION
54#include <qpe/qpeapplication.h> 54#include <qpe/qpeapplication.h>
55#endif 55#endif
56JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : 56JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) :
57 QFrame(parent) 57 QFrame(parent)
58{ 58{
59 showOnlyMode = false;
59 mCalendar = calendar; 60 mCalendar = calendar;
60 mJournal = 0; 61 mJournal = 0;
61 mDirty = false; 62 mDirty = false;
62 63
63 QHBox * vb = new QHBox ( this ); 64 QHBox * vb = new QHBox ( this );
65 QPushButton * newJournal = new QPushButton( vb );
66 QIconSet icon;
67 if ( QApplication::desktop()->width() < 321 )
68 icon = SmallIcon("ko16old");
69 else
70 icon = SmallIcon("ko24old");
71 newJournal->setIconSet (icon ) ;
72 int size = newJournal->sizeHint().height();
73 newJournal->setFixedSize( size, size );
74
75
76 QPushButton * toggleJournal = new QPushButton( vb );
77 icon = SmallIcon("1updownarrow");
78 toggleJournal->setIconSet (icon ) ;
79 //int size = toggleJournal->sizeHint().height();
80 toggleJournal->setFixedSize( size * 2 /3 , size );
81
82
83
84 mTitleLabel = new QLabel(i18n("Title"),vb);
85 mTitleLabel->setMargin(2);
86 mTitleLabel->setAlignment(AlignCenter);
64 QPushButton * loadTemplate = new QPushButton( vb ); 87 QPushButton * loadTemplate = new QPushButton( vb );
65 QPushButton * saveTemplate = new QPushButton( vb ); 88 QPushButton * saveTemplate = new QPushButton( vb );
66 QIconSet icon;
67 if ( QApplication::desktop()->width() < 321 ) 89 if ( QApplication::desktop()->width() < 321 )
68 icon = SmallIcon("fileexport16"); 90 icon = SmallIcon("fileexport16");
69 else 91 else
70 icon = SmallIcon("fileexport"); 92 icon = SmallIcon("fileexport");
71 saveTemplate->setIconSet (icon ) ; 93 saveTemplate->setIconSet (icon ) ;
72 int size = saveTemplate->sizeHint().height(); 94 //size = saveTemplate->sizeHint().height();
73 saveTemplate->setFixedSize( size, size ); 95 saveTemplate->setFixedSize( size, size );
74 if ( QApplication::desktop()->width() < 321 ) 96 if ( QApplication::desktop()->width() < 321 )
75 icon = SmallIcon("fileimport16"); 97 icon = SmallIcon("fileimport16");
76 else 98 else
77 icon = SmallIcon("fileimport"); 99 icon = SmallIcon("fileimport");
78 loadTemplate->setIconSet (icon ) ; 100 loadTemplate->setIconSet (icon ) ;
79 loadTemplate->setFixedSize( size, size ); 101 loadTemplate->setFixedSize( size, size );
80
81 mTitleLabel = new QLabel(i18n("Title"),vb);
82 mTitleLabel->setMargin(2);
83 mTitleLabel->setAlignment(AlignCenter);
84
85 mEditor = new KTextEdit(this); 102 mEditor = new KTextEdit(this);
86 connect(mEditor,SIGNAL(textChanged()),SLOT(setDirty())); 103 connect(mEditor,SIGNAL(textChanged()),SLOT(setDirty()));
87#ifndef DESKTOP_VERSION 104#ifndef DESKTOP_VERSION
88 QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold ); 105 QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold );
89#endif 106#endif
90 mEditor->setWordWrap( KTextEdit::WidgetWidth ); 107 mEditor->setWordWrap( KTextEdit::WidgetWidth );
91 QBoxLayout *topLayout = new QVBoxLayout(this); 108 QBoxLayout *topLayout = new QVBoxLayout(this);
92 topLayout->addWidget(vb); 109 topLayout->addWidget(vb);
93 topLayout->addWidget(mEditor); 110 topLayout->addWidget(mEditor);
94 mEditor->installEventFilter(this); 111 mEditor->installEventFilter(this);
95 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); 112 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) );
96 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); 113 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) );
114 connect( newJournal, SIGNAL( clicked() ), this , SIGNAL( newJournal() ) );
115 connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) );
97} 116}
98 117
99JournalEntry::~JournalEntry() 118JournalEntry::~JournalEntry()
100{ 119{
101} 120}
102 121
103void JournalEntry::slotSaveTemplate() 122void JournalEntry::slotSaveTemplate()
104{ 123{
105 QString fileName =locateLocal( "templates", "journals" ); 124 QString fileName =locateLocal( "templates", "journals" );
106 QDir t_dir; 125 QDir t_dir;
107 if ( !t_dir.exists(fileName) ) 126 if ( !t_dir.exists(fileName) )
108 t_dir.mkdir ( fileName ); 127 t_dir.mkdir ( fileName );
109 fileName += "/journal"; 128 fileName += "/journal";
110 fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this ); 129 fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this );
111 if ( fileName.length() == 0 ) 130 if ( fileName.length() == 0 )
112 return; 131 return;
113 132
114 QFile fileIn( fileName ); 133 QFile fileIn( fileName );
115 if (!fileIn.open( IO_WriteOnly ) ) { 134 if (!fileIn.open( IO_WriteOnly ) ) {
116 KMessageBox::error( this, i18n("Error saving template file\n '%1'.") 135 KMessageBox::error( this, i18n("Error saving template file\n '%1'.")
117 .arg( fileName ) ); 136 .arg( fileName ) );
118 return; 137 return;
119 } 138 }
120 // QString text; 139 // QString text;
121 QTextStream tsIn( &fileIn ); 140 QTextStream tsIn( &fileIn );
122 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 141 tsIn.setCodec( QTextCodec::codecForName("utf8") );
123 tsIn << mEditor->text(); 142 tsIn << mEditor->text();
124 fileIn.close(); 143 fileIn.close();
125} 144}
126void JournalEntry::slotLoadTemplate() 145void JournalEntry::slotLoadTemplate()
127{ 146{
128 QString fileName =locateLocal( "templates", "journals" ); 147 QString fileName =locateLocal( "templates", "journals" );
129 QDir t_dir; 148 QDir t_dir;
130 if ( !t_dir.exists(fileName) ) 149 if ( !t_dir.exists(fileName) )
131 t_dir.mkdir ( fileName ); 150 t_dir.mkdir ( fileName );
132 fileName += "/journal"; 151 fileName += "/journal";
133 fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this ); 152 fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this );
134 if ( fileName.length() == 0 ) 153 if ( fileName.length() == 0 )
135 return; 154 return;
136 QFile fileIn( fileName ); 155 QFile fileIn( fileName );
137 if (!fileIn.open( IO_ReadOnly ) ) { 156 if (!fileIn.open( IO_ReadOnly ) ) {
138 KMessageBox::error( this, i18n("Error loading template file\n '%1'.") 157 KMessageBox::error( this, i18n("Error loading template file\n '%1'.")
139 .arg( fileName ) ); 158 .arg( fileName ) );
140 return; 159 return;
141 } 160 }
142 QTextStream tsIn( &fileIn ); 161 QTextStream tsIn( &fileIn );
143 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 162 tsIn.setCodec( QTextCodec::codecForName("utf8") );
144 QString text = tsIn.read(); 163 QString text = tsIn.read();
145 fileIn.close(); 164 fileIn.close();
146 int line, col; 165 int line, col;
147 mEditor->getCursorPosition (& line, & col ); 166 mEditor->getCursorPosition (& line, & col );
148 mEditor-> insertAt ( text, line, col, true ); 167 mEditor-> insertAt ( text, line, col, true );
149 //mEditor->setIgnoreMark( true ); 168 //mEditor->setIgnoreMark( true );
150 setDirty(); 169 setDirty();
151} 170}
152void JournalEntry::setDate(const QDate &date) 171void JournalEntry::setDate(const QDate &date)
153{ 172{
173 showOnlyMode = false;
174 mDate = date;
154 writeJournal(); 175 writeJournal();
176 int id = mCalendar->defaultCalendar();
177 if ( id == 1 ) {
178 mTitleLabel->setText(KGlobal::locale()->formatDate(date));
179 } else {
180 QString calname = KOPrefs::instance()->getCalendar( id )->mName;
181 mTitleLabel->setText( KGlobal::locale()->formatDate(mDate,true) + " (" + calname +")");
182 }
183}
155 184
156 mTitleLabel->setText(KGlobal::locale()->formatDate(date)); 185void JournalEntry::toggleShowJournal()
157 186{
158 187 if ( showOnlyMode )
159 mDate = date; 188 emit showJournalOnly( 0 );
189 else
190 emit showJournalOnly( mJournal );
160} 191}
161 192
162void JournalEntry::setJournal(Journal *journal) 193void JournalEntry::setJournal(Journal *journal)
163{ 194{
164 writeJournal(); 195 writeJournal();
165 196
166 mJournal = journal; 197 mJournal = journal;
167 198
168 mEditor->setText(mJournal->description()); 199 mEditor->setText(mJournal->description());
169 200 int id = mJournal->calID();
201 if ( id > 1 ) {
202 QString calname = KOPrefs::instance()->getCalendar( id )->mName;
203 mTitleLabel->setText( KGlobal::locale()->formatDate(mDate,true) + " (" + calname +")");
204 } else {
205 mTitleLabel->setText(KGlobal::locale()->formatDate(mDate));
206 }
170 mDirty = false; 207 mDirty = false;
171} 208}
172 209
173Journal *JournalEntry::journal() const 210Journal *JournalEntry::journal() const
174{ 211{
175 return mJournal; 212 return mJournal;
176} 213}
177 214
178void JournalEntry::setDirty() 215void JournalEntry::setDirty()
179{ 216{
180 mDirty = true; 217 mDirty = true;
181 218
182// kdDebug() << "JournalEntry::setDirty()" << endl; 219// kdDebug() << "JournalEntry::setDirty()" << endl;
183} 220}
184 221
185void JournalEntry::clear() 222void JournalEntry::clear()
186{ 223{
187 mJournal = 0; 224 mJournal = 0;
188 mEditor->setText(""); 225 mEditor->setText("");
189} 226}
190 227
191bool JournalEntry::eventFilter( QObject *o, QEvent *e ) 228bool JournalEntry::eventFilter( QObject *o, QEvent *e )
192{ 229{
193// kdDebug() << "JournalEntry::event received " << e->type() << endl; 230// kdDebug() << "JournalEntry::event received " << e->type() << endl;
194 231
195 if ( e->type() == QEvent::FocusOut ) { 232 if ( e->type() == QEvent::FocusOut ) {
196 writeJournal(); 233 writeJournal();
197 } 234 }
198 if ( e->type() == QEvent::KeyPress ) { 235 if ( e->type() == QEvent::KeyPress ) {
199 QKeyEvent * k = (QKeyEvent *) e; 236 QKeyEvent * k = (QKeyEvent *) e;
200 if ( k->state() == Qt::ControlButton ) { 237 if ( k->state() == Qt::ControlButton ) {
201 k->ignore(); 238 k->ignore();
202 //return true; 239 //return true;
203 } 240 }
204 } 241 }
205 242
206 return QFrame::eventFilter( o, e ); // standard event processing 243 return QFrame::eventFilter( o, e ); // standard event processing
207} 244}
208 245
209void JournalEntry::writeJournal() 246void JournalEntry::writeJournal()
210{ 247{
211// kdDebug() << "JournalEntry::writeJournal()" << endl; 248// kdDebug() << "JournalEntry::writeJournal()" << endl;
212 if (!mDirty) return; 249 if (!mDirty) return;
213 250
214 if (mEditor->text().isEmpty()) { 251 if (mEditor->text().isEmpty()) {
215 if ( mJournal ) { 252 if ( mJournal ) {
216 mDirty = false; 253 mDirty = false;
217 bool conf = KOPrefs::instance()->mConfirm; 254 bool conf = KOPrefs::instance()->mConfirm;
218 KOPrefs::instance()->mConfirm = false; 255 KOPrefs::instance()->mConfirm = false;
219 emit deleteJournal(mJournal); 256 emit deleteJournal(mJournal);
220 KOPrefs::instance()->mConfirm = conf; 257 KOPrefs::instance()->mConfirm = conf;
221 mJournal = 0; 258 mJournal = 0;
222 } 259 }
223 return; 260 return;
224 } 261 }
225 262
226// kdDebug() << "JournalEntry::writeJournal()..." << endl; 263// kdDebug() << "JournalEntry::writeJournal()..." << endl;
227 264
228 if (!mJournal) { 265 if (!mJournal) {
229 mJournal = new Journal; 266 mJournal = new Journal;
230 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0))); 267 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0)));
231 mCalendar->addJournal(mJournal); 268 mCalendar->addJournal(mJournal);
232 } 269 }
233 270
234 mJournal->setDescription(mEditor->text()); 271 mJournal->setDescription(mEditor->text());
235 //qDebug("tttt%s ", mEditor->text().latin1()); 272 //qDebug("tttt%s ", mEditor->text().latin1());
236 273
237 mDirty = false; 274 mDirty = false;
238} 275}
239 276
240void JournalEntry::flushEntry() 277void JournalEntry::flushEntry()
241{ 278{
242 if (!mDirty) return; 279 if (!mDirty) return;
243 280
244 writeJournal(); 281 writeJournal();
245} 282}
246void JournalEntry::keyPressEvent ( QKeyEvent * e ) 283void JournalEntry::keyPressEvent ( QKeyEvent * e )
247{ 284{
248 e->ignore(); 285 e->ignore();
249 286
250} 287}
diff --git a/korganizer/journalentry.h b/korganizer/journalentry.h
index f1a1fef..85ad5df 100644
--- a/korganizer/journalentry.h
+++ b/korganizer/journalentry.h
@@ -1,75 +1,80 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23#ifndef JOURNALENTRY_H 23#ifndef JOURNALENTRY_H
24#define JOURNALENTRY_H 24#define JOURNALENTRY_H
25// 25//
26// Widget showing one Journal entry 26// Widget showing one Journal entry
27 27
28#include <qframe.h> 28#include <qframe.h>
29 29
30#include <libkcal/calendar.h> 30#include <libkcal/calendar.h>
31 31
32class QLabel; 32class QLabel;
33class KTextEdit; 33class KTextEdit;
34 34
35using namespace KCal; 35using namespace KCal;
36 36
37class JournalEntry : public QFrame { 37class JournalEntry : public QFrame {
38 Q_OBJECT 38 Q_OBJECT
39 public: 39 public:
40 JournalEntry(Calendar *,QWidget *parent); 40 JournalEntry(Calendar *,QWidget *parent);
41 virtual ~JournalEntry(); 41 virtual ~JournalEntry();
42 42
43 void setJournal(Journal *); 43 void setJournal(Journal *);
44 Journal *journal() const; 44 Journal *journal() const;
45 45
46 void setDate(const QDate &); 46 void setDate(const QDate &);
47 47
48 void clear(); 48 void clear();
49 49
50 void flushEntry(); 50 void flushEntry();
51 void setShowOnly() {showOnlyMode = true;}
51 52
52 protected slots: 53 protected slots:
53 void slotSaveTemplate(); 54 void slotSaveTemplate();
54 void slotLoadTemplate(); 55 void slotLoadTemplate();
55 void setDirty(); 56 void setDirty();
57 void toggleShowJournal();
56 signals: 58 signals:
57 void deleteJournal(Journal *); 59 void deleteJournal(Journal *);
60 void newJournal();
61 void showJournalOnly( Journal * );
58 62
59 protected: 63 protected:
60 bool eventFilter( QObject *o, QEvent *e ); 64 bool eventFilter( QObject *o, QEvent *e );
61 65
62 void writeJournal(); 66 void writeJournal();
63 67
64 private: 68 private:
69 bool showOnlyMode;
65 Calendar *mCalendar; 70 Calendar *mCalendar;
66 Journal *mJournal; 71 Journal *mJournal;
67 QDate mDate; 72 QDate mDate;
68 void keyPressEvent ( QKeyEvent * ) ; 73 void keyPressEvent ( QKeyEvent * ) ;
69 QLabel *mTitleLabel; 74 QLabel *mTitleLabel;
70 KTextEdit *mEditor; 75 KTextEdit *mEditor;
71 76
72 bool mDirty; 77 bool mDirty;
73}; 78};
74 79
75#endif 80#endif
diff --git a/korganizer/kojournalview.cpp b/korganizer/kojournalview.cpp
index bc16037..fae59d6 100644
--- a/korganizer/kojournalview.cpp
+++ b/korganizer/kojournalview.cpp
@@ -1,116 +1,188 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24// 24//
25// View of Journal entries 25// View of Journal entries
26 26
27#include <qlayout.h> 27#include <qlayout.h>
28#include <qpopupmenu.h> 28#include <qpopupmenu.h>
29 29
30#include <klocale.h> 30#include <klocale.h>
31#include <kdebug.h> 31#include <kdebug.h>
32#include "koprefs.h" 32#include "koprefs.h"
33 33
34#include <libkcal/calendar.h> 34#include <libkcal/calendar.h>
35 35
36#include "journalentry.h" 36#include "journalentry.h"
37 37
38#include "kojournalview.h" 38#include "kojournalview.h"
39using namespace KOrg; 39using namespace KOrg;
40 40
41KOJournalView::KOJournalView(Calendar *calendar, QWidget *parent, 41KOJournalView::KOJournalView(Calendar *calendar, QWidget *parent,
42 const char *name) 42 const char *name)
43 : KOrg::BaseView(calendar, parent, name) 43 : KOrg::BaseView(calendar, parent, name)
44{ 44{
45 mEntry = new JournalEntry(calendar,this); 45 mCalendar = calendar;
46 mEntry->setFont ( KOPrefs::instance()->mJornalViewFont ); 46 mTopLayout = new QVBoxLayout(this);
47 QBoxLayout *topLayout = new QVBoxLayout(this); 47 getNewEntry();
48 topLayout->addWidget(mEntry);
49 connect ( mEntry,SIGNAL(deleteJournal(Journal *) ),this ,SIGNAL(deleteJournal(Journal *) ) ) ;
50} 48}
51 49
52KOJournalView::~KOJournalView() 50KOJournalView::~KOJournalView()
53{ 51{
54} 52}
55 53
56int KOJournalView::currentDateCount() 54int KOJournalView::currentDateCount()
57{ 55{
58 return 0; 56 return 0;
59} 57}
58JournalEntry* KOJournalView::getNewEntry()
59{
60 JournalEntry* Entry = new JournalEntry(mCalendar,this);
61 jEntries.append( Entry );
62 mTopLayout->addWidget(Entry);
63 Entry->setFont ( KOPrefs::instance()->mJornalViewFont );
64 connect ( Entry,SIGNAL(deleteJournal(Journal *) ),this ,SIGNAL(deleteJournal(Journal *) ) ) ;
65 connect ( Entry,SIGNAL(newJournal() ),this ,SLOT(newJournal() ) ) ;
66 connect ( Entry,SIGNAL(showJournalOnly( Journal * ) ),this ,SLOT(showOnly ( Journal* ) ) ) ;
67 return Entry;
68}
60 69
61QPtrList<Incidence> KOJournalView::selectedIncidences() 70QPtrList<Incidence> KOJournalView::selectedIncidences()
62{ 71{
63 QPtrList<Incidence> eventList; 72 QPtrList<Incidence> eventList;
64 73
65 return eventList; 74 return eventList;
66} 75}
67void KOJournalView::updateConfig() 76void KOJournalView::updateConfig()
68{ 77{
69 mEntry->setFont ( KOPrefs::instance()->mJornalViewFont ); 78 JournalEntry* mEntry = jEntries.first();
79 while ( mEntry ) {
80 mEntry->setFont ( KOPrefs::instance()->mJornalViewFont );
81 mEntry = jEntries.next();
82 }
70} 83}
71void KOJournalView::updateView() 84void KOJournalView::updateView()
72{ 85{
73 mEntry->setFont ( KOPrefs::instance()->mJornalViewFont ); 86 JournalEntry* mEntry = jEntries.first();
87 while ( mEntry ) {
88 mEntry->setFont ( KOPrefs::instance()->mJornalViewFont );
89 mEntry = jEntries.next();
90 }
91 showDates( mDate, QDate() );
74} 92}
75 93
76void KOJournalView::flushView() 94void KOJournalView::flushView()
77{ 95{
78 mEntry->flushEntry(); 96 JournalEntry* mEntry = jEntries.first();
97 while ( mEntry ) {
98 mEntry->flushEntry();
99 mEntry = jEntries.next();
100 }
79} 101}
80 102
81void KOJournalView::clearList() 103void KOJournalView::clearList()
82{ 104{
83 mEntry->clear(); 105 JournalEntry* mEntry = jEntries.first();
106 while ( mEntry ) {
107 mEntry->clear();
108 mEntry = jEntries.next();
109 }
84} 110}
85void KOJournalView::showDates(const QDate &start, const QDate &) 111void KOJournalView::newJournal()
86{ 112{
87// kdDebug() << "KOJournalView::selectDates()" << endl; 113 Journal* mJournal = new Journal;
114 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0)));
115 mCalendar->addJournal(mJournal);
116 showDates( mDate, QDate() );
117}
88 118
89 mEntry->setDate(start); 119void KOJournalView::showOnly ( Journal* j )
120{
121 if ( j == 0 ) {
122 showDates( mDate, QDate() );
123 return;
124 }
125 QPtrList<Journal> jl;
126 jl.append ( j );
127 showList( jl );
128 JournalEntry* mEntry = jEntries.first();
129 mEntry->setShowOnly();
130}
131void KOJournalView::showList(QPtrList<Journal> jl)
132{
133 JournalEntry* mEntry = jEntries.first();
134 JournalEntry* firstEntry = mEntry;
135 int count = jl.count();
136 int iii = 0;
137 while ( iii < count ) {
138 if ( !mEntry ) {
139 mEntry = getNewEntry();
140 mEntry->show();
141 mEntry->setDate(mDate);
142 mEntry->setJournal(jl.at(iii));
143 mEntry = 0;
144 } else {
145 mEntry->setDate(mDate);
146 mEntry->setJournal(jl.at(iii));
147 mEntry->show();
148 mEntry = jEntries.next();
149 }
150 ++iii;
151 }
152 while ( mEntry ) {
153 mEntry->setDate(mDate);
154 mEntry->clear();
155 if ( mEntry != firstEntry )
156 mEntry->hide();
157 else
158 mEntry->show();
159 mEntry = jEntries.next();
160 }
161}
90 162
91 Journal *j = calendar()->journal(start); 163void KOJournalView::showDates(const QDate &start, const QDate &)
92 if (j) mEntry->setJournal(j); 164{
93 else mEntry->clear(); 165 mDate = start;
94 166 QPtrList<Journal> jl = calendar()->journals4Date( start );
95// emit incidenceSelected( 0 ); 167 showList( jl );
96} 168}
97 169
98void KOJournalView::showEvents(QPtrList<Event>) 170void KOJournalView::showEvents(QPtrList<Event>)
99{ 171{
100 // After new creation of list view no events are selected. 172 // After new creation of list view no events are selected.
101// emit incidenceSelected( 0 ); 173// emit incidenceSelected( 0 );
102} 174}
103 175
104void KOJournalView::changeEventDisplay(Event *, int /*action*/) 176void KOJournalView::changeEventDisplay(Event *, int /*action*/)
105{ 177{
106 updateView(); 178 updateView();
107} 179}
108 180
109void KOJournalView::keyPressEvent ( QKeyEvent * e ) 181void KOJournalView::keyPressEvent ( QKeyEvent * e )
110{ 182{
111 //qDebug("keyPressEven "); 183 //qDebug("keyPressEven ");
112 if ( e->state() == Qt::ControlButton ) { 184 if ( e->state() == Qt::ControlButton ) {
113 if ( e->key () == Qt::Key_Right || e->key () == Qt::Key_Left ) 185 if ( e->key () == Qt::Key_Right || e->key () == Qt::Key_Left )
114 e->ignore(); 186 e->ignore();
115 } 187 }
116} 188}
diff --git a/korganizer/kojournalview.h b/korganizer/kojournalview.h
index 445f940..aabf11c 100644
--- a/korganizer/kojournalview.h
+++ b/korganizer/kojournalview.h
@@ -1,68 +1,76 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23#ifndef _KOJOURNALVIEW_H 23#ifndef _KOJOURNALVIEW_H
24#define _KOJOURNALVIEW_H 24#define _KOJOURNALVIEW_H
25 25
26#include <korganizer/baseview.h> 26#include <korganizer/baseview.h>
27#include <qlayout.h>
27 28
28class JournalEntry; 29class JournalEntry;
29 30
30/** 31/**
31 * This class provides a journal view. 32 * This class provides a journal view.
32 33
33 * @short View for Journal components. 34 * @short View for Journal components.
34 * @author Cornelius Schumacher <schumacher@kde.org> 35 * @author Cornelius Schumacher <schumacher@kde.org>
35 * @see KOBaseView 36 * @see KOBaseView
36 */ 37 */
37class KOJournalView : public KOrg::BaseView 38class KOJournalView : public KOrg::BaseView
38{ 39{
39 Q_OBJECT 40 Q_OBJECT
40 public: 41 public:
41 KOJournalView(Calendar *calendar, QWidget *parent = 0, 42 KOJournalView(Calendar *calendar, QWidget *parent = 0,
42 const char *name = 0); 43 const char *name = 0);
43 ~KOJournalView(); 44 ~KOJournalView();
44 45
45 virtual int currentDateCount(); 46 virtual int currentDateCount();
46 void clearList(); 47 void clearList();
47 virtual QPtrList<Incidence> selectedIncidences(); 48 virtual QPtrList<Incidence> selectedIncidences();
48 DateList selectedDates() 49 DateList selectedDates()
49 {DateList q; 50 {DateList q;
50 return q;}; 51 return q;};
51 signals: 52 signals:
52 void deleteJournal(Journal *); 53 void deleteJournal(Journal *);
53 public slots: 54 public slots:
55 void showOnly ( Journal* );
56 void newJournal();
54 void updateView(); 57 void updateView();
55 void flushView(); 58 void flushView();
56 void updateConfig(); 59 void updateConfig();
57 void showDates( const QDate &start, const QDate &end ); 60 void showDates( const QDate &start, const QDate &end );
58 void showEvents(QPtrList<Event> eventList); 61 void showEvents(QPtrList<Event> eventList);
59 62
60 void changeEventDisplay(Event *, int); 63 void changeEventDisplay(Event *, int);
61 64
62 private: 65 private:
63 JournalEntry *mEntry; 66 void showList(QPtrList<Journal> jl);
67 Calendar *mCalendar;
68 JournalEntry* getNewEntry();
69 QPtrList<JournalEntry> jEntries;
64 void keyPressEvent ( QKeyEvent * ) ; 70 void keyPressEvent ( QKeyEvent * ) ;
71 QBoxLayout *mTopLayout;
72 QDate mDate;
65 73
66}; 74};
67 75
68#endif 76#endif
diff --git a/korganizer/koviewmanager.cpp b/korganizer/koviewmanager.cpp
index 5d9af6d..7b307f7 100644
--- a/korganizer/koviewmanager.cpp
+++ b/korganizer/koviewmanager.cpp
@@ -1,849 +1,856 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Copyright (c) 2001 4 Copyright (c) 2001
5 Cornelius Schumacher <schumacher@kde.org> 5 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
11 11
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
15 GNU General Public License for more details. 15 GNU General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 20
21 As a special exception, permission is given to link this program 21 As a special exception, permission is given to link this program
22 with any edition of Qt, and distribute the resulting executable, 22 with any edition of Qt, and distribute the resulting executable,
23 without including the source code for Qt in the source distribution. 23 without including the source code for Qt in the source distribution.
24*/ 24*/
25 25
26#include <qwidgetstack.h> 26#include <qwidgetstack.h>
27 27
28#include <kconfig.h> 28#include <kconfig.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#ifndef DESKTOP_VERSION 30#ifndef DESKTOP_VERSION
31#include <qpe/qpeapplication.h> 31#include <qpe/qpeapplication.h>
32#else 32#else
33#include <qapplication.h> 33#include <qapplication.h>
34#endif 34#endif
35#include <qdatetime.h> 35#include <qdatetime.h>
36#include "calendarview.h" 36#include "calendarview.h"
37#include "datenavigator.h" 37#include "datenavigator.h"
38#include "kotodoview.h" 38#include "kotodoview.h"
39#include "koagendaview.h" 39#include "koagendaview.h"
40#include "kodialogmanager.h" 40#include "kodialogmanager.h"
41#include "komonthview.h" 41#include "komonthview.h"
42#include "kolistview.h" 42#include "kolistview.h"
43#include "kowhatsnextview.h" 43#include "kowhatsnextview.h"
44#include "kojournalview.h" 44#include "kojournalview.h"
45#include "kotimespanview.h" 45#include "kotimespanview.h"
46#include "koprefs.h" 46#include "koprefs.h"
47#include "navigatorbar.h" 47#include "navigatorbar.h"
48#include "kdatenavigator.h" 48#include "kdatenavigator.h"
49 49
50#include "koviewmanager.h" 50#include "koviewmanager.h"
51//extern bool externFlagMonthviewBlockPainting; 51//extern bool externFlagMonthviewBlockPainting;
52 52
53//bool globalFlagBlockPainting = false; 53//bool globalFlagBlockPainting = false;
54int globalFlagBlockAgenda = 0; 54int globalFlagBlockAgenda = 0;
55int globalFlagBlockLabel = 0; 55int globalFlagBlockLabel = 0;
56int globalFlagBlockAgendaItemPaint = 1; 56int globalFlagBlockAgendaItemPaint = 1;
57int globalFlagBlockAgendaItemUpdate = 1; 57int globalFlagBlockAgendaItemUpdate = 1;
58 58
59 59
60KOViewManager::KOViewManager( CalendarView *mainView ) : 60KOViewManager::KOViewManager( CalendarView *mainView ) :
61 QObject(), mMainView( mainView ) 61 QObject(), mMainView( mainView )
62{ 62{
63 mCurrentView = 0; 63 mCurrentView = 0;
64 flagResetViewChangeDate = 0; 64 flagResetViewChangeDate = 0;
65 mWhatsNextView = 0; 65 mWhatsNextView = 0;
66 mTodoView = 0; 66 mTodoView = 0;
67 mAgendaView = 0; 67 mAgendaView = 0;
68 mMonthView = 0; 68 mMonthView = 0;
69 mListView = 0; 69 mListView = 0;
70 mJournalView = 0; 70 mJournalView = 0;
71 mTimeSpanView = 0; 71 mTimeSpanView = 0;
72 mCurrentAgendaView = 0 ; 72 mCurrentAgendaView = 0 ;
73 mFlagShowNextxDays = false; 73 mFlagShowNextxDays = false;
74} 74}
75 75
76KOViewManager::~KOViewManager() 76KOViewManager::~KOViewManager()
77{ 77{
78} 78}
79 79
80 80
81KOrg::BaseView *KOViewManager::currentView() 81KOrg::BaseView *KOViewManager::currentView()
82{ 82{
83 return mCurrentView; 83 return mCurrentView;
84} 84}
85 85
86void KOViewManager::readSettings(KConfig *config) 86void KOViewManager::readSettings(KConfig *config)
87{ 87{
88 config->setGroup("General"); 88 config->setGroup("General");
89 QString view = config->readEntry("Current View"); 89 QString view = config->readEntry("Current View");
90 if (view == "WhatsNext") showWhatsNextView(); 90 if (view == "WhatsNext") showWhatsNextView();
91 else if (view == "Month") { 91 else if (view == "Month") {
92 if ( !KOPrefs::instance()->mMonthViewWeek ) 92 if ( !KOPrefs::instance()->mMonthViewWeek )
93 showMonthView(); 93 showMonthView();
94 else 94 else
95 showMonthViewWeek(); 95 showMonthViewWeek();
96 } 96 }
97 else if (view == "List") showListView(); 97 else if (view == "List") showListView();
98 else if (view == "Journal") showJournalView(); 98 else if (view == "Journal") showJournalView();
99 else if (view == "TimeSpan") showTimeSpanView(); 99 else if (view == "TimeSpan") showTimeSpanView();
100 else if (view == "Todo") showTodoView(); 100 else if (view == "Todo") showTodoView();
101 else { 101 else {
102 config->setGroup( "Views" ); 102 config->setGroup( "Views" );
103 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 103 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
104 mCurrentAgendaView = dateCount; 104 mCurrentAgendaView = dateCount;
105 showAgendaView(); 105 showAgendaView();
106 mCurrentAgendaView = dateCount; 106 mCurrentAgendaView = dateCount;
107#ifdef DESKTOP_VERSION 107#ifdef DESKTOP_VERSION
108 QTimer::singleShot( 1000, mAgendaView, SLOT ( setInitStartHour() ) ); 108 QTimer::singleShot( 1000, mAgendaView, SLOT ( setInitStartHour() ) );
109#endif 109#endif
110 } 110 }
111} 111}
112 112
113
113void KOViewManager::showDateView( int view, QDate date) 114void KOViewManager::showDateView( int view, QDate date)
114{ 115{
115 static int lastMode = 0; 116 static int lastMode = 0;
116 static int lastCount = 0; 117 static int lastCount = 0;
117 static bool lastNDMode = false; 118 static bool lastNDMode = false;
118 static QDate lastDate; 119 static QDate lastDate;
119 //qDebug("date %d %s", view, date.toString().latin1()); 120 //qDebug("date %d %s", view, date.toString().latin1());
120 121
121 if (view != 9) 122 if (view != 9)
122 lastMode = 0; 123 lastMode = 0;
123 //qDebug("%d %d ", lastNDMode, mFlagShowNextxDays ); 124 //qDebug("%d %d ", lastNDMode, mFlagShowNextxDays );
124 bool savemFlagShowNextxDays = mFlagShowNextxDays; 125 bool savemFlagShowNextxDays = mFlagShowNextxDays;
125 mFlagShowNextxDays = false; 126 mFlagShowNextxDays = false;
126 if ( view == 3 ) { 127 if ( view == 3 ) {
127 //mCurrentAgendaView = 1 ; 128 //mCurrentAgendaView = 1 ;
128 lastDate = mMainView->dateNavigator()->selectedDates().first(); 129 lastDate = mMainView->dateNavigator()->selectedDates().first();
129 lastCount = mMainView->dateNavigator()->selectedDates().count(); 130 lastCount = mMainView->dateNavigator()->selectedDates().count();
130 lastNDMode = savemFlagShowNextxDays; 131 lastNDMode = savemFlagShowNextxDays;
131 mMainView->dateNavigator()->selectDate( date ); 132 mMainView->dateNavigator()->selectDate( date );
132 lastMode = 1; 133 lastMode = 1;
133 mCurrentAgendaView = 1 ; 134 mCurrentAgendaView = 1 ;
134 } else if (view == 4 ) { 135 } else if (view == 4 ) {
135 mCurrentAgendaView = 7 ; 136 mCurrentAgendaView = 7 ;
136 mMainView->dateNavigator()->selectDates( date, 7 ); 137 mMainView->dateNavigator()->selectDates( date, 7 );
137 } else if (view == 5 ) { 138 } else if (view == 5 ) {
138 mCurrentAgendaView = 14 ; 139 mCurrentAgendaView = 14 ;
139 mMainView->dateNavigator()->selectDates( date, 14); 140 mMainView->dateNavigator()->selectDates( date, 14);
140 } else if (view == 6 ) { 141 } else if (view == 6 ) {
141 resetDateSilent( date,1); 142 resetDateSilent( date,1);
142 showMonthView(); 143 showMonthView();
143 } else if (view == 7 ) { 144 } else if (view == 7 ) {
144 mMainView->dateNavigator()->selectDate( date ); 145 mMainView->dateNavigator()->selectDate( date );
145 showJournalView(); 146 showJournalView();
146 } else if (view == 8 ) { 147 } else if (view == 8 ) {
147 globalFlagBlockAgenda = 1; 148 globalFlagBlockAgenda = 1;
148 if ( mCurrentAgendaView != 3 ) 149 if ( mCurrentAgendaView != 3 )
149 mCurrentAgendaView = -1; 150 mCurrentAgendaView = -1;
150 showAgendaView(KOPrefs::instance()->mFullViewMonth); 151 showAgendaView(KOPrefs::instance()->mFullViewMonth);
151 globalFlagBlockAgenda = 2; 152 globalFlagBlockAgenda = 2;
152 mMainView->dateNavigator()->selectDates( date , 153 mMainView->dateNavigator()->selectDates( date ,
153 KOPrefs::instance()->mNextXDays ); 154 KOPrefs::instance()->mNextXDays );
154 mFlagShowNextxDays = true; 155 mFlagShowNextxDays = true;
155 mCurrentAgendaView = 3 ; 156 mCurrentAgendaView = 3 ;
156 } if (view == 9) { // return behaviour, for getting back from mode == 3 (single day mode ) 157 } if (view == 9) { // return behaviour, for getting back from mode == 3 (single day mode )
157 if ( lastMode ) { 158 if ( lastMode ) {
158 mCurrentAgendaView = lastCount ; 159 mCurrentAgendaView = lastCount ;
159 mMainView->dateNavigator()->selectDates( lastDate, lastCount); 160 mMainView->dateNavigator()->selectDates( lastDate, lastCount);
160 mFlagShowNextxDays = lastNDMode; 161 mFlagShowNextxDays = lastNDMode;
161 if ( mFlagShowNextxDays ) { 162 if ( mFlagShowNextxDays ) {
162 mCurrentAgendaView = 3 ; 163 mCurrentAgendaView = 3 ;
163 } 164 }
164 } else 165 } else
165 showWeekView(); 166 showWeekView();
166 } else if (view == 10) { 167 } else if (view == 10) {
167 mMainView->dateNavigator()->selectDates( date,mMainView->dateNavigator()->selectedDates().count() ); 168 mMainView->dateNavigator()->selectDates( date,mMainView->dateNavigator()->selectedDates().count() );
168 } 169 }
169} 170}
170 171
171 172
172 173
173void KOViewManager::writeSettings(KConfig *config) 174void KOViewManager::writeSettings(KConfig *config)
174{ 175{
175 config->setGroup("General"); 176 config->setGroup("General");
176 177
177 QString view; 178 QString view;
178 if (mCurrentView == mWhatsNextView) view = "WhatsNext"; 179 if (mCurrentView == mWhatsNextView) view = "WhatsNext";
179 else if (mCurrentView == mMonthView) view = "Month"; 180 else if (mCurrentView == mMonthView) view = "Month";
180 else if (mCurrentView == mListView) view = "List"; 181 else if (mCurrentView == mListView) view = "List";
181 else if (mCurrentView == mJournalView) view = "Journal"; 182 else if (mCurrentView == mJournalView) view = "Journal";
182 else if (mCurrentView == mTimeSpanView) view = "TimeSpan"; 183 else if (mCurrentView == mTimeSpanView) view = "TimeSpan";
183 else if (mCurrentView == mTodoView) view = "Todo"; 184 else if (mCurrentView == mTodoView) view = "Todo";
184 else view = "Agenda"; 185 else view = "Agenda";
185 186
186 config->writeEntry("Current View",view); 187 config->writeEntry("Current View",view);
187 188
188 if (mAgendaView) { 189 if (mAgendaView) {
189 mAgendaView->writeSettings(config); 190 mAgendaView->writeSettings(config);
190 } 191 }
191 if (mTimeSpanView) { 192 if (mTimeSpanView) {
192 mTimeSpanView->writeSettings(config); 193 mTimeSpanView->writeSettings(config);
193 } 194 }
194 if (mListView) { 195 if (mListView) {
195 mListView->writeSettings(config); 196 mListView->writeSettings(config);
196 } 197 }
197 if (mTodoView) { 198 if (mTodoView) {
198 mTodoView->saveLayout(config,"Todo View"); 199 mTodoView->saveLayout(config,"Todo View");
199 } 200 }
200} 201}
201void KOViewManager::showNextView() 202void KOViewManager::showNextView()
202{ 203{
203 static int selecteddatescount = 0; 204 static int selecteddatescount = 0;
204 static QDate selecteddate = QDate ( 2000, 1, 1 ); 205 static QDate selecteddate = QDate ( 2000, 1, 1 );
205 static QDate baseCycleDate = QDate ( 2000, 1, 1 ); 206 static QDate baseCycleDate = QDate ( 2000, 1, 1 );
206 int newCount = mMainView->dateNavigator()->selectedDates().count(); 207 int newCount = mMainView->dateNavigator()->selectedDates().count();
207 if ( selecteddatescount != newCount && flagResetViewChangeDate == 0 ) { 208 if ( selecteddatescount != newCount && flagResetViewChangeDate == 0 ) {
208 flagResetViewChangeDate = 1; 209 flagResetViewChangeDate = 1;
209 } 210 }
210 if ( selecteddate != mMainView->dateNavigator()->selectedDates().first() ) 211 if ( selecteddate != mMainView->dateNavigator()->selectedDates().first() )
211 flagResetViewChangeDate = 1; 212 flagResetViewChangeDate = 1;
212 if ( flagResetViewChangeDate > 0 ) { 213 if ( flagResetViewChangeDate > 0 ) {
213 baseCycleDate = mMainView->dateNavigator()->selectedDates().first(); 214 baseCycleDate = mMainView->dateNavigator()->selectedDates().first();
214 //qDebug("newCycle "); 215 //qDebug("newCycle ");
215 } 216 }
216 if (mCurrentView == mWhatsNextView) goto NEXT_X; 217 if (mCurrentView == mWhatsNextView) goto NEXT_X;
217 if (mCurrentView == mAgendaView && mFlagShowNextxDays) goto JOURNAL; 218 if (mCurrentView == mAgendaView && mFlagShowNextxDays) goto JOURNAL;
218 if (mCurrentView == mJournalView ) goto DAY_1; 219 if (mCurrentView == mJournalView ) goto DAY_1;
219 if (mCurrentView == mAgendaView && mCurrentAgendaView == 1 ) goto DAY_5; 220 if (mCurrentView == mAgendaView && mCurrentAgendaView == 1 ) goto DAY_5;
220 if (mCurrentView == mAgendaView && mCurrentAgendaView == 5 ) goto DAY_7; 221 if (mCurrentView == mAgendaView && mCurrentAgendaView == 5 ) goto DAY_7;
221 if (mCurrentView == mAgendaView ) goto DAY_6; 222 if (mCurrentView == mAgendaView ) goto DAY_6;
222 if (mCurrentView == mMonthView && KOPrefs::instance()->mMonthViewWeek) goto MONTH; 223 if (mCurrentView == mMonthView && KOPrefs::instance()->mMonthViewWeek) goto MONTH;
223 if (mCurrentView == mMonthView ) goto LIST; 224 if (mCurrentView == mMonthView ) goto LIST;
224 if (mCurrentView == mListView ) goto TODO; 225 if (mCurrentView == mListView ) goto TODO;
225 // if (mCurrentView == mTodoView ) goto NEXT; 226 // if (mCurrentView == mTodoView ) goto NEXT;
226 NEXT: 227 NEXT:
227 if ( KOPrefs::instance()->mShowIconNext ) { showWhatsNextView();goto ENTE ;} 228 if ( KOPrefs::instance()->mShowIconNext ) { showWhatsNextView();goto ENTE ;}
228 NEXT_X: 229 NEXT_X:
229 if ( KOPrefs::instance()->mShowIconNextDays ) { 230 if ( KOPrefs::instance()->mShowIconNextDays ) {
230 showNextXView(); 231 showNextXView();
231 goto ENTE ; 232 goto ENTE ;
232 } 233 }
233 JOURNAL: 234 JOURNAL:
234 if ( KOPrefs::instance()->mShowIconJournal ) { 235 if ( KOPrefs::instance()->mShowIconJournal ) {
235 resetDateSilent( baseCycleDate , 1 ); 236 resetDateSilent( baseCycleDate , 1 );
236 showJournalView() ;goto ENTE ;} 237 showJournalView() ;goto ENTE ;}
237 DAY_1: 238 DAY_1:
238 if ( KOPrefs::instance()->mShowIconDay1 ) { 239 if ( KOPrefs::instance()->mShowIconDay1 ) {
239 resetDateSilent( baseCycleDate , 2 ); 240 resetDateSilent( baseCycleDate , 2 );
240 showDayView() ;goto ENTE ;} 241 showDayView() ;goto ENTE ;}
241 DAY_5: 242 DAY_5:
242 if ( KOPrefs::instance()->mShowIconDay5 ) { 243 if ( KOPrefs::instance()->mShowIconDay5 ) {
243 resetDateSilent( baseCycleDate , 2 ); 244 resetDateSilent( baseCycleDate , 2 );
244 showWorkWeekView() ;goto ENTE ;} 245 showWorkWeekView() ;goto ENTE ;}
245 DAY_7: 246 DAY_7:
246 if ( KOPrefs::instance()->mShowIconDay7 ) { 247 if ( KOPrefs::instance()->mShowIconDay7 ) {
247 resetDateSilent( baseCycleDate , 2 ); 248 resetDateSilent( baseCycleDate , 2 );
248 showWeekView();goto ENTE ;} 249 showWeekView();goto ENTE ;}
249 DAY_6: 250 DAY_6:
250 if ( KOPrefs::instance()->mShowIconDay6 ) { 251 if ( KOPrefs::instance()->mShowIconDay6 ) {
251 resetDateSilent( baseCycleDate , 2 ); 252 resetDateSilent( baseCycleDate , 2 );
252 showMonthViewWeek();goto ENTE ;} 253 showMonthViewWeek();goto ENTE ;}
253 MONTH: 254 MONTH:
254 if ( KOPrefs::instance()->mShowIconMonth ) { 255 if ( KOPrefs::instance()->mShowIconMonth ) {
255 resetDateSilent( baseCycleDate , 2 ); 256 resetDateSilent( baseCycleDate , 2 );
256 showMonthView();goto ENTE ;} 257 showMonthView();goto ENTE ;}
257 LIST: 258 LIST:
258 if ( KOPrefs::instance()->mShowIconList ) { 259 if ( KOPrefs::instance()->mShowIconList ) {
259 resetDateSilent( baseCycleDate , 2 ); 260 resetDateSilent( baseCycleDate , 2 );
260 showListView() ;goto ENTE ;} 261 showListView() ;goto ENTE ;}
261 TODO: 262 TODO:
262 if ( KOPrefs::instance()->mShowIconTodoview ) { showTodoView() ;goto ENTE ;} 263 if ( KOPrefs::instance()->mShowIconTodoview ) { showTodoView() ;goto ENTE ;}
263 if ( KOPrefs::instance()->mShowIconNext ) { goto NEXT ;} 264 if ( KOPrefs::instance()->mShowIconNext ) { goto NEXT ;}
264 if ( KOPrefs::instance()->mShowIconNextDays ) { goto NEXT_X ;} 265 if ( KOPrefs::instance()->mShowIconNextDays ) { goto NEXT_X ;}
265 if ( KOPrefs::instance()->mShowIconJournal ) { goto JOURNAL;} 266 if ( KOPrefs::instance()->mShowIconJournal ) { goto JOURNAL;}
266 if ( KOPrefs::instance()->mShowIconDay1 ) { goto DAY_1 ;} 267 if ( KOPrefs::instance()->mShowIconDay1 ) { goto DAY_1 ;}
267 if ( KOPrefs::instance()->mShowIconDay5 ) { goto DAY_5 ;} 268 if ( KOPrefs::instance()->mShowIconDay5 ) { goto DAY_5 ;}
268 if ( KOPrefs::instance()->mShowIconDay7 ) { goto DAY_7 ;} 269 if ( KOPrefs::instance()->mShowIconDay7 ) { goto DAY_7 ;}
269 if ( KOPrefs::instance()->mShowIconDay6 ) { goto DAY_6 ;} 270 if ( KOPrefs::instance()->mShowIconDay6 ) { goto DAY_6 ;}
270 if ( KOPrefs::instance()->mShowIconMonth ) {goto MONTH ;} 271 if ( KOPrefs::instance()->mShowIconMonth ) {goto MONTH ;}
271 if ( KOPrefs::instance()->mShowIconList ) { goto LIST ;} 272 if ( KOPrefs::instance()->mShowIconList ) { goto LIST ;}
272 //if ( KOPrefs::instance()->mShowIconTodoview ) { showTodoView() ;goto ENTE ;} 273 //if ( KOPrefs::instance()->mShowIconTodoview ) { showTodoView() ;goto ENTE ;}
273 ENTE: 274 ENTE:
274 flagResetViewChangeDate = 0; 275 flagResetViewChangeDate = 0;
275 selecteddatescount = mMainView->dateNavigator()->selectedDates().count(); 276 selecteddatescount = mMainView->dateNavigator()->selectedDates().count();
276 selecteddate = mMainView->dateNavigator()->selectedDates().first(); 277 selecteddate = mMainView->dateNavigator()->selectedDates().first();
277 278
278} 279}
279void KOViewManager::resetDateSilent( QDate date , int days ) 280void KOViewManager::resetDateSilent( QDate date , int days )
280{ 281{
281 mMainView->dateNavigator()->blockSignals( true ); 282 mMainView->dateNavigator()->blockSignals( true );
282 mMainView->dateNavigator()->selectDates( date , days ); 283 mMainView->dateNavigator()->selectDates( date , days );
283 mMainView->dateNavigator()->blockSignals( false ); 284 mMainView->dateNavigator()->blockSignals( false );
284} 285}
286void KOViewManager::setDefaultCalendar(int)
287{
288 if ( mJournalView && mCurrentView == mJournalView )
289 mJournalView->updateView();
290}
291
285void KOViewManager::showView(KOrg::BaseView *view, bool fullScreen ) 292void KOViewManager::showView(KOrg::BaseView *view, bool fullScreen )
286{ 293{
287 if ( flagResetViewChangeDate < 10 ) 294 if ( flagResetViewChangeDate < 10 )
288 ++flagResetViewChangeDate; 295 ++flagResetViewChangeDate;
289 //mFlagShowNextxDays = false; 296 //mFlagShowNextxDays = false;
290 //if(view == mCurrentView) return; 297 //if(view == mCurrentView) return;
291 if ( view == 0 ) { 298 if ( view == 0 ) {
292 view = mCurrentView; 299 view = mCurrentView;
293 if ( view == 0 ) 300 if ( view == 0 )
294 return; 301 return;
295 } 302 }
296 bool callupdate = !(view == mCurrentView); 303 bool callupdate = !(view == mCurrentView);
297 bool full = fullScreen; 304 bool full = fullScreen;
298 if(view == mCurrentView && view != mWhatsNextView ) { 305 if(view == mCurrentView && view != mWhatsNextView ) {
299 if ( mCurrentAgendaView < 0 ) 306 if ( mCurrentAgendaView < 0 )
300 return; 307 return;
301 if ( view != mMonthView ) 308 if ( view != mMonthView )
302 full = mMainView->leftFrame()->isVisible(); 309 full = mMainView->leftFrame()->isVisible();
303 } else { 310 } else {
304 if ( view == mMonthView && mMonthView) 311 if ( view == mMonthView && mMonthView)
305 ;//mMonthView->skipResize = true ; 312 ;//mMonthView->skipResize = true ;
306 mCurrentView = view; 313 mCurrentView = view;
307 // bool full = fullScreen; 314 // bool full = fullScreen;
308 bool isFull = !mMainView->leftFrame()->isVisible(); 315 bool isFull = !mMainView->leftFrame()->isVisible();
309 if ( isFull && KOPrefs::instance()->mViewChangeHoldFullscreen ) 316 if ( isFull && KOPrefs::instance()->mViewChangeHoldFullscreen )
310 full = true; 317 full = true;
311 if ( !isFull && KOPrefs::instance()->mViewChangeHoldNonFullscreen ) 318 if ( !isFull && KOPrefs::instance()->mViewChangeHoldNonFullscreen )
312 full = false; 319 full = false;
313 } 320 }
314 if ( mAgendaView ) mAgendaView->deleteSelectedDateTime(); 321 if ( mAgendaView ) mAgendaView->deleteSelectedDateTime();
315 //raiseCurrentView( full ); 322 //raiseCurrentView( full );
316 mMainView->processIncidenceSelection( 0 ); 323 mMainView->processIncidenceSelection( 0 );
317 //mMainView->updateView(); 324 //mMainView->updateView();
318 raiseCurrentView( full, callupdate ); 325 raiseCurrentView( full, callupdate );
319 mMainView->adaptNavigationUnits(); 326 mMainView->adaptNavigationUnits();
320 mMainView->updateUnmanagedViews(); 327 mMainView->updateUnmanagedViews();
321} 328}
322 329
323void KOViewManager::raiseCurrentView( bool fullScreen, bool callUpdateView ) 330void KOViewManager::raiseCurrentView( bool fullScreen, bool callUpdateView )
324{ 331{
325 mCurrentAgendaView = 0; 332 mCurrentAgendaView = 0;
326 if ( fullScreen ) { 333 if ( fullScreen ) {
327 mMainView->leftFrame()->hide(); 334 mMainView->leftFrame()->hide();
328 } else { 335 } else {
329 mMainView->leftFrame()->show(); 336 mMainView->leftFrame()->show();
330 } 337 }
331 //if ( mCurrentView == mMonthView ) qApp->processEvents(); 338 //if ( mCurrentView == mMonthView ) qApp->processEvents();
332 emit signalFullScreen( !fullScreen ); 339 emit signalFullScreen( !fullScreen );
333 if ( callUpdateView ) 340 if ( callUpdateView )
334 mMainView->updateView(); 341 mMainView->updateView();
335 342
336 if ( globalFlagBlockAgenda == 5 ) { 343 if ( globalFlagBlockAgenda == 5 ) {
337 globalFlagBlockAgenda = 4; 344 globalFlagBlockAgenda = 4;
338 globalFlagBlockAgendaItemPaint = 1; 345 globalFlagBlockAgendaItemPaint = 1;
339 } 346 }
340 mMainView->viewStack()->raiseWidget(mCurrentView); 347 mMainView->viewStack()->raiseWidget(mCurrentView);
341 if ( globalFlagBlockAgenda == 4 ) { 348 if ( globalFlagBlockAgenda == 4 ) {
342 if ( mCurrentView == mAgendaView ) { 349 if ( mCurrentView == mAgendaView ) {
343 //globalFlagBlockAgenda =1 ; 350 //globalFlagBlockAgenda =1 ;
344 if ( KOPrefs::instance()->mSetTimeToDayStartAt ) 351 if ( KOPrefs::instance()->mSetTimeToDayStartAt )
345 mAgendaView->setStartHour( KOPrefs::instance()->mDayBegins ); 352 mAgendaView->setStartHour( KOPrefs::instance()->mDayBegins );
346 else if ( KOPrefs::instance()->mCenterOnCurrentTime ) 353 else if ( KOPrefs::instance()->mCenterOnCurrentTime )
347 mAgendaView->setStartHour( QTime::currentTime ().hour() ); 354 mAgendaView->setStartHour( QTime::currentTime ().hour() );
348 qApp->processEvents(); 355 qApp->processEvents();
349 //qDebug("qApp->processEvents() "); 356 //qDebug("qApp->processEvents() ");
350 globalFlagBlockAgenda = 0; 357 globalFlagBlockAgenda = 0;
351 mAgendaView->repaintAgenda(); 358 mAgendaView->repaintAgenda();
352 359
353 } 360 }
354 globalFlagBlockAgenda = 0; 361 globalFlagBlockAgenda = 0;
355 } 362 }
356 emit signalAgendaView( mCurrentView == mAgendaView ); 363 emit signalAgendaView( mCurrentView == mAgendaView );
357 //qDebug("raiseCurrentView ende "); 364 //qDebug("raiseCurrentView ende ");
358 365
359} 366}
360 367
361void KOViewManager::clearAllViews() 368void KOViewManager::clearAllViews()
362{ 369{
363 370
364 if ( mTodoView ) mTodoView->clearList(); 371 if ( mTodoView ) mTodoView->clearList();
365 if ( mListView ) mListView->clearList(); 372 if ( mListView ) mListView->clearList();
366 373
367 if ( mAgendaView ) mAgendaView->clearList(); 374 if ( mAgendaView ) mAgendaView->clearList();
368 if ( mMonthView ) mMonthView->clearList(); 375 if ( mMonthView ) mMonthView->clearList();
369 if ( mWhatsNextView ) mWhatsNextView->clearList(); 376 if ( mWhatsNextView ) mWhatsNextView->clearList();
370 if ( mJournalView ) mJournalView->clearList(); 377 if ( mJournalView ) mJournalView->clearList();
371 378
372} 379}
373void KOViewManager::updateView() 380void KOViewManager::updateView()
374{ 381{
375 // qDebug("KOViewManager::updateView() "); 382 // qDebug("KOViewManager::updateView() ");
376 // if we are updating mTodoView, we get endless recursion 383 // if we are updating mTodoView, we get endless recursion
377 if ( mTodoView == mCurrentView ) 384 if ( mTodoView == mCurrentView )
378 return; 385 return;
379 if ( mCurrentView ) mCurrentView->updateView(); 386 if ( mCurrentView ) mCurrentView->updateView();
380 387
381} 388}
382 389
383void KOViewManager::updateView(const QDate &start, const QDate &end) 390void KOViewManager::updateView(const QDate &start, const QDate &end)
384{ 391{
385 // kdDebug() << "KOViewManager::updateView()" << endl; 392 // kdDebug() << "KOViewManager::updateView()" << endl;
386 393
387 if (mCurrentView) mCurrentView->showDates(start, end); 394 if (mCurrentView) mCurrentView->showDates(start, end);
388 395
389 if (mTodoView && mTodoView == mCurrentView ) mTodoView->updateView(); 396 if (mTodoView && mTodoView == mCurrentView ) mTodoView->updateView();
390} 397}
391 398
392 399
393void KOViewManager::updateWNview() 400void KOViewManager::updateWNview()
394{ 401{
395 if ( mCurrentView == mWhatsNextView && mWhatsNextView ) 402 if ( mCurrentView == mWhatsNextView && mWhatsNextView )
396 mWhatsNextView->updateView(); 403 mWhatsNextView->updateView();
397 if ( mCurrentView == mMonthView && mMonthView ) 404 if ( mCurrentView == mMonthView && mMonthView )
398 mMonthView->updateView(); 405 mMonthView->updateView();
399 406
400} 407}
401void KOViewManager::showWhatsNextView() 408void KOViewManager::showWhatsNextView()
402{ 409{
403 if (!mWhatsNextView) { 410 if (!mWhatsNextView) {
404 mWhatsNextView = new KOWhatsNextView(mMainView->calendar(),mMainView->viewStack(), 411 mWhatsNextView = new KOWhatsNextView(mMainView->calendar(),mMainView->viewStack(),
405 "KOViewManager::WhatsNextView"); 412 "KOViewManager::WhatsNextView");
406 mWhatsNextView->setEventViewer( mMainView->getEventViewerDialog()); 413 mWhatsNextView->setEventViewer( mMainView->getEventViewerDialog());
407 connect(mMainView, SIGNAL(configChanged()), mWhatsNextView, SLOT(updateConfig())); 414 connect(mMainView, SIGNAL(configChanged()), mWhatsNextView, SLOT(updateConfig()));
408 addView(mWhatsNextView); 415 addView(mWhatsNextView);
409 connect(this, SIGNAL( printWNV() ), 416 connect(this, SIGNAL( printWNV() ),
410 mWhatsNextView, SLOT( printMe() ) ); 417 mWhatsNextView, SLOT( printMe() ) );
411 } 418 }
412 globalFlagBlockAgenda = 1; 419 globalFlagBlockAgenda = 1;
413 KOPrefs::instance()->mCurrentDisplayedView = VIEW_WN_VIEW; 420 KOPrefs::instance()->mCurrentDisplayedView = VIEW_WN_VIEW;
414 showView(mWhatsNextView, true ); 421 showView(mWhatsNextView, true );
415 //mWhatsNextView->updateView(); 422 //mWhatsNextView->updateView();
416 KOPrefs::instance()->mCurrentDisplayedView = VIEW_WN_VIEW; 423 KOPrefs::instance()->mCurrentDisplayedView = VIEW_WN_VIEW;
417} 424}
418 425
419void KOViewManager::slotprintWNV() 426void KOViewManager::slotprintWNV()
420{ 427{
421 if (!mWhatsNextView) 428 if (!mWhatsNextView)
422 showWhatsNextView(); 429 showWhatsNextView();
423 emit printWNV(); 430 emit printWNV();
424 431
425} 432}
426void KOViewManager::showListView() 433void KOViewManager::showListView()
427{ 434{
428 if (!mListView) { 435 if (!mListView) {
429 mListView = new KOListView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::ListView"); 436 mListView = new KOListView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::ListView");
430 addView(mListView); 437 addView(mListView);
431 438
432 connect(mListView, SIGNAL(showIncidenceSignal(Incidence *)), 439 connect(mListView, SIGNAL(showIncidenceSignal(Incidence *)),
433 mMainView, SLOT(showIncidence(Incidence *))); 440 mMainView, SLOT(showIncidence(Incidence *)));
434 connect(mListView, SIGNAL(editIncidenceSignal(Incidence *)), 441 connect(mListView, SIGNAL(editIncidenceSignal(Incidence *)),
435 mMainView, SLOT(editIncidence(Incidence *))); 442 mMainView, SLOT(editIncidence(Incidence *)));
436 connect(mListView, SIGNAL(deleteIncidenceSignal(Incidence *)), 443 connect(mListView, SIGNAL(deleteIncidenceSignal(Incidence *)),
437 mMainView, SLOT(deleteIncidence(Incidence *))); 444 mMainView, SLOT(deleteIncidence(Incidence *)));
438 connect( mListView, SIGNAL( incidenceSelected( Incidence * ) ), 445 connect( mListView, SIGNAL( incidenceSelected( Incidence * ) ),
439 mMainView, SLOT( processMainViewSelection( Incidence * ) ) ); 446 mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
440 connect( mListView, SIGNAL( signalNewEvent() ), 447 connect( mListView, SIGNAL( signalNewEvent() ),
441 mMainView, SLOT( newEvent() ) ); 448 mMainView, SLOT( newEvent() ) );
442 connect(mMainView, SIGNAL(configChanged()), mListView, SLOT(updateConfig())); 449 connect(mMainView, SIGNAL(configChanged()), mListView, SLOT(updateConfig()));
443 connect( mListView, SIGNAL( cloneIncidenceSignal( Incidence * ) ), 450 connect( mListView, SIGNAL( cloneIncidenceSignal( Incidence * ) ),
444 mMainView, SLOT ( cloneIncidence( Incidence * ) ) ); 451 mMainView, SLOT ( cloneIncidence( Incidence * ) ) );
445 connect( mListView, SIGNAL( cancelIncidenceSignal( Incidence * ) ), 452 connect( mListView, SIGNAL( cancelIncidenceSignal( Incidence * ) ),
446 mMainView, SLOT ( cancelIncidence( Incidence * ) ) ); 453 mMainView, SLOT ( cancelIncidence( Incidence * ) ) );
447 connect( mListView, SIGNAL( moveIncidenceSignal( Incidence * ) ), 454 connect( mListView, SIGNAL( moveIncidenceSignal( Incidence * ) ),
448 mMainView, SLOT ( moveIncidence( Incidence * ) ) ); 455 mMainView, SLOT ( moveIncidence( Incidence * ) ) );
449 connect( mListView, SIGNAL( beamIncidenceSignal( Incidence * ) ), 456 connect( mListView, SIGNAL( beamIncidenceSignal( Incidence * ) ),
450 mMainView, SLOT ( beamIncidence( Incidence * ) ) ); 457 mMainView, SLOT ( beamIncidence( Incidence * ) ) );
451 } 458 }
452 // bool temp = mFlagShowNextxDays; 459 // bool temp = mFlagShowNextxDays;
453 //globalFlagBlockPainting = true; 460 //globalFlagBlockPainting = true;
454 globalFlagBlockAgenda = 1; 461 globalFlagBlockAgenda = 1;
455 if ( KOPrefs::instance()->mListViewMonthTimespan ) { 462 if ( KOPrefs::instance()->mListViewMonthTimespan ) {
456 mMainView->setBlockShowDates( true ); 463 mMainView->setBlockShowDates( true );
457 mMainView->dateNavigator()->selectMonth(); 464 mMainView->dateNavigator()->selectMonth();
458 mMainView->setBlockShowDates( false ); 465 mMainView->setBlockShowDates( false );
459 } 466 }
460 KOPrefs::instance()->mCurrentDisplayedView = VIEW_L_VIEW; 467 KOPrefs::instance()->mCurrentDisplayedView = VIEW_L_VIEW;
461 showView(mListView, KOPrefs::instance()->mFullViewTodo); 468 showView(mListView, KOPrefs::instance()->mFullViewTodo);
462 //mFlagShowNextxDays = temp; 469 //mFlagShowNextxDays = temp;
463 KOPrefs::instance()->mCurrentDisplayedView = VIEW_L_VIEW; 470 KOPrefs::instance()->mCurrentDisplayedView = VIEW_L_VIEW;
464} 471}
465 472
466void KOViewManager::showAgendaView( bool fullScreen ) 473void KOViewManager::showAgendaView( bool fullScreen )
467{ 474{
468 475
469 mMainView->dialogManager()->hideSearchDialog(); 476 mMainView->dialogManager()->hideSearchDialog();
470 // qDebug("KOViewManager::showAgendaView "); 477 // qDebug("KOViewManager::showAgendaView ");
471 bool full; 478 bool full;
472 full = fullScreen; 479 full = fullScreen;
473 if (!mAgendaView) { 480 if (!mAgendaView) {
474 full = false; 481 full = false;
475 mAgendaView = new KOAgendaView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::AgendaView"); 482 mAgendaView = new KOAgendaView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::AgendaView");
476 addView(mAgendaView); 483 addView(mAgendaView);
477#ifndef DESKTOP_VERSION 484#ifndef DESKTOP_VERSION
478 QPEApplication::setStylusOperation( mAgendaView, QPEApplication::RightOnHold ); 485 QPEApplication::setStylusOperation( mAgendaView, QPEApplication::RightOnHold );
479#endif 486#endif
480 connect( mAgendaView, SIGNAL( incidenceChanged(Incidence *, int )), 487 connect( mAgendaView, SIGNAL( incidenceChanged(Incidence *, int )),
481 mMainView, SLOT( changeIncidenceDisplay( Incidence *, int ) )); 488 mMainView, SLOT( changeIncidenceDisplay( Incidence *, int ) ));
482 489
483 // SIGNALS/SLOTS FOR DAY/WEEK VIEW 490 // SIGNALS/SLOTS FOR DAY/WEEK VIEW
484 491
485 connect(mAgendaView,SIGNAL(showDateView( int, QDate )),SLOT(showDateView( int, QDate ))); 492 connect(mAgendaView,SIGNAL(showDateView( int, QDate )),SLOT(showDateView( int, QDate )));
486 493
487 connect(mAgendaView,SIGNAL(newTodoSignal(QDateTime,bool)), 494 connect(mAgendaView,SIGNAL(newTodoSignal(QDateTime,bool)),
488 mMainView, SLOT(newTodoDateTime(QDateTime,bool))); 495 mMainView, SLOT(newTodoDateTime(QDateTime,bool)));
489 connect(mAgendaView,SIGNAL(newEventSignal(QDateTime)), 496 connect(mAgendaView,SIGNAL(newEventSignal(QDateTime)),
490 mMainView, SLOT(newEvent(QDateTime))); 497 mMainView, SLOT(newEvent(QDateTime)));
491 connect(mAgendaView,SIGNAL(newEventSignal(QDateTime,QDateTime)), 498 connect(mAgendaView,SIGNAL(newEventSignal(QDateTime,QDateTime)),
492 mMainView, SLOT(newEvent(QDateTime,QDateTime))); 499 mMainView, SLOT(newEvent(QDateTime,QDateTime)));
493 connect(mAgendaView,SIGNAL(newEventSignal(QDate)), 500 connect(mAgendaView,SIGNAL(newEventSignal(QDate)),
494 mMainView, SLOT(newEvent(QDate))); 501 mMainView, SLOT(newEvent(QDate)));
495 502
496 connect(mAgendaView, SIGNAL(editIncidenceSignal(Incidence *)), 503 connect(mAgendaView, SIGNAL(editIncidenceSignal(Incidence *)),
497 mMainView, SLOT(editIncidence(Incidence *))); 504 mMainView, SLOT(editIncidence(Incidence *)));
498 connect(mAgendaView, SIGNAL(showIncidenceSignal(Incidence *)), 505 connect(mAgendaView, SIGNAL(showIncidenceSignal(Incidence *)),
499 mMainView, SLOT(showIncidence(Incidence *))); 506 mMainView, SLOT(showIncidence(Incidence *)));
500 connect(mAgendaView, SIGNAL(deleteIncidenceSignal(Incidence *)), 507 connect(mAgendaView, SIGNAL(deleteIncidenceSignal(Incidence *)),
501 mMainView, SLOT(deleteIncidence(Incidence *))); 508 mMainView, SLOT(deleteIncidence(Incidence *)));
502 509
503 connect( mAgendaView, SIGNAL( incidenceSelected( Incidence * ) ), 510 connect( mAgendaView, SIGNAL( incidenceSelected( Incidence * ) ),
504 mMainView, SLOT( processMainViewSelection( Incidence * ) ) ); 511 mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
505 512
506 connect(mAgendaView, SIGNAL( toggleExpand() ), 513 connect(mAgendaView, SIGNAL( toggleExpand() ),
507 mMainView, SLOT( toggleExpand() ) ); 514 mMainView, SLOT( toggleExpand() ) );
508 515
509 connect( mAgendaView, SIGNAL( cloneIncidenceSignal(Incidence *) ), 516 connect( mAgendaView, SIGNAL( cloneIncidenceSignal(Incidence *) ),
510 mMainView, SLOT(cloneIncidence(Incidence *) ) ) ; 517 mMainView, SLOT(cloneIncidence(Incidence *) ) ) ;
511 connect( mAgendaView, SIGNAL( cancelIncidenceSignal(Incidence *) ), 518 connect( mAgendaView, SIGNAL( cancelIncidenceSignal(Incidence *) ),
512 mMainView, SLOT(cancelIncidence(Incidence *) ) ) ; 519 mMainView, SLOT(cancelIncidence(Incidence *) ) ) ;
513 connect(mMainView, SIGNAL(configChanged()), mAgendaView, SLOT(updateConfig())); 520 connect(mMainView, SIGNAL(configChanged()), mAgendaView, SLOT(updateConfig()));
514 connect( mMainView, SIGNAL( todoModified( Todo *, int )), mAgendaView, 521 connect( mMainView, SIGNAL( todoModified( Todo *, int )), mAgendaView,
515 SLOT( updateTodo( Todo *, int ) ) ); 522 SLOT( updateTodo( Todo *, int ) ) );
516 connect( mAgendaView,SIGNAL( todoMoved( Todo *, int )), 523 connect( mAgendaView,SIGNAL( todoMoved( Todo *, int )),
517 mMainView, SIGNAL( todoModified( Todo *, int ))); 524 mMainView, SIGNAL( todoModified( Todo *, int )));
518 connect( mAgendaView, SIGNAL( moveIncidenceSignal( Incidence * ) ), 525 connect( mAgendaView, SIGNAL( moveIncidenceSignal( Incidence * ) ),
519 mMainView, SLOT ( moveIncidence( Incidence * ) ) ); 526 mMainView, SLOT ( moveIncidence( Incidence * ) ) );
520 connect( mAgendaView, SIGNAL( beamIncidenceSignal( Incidence * ) ), 527 connect( mAgendaView, SIGNAL( beamIncidenceSignal( Incidence * ) ),
521 mMainView, SLOT ( beamIncidence( Incidence * ) ) ); 528 mMainView, SLOT ( beamIncidence( Incidence * ) ) );
522 connect( mAgendaView, SIGNAL( selectWeekNum( int ) ), 529 connect( mAgendaView, SIGNAL( selectWeekNum( int ) ),
523 mMainView->dateNavigator(), SLOT ( selectWeek( int ) ) ); 530 mMainView->dateNavigator(), SLOT ( selectWeek( int ) ) );
524 mAgendaView->readSettings(); 531 mAgendaView->readSettings();
525 mAgendaView->updateConfig(); 532 mAgendaView->updateConfig();
526 } 533 }
527 534
528 KOPrefs::instance()->mCurrentDisplayedView = VIEW_A_VIEW; 535 KOPrefs::instance()->mCurrentDisplayedView = VIEW_A_VIEW;
529 showView( mAgendaView, full); 536 showView( mAgendaView, full);
530 KOPrefs::instance()->mCurrentDisplayedView = VIEW_A_VIEW; 537 KOPrefs::instance()->mCurrentDisplayedView = VIEW_A_VIEW;
531} 538}
532 539
533void KOViewManager::showDayView() 540void KOViewManager::showDayView()
534{ 541{
535 mCurrentAgendaView = mMainView->dateNavigator()->selectedDates().count(); 542 mCurrentAgendaView = mMainView->dateNavigator()->selectedDates().count();
536 mFlagShowNextxDays = false; 543 mFlagShowNextxDays = false;
537 globalFlagBlockLabel = 1; 544 globalFlagBlockLabel = 1;
538 globalFlagBlockAgenda = 1; 545 globalFlagBlockAgenda = 1;
539 if ( mCurrentAgendaView != 1 ) 546 if ( mCurrentAgendaView != 1 )
540 mCurrentAgendaView = -1; 547 mCurrentAgendaView = -1;
541 showAgendaView(); 548 showAgendaView();
542 qApp->processEvents(); 549 qApp->processEvents();
543 globalFlagBlockAgenda = 2; 550 globalFlagBlockAgenda = 2;
544 globalFlagBlockLabel = 0; 551 globalFlagBlockLabel = 0;
545 mMainView->dateNavigator()->selectDates( 1 ); 552 mMainView->dateNavigator()->selectDates( 1 );
546 mCurrentAgendaView = 1 ; 553 mCurrentAgendaView = 1 ;
547 554
548} 555}
549 556
550void KOViewManager::showWorkWeekView() 557void KOViewManager::showWorkWeekView()
551{ 558{
552 mCurrentAgendaView = mMainView->dateNavigator()->selectedDates().count(); 559 mCurrentAgendaView = mMainView->dateNavigator()->selectedDates().count();
553 mFlagShowNextxDays = false; 560 mFlagShowNextxDays = false;
554 globalFlagBlockAgenda = 1; 561 globalFlagBlockAgenda = 1;
555 globalFlagBlockLabel = 1; 562 globalFlagBlockLabel = 1;
556 if ( mCurrentAgendaView != 5 ) 563 if ( mCurrentAgendaView != 5 )
557 mCurrentAgendaView = -1; 564 mCurrentAgendaView = -1;
558 showAgendaView(); 565 showAgendaView();
559 qApp->processEvents(); 566 qApp->processEvents();
560 globalFlagBlockAgenda = 2; 567 globalFlagBlockAgenda = 2;
561 globalFlagBlockLabel = 0; 568 globalFlagBlockLabel = 0;
562 mMainView->dateNavigator()->selectWorkWeek(); 569 mMainView->dateNavigator()->selectWorkWeek();
563 mCurrentAgendaView = 5 ; 570 mCurrentAgendaView = 5 ;
564 571
565} 572}
566 573
567void KOViewManager::showWeekView() 574void KOViewManager::showWeekView()
568{ 575{
569 576
570 mCurrentAgendaView = mMainView->dateNavigator()->selectedDates().count(); 577 mCurrentAgendaView = mMainView->dateNavigator()->selectedDates().count();
571 mFlagShowNextxDays = false; 578 mFlagShowNextxDays = false;
572 globalFlagBlockAgenda = 1; 579 globalFlagBlockAgenda = 1;
573 globalFlagBlockLabel = 1; 580 globalFlagBlockLabel = 1;
574 if ( mCurrentAgendaView != 7 ) 581 if ( mCurrentAgendaView != 7 )
575 mCurrentAgendaView = -1; 582 mCurrentAgendaView = -1;
576 showAgendaView(); 583 showAgendaView();
577 qApp->processEvents(); 584 qApp->processEvents();
578 globalFlagBlockAgenda = 2; 585 globalFlagBlockAgenda = 2;
579 globalFlagBlockLabel = 0; 586 globalFlagBlockLabel = 0;
580 mMainView->dateNavigator()->selectWeek(); 587 mMainView->dateNavigator()->selectWeek();
581 mCurrentAgendaView = 7 ; 588 mCurrentAgendaView = 7 ;
582} 589}
583 590
584void KOViewManager::showNextXView() 591void KOViewManager::showNextXView()
585{ 592{
586 593
587 KOPrefs::instance()->mCurrentDisplayedView = VIEW_NX_VIEW; 594 KOPrefs::instance()->mCurrentDisplayedView = VIEW_NX_VIEW;
588 globalFlagBlockAgenda = 1; 595 globalFlagBlockAgenda = 1;
589 if ( mCurrentAgendaView != 3 ) 596 if ( mCurrentAgendaView != 3 )
590 mCurrentAgendaView = -1; 597 mCurrentAgendaView = -1;
591 showAgendaView(KOPrefs::instance()->mFullViewMonth); 598 showAgendaView(KOPrefs::instance()->mFullViewMonth);
592 globalFlagBlockAgenda = 2; 599 globalFlagBlockAgenda = 2;
593 mMainView->dateNavigator()->selectDates( QDate::currentDate(), 600 mMainView->dateNavigator()->selectDates( QDate::currentDate(),
594 KOPrefs::instance()->mNextXDays ); 601 KOPrefs::instance()->mNextXDays );
595 mFlagShowNextxDays = true; 602 mFlagShowNextxDays = true;
596 mCurrentAgendaView = 3 ; 603 mCurrentAgendaView = 3 ;
597 KOPrefs::instance()->mCurrentDisplayedView = VIEW_NX_VIEW; 604 KOPrefs::instance()->mCurrentDisplayedView = VIEW_NX_VIEW;
598} 605}
599bool KOViewManager::showsNextDays() 606bool KOViewManager::showsNextDays()
600{ 607{
601 return mFlagShowNextxDays; 608 return mFlagShowNextxDays;
602} 609}
603void KOViewManager::createMonthView() 610void KOViewManager::createMonthView()
604{ 611{
605if (!mMonthView) { 612if (!mMonthView) {
606 mMonthView = new KOMonthView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::MonthView"); 613 mMonthView = new KOMonthView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::MonthView");
607 614
608 addView(mMonthView); 615 addView(mMonthView);
609 // mMonthView->show(); 616 // mMonthView->show();
610 // SIGNALS/SLOTS FOR MONTH VIEW 617 // SIGNALS/SLOTS FOR MONTH VIEW
611 618
612 connect(mMonthView,SIGNAL(showJournalSignal( int, QDate )),SLOT(showDateView( int, QDate ))); 619 connect(mMonthView,SIGNAL(showJournalSignal( int, QDate )),SLOT(showDateView( int, QDate )));
613 620
614 connect(mMonthView, SIGNAL(newTodoSignal(QDateTime,bool)), 621 connect(mMonthView, SIGNAL(newTodoSignal(QDateTime,bool)),
615 mMainView, SLOT(newTodoDateTime(QDateTime, bool))); 622 mMainView, SLOT(newTodoDateTime(QDateTime, bool)));
616 623
617 624
618 connect(mMonthView, SIGNAL(newEventSignal(QDateTime)), 625 connect(mMonthView, SIGNAL(newEventSignal(QDateTime)),
619 mMainView, SLOT(newEvent(QDateTime))); 626 mMainView, SLOT(newEvent(QDateTime)));
620 627
621 connect(mMonthView, SIGNAL(showIncidenceSignal(Incidence *)), 628 connect(mMonthView, SIGNAL(showIncidenceSignal(Incidence *)),
622 mMainView, SLOT(showIncidence(Incidence *))); 629 mMainView, SLOT(showIncidence(Incidence *)));
623 connect(mMonthView, SIGNAL(editIncidenceSignal(Incidence *)), 630 connect(mMonthView, SIGNAL(editIncidenceSignal(Incidence *)),
624 mMainView, SLOT(editIncidence(Incidence *))); 631 mMainView, SLOT(editIncidence(Incidence *)));
625 connect(mMonthView, SIGNAL(deleteIncidenceSignal(Incidence *)), 632 connect(mMonthView, SIGNAL(deleteIncidenceSignal(Incidence *)),
626 mMainView, SLOT(deleteIncidence(Incidence *))); 633 mMainView, SLOT(deleteIncidence(Incidence *)));
627 634
628 connect( mMonthView, SIGNAL( incidenceSelected( Incidence * ) ), 635 connect( mMonthView, SIGNAL( incidenceSelected( Incidence * ) ),
629 mMainView, SLOT( processMainViewSelection( Incidence * ) ) ); 636 mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
630 connect( mMonthView, SIGNAL( cloneIncidenceSignal( Incidence * ) ), 637 connect( mMonthView, SIGNAL( cloneIncidenceSignal( Incidence * ) ),
631 mMainView, SLOT ( cloneIncidence( Incidence * ) ) ); 638 mMainView, SLOT ( cloneIncidence( Incidence * ) ) );
632 connect( mMonthView, SIGNAL( cancelIncidenceSignal( Incidence * ) ), 639 connect( mMonthView, SIGNAL( cancelIncidenceSignal( Incidence * ) ),
633 mMainView, SLOT ( cancelIncidence( Incidence * ) ) ); 640 mMainView, SLOT ( cancelIncidence( Incidence * ) ) );
634 641
635 connect( mMonthView, SIGNAL( moveIncidenceSignal( Incidence * ) ), 642 connect( mMonthView, SIGNAL( moveIncidenceSignal( Incidence * ) ),
636 mMainView, SLOT ( moveIncidence( Incidence * ) ) ); 643 mMainView, SLOT ( moveIncidence( Incidence * ) ) );
637 connect( mMonthView, SIGNAL( beamIncidenceSignal( Incidence * ) ), 644 connect( mMonthView, SIGNAL( beamIncidenceSignal( Incidence * ) ),
638 mMainView, SLOT ( beamIncidence( Incidence * ) ) ); 645 mMainView, SLOT ( beamIncidence( Incidence * ) ) );
639 connect( mMonthView, SIGNAL( selectWeekNum( int ) ), 646 connect( mMonthView, SIGNAL( selectWeekNum( int ) ),
640 mMainView->dateNavigator(), SLOT ( selectWeekFromMonthView( int ) ) ); 647 mMainView->dateNavigator(), SLOT ( selectWeekFromMonthView( int ) ) );
641 connect( mMonthView, SIGNAL( selectMonth() ), 648 connect( mMonthView, SIGNAL( selectMonth() ),
642 mMainView->dateNavigator(), SLOT ( selectMonthFromMonthview() ) ); 649 mMainView->dateNavigator(), SLOT ( selectMonthFromMonthview() ) );
643 connect( mMonthView, SIGNAL( showDaySignal( QDate ) ), 650 connect( mMonthView, SIGNAL( showDaySignal( QDate ) ),
644 mMainView, SLOT ( showDay( QDate ) ) ); 651 mMainView, SLOT ( showDay( QDate ) ) );
645 connect(mMainView, SIGNAL(configChanged()), mMonthView, SLOT(updateConfig())); 652 connect(mMainView, SIGNAL(configChanged()), mMonthView, SLOT(updateConfig()));
646 connect( mMonthView, SIGNAL(nextMonth() ), 653 connect( mMonthView, SIGNAL(nextMonth() ),
647 mMonthView->navigatorBar(), SIGNAL(goNextMonth() ) ); 654 mMonthView->navigatorBar(), SIGNAL(goNextMonth() ) );
648 connect( mMonthView, SIGNAL(prevMonth() ), 655 connect( mMonthView, SIGNAL(prevMonth() ),
649 mMonthView->navigatorBar(), SIGNAL(goPrevMonth() ) ); 656 mMonthView->navigatorBar(), SIGNAL(goPrevMonth() ) );
650 connect( mMonthView->navigatorBar(), SIGNAL( goPrevYear() ), 657 connect( mMonthView->navigatorBar(), SIGNAL( goPrevYear() ),
651 mMainView->dateNavigator(), SLOT( selectPreviousYear() ) ); 658 mMainView->dateNavigator(), SLOT( selectPreviousYear() ) );
652 connect( mMonthView->navigatorBar(), SIGNAL( goNextYear() ), 659 connect( mMonthView->navigatorBar(), SIGNAL( goNextYear() ),
653 mMainView->dateNavigator(), SLOT( selectNextYear() ) ); 660 mMainView->dateNavigator(), SLOT( selectNextYear() ) );
654 connect( mMonthView->navigatorBar(), SIGNAL( goPrevMonth() ), 661 connect( mMonthView->navigatorBar(), SIGNAL( goPrevMonth() ),
655 mMainView->dateNavigator(), SLOT( selectPreviousMonth() ) ); 662 mMainView->dateNavigator(), SLOT( selectPreviousMonth() ) );
656 connect( mMonthView->navigatorBar(), SIGNAL( goNextMonth() ), 663 connect( mMonthView->navigatorBar(), SIGNAL( goNextMonth() ),
657 mMainView->dateNavigator(), SLOT( selectNextMonth() ) ); 664 mMainView->dateNavigator(), SLOT( selectNextMonth() ) );
658 connect( mMonthView->navigatorBar(), SIGNAL( goPrevWeek() ), 665 connect( mMonthView->navigatorBar(), SIGNAL( goPrevWeek() ),
659 mMainView->dateNavigator(), SLOT( selectPreviousWeek() ) ); 666 mMainView->dateNavigator(), SLOT( selectPreviousWeek() ) );
660 connect( mMonthView->navigatorBar(), SIGNAL( goNextWeek() ), 667 connect( mMonthView->navigatorBar(), SIGNAL( goNextWeek() ),
661 mMainView->dateNavigator(), SLOT( selectNextWeek() ) ); 668 mMainView->dateNavigator(), SLOT( selectNextWeek() ) );
662 669
663 connect( mMainView->dateNavigator(), SIGNAL( datesSelected( const KCal::DateList & ) ), 670 connect( mMainView->dateNavigator(), SIGNAL( datesSelected( const KCal::DateList & ) ),
664 mMonthView->navigatorBar(), SLOT( selectDates( const KCal::DateList & ) ) ); 671 mMonthView->navigatorBar(), SLOT( selectDates( const KCal::DateList & ) ) );
665 672
666 673
667 connect( mMonthView->navigatorBar(), SIGNAL( monthSelected ( int ) ), 674 connect( mMonthView->navigatorBar(), SIGNAL( monthSelected ( int ) ),
668 mMainView->dateNavigator(), SLOT( slotMonthSelect( int ) ) ); 675 mMainView->dateNavigator(), SLOT( slotMonthSelect( int ) ) );
669 676
670 } 677 }
671} 678}
672void KOViewManager::showMonthViewWeek() 679void KOViewManager::showMonthViewWeek()
673{ 680{
674 createMonthView(); 681 createMonthView();
675 KOPrefs::instance()->mCurrentDisplayedView = VIEW_ML_VIEW ; 682 KOPrefs::instance()->mCurrentDisplayedView = VIEW_ML_VIEW ;
676 globalFlagBlockAgenda = 1; 683 globalFlagBlockAgenda = 1;
677 bool full = true; 684 bool full = true;
678 if ( mCurrentView == mMonthView) 685 if ( mCurrentView == mMonthView)
679 full = mMainView->leftFrame()->isVisible(); 686 full = mMainView->leftFrame()->isVisible();
680 if ( !KOPrefs::instance()->mMonthViewWeek ) { 687 if ( !KOPrefs::instance()->mMonthViewWeek ) {
681 mMonthView->switchView(); 688 mMonthView->switchView();
682 if ( KOPrefs::instance()->mViewChangeHoldNonFullscreen && mMainView->leftFrame()->isVisible() ) 689 if ( KOPrefs::instance()->mViewChangeHoldNonFullscreen && mMainView->leftFrame()->isVisible() )
683 full = false; 690 full = false;
684 else 691 else
685 full = true; 692 full = true;
686 } 693 }
687 mMainView->dateNavigator()->selectWeek(); 694 mMainView->dateNavigator()->selectWeek();
688 showView(mMonthView, full ); 695 showView(mMonthView, full );
689 mMonthView->setKeyBFocus(); 696 mMonthView->setKeyBFocus();
690 KOPrefs::instance()->mCurrentDisplayedView = VIEW_ML_VIEW ; 697 KOPrefs::instance()->mCurrentDisplayedView = VIEW_ML_VIEW ;
691} 698}
692 699
693void KOViewManager::showMonth( const QDate & date ) 700void KOViewManager::showMonth( const QDate & date )
694{ 701{
695 mMainView->dateNavigator()->blockSignals( true ); 702 mMainView->dateNavigator()->blockSignals( true );
696 mMainView->dateNavigator()->selectDate( date ); 703 mMainView->dateNavigator()->selectDate( date );
697 mMainView->dateNavigator()->blockSignals( false ); 704 mMainView->dateNavigator()->blockSignals( false );
698 showMonthView(); 705 showMonthView();
699} 706}
700void KOViewManager::showMonthView() 707void KOViewManager::showMonthView()
701 { 708 {
702 709
703 createMonthView(); 710 createMonthView();
704 KOPrefs::instance()->mCurrentDisplayedView = VIEW_M_VIEW ; 711 KOPrefs::instance()->mCurrentDisplayedView = VIEW_M_VIEW ;
705 globalFlagBlockAgenda = 1; 712 globalFlagBlockAgenda = 1;
706 //mFlagShowNextxDays = false; 713 //mFlagShowNextxDays = false;
707 bool full = true; 714 bool full = true;
708 if ( mCurrentView == mMonthView) 715 if ( mCurrentView == mMonthView)
709 full = mMainView->leftFrame()->isVisible(); 716 full = mMainView->leftFrame()->isVisible();
710 // if(mMonthView == mCurrentView) return; 717 // if(mMonthView == mCurrentView) return;
711 if ( KOPrefs::instance()->mMonthViewWeek ) { 718 if ( KOPrefs::instance()->mMonthViewWeek ) {
712 mMonthView->switchView(); 719 mMonthView->switchView();
713 if ( KOPrefs::instance()->mViewChangeHoldNonFullscreen && mMainView->leftFrame()->isVisible() ) 720 if ( KOPrefs::instance()->mViewChangeHoldNonFullscreen && mMainView->leftFrame()->isVisible() )
714 full = false; 721 full = false;
715 else 722 else
716 full = true; 723 full = true;
717 } 724 }
718 mMainView->dateNavigator()->selectMonth(); 725 mMainView->dateNavigator()->selectMonth();
719 726
720 showView(mMonthView, full ); 727 showView(mMonthView, full );
721 mMonthView->setKeyBFocus(); 728 mMonthView->setKeyBFocus();
722 KOPrefs::instance()->mCurrentDisplayedView = VIEW_M_VIEW ; 729 KOPrefs::instance()->mCurrentDisplayedView = VIEW_M_VIEW ;
723 730
724} 731}
725 732
726void KOViewManager::showTodoView() 733void KOViewManager::showTodoView()
727{ 734{
728 //mFlagShowNextxDays = false; 735 //mFlagShowNextxDays = false;
729 if ( !mTodoView ) { 736 if ( !mTodoView ) {
730 mTodoView = new KOTodoView( mMainView->calendar(), mMainView->viewStack(), 737 mTodoView = new KOTodoView( mMainView->calendar(), mMainView->viewStack(),
731 "KOViewManager::TodoView" ); 738 "KOViewManager::TodoView" );
732 739
733 addView( mTodoView ); 740 addView( mTodoView );
734 // QPEApplication::setStylusOperation( mTodoView, QPEApplication::RightOnHold ); 741 // QPEApplication::setStylusOperation( mTodoView, QPEApplication::RightOnHold );
735 742
736 // SIGNALS/SLOTS FOR TODO VIEW 743 // SIGNALS/SLOTS FOR TODO VIEW
737 connect( mTodoView, SIGNAL( newTodoSignal() ), 744 connect( mTodoView, SIGNAL( newTodoSignal() ),
738 mMainView, SLOT( newTodo() ) ); 745 mMainView, SLOT( newTodo() ) );
739 connect( mTodoView, SIGNAL( newSubTodoSignal( Todo * ) ), 746 connect( mTodoView, SIGNAL( newSubTodoSignal( Todo * ) ),
740 mMainView, SLOT( newSubTodo( Todo *) ) ); 747 mMainView, SLOT( newSubTodo( Todo *) ) );
741 connect( mTodoView, SIGNAL( showTodoSignal( Todo *) ), 748 connect( mTodoView, SIGNAL( showTodoSignal( Todo *) ),
742 mMainView, SLOT( showTodo( Todo * ) ) ); 749 mMainView, SLOT( showTodo( Todo * ) ) );
743 connect( mTodoView, SIGNAL( editTodoSignal( Todo * ) ), 750 connect( mTodoView, SIGNAL( editTodoSignal( Todo * ) ),
744 mMainView, SLOT( editTodo( Todo * ) ) ); 751 mMainView, SLOT( editTodo( Todo * ) ) );
745 connect( mTodoView, SIGNAL( deleteTodoSignal( Todo * ) ), 752 connect( mTodoView, SIGNAL( deleteTodoSignal( Todo * ) ),
746 mMainView, SLOT( deleteTodo( Todo * ) ) ); 753 mMainView, SLOT( deleteTodo( Todo * ) ) );
747 connect( mTodoView, SIGNAL( purgeCompletedSignal() ), 754 connect( mTodoView, SIGNAL( purgeCompletedSignal() ),
748 mMainView, SLOT( purgeCompleted() ) ); 755 mMainView, SLOT( purgeCompleted() ) );
749 756
750 connect( mTodoView, SIGNAL( incidenceSelected( Incidence * ) ), 757 connect( mTodoView, SIGNAL( incidenceSelected( Incidence * ) ),
751 mMainView, SLOT( processMainViewSelection( Incidence * ) ) ); 758 mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
752 759
753 connect( mMainView, SIGNAL( configChanged() ), mTodoView, 760 connect( mMainView, SIGNAL( configChanged() ), mTodoView,
754 SLOT( updateConfig() ) ); 761 SLOT( updateConfig() ) );
755 connect( mMainView, SIGNAL( todoModified( Todo *, int )), mTodoView, 762 connect( mMainView, SIGNAL( todoModified( Todo *, int )), mTodoView,
756 SLOT( updateTodo( Todo *, int ) ) ); 763 SLOT( updateTodo( Todo *, int ) ) );
757 connect( mTodoView, SIGNAL( todoModifiedSignal( Todo *, int ) ), 764 connect( mTodoView, SIGNAL( todoModifiedSignal( Todo *, int ) ),
758 mMainView, SIGNAL ( todoModified( Todo *, int ) ) ); 765 mMainView, SIGNAL ( todoModified( Todo *, int ) ) );
759 connect( mTodoView, SIGNAL( cloneTodoSignal( Incidence * ) ), 766 connect( mTodoView, SIGNAL( cloneTodoSignal( Incidence * ) ),
760 mMainView, SLOT ( cloneIncidence( Incidence * ) ) ); 767 mMainView, SLOT ( cloneIncidence( Incidence * ) ) );
761 connect( mTodoView, SIGNAL( cancelTodoSignal( Incidence * ) ), 768 connect( mTodoView, SIGNAL( cancelTodoSignal( Incidence * ) ),
762 mMainView, SLOT ( cancelIncidence( Incidence * ) ) ); 769 mMainView, SLOT ( cancelIncidence( Incidence * ) ) );
763 connect( mTodoView, SIGNAL( unparentTodoSignal( Todo * ) ), 770 connect( mTodoView, SIGNAL( unparentTodoSignal( Todo * ) ),
764 mMainView, SLOT ( todo_unsub( Todo * ) ) ); 771 mMainView, SLOT ( todo_unsub( Todo * ) ) );
765 connect( mTodoView, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), 772 connect( mTodoView, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ),
766 mMainView, SLOT ( todo_resub( Todo *, Todo *) ) ); 773 mMainView, SLOT ( todo_resub( Todo *, Todo *) ) );
767 connect( mTodoView, SIGNAL( moveTodoSignal( Incidence * ) ), 774 connect( mTodoView, SIGNAL( moveTodoSignal( Incidence * ) ),
768 mMainView, SLOT ( moveIncidence( Incidence * ) ) ); 775 mMainView, SLOT ( moveIncidence( Incidence * ) ) );
769 connect( mTodoView, SIGNAL( beamTodoSignal( Incidence * ) ), 776 connect( mTodoView, SIGNAL( beamTodoSignal( Incidence * ) ),
770 mMainView, SLOT ( beamIncidence( Incidence * ) ) ); 777 mMainView, SLOT ( beamIncidence( Incidence * ) ) );
771 KConfig *config = KOGlobals::config(); 778 KConfig *config = KOGlobals::config();
772 mTodoView->restoreLayout(config,"Todo View"); 779 mTodoView->restoreLayout(config,"Todo View");
773 mTodoView->setNavigator( mMainView->dateNavigator() ); 780 mTodoView->setNavigator( mMainView->dateNavigator() );
774 } 781 }
775 782
776 KOPrefs::instance()->mCurrentDisplayedView = VIEW_T_VIEW ; 783 KOPrefs::instance()->mCurrentDisplayedView = VIEW_T_VIEW ;
777 globalFlagBlockAgenda = 1; 784 globalFlagBlockAgenda = 1;
778 showView( mTodoView, true ); 785 showView( mTodoView, true );
779 KOPrefs::instance()->mCurrentDisplayedView = VIEW_T_VIEW ; 786 KOPrefs::instance()->mCurrentDisplayedView = VIEW_T_VIEW ;
780 787
781} 788}
782 789
783void KOViewManager::showJournalView() 790void KOViewManager::showJournalView()
784{ 791{
785 //mFlagShowNextxDays = false; 792 //mFlagShowNextxDays = false;
786 if (!mJournalView) { 793 if (!mJournalView) {
787 mJournalView = new KOJournalView(mMainView->calendar(),mMainView->viewStack(), 794 mJournalView = new KOJournalView(mMainView->calendar(),mMainView->viewStack(),
788 "KOViewManager::JournalView"); 795 "KOViewManager::JournalView");
789 connect( mMainView, SIGNAL( configChanged() ), mJournalView, 796 connect( mMainView, SIGNAL( configChanged() ), mJournalView,
790 SLOT( updateConfig() ) ); 797 SLOT( updateConfig() ) );
791 connect(mJournalView, SIGNAL(deleteJournal(Journal *) ), mMainView,SLOT(deleteJournal(Journal *)) ); 798 connect(mJournalView, SIGNAL(deleteJournal(Journal *) ), mMainView,SLOT(deleteJournal(Journal *)) );
792 addView(mJournalView); 799 addView(mJournalView);
793 } 800 }
794 801
795 KOPrefs::instance()->mCurrentDisplayedView = VIEW_J_VIEW ; 802 KOPrefs::instance()->mCurrentDisplayedView = VIEW_J_VIEW ;
796 showView(mJournalView); 803 showView(mJournalView);
797 mMainView->dateNavigator()->selectDates( 1 ); 804 mMainView->dateNavigator()->selectDates( 1 );
798 KOPrefs::instance()->mCurrentDisplayedView = VIEW_J_VIEW ; 805 KOPrefs::instance()->mCurrentDisplayedView = VIEW_J_VIEW ;
799} 806}
800 807
801void KOViewManager::showTimeSpanView() 808void KOViewManager::showTimeSpanView()
802{ 809{
803 //mFlagShowNextxDays = false; 810 //mFlagShowNextxDays = false;
804 if (!mTimeSpanView) { 811 if (!mTimeSpanView) {
805 mTimeSpanView = new KOTimeSpanView(mMainView->calendar(),mMainView->viewStack(), 812 mTimeSpanView = new KOTimeSpanView(mMainView->calendar(),mMainView->viewStack(),
806 "KOViewManager::TimeSpanView"); 813 "KOViewManager::TimeSpanView");
807 addView(mTimeSpanView); 814 addView(mTimeSpanView);
808 815
809 mTimeSpanView->readSettings(); 816 mTimeSpanView->readSettings();
810 } 817 }
811 818
812 showView(mTimeSpanView); 819 showView(mTimeSpanView);
813} 820}
814 821
815Incidence *KOViewManager::currentSelection() 822Incidence *KOViewManager::currentSelection()
816{ 823{
817 if (!mCurrentView) return 0; 824 if (!mCurrentView) return 0;
818 if ( mCurrentView == mListView ) { 825 if ( mCurrentView == mListView ) {
819 if ( mListView->currentItem() ) 826 if ( mListView->currentItem() )
820 return mListView->currentItem(); 827 return mListView->currentItem();
821 } 828 }
822 return mCurrentView->selectedIncidences().first(); 829 return mCurrentView->selectedIncidences().first();
823} 830}
824 831
825QDate KOViewManager::currentSelectionDate() 832QDate KOViewManager::currentSelectionDate()
826{ 833{
827 QDate qd; 834 QDate qd;
828 if (mCurrentView) { 835 if (mCurrentView) {
829 DateList qvl = mCurrentView->selectedDates(); 836 DateList qvl = mCurrentView->selectedDates();
830 if (!qvl.isEmpty()) qd = qvl.first(); 837 if (!qvl.isEmpty()) qd = qvl.first();
831 } 838 }
832 return qd; 839 return qd;
833} 840}
834 841
835void KOViewManager::addView(KOrg::BaseView *view) 842void KOViewManager::addView(KOrg::BaseView *view)
836{ 843{
837#if QT_VERSION >= 0x030000 844#if QT_VERSION >= 0x030000
838 mMainView->viewStack()->addWidget( view ); 845 mMainView->viewStack()->addWidget( view );
839#else 846#else
840 mMainView->viewStack()->addWidget( view, 1 ); 847 mMainView->viewStack()->addWidget( view, 1 );
841#endif 848#endif
842} 849}
843 850
844void KOViewManager::setDocumentId( const QString &id ) 851void KOViewManager::setDocumentId( const QString &id )
845{ 852{
846 if (mTodoView) { 853 if (mTodoView) {
847 mTodoView->setDocumentId( id ); 854 mTodoView->setDocumentId( id );
848 } 855 }
849} 856}
diff --git a/korganizer/koviewmanager.h b/korganizer/koviewmanager.h
index 838583b..d5a8e3b 100644
--- a/korganizer/koviewmanager.h
+++ b/korganizer/koviewmanager.h
@@ -1,127 +1,128 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 3 Copyright (c) 2001
4 Cornelius Schumacher <schumacher@kde.org> 4 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or 8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software 17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 19
20 As a special exception, permission is given to link this program 20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable, 21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution. 22 without including the source code for Qt in the source distribution.
23*/ 23*/
24#ifndef KOVIEWMANAGER_H 24#ifndef KOVIEWMANAGER_H
25#define KOVIEWMANAGER_H 25#define KOVIEWMANAGER_H
26 26
27#include <qobject.h> 27#include <qobject.h>
28 28
29#include <korganizer/baseview.h> 29#include <korganizer/baseview.h>
30 30
31class CalendarView; 31class CalendarView;
32 32
33class KOListView; 33class KOListView;
34class KOAgendaView; 34class KOAgendaView;
35class KOMonthView; 35class KOMonthView;
36class KOTimeSpanView; 36class KOTimeSpanView;
37class KOTodoView; 37class KOTodoView;
38class KOWhatsNextView; 38class KOWhatsNextView;
39class KOJournalView; 39class KOJournalView;
40 40
41using namespace KCal; 41using namespace KCal;
42 42
43/** 43/**
44 This class manages the views of the calendar. It owns the objects and handles 44 This class manages the views of the calendar. It owns the objects and handles
45 creation and selection. 45 creation and selection.
46*/ 46*/
47class KOViewManager : public QObject 47class KOViewManager : public QObject
48{ 48{
49 Q_OBJECT 49 Q_OBJECT
50 public: 50 public:
51 KOViewManager( CalendarView * ); 51 KOViewManager( CalendarView * );
52 virtual ~KOViewManager(); 52 virtual ~KOViewManager();
53 53
54 /** changes the view to be the currently selected view */ 54 /** changes the view to be the currently selected view */
55 void showView(KOrg::BaseView *, bool fullScreen = false ); 55 void showView(KOrg::BaseView *, bool fullScreen = false );
56 void updateWNview(); 56 void updateWNview();
57 void readSettings(KConfig *config); 57 void readSettings(KConfig *config);
58 void writeSettings(KConfig *config); 58 void writeSettings(KConfig *config);
59 bool showsNextDays(); 59 bool showsNextDays();
60 /** Read which view was shown last from config file */ 60 /** Read which view was shown last from config file */
61 void readCurrentView(KConfig *); 61 void readCurrentView(KConfig *);
62 /** Write which view is currently shown to config file */ 62 /** Write which view is currently shown to config file */
63 void writeCurrentView(KConfig *); 63 void writeCurrentView(KConfig *);
64 64
65 KOrg::BaseView *currentView(); 65 KOrg::BaseView *currentView();
66 66
67 void setDocumentId( const QString & ); 67 void setDocumentId( const QString & );
68 68
69 void updateView( const QDate &start, const QDate &end ); 69 void updateView( const QDate &start, const QDate &end );
70 void clearAllViews(); 70 void clearAllViews();
71 71
72 void raiseCurrentView( bool fullScreen = false , bool updateView = false); 72 void raiseCurrentView( bool fullScreen = false , bool updateView = false);
73 73
74 void addView(KOrg::BaseView *); 74 void addView(KOrg::BaseView *);
75 75
76 Incidence *currentSelection(); 76 Incidence *currentSelection();
77 QDate currentSelectionDate(); 77 QDate currentSelectionDate();
78 78
79 KOAgendaView *agendaView() const { return mAgendaView; } 79 KOAgendaView *agendaView() const { return mAgendaView; }
80 80
81 signals: 81 signals:
82 void printWNV(); 82 void printWNV();
83 void signalFullScreen( bool ); 83 void signalFullScreen( bool );
84 void signalAgendaView( bool ); 84 void signalAgendaView( bool );
85 public slots: 85 public slots:
86 void setDefaultCalendar(int);
86 void slotprintWNV(); 87 void slotprintWNV();
87 void showNextView(); 88 void showNextView();
88 void showMonth( const QDate & ); 89 void showMonth( const QDate & );
89 void showDateView( int, QDate ); 90 void showDateView( int, QDate );
90 void updateView(); 91 void updateView();
91 void showWhatsNextView(); 92 void showWhatsNextView();
92 void showListView(); 93 void showListView();
93 void showAgendaView( bool fullScreen = false ); 94 void showAgendaView( bool fullScreen = false );
94 void showDayView(); 95 void showDayView();
95 void showWorkWeekView(); 96 void showWorkWeekView();
96 void showWeekView(); 97 void showWeekView();
97 void showNextXView(); 98 void showNextXView();
98 void showMonthView(); 99 void showMonthView();
99 void showMonthViewWeek(); 100 void showMonthViewWeek();
100 void showTodoView(); 101 void showTodoView();
101 void showJournalView(); 102 void showJournalView();
102 void showTimeSpanView(); 103 void showTimeSpanView();
103 104
104 private: 105 private:
105 void resetDateSilent( QDate date , int days ); 106 void resetDateSilent( QDate date , int days );
106 int flagResetViewChangeDate; 107 int flagResetViewChangeDate;
107 QDate currentViewChangeDate; 108 QDate currentViewChangeDate;
108 void createMonthView(); 109 void createMonthView();
109 CalendarView *mMainView; 110 CalendarView *mMainView;
110 111
111 int mCurrentAgendaView; 112 int mCurrentAgendaView;
112 KOAgendaView *mAgendaView; 113 KOAgendaView *mAgendaView;
113 KOListView *mListView; 114 KOListView *mListView;
114 KOMonthView *mMonthView; 115 KOMonthView *mMonthView;
115 KOTodoView *mTodoView; 116 KOTodoView *mTodoView;
116 KOWhatsNextView *mWhatsNextView; 117 KOWhatsNextView *mWhatsNextView;
117 KOJournalView *mJournalView; 118 KOJournalView *mJournalView;
118 KOTimeSpanView *mTimeSpanView; 119 KOTimeSpanView *mTimeSpanView;
119 120
120 KOrg::BaseView *mCurrentView; // currently active event view 121 KOrg::BaseView *mCurrentView; // currently active event view
121 122
122 int mAgendaViewMode; 123 int mAgendaViewMode;
123 bool mFlagShowNextxDays; 124 bool mFlagShowNextxDays;
124 125
125}; 126};
126 127
127#endif 128#endif
diff --git a/libkcal/calendar.h b/libkcal/calendar.h
index 2efa355..4652fe5 100644
--- a/libkcal/calendar.h
+++ b/libkcal/calendar.h
@@ -1,376 +1,377 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#ifndef CALENDAR_H 22#ifndef CALENDAR_H
23#define CALENDAR_H 23#define CALENDAR_H
24 24
25#include <qobject.h> 25#include <qobject.h>
26#include <qstring.h> 26#include <qstring.h>
27#include <qdatetime.h> 27#include <qdatetime.h>
28#include <qptrlist.h> 28#include <qptrlist.h>
29#include <qdict.h> 29#include <qdict.h>
30 30
31#include "customproperties.h" 31#include "customproperties.h"
32#include "event.h" 32#include "event.h"
33#include "todo.h" 33#include "todo.h"
34#include "journal.h" 34#include "journal.h"
35#include "calfilter.h" 35#include "calfilter.h"
36 36
37//#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ 37//#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */
38 38
39class KConfig; 39class KConfig;
40 40
41namespace KCal { 41namespace KCal {
42 42
43 43
44/** 44/**
45 This is the main "calendar" object class for KOrganizer. It holds 45 This is the main "calendar" object class for KOrganizer. It holds
46 information like all appointments/events, user information, etc. etc. 46 information like all appointments/events, user information, etc. etc.
47 one calendar is associated with each CalendarView (@see calendarview.h). 47 one calendar is associated with each CalendarView (@see calendarview.h).
48 This is an abstract base class defining the interface to a calendar. It is 48 This is an abstract base class defining the interface to a calendar. It is
49 implemented by subclasses like @see CalendarLocal, which use different 49 implemented by subclasses like @see CalendarLocal, which use different
50 methods to store and access the data. 50 methods to store and access the data.
51 51
52 Ownership of events etc. is handled by the following policy: As soon as an 52 Ownership of events etc. is handled by the following policy: As soon as an
53 event (or any other subclass of IncidenceBase) object is added to the 53 event (or any other subclass of IncidenceBase) object is added to the
54 Calendar by addEvent() it is owned by the Calendar object. The Calendar takes 54 Calendar by addEvent() it is owned by the Calendar object. The Calendar takes
55 care of deleting it. All Events returned by the query functions are returned 55 care of deleting it. All Events returned by the query functions are returned
56 as pointers, that means all changes to the returned events are immediately 56 as pointers, that means all changes to the returned events are immediately
57 visible in the Calendar. You shouldn't delete any Event object you get from 57 visible in the Calendar. You shouldn't delete any Event object you get from
58 Calendar. 58 Calendar.
59*/ 59*/
60class Calendar : public QObject, public CustomProperties, 60class Calendar : public QObject, public CustomProperties,
61 public IncidenceBase::Observer 61 public IncidenceBase::Observer
62{ 62{
63 Q_OBJECT 63 Q_OBJECT
64public: 64public:
65 Calendar(); 65 Calendar();
66 Calendar(const QString &timeZoneId); 66 Calendar(const QString &timeZoneId);
67 virtual ~Calendar(); 67 virtual ~Calendar();
68 Incidence * undoIncidence() { return mUndoIncidence; }; 68 Incidence * undoIncidence() { return mUndoIncidence; };
69 bool undoDeleteIncidence(); 69 bool undoDeleteIncidence();
70 void deleteIncidence(Incidence *in); 70 void deleteIncidence(Incidence *in);
71 void resetTempSyncStat(); 71 void resetTempSyncStat();
72 void resetPilotStat(int id); 72 void resetPilotStat(int id);
73 /** 73 /**
74 Clears out the current calendar, freeing all used memory etc. 74 Clears out the current calendar, freeing all used memory etc.
75 */ 75 */
76 virtual void close() = 0; 76 virtual void close() = 0;
77 virtual void addCalendar( Calendar* ) = 0; 77 virtual void addCalendar( Calendar* ) = 0;
78 virtual bool addCalendarFile( QString name, int id ) = 0; 78 virtual bool addCalendarFile( QString name, int id ) = 0;
79 virtual void setSyncEventsReadOnly() = 0; 79 virtual void setSyncEventsReadOnly() = 0;
80 virtual void stopAllTodos() = 0; 80 virtual void stopAllTodos() = 0;
81 81
82 /** 82 /**
83 Sync changes in memory to persistant storage. 83 Sync changes in memory to persistant storage.
84 */ 84 */
85 virtual void save() = 0; 85 virtual void save() = 0;
86 virtual QPtrList<Event> getExternLastSyncEvents() = 0; 86 virtual QPtrList<Event> getExternLastSyncEvents() = 0;
87 virtual void removeSyncInfo( QString syncProfile) = 0; 87 virtual void removeSyncInfo( QString syncProfile) = 0;
88 virtual bool isSaving() { return false; } 88 virtual bool isSaving() { return false; }
89 89
90 /** 90 /**
91 Return the owner of the calendar's full name. 91 Return the owner of the calendar's full name.
92 */ 92 */
93 const QString &getOwner() const; 93 const QString &getOwner() const;
94 /** 94 /**
95 Set the owner of the calendar. Should be owner's full name. 95 Set the owner of the calendar. Should be owner's full name.
96 */ 96 */
97 void setOwner( const QString &os ); 97 void setOwner( const QString &os );
98 /** 98 /**
99 Return the email address of the calendar owner. 99 Return the email address of the calendar owner.
100 */ 100 */
101 const QString &getEmail(); 101 const QString &getEmail();
102 /** 102 /**
103 Set the email address of the calendar owner. 103 Set the email address of the calendar owner.
104 */ 104 */
105 void setEmail( const QString & ); 105 void setEmail( const QString & );
106 106
107 /** 107 /**
108 Set time zone from a timezone string (e.g. -2:00) 108 Set time zone from a timezone string (e.g. -2:00)
109 */ 109 */
110 void setTimeZone( const QString &tz ); 110 void setTimeZone( const QString &tz );
111 /** 111 /**
112 Set time zone from a minutes value (e.g. -60) 112 Set time zone from a minutes value (e.g. -60)
113 */ 113 */
114 void setTimeZone( int tz ); 114 void setTimeZone( int tz );
115 /** 115 /**
116 Return time zone as offest in minutes. 116 Return time zone as offest in minutes.
117 */ 117 */
118 int getTimeZone() const; 118 int getTimeZone() const;
119 /** 119 /**
120 Compute an ISO 8601 format string from the time zone. 120 Compute an ISO 8601 format string from the time zone.
121 */ 121 */
122 QString getTimeZoneStr() const; 122 QString getTimeZoneStr() const;
123 /** 123 /**
124 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal 124 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal
125 values). 125 values).
126 */ 126 */
127 void setTimeZoneId( const QString & ); 127 void setTimeZoneId( const QString & );
128 /** 128 /**
129 Return time zone id. 129 Return time zone id.
130 */ 130 */
131 QString timeZoneId() const; 131 QString timeZoneId() const;
132 /** 132 /**
133 Use local time, not UTC or a time zone. 133 Use local time, not UTC or a time zone.
134 */ 134 */
135 void setLocalTime(); 135 void setLocalTime();
136 /** 136 /**
137 Return whether local time is being used. 137 Return whether local time is being used.
138 */ 138 */
139 bool isLocalTime() const; 139 bool isLocalTime() const;
140 140
141 /** 141 /**
142 Add an incidence to calendar. 142 Add an incidence to calendar.
143 143
144 @return true on success, false on error. 144 @return true on success, false on error.
145 */ 145 */
146 virtual bool addIncidence( Incidence * ); 146 virtual bool addIncidence( Incidence * );
147 147
148 // Adds an incidence and all relatedto incidences to the cal 148 // Adds an incidence and all relatedto incidences to the cal
149 void addIncidenceBranch( Incidence * ); 149 void addIncidenceBranch( Incidence * );
150 /** 150 /**
151 Return filtered list of all incidences of this calendar. 151 Return filtered list of all incidences of this calendar.
152 */ 152 */
153 virtual QPtrList<Incidence> incidences(); 153 virtual QPtrList<Incidence> incidences();
154 154
155 /** 155 /**
156 Return unfiltered list of all incidences of this calendar. 156 Return unfiltered list of all incidences of this calendar.
157 */ 157 */
158 virtual QPtrList<Incidence> rawIncidences(); 158 virtual QPtrList<Incidence> rawIncidences();
159 159
160 /** 160 /**
161 Adds a Event to this calendar object. 161 Adds a Event to this calendar object.
162 @param anEvent a pointer to the event to add 162 @param anEvent a pointer to the event to add
163 163
164 @return true on success, false on error. 164 @return true on success, false on error.
165 */ 165 */
166 virtual bool addEventNoDup( Event *event ) = 0; 166 virtual bool addEventNoDup( Event *event ) = 0;
167 virtual bool addAnniversaryNoDup( Event *event ) = 0; 167 virtual bool addAnniversaryNoDup( Event *event ) = 0;
168 virtual bool addEvent( Event *anEvent ) = 0; 168 virtual bool addEvent( Event *anEvent ) = 0;
169 /** 169 /**
170 Delete event from calendar. 170 Delete event from calendar.
171 */ 171 */
172 virtual void deleteEvent( Event * ) = 0; 172 virtual void deleteEvent( Event * ) = 0;
173 /** 173 /**
174 Retrieves an event on the basis of the unique string ID. 174 Retrieves an event on the basis of the unique string ID.
175 */ 175 */
176 virtual Event *event( const QString &UniqueStr ) = 0; 176 virtual Event *event( const QString &UniqueStr ) = 0;
177 virtual Event *event( QString, QString ) = 0; 177 virtual Event *event( QString, QString ) = 0;
178 /** 178 /**
179 Builds and then returns a list of all events that match for the 179 Builds and then returns a list of all events that match for the
180 date specified. useful for dayView, etc. etc. 180 date specified. useful for dayView, etc. etc.
181 The calendar filter is applied. 181 The calendar filter is applied.
182 */ 182 */
183 QPtrList<Event> events( const QDate &date, bool sorted = false); 183 QPtrList<Event> events( const QDate &date, bool sorted = false);
184 /** 184 /**
185 Get events, which occur on the given date. 185 Get events, which occur on the given date.
186 The calendar filter is applied. 186 The calendar filter is applied.
187 */ 187 */
188 QPtrList<Event> events( const QDateTime &qdt ); 188 QPtrList<Event> events( const QDateTime &qdt );
189 /** 189 /**
190 Get events in a range of dates. If inclusive is set to true, only events 190 Get events in a range of dates. If inclusive is set to true, only events
191 are returned, which are completely included in the range. 191 are returned, which are completely included in the range.
192 The calendar filter is applied. 192 The calendar filter is applied.
193 */ 193 */
194 QPtrList<Event> events( const QDate &start, const QDate &end, 194 QPtrList<Event> events( const QDate &start, const QDate &end,
195 bool inclusive = false); 195 bool inclusive = false);
196 /** 196 /**
197 Return filtered list of all events in calendar. 197 Return filtered list of all events in calendar.
198 */ 198 */
199 virtual QPtrList<Event> events(); 199 virtual QPtrList<Event> events();
200 /** 200 /**
201 Return unfiltered list of all events in calendar. 201 Return unfiltered list of all events in calendar.
202 */ 202 */
203 virtual QPtrList<Event> rawEvents() = 0; 203 virtual QPtrList<Event> rawEvents() = 0;
204 204
205 /** 205 /**
206 Add a todo to the todolist. 206 Add a todo to the todolist.
207 207
208 @return true on success, false on error. 208 @return true on success, false on error.
209 */ 209 */
210 virtual bool addTodo( Todo *todo ) = 0; 210 virtual bool addTodo( Todo *todo ) = 0;
211 virtual bool addTodoNoDup( Todo *todo ) = 0; 211 virtual bool addTodoNoDup( Todo *todo ) = 0;
212 /** 212 /**
213 Remove a todo from the todolist. 213 Remove a todo from the todolist.
214 */ 214 */
215 virtual void deleteTodo( Todo * ) = 0; 215 virtual void deleteTodo( Todo * ) = 0;
216 virtual void deleteJournal( Journal * ) = 0; 216 virtual void deleteJournal( Journal * ) = 0;
217 /** 217 /**
218 Return filterd list of todos. 218 Return filterd list of todos.
219 */ 219 */
220 virtual QPtrList<Todo> todos(); 220 virtual QPtrList<Todo> todos();
221 /** 221 /**
222 Searches todolist for an event with this unique string identifier, 222 Searches todolist for an event with this unique string identifier,
223 returns a pointer or null. 223 returns a pointer or null.
224 */ 224 */
225 virtual Todo *todo( const QString &uid ) = 0; 225 virtual Todo *todo( const QString &uid ) = 0;
226 virtual Todo *todo( QString, QString ) = 0; 226 virtual Todo *todo( QString, QString ) = 0;
227 /** 227 /**
228 Returns list of todos due on the specified date. 228 Returns list of todos due on the specified date.
229 */ 229 */
230 virtual QPtrList<Todo> todos( const QDate &date ) = 0; 230 virtual QPtrList<Todo> todos( const QDate &date ) = 0;
231 /** 231 /**
232 Return unfiltered list of todos. 232 Return unfiltered list of todos.
233 */ 233 */
234 virtual QPtrList<Todo> rawTodos() = 0; 234 virtual QPtrList<Todo> rawTodos() = 0;
235 235
236 /** 236 /**
237 Add a Journal entry to calendar. 237 Add a Journal entry to calendar.
238 238
239 @return true on success, false on error. 239 @return true on success, false on error.
240 */ 240 */
241 virtual bool addJournal( Journal * ) = 0; 241 virtual bool addJournal( Journal * ) = 0;
242 /** 242 /**
243 Return Journal for given date. 243 Return Journal for given date.
244 */ 244 */
245 virtual Journal *journal( const QDate & ) = 0; 245 virtual Journal *journal( const QDate & ) = 0;
246 virtual QPtrList<Journal> journals4Date( const QDate & ) = 0;
246 /** 247 /**
247 Return Journal with given UID. 248 Return Journal with given UID.
248 */ 249 */
249 virtual Journal *journal( const QString &UID ) = 0; 250 virtual Journal *journal( const QString &UID ) = 0;
250 /** 251 /**
251 Return list of all Journal entries. 252 Return list of all Journal entries.
252 */ 253 */
253 virtual QPtrList<Journal> journals() = 0; 254 virtual QPtrList<Journal> journals() = 0;
254 255
255 /** 256 /**
256 Searches all incidence types for an incidence with this unique 257 Searches all incidence types for an incidence with this unique
257 string identifier, returns a pointer or null. 258 string identifier, returns a pointer or null.
258 */ 259 */
259 Incidence* incidence( const QString&UID ); 260 Incidence* incidence( const QString&UID );
260 261
261 /** 262 /**
262 Setup relations for an incidence. 263 Setup relations for an incidence.
263 */ 264 */
264 virtual void setupRelations( Incidence * ); 265 virtual void setupRelations( Incidence * );
265 /** 266 /**
266 Remove all relations to an incidence 267 Remove all relations to an incidence
267 */ 268 */
268 virtual void removeRelations( Incidence * ); 269 virtual void removeRelations( Incidence * );
269 270
270 /** 271 /**
271 Set calendar filter, which filters events for the events() functions. 272 Set calendar filter, which filters events for the events() functions.
272 The Filter object is owned by the caller. 273 The Filter object is owned by the caller.
273 */ 274 */
274 void setFilter( CalFilter * ); 275 void setFilter( CalFilter * );
275 /** 276 /**
276 Return calendar filter. 277 Return calendar filter.
277 */ 278 */
278 CalFilter *filter(); 279 CalFilter *filter();
279 virtual QDateTime nextAlarm( int daysTo ) = 0; 280 virtual QDateTime nextAlarm( int daysTo ) = 0;
280 virtual QString nextSummary( ) const = 0; 281 virtual QString nextSummary( ) const = 0;
281 virtual void reInitAlarmSettings() = 0; 282 virtual void reInitAlarmSettings() = 0;
282 virtual QDateTime nextAlarmEventDateTime() const = 0; 283 virtual QDateTime nextAlarmEventDateTime() const = 0;
283 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; 284 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0;
284 /** 285 /**
285 Return all alarms, which ocur in the given time interval. 286 Return all alarms, which ocur in the given time interval.
286 */ 287 */
287 virtual Alarm::List alarms( const QDateTime &from, 288 virtual Alarm::List alarms( const QDateTime &from,
288 const QDateTime &to ) = 0; 289 const QDateTime &to ) = 0;
289 290
290 class Observer { 291 class Observer {
291 public: 292 public:
292 virtual void calendarModified( bool, Calendar * ) = 0; 293 virtual void calendarModified( bool, Calendar * ) = 0;
293 }; 294 };
294 295
295 void registerObserver( Observer * ); 296 void registerObserver( Observer * );
296 297
297 void setModified( bool ); 298 void setModified( bool );
298 299
299 /** 300 /**
300 Set product id returned by loadedProductId(). This function is only 301 Set product id returned by loadedProductId(). This function is only
301 useful for the calendar loading code. 302 useful for the calendar loading code.
302 */ 303 */
303 void setLoadedProductId( const QString & ); 304 void setLoadedProductId( const QString & );
304 /** 305 /**
305 Return product id taken from file that has been loaded. Returns 306 Return product id taken from file that has been loaded. Returns
306 QString::null, if no calendar has been loaded. 307 QString::null, if no calendar has been loaded.
307 */ 308 */
308 QString loadedProductId(); 309 QString loadedProductId();
309 int defaultCalendar(); 310 int defaultCalendar();
310 void setDontDeleteIncidencesOnClose (); 311 void setDontDeleteIncidencesOnClose ();
311 public slots: 312 public slots:
312 void setDefaultCalendar( int ); 313 void setDefaultCalendar( int );
313 virtual void setCalendarEnabled( int id, bool enable ) = 0; 314 virtual void setCalendarEnabled( int id, bool enable ) = 0;
314 virtual void setAlarmEnabled( int id, bool enable ) = 0; 315 virtual void setAlarmEnabled( int id, bool enable ) = 0;
315 virtual void setReadOnly( int id, bool enable ) = 0; 316 virtual void setReadOnly( int id, bool enable ) = 0;
316 virtual void setDefaultCalendarEnabledOnly() = 0; 317 virtual void setDefaultCalendarEnabledOnly() = 0;
317 virtual void setCalendarRemove( int id ) = 0; 318 virtual void setCalendarRemove( int id ) = 0;
318 signals: 319 signals:
319 void calendarChanged(); 320 void calendarChanged();
320 void calendarSaved(); 321 void calendarSaved();
321 void calendarLoaded(); 322 void calendarLoaded();
322 void addAlarm(const QDateTime &qdt, const QString &noti ); 323 void addAlarm(const QDateTime &qdt, const QString &noti );
323 void removeAlarm(const QDateTime &qdt, const QString &noti ); 324 void removeAlarm(const QDateTime &qdt, const QString &noti );
324 325
325 protected: 326 protected:
326 /** 327 /**
327 Get unfiltered events, which occur on the given date. 328 Get unfiltered events, which occur on the given date.
328 */ 329 */
329 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; 330 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0;
330 /** 331 /**
331 Get unfiltered events, which occur on the given date. 332 Get unfiltered events, which occur on the given date.
332 */ 333 */
333 virtual QPtrList<Event> rawEventsForDate( const QDate &date, 334 virtual QPtrList<Event> rawEventsForDate( const QDate &date,
334 bool sorted = false ) = 0; 335 bool sorted = false ) = 0;
335 /** 336 /**
336 Get events in a range of dates. If inclusive is set to true, only events 337 Get events in a range of dates. If inclusive is set to true, only events
337 are returned, which are completely included in the range. 338 are returned, which are completely included in the range.
338 */ 339 */
339 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, 340 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end,
340 bool inclusive = false ) = 0; 341 bool inclusive = false ) = 0;
341 342
342 Incidence *mNextAlarmIncidence; 343 Incidence *mNextAlarmIncidence;
343 Incidence *mUndoIncidence; 344 Incidence *mUndoIncidence;
344 int mDefaultCalendar; 345 int mDefaultCalendar;
345 bool mDeleteIncidencesOnClose; 346 bool mDeleteIncidencesOnClose;
346 347
347private: 348private:
348 void init(); 349 void init();
349 350
350 QString mOwner; // who the calendar belongs to 351 QString mOwner; // who the calendar belongs to
351 QString mOwnerEmail; // email address of the owner 352 QString mOwnerEmail; // email address of the owner
352 int mTimeZone; // timezone OFFSET from GMT (MINUTES) 353 int mTimeZone; // timezone OFFSET from GMT (MINUTES)
353 bool mLocalTime; // use local time, not UTC or a time zone 354 bool mLocalTime; // use local time, not UTC or a time zone
354 355
355 356
356 CalFilter *mFilter; 357 CalFilter *mFilter;
357 CalFilter *mDefaultFilter; 358 CalFilter *mDefaultFilter;
358 359
359 360
360 QString mTimeZoneId; 361 QString mTimeZoneId;
361 362
362 Observer *mObserver; 363 Observer *mObserver;
363 bool mNewObserver; 364 bool mNewObserver;
364 365
365 bool mModified; 366 bool mModified;
366 367
367 QString mLoadedProductId; 368 QString mLoadedProductId;
368 369
369 // This list is used to put together related todos 370 // This list is used to put together related todos
370 QDict<Incidence> mOrphans; 371 QDict<Incidence> mOrphans;
371 QDict<Incidence> mOrphanUids; 372 QDict<Incidence> mOrphanUids;
372}; 373};
373 374
374} 375}
375 376
376#endif 377#endif
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index 418bfca..ca64e66 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -1,925 +1,927 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 1998 Preston Brown 4 Copyright (c) 1998 Preston Brown
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> 5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26 26
27#include <kdebug.h> 27#include <kdebug.h>
28#include <kconfig.h> 28#include <kconfig.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#include <klocale.h> 30#include <klocale.h>
31 31
32#include "vcaldrag.h" 32#include "vcaldrag.h"
33#include "vcalformat.h" 33#include "vcalformat.h"
34#include "icalformat.h" 34#include "icalformat.h"
35#include "exceptions.h" 35#include "exceptions.h"
36#include "incidence.h" 36#include "incidence.h"
37#include "journal.h" 37#include "journal.h"
38#include "filestorage.h" 38#include "filestorage.h"
39#include "calfilter.h" 39#include "calfilter.h"
40 40
41#include "calendarlocal.h" 41#include "calendarlocal.h"
42 42
43// #ifndef DESKTOP_VERSION 43// #ifndef DESKTOP_VERSION
44// #include <qtopia/alarmserver.h> 44// #include <qtopia/alarmserver.h>
45// #endif 45// #endif
46using namespace KCal; 46using namespace KCal;
47 47
48CalendarLocal::CalendarLocal() 48CalendarLocal::CalendarLocal()
49 : Calendar() 49 : Calendar()
50{ 50{
51 init(); 51 init();
52} 52}
53 53
54CalendarLocal::CalendarLocal(const QString &timeZoneId) 54CalendarLocal::CalendarLocal(const QString &timeZoneId)
55 : Calendar(timeZoneId) 55 : Calendar(timeZoneId)
56{ 56{
57 init(); 57 init();
58} 58}
59 59
60void CalendarLocal::init() 60void CalendarLocal::init()
61{ 61{
62 mNextAlarmIncidence = 0; 62 mNextAlarmIncidence = 0;
63} 63}
64 64
65 65
66CalendarLocal::~CalendarLocal() 66CalendarLocal::~CalendarLocal()
67{ 67{
68 if ( mDeleteIncidencesOnClose ) 68 if ( mDeleteIncidencesOnClose )
69 close(); 69 close();
70} 70}
71bool CalendarLocal::addCalendarFile( QString name, int id ) 71bool CalendarLocal::addCalendarFile( QString name, int id )
72{ 72{
73 CalendarLocal calendar( timeZoneId() ); 73 CalendarLocal calendar( timeZoneId() );
74 calendar.setDefaultCalendar( id ); 74 calendar.setDefaultCalendar( id );
75 if ( calendar.load( name ) ) { 75 if ( calendar.load( name ) ) {
76 addCalendar( &calendar ); 76 addCalendar( &calendar );
77 return true; 77 return true;
78 } 78 }
79 return false; 79 return false;
80} 80}
81void CalendarLocal::setSyncEventsReadOnly() 81void CalendarLocal::setSyncEventsReadOnly()
82{ 82{
83 Event * ev; 83 Event * ev;
84 ev = mEventList.first(); 84 ev = mEventList.first();
85 while ( ev ) { 85 while ( ev ) {
86 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 86 if ( ev->uid().left(15) == QString("last-syncEvent-") )
87 ev->setReadOnly( true ); 87 ev->setReadOnly( true );
88 ev = mEventList.next(); 88 ev = mEventList.next();
89 } 89 }
90} 90}
91void CalendarLocal::addCalendar( Calendar* cal ) 91void CalendarLocal::addCalendar( Calendar* cal )
92{ 92{
93 cal->setDontDeleteIncidencesOnClose(); 93 cal->setDontDeleteIncidencesOnClose();
94 { 94 {
95 QPtrList<Event> EventList = cal->rawEvents(); 95 QPtrList<Event> EventList = cal->rawEvents();
96 Event * ev = EventList.first(); 96 Event * ev = EventList.first();
97 while ( ev ) { 97 while ( ev ) {
98 ev->unRegisterObserver( cal ); 98 ev->unRegisterObserver( cal );
99 ev->registerObserver( this ); 99 ev->registerObserver( this );
100 mEventList.append( ev ); 100 mEventList.append( ev );
101 ev = EventList.next(); 101 ev = EventList.next();
102 } 102 }
103 } 103 }
104 { 104 {
105 105
106 QPtrList<Todo> TodoList = cal->rawTodos(); 106 QPtrList<Todo> TodoList = cal->rawTodos();
107 Todo * ev = TodoList.first(); 107 Todo * ev = TodoList.first();
108 while ( ev ) { 108 while ( ev ) {
109 QString rel = ev->relatedToUid(); 109 QString rel = ev->relatedToUid();
110 if ( !rel.isEmpty() ){ 110 if ( !rel.isEmpty() ){
111 ev->setRelatedTo ( 0 ); 111 ev->setRelatedTo ( 0 );
112 ev->setRelatedToUid( rel ); 112 ev->setRelatedToUid( rel );
113 } 113 }
114 ev = TodoList.next(); 114 ev = TodoList.next();
115 } 115 }
116 //TodoList = cal->rawTodos(); 116 //TodoList = cal->rawTodos();
117 ev = TodoList.first(); 117 ev = TodoList.first();
118 while ( ev ) { 118 while ( ev ) {
119 ev->unRegisterObserver( cal ); 119 ev->unRegisterObserver( cal );
120 ev->registerObserver( this ); 120 ev->registerObserver( this );
121 mTodoList.append( ev ); 121 mTodoList.append( ev );
122 setupRelations( ev ); 122 setupRelations( ev );
123 ev = TodoList.next(); 123 ev = TodoList.next();
124 } 124 }
125 } 125 }
126 { 126 {
127 QPtrList<Journal> JournalList = cal->journals(); 127 QPtrList<Journal> JournalList = cal->journals();
128 Journal * ev = JournalList.first(); 128 Journal * ev = JournalList.first();
129 while ( ev ) { 129 while ( ev ) {
130 ev->unRegisterObserver( cal ); 130 ev->unRegisterObserver( cal );
131 ev->registerObserver( this ); 131 ev->registerObserver( this );
132 mJournalList.append( ev ); 132 mJournalList.append( ev );
133 ev = JournalList.next(); 133 ev = JournalList.next();
134 } 134 }
135 } 135 }
136 setModified( true ); 136 setModified( true );
137} 137}
138bool CalendarLocal::load( const QString &fileName ) 138bool CalendarLocal::load( const QString &fileName )
139{ 139{
140 FileStorage storage( this, fileName ); 140 FileStorage storage( this, fileName );
141 return storage.load(); 141 return storage.load();
142} 142}
143 143
144bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 144bool CalendarLocal::save( const QString &fileName, CalFormat *format )
145{ 145{
146 FileStorage storage( this, fileName, format ); 146 FileStorage storage( this, fileName, format );
147 return storage.save(); 147 return storage.save();
148} 148}
149 149
150void CalendarLocal::stopAllTodos() 150void CalendarLocal::stopAllTodos()
151{ 151{
152 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 152 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
153 it->setRunning( false ); 153 it->setRunning( false );
154 154
155} 155}
156void CalendarLocal::close() 156void CalendarLocal::close()
157{ 157{
158 158
159 Todo * i; 159 Todo * i;
160 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); 160 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
161 161
162 mEventList.setAutoDelete( true ); 162 mEventList.setAutoDelete( true );
163 mTodoList.setAutoDelete( true ); 163 mTodoList.setAutoDelete( true );
164 mJournalList.setAutoDelete( false ); 164 mJournalList.setAutoDelete( false );
165 165
166 mEventList.clear(); 166 mEventList.clear();
167 mTodoList.clear(); 167 mTodoList.clear();
168 mJournalList.clear(); 168 mJournalList.clear();
169 169
170 mEventList.setAutoDelete( false ); 170 mEventList.setAutoDelete( false );
171 mTodoList.setAutoDelete( false ); 171 mTodoList.setAutoDelete( false );
172 mJournalList.setAutoDelete( false ); 172 mJournalList.setAutoDelete( false );
173 173
174 setModified( false ); 174 setModified( false );
175} 175}
176 176
177bool CalendarLocal::addAnniversaryNoDup( Event *event ) 177bool CalendarLocal::addAnniversaryNoDup( Event *event )
178{ 178{
179 QString cat; 179 QString cat;
180 bool isBirthday = true; 180 bool isBirthday = true;
181 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 181 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
182 isBirthday = false; 182 isBirthday = false;
183 cat = i18n( "Anniversary" ); 183 cat = i18n( "Anniversary" );
184 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 184 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
185 isBirthday = true; 185 isBirthday = true;
186 cat = i18n( "Birthday" ); 186 cat = i18n( "Birthday" );
187 } else { 187 } else {
188 qDebug("addAnniversaryNoDup called without fitting category! "); 188 qDebug("addAnniversaryNoDup called without fitting category! ");
189 return false; 189 return false;
190 } 190 }
191 Event * eve; 191 Event * eve;
192 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 192 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
193 if ( !(eve->categories().contains( cat ) )) 193 if ( !(eve->categories().contains( cat ) ))
194 continue; 194 continue;
195 // now we have an event with fitting category 195 // now we have an event with fitting category
196 if ( eve->dtStart().date() != event->dtStart().date() ) 196 if ( eve->dtStart().date() != event->dtStart().date() )
197 continue; 197 continue;
198 // now we have an event with fitting category+date 198 // now we have an event with fitting category+date
199 if ( eve->summary() != event->summary() ) 199 if ( eve->summary() != event->summary() )
200 continue; 200 continue;
201 // now we have an event with fitting category+date+summary 201 // now we have an event with fitting category+date+summary
202 return false; 202 return false;
203 } 203 }
204 return addEvent( event ); 204 return addEvent( event );
205 205
206} 206}
207bool CalendarLocal::addEventNoDup( Event *event ) 207bool CalendarLocal::addEventNoDup( Event *event )
208{ 208{
209 Event * eve; 209 Event * eve;
210 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 210 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
211 if ( *eve == *event ) { 211 if ( *eve == *event ) {
212 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 212 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
213 return false; 213 return false;
214 } 214 }
215 } 215 }
216 return addEvent( event ); 216 return addEvent( event );
217} 217}
218 218
219bool CalendarLocal::addEvent( Event *event ) 219bool CalendarLocal::addEvent( Event *event )
220{ 220{
221 insertEvent( event ); 221 insertEvent( event );
222 222
223 event->registerObserver( this ); 223 event->registerObserver( this );
224 224
225 setModified( true ); 225 setModified( true );
226 event->setCalID( mDefaultCalendar ); 226 event->setCalID( mDefaultCalendar );
227 event->setCalEnabled( true ); 227 event->setCalEnabled( true );
228 228
229 return true; 229 return true;
230} 230}
231 231
232void CalendarLocal::deleteEvent( Event *event ) 232void CalendarLocal::deleteEvent( Event *event )
233{ 233{
234 if ( mUndoIncidence ) delete mUndoIncidence; 234 if ( mUndoIncidence ) delete mUndoIncidence;
235 mUndoIncidence = event->clone(); 235 mUndoIncidence = event->clone();
236 if ( mEventList.removeRef( event ) ) { 236 if ( mEventList.removeRef( event ) ) {
237 setModified( true ); 237 setModified( true );
238 } 238 }
239} 239}
240 240
241 241
242Event *CalendarLocal::event( const QString &uid ) 242Event *CalendarLocal::event( const QString &uid )
243{ 243{
244 Event *event; 244 Event *event;
245 Event *retVal = 0; 245 Event *retVal = 0;
246 for ( event = mEventList.first(); event; event = mEventList.next() ) { 246 for ( event = mEventList.first(); event; event = mEventList.next() ) {
247 if ( event->calEnabled() && event->uid() == uid ) { 247 if ( event->calEnabled() && event->uid() == uid ) {
248 if ( retVal ) { 248 if ( retVal ) {
249 if ( retVal->calID() > event->calID() ) { 249 if ( retVal->calID() > event->calID() ) {
250 retVal = event; 250 retVal = event;
251 } 251 }
252 } else { 252 } else {
253 retVal = event; 253 retVal = event;
254 } 254 }
255 } 255 }
256 } 256 }
257 return retVal; 257 return retVal;
258} 258}
259bool CalendarLocal::addTodoNoDup( Todo *todo ) 259bool CalendarLocal::addTodoNoDup( Todo *todo )
260{ 260{
261 Todo * eve; 261 Todo * eve;
262 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 262 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
263 if ( *eve == *todo ) { 263 if ( *eve == *todo ) {
264 //qDebug("duplicate todo found! not inserted! "); 264 //qDebug("duplicate todo found! not inserted! ");
265 return false; 265 return false;
266 } 266 }
267 } 267 }
268 return addTodo( todo ); 268 return addTodo( todo );
269} 269}
270bool CalendarLocal::addTodo( Todo *todo ) 270bool CalendarLocal::addTodo( Todo *todo )
271{ 271{
272 mTodoList.append( todo ); 272 mTodoList.append( todo );
273 273
274 todo->registerObserver( this ); 274 todo->registerObserver( this );
275 275
276 // Set up subtask relations 276 // Set up subtask relations
277 setupRelations( todo ); 277 setupRelations( todo );
278 278
279 setModified( true ); 279 setModified( true );
280 todo->setCalID( mDefaultCalendar ); 280 todo->setCalID( mDefaultCalendar );
281 todo->setCalEnabled( true ); 281 todo->setCalEnabled( true );
282 return true; 282 return true;
283} 283}
284 284
285void CalendarLocal::deleteTodo( Todo *todo ) 285void CalendarLocal::deleteTodo( Todo *todo )
286{ 286{
287 // Handle orphaned children 287 // Handle orphaned children
288 if ( mUndoIncidence ) delete mUndoIncidence; 288 if ( mUndoIncidence ) delete mUndoIncidence;
289 removeRelations( todo ); 289 removeRelations( todo );
290 mUndoIncidence = todo->clone(); 290 mUndoIncidence = todo->clone();
291 291
292 if ( mTodoList.removeRef( todo ) ) { 292 if ( mTodoList.removeRef( todo ) ) {
293 setModified( true ); 293 setModified( true );
294 } 294 }
295} 295}
296 296
297QPtrList<Todo> CalendarLocal::rawTodos() 297QPtrList<Todo> CalendarLocal::rawTodos()
298{ 298{
299 QPtrList<Todo> el; 299 QPtrList<Todo> el;
300 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 300 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
301 if ( it->calEnabled() ) el.append( it ); 301 if ( it->calEnabled() ) el.append( it );
302 return el; 302 return el;
303} 303}
304Todo *CalendarLocal::todo( QString syncProf, QString id ) 304Todo *CalendarLocal::todo( QString syncProf, QString id )
305{ 305{
306 Todo *todo; 306 Todo *todo;
307 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 307 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
308 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 308 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
309 } 309 }
310 310
311 return 0; 311 return 0;
312} 312}
313void CalendarLocal::removeSyncInfo( QString syncProfile) 313void CalendarLocal::removeSyncInfo( QString syncProfile)
314{ 314{
315 QPtrList<Incidence> all = rawIncidences() ; 315 QPtrList<Incidence> all = rawIncidences() ;
316 Incidence *inc; 316 Incidence *inc;
317 for ( inc = all.first(); inc; inc = all.next() ) { 317 for ( inc = all.first(); inc; inc = all.next() ) {
318 inc->removeID( syncProfile ); 318 inc->removeID( syncProfile );
319 } 319 }
320 if ( syncProfile.isEmpty() ) { 320 if ( syncProfile.isEmpty() ) {
321 QPtrList<Event> el; 321 QPtrList<Event> el;
322 Event *todo; 322 Event *todo;
323 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 323 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
324 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 324 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
325 el.append( todo ); 325 el.append( todo );
326 } 326 }
327 for ( todo = el.first(); todo; todo = el.next() ) { 327 for ( todo = el.first(); todo; todo = el.next() ) {
328 deleteIncidence ( todo ); 328 deleteIncidence ( todo );
329 } 329 }
330 } else { 330 } else {
331 Event *lse = event( "last-syncEvent-"+ syncProfile); 331 Event *lse = event( "last-syncEvent-"+ syncProfile);
332 if ( lse ) 332 if ( lse )
333 deleteIncidence ( lse ); 333 deleteIncidence ( lse );
334 } 334 }
335} 335}
336QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 336QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
337{ 337{
338 QPtrList<Event> el; 338 QPtrList<Event> el;
339 Event *todo; 339 Event *todo;
340 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 340 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
341 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 341 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
342 if ( todo->summary().left(3) == "E: " ) 342 if ( todo->summary().left(3) == "E: " )
343 el.append( todo ); 343 el.append( todo );
344 } 344 }
345 345
346 return el; 346 return el;
347 347
348} 348}
349Event *CalendarLocal::event( QString syncProf, QString id ) 349Event *CalendarLocal::event( QString syncProf, QString id )
350{ 350{
351 Event *todo; 351 Event *todo;
352 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 352 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
353 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 353 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
354 } 354 }
355 355
356 return 0; 356 return 0;
357} 357}
358Todo *CalendarLocal::todo( const QString &uid ) 358Todo *CalendarLocal::todo( const QString &uid )
359{ 359{
360 Todo *todo;; 360 Todo *todo;;
361 Todo *retVal = 0; 361 Todo *retVal = 0;
362 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 362 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
363 if ( todo->calEnabled() && todo->uid() == uid ) { 363 if ( todo->calEnabled() && todo->uid() == uid ) {
364 if ( retVal ) { 364 if ( retVal ) {
365 if ( retVal->calID() > todo->calID() ) { 365 if ( retVal->calID() > todo->calID() ) {
366 retVal = todo; 366 retVal = todo;
367 } 367 }
368 } else { 368 } else {
369 retVal = todo; 369 retVal = todo;
370 } 370 }
371 } 371 }
372 } 372 }
373 return retVal; 373 return retVal;
374} 374}
375QString CalendarLocal::nextSummary() const 375QString CalendarLocal::nextSummary() const
376{ 376{
377 return mNextSummary; 377 return mNextSummary;
378} 378}
379QDateTime CalendarLocal::nextAlarmEventDateTime() const 379QDateTime CalendarLocal::nextAlarmEventDateTime() const
380{ 380{
381 return mNextAlarmEventDateTime; 381 return mNextAlarmEventDateTime;
382} 382}
383void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 383void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
384{ 384{
385 //mNextAlarmIncidence 385 //mNextAlarmIncidence
386 //mNextAlarmDateTime 386 //mNextAlarmDateTime
387 //return mNextSummary; 387 //return mNextSummary;
388 //return mNextAlarmEventDateTime; 388 //return mNextAlarmEventDateTime;
389 bool newNextAlarm = false; 389 bool newNextAlarm = false;
390 bool computeNextAlarm = false; 390 bool computeNextAlarm = false;
391 bool ok; 391 bool ok;
392 int offset; 392 int offset;
393 QDateTime nextA; 393 QDateTime nextA;
394 // QString nextSum; 394 // QString nextSum;
395 //QDateTime nextEvent; 395 //QDateTime nextEvent;
396 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 396 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
397 computeNextAlarm = true; 397 computeNextAlarm = true;
398 } else { 398 } else {
399 if ( ! deleted ) { 399 if ( ! deleted ) {
400 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 400 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
401 if ( ok ) { 401 if ( ok ) {
402 if ( nextA < mNextAlarmDateTime ) { 402 if ( nextA < mNextAlarmDateTime ) {
403 deRegisterAlarm(); 403 deRegisterAlarm();
404 mNextAlarmDateTime = nextA; 404 mNextAlarmDateTime = nextA;
405 mNextSummary = incidence->summary(); 405 mNextSummary = incidence->summary();
406 mNextAlarmEventDateTime = nextA.addSecs(offset ) ; 406 mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
407 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 407 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
408 newNextAlarm = true; 408 newNextAlarm = true;
409 mNextAlarmIncidence = incidence; 409 mNextAlarmIncidence = incidence;
410 } else { 410 } else {
411 if ( incidence == mNextAlarmIncidence ) { 411 if ( incidence == mNextAlarmIncidence ) {
412 computeNextAlarm = true; 412 computeNextAlarm = true;
413 } 413 }
414 } 414 }
415 } else { 415 } else {
416 if ( mNextAlarmIncidence == incidence ) { 416 if ( mNextAlarmIncidence == incidence ) {
417 computeNextAlarm = true; 417 computeNextAlarm = true;
418 } 418 }
419 } 419 }
420 } else { // deleted 420 } else { // deleted
421 if ( incidence == mNextAlarmIncidence ) { 421 if ( incidence == mNextAlarmIncidence ) {
422 computeNextAlarm = true; 422 computeNextAlarm = true;
423 } 423 }
424 } 424 }
425 } 425 }
426 if ( computeNextAlarm ) { 426 if ( computeNextAlarm ) {
427 deRegisterAlarm(); 427 deRegisterAlarm();
428 nextA = nextAlarm( 1000 ); 428 nextA = nextAlarm( 1000 );
429 if (! mNextAlarmIncidence ) { 429 if (! mNextAlarmIncidence ) {
430 return; 430 return;
431 } 431 }
432 newNextAlarm = true; 432 newNextAlarm = true;
433 } 433 }
434 if ( newNextAlarm ) 434 if ( newNextAlarm )
435 registerAlarm(); 435 registerAlarm();
436} 436}
437QString CalendarLocal:: getAlarmNotification() 437QString CalendarLocal:: getAlarmNotification()
438{ 438{
439 QString ret; 439 QString ret;
440 // this should not happen 440 // this should not happen
441 if (! mNextAlarmIncidence ) 441 if (! mNextAlarmIncidence )
442 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; 442 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
443 Alarm* alarm = mNextAlarmIncidence->alarms().first(); 443 Alarm* alarm = mNextAlarmIncidence->alarms().first();
444 if ( alarm->type() == Alarm::Procedure ) { 444 if ( alarm->type() == Alarm::Procedure ) {
445 ret = "proc_alarm" + alarm->programFile()+"+++"; 445 ret = "proc_alarm" + alarm->programFile()+"+++";
446 } else { 446 } else {
447 ret = "audio_alarm" +alarm->audioFile() +"+++"; 447 ret = "audio_alarm" +alarm->audioFile() +"+++";
448 } 448 }
449 ret += "cal_alarm"+ mNextSummary.left( 25 ); 449 ret += "cal_alarm"+ mNextSummary.left( 25 );
450 if ( mNextSummary.length() > 25 ) 450 if ( mNextSummary.length() > 25 )
451 ret += "\n" + mNextSummary.mid(25, 25 ); 451 ret += "\n" + mNextSummary.mid(25, 25 );
452 ret+= "\n"+mNextAlarmEventDateTimeString; 452 ret+= "\n"+mNextAlarmEventDateTimeString;
453 return ret; 453 return ret;
454} 454}
455void CalendarLocal::registerAlarm() 455void CalendarLocal::registerAlarm()
456{ 456{
457 mLastAlarmNotificationString = getAlarmNotification(); 457 mLastAlarmNotificationString = getAlarmNotification();
458 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); 458 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() );
459 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 459 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
460// #ifndef DESKTOP_VERSION 460// #ifndef DESKTOP_VERSION
461// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); 461// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
462// #endif 462// #endif
463} 463}
464void CalendarLocal::deRegisterAlarm() 464void CalendarLocal::deRegisterAlarm()
465{ 465{
466 if ( mLastAlarmNotificationString.isNull() ) 466 if ( mLastAlarmNotificationString.isNull() )
467 return; 467 return;
468 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); 468 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
469 469
470 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 470 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
471 mNextAlarmEventDateTime = QDateTime(); 471 mNextAlarmEventDateTime = QDateTime();
472// #ifndef DESKTOP_VERSION 472// #ifndef DESKTOP_VERSION
473// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); 473// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
474// #endif 474// #endif
475} 475}
476 476
477QPtrList<Todo> CalendarLocal::todos( const QDate &date ) 477QPtrList<Todo> CalendarLocal::todos( const QDate &date )
478{ 478{
479 QPtrList<Todo> todos; 479 QPtrList<Todo> todos;
480 480
481 Todo *todo; 481 Todo *todo;
482 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 482 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
483 if ( !todo->calEnabled() ) continue; 483 if ( !todo->calEnabled() ) continue;
484 if ( todo->hasDueDate() && todo->dtDue().date() == date ) { 484 if ( todo->hasDueDate() && todo->dtDue().date() == date ) {
485 todos.append( todo ); 485 todos.append( todo );
486 } 486 }
487 } 487 }
488 488
489 filter()->apply( &todos ); 489 filter()->apply( &todos );
490 return todos; 490 return todos;
491} 491}
492void CalendarLocal::reInitAlarmSettings() 492void CalendarLocal::reInitAlarmSettings()
493{ 493{
494 if ( !mNextAlarmIncidence ) { 494 if ( !mNextAlarmIncidence ) {
495 nextAlarm( 1000 ); 495 nextAlarm( 1000 );
496 } 496 }
497 deRegisterAlarm(); 497 deRegisterAlarm();
498 mNextAlarmIncidence = 0; 498 mNextAlarmIncidence = 0;
499 checkAlarmForIncidence( 0, false ); 499 checkAlarmForIncidence( 0, false );
500 500
501} 501}
502 502
503 503
504 504
505QDateTime CalendarLocal::nextAlarm( int daysTo ) 505QDateTime CalendarLocal::nextAlarm( int daysTo )
506{ 506{
507 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); 507 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo );
508 QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); 508 QDateTime start = QDateTime::currentDateTime().addSecs( 30 );
509 QDateTime next; 509 QDateTime next;
510 Event *e; 510 Event *e;
511 bool ok; 511 bool ok;
512 bool found = false; 512 bool found = false;
513 int offset; 513 int offset;
514 mNextAlarmIncidence = 0; 514 mNextAlarmIncidence = 0;
515 for( e = mEventList.first(); e; e = mEventList.next() ) { 515 for( e = mEventList.first(); e; e = mEventList.next() ) {
516 if ( !e->calEnabled() ) continue; 516 if ( !e->calEnabled() ) continue;
517 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 517 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
518 if ( ok ) { 518 if ( ok ) {
519 if ( next < nextA ) { 519 if ( next < nextA ) {
520 nextA = next; 520 nextA = next;
521 found = true; 521 found = true;
522 mNextSummary = e->summary(); 522 mNextSummary = e->summary();
523 mNextAlarmEventDateTime = next.addSecs(offset ) ; 523 mNextAlarmEventDateTime = next.addSecs(offset ) ;
524 mNextAlarmIncidence = (Incidence *) e; 524 mNextAlarmIncidence = (Incidence *) e;
525 } 525 }
526 } 526 }
527 } 527 }
528 Todo *t; 528 Todo *t;
529 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 529 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
530 if ( !t->calEnabled() ) continue; 530 if ( !t->calEnabled() ) continue;
531 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 531 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
532 if ( ok ) { 532 if ( ok ) {
533 if ( next < nextA ) { 533 if ( next < nextA ) {
534 nextA = next; 534 nextA = next;
535 found = true; 535 found = true;
536 mNextSummary = t->summary(); 536 mNextSummary = t->summary();
537 mNextAlarmEventDateTime = next.addSecs(offset ); 537 mNextAlarmEventDateTime = next.addSecs(offset );
538 mNextAlarmIncidence = (Incidence *) t; 538 mNextAlarmIncidence = (Incidence *) t;
539 } 539 }
540 } 540 }
541 } 541 }
542 if ( mNextAlarmIncidence ) { 542 if ( mNextAlarmIncidence ) {
543 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 543 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
544 mNextAlarmDateTime = nextA; 544 mNextAlarmDateTime = nextA;
545 } 545 }
546 return nextA; 546 return nextA;
547} 547}
548Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) 548Alarm::List CalendarLocal::alarmsTo( const QDateTime &to )
549{ 549{
550 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); 550 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to );
551} 551}
552 552
553Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) 553Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
554{ 554{
555 555
556 Alarm::List alarms; 556 Alarm::List alarms;
557 557
558 Event *e; 558 Event *e;
559 559
560 for( e = mEventList.first(); e; e = mEventList.next() ) { 560 for( e = mEventList.first(); e; e = mEventList.next() ) {
561 if ( !e->calEnabled() ) continue; 561 if ( !e->calEnabled() ) continue;
562 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); 562 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to );
563 else appendAlarms( alarms, e, from, to ); 563 else appendAlarms( alarms, e, from, to );
564 } 564 }
565 565
566 Todo *t; 566 Todo *t;
567 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 567 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
568 if ( !t->calEnabled() ) continue; 568 if ( !t->calEnabled() ) continue;
569 appendAlarms( alarms, t, from, to ); 569 appendAlarms( alarms, t, from, to );
570 } 570 }
571 571
572 return alarms; 572 return alarms;
573} 573}
574 574
575void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, 575void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence,
576 const QDateTime &from, const QDateTime &to ) 576 const QDateTime &from, const QDateTime &to )
577{ 577{
578 QPtrList<Alarm> alarmList = incidence->alarms(); 578 QPtrList<Alarm> alarmList = incidence->alarms();
579 Alarm *alarm; 579 Alarm *alarm;
580 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 580 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
581// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() 581// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text()
582// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; 582// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl;
583 if ( alarm->enabled() ) { 583 if ( alarm->enabled() ) {
584 if ( alarm->time() >= from && alarm->time() <= to ) { 584 if ( alarm->time() >= from && alarm->time() <= to ) {
585 alarms.append( alarm ); 585 alarms.append( alarm );
586 } 586 }
587 } 587 }
588 } 588 }
589} 589}
590 590
591void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, 591void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms,
592 Incidence *incidence, 592 Incidence *incidence,
593 const QDateTime &from, 593 const QDateTime &from,
594 const QDateTime &to ) 594 const QDateTime &to )
595{ 595{
596 596
597 QPtrList<Alarm> alarmList = incidence->alarms(); 597 QPtrList<Alarm> alarmList = incidence->alarms();
598 Alarm *alarm; 598 Alarm *alarm;
599 QDateTime qdt; 599 QDateTime qdt;
600 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 600 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
601 if (incidence->recursOn(from.date())) { 601 if (incidence->recursOn(from.date())) {
602 qdt.setTime(alarm->time().time()); 602 qdt.setTime(alarm->time().time());
603 qdt.setDate(from.date()); 603 qdt.setDate(from.date());
604 } 604 }
605 else qdt = alarm->time(); 605 else qdt = alarm->time();
606 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); 606 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1());
607 if ( alarm->enabled() ) { 607 if ( alarm->enabled() ) {
608 if ( qdt >= from && qdt <= to ) { 608 if ( qdt >= from && qdt <= to ) {
609 alarms.append( alarm ); 609 alarms.append( alarm );
610 } 610 }
611 } 611 }
612 } 612 }
613} 613}
614 614
615 615
616/****************************** PROTECTED METHODS ****************************/ 616/****************************** PROTECTED METHODS ****************************/
617 617
618// after changes are made to an event, this should be called. 618// after changes are made to an event, this should be called.
619void CalendarLocal::update( IncidenceBase *incidence ) 619void CalendarLocal::update( IncidenceBase *incidence )
620{ 620{
621 incidence->setSyncStatus( Event::SYNCMOD ); 621 incidence->setSyncStatus( Event::SYNCMOD );
622 incidence->setLastModified( QDateTime::currentDateTime() ); 622 incidence->setLastModified( QDateTime::currentDateTime() );
623 // we should probably update the revision number here, 623 // we should probably update the revision number here,
624 // or internally in the Event itself when certain things change. 624 // or internally in the Event itself when certain things change.
625 // need to verify with ical documentation. 625 // need to verify with ical documentation.
626 626
627 setModified( true ); 627 setModified( true );
628} 628}
629 629
630void CalendarLocal::insertEvent( Event *event ) 630void CalendarLocal::insertEvent( Event *event )
631{ 631{
632 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); 632 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event );
633} 633}
634 634
635 635
636QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) 636QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted )
637{ 637{
638 QPtrList<Event> eventList; 638 QPtrList<Event> eventList;
639 639
640 Event *event; 640 Event *event;
641 for( event = mEventList.first(); event; event = mEventList.next() ) { 641 for( event = mEventList.first(); event; event = mEventList.next() ) {
642 if ( !event->calEnabled() ) continue; 642 if ( !event->calEnabled() ) continue;
643 if ( event->doesRecur() ) { 643 if ( event->doesRecur() ) {
644 if ( event->isMultiDay() ) { 644 if ( event->isMultiDay() ) {
645 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); 645 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() );
646 int i; 646 int i;
647 for ( i = 0; i <= extraDays; i++ ) { 647 for ( i = 0; i <= extraDays; i++ ) {
648 if ( event->recursOn( qd.addDays( -i ) ) ) { 648 if ( event->recursOn( qd.addDays( -i ) ) ) {
649 eventList.append( event ); 649 eventList.append( event );
650 break; 650 break;
651 } 651 }
652 } 652 }
653 } else { 653 } else {
654 if ( event->recursOn( qd ) ) 654 if ( event->recursOn( qd ) )
655 eventList.append( event ); 655 eventList.append( event );
656 } 656 }
657 } else { 657 } else {
658 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { 658 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) {
659 eventList.append( event ); 659 eventList.append( event );
660 } 660 }
661 } 661 }
662 } 662 }
663 663
664 if ( !sorted ) { 664 if ( !sorted ) {
665 return eventList; 665 return eventList;
666 } 666 }
667 667
668 // kdDebug(5800) << "Sorting events for date\n" << endl; 668 // kdDebug(5800) << "Sorting events for date\n" << endl;
669 // now, we have to sort it based on dtStart.time() 669 // now, we have to sort it based on dtStart.time()
670 QPtrList<Event> eventListSorted; 670 QPtrList<Event> eventListSorted;
671 Event *sortEvent; 671 Event *sortEvent;
672 for ( event = eventList.first(); event; event = eventList.next() ) { 672 for ( event = eventList.first(); event; event = eventList.next() ) {
673 sortEvent = eventListSorted.first(); 673 sortEvent = eventListSorted.first();
674 int i = 0; 674 int i = 0;
675 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) 675 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() )
676 { 676 {
677 i++; 677 i++;
678 sortEvent = eventListSorted.next(); 678 sortEvent = eventListSorted.next();
679 } 679 }
680 eventListSorted.insert( i, event ); 680 eventListSorted.insert( i, event );
681 } 681 }
682 return eventListSorted; 682 return eventListSorted;
683} 683}
684 684
685 685
686QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, 686QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
687 bool inclusive ) 687 bool inclusive )
688{ 688{
689 Event *event = 0; 689 Event *event = 0;
690 690
691 QPtrList<Event> eventList; 691 QPtrList<Event> eventList;
692 692
693 // Get non-recurring events 693 // Get non-recurring events
694 for( event = mEventList.first(); event; event = mEventList.next() ) { 694 for( event = mEventList.first(); event; event = mEventList.next() ) {
695 if ( !event->calEnabled() ) continue; 695 if ( !event->calEnabled() ) continue;
696 if ( event->doesRecur() ) { 696 if ( event->doesRecur() ) {
697 QDate rStart = event->dtStart().date(); 697 QDate rStart = event->dtStart().date();
698 bool found = false; 698 bool found = false;
699 if ( inclusive ) { 699 if ( inclusive ) {
700 if ( rStart >= start && rStart <= end ) { 700 if ( rStart >= start && rStart <= end ) {
701 // Start date of event is in range. Now check for end date. 701 // Start date of event is in range. Now check for end date.
702 // if duration is negative, event recurs forever, so do not include it. 702 // if duration is negative, event recurs forever, so do not include it.
703 if ( event->recurrence()->duration() == 0 ) { // End date set 703 if ( event->recurrence()->duration() == 0 ) { // End date set
704 QDate rEnd = event->recurrence()->endDate(); 704 QDate rEnd = event->recurrence()->endDate();
705 if ( rEnd >= start && rEnd <= end ) { // End date within range 705 if ( rEnd >= start && rEnd <= end ) { // End date within range
706 found = true; 706 found = true;
707 } 707 }
708 } else if ( event->recurrence()->duration() > 0 ) { // Duration set 708 } else if ( event->recurrence()->duration() > 0 ) { // Duration set
709 // TODO: Calculate end date from duration. Should be done in Event 709 // TODO: Calculate end date from duration. Should be done in Event
710 // For now exclude all events with a duration. 710 // For now exclude all events with a duration.
711 } 711 }
712 } 712 }
713 } else { 713 } else {
714 bool founOne; 714 bool founOne;
715 QDate next = event->getNextOccurence( start, &founOne ).date(); 715 QDate next = event->getNextOccurence( start, &founOne ).date();
716 if ( founOne ) { 716 if ( founOne ) {
717 if ( next <= end ) { 717 if ( next <= end ) {
718 found = true; 718 found = true;
719 } 719 }
720 } 720 }
721 721
722 /* 722 /*
723 // crap !!! 723 // crap !!!
724 if ( rStart <= end ) { // Start date not after range 724 if ( rStart <= end ) { // Start date not after range
725 if ( rStart >= start ) { // Start date within range 725 if ( rStart >= start ) { // Start date within range
726 found = true; 726 found = true;
727 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever 727 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever
728 found = true; 728 found = true;
729 } else if ( event->recurrence()->duration() == 0 ) { // End date set 729 } else if ( event->recurrence()->duration() == 0 ) { // End date set
730 QDate rEnd = event->recurrence()->endDate(); 730 QDate rEnd = event->recurrence()->endDate();
731 if ( rEnd >= start && rEnd <= end ) { // End date within range 731 if ( rEnd >= start && rEnd <= end ) { // End date within range
732 found = true; 732 found = true;
733 } 733 }
734 } else { // Duration set 734 } else { // Duration set
735 // TODO: Calculate end date from duration. Should be done in Event 735 // TODO: Calculate end date from duration. Should be done in Event
736 // For now include all events with a duration. 736 // For now include all events with a duration.
737 found = true; 737 found = true;
738 } 738 }
739 } 739 }
740 */ 740 */
741 741
742 } 742 }
743 743
744 if ( found ) eventList.append( event ); 744 if ( found ) eventList.append( event );
745 } else { 745 } else {
746 QDate s = event->dtStart().date(); 746 QDate s = event->dtStart().date();
747 QDate e = event->dtEnd().date(); 747 QDate e = event->dtEnd().date();
748 748
749 if ( inclusive ) { 749 if ( inclusive ) {
750 if ( s >= start && e <= end ) { 750 if ( s >= start && e <= end ) {
751 eventList.append( event ); 751 eventList.append( event );
752 } 752 }
753 } else { 753 } else {
754 if ( ( e >= start && s <= end ) ) { 754 if ( ( e >= start && s <= end ) ) {
755 eventList.append( event ); 755 eventList.append( event );
756 } 756 }
757 } 757 }
758 } 758 }
759 } 759 }
760 760
761 return eventList; 761 return eventList;
762} 762}
763 763
764QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) 764QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt )
765{ 765{
766 return rawEventsForDate( qdt.date() ); 766 return rawEventsForDate( qdt.date() );
767} 767}
768 768
769QPtrList<Event> CalendarLocal::rawEvents() 769QPtrList<Event> CalendarLocal::rawEvents()
770{ 770{
771 QPtrList<Event> el; 771 QPtrList<Event> el;
772 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 772 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
773 if ( it->calEnabled() ) el.append( it ); 773 if ( it->calEnabled() ) el.append( it );
774 return el; 774 return el;
775} 775}
776 776
777bool CalendarLocal::addJournal(Journal *journal) 777bool CalendarLocal::addJournal(Journal *journal)
778{ 778{
779 if ( journal->dtStart().isValid()) 779 mJournalList.append(journal);
780 kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl;
781 else
782 kdDebug(5800) << "Adding Journal without a DTSTART" << endl;
783
784 mJournalList.append(journal);
785 780
786 journal->registerObserver( this ); 781 journal->registerObserver( this );
787 782
788 setModified( true ); 783 setModified( true );
789 journal->setCalID( mDefaultCalendar ); 784 journal->setCalID( mDefaultCalendar );
790 journal->setCalEnabled( true ); 785 journal->setCalEnabled( true );
791 return true; 786 return true;
792} 787}
793 788
794void CalendarLocal::deleteJournal( Journal *journal ) 789void CalendarLocal::deleteJournal( Journal *journal )
795{ 790{
796 if ( mUndoIncidence ) delete mUndoIncidence; 791 if ( mUndoIncidence ) delete mUndoIncidence;
797 mUndoIncidence = journal->clone(); 792 mUndoIncidence = journal->clone();
798 mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); 793 mUndoIncidence->setSummary( mUndoIncidence->description().left(25));
799 if ( mJournalList.removeRef(journal) ) { 794 if ( mJournalList.removeRef(journal) ) {
800 setModified( true ); 795 setModified( true );
801 } 796 }
802} 797}
803 798
799QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date )
800{
801 QPtrList<Journal> el;
802 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
803 if ( it->calEnabled() && it->dtStart().date() == date) el.append( it );
804 return el;
805}
804Journal *CalendarLocal::journal( const QDate &date ) 806Journal *CalendarLocal::journal( const QDate &date )
805{ 807{
806// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; 808// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl;
807 809
808 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 810 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
809 if ( it->calEnabled() && it->dtStart().date() == date ) 811 if ( it->calEnabled() && it->dtStart().date() == date )
810 return it; 812 return it;
811 813
812 return 0; 814 return 0;
813} 815}
814 816
815Journal *CalendarLocal::journal( const QString &uid ) 817Journal *CalendarLocal::journal( const QString &uid )
816{ 818{
817 Journal * retVal = 0; 819 Journal * retVal = 0;
818 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 820 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
819 if ( it->calEnabled() && it->uid() == uid ) { 821 if ( it->calEnabled() && it->uid() == uid ) {
820 if ( retVal ) { 822 if ( retVal ) {
821 if ( retVal->calID() > it->calID() ) { 823 if ( retVal->calID() > it->calID() ) {
822 retVal = it; 824 retVal = it;
823 } 825 }
824 } else { 826 } else {
825 retVal = it; 827 retVal = it;
826 } 828 }
827 } 829 }
828 return retVal; 830 return retVal;
829} 831}
830 832
831QPtrList<Journal> CalendarLocal::journals() 833QPtrList<Journal> CalendarLocal::journals()
832{ 834{
833 QPtrList<Journal> el; 835 QPtrList<Journal> el;
834 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 836 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
835 if ( it->calEnabled() ) el.append( it ); 837 if ( it->calEnabled() ) el.append( it );
836 return el; 838 return el;
837} 839}
838void CalendarLocal::setCalendarRemove( int id ) 840void CalendarLocal::setCalendarRemove( int id )
839{ 841{
840 842
841 { 843 {
842 QPtrList<Event> EventList = mEventList; 844 QPtrList<Event> EventList = mEventList;
843 Event * ev = EventList.first(); 845 Event * ev = EventList.first();
844 while ( ev ) { 846 while ( ev ) {
845 if ( ev->calID() == id ) 847 if ( ev->calID() == id )
846 deleteEvent( ev ); 848 deleteEvent( ev );
847 ev = EventList.next(); 849 ev = EventList.next();
848 } 850 }
849 } 851 }
850 { 852 {
851 853
852 QPtrList<Todo> TodoList = mTodoList; 854 QPtrList<Todo> TodoList = mTodoList;
853 Todo * ev = TodoList.first(); 855 Todo * ev = TodoList.first();
854 while ( ev ) { 856 while ( ev ) {
855 if ( ev->calID() == id ) 857 if ( ev->calID() == id )
856 deleteTodo( ev ); 858 deleteTodo( ev );
857 ev = TodoList.next(); 859 ev = TodoList.next();
858 } 860 }
859 } 861 }
860 { 862 {
861 QPtrList<Journal> JournalList = mJournalList; 863 QPtrList<Journal> JournalList = mJournalList;
862 Journal * ev = JournalList.first(); 864 Journal * ev = JournalList.first();
863 while ( ev ) { 865 while ( ev ) {
864 if ( ev->calID() == id ) 866 if ( ev->calID() == id )
865 deleteJournal( ev ); 867 deleteJournal( ev );
866 ev = JournalList.next(); 868 ev = JournalList.next();
867 } 869 }
868 } 870 }
869 871
870 if ( mUndoIncidence ) delete mUndoIncidence; 872 if ( mUndoIncidence ) delete mUndoIncidence;
871 mUndoIncidence = 0; 873 mUndoIncidence = 0;
872 874
873} 875}
874 876
875void CalendarLocal::setCalendarEnabled( int id, bool enable ) 877void CalendarLocal::setCalendarEnabled( int id, bool enable )
876{ 878{
877 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 879 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
878 if ( it->calID() == id ) it->setCalEnabled( enable ); 880 if ( it->calID() == id ) it->setCalEnabled( enable );
879 881
880 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 882 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
881 if ( it->calID() == id ) it->setCalEnabled( enable ); 883 if ( it->calID() == id ) it->setCalEnabled( enable );
882 884
883 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 885 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
884 if ( it->calID() == id ) it->setCalEnabled( enable ); 886 if ( it->calID() == id ) it->setCalEnabled( enable );
885 887
886} 888}
887 889
888void CalendarLocal::setReadOnly( int id, bool enable ) 890void CalendarLocal::setReadOnly( int id, bool enable )
889{ 891{
890 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 892 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
891 if ( it->calID() == id ) it->setReadOnly( enable ); 893 if ( it->calID() == id ) it->setReadOnly( enable );
892 894
893 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 895 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
894 if ( it->calID() == id ) it->setReadOnly( enable ); 896 if ( it->calID() == id ) it->setReadOnly( enable );
895 897
896 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 898 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
897 if ( it->calID() == id ) it->setReadOnly( enable ); 899 if ( it->calID() == id ) it->setReadOnly( enable );
898 900
899} 901}
900 902
901void CalendarLocal::setAlarmEnabled( int id, bool enable ) 903void CalendarLocal::setAlarmEnabled( int id, bool enable )
902{ 904{
903 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 905 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
904 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 906 if ( it->calID() == id ) it->setAlarmEnabled( enable );
905 907
906 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 908 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
907 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 909 if ( it->calID() == id ) it->setAlarmEnabled( enable );
908 910
909 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 911 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
910 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 912 if ( it->calID() == id ) it->setAlarmEnabled( enable );
911 reInitAlarmSettings(); 913 reInitAlarmSettings();
912 914
913} 915}
914void CalendarLocal::setDefaultCalendarEnabledOnly() 916void CalendarLocal::setDefaultCalendarEnabledOnly()
915{ 917{
916 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 918 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
917 it->setCalEnabled( it->calID() == mDefaultCalendar ); 919 it->setCalEnabled( it->calID() == mDefaultCalendar );
918 920
919 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 921 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
920 it->setCalEnabled( it->calID() == mDefaultCalendar); 922 it->setCalEnabled( it->calID() == mDefaultCalendar);
921 923
922 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 924 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
923 it->setCalEnabled( it->calID() == mDefaultCalendar); 925 it->setCalEnabled( it->calID() == mDefaultCalendar);
924 926
925} 927}
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h
index d32597f..98d16a3 100644
--- a/libkcal/calendarlocal.h
+++ b/libkcal/calendarlocal.h
@@ -1,226 +1,227 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 1998 Preston Brown 4 Copyright (c) 1998 Preston Brown
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> 5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22#ifndef KCAL_CALENDARLOCAL_H 22#ifndef KCAL_CALENDARLOCAL_H
23#define KCAL_CALENDARLOCAL_H 23#define KCAL_CALENDARLOCAL_H
24 24
25#include "calendar.h" 25#include "calendar.h"
26 26
27namespace KCal { 27namespace KCal {
28 28
29class CalFormat; 29class CalFormat;
30 30
31/** 31/**
32 This class provides a calendar stored as a local file. 32 This class provides a calendar stored as a local file.
33*/ 33*/
34class CalendarLocal : public Calendar 34class CalendarLocal : public Calendar
35{ 35{
36 public: 36 public:
37 /** 37 /**
38 Constructs a new calendar, with variables initialized to sane values. 38 Constructs a new calendar, with variables initialized to sane values.
39 */ 39 */
40 CalendarLocal(); 40 CalendarLocal();
41 /** 41 /**
42 Constructs a new calendar, with variables initialized to sane values. 42 Constructs a new calendar, with variables initialized to sane values.
43 */ 43 */
44 CalendarLocal( const QString &timeZoneId ); 44 CalendarLocal( const QString &timeZoneId );
45 ~CalendarLocal(); 45 ~CalendarLocal();
46 void addCalendar( Calendar* ); 46 void addCalendar( Calendar* );
47 bool addCalendarFile( QString name, int id ); 47 bool addCalendarFile( QString name, int id );
48 void setSyncEventsReadOnly(); 48 void setSyncEventsReadOnly();
49 void stopAllTodos(); 49 void stopAllTodos();
50 /** 50 /**
51 Loads a calendar on disk in vCalendar or iCalendar format into the current 51 Loads a calendar on disk in vCalendar or iCalendar format into the current
52 calendar. Any information already present is lost. 52 calendar. Any information already present is lost.
53 @return true, if successfull, false on error. 53 @return true, if successfull, false on error.
54 @param fileName the name of the calendar on disk. 54 @param fileName the name of the calendar on disk.
55 */ 55 */
56 bool load( const QString &fileName ); 56 bool load( const QString &fileName );
57 /** 57 /**
58 Writes out the calendar to disk in the specified \a format. 58 Writes out the calendar to disk in the specified \a format.
59 CalendarLocal takes ownership of the CalFormat object. 59 CalendarLocal takes ownership of the CalFormat object.
60 @return true, if successfull, false on error. 60 @return true, if successfull, false on error.
61 @param fileName the name of the file 61 @param fileName the name of the file
62 */ 62 */
63 bool save( const QString &fileName, CalFormat *format = 0 ); 63 bool save( const QString &fileName, CalFormat *format = 0 );
64 64
65 /** 65 /**
66 Clears out the current calendar, freeing all used memory etc. etc. 66 Clears out the current calendar, freeing all used memory etc. etc.
67 */ 67 */
68 void close(); 68 void close();
69 69
70 void save() {} 70 void save() {}
71 71
72 /** 72 /**
73 Add Event to calendar. 73 Add Event to calendar.
74 */ 74 */
75 void removeSyncInfo( QString syncProfile); 75 void removeSyncInfo( QString syncProfile);
76 bool addAnniversaryNoDup( Event *event ); 76 bool addAnniversaryNoDup( Event *event );
77 bool addEventNoDup( Event *event ); 77 bool addEventNoDup( Event *event );
78 bool addEvent( Event *event ); 78 bool addEvent( Event *event );
79 /** 79 /**
80 Deletes an event from this calendar. 80 Deletes an event from this calendar.
81 */ 81 */
82 void deleteEvent( Event *event ); 82 void deleteEvent( Event *event );
83 83
84 /** 84 /**
85 Retrieves an event on the basis of the unique string ID. 85 Retrieves an event on the basis of the unique string ID.
86 */ 86 */
87 Event *event( const QString &uid ); 87 Event *event( const QString &uid );
88 /** 88 /**
89 Return unfiltered list of all events in calendar. 89 Return unfiltered list of all events in calendar.
90 */ 90 */
91 QPtrList<Event> rawEvents(); 91 QPtrList<Event> rawEvents();
92 QPtrList<Event> getExternLastSyncEvents(); 92 QPtrList<Event> getExternLastSyncEvents();
93 /** 93 /**
94 Add a todo to the todolist. 94 Add a todo to the todolist.
95 */ 95 */
96 bool addTodo( Todo *todo ); 96 bool addTodo( Todo *todo );
97 bool addTodoNoDup( Todo *todo ); 97 bool addTodoNoDup( Todo *todo );
98 /** 98 /**
99 Remove a todo from the todolist. 99 Remove a todo from the todolist.
100 */ 100 */
101 void deleteTodo( Todo * ); 101 void deleteTodo( Todo * );
102 /** 102 /**
103 Searches todolist for an event with this unique string identifier, 103 Searches todolist for an event with this unique string identifier,
104 returns a pointer or null. 104 returns a pointer or null.
105 */ 105 */
106 Todo *todo( const QString &uid ); 106 Todo *todo( const QString &uid );
107 /** 107 /**
108 Return list of all todos. 108 Return list of all todos.
109 */ 109 */
110 QPtrList<Todo> rawTodos(); 110 QPtrList<Todo> rawTodos();
111 /** 111 /**
112 Returns list of todos due on the specified date. 112 Returns list of todos due on the specified date.
113 */ 113 */
114 QPtrList<Todo> todos( const QDate &date ); 114 QPtrList<Todo> todos( const QDate &date );
115 /** 115 /**
116 Return list of all todos. 116 Return list of all todos.
117 117
118 Workaround because compiler does not recognize function of base class. 118 Workaround because compiler does not recognize function of base class.
119 */ 119 */
120 QPtrList<Todo> todos() { return Calendar::todos(); } 120 QPtrList<Todo> todos() { return Calendar::todos(); }
121 121
122 /** 122 /**
123 Add a Journal entry to calendar. 123 Add a Journal entry to calendar.
124 */ 124 */
125 bool addJournal( Journal * ); 125 bool addJournal( Journal * );
126 /** 126 /**
127 Remove a Journal from the calendar. 127 Remove a Journal from the calendar.
128 */ 128 */
129 void deleteJournal( Journal * ); 129 void deleteJournal( Journal * );
130 /** 130 /**
131 Return Journal for given date. 131 Return Journal for given date.
132 */ 132 */
133 Journal *journal( const QDate & ); 133 Journal *journal( const QDate & );
134 QPtrList<Journal> journals4Date( const QDate & );
134 /** 135 /**
135 Return Journal with given UID. 136 Return Journal with given UID.
136 */ 137 */
137 Journal *journal( const QString &uid ); 138 Journal *journal( const QString &uid );
138 /** 139 /**
139 Return list of all Journals stored in calendar. 140 Return list of all Journals stored in calendar.
140 */ 141 */
141 QPtrList<Journal> journals(); 142 QPtrList<Journal> journals();
142 143
143 /** 144 /**
144 Return all alarms, which ocur in the given time interval. 145 Return all alarms, which ocur in the given time interval.
145 */ 146 */
146 Alarm::List alarms( const QDateTime &from, const QDateTime &to ); 147 Alarm::List alarms( const QDateTime &from, const QDateTime &to );
147 148
148 /** 149 /**
149 Return all alarms, which ocur before given date. 150 Return all alarms, which ocur before given date.
150 */ 151 */
151 Alarm::List alarmsTo( const QDateTime &to ); 152 Alarm::List alarmsTo( const QDateTime &to );
152 153
153 QDateTime nextAlarm( int daysTo ) ; 154 QDateTime nextAlarm( int daysTo ) ;
154 QDateTime nextAlarmEventDateTime() const; 155 QDateTime nextAlarmEventDateTime() const;
155 void checkAlarmForIncidence( Incidence *, bool deleted ) ; 156 void checkAlarmForIncidence( Incidence *, bool deleted ) ;
156 void registerAlarm(); 157 void registerAlarm();
157 void deRegisterAlarm(); 158 void deRegisterAlarm();
158 QString getAlarmNotification(); 159 QString getAlarmNotification();
159 QString nextSummary() const ; 160 QString nextSummary() const ;
160 /** 161 /**
161 This method should be called whenever a Event is modified directly 162 This method should be called whenever a Event is modified directly
162 via it's pointer. It makes sure that the calendar is internally 163 via it's pointer. It makes sure that the calendar is internally
163 consistent. 164 consistent.
164 */ 165 */
165 void update( IncidenceBase *incidence ); 166 void update( IncidenceBase *incidence );
166 167
167 /** 168 /**
168 Builds and then returns a list of all events that match for the 169 Builds and then returns a list of all events that match for the
169 date specified. useful for dayView, etc. etc. 170 date specified. useful for dayView, etc. etc.
170 */ 171 */
171 QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); 172 QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false );
172 /** 173 /**
173 Get unfiltered events for date \a qdt. 174 Get unfiltered events for date \a qdt.
174 */ 175 */
175 QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); 176 QPtrList<Event> rawEventsForDate( const QDateTime &qdt );
176 /** 177 /**
177 Get unfiltered events in a range of dates. If inclusive is set to true, 178 Get unfiltered events in a range of dates. If inclusive is set to true,
178 only events are returned, which are completely included in the range. 179 only events are returned, which are completely included in the range.
179 */ 180 */
180 QPtrList<Event> rawEvents( const QDate &start, const QDate &end, 181 QPtrList<Event> rawEvents( const QDate &start, const QDate &end,
181 bool inclusive = false ); 182 bool inclusive = false );
182 Todo *todo( QString, QString ); 183 Todo *todo( QString, QString );
183 Event *event( QString, QString ); 184 Event *event( QString, QString );
184 185
185public slots: 186public slots:
186 void setCalendarEnabled( int id, bool enable ); 187 void setCalendarEnabled( int id, bool enable );
187 void setAlarmEnabled( int id, bool enable ); 188 void setAlarmEnabled( int id, bool enable );
188 void setReadOnly( int id, bool enable ); 189 void setReadOnly( int id, bool enable );
189 void setDefaultCalendarEnabledOnly(); 190 void setDefaultCalendarEnabledOnly();
190 void setCalendarRemove( int id ); 191 void setCalendarRemove( int id );
191 192
192 protected: 193 protected:
193 194
194 // Event* mNextAlarmEvent; 195 // Event* mNextAlarmEvent;
195 QString mNextSummary; 196 QString mNextSummary;
196 QString mNextAlarmEventDateTimeString; 197 QString mNextAlarmEventDateTimeString;
197 QString mLastAlarmNotificationString; 198 QString mLastAlarmNotificationString;
198 QDateTime mNextAlarmEventDateTime; 199 QDateTime mNextAlarmEventDateTime;
199 QDateTime mNextAlarmDateTime; 200 QDateTime mNextAlarmDateTime;
200 void reInitAlarmSettings(); 201 void reInitAlarmSettings();
201 202
202 /** Notification function of IncidenceBase::Observer. */ 203 /** Notification function of IncidenceBase::Observer. */
203 void incidenceUpdated( IncidenceBase *i ) { update( i ); } 204 void incidenceUpdated( IncidenceBase *i ) { update( i ); }
204 205
205 /** inserts an event into its "proper place" in the calendar. */ 206 /** inserts an event into its "proper place" in the calendar. */
206 void insertEvent( Event *event ); 207 void insertEvent( Event *event );
207 208
208 /** Append alarms of incidence in interval to list of alarms. */ 209 /** Append alarms of incidence in interval to list of alarms. */
209 void appendAlarms( Alarm::List &alarms, Incidence *incidence, 210 void appendAlarms( Alarm::List &alarms, Incidence *incidence,
210 const QDateTime &from, const QDateTime &to ); 211 const QDateTime &from, const QDateTime &to );
211 212
212 /** Append alarms of recurring events in interval to list of alarms. */ 213 /** Append alarms of recurring events in interval to list of alarms. */
213 void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, 214 void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence,
214 const QDateTime &from, const QDateTime &to ); 215 const QDateTime &from, const QDateTime &to );
215 216
216 private: 217 private:
217 void init(); 218 void init();
218 219
219 QPtrList<Event> mEventList; 220 QPtrList<Event> mEventList;
220 QPtrList<Todo> mTodoList; 221 QPtrList<Todo> mTodoList;
221 QPtrList<Journal> mJournalList; 222 QPtrList<Journal> mJournalList;
222}; 223};
223 224
224} 225}
225 226
226#endif 227#endif