summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kde2file/caldump/main.cpp55
-rw-r--r--korganizer/calendarview.cpp8
-rw-r--r--libkcal/calendar.cpp16
-rw-r--r--libkcal/calendar.h1
4 files changed, 56 insertions, 24 deletions
diff --git a/kde2file/caldump/main.cpp b/kde2file/caldump/main.cpp
index 03571b9..755e792 100644
--- a/kde2file/caldump/main.cpp
+++ b/kde2file/caldump/main.cpp
@@ -1,248 +1,255 @@
1/******************************************************************************* 1/*******************************************************************************
2 * main.cpp * 2 * main.cpp *
3 * * 3 * *
4 * 4 *
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 ******************************************************************************/ 24 ******************************************************************************/
25 25
26#ifdef HAVE_CONFIG_H 26#ifdef HAVE_CONFIG_H
27#include "config.h" 27#include "config.h"
28#endif 28#endif
29 29
30#if TIME_WITH_SYS_TIME 30#if TIME_WITH_SYS_TIME
31# include <sys/time.h> 31# include <sys/time.h>
32# include <time.h> 32# include <time.h>
33#else 33#else
34# if HAVE_SYS_TIME_H 34# if HAVE_SYS_TIME_H
35# include <sys/time.h> 35# include <sys/time.h>
36# else 36# else
37# include <time.h> 37# include <time.h>
38# endif 38# endif
39#endif 39#endif
40 40
41#include <kcmdlineargs.h> 41#include <kcmdlineargs.h>
42#include <kaboutdata.h> 42#include <kaboutdata.h>
43#include <klocale.h> 43#include <klocale.h>
44#include <kglobal.h> 44#include <kglobal.h>
45#include <kconfig.h> 45#include <kconfig.h>
46#include <kstandarddirs.h> 46#include <kstandarddirs.h>
47#include <kdebug.h> 47#include <kdebug.h>
48 48
49#include <libkcal/calformat.h> 49#include <libkcal/calformat.h>
50#include <libkcal/calendarresources.h> 50#include <libkcal/calendarresources.h>
51#include <libkcal/resourcelocal.h> 51#include <libkcal/resourcelocal.h>
52#include <libkcal/filestorage.h> 52#include <libkcal/filestorage.h>
53#include <libkcal/icalformat.h> 53#include <libkcal/icalformat.h>
54 54
55#include <qdatetime.h> 55#include <qdatetime.h>
56#include <qfile.h> 56#include <qfile.h>
57#include <qdir.h> 57#include <qdir.h>
58 58
59#include <stdlib.h> 59#include <stdlib.h>
60#include <iostream> 60#include <iostream>
61 61
62using namespace KCal; 62using namespace KCal;
63using namespace std; 63using namespace std;
64 64
65static const char progName[] = "kdecalendar"; 65static const char progName[] = "kdecalendar";
66static const char progDisplay[] = "KDE_Calendar"; 66static const char progDisplay[] = "KDE_Calendar";
67static const char progVersion[] = "33.1/3"; 67static const char progVersion[] = "33.1/3";
68static const char progDesc[] = "A command line interface to KDE calendars"; 68static const char progDesc[] = "A command line interface to KDE calendars";
69 69
70 70
71static KCmdLineOptions options[] = 71static KCmdLineOptions options[] =
72 { 72 {
73 { "dump", 73 { "dump",
74 I18N_NOOP( "Dumps calendar" ), 0 }, 74 I18N_NOOP( "Dumps calendar" ), 0 },
75 { "read", 75 { "read",
76 I18N_NOOP( "Reads calendar" ), 0 }, 76 I18N_NOOP( "Reads calendar" ), 0 },
77 KCmdLineLastOption 77 KCmdLineLastOption
78 }; 78 };
79 79
80int main( int argc, char *argv[] ) 80int main( int argc, char *argv[] )
81{ 81{
82 KAboutData aboutData( 82 KAboutData aboutData(
83 progName, // internal program name 83 progName, // internal program name
84 I18N_NOOP( progDisplay ), // displayable program name. 84 I18N_NOOP( progDisplay ), // displayable program name.
85 progVersion, // version string 85 progVersion, // version string
86 I18N_NOOP( progDesc ), // short porgram description 86 I18N_NOOP( progDesc ), // short porgram description
87 KAboutData::License_GPL, // license type 87 KAboutData::License_GPL, // license type
88 "(c) 2004, Lutz Rogowski", // copyright statement 88 "(c) 2004, Lutz Rogowski", // copyright statement
89 0, // any free form text 89 0, // any free form text
90 "", // program home page address 90 "", // program home page address
91 "bugs.kde.org" // bug report email address 91 "bugs.kde.org" // bug report email address
92 ); 92 );
93 93
94 94
95 // KCmdLineArgs::init() final 'true' argument indicates no commandline options 95 // KCmdLineArgs::init() final 'true' argument indicates no commandline options
96 // for QApplication/KApplication (no KDE or Qt options) 96 // for QApplication/KApplication (no KDE or Qt options)
97 KCmdLineArgs::init( argc, argv, &aboutData, true ); 97 KCmdLineArgs::init( argc, argv, &aboutData, true );
98 KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. 98 KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
99 99
100 KInstance ins ( progName ); 100 KInstance ins ( progName );
101 101
102 KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); 102 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
103 103
104 bool read = false; 104 bool read = false;
105 if ( args->isSet( "read" ) ) { 105 if ( args->isSet( "read" ) ) {
106 read = true; 106 read = true;
107 qDebug("read "); 107 qDebug("read ");
108 } 108 }
109 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; 109 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics";
110 CalendarResources *calendarResource = 0; 110 CalendarResources *calendarResource = 0;
111 CalendarLocal *localCalendar = 0; 111 CalendarLocal *localCalendar = 0;
112 KConfig c( locate( "config", "korganizerrc" ) ); 112 KConfig c( locate( "config", "korganizerrc" ) );
113 c.setGroup( "Time & Date" ); 113 c.setGroup( "Time & Date" );
114 QString tz = c.readEntry( "TimeZoneId" ); 114 QString tz = c.readEntry( "TimeZoneId" );
115 calendarResource = new CalendarResources( tz ); 115 calendarResource = new CalendarResources( tz );
116 calendarResource->readConfig(); 116 calendarResource->readConfig();
117 calendarResource->load(); 117 calendarResource->load();
118 qDebug("************************************* "); 118 qDebug("************************************* ");
119 qDebug("**************kdecaldump************* "); 119 qDebug("**************kdecaldump************* ");
120 qDebug("************************************* "); 120 qDebug("************************************* ");
121 qDebug("Using timezone ID: %s", calendarResource->timeZoneId().latin1()); 121 qDebug("Using timezone ID: %s", calendarResource->timeZoneId().latin1());
122 122
123 if ( !read ) { 123 if ( !read ) {
124 localCalendar = new CalendarLocal(); 124 localCalendar = new CalendarLocal();
125 localCalendar->setTimeZoneId( calendarResource->timeZoneId()); 125 localCalendar->setTimeZoneId( calendarResource->timeZoneId());
126 KCal::Incidence::List allInc = calendarResource->rawIncidences(); 126 KCal::Incidence::List allInc = calendarResource->rawIncidences();
127 Incidence::List::ConstIterator it; 127 Incidence::List::ConstIterator it;
128 int num = 0; 128 int num = 0;
129 for( it = allInc.begin(); it != allInc.end(); ++it ) { 129 for( it = allInc.begin(); it != allInc.end(); ++it ) {
130 ResourceCalendar * re = calendarResource->resource( (*it) ); 130 ResourceCalendar * re = calendarResource->resource( (*it) );
131 if ( re && !re->readOnly() ) { 131 if ( re && !re->readOnly() ) {
132 ++num; 132 ++num;
133 Incidence* cl = (*it)->clone(); 133 Incidence* cl = (*it)->clone();
134 cl->setLastModified( (*it)->lastModified() ); 134 cl->setLastModified( (*it)->lastModified() );
135 if ( cl->type() == "Journal" ) 135 if ( cl->type() == "Journal" )
136 localCalendar->addJournal( (Journal *) cl ); 136 localCalendar->addJournal( (Journal *) cl );
137 else if ( cl->type() == "Todo" ) 137 else if ( cl->type() == "Todo" )
138 localCalendar->addTodo( (Todo *) cl ); 138 localCalendar->addTodo( (Todo *) cl );
139 else if ( cl->type() == "Event" ) 139 else if ( cl->type() == "Event" )
140 localCalendar->addEvent( (Event *) cl ); 140 localCalendar->addEvent( (Event *) cl );
141 } 141 }
142 } 142 }
143 143
144 FileStorage* storage = new FileStorage( calendarResource ); 144 FileStorage* storage = new FileStorage( calendarResource );
145 storage->setFileName( fileName ); 145 storage->setFileName( fileName );
146 storage->setSaveFormat( new ICalFormat() ); 146 storage->setSaveFormat( new ICalFormat() );
147 storage->save(); 147 storage->save();
148 delete storage; 148 delete storage;
149 qDebug("************************************* "); 149 qDebug("************************************* ");
150 qDebug("************kdecaldump*************** "); 150 qDebug("************kdecaldump*************** ");
151 qDebug("************************************* "); 151 qDebug("************************************* ");
152 qDebug("%d calendar entries dumped to file %s", num, fileName.latin1()); 152 qDebug("%d calendar entries dumped to file %s", num, fileName.latin1());
153 153
154 } else { 154 } else {
155 qDebug("*************************load"); 155 qDebug("*************************load");
156 localCalendar = new CalendarLocal(); 156 localCalendar = new CalendarLocal();
157 localCalendar->setTimeZoneId( calendarResource->timeZoneId()); 157 localCalendar->setTimeZoneId( calendarResource->timeZoneId());
158 FileStorage* storage = new FileStorage( localCalendar ); 158 FileStorage* storage = new FileStorage( localCalendar );
159 storage->setFileName( fileName ); 159 storage->setFileName( fileName );
160 int num = 0; 160 int num = 0;
161 int del = 0; 161 int del = 0;
162 int add = 0; 162 int add = 0;
163 if ( storage->load() ) { 163 if ( storage->load() ) {
164 qDebug("*************************loaded!"); 164 qDebug("*************************loaded!");
165 KCal::Incidence::List newInc = localCalendar->rawIncidences(); 165 KCal::Incidence::List newInc = localCalendar->rawIncidences();
166 Incidence::List::ConstIterator it; 166 Incidence::List::ConstIterator it;
167 for( it = newInc.begin(); it != newInc.end(); ++it ) { 167 for( it = newInc.begin(); it != newInc.end(); ++it ) {
168 Incidence* cl = (*it)->clone(); 168 if ( (*it)->pilotId() > 0 ) { //changed
169 Incidence *incOld = calendarResource->incidence( cl->uid() ); 169 Incidence* cl = (*it)->clone();
170 ResourceCalendar * res = 0; 170 Incidence *incOld = calendarResource->incidence( cl->uid() );
171 if ( incOld ) 171 ResourceCalendar * res = 0;
172 res = calendarResource->resource( incOld ); 172 if ( incOld )
173 if ( res ) { 173 res = calendarResource->resource( incOld );
174 ++num; 174 if ( res ) {
175 if ( incOld->type() == "Journal" ) 175 cl->setPilotId( incOld->pilotId() );
176 calendarResource->deleteJournal( (Journal *) incOld ); 176 ++num;
177 else if ( incOld->type() == "Todo" )
178 calendarResource->deleteTodo( (Todo *) incOld );
179 else if ( incOld->type() == "Event" )
180 calendarResource->deleteEvent( (Event *) incOld );
181
182 if ( cl->type() == "Journal" )
183 calendarResource->addJournal( (Journal *) cl, res );
184 else if ( cl->type() == "Todo" )
185 calendarResource->addTodo( (Todo *) cl, res );
186 else if ( cl->type() == "Event" )
187 calendarResource->addEvent( (Event *) cl, res );
188
189 } else {
190 if ( incOld ) {
191 qDebug("ERROR: no resource found for old incidence ");
192 if ( incOld->type() == "Journal" ) 177 if ( incOld->type() == "Journal" )
193 calendarResource->deleteJournal( (Journal *) incOld ); 178 calendarResource->deleteJournal( (Journal *) incOld );
194 else if ( incOld->type() == "Todo" ) 179 else if ( incOld->type() == "Todo" )
195 calendarResource->deleteTodo( (Todo *) incOld ); 180 calendarResource->deleteTodo( (Todo *) incOld );
196 else if ( incOld->type() == "Event" ) 181 else if ( incOld->type() == "Event" )
197 calendarResource->deleteEvent( (Event *) incOld ); 182 calendarResource->deleteEvent( (Event *) incOld );
183
184 if ( cl->type() == "Journal" )
185 calendarResource->addJournal( (Journal *) cl, res );
186 else if ( cl->type() == "Todo" )
187 calendarResource->addTodo( (Todo *) cl, res );
188 else if ( cl->type() == "Event" )
189 calendarResource->addEvent( (Event *) cl, res );
190
191 } else {
192 if ( incOld ) {
193 qDebug("ERROR: no resource found for old incidence ");
194 if ( incOld->type() == "Journal" )
195 calendarResource->deleteJournal( (Journal *) incOld );
196 else if ( incOld->type() == "Todo" )
197 calendarResource->deleteTodo( (Todo *) incOld );
198 else if ( incOld->type() == "Event" )
199 calendarResource->deleteEvent( (Event *) incOld );
198 200
201 }
202 calendarResource->addIncidence( cl );
203 ++add;
199 } 204 }
205 } else { // added
206 Incidence* cl = (*it)->clone();
200 calendarResource->addIncidence( cl ); 207 calendarResource->addIncidence( cl );
201 ++add; 208 ++add;
202 } 209 }
203 } 210 }
204 KCal::Incidence::List allInc = calendarResource->rawIncidences(); 211 KCal::Incidence::List allInc = calendarResource->rawIncidences();
205 212
206 for( it = allInc.begin(); it != allInc.end(); ++it ) { 213 for( it = allInc.begin(); it != allInc.end(); ++it ) {
207 ResourceCalendar * re = calendarResource->resource( (*it) ); 214 ResourceCalendar * re = calendarResource->resource( (*it) );
208 if ( re && !re->readOnly() ) { 215 if ( re && !re->readOnly() ) {
209 Incidence* cl = localCalendar->incidence( (*it)->uid() ); 216 Incidence* cl = localCalendar->incidence( (*it)->uid() );
210 if ( !cl ) { 217 if ( !cl ) {
211 ++del; 218 ++del;
212 cl = (*it); 219 cl = (*it);
213 if ( cl->type() == "Journal" ) 220 if ( cl->type() == "Journal" )
214 calendarResource->deleteJournal( (Journal *) cl ); 221 calendarResource->deleteJournal( (Journal *) cl );
215 else if ( cl->type() == "Todo" ) 222 else if ( cl->type() == "Todo" )
216 calendarResource->deleteTodo( (Todo *) cl ); 223 calendarResource->deleteTodo( (Todo *) cl );
217 else if ( cl->type() == "Event" ) 224 else if ( cl->type() == "Event" )
218 calendarResource->deleteEvent( (Event *) cl ); 225 calendarResource->deleteEvent( (Event *) cl );
219 //QDateTime lm = cl->lastModified(); 226 //QDateTime lm = cl->lastModified();
220 //cl->setResources( (*it)->resources() ); 227 //cl->setResources( (*it)->resources() );
221 //cl->setLastModified(lm); 228 //cl->setLastModified(lm);
222 } 229 }
223 } 230 }
224 } 231 }
225 232
226 calendarResource->save(); 233 calendarResource->save();
227 qDebug("************************************* "); 234 qDebug("************************************* ");
228 qDebug("************kdecaldump*************** "); 235 qDebug("************kdecaldump*************** ");
229 qDebug("************************************* "); 236 qDebug("************************************* ");
230 qDebug("Calendar entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", num,del, add, fileName.latin1()); 237 qDebug("Calendar entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", num,del, add, fileName.latin1());
231 238
232 } else 239 } else
233 qDebug("ERROR loading file %s",fileName.latin1() ); 240 qDebug("ERROR loading file %s",fileName.latin1() );
234 241
235 } 242 }
236 243
237 if ( localCalendar ) { 244 if ( localCalendar ) {
238 localCalendar->close(); 245 localCalendar->close();
239 delete localCalendar; 246 delete localCalendar;
240 } 247 }
241 if ( calendarResource ) { 248 if ( calendarResource ) {
242 calendarResource->close(); 249 calendarResource->close();
243 delete calendarResource; 250 delete calendarResource;
244 } 251 }
245 252
246 qDebug("ente "); 253 qDebug("ente ");
247 return 0; 254 return 0;
248} 255}
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 1f8ad5b..f727cd4 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,3076 +1,3084 @@
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 (preston.brown@yale.edu) 8 Preston Brown (preston.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 "statusdialog.h" 110#include "statusdialog.h"
111#include "kdatenavigator.h" 111#include "kdatenavigator.h"
112#include "kotodoview.h" 112#include "kotodoview.h"
113#include "datenavigator.h" 113#include "datenavigator.h"
114#include "resourceview.h" 114#include "resourceview.h"
115#include "navigatorbar.h" 115#include "navigatorbar.h"
116#include "searchdialog.h" 116#include "searchdialog.h"
117#include "mainwindow.h" 117#include "mainwindow.h"
118 118
119#include "calendarview.h" 119#include "calendarview.h"
120#ifndef DESKTOP_VERSION 120#ifndef DESKTOP_VERSION
121#include <qtopia/alarmserver.h> 121#include <qtopia/alarmserver.h>
122#endif 122#endif
123#ifndef _WIN32_ 123#ifndef _WIN32_
124#include <stdlib.h> 124#include <stdlib.h>
125#include <stdio.h> 125#include <stdio.h>
126#include <unistd.h> 126#include <unistd.h>
127#else 127#else
128#include <qprocess.h> 128#include <qprocess.h>
129#endif 129#endif
130 130
131#ifdef DESKTOP_VERSION 131#ifdef DESKTOP_VERSION
132#include <kabc/stdaddressbook.h> 132#include <kabc/stdaddressbook.h>
133#endif 133#endif
134using namespace KOrg; 134using namespace KOrg;
135using namespace KCal; 135using namespace KCal;
136extern int globalFlagBlockAgenda; 136extern int globalFlagBlockAgenda;
137extern int globalFlagBlockStartup; 137extern int globalFlagBlockStartup;
138 138
139 139
140 140
141class KOBeamPrefs : public QDialog 141class KOBeamPrefs : public QDialog
142{ 142{
143 public: 143 public:
144 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : 144 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) :
145 QDialog( parent, name, true ) 145 QDialog( parent, name, true )
146 { 146 {
147 setCaption( i18n("Beam Options") ); 147 setCaption( i18n("Beam Options") );
148 QVBoxLayout* lay = new QVBoxLayout( this ); 148 QVBoxLayout* lay = new QVBoxLayout( this );
149 lay->setSpacing( 3 ); 149 lay->setSpacing( 3 );
150 lay->setMargin( 3 ); 150 lay->setMargin( 3 );
151 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); 151 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this );
152 lay->addWidget( format ); 152 lay->addWidget( format );
153 format->setExclusive ( true ) ; 153 format->setExclusive ( true ) ;
154 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); 154 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this );
155 lay->addWidget( time ); time->setExclusive ( true ) ; 155 lay->addWidget( time ); time->setExclusive ( true ) ;
156 vcal = new QRadioButton(" vCalendar ", format ); 156 vcal = new QRadioButton(" vCalendar ", format );
157 ical = new QRadioButton(" iCalendar ", format ); 157 ical = new QRadioButton(" iCalendar ", format );
158 vcal->setChecked( true ); 158 vcal->setChecked( true );
159 tz = new QRadioButton(i18n(" With timezone "), time ); 159 tz = new QRadioButton(i18n(" With timezone "), time );
160 local = new QRadioButton(i18n(" Local time "), time ); 160 local = new QRadioButton(i18n(" Local time "), time );
161 tz->setChecked( true ); 161 tz->setChecked( true );
162 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); 162 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this );
163 lay->addWidget( ok ); 163 lay->addWidget( ok );
164 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 164 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
165 lay->addWidget( cancel ); 165 lay->addWidget( cancel );
166 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 166 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
167 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 167 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
168 resize( 200, 200 ); 168 resize( 200, 200 );
169 } 169 }
170 170
171 bool beamVcal() { return vcal->isChecked(); } 171 bool beamVcal() { return vcal->isChecked(); }
172 bool beamLocal() { return local->isChecked(); } 172 bool beamLocal() { return local->isChecked(); }
173private: 173private:
174 QRadioButton* vcal, *ical, *local, *tz; 174 QRadioButton* vcal, *ical, *local, *tz;
175}; 175};
176class KOCatPrefs : public QDialog 176class KOCatPrefs : public QDialog
177{ 177{
178 public: 178 public:
179 KOCatPrefs( QWidget *parent=0, const char *name=0 ) : 179 KOCatPrefs( QWidget *parent=0, const char *name=0 ) :
180 QDialog( parent, name, true ) 180 QDialog( parent, name, true )
181 { 181 {
182 setCaption( i18n("Manage new Categories") ); 182 setCaption( i18n("Manage new Categories") );
183 QVBoxLayout* lay = new QVBoxLayout( this ); 183 QVBoxLayout* lay = new QVBoxLayout( this );
184 lay->setSpacing( 3 ); 184 lay->setSpacing( 3 );
185 lay->setMargin( 3 ); 185 lay->setMargin( 3 );
186 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 ); 186 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 );
187 lay->addWidget( lab ); 187 lay->addWidget( lab );
188 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); 188 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this );
189 lay->addWidget( format ); 189 lay->addWidget( format );
190 format->setExclusive ( true ) ; 190 format->setExclusive ( true ) ;
191 addCatBut = new QRadioButton(i18n("Add to category list"), format ); 191 addCatBut = new QRadioButton(i18n("Add to category list"), format );
192 new QRadioButton(i18n("Remove from Events/Todos"), format ); 192 new QRadioButton(i18n("Remove from Events/Todos"), format );
193 addCatBut->setChecked( true ); 193 addCatBut->setChecked( true );
194 QPushButton * ok = new QPushButton( i18n("OK"), this ); 194 QPushButton * ok = new QPushButton( i18n("OK"), this );
195 lay->addWidget( ok ); 195 lay->addWidget( ok );
196 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 196 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
197 lay->addWidget( cancel ); 197 lay->addWidget( cancel );
198 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 198 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
199 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 199 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
200 resize( 200, 200 ); 200 resize( 200, 200 );
201 } 201 }
202 202
203 bool addCat() { return addCatBut->isChecked(); } 203 bool addCat() { return addCatBut->isChecked(); }
204private: 204private:
205 QRadioButton* addCatBut; 205 QRadioButton* addCatBut;
206}; 206};
207 207
208 208
209 209
210CalendarView::CalendarView( CalendarResources *calendar, 210CalendarView::CalendarView( CalendarResources *calendar,
211 QWidget *parent, const char *name ) 211 QWidget *parent, const char *name )
212 : CalendarViewBase( parent, name ), 212 : CalendarViewBase( parent, name ),
213 mCalendar( calendar ), 213 mCalendar( calendar ),
214 mResourceManager( calendar->resourceManager() ) 214 mResourceManager( calendar->resourceManager() )
215{ 215{
216 216
217 mEventEditor = 0; 217 mEventEditor = 0;
218 mTodoEditor = 0; 218 mTodoEditor = 0;
219 219
220 init(); 220 init();
221} 221}
222 222
223CalendarView::CalendarView( Calendar *calendar, 223CalendarView::CalendarView( Calendar *calendar,
224 QWidget *parent, const char *name ) 224 QWidget *parent, const char *name )
225 : CalendarViewBase( parent, name ), 225 : CalendarViewBase( parent, name ),
226 mCalendar( calendar ), 226 mCalendar( calendar ),
227 mResourceManager( 0 ) 227 mResourceManager( 0 )
228{ 228{
229 229
230 mEventEditor = 0; 230 mEventEditor = 0;
231 mTodoEditor = 0; 231 mTodoEditor = 0;
232 init();} 232 init();}
233 233
234void CalendarView::init() 234void CalendarView::init()
235{ 235{
236 beamDialog = new KOBeamPrefs(); 236 beamDialog = new KOBeamPrefs();
237 mDatePickerMode = 0; 237 mDatePickerMode = 0;
238 mCurrentSyncDevice = ""; 238 mCurrentSyncDevice = "";
239 writeLocale(); 239 writeLocale();
240 mViewManager = new KOViewManager( this ); 240 mViewManager = new KOViewManager( this );
241 mDialogManager = new KODialogManager( this ); 241 mDialogManager = new KODialogManager( this );
242 mEventViewerDialog = 0; 242 mEventViewerDialog = 0;
243 mModified = false; 243 mModified = false;
244 mReadOnly = false; 244 mReadOnly = false;
245 mSelectedIncidence = 0; 245 mSelectedIncidence = 0;
246 mCalPrinter = 0; 246 mCalPrinter = 0;
247 mFilters.setAutoDelete(true); 247 mFilters.setAutoDelete(true);
248 248
249 mCalendar->registerObserver( this ); 249 mCalendar->registerObserver( this );
250 // TODO: Make sure that view is updated, when calendar is changed. 250 // TODO: Make sure that view is updated, when calendar is changed.
251 251
252 mStorage = new FileStorage( mCalendar ); 252 mStorage = new FileStorage( mCalendar );
253 mNavigator = new DateNavigator( this, "datevav", mViewManager ); 253 mNavigator = new DateNavigator( this, "datevav", mViewManager );
254 254
255 QBoxLayout *topLayout = (QBoxLayout*)layout(); 255 QBoxLayout *topLayout = (QBoxLayout*)layout();
256#ifndef KORG_NOSPLITTER 256#ifndef KORG_NOSPLITTER
257 // create the main layout frames. 257 // create the main layout frames.
258 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); 258 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner");
259 topLayout->addWidget(mPanner); 259 topLayout->addWidget(mPanner);
260 260
261 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, 261 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner,
262 "CalendarView::LeftFrame"); 262 "CalendarView::LeftFrame");
263 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); 263 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize);
264 264
265 mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE, 265 mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE,
266 "CalendarView::DateNavigator", QDate::currentDate() ); 266 "CalendarView::DateNavigator", QDate::currentDate() );
267 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); 267 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize);
268 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); 268 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2");
269 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); 269 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView");
270 270
271#ifdef KORG_NORESOURCEVIEW 271#ifdef KORG_NORESOURCEVIEW
272 mResourceView = 0; 272 mResourceView = 0;
273#else 273#else
274 if ( mResourceManager ) { 274 if ( mResourceManager ) {
275 mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); 275 mResourceView = new ResourceView( mResourceManager, mLeftSplitter );
276 mResourceView->updateView(); 276 mResourceView->updateView();
277 connect( mResourceView, SIGNAL( resourcesChanged() ), 277 connect( mResourceView, SIGNAL( resourcesChanged() ),
278 SLOT( updateView() ) ); 278 SLOT( updateView() ) );
279 } else { 279 } else {
280 mResourceView = 0; 280 mResourceView = 0;
281 } 281 }
282#endif 282#endif
283 QWidget *rightBox = new QWidget( mPanner ); 283 QWidget *rightBox = new QWidget( mPanner );
284 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 284 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
285 285
286 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); 286 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" );
287 rightLayout->addWidget( mNavigatorBar ); 287 rightLayout->addWidget( mNavigatorBar );
288 288
289 mRightFrame = new QWidgetStack( rightBox ); 289 mRightFrame = new QWidgetStack( rightBox );
290 rightLayout->addWidget( mRightFrame, 1 ); 290 rightLayout->addWidget( mRightFrame, 1 );
291 291
292 mLeftFrame = mLeftSplitter; 292 mLeftFrame = mLeftSplitter;
293#else 293#else
294 QWidget *mainBox = new QWidget( this ); 294 QWidget *mainBox = new QWidget( this );
295 QWidget *leftFrame = new QWidget( mainBox ); 295 QWidget *leftFrame = new QWidget( mainBox );
296 296
297 QBoxLayout * mainBoxLayout; 297 QBoxLayout * mainBoxLayout;
298 QBoxLayout * leftFrameLayout; 298 QBoxLayout * leftFrameLayout;
299 if ( KOPrefs::instance()->mVerticalScreen ) { 299 if ( KOPrefs::instance()->mVerticalScreen ) {
300 mainBoxLayout = new QVBoxLayout(mainBox); 300 mainBoxLayout = new QVBoxLayout(mainBox);
301 leftFrameLayout = new QHBoxLayout(leftFrame ); 301 leftFrameLayout = new QHBoxLayout(leftFrame );
302 } else { 302 } else {
303 mainBoxLayout = new QHBoxLayout(mainBox); 303 mainBoxLayout = new QHBoxLayout(mainBox);
304 leftFrameLayout = new QVBoxLayout(leftFrame ); 304 leftFrameLayout = new QVBoxLayout(leftFrame );
305 } 305 }
306 topLayout->addWidget( mainBox ); 306 topLayout->addWidget( mainBox );
307 mainBoxLayout->addWidget (leftFrame); 307 mainBoxLayout->addWidget (leftFrame);
308 mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE, 308 mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE,
309 "CalendarView::DateNavigator", QDate::currentDate()); 309 "CalendarView::DateNavigator", QDate::currentDate());
310 // mDateNavigator->blockSignals( true ); 310 // mDateNavigator->blockSignals( true );
311 leftFrameLayout->addWidget( mDateNavigator ); 311 leftFrameLayout->addWidget( mDateNavigator );
312 mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView"); 312 mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView");
313 mTodoList = new KOTodoView(mCalendar, leftFrame, "todolistsmall"); 313 mTodoList = new KOTodoView(mCalendar, leftFrame, "todolistsmall");
314 314
315 if ( QApplication::desktop()->width() < 480 ) { 315 if ( QApplication::desktop()->width() < 480 ) {
316 leftFrameLayout->addWidget(mFilterView); 316 leftFrameLayout->addWidget(mFilterView);
317 leftFrameLayout->addWidget(mTodoList, 2 ); 317 leftFrameLayout->addWidget(mTodoList, 2 );
318 318
319 } else { 319 } else {
320 leftFrameLayout->addWidget(mTodoList,2 ); 320 leftFrameLayout->addWidget(mTodoList,2 );
321 leftFrameLayout->addWidget(mFilterView ); 321 leftFrameLayout->addWidget(mFilterView );
322 } 322 }
323 mFilterView->hide(); 323 mFilterView->hide();
324 QWidget *rightBox = new QWidget( mainBox ); 324 QWidget *rightBox = new QWidget( mainBox );
325 mainBoxLayout->addWidget ( rightBox, 10 ); 325 mainBoxLayout->addWidget ( rightBox, 10 );
326 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 326 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
327 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); 327 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" );
328 mRightFrame = new QWidgetStack( rightBox ); 328 mRightFrame = new QWidgetStack( rightBox );
329 rightLayout->addWidget( mNavigatorBar ); 329 rightLayout->addWidget( mNavigatorBar );
330 rightLayout->addWidget( mRightFrame, 10 ); 330 rightLayout->addWidget( mRightFrame, 10 );
331 331
332 mLeftFrame = leftFrame; 332 mLeftFrame = leftFrame;
333 if ( KOPrefs::instance()->mVerticalScreen ) { 333 if ( KOPrefs::instance()->mVerticalScreen ) {
334 mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); 334 mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() );
335 leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); 335 leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() );
336 } else { 336 } else {
337 mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); 337 mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() );
338 leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); 338 leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() );
339 } 339 }
340 340
341 //qDebug("Calendarview Size %d %d ", width(), height()); 341 //qDebug("Calendarview Size %d %d ", width(), height());
342#endif 342#endif
343 343
344 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 344 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
345 SLOT( showDates( const KCal::DateList & ) ) ); 345 SLOT( showDates( const KCal::DateList & ) ) );
346 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 346 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
347 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 347 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
348 348
349 connect( mNavigatorBar, SIGNAL( goPrevYear() ), 349 connect( mNavigatorBar, SIGNAL( goPrevYear() ),
350 mNavigator, SLOT( selectPreviousYear() ) ); 350 mNavigator, SLOT( selectPreviousYear() ) );
351 connect( mNavigatorBar, SIGNAL( goNextYear() ), 351 connect( mNavigatorBar, SIGNAL( goNextYear() ),
352 mNavigator, SLOT( selectNextYear() ) ); 352 mNavigator, SLOT( selectNextYear() ) );
353 connect( mNavigatorBar, SIGNAL( goPrevMonth() ), 353 connect( mNavigatorBar, SIGNAL( goPrevMonth() ),
354 mNavigator, SLOT( selectPreviousMonth() ) ); 354 mNavigator, SLOT( selectPreviousMonth() ) );
355 connect( mNavigatorBar, SIGNAL( goNextMonth() ), 355 connect( mNavigatorBar, SIGNAL( goNextMonth() ),
356 mNavigator, SLOT( selectNextMonth() ) ); 356 mNavigator, SLOT( selectNextMonth() ) );
357 357
358 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 358 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
359 mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) ); 359 mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) );
360 360
361 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), 361 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ),
362 mNavigator, SLOT( selectWeek( const QDate & ) ) ); 362 mNavigator, SLOT( selectWeek( const QDate & ) ) );
363 363
364 connect( mDateNavigator, SIGNAL( goPrevYear() ), 364 connect( mDateNavigator, SIGNAL( goPrevYear() ),
365 mNavigator, SLOT( selectPreviousYear() ) ); 365 mNavigator, SLOT( selectPreviousYear() ) );
366 connect( mDateNavigator, SIGNAL( goNextYear() ), 366 connect( mDateNavigator, SIGNAL( goNextYear() ),
367 mNavigator, SLOT( selectNextYear() ) ); 367 mNavigator, SLOT( selectNextYear() ) );
368 connect( mDateNavigator, SIGNAL( goPrevMonth() ), 368 connect( mDateNavigator, SIGNAL( goPrevMonth() ),
369 mNavigator, SLOT( selectPreviousMonth() ) ); 369 mNavigator, SLOT( selectPreviousMonth() ) );
370 connect( mDateNavigator, SIGNAL( goNextMonth() ), 370 connect( mDateNavigator, SIGNAL( goNextMonth() ),
371 mNavigator, SLOT( selectNextMonth() ) ); 371 mNavigator, SLOT( selectNextMonth() ) );
372 372
373 connect( mDateNavigator, SIGNAL( goPrevious() ), 373 connect( mDateNavigator, SIGNAL( goPrevious() ),
374 mNavigator, SLOT( selectPrevious() ) ); 374 mNavigator, SLOT( selectPrevious() ) );
375 connect( mDateNavigator, SIGNAL( goNext() ), 375 connect( mDateNavigator, SIGNAL( goNext() ),
376 mNavigator, SLOT( selectNext() ) ); 376 mNavigator, SLOT( selectNext() ) );
377 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), 377 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ),
378 mNavigator, SLOT( slotMonthSelect( int ) ) ); 378 mNavigator, SLOT( slotMonthSelect( int ) ) );
379 connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ), 379 connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ),
380 mNavigator, SLOT( slotMonthSelect( int ) ) ); 380 mNavigator, SLOT( slotMonthSelect( int ) ) );
381 381
382 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 382 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
383 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 383 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
384 384
385 connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ), 385 connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ),
386 SLOT( eventAdded( Event *) ) ); 386 SLOT( eventAdded( Event *) ) );
387 387
388 connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); 388 connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView()));
389 389
390 connect( this, SIGNAL( configChanged() ), 390 connect( this, SIGNAL( configChanged() ),
391 mDateNavigator, SLOT( updateConfig() ) ); 391 mDateNavigator, SLOT( updateConfig() ) );
392 392
393 connect( mTodoList, SIGNAL( newTodoSignal() ), 393 connect( mTodoList, SIGNAL( newTodoSignal() ),
394 SLOT( newTodo() ) ); 394 SLOT( newTodo() ) );
395 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), 395 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ),
396 SLOT( newSubTodo( Todo * ) ) ); 396 SLOT( newSubTodo( Todo * ) ) );
397 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), 397 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ),
398 SLOT( editTodo( Todo * ) ) ); 398 SLOT( editTodo( Todo * ) ) );
399 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), 399 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ),
400 SLOT( showTodo( Todo *) ) ); 400 SLOT( showTodo( Todo *) ) );
401 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), 401 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ),
402 SLOT( deleteTodo( Todo *) ) ); 402 SLOT( deleteTodo( Todo *) ) );
403 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); 403 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) );
404 connect( mTodoList, SIGNAL( purgeCompletedSignal() ), 404 connect( mTodoList, SIGNAL( purgeCompletedSignal() ),
405 SLOT( purgeCompleted() ) ); 405 SLOT( purgeCompleted() ) );
406 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), 406 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ),
407 SIGNAL( todoModified( Todo *, int ) ) ); 407 SIGNAL( todoModified( Todo *, int ) ) );
408 408
409 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), 409 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ),
410 this, SLOT ( cloneIncidence( Incidence * ) ) ); 410 this, SLOT ( cloneIncidence( Incidence * ) ) );
411 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), 411 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ),
412 this, SLOT (cancelIncidence( Incidence * ) ) ); 412 this, SLOT (cancelIncidence( Incidence * ) ) );
413 413
414 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), 414 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ),
415 this, SLOT ( moveIncidence( Incidence * ) ) ); 415 this, SLOT ( moveIncidence( Incidence * ) ) );
416 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), 416 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ),
417 this, SLOT ( beamIncidence( Incidence * ) ) ); 417 this, SLOT ( beamIncidence( Incidence * ) ) );
418 418
419 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), 419 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ),
420 this, SLOT ( todo_unsub( Todo * ) ) ); 420 this, SLOT ( todo_unsub( Todo * ) ) );
421 421
422 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), 422 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ),
423 this, SLOT ( todo_resub( Todo *,Todo * ) ) ); 423 this, SLOT ( todo_resub( Todo *,Todo * ) ) );
424 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, 424 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList,
425 SLOT( updateTodo( Todo *, int ) ) ); 425 SLOT( updateTodo( Todo *, int ) ) );
426 connect( this, SIGNAL( todoModified( Todo *, int )), this, 426 connect( this, SIGNAL( todoModified( Todo *, int )), this,
427 SLOT( changeTodoDisplay( Todo *, int ) ) ); 427 SLOT( changeTodoDisplay( Todo *, int ) ) );
428 428
429 429
430 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); 430 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) );
431 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); 431 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) );
432 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); 432 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) );
433 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); 433 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) );
434 434
435 435
436 436
437 437
438 438
439 connect(QApplication::clipboard(),SIGNAL(dataChanged()), 439 connect(QApplication::clipboard(),SIGNAL(dataChanged()),
440 SLOT(checkClipboard())); 440 SLOT(checkClipboard()));
441 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), 441 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ),
442 SLOT( processTodoListSelection( Incidence * ) ) ); 442 SLOT( processTodoListSelection( Incidence * ) ) );
443 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); 443 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
444 444
445 // kdDebug() << "CalendarView::CalendarView() done" << endl; 445 // kdDebug() << "CalendarView::CalendarView() done" << endl;
446 446
447 mDateFrame = new QVBox(0,0,WType_Popup); 447 mDateFrame = new QVBox(0,0,WType_Popup);
448 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 448 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
449 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 449 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
450 mDateFrame->setLineWidth(3); 450 mDateFrame->setLineWidth(3);
451 mDateFrame->hide(); 451 mDateFrame->hide();
452 mDateFrame->setCaption( i18n( "Pick a date to display")); 452 mDateFrame->setCaption( i18n( "Pick a date to display"));
453 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); 453 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() );
454 454
455 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); 455 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate)));
456 456
457 mEventEditor = mDialogManager->getEventEditor(); 457 mEventEditor = mDialogManager->getEventEditor();
458 mTodoEditor = mDialogManager->getTodoEditor(); 458 mTodoEditor = mDialogManager->getTodoEditor();
459 459
460 mFlagEditDescription = false; 460 mFlagEditDescription = false;
461 461
462 mSuspendTimer = new QTimer( this ); 462 mSuspendTimer = new QTimer( this );
463 mAlarmTimer = new QTimer( this ); 463 mAlarmTimer = new QTimer( this );
464 mRecheckAlarmTimer = new QTimer( this ); 464 mRecheckAlarmTimer = new QTimer( this );
465 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); 465 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) );
466 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 466 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
467 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 467 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
468 mAlarmDialog = new AlarmDialog( this ); 468 mAlarmDialog = new AlarmDialog( this );
469 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 469 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
470 mAlarmDialog->setServerNotification( false ); 470 mAlarmDialog->setServerNotification( false );
471 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 471 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
472 472
473 473
474#ifndef DESKTOP_VERSION 474#ifndef DESKTOP_VERSION
475//US listen for arriving address resultsets 475//US listen for arriving address resultsets
476 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), 476 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)),
477 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); 477 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)));
478#endif 478#endif
479 479
480} 480}
481 481
482 482
483CalendarView::~CalendarView() 483CalendarView::~CalendarView()
484{ 484{
485 // kdDebug() << "~CalendarView()" << endl; 485 // kdDebug() << "~CalendarView()" << endl;
486 //qDebug("CalendarView::~CalendarView() "); 486 //qDebug("CalendarView::~CalendarView() ");
487 delete mDialogManager; 487 delete mDialogManager;
488 delete mViewManager; 488 delete mViewManager;
489 delete mStorage; 489 delete mStorage;
490 delete mDateFrame ; 490 delete mDateFrame ;
491 delete beamDialog; 491 delete beamDialog;
492 //kdDebug() << "~CalendarView() done" << endl; 492 //kdDebug() << "~CalendarView() done" << endl;
493} 493}
494void CalendarView::timerAlarm() 494void CalendarView::timerAlarm()
495{ 495{
496 //qDebug("CalendarView::timerAlarm() "); 496 //qDebug("CalendarView::timerAlarm() ");
497 computeAlarm(mAlarmNotification ); 497 computeAlarm(mAlarmNotification );
498} 498}
499 499
500void CalendarView::suspendAlarm() 500void CalendarView::suspendAlarm()
501{ 501{
502 //qDebug(" CalendarView::suspendAlarm() "); 502 //qDebug(" CalendarView::suspendAlarm() ");
503 computeAlarm(mSuspendAlarmNotification ); 503 computeAlarm(mSuspendAlarmNotification );
504 504
505} 505}
506 506
507void CalendarView::startAlarm( QString mess , QString filename) 507void CalendarView::startAlarm( QString mess , QString filename)
508{ 508{
509 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 509 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
510 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); 510 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) );
511 511
512} 512}
513 513
514void CalendarView::checkNextTimerAlarm() 514void CalendarView::checkNextTimerAlarm()
515{ 515{
516 mCalendar->checkAlarmForIncidence( 0, true ); 516 mCalendar->checkAlarmForIncidence( 0, true );
517} 517}
518 518
519void CalendarView::computeAlarm( QString msg ) 519void CalendarView::computeAlarm( QString msg )
520{ 520{
521 521
522 QString mess = msg; 522 QString mess = msg;
523 QString mAlarmMessage = mess.mid( 9 ); 523 QString mAlarmMessage = mess.mid( 9 );
524 QString filename = MainWindow::resourcePath(); 524 QString filename = MainWindow::resourcePath();
525 filename += "koalarm.wav"; 525 filename += "koalarm.wav";
526 QString tempfilename; 526 QString tempfilename;
527 if ( mess.left( 13 ) == "suspend_alarm") { 527 if ( mess.left( 13 ) == "suspend_alarm") {
528 bool error = false; 528 bool error = false;
529 int len = mess.mid( 13 ).find("+++"); 529 int len = mess.mid( 13 ).find("+++");
530 if ( len < 2 ) 530 if ( len < 2 )
531 error = true; 531 error = true;
532 else { 532 else {
533 tempfilename = mess.mid( 13, len ); 533 tempfilename = mess.mid( 13, len );
534 if ( !QFile::exists( tempfilename ) ) 534 if ( !QFile::exists( tempfilename ) )
535 error = true; 535 error = true;
536 } 536 }
537 if ( ! error ) { 537 if ( ! error ) {
538 filename = tempfilename; 538 filename = tempfilename;
539 } 539 }
540 mAlarmMessage = mess.mid( 13+len+3 ); 540 mAlarmMessage = mess.mid( 13+len+3 );
541 //qDebug("suspend file %s ",tempfilename.latin1() ); 541 //qDebug("suspend file %s ",tempfilename.latin1() );
542 startAlarm( mAlarmMessage, filename); 542 startAlarm( mAlarmMessage, filename);
543 return; 543 return;
544 } 544 }
545 if ( mess.left( 11 ) == "timer_alarm") { 545 if ( mess.left( 11 ) == "timer_alarm") {
546 //mTimerTime = 0; 546 //mTimerTime = 0;
547 startAlarm( mess.mid( 11 ), filename ); 547 startAlarm( mess.mid( 11 ), filename );
548 return; 548 return;
549 } 549 }
550 if ( mess.left( 10 ) == "proc_alarm") { 550 if ( mess.left( 10 ) == "proc_alarm") {
551 bool error = false; 551 bool error = false;
552 int len = mess.mid( 10 ).find("+++"); 552 int len = mess.mid( 10 ).find("+++");
553 if ( len < 2 ) 553 if ( len < 2 )
554 error = true; 554 error = true;
555 else { 555 else {
556 tempfilename = mess.mid( 10, len ); 556 tempfilename = mess.mid( 10, len );
557 if ( !QFile::exists( tempfilename ) ) 557 if ( !QFile::exists( tempfilename ) )
558 error = true; 558 error = true;
559 } 559 }
560 if ( error ) { 560 if ( error ) {
561 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 561 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
562 mAlarmMessage += mess.mid( 10+len+3+9 ); 562 mAlarmMessage += mess.mid( 10+len+3+9 );
563 } else { 563 } else {
564 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 564 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
565 //qDebug("-----system command %s ",tempfilename.latin1() ); 565 //qDebug("-----system command %s ",tempfilename.latin1() );
566#ifndef _WIN32_ 566#ifndef _WIN32_
567 if ( vfork () == 0 ) { 567 if ( vfork () == 0 ) {
568 execl ( tempfilename.latin1(), 0 ); 568 execl ( tempfilename.latin1(), 0 );
569 return; 569 return;
570 } 570 }
571#else 571#else
572 QProcess* p = new QProcess(); 572 QProcess* p = new QProcess();
573 p->addArgument( tempfilename.latin1() ); 573 p->addArgument( tempfilename.latin1() );
574 p->start(); 574 p->start();
575 return; 575 return;
576#endif 576#endif
577 577
578 return; 578 return;
579 } 579 }
580 580
581 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 581 //qDebug("+++++++system command %s ",tempfilename.latin1() );
582 } 582 }
583 if ( mess.left( 11 ) == "audio_alarm") { 583 if ( mess.left( 11 ) == "audio_alarm") {
584 bool error = false; 584 bool error = false;
585 int len = mess.mid( 11 ).find("+++"); 585 int len = mess.mid( 11 ).find("+++");
586 if ( len < 2 ) 586 if ( len < 2 )
587 error = true; 587 error = true;
588 else { 588 else {
589 tempfilename = mess.mid( 11, len ); 589 tempfilename = mess.mid( 11, len );
590 if ( !QFile::exists( tempfilename ) ) 590 if ( !QFile::exists( tempfilename ) )
591 error = true; 591 error = true;
592 } 592 }
593 if ( ! error ) { 593 if ( ! error ) {
594 filename = tempfilename; 594 filename = tempfilename;
595 } 595 }
596 mAlarmMessage = mess.mid( 11+len+3+9 ); 596 mAlarmMessage = mess.mid( 11+len+3+9 );
597 //qDebug("audio file command %s ",tempfilename.latin1() ); 597 //qDebug("audio file command %s ",tempfilename.latin1() );
598 } 598 }
599 if ( mess.left( 9 ) == "cal_alarm") { 599 if ( mess.left( 9 ) == "cal_alarm") {
600 mAlarmMessage = mess.mid( 9 ) ; 600 mAlarmMessage = mess.mid( 9 ) ;
601 } 601 }
602 602
603 startAlarm( mAlarmMessage, filename ); 603 startAlarm( mAlarmMessage, filename );
604 604
605 605
606} 606}
607 607
608void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 608void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
609{ 609{
610 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 610 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
611 611
612 mSuspendAlarmNotification = noti; 612 mSuspendAlarmNotification = noti;
613 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 613 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
614 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 614 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
615 mSuspendTimer->start( ms , true ); 615 mSuspendTimer->start( ms , true );
616 616
617} 617}
618 618
619void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 619void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
620{ 620{
621 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 621 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
622 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 622 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
623#ifndef DESKTOP_VERSION 623#ifndef DESKTOP_VERSION
624 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); 624 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() );
625#endif 625#endif
626 return; 626 return;
627 } 627 }
628 int maxSec; 628 int maxSec;
629 //maxSec = 5; //testing only 629 //maxSec = 5; //testing only
630 maxSec = 86400+3600; // one day+1hour 630 maxSec = 86400+3600; // one day+1hour
631 mAlarmNotification = noti; 631 mAlarmNotification = noti;
632 int sec = QDateTime::currentDateTime().secsTo( qdt ); 632 int sec = QDateTime::currentDateTime().secsTo( qdt );
633 if ( sec > maxSec ) { 633 if ( sec > maxSec ) {
634 mRecheckAlarmTimer->start( maxSec * 1000 ); 634 mRecheckAlarmTimer->start( maxSec * 1000 );
635 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 635 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
636 return; 636 return;
637 } else { 637 } else {
638 mRecheckAlarmTimer->stop(); 638 mRecheckAlarmTimer->stop();
639 } 639 }
640 //qDebug("Alarm timer started with secs: %d ", sec); 640 //qDebug("Alarm timer started with secs: %d ", sec);
641 mAlarmTimer->start( sec *1000 , true ); 641 mAlarmTimer->start( sec *1000 , true );
642 642
643} 643}
644// called by mRecheckAlarmTimer to get next alarm 644// called by mRecheckAlarmTimer to get next alarm
645// we need this, because a QTimer has only a max range of 25 days 645// we need this, because a QTimer has only a max range of 25 days
646void CalendarView::recheckTimerAlarm() 646void CalendarView::recheckTimerAlarm()
647{ 647{
648 mAlarmTimer->stop(); 648 mAlarmTimer->stop();
649 mRecheckAlarmTimer->stop(); 649 mRecheckAlarmTimer->stop();
650 mCalendar->checkAlarmForIncidence( 0, true ); 650 mCalendar->checkAlarmForIncidence( 0, true );
651} 651}
652void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 652void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
653{ 653{
654 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 654 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
655 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 655 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
656#ifndef DESKTOP_VERSION 656#ifndef DESKTOP_VERSION
657 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 657 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
658#endif 658#endif
659 return; 659 return;
660 } 660 }
661 mAlarmTimer->stop(); 661 mAlarmTimer->stop();
662} 662}
663void CalendarView::selectWeekNum ( int num ) 663void CalendarView::selectWeekNum ( int num )
664{ 664{
665 dateNavigator()->selectWeek( num ); 665 dateNavigator()->selectWeek( num );
666 mViewManager->showWeekView(); 666 mViewManager->showWeekView();
667} 667}
668KOViewManager *CalendarView::viewManager() 668KOViewManager *CalendarView::viewManager()
669{ 669{
670 return mViewManager; 670 return mViewManager;
671} 671}
672 672
673KODialogManager *CalendarView::dialogManager() 673KODialogManager *CalendarView::dialogManager()
674{ 674{
675 return mDialogManager; 675 return mDialogManager;
676} 676}
677 677
678QDate CalendarView::startDate() 678QDate CalendarView::startDate()
679{ 679{
680 DateList dates = mNavigator->selectedDates(); 680 DateList dates = mNavigator->selectedDates();
681 681
682 return dates.first(); 682 return dates.first();
683} 683}
684 684
685QDate CalendarView::endDate() 685QDate CalendarView::endDate()
686{ 686{
687 DateList dates = mNavigator->selectedDates(); 687 DateList dates = mNavigator->selectedDates();
688 688
689 return dates.last(); 689 return dates.last();
690} 690}
691 691
692 692
693void CalendarView::createPrinter() 693void CalendarView::createPrinter()
694{ 694{
695#ifndef KORG_NOPRINTER 695#ifndef KORG_NOPRINTER
696 if (!mCalPrinter) { 696 if (!mCalPrinter) {
697 mCalPrinter = new CalPrinter(this, mCalendar); 697 mCalPrinter = new CalPrinter(this, mCalendar);
698 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 698 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
699 } 699 }
700#endif 700#endif
701} 701}
702 702
703 703
704//KOPrefs::instance()->mWriteBackFile 704//KOPrefs::instance()->mWriteBackFile
705//KOPrefs::instance()->mWriteBackExistingOnly 705//KOPrefs::instance()->mWriteBackExistingOnly
706 706
707// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 707// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
708// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 708// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
709// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 709// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
710// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 710// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
711// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 711// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
712// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 712// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
713 713
714int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 714int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
715{ 715{
716 716
717 //void setZaurusId(int id); 717 //void setZaurusId(int id);
718 // int zaurusId() const; 718 // int zaurusId() const;
719 // void setZaurusUid(int id); 719 // void setZaurusUid(int id);
720 // int zaurusUid() const; 720 // int zaurusUid() const;
721 // void setZaurusStat(int id); 721 // void setZaurusStat(int id);
722 // int zaurusStat() const; 722 // int zaurusStat() const;
723 // 0 equal 723 // 0 equal
724 // 1 take local 724 // 1 take local
725 // 2 take remote 725 // 2 take remote
726 // 3 cancel 726 // 3 cancel
727 QDateTime lastSync = mLastCalendarSync; 727 QDateTime lastSync = mLastCalendarSync;
728 QDateTime localMod = local->lastModified(); 728 QDateTime localMod = local->lastModified();
729 QDateTime remoteMod = remote->lastModified(); 729 QDateTime remoteMod = remote->lastModified();
730 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 730 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
731 bool remCh, locCh; 731 bool remCh, locCh;
732 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 732 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
733 //if ( remCh ) 733 //if ( remCh )
734 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 734 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
735 locCh = ( localMod > mLastCalendarSync ); 735 locCh = ( localMod > mLastCalendarSync );
736 if ( !remCh && ! locCh ) { 736 if ( !remCh && ! locCh ) {
737 //qDebug("both not changed "); 737 //qDebug("both not changed ");
738 lastSync = localMod.addDays(1); 738 lastSync = localMod.addDays(1);
739 if ( mode <= SYNC_PREF_ASK ) 739 if ( mode <= SYNC_PREF_ASK )
740 return 0; 740 return 0;
741 } else { 741 } else {
742 if ( locCh ) { 742 if ( locCh ) {
743 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 743 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
744 lastSync = localMod.addDays( -1 ); 744 lastSync = localMod.addDays( -1 );
745 if ( !remCh ) 745 if ( !remCh )
746 remoteMod = ( lastSync.addDays( -1 ) ); 746 remoteMod = ( lastSync.addDays( -1 ) );
747 } else { 747 } else {
748 //qDebug(" not loc changed "); 748 //qDebug(" not loc changed ");
749 lastSync = localMod.addDays( 1 ); 749 lastSync = localMod.addDays( 1 );
750 if ( remCh ) 750 if ( remCh )
751 remoteMod =( lastSync.addDays( 1 ) ); 751 remoteMod =( lastSync.addDays( 1 ) );
752 752
753 } 753 }
754 } 754 }
755 full = true; 755 full = true;
756 if ( mode < SYNC_PREF_ASK ) 756 if ( mode < SYNC_PREF_ASK )
757 mode = SYNC_PREF_ASK; 757 mode = SYNC_PREF_ASK;
758 } else { 758 } else {
759 if ( localMod == remoteMod ) 759 if ( localMod == remoteMod )
760 if ( local->revision() == remote->revision() ) 760 if ( local->revision() == remote->revision() )
761 return 0; 761 return 0;
762 762
763 } 763 }
764 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 764 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
765 765
766 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 766 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
767 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 767 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
768 //full = true; //debug only 768 //full = true; //debug only
769 if ( full ) { 769 if ( full ) {
770 bool equ = false; 770 bool equ = false;
771 if ( local->type() == "Event" ) { 771 if ( local->type() == "Event" ) {
772 equ = (*((Event*) local) == *((Event*) remote)); 772 equ = (*((Event*) local) == *((Event*) remote));
773 } 773 }
774 else if ( local->type() =="Todo" ) 774 else if ( local->type() =="Todo" )
775 equ = (*((Todo*) local) == (*(Todo*) remote)); 775 equ = (*((Todo*) local) == (*(Todo*) remote));
776 else if ( local->type() =="Journal" ) 776 else if ( local->type() =="Journal" )
777 equ = (*((Journal*) local) == *((Journal*) remote)); 777 equ = (*((Journal*) local) == *((Journal*) remote));
778 if ( equ ) { 778 if ( equ ) {
779 //qDebug("equal "); 779 //qDebug("equal ");
780 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 780 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
781 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 781 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
782 } 782 }
783 if ( mode < SYNC_PREF_FORCE_LOCAL ) 783 if ( mode < SYNC_PREF_FORCE_LOCAL )
784 return 0; 784 return 0;
785 785
786 }//else //debug only 786 }//else //debug only
787 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 787 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
788 } 788 }
789 int result; 789 int result;
790 bool localIsNew; 790 bool localIsNew;
791 //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() ); 791 //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() );
792 792
793 if ( full && mode < SYNC_PREF_NEWEST ) 793 if ( full && mode < SYNC_PREF_NEWEST )
794 mode = SYNC_PREF_ASK; 794 mode = SYNC_PREF_ASK;
795 795
796 switch( mode ) { 796 switch( mode ) {
797 case SYNC_PREF_LOCAL: 797 case SYNC_PREF_LOCAL:
798 if ( lastSync > remoteMod ) 798 if ( lastSync > remoteMod )
799 return 1; 799 return 1;
800 if ( lastSync > localMod ) 800 if ( lastSync > localMod )
801 return 2; 801 return 2;
802 return 1; 802 return 1;
803 break; 803 break;
804 case SYNC_PREF_REMOTE: 804 case SYNC_PREF_REMOTE:
805 if ( lastSync > remoteMod ) 805 if ( lastSync > remoteMod )
806 return 1; 806 return 1;
807 if ( lastSync > localMod ) 807 if ( lastSync > localMod )
808 return 2; 808 return 2;
809 return 2; 809 return 2;
810 break; 810 break;
811 case SYNC_PREF_NEWEST: 811 case SYNC_PREF_NEWEST:
812 if ( localMod > remoteMod ) 812 if ( localMod > remoteMod )
813 return 1; 813 return 1;
814 else 814 else
815 return 2; 815 return 2;
816 break; 816 break;
817 case SYNC_PREF_ASK: 817 case SYNC_PREF_ASK:
818 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 818 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
819 if ( lastSync > remoteMod ) 819 if ( lastSync > remoteMod )
820 return 1; 820 return 1;
821 if ( lastSync > localMod ) 821 if ( lastSync > localMod )
822 return 2; 822 return 2;
823 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 823 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
824 localIsNew = localMod >= remoteMod; 824 localIsNew = localMod >= remoteMod;
825 if ( localIsNew ) 825 if ( localIsNew )
826 getEventViewerDialog()->setColorMode( 1 ); 826 getEventViewerDialog()->setColorMode( 1 );
827 else 827 else
828 getEventViewerDialog()->setColorMode( 2 ); 828 getEventViewerDialog()->setColorMode( 2 );
829 getEventViewerDialog()->setIncidence(local); 829 getEventViewerDialog()->setIncidence(local);
830 if ( localIsNew ) 830 if ( localIsNew )
831 getEventViewerDialog()->setColorMode( 2 ); 831 getEventViewerDialog()->setColorMode( 2 );
832 else 832 else
833 getEventViewerDialog()->setColorMode( 1 ); 833 getEventViewerDialog()->setColorMode( 1 );
834 getEventViewerDialog()->addIncidence(remote); 834 getEventViewerDialog()->addIncidence(remote);
835 getEventViewerDialog()->setColorMode( 0 ); 835 getEventViewerDialog()->setColorMode( 0 );
836 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 836 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
837 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 837 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
838 getEventViewerDialog()->showMe(); 838 getEventViewerDialog()->showMe();
839 result = getEventViewerDialog()->executeS( localIsNew ); 839 result = getEventViewerDialog()->executeS( localIsNew );
840 return result; 840 return result;
841 841
842 break; 842 break;
843 case SYNC_PREF_FORCE_LOCAL: 843 case SYNC_PREF_FORCE_LOCAL:
844 return 1; 844 return 1;
845 break; 845 break;
846 case SYNC_PREF_FORCE_REMOTE: 846 case SYNC_PREF_FORCE_REMOTE:
847 return 2; 847 return 2;
848 break; 848 break;
849 849
850 default: 850 default:
851 // SYNC_PREF_TAKE_BOTH not implemented 851 // SYNC_PREF_TAKE_BOTH not implemented
852 break; 852 break;
853 } 853 }
854 return 0; 854 return 0;
855} 855}
856Event* CalendarView::getLastSyncEvent() 856Event* CalendarView::getLastSyncEvent()
857{ 857{
858 Event* lse; 858 Event* lse;
859 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 859 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
860 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 860 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
861 if (!lse) { 861 if (!lse) {
862 lse = new Event(); 862 lse = new Event();
863 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 863 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
864 QString sum = ""; 864 QString sum = "";
865 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 865 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
866 sum = "E: "; 866 sum = "E: ";
867 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 867 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
868 lse->setDtStart( mLastCalendarSync ); 868 lse->setDtStart( mLastCalendarSync );
869 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 869 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
870 lse->setCategories( i18n("SyncEvent") ); 870 lse->setCategories( i18n("SyncEvent") );
871 lse->setReadOnly( true ); 871 lse->setReadOnly( true );
872 mCalendar->addEvent( lse ); 872 mCalendar->addEvent( lse );
873 } 873 }
874 874
875 return lse; 875 return lse;
876 876
877} 877}
878 878
879// we check, if the to delete event has a id for a profile 879// we check, if the to delete event has a id for a profile
880// if yes, we set this id in the profile to delete 880// if yes, we set this id in the profile to delete
881void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 881void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
882{ 882{
883 if ( lastSync.count() == 0 ) { 883 if ( lastSync.count() == 0 ) {
884 //qDebug(" lastSync.count() == 0"); 884 //qDebug(" lastSync.count() == 0");
885 return; 885 return;
886 } 886 }
887 if ( toDelete->type() == "Journal" ) 887 if ( toDelete->type() == "Journal" )
888 return; 888 return;
889 889
890 Event* eve = lastSync.first(); 890 Event* eve = lastSync.first();
891 891
892 while ( eve ) { 892 while ( eve ) {
893 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 893 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
894 if ( !id.isEmpty() ) { 894 if ( !id.isEmpty() ) {
895 QString des = eve->description(); 895 QString des = eve->description();
896 QString pref = "e"; 896 QString pref = "e";
897 if ( toDelete->type() == "Todo" ) 897 if ( toDelete->type() == "Todo" )
898 pref = "t"; 898 pref = "t";
899 des += pref+ id + ","; 899 des += pref+ id + ",";
900 eve->setReadOnly( false ); 900 eve->setReadOnly( false );
901 eve->setDescription( des ); 901 eve->setDescription( des );
902 //qDebug("setdes %s ", des.latin1()); 902 //qDebug("setdes %s ", des.latin1());
903 eve->setReadOnly( true ); 903 eve->setReadOnly( true );
904 } 904 }
905 eve = lastSync.next(); 905 eve = lastSync.next();
906 } 906 }
907 907
908} 908}
909void CalendarView::checkExternalId( Incidence * inc ) 909void CalendarView::checkExternalId( Incidence * inc )
910{ 910{
911 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 911 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
912 checkExternSyncEvent( lastSync, inc ); 912 checkExternSyncEvent( lastSync, inc );
913 913
914} 914}
915bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 915bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
916{ 916{
917 bool syncOK = true; 917 bool syncOK = true;
918 int addedEvent = 0; 918 int addedEvent = 0;
919 int addedEventR = 0; 919 int addedEventR = 0;
920 int deletedEventR = 0; 920 int deletedEventR = 0;
921 int deletedEventL = 0; 921 int deletedEventL = 0;
922 int changedLocal = 0; 922 int changedLocal = 0;
923 int changedRemote = 0; 923 int changedRemote = 0;
924 //QPtrList<Event> el = local->rawEvents(); 924 //QPtrList<Event> el = local->rawEvents();
925 Event* eventR; 925 Event* eventR;
926 QString uid; 926 QString uid;
927 int take; 927 int take;
928 Event* eventL; 928 Event* eventL;
929 Event* eventRSync; 929 Event* eventRSync;
930 Event* eventLSync; 930 Event* eventLSync;
931 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 931 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
932 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 932 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
933 bool fullDateRange = false; 933 bool fullDateRange = false;
934 local->resetTempSyncStat(); 934 local->resetTempSyncStat();
935#ifdef DESKTOP_VERSION
936 //Needed for KDE - OL sync
937 local->resetPilotStat();
938 remote->resetPilotStat();
939#endif
935 mLastCalendarSync = QDateTime::currentDateTime(); 940 mLastCalendarSync = QDateTime::currentDateTime();
936 QDateTime modifiedCalendar = mLastCalendarSync;; 941 QDateTime modifiedCalendar = mLastCalendarSync;;
937 eventLSync = getLastSyncEvent(); 942 eventLSync = getLastSyncEvent();
938 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 943 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
939 if ( eventR ) { 944 if ( eventR ) {
940 eventRSync = (Event*) eventR->clone(); 945 eventRSync = (Event*) eventR->clone();
941 remote->deleteEvent(eventR ); 946 remote->deleteEvent(eventR );
942 947
943 } else { 948 } else {
944 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 949 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
945 eventRSync = (Event*)eventLSync->clone(); 950 eventRSync = (Event*)eventLSync->clone();
946 } else { 951 } else {
947 fullDateRange = true; 952 fullDateRange = true;
948 eventRSync = new Event(); 953 eventRSync = new Event();
949 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 954 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
950 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 955 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
951 eventRSync->setDtStart( mLastCalendarSync ); 956 eventRSync->setDtStart( mLastCalendarSync );
952 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 957 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
953 eventRSync->setCategories( i18n("SyncEvent") ); 958 eventRSync->setCategories( i18n("SyncEvent") );
954 } 959 }
955 } 960 }
956 if ( eventLSync->dtStart() == mLastCalendarSync ) 961 if ( eventLSync->dtStart() == mLastCalendarSync )
957 fullDateRange = true; 962 fullDateRange = true;
958 963
959 if ( ! fullDateRange ) { 964 if ( ! fullDateRange ) {
960 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 965 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
961 966
962 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 967 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
963 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 968 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
964 fullDateRange = true; 969 fullDateRange = true;
965 } 970 }
966 } 971 }
967 if ( fullDateRange ) 972 if ( fullDateRange )
968 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 973 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
969 else 974 else
970 mLastCalendarSync = eventLSync->dtStart(); 975 mLastCalendarSync = eventLSync->dtStart();
971 // for resyncing if own file has changed 976 // for resyncing if own file has changed
972 if ( mCurrentSyncDevice == "deleteaftersync" ) { 977 if ( mCurrentSyncDevice == "deleteaftersync" ) {
973 mLastCalendarSync = loadedFileVersion; 978 mLastCalendarSync = loadedFileVersion;
974 qDebug("setting mLastCalendarSync "); 979 qDebug("setting mLastCalendarSync ");
975 } 980 }
976 //qDebug("*************************** "); 981 //qDebug("*************************** ");
977 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); 982 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() );
978 QPtrList<Incidence> er = remote->rawIncidences(); 983 QPtrList<Incidence> er = remote->rawIncidences();
979 Incidence* inR = er.first(); 984 Incidence* inR = er.first();
980 Incidence* inL; 985 Incidence* inL;
981 QProgressBar bar( er.count(),0 ); 986 QProgressBar bar( er.count(),0 );
982 bar.setCaption (i18n("Syncing - close to abort!") ); 987 bar.setCaption (i18n("Syncing - close to abort!") );
983 988
984 int w = 300; 989 int w = 300;
985 if ( QApplication::desktop()->width() < 320 ) 990 if ( QApplication::desktop()->width() < 320 )
986 w = 220; 991 w = 220;
987 int h = bar.sizeHint().height() ; 992 int h = bar.sizeHint().height() ;
988 int dw = QApplication::desktop()->width(); 993 int dw = QApplication::desktop()->width();
989 int dh = QApplication::desktop()->height(); 994 int dh = QApplication::desktop()->height();
990 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 995 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
991 bar.show(); 996 bar.show();
992 int modulo = (er.count()/10)+1; 997 int modulo = (er.count()/10)+1;
993 int incCounter = 0; 998 int incCounter = 0;
994 while ( inR ) { 999 while ( inR ) {
995 if ( ! bar.isVisible() ) 1000 if ( ! bar.isVisible() )
996 return false; 1001 return false;
997 if ( incCounter % modulo == 0 ) 1002 if ( incCounter % modulo == 0 )
998 bar.setProgress( incCounter ); 1003 bar.setProgress( incCounter );
999 ++incCounter; 1004 ++incCounter;
1000 uid = inR->uid(); 1005 uid = inR->uid();
1001 bool skipIncidence = false; 1006 bool skipIncidence = false;
1002 if ( uid.left(15) == QString("last-syncEvent-") ) 1007 if ( uid.left(15) == QString("last-syncEvent-") )
1003 skipIncidence = true; 1008 skipIncidence = true;
1004 QString idS; 1009 QString idS;
1005 qApp->processEvents(); 1010 qApp->processEvents();
1006 if ( !skipIncidence ) { 1011 if ( !skipIncidence ) {
1007 inL = local->incidence( uid ); 1012 inL = local->incidence( uid );
1008 if ( inL ) { // maybe conflict - same uid in both calendars 1013 if ( inL ) { // maybe conflict - same uid in both calendars
1009 int maxrev = inL->revision(); 1014 int maxrev = inL->revision();
1010 if ( maxrev < inR->revision() ) 1015 if ( maxrev < inR->revision() )
1011 maxrev = inR->revision(); 1016 maxrev = inR->revision();
1012 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1017 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1013 //qDebug("take %d %s ", take, inL->summary().latin1()); 1018 //qDebug("take %d %s ", take, inL->summary().latin1());
1014 if ( take == 3 ) 1019 if ( take == 3 )
1015 return false; 1020 return false;
1016 if ( take == 1 ) {// take local 1021 if ( take == 1 ) {// take local
1017 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1022 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1018 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1023 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1019 else 1024 else
1020 idS = inR->IDStr(); 1025 idS = inR->IDStr();
1021 remote->deleteIncidence( inR ); 1026 remote->deleteIncidence( inR );
1022 if ( inL->revision() < maxrev ) 1027 if ( inL->revision() < maxrev )
1023 inL->setRevision( maxrev ); 1028 inL->setRevision( maxrev );
1024 inR = inL->clone(); 1029 inR = inL->clone();
1025 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1030 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1026 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1031 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1027 inR->setIDStr( idS ); 1032 inR->setIDStr( idS );
1028 remote->addIncidence( inR ); 1033 remote->addIncidence( inR );
1034#ifdef DESKTOP_VERSION
1035 inR->setPilotId( 1 );
1036#endif
1029 ++changedRemote; 1037 ++changedRemote;
1030 } else { 1038 } else {
1031 if ( inR->revision() < maxrev ) 1039 if ( inR->revision() < maxrev )
1032 inR->setRevision( maxrev ); 1040 inR->setRevision( maxrev );
1033 idS = inL->IDStr(); 1041 idS = inL->IDStr();
1034 local->deleteIncidence( inL ); 1042 local->deleteIncidence( inL );
1035 inL = inR->clone(); 1043 inL = inR->clone();
1036 inL->setIDStr( idS ); 1044 inL->setIDStr( idS );
1037 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1045 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1038 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1046 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1039 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1047 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1040 } 1048 }
1041 local->addIncidence( inL ); 1049 local->addIncidence( inL );
1042 ++changedLocal; 1050 ++changedLocal;
1043 } 1051 }
1044 } 1052 }
1045 } else { // no conflict 1053 } else { // no conflict
1046 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1054 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1047 QString des = eventLSync->description(); 1055 QString des = eventLSync->description();
1048 QString pref = "e"; 1056 QString pref = "e";
1049 if ( inR->type() == "Todo" ) 1057 if ( inR->type() == "Todo" )
1050 pref = "t"; 1058 pref = "t";
1051 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1059 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1052 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1060 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1053 //remote->deleteIncidence( inR ); 1061 //remote->deleteIncidence( inR );
1054 ++deletedEventR; 1062 ++deletedEventR;
1055 } else { 1063 } else {
1056 inR->setLastModified( modifiedCalendar ); 1064 inR->setLastModified( modifiedCalendar );
1057 inL = inR->clone(); 1065 inL = inR->clone();
1058 local->addIncidence( inL ); 1066 local->addIncidence( inL );
1059 ++addedEvent; 1067 ++addedEvent;
1060 } 1068 }
1061 } else { 1069 } else {
1062 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1070 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1063 inR->setLastModified( modifiedCalendar ); 1071 inR->setLastModified( modifiedCalendar );
1064 local->addIncidence( inR->clone() ); 1072 local->addIncidence( inR->clone() );
1065 ++addedEvent; 1073 ++addedEvent;
1066 } else { 1074 } else {
1067 checkExternSyncEvent(eventRSyncSharp, inR); 1075 checkExternSyncEvent(eventRSyncSharp, inR);
1068 remote->deleteIncidence( inR ); 1076 remote->deleteIncidence( inR );
1069 ++deletedEventR; 1077 ++deletedEventR;
1070 } 1078 }
1071 } 1079 }
1072 } 1080 }
1073 } 1081 }
1074 inR = er.next(); 1082 inR = er.next();
1075 } 1083 }
1076 QPtrList<Incidence> el = local->rawIncidences(); 1084 QPtrList<Incidence> el = local->rawIncidences();
1077 inL = el.first(); 1085 inL = el.first();
1078 modulo = (el.count()/10)+1; 1086 modulo = (el.count()/10)+1;
1079 bar.setCaption (i18n("Add / remove events") ); 1087 bar.setCaption (i18n("Add / remove events") );
1080 bar.setTotalSteps ( el.count() ) ; 1088 bar.setTotalSteps ( el.count() ) ;
1081 bar.show(); 1089 bar.show();
1082 incCounter = 0; 1090 incCounter = 0;
1083 1091
1084 while ( inL ) { 1092 while ( inL ) {
1085 1093
1086 qApp->processEvents(); 1094 qApp->processEvents();
1087 if ( ! bar.isVisible() ) 1095 if ( ! bar.isVisible() )
1088 return false; 1096 return false;
1089 if ( incCounter % modulo == 0 ) 1097 if ( incCounter % modulo == 0 )
1090 bar.setProgress( incCounter ); 1098 bar.setProgress( incCounter );
1091 ++incCounter; 1099 ++incCounter;
1092 uid = inL->uid(); 1100 uid = inL->uid();
1093 bool skipIncidence = false; 1101 bool skipIncidence = false;
1094 if ( uid.left(15) == QString("last-syncEvent-") ) 1102 if ( uid.left(15) == QString("last-syncEvent-") )
1095 skipIncidence = true; 1103 skipIncidence = true;
1096 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1104 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1097 skipIncidence = true; 1105 skipIncidence = true;
1098 if ( !skipIncidence ) { 1106 if ( !skipIncidence ) {
1099 inR = remote->incidence( uid ); 1107 inR = remote->incidence( uid );
1100 if ( ! inR ) { 1108 if ( ! inR ) {
1101 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1109 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1102 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1110 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1103 checkExternSyncEvent(eventLSyncSharp, inL); 1111 checkExternSyncEvent(eventLSyncSharp, inL);
1104 local->deleteIncidence( inL ); 1112 local->deleteIncidence( inL );
1105 ++deletedEventL; 1113 ++deletedEventL;
1106 } else { 1114 } else {
1107 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1115 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1108 inL->removeID(mCurrentSyncDevice ); 1116 inL->removeID(mCurrentSyncDevice );
1109 ++addedEventR; 1117 ++addedEventR;
1110 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1118 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1111 inL->setLastModified( modifiedCalendar ); 1119 inL->setLastModified( modifiedCalendar );
1112 inR = inL->clone(); 1120 inR = inL->clone();
1113 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1121 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1114 remote->addIncidence( inR ); 1122 remote->addIncidence( inR );
1115 } 1123 }
1116 } 1124 }
1117 } else { 1125 } else {
1118 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1126 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1119 checkExternSyncEvent(eventLSyncSharp, inL); 1127 checkExternSyncEvent(eventLSyncSharp, inL);
1120 local->deleteIncidence( inL ); 1128 local->deleteIncidence( inL );
1121 ++deletedEventL; 1129 ++deletedEventL;
1122 } else { 1130 } else {
1123 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1131 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1124 ++addedEventR; 1132 ++addedEventR;
1125 inL->setLastModified( modifiedCalendar ); 1133 inL->setLastModified( modifiedCalendar );
1126 remote->addIncidence( inL->clone() ); 1134 remote->addIncidence( inL->clone() );
1127 } 1135 }
1128 } 1136 }
1129 } 1137 }
1130 } 1138 }
1131 } 1139 }
1132 inL = el.next(); 1140 inL = el.next();
1133 } 1141 }
1134 int delFut = 0; 1142 int delFut = 0;
1135 int remRem = 0; 1143 int remRem = 0;
1136 if ( mSyncManager->mWriteBackInFuture ) { 1144 if ( mSyncManager->mWriteBackInFuture ) {
1137 er = remote->rawIncidences(); 1145 er = remote->rawIncidences();
1138 remRem = er.count(); 1146 remRem = er.count();
1139 inR = er.first(); 1147 inR = er.first();
1140 QDateTime dt; 1148 QDateTime dt;
1141 QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); 1149 QDateTime cur = QDateTime::currentDateTime().addDays( -7 );
1142 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 ); 1150 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 );
1143 while ( inR ) { 1151 while ( inR ) {
1144 if ( inR->type() == "Todo" ) { 1152 if ( inR->type() == "Todo" ) {
1145 Todo * t = (Todo*)inR; 1153 Todo * t = (Todo*)inR;
1146 if ( t->hasDueDate() ) 1154 if ( t->hasDueDate() )
1147 dt = t->dtDue(); 1155 dt = t->dtDue();
1148 else 1156 else
1149 dt = cur.addSecs( 62 ); 1157 dt = cur.addSecs( 62 );
1150 } 1158 }
1151 else if (inR->type() == "Event" ) { 1159 else if (inR->type() == "Event" ) {
1152 bool ok; 1160 bool ok;
1153 dt = inR->getNextOccurence( cur, &ok ); 1161 dt = inR->getNextOccurence( cur, &ok );
1154 if ( !ok ) 1162 if ( !ok )
1155 dt = cur.addSecs( -62 ); 1163 dt = cur.addSecs( -62 );
1156 } 1164 }
1157 else 1165 else
1158 dt = inR->dtStart(); 1166 dt = inR->dtStart();
1159 if ( dt < cur || dt > end ) { 1167 if ( dt < cur || dt > end ) {
1160 remote->deleteIncidence( inR ); 1168 remote->deleteIncidence( inR );
1161 ++delFut; 1169 ++delFut;
1162 } 1170 }
1163 inR = er.next(); 1171 inR = er.next();
1164 } 1172 }
1165 } 1173 }
1166 bar.hide(); 1174 bar.hide();
1167 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1175 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1168 eventLSync->setReadOnly( false ); 1176 eventLSync->setReadOnly( false );
1169 eventLSync->setDtStart( mLastCalendarSync ); 1177 eventLSync->setDtStart( mLastCalendarSync );
1170 eventRSync->setDtStart( mLastCalendarSync ); 1178 eventRSync->setDtStart( mLastCalendarSync );
1171 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1179 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1172 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1180 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1173 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1181 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1174 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1182 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1175 eventLSync->setReadOnly( true ); 1183 eventLSync->setReadOnly( true );
1176 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 1184 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
1177 remote->addEvent( eventRSync ); 1185 remote->addEvent( eventRSync );
1178 QString mes; 1186 QString mes;
1179 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"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR ); 1187 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"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR );
1180 QString delmess; 1188 QString delmess;
1181 if ( delFut ) { 1189 if ( delFut ) {
1182 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInFuture, remRem-delFut); 1190 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInFuture, remRem-delFut);
1183 mes += delmess; 1191 mes += delmess;
1184 } 1192 }
1185 if ( mSyncManager->mShowSyncSummary ) { 1193 if ( mSyncManager->mShowSyncSummary ) {
1186 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1194 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1187 } 1195 }
1188 qDebug( mes ); 1196 qDebug( mes );
1189 mCalendar->checkAlarmForIncidence( 0, true ); 1197 mCalendar->checkAlarmForIncidence( 0, true );
1190 return syncOK; 1198 return syncOK;
1191} 1199}
1192 1200
1193void CalendarView::setSyncDevice( QString s ) 1201void CalendarView::setSyncDevice( QString s )
1194{ 1202{
1195 mCurrentSyncDevice= s; 1203 mCurrentSyncDevice= s;
1196} 1204}
1197void CalendarView::setSyncName( QString s ) 1205void CalendarView::setSyncName( QString s )
1198{ 1206{
1199 mCurrentSyncName= s; 1207 mCurrentSyncName= s;
1200} 1208}
1201bool CalendarView::syncCalendar(QString filename, int mode) 1209bool CalendarView::syncCalendar(QString filename, int mode)
1202{ 1210{
1203 //qDebug("syncCalendar %s ", filename.latin1()); 1211 //qDebug("syncCalendar %s ", filename.latin1());
1204 mGlobalSyncMode = SYNC_MODE_NORMAL; 1212 mGlobalSyncMode = SYNC_MODE_NORMAL;
1205 CalendarLocal* calendar = new CalendarLocal(); 1213 CalendarLocal* calendar = new CalendarLocal();
1206 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1214 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1207 FileStorage* storage = new FileStorage( calendar ); 1215 FileStorage* storage = new FileStorage( calendar );
1208 bool syncOK = false; 1216 bool syncOK = false;
1209 storage->setFileName( filename ); 1217 storage->setFileName( filename );
1210 // qDebug("loading ... "); 1218 // qDebug("loading ... ");
1211 if ( storage->load() ) { 1219 if ( storage->load() ) {
1212 getEventViewerDialog()->setSyncMode( true ); 1220 getEventViewerDialog()->setSyncMode( true );
1213 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1221 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1214 getEventViewerDialog()->setSyncMode( false ); 1222 getEventViewerDialog()->setSyncMode( false );
1215 if ( syncOK ) { 1223 if ( syncOK ) {
1216 if ( mSyncManager->mWriteBackFile ) 1224 if ( mSyncManager->mWriteBackFile )
1217 { 1225 {
1218 storage->setSaveFormat( new ICalFormat() ); 1226 storage->setSaveFormat( new ICalFormat() );
1219 storage->save(); 1227 storage->save();
1220 } 1228 }
1221 } 1229 }
1222 setModified( true ); 1230 setModified( true );
1223 } 1231 }
1224 delete storage; 1232 delete storage;
1225 delete calendar; 1233 delete calendar;
1226 if ( syncOK ) 1234 if ( syncOK )
1227 updateView(); 1235 updateView();
1228 return syncOK; 1236 return syncOK;
1229} 1237}
1230 1238
1231void CalendarView::syncExternal( int mode ) 1239void CalendarView::syncExternal( int mode )
1232{ 1240{
1233 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1241 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1234 1242
1235 qApp->processEvents(); 1243 qApp->processEvents();
1236 CalendarLocal* calendar = new CalendarLocal(); 1244 CalendarLocal* calendar = new CalendarLocal();
1237 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1245 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1238 bool syncOK = false; 1246 bool syncOK = false;
1239 bool loadSuccess = false; 1247 bool loadSuccess = false;
1240 PhoneFormat* phoneFormat = 0; 1248 PhoneFormat* phoneFormat = 0;
1241#ifndef DESKTOP_VERSION 1249#ifndef DESKTOP_VERSION
1242 SharpFormat* sharpFormat = 0; 1250 SharpFormat* sharpFormat = 0;
1243 if ( mode == 0 ) { // sharp 1251 if ( mode == 0 ) { // sharp
1244 sharpFormat = new SharpFormat () ; 1252 sharpFormat = new SharpFormat () ;
1245 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1253 loadSuccess = sharpFormat->load( calendar, mCalendar );
1246 1254
1247 } else 1255 } else
1248#endif 1256#endif
1249 if ( mode == 1 ) { // phone 1257 if ( mode == 1 ) { // phone
1250 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1258 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1251 mSyncManager->mPhoneDevice, 1259 mSyncManager->mPhoneDevice,
1252 mSyncManager->mPhoneConnection, 1260 mSyncManager->mPhoneConnection,
1253 mSyncManager->mPhoneModel); 1261 mSyncManager->mPhoneModel);
1254 loadSuccess = phoneFormat->load( calendar,mCalendar); 1262 loadSuccess = phoneFormat->load( calendar,mCalendar);
1255 1263
1256 } else 1264 } else
1257 return; 1265 return;
1258 if ( loadSuccess ) { 1266 if ( loadSuccess ) {
1259 getEventViewerDialog()->setSyncMode( true ); 1267 getEventViewerDialog()->setSyncMode( true );
1260 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1268 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1261 getEventViewerDialog()->setSyncMode( false ); 1269 getEventViewerDialog()->setSyncMode( false );
1262 qApp->processEvents(); 1270 qApp->processEvents();
1263 if ( syncOK ) { 1271 if ( syncOK ) {
1264 if ( mSyncManager->mWriteBackFile ) 1272 if ( mSyncManager->mWriteBackFile )
1265 { 1273 {
1266 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1274 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1267 Incidence* inc = iL.first(); 1275 Incidence* inc = iL.first();
1268 if ( phoneFormat ) { 1276 if ( phoneFormat ) {
1269 while ( inc ) { 1277 while ( inc ) {
1270 inc->removeID(mCurrentSyncDevice); 1278 inc->removeID(mCurrentSyncDevice);
1271 inc = iL.next(); 1279 inc = iL.next();
1272 } 1280 }
1273 } 1281 }
1274#ifndef DESKTOP_VERSION 1282#ifndef DESKTOP_VERSION
1275 if ( sharpFormat ) 1283 if ( sharpFormat )
1276 sharpFormat->save(calendar); 1284 sharpFormat->save(calendar);
1277#endif 1285#endif
1278 if ( phoneFormat ) 1286 if ( phoneFormat )
1279 phoneFormat->save(calendar); 1287 phoneFormat->save(calendar);
1280 iL = calendar->rawIncidences(); 1288 iL = calendar->rawIncidences();
1281 inc = iL.first(); 1289 inc = iL.first();
1282 Incidence* loc; 1290 Incidence* loc;
1283 while ( inc ) { 1291 while ( inc ) {
1284 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1292 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1285 loc = mCalendar->incidence(inc->uid() ); 1293 loc = mCalendar->incidence(inc->uid() );
1286 if ( loc ) { 1294 if ( loc ) {
1287 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1295 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1288 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1296 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1289 } 1297 }
1290 } 1298 }
1291 inc = iL.next(); 1299 inc = iL.next();
1292 } 1300 }
1293 Incidence* lse = getLastSyncEvent(); 1301 Incidence* lse = getLastSyncEvent();
1294 if ( lse ) { 1302 if ( lse ) {
1295 lse->setReadOnly( false ); 1303 lse->setReadOnly( false );
1296 lse->setDescription( "" ); 1304 lse->setDescription( "" );
1297 lse->setReadOnly( true ); 1305 lse->setReadOnly( true );
1298 } 1306 }
1299 } 1307 }
1300 } 1308 }
1301 setModified( true ); 1309 setModified( true );
1302 } else { 1310 } else {
1303 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1311 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1304 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1312 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1305 question, i18n("Ok")) ; 1313 question, i18n("Ok")) ;
1306 1314
1307 } 1315 }
1308 delete calendar; 1316 delete calendar;
1309 updateView(); 1317 updateView();
1310 return ;//syncOK; 1318 return ;//syncOK;
1311 1319
1312} 1320}
1313 1321
1314bool CalendarView::importBday() 1322bool CalendarView::importBday()
1315{ 1323{
1316#ifndef KORG_NOKABC 1324#ifndef KORG_NOKABC
1317 1325
1318#ifdef DESKTOP_VERSION 1326#ifdef DESKTOP_VERSION
1319 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1327 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1320 KABC::AddressBook::Iterator it; 1328 KABC::AddressBook::Iterator it;
1321 int count = 0; 1329 int count = 0;
1322 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1330 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1323 ++count; 1331 ++count;
1324 } 1332 }
1325 QProgressBar bar(count,0 ); 1333 QProgressBar bar(count,0 );
1326 int w = 300; 1334 int w = 300;
1327 if ( QApplication::desktop()->width() < 320 ) 1335 if ( QApplication::desktop()->width() < 320 )
1328 w = 220; 1336 w = 220;
1329 int h = bar.sizeHint().height() ; 1337 int h = bar.sizeHint().height() ;
1330 int dw = QApplication::desktop()->width(); 1338 int dw = QApplication::desktop()->width();
1331 int dh = QApplication::desktop()->height(); 1339 int dh = QApplication::desktop()->height();
1332 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1340 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1333 bar.show(); 1341 bar.show();
1334 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1342 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1335 qApp->processEvents(); 1343 qApp->processEvents();
1336 count = 0; 1344 count = 0;
1337 int addCount = 0; 1345 int addCount = 0;
1338 KCal::Attendee* a = 0; 1346 KCal::Attendee* a = 0;
1339 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1347 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1340 if ( ! bar.isVisible() ) 1348 if ( ! bar.isVisible() )
1341 return false; 1349 return false;
1342 bar.setProgress( count++ ); 1350 bar.setProgress( count++ );
1343 qApp->processEvents(); 1351 qApp->processEvents();
1344 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1352 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1345 if ( (*it).birthday().date().isValid() ){ 1353 if ( (*it).birthday().date().isValid() ){
1346 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1354 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1347 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1355 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1348 ++addCount; 1356 ++addCount;
1349 } 1357 }
1350 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1358 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1351 if ( anni.isValid() ){ 1359 if ( anni.isValid() ){
1352 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1360 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1353 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1361 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1354 ++addCount; 1362 ++addCount;
1355 } 1363 }
1356 } 1364 }
1357 updateView(); 1365 updateView();
1358 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1366 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1359#else //DESKTOP_VERSION 1367#else //DESKTOP_VERSION
1360 1368
1361 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1369 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1362 // the result should now arrive through method insertBirthdays 1370 // the result should now arrive through method insertBirthdays
1363 1371
1364#endif //DESKTOP_VERSION 1372#endif //DESKTOP_VERSION
1365 1373
1366#endif //KORG_NOKABC 1374#endif //KORG_NOKABC
1367 1375
1368 1376
1369 return true; 1377 return true;
1370} 1378}
1371 1379
1372// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1380// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1373void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1381void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1374 const QStringList& anniversaryList, const QStringList& realNameList, 1382 const QStringList& anniversaryList, const QStringList& realNameList,
1375 const QStringList& emailList, const QStringList& assembledNameList, 1383 const QStringList& emailList, const QStringList& assembledNameList,
1376 const QStringList& uidList) 1384 const QStringList& uidList)
1377{ 1385{
1378 qDebug("CalendarView::insertBirthdays"); 1386 qDebug("CalendarView::insertBirthdays");
1379 if (uid == this->name()) 1387 if (uid == this->name())
1380 { 1388 {
1381 int count = birthdayList.count(); 1389 int count = birthdayList.count();
1382 int addCount = 0; 1390 int addCount = 0;
1383 KCal::Attendee* a = 0; 1391 KCal::Attendee* a = 0;
1384 1392
1385 qDebug("CalView 1 %i", count); 1393 qDebug("CalView 1 %i", count);
1386 1394
1387 QProgressBar bar(count,0 ); 1395 QProgressBar bar(count,0 );
1388 int w = 300; 1396 int w = 300;
1389 if ( QApplication::desktop()->width() < 320 ) 1397 if ( QApplication::desktop()->width() < 320 )
1390 w = 220; 1398 w = 220;
1391 int h = bar.sizeHint().height() ; 1399 int h = bar.sizeHint().height() ;
1392 int dw = QApplication::desktop()->width(); 1400 int dw = QApplication::desktop()->width();
1393 int dh = QApplication::desktop()->height(); 1401 int dh = QApplication::desktop()->height();
1394 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1402 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1395 bar.show(); 1403 bar.show();
1396 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1404 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1397 qApp->processEvents(); 1405 qApp->processEvents();
1398 1406
1399 QDate birthday; 1407 QDate birthday;
1400 QDate anniversary; 1408 QDate anniversary;
1401 QString realName; 1409 QString realName;
1402 QString email; 1410 QString email;
1403 QString assembledName; 1411 QString assembledName;
1404 QString uid; 1412 QString uid;
1405 bool ok = true; 1413 bool ok = true;
1406 for ( int i = 0; i < count; i++) 1414 for ( int i = 0; i < count; i++)
1407 { 1415 {
1408 if ( ! bar.isVisible() ) 1416 if ( ! bar.isVisible() )
1409 return; 1417 return;
1410 bar.setProgress( i ); 1418 bar.setProgress( i );
1411 qApp->processEvents(); 1419 qApp->processEvents();
1412 1420
1413 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1421 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1414 if (!ok) { 1422 if (!ok) {
1415 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1423 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1416 } 1424 }
1417 1425
1418 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1426 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1419 if (!ok) { 1427 if (!ok) {
1420 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1428 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1421 } 1429 }
1422 realName = realNameList[i]; 1430 realName = realNameList[i];
1423 email = emailList[i]; 1431 email = emailList[i];
1424 assembledName = assembledNameList[i]; 1432 assembledName = assembledNameList[i];
1425 uid = uidList[i]; 1433 uid = uidList[i];
1426 //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() ); 1434 //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() );
1427 1435
1428 if ( birthday.isValid() ){ 1436 if ( birthday.isValid() ){
1429 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1437 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1430 KCal::Attendee::ReqParticipant,uid) ; 1438 KCal::Attendee::ReqParticipant,uid) ;
1431 if ( addAnniversary( birthday, assembledName, a, true ) ) 1439 if ( addAnniversary( birthday, assembledName, a, true ) )
1432 ++addCount; 1440 ++addCount;
1433 } 1441 }
1434 1442
1435 if ( anniversary.isValid() ){ 1443 if ( anniversary.isValid() ){
1436 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1444 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1437 KCal::Attendee::ReqParticipant,uid) ; 1445 KCal::Attendee::ReqParticipant,uid) ;
1438 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1446 if ( addAnniversary( anniversary, assembledName, a, false ) )
1439 ++addCount; 1447 ++addCount;
1440 } 1448 }
1441 } 1449 }
1442 1450
1443 updateView(); 1451 updateView();
1444 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1452 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1445 1453
1446 } 1454 }
1447 1455
1448} 1456}
1449 1457
1450 1458
1451 1459
1452bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1460bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1453{ 1461{
1454 //qDebug("addAnni "); 1462 //qDebug("addAnni ");
1455 Event * ev = new Event(); 1463 Event * ev = new Event();
1456 if ( a ) { 1464 if ( a ) {
1457 ev->addAttendee( a ); 1465 ev->addAttendee( a );
1458 } 1466 }
1459 QString kind; 1467 QString kind;
1460 if ( birthday ) 1468 if ( birthday )
1461 kind = i18n( "Birthday" ); 1469 kind = i18n( "Birthday" );
1462 else 1470 else
1463 kind = i18n( "Anniversary" ); 1471 kind = i18n( "Anniversary" );
1464 ev->setSummary( name + " - " + kind ); 1472 ev->setSummary( name + " - " + kind );
1465 ev->setOrganizer( "nobody@nowhere" ); 1473 ev->setOrganizer( "nobody@nowhere" );
1466 ev->setCategories( kind ); 1474 ev->setCategories( kind );
1467 ev->setDtStart( QDateTime(date) ); 1475 ev->setDtStart( QDateTime(date) );
1468 ev->setDtEnd( QDateTime(date) ); 1476 ev->setDtEnd( QDateTime(date) );
1469 ev->setFloats( true ); 1477 ev->setFloats( true );
1470 Recurrence * rec = ev->recurrence(); 1478 Recurrence * rec = ev->recurrence();
1471 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1479 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1472 rec->addYearlyNum( date.month() ); 1480 rec->addYearlyNum( date.month() );
1473 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1481 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1474 delete ev; 1482 delete ev;
1475 return false; 1483 return false;
1476 } 1484 }
1477 return true; 1485 return true;
1478 1486
1479} 1487}
1480bool CalendarView::importQtopia( const QString &categories, 1488bool CalendarView::importQtopia( const QString &categories,
1481 const QString &datebook, 1489 const QString &datebook,
1482 const QString &todolist ) 1490 const QString &todolist )
1483{ 1491{
1484 1492
1485 QtopiaFormat qtopiaFormat; 1493 QtopiaFormat qtopiaFormat;
1486 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1494 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1487 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1495 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1488 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1496 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1489 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1497 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1490 1498
1491 updateView(); 1499 updateView();
1492 return true; 1500 return true;
1493 1501
1494#if 0 1502#if 0
1495 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1503 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1496 mCurrentSyncDevice = "qtopia-XML"; 1504 mCurrentSyncDevice = "qtopia-XML";
1497 if ( mSyncManager->mAskForPreferences ) 1505 if ( mSyncManager->mAskForPreferences )
1498 edit_sync_options(); 1506 edit_sync_options();
1499 qApp->processEvents(); 1507 qApp->processEvents();
1500 CalendarLocal* calendar = new CalendarLocal(); 1508 CalendarLocal* calendar = new CalendarLocal();
1501 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1509 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1502 bool syncOK = false; 1510 bool syncOK = false;
1503 QtopiaFormat qtopiaFormat; 1511 QtopiaFormat qtopiaFormat;
1504 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1512 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1505 bool loadOk = true; 1513 bool loadOk = true;
1506 if ( !categories.isEmpty() ) 1514 if ( !categories.isEmpty() )
1507 loadOk = qtopiaFormat.load( calendar, categories ); 1515 loadOk = qtopiaFormat.load( calendar, categories );
1508 if ( loadOk && !datebook.isEmpty() ) 1516 if ( loadOk && !datebook.isEmpty() )
1509 loadOk = qtopiaFormat.load( calendar, datebook ); 1517 loadOk = qtopiaFormat.load( calendar, datebook );
1510 if ( loadOk && !todolist.isEmpty() ) 1518 if ( loadOk && !todolist.isEmpty() )
1511 loadOk = qtopiaFormat.load( calendar, todolist ); 1519 loadOk = qtopiaFormat.load( calendar, todolist );
1512 1520
1513 if ( loadOk ) { 1521 if ( loadOk ) {
1514 getEventViewerDialog()->setSyncMode( true ); 1522 getEventViewerDialog()->setSyncMode( true );
1515 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1523 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1516 getEventViewerDialog()->setSyncMode( false ); 1524 getEventViewerDialog()->setSyncMode( false );
1517 qApp->processEvents(); 1525 qApp->processEvents();
1518 if ( syncOK ) { 1526 if ( syncOK ) {
1519 if ( mSyncManager->mWriteBackFile ) 1527 if ( mSyncManager->mWriteBackFile )
1520 { 1528 {
1521 // write back XML file 1529 // write back XML file
1522 1530
1523 } 1531 }
1524 setModified( true ); 1532 setModified( true );
1525 } 1533 }
1526 } else { 1534 } else {
1527 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1535 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1528 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1536 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1529 question, i18n("Ok")) ; 1537 question, i18n("Ok")) ;
1530 } 1538 }
1531 delete calendar; 1539 delete calendar;
1532 updateView(); 1540 updateView();
1533 return syncOK; 1541 return syncOK;
1534 1542
1535 1543
1536#endif 1544#endif
1537 1545
1538} 1546}
1539 1547
1540void CalendarView::setSyncEventsReadOnly() 1548void CalendarView::setSyncEventsReadOnly()
1541{ 1549{
1542 Event * ev; 1550 Event * ev;
1543 QPtrList<Event> eL = mCalendar->rawEvents(); 1551 QPtrList<Event> eL = mCalendar->rawEvents();
1544 ev = eL.first(); 1552 ev = eL.first();
1545 while ( ev ) { 1553 while ( ev ) {
1546 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1554 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1547 ev->setReadOnly( true ); 1555 ev->setReadOnly( true );
1548 ev = eL.next(); 1556 ev = eL.next();
1549 } 1557 }
1550} 1558}
1551bool CalendarView::openCalendar(QString filename, bool merge) 1559bool CalendarView::openCalendar(QString filename, bool merge)
1552{ 1560{
1553 1561
1554 if (filename.isEmpty()) { 1562 if (filename.isEmpty()) {
1555 return false; 1563 return false;
1556 } 1564 }
1557 1565
1558 if (!QFile::exists(filename)) { 1566 if (!QFile::exists(filename)) {
1559 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1567 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1560 return false; 1568 return false;
1561 } 1569 }
1562 1570
1563 globalFlagBlockAgenda = 1; 1571 globalFlagBlockAgenda = 1;
1564 if (!merge) mCalendar->close(); 1572 if (!merge) mCalendar->close();
1565 1573
1566 mStorage->setFileName( filename ); 1574 mStorage->setFileName( filename );
1567 1575
1568 if ( mStorage->load() ) { 1576 if ( mStorage->load() ) {
1569 if ( merge ) ;//setModified( true ); 1577 if ( merge ) ;//setModified( true );
1570 else { 1578 else {
1571 //setModified( true ); 1579 //setModified( true );
1572 mViewManager->setDocumentId( filename ); 1580 mViewManager->setDocumentId( filename );
1573 mDialogManager->setDocumentId( filename ); 1581 mDialogManager->setDocumentId( filename );
1574 mTodoList->setDocumentId( filename ); 1582 mTodoList->setDocumentId( filename );
1575 } 1583 }
1576 globalFlagBlockAgenda = 2; 1584 globalFlagBlockAgenda = 2;
1577 // if ( getLastSyncEvent() ) 1585 // if ( getLastSyncEvent() )
1578 // getLastSyncEvent()->setReadOnly( true ); 1586 // getLastSyncEvent()->setReadOnly( true );
1579 mCalendar->reInitAlarmSettings(); 1587 mCalendar->reInitAlarmSettings();
1580 setSyncEventsReadOnly(); 1588 setSyncEventsReadOnly();
1581 updateUnmanagedViews(); 1589 updateUnmanagedViews();
1582 updateView(); 1590 updateView();
1583 if ( filename != MainWindow::defaultFileName() ) { 1591 if ( filename != MainWindow::defaultFileName() ) {
1584 saveCalendar( MainWindow::defaultFileName() ); 1592 saveCalendar( MainWindow::defaultFileName() );
1585 } else { 1593 } else {
1586 QFileInfo finf ( MainWindow::defaultFileName()); 1594 QFileInfo finf ( MainWindow::defaultFileName());
1587 if ( finf.exists() ) { 1595 if ( finf.exists() ) {
1588 setLoadedFileVersion( finf.lastModified () ); 1596 setLoadedFileVersion( finf.lastModified () );
1589 } 1597 }
1590 } 1598 }
1591 return true; 1599 return true;
1592 } else { 1600 } else {
1593 // while failing to load, the calendar object could 1601 // while failing to load, the calendar object could
1594 // have become partially populated. Clear it out. 1602 // have become partially populated. Clear it out.
1595 if ( !merge ) { 1603 if ( !merge ) {
1596 mCalendar->close(); 1604 mCalendar->close();
1597 mViewManager->setDocumentId( filename ); 1605 mViewManager->setDocumentId( filename );
1598 mDialogManager->setDocumentId( filename ); 1606 mDialogManager->setDocumentId( filename );
1599 mTodoList->setDocumentId( filename ); 1607 mTodoList->setDocumentId( filename );
1600 } 1608 }
1601 1609
1602 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1610 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1603 1611
1604 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 1612 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
1605 globalFlagBlockAgenda = 2; 1613 globalFlagBlockAgenda = 2;
1606 mCalendar->reInitAlarmSettings(); 1614 mCalendar->reInitAlarmSettings();
1607 setSyncEventsReadOnly(); 1615 setSyncEventsReadOnly();
1608 updateUnmanagedViews(); 1616 updateUnmanagedViews();
1609 updateView(); 1617 updateView();
1610 } 1618 }
1611 return false; 1619 return false;
1612} 1620}
1613void CalendarView::showOpenError() 1621void CalendarView::showOpenError()
1614{ 1622{
1615 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 1623 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
1616} 1624}
1617void CalendarView::setLoadedFileVersion(QDateTime dt) 1625void CalendarView::setLoadedFileVersion(QDateTime dt)
1618{ 1626{
1619 loadedFileVersion = dt; 1627 loadedFileVersion = dt;
1620} 1628}
1621bool CalendarView::checkFileChanged(QString fn) 1629bool CalendarView::checkFileChanged(QString fn)
1622{ 1630{
1623 QFileInfo finf ( fn ); 1631 QFileInfo finf ( fn );
1624 if ( !finf.exists() ) 1632 if ( !finf.exists() )
1625 return true; 1633 return true;
1626 QDateTime dt = finf.lastModified (); 1634 QDateTime dt = finf.lastModified ();
1627 if ( dt <= loadedFileVersion ) 1635 if ( dt <= loadedFileVersion )
1628 return false; 1636 return false;
1629 return true; 1637 return true;
1630 1638
1631} 1639}
1632void CalendarView::watchSavedFile() 1640void CalendarView::watchSavedFile()
1633{ 1641{
1634 QFileInfo finf ( MainWindow::defaultFileName()); 1642 QFileInfo finf ( MainWindow::defaultFileName());
1635 if ( !finf.exists() ) 1643 if ( !finf.exists() )
1636 return; 1644 return;
1637 QDateTime dt = finf.lastModified (); 1645 QDateTime dt = finf.lastModified ();
1638 if ( dt < loadedFileVersion ) { 1646 if ( dt < loadedFileVersion ) {
1639 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 1647 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
1640 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 1648 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
1641 return; 1649 return;
1642 } 1650 }
1643 loadedFileVersion = dt; 1651 loadedFileVersion = dt;
1644} 1652}
1645 1653
1646bool CalendarView::checkFileVersion(QString fn) 1654bool CalendarView::checkFileVersion(QString fn)
1647{ 1655{
1648 QFileInfo finf ( fn ); 1656 QFileInfo finf ( fn );
1649 if ( !finf.exists() ) 1657 if ( !finf.exists() )
1650 return true; 1658 return true;
1651 QDateTime dt = finf.lastModified (); 1659 QDateTime dt = finf.lastModified ();
1652 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1660 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1653 //qDebug("file on disk version %s",dt.toString().latin1()); 1661 //qDebug("file on disk version %s",dt.toString().latin1());
1654 if ( dt <= loadedFileVersion ) 1662 if ( dt <= loadedFileVersion )
1655 return true; 1663 return true;
1656 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , 1664 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
1657 i18n("KO/Pi Warning"),i18n("Overwrite"), 1665 i18n("KO/Pi Warning"),i18n("Overwrite"),
1658 i18n("Sync+save")); 1666 i18n("Sync+save"));
1659 1667
1660 if ( km == KMessageBox::Cancel ) 1668 if ( km == KMessageBox::Cancel )
1661 return false; 1669 return false;
1662 if ( km == KMessageBox::Yes ) 1670 if ( km == KMessageBox::Yes )
1663 return true; 1671 return true;
1664 1672
1665 setSyncDevice("deleteaftersync" ); 1673 setSyncDevice("deleteaftersync" );
1666 mSyncManager->mAskForPreferences = true; 1674 mSyncManager->mAskForPreferences = true;
1667 mSyncManager->mSyncAlgoPrefs = 3; 1675 mSyncManager->mSyncAlgoPrefs = 3;
1668 mSyncManager->mWriteBackFile = false; 1676 mSyncManager->mWriteBackFile = false;
1669 mSyncManager->mWriteBackExistingOnly = false; 1677 mSyncManager->mWriteBackExistingOnly = false;
1670 mSyncManager->mShowSyncSummary = false; 1678 mSyncManager->mShowSyncSummary = false;
1671 syncCalendar( fn, 3 ); 1679 syncCalendar( fn, 3 );
1672 Event * e = getLastSyncEvent(); 1680 Event * e = getLastSyncEvent();
1673 mCalendar->deleteEvent ( e ); 1681 mCalendar->deleteEvent ( e );
1674 updateView(); 1682 updateView();
1675 return true; 1683 return true;
1676} 1684}
1677 1685
1678bool CalendarView::saveCalendar( QString filename ) 1686bool CalendarView::saveCalendar( QString filename )
1679{ 1687{
1680 1688
1681 // Store back all unsaved data into calendar object 1689 // Store back all unsaved data into calendar object
1682 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 1690 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
1683 if ( mViewManager->currentView() ) 1691 if ( mViewManager->currentView() )
1684 mViewManager->currentView()->flushView(); 1692 mViewManager->currentView()->flushView();
1685 1693
1686 1694
1687 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 1695 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
1688 mStorage->setSaveFormat( new ICalFormat() ); 1696 mStorage->setSaveFormat( new ICalFormat() );
1689 mStorage->setFileName( filename ); 1697 mStorage->setFileName( filename );
1690 bool success; 1698 bool success;
1691 success = mStorage->save(); 1699 success = mStorage->save();
1692 if ( !success ) { 1700 if ( !success ) {
1693 return false; 1701 return false;
1694 } 1702 }
1695 if ( filename == MainWindow::defaultFileName() ) { 1703 if ( filename == MainWindow::defaultFileName() ) {
1696 setLoadedFileVersion( lfv ); 1704 setLoadedFileVersion( lfv );
1697 watchSavedFile(); 1705 watchSavedFile();
1698 } 1706 }
1699 return true; 1707 return true;
1700} 1708}
1701 1709
1702void CalendarView::closeCalendar() 1710void CalendarView::closeCalendar()
1703{ 1711{
1704 1712
1705 // child windows no longer valid 1713 // child windows no longer valid
1706 emit closingDown(); 1714 emit closingDown();
1707 1715
1708 mCalendar->close(); 1716 mCalendar->close();
1709 setModified(false); 1717 setModified(false);
1710 updateView(); 1718 updateView();
1711} 1719}
1712 1720
1713void CalendarView::archiveCalendar() 1721void CalendarView::archiveCalendar()
1714{ 1722{
1715 mDialogManager->showArchiveDialog(); 1723 mDialogManager->showArchiveDialog();
1716} 1724}
1717 1725
1718 1726
1719void CalendarView::readSettings() 1727void CalendarView::readSettings()
1720{ 1728{
1721 1729
1722 1730
1723 // mViewManager->showAgendaView(); 1731 // mViewManager->showAgendaView();
1724 QString str; 1732 QString str;
1725 //qDebug("CalendarView::readSettings() "); 1733 //qDebug("CalendarView::readSettings() ");
1726 // read settings from the KConfig, supplying reasonable 1734 // read settings from the KConfig, supplying reasonable
1727 // defaults where none are to be found 1735 // defaults where none are to be found
1728 KConfig *config = KOGlobals::config(); 1736 KConfig *config = KOGlobals::config();
1729#ifndef KORG_NOSPLITTER 1737#ifndef KORG_NOSPLITTER
1730 config->setGroup("KOrganizer Geometry"); 1738 config->setGroup("KOrganizer Geometry");
1731 1739
1732 QValueList<int> sizes = config->readIntListEntry("Separator1"); 1740 QValueList<int> sizes = config->readIntListEntry("Separator1");
1733 if (sizes.count() != 2) { 1741 if (sizes.count() != 2) {
1734 sizes << mDateNavigator->minimumSizeHint().width(); 1742 sizes << mDateNavigator->minimumSizeHint().width();
1735 sizes << 300; 1743 sizes << 300;
1736 } 1744 }
1737 mPanner->setSizes(sizes); 1745 mPanner->setSizes(sizes);
1738 1746
1739 sizes = config->readIntListEntry("Separator2"); 1747 sizes = config->readIntListEntry("Separator2");
1740 if ( ( mResourceView && sizes.count() == 4 ) || 1748 if ( ( mResourceView && sizes.count() == 4 ) ||
1741 ( !mResourceView && sizes.count() == 3 ) ) { 1749 ( !mResourceView && sizes.count() == 3 ) ) {
1742 mLeftSplitter->setSizes(sizes); 1750 mLeftSplitter->setSizes(sizes);
1743 } 1751 }
1744#endif 1752#endif
1745 globalFlagBlockAgenda = 1; 1753 globalFlagBlockAgenda = 1;
1746 mViewManager->showAgendaView(); 1754 mViewManager->showAgendaView();
1747 //mViewManager->readSettings( config ); 1755 //mViewManager->readSettings( config );
1748 mTodoList->restoreLayout(config,QString("Todo Layout")); 1756 mTodoList->restoreLayout(config,QString("Todo Layout"));
1749 readFilterSettings(config); 1757 readFilterSettings(config);
1750 config->setGroup( "Views" ); 1758 config->setGroup( "Views" );
1751 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 1759 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
1752 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 1760 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
1753 else if ( dateCount == 7 ) mNavigator->selectWeek(); 1761 else if ( dateCount == 7 ) mNavigator->selectWeek();
1754 else mNavigator->selectDates( dateCount ); 1762 else mNavigator->selectDates( dateCount );
1755 // mViewManager->readSettings( config ); 1763 // mViewManager->readSettings( config );
1756 updateConfig(); 1764 updateConfig();
1757 globalFlagBlockAgenda = 2; 1765 globalFlagBlockAgenda = 2;
1758 mViewManager->readSettings( config ); 1766 mViewManager->readSettings( config );
1759#ifdef DESKTOP_VERSION 1767#ifdef DESKTOP_VERSION
1760 config->setGroup("WidgetLayout"); 1768 config->setGroup("WidgetLayout");
1761 QStringList list; 1769 QStringList list;
1762 list = config->readListEntry("MainLayout"); 1770 list = config->readListEntry("MainLayout");
1763 int x,y,w,h; 1771 int x,y,w,h;
1764 if ( ! list.isEmpty() ) { 1772 if ( ! list.isEmpty() ) {
1765 x = list[0].toInt(); 1773 x = list[0].toInt();
1766 y = list[1].toInt(); 1774 y = list[1].toInt();
1767 w = list[2].toInt(); 1775 w = list[2].toInt();
1768 h = list[3].toInt(); 1776 h = list[3].toInt();
1769 topLevelWidget()->setGeometry(x,y,w,h); 1777 topLevelWidget()->setGeometry(x,y,w,h);
1770 1778
1771 } else { 1779 } else {
1772 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 1780 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
1773 } 1781 }
1774 list = config->readListEntry("EditEventLayout"); 1782 list = config->readListEntry("EditEventLayout");
1775 if ( ! list.isEmpty() ) { 1783 if ( ! list.isEmpty() ) {
1776 x = list[0].toInt(); 1784 x = list[0].toInt();
1777 y = list[1].toInt(); 1785 y = list[1].toInt();
1778 w = list[2].toInt(); 1786 w = list[2].toInt();
1779 h = list[3].toInt(); 1787 h = list[3].toInt();
1780 mEventEditor->setGeometry(x,y,w,h); 1788 mEventEditor->setGeometry(x,y,w,h);
1781 1789
1782 } 1790 }
1783 list = config->readListEntry("EditTodoLayout"); 1791 list = config->readListEntry("EditTodoLayout");
1784 if ( ! list.isEmpty() ) { 1792 if ( ! list.isEmpty() ) {
1785 x = list[0].toInt(); 1793 x = list[0].toInt();
1786 y = list[1].toInt(); 1794 y = list[1].toInt();
1787 w = list[2].toInt(); 1795 w = list[2].toInt();
1788 h = list[3].toInt(); 1796 h = list[3].toInt();
1789 mTodoEditor->setGeometry(x,y,w,h); 1797 mTodoEditor->setGeometry(x,y,w,h);
1790 1798
1791 } 1799 }
1792 list = config->readListEntry("ViewerLayout"); 1800 list = config->readListEntry("ViewerLayout");
1793 if ( ! list.isEmpty() ) { 1801 if ( ! list.isEmpty() ) {
1794 x = list[0].toInt(); 1802 x = list[0].toInt();
1795 y = list[1].toInt(); 1803 y = list[1].toInt();
1796 w = list[2].toInt(); 1804 w = list[2].toInt();
1797 h = list[3].toInt(); 1805 h = list[3].toInt();
1798 getEventViewerDialog()->setGeometry(x,y,w,h); 1806 getEventViewerDialog()->setGeometry(x,y,w,h);
1799 } 1807 }
1800#endif 1808#endif
1801 1809
1802} 1810}
1803 1811
1804 1812
1805void CalendarView::writeSettings() 1813void CalendarView::writeSettings()
1806{ 1814{
1807 // kdDebug() << "CalendarView::writeSettings" << endl; 1815 // kdDebug() << "CalendarView::writeSettings" << endl;
1808 1816
1809 KConfig *config = KOGlobals::config(); 1817 KConfig *config = KOGlobals::config();
1810 1818
1811#ifndef KORG_NOSPLITTER 1819#ifndef KORG_NOSPLITTER
1812 config->setGroup("KOrganizer Geometry"); 1820 config->setGroup("KOrganizer Geometry");
1813 1821
1814 QValueList<int> list = mPanner->sizes(); 1822 QValueList<int> list = mPanner->sizes();
1815 config->writeEntry("Separator1",list); 1823 config->writeEntry("Separator1",list);
1816 1824
1817 list = mLeftSplitter->sizes(); 1825 list = mLeftSplitter->sizes();
1818 config->writeEntry("Separator2",list); 1826 config->writeEntry("Separator2",list);
1819#endif 1827#endif
1820 1828
1821 mViewManager->writeSettings( config ); 1829 mViewManager->writeSettings( config );
1822 mTodoList->saveLayout(config,QString("Todo Layout")); 1830 mTodoList->saveLayout(config,QString("Todo Layout"));
1823 mDialogManager->writeSettings( config ); 1831 mDialogManager->writeSettings( config );
1824 //KOPrefs::instance()->usrWriteConfig(); 1832 //KOPrefs::instance()->usrWriteConfig();
1825 KOPrefs::instance()->writeConfig(); 1833 KOPrefs::instance()->writeConfig();
1826 1834
1827 writeFilterSettings(config); 1835 writeFilterSettings(config);
1828 1836
1829 config->setGroup( "Views" ); 1837 config->setGroup( "Views" );
1830 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 1838 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
1831 1839
1832#ifdef DESKTOP_VERSION 1840#ifdef DESKTOP_VERSION
1833 config->setGroup("WidgetLayout"); 1841 config->setGroup("WidgetLayout");
1834 QStringList list ;//= config->readListEntry("MainLayout"); 1842 QStringList list ;//= config->readListEntry("MainLayout");
1835 int x,y,w,h; 1843 int x,y,w,h;
1836 QWidget* wid; 1844 QWidget* wid;
1837 wid = topLevelWidget(); 1845 wid = topLevelWidget();
1838 x = wid->geometry().x(); 1846 x = wid->geometry().x();
1839 y = wid->geometry().y(); 1847 y = wid->geometry().y();
1840 w = wid->width(); 1848 w = wid->width();
1841 h = wid->height(); 1849 h = wid->height();
1842 list.clear(); 1850 list.clear();
1843 list << QString::number( x ); 1851 list << QString::number( x );
1844 list << QString::number( y ); 1852 list << QString::number( y );
1845 list << QString::number( w ); 1853 list << QString::number( w );
1846 list << QString::number( h ); 1854 list << QString::number( h );
1847 config->writeEntry("MainLayout",list ); 1855 config->writeEntry("MainLayout",list );
1848 1856
1849 wid = mEventEditor; 1857 wid = mEventEditor;
1850 x = wid->geometry().x(); 1858 x = wid->geometry().x();
1851 y = wid->geometry().y(); 1859 y = wid->geometry().y();
1852 w = wid->width(); 1860 w = wid->width();
1853 h = wid->height(); 1861 h = wid->height();
1854 list.clear(); 1862 list.clear();
1855 list << QString::number( x ); 1863 list << QString::number( x );
1856 list << QString::number( y ); 1864 list << QString::number( y );
1857 list << QString::number( w ); 1865 list << QString::number( w );
1858 list << QString::number( h ); 1866 list << QString::number( h );
1859 config->writeEntry("EditEventLayout",list ); 1867 config->writeEntry("EditEventLayout",list );
1860 1868
1861 wid = mTodoEditor; 1869 wid = mTodoEditor;
1862 x = wid->geometry().x(); 1870 x = wid->geometry().x();
1863 y = wid->geometry().y(); 1871 y = wid->geometry().y();
1864 w = wid->width(); 1872 w = wid->width();
1865 h = wid->height(); 1873 h = wid->height();
1866 list.clear(); 1874 list.clear();
1867 list << QString::number( x ); 1875 list << QString::number( x );
1868 list << QString::number( y ); 1876 list << QString::number( y );
1869 list << QString::number( w ); 1877 list << QString::number( w );
1870 list << QString::number( h ); 1878 list << QString::number( h );
1871 config->writeEntry("EditTodoLayout",list ); 1879 config->writeEntry("EditTodoLayout",list );
1872 wid = getEventViewerDialog(); 1880 wid = getEventViewerDialog();
1873 x = wid->geometry().x(); 1881 x = wid->geometry().x();
1874 y = wid->geometry().y(); 1882 y = wid->geometry().y();
1875 w = wid->width(); 1883 w = wid->width();
1876 h = wid->height(); 1884 h = wid->height();
1877 list.clear(); 1885 list.clear();
1878 list << QString::number( x ); 1886 list << QString::number( x );
1879 list << QString::number( y ); 1887 list << QString::number( y );
1880 list << QString::number( w ); 1888 list << QString::number( w );
1881 list << QString::number( h ); 1889 list << QString::number( h );
1882 config->writeEntry("ViewerLayout",list ); 1890 config->writeEntry("ViewerLayout",list );
1883 wid = mDialogManager->getSearchDialog(); 1891 wid = mDialogManager->getSearchDialog();
1884 if ( wid ) { 1892 if ( wid ) {
1885 x = wid->geometry().x(); 1893 x = wid->geometry().x();
1886 y = wid->geometry().y(); 1894 y = wid->geometry().y();
1887 w = wid->width(); 1895 w = wid->width();
1888 h = wid->height(); 1896 h = wid->height();
1889 list.clear(); 1897 list.clear();
1890 list << QString::number( x ); 1898 list << QString::number( x );
1891 list << QString::number( y ); 1899 list << QString::number( y );
1892 list << QString::number( w ); 1900 list << QString::number( w );
1893 list << QString::number( h ); 1901 list << QString::number( h );
1894 config->writeEntry("SearchLayout",list ); 1902 config->writeEntry("SearchLayout",list );
1895 } 1903 }
1896#endif 1904#endif
1897 1905
1898 1906
1899 config->sync(); 1907 config->sync();
1900} 1908}
1901 1909
1902void CalendarView::readFilterSettings(KConfig *config) 1910void CalendarView::readFilterSettings(KConfig *config)
1903{ 1911{
1904 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 1912 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
1905 1913
1906 mFilters.clear(); 1914 mFilters.clear();
1907 1915
1908 config->setGroup("General"); 1916 config->setGroup("General");
1909 QStringList filterList = config->readListEntry("CalendarFilters"); 1917 QStringList filterList = config->readListEntry("CalendarFilters");
1910 1918
1911 QStringList::ConstIterator it = filterList.begin(); 1919 QStringList::ConstIterator it = filterList.begin();
1912 QStringList::ConstIterator end = filterList.end(); 1920 QStringList::ConstIterator end = filterList.end();
1913 while(it != end) { 1921 while(it != end) {
1914 // kdDebug() << " filter: " << (*it) << endl; 1922 // kdDebug() << " filter: " << (*it) << endl;
1915 1923
1916 CalFilter *filter; 1924 CalFilter *filter;
1917 filter = new CalFilter(*it); 1925 filter = new CalFilter(*it);
1918 config->setGroup("Filter_" + (*it)); 1926 config->setGroup("Filter_" + (*it));
1919 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 1927 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
1920 filter->setCriteria(config->readNumEntry("Criteria",0)); 1928 filter->setCriteria(config->readNumEntry("Criteria",0));
1921 filter->setCategoryList(config->readListEntry("CategoryList")); 1929 filter->setCategoryList(config->readListEntry("CategoryList"));
1922 mFilters.append(filter); 1930 mFilters.append(filter);
1923 1931
1924 ++it; 1932 ++it;
1925 } 1933 }
1926 1934
1927 if (mFilters.count() == 0) { 1935 if (mFilters.count() == 0) {
1928 CalFilter *filter = new CalFilter(i18n("Default")); 1936 CalFilter *filter = new CalFilter(i18n("Default"));
1929 mFilters.append(filter); 1937 mFilters.append(filter);
1930 } 1938 }
1931 mFilterView->updateFilters(); 1939 mFilterView->updateFilters();
1932 config->setGroup("FilterView"); 1940 config->setGroup("FilterView");
1933 1941
1934 mFilterView->blockSignals(true); 1942 mFilterView->blockSignals(true);
1935 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 1943 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
1936 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 1944 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
1937 mFilterView->blockSignals(false); 1945 mFilterView->blockSignals(false);
1938 // We do it manually to avoid it being done twice by the above calls 1946 // We do it manually to avoid it being done twice by the above calls
1939 updateFilter(); 1947 updateFilter();
1940} 1948}
1941 1949
1942void CalendarView::writeFilterSettings(KConfig *config) 1950void CalendarView::writeFilterSettings(KConfig *config)
1943{ 1951{
1944 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 1952 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
1945 1953
1946 QStringList filterList; 1954 QStringList filterList;
1947 1955
1948 CalFilter *filter = mFilters.first(); 1956 CalFilter *filter = mFilters.first();
1949 while(filter) { 1957 while(filter) {
1950 // kdDebug() << " fn: " << filter->name() << endl; 1958 // kdDebug() << " fn: " << filter->name() << endl;
1951 filterList << filter->name(); 1959 filterList << filter->name();
1952 config->setGroup("Filter_" + filter->name()); 1960 config->setGroup("Filter_" + filter->name());
1953 config->writeEntry("Criteria",filter->criteria()); 1961 config->writeEntry("Criteria",filter->criteria());
1954 config->writeEntry("CategoryList",filter->categoryList()); 1962 config->writeEntry("CategoryList",filter->categoryList());
1955 filter = mFilters.next(); 1963 filter = mFilters.next();
1956 } 1964 }
1957 config->setGroup("General"); 1965 config->setGroup("General");
1958 config->writeEntry("CalendarFilters",filterList); 1966 config->writeEntry("CalendarFilters",filterList);
1959 1967
1960 config->setGroup("FilterView"); 1968 config->setGroup("FilterView");
1961 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 1969 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
1962 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 1970 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
1963} 1971}
1964 1972
1965 1973
1966void CalendarView::goToday() 1974void CalendarView::goToday()
1967{ 1975{
1968 mNavigator->selectToday(); 1976 mNavigator->selectToday();
1969} 1977}
1970 1978
1971void CalendarView::goNext() 1979void CalendarView::goNext()
1972{ 1980{
1973 mNavigator->selectNext(); 1981 mNavigator->selectNext();
1974} 1982}
1975 1983
1976void CalendarView::goPrevious() 1984void CalendarView::goPrevious()
1977{ 1985{
1978 mNavigator->selectPrevious(); 1986 mNavigator->selectPrevious();
1979} 1987}
1980void CalendarView::goNextMonth() 1988void CalendarView::goNextMonth()
1981{ 1989{
1982 mNavigator->selectNextMonth(); 1990 mNavigator->selectNextMonth();
1983} 1991}
1984 1992
1985void CalendarView::goPreviousMonth() 1993void CalendarView::goPreviousMonth()
1986{ 1994{
1987 mNavigator->selectPreviousMonth(); 1995 mNavigator->selectPreviousMonth();
1988} 1996}
1989void CalendarView::writeLocale() 1997void CalendarView::writeLocale()
1990{ 1998{
1991 //KPimGlobalPrefs::instance()->setGlobalConfig(); 1999 //KPimGlobalPrefs::instance()->setGlobalConfig();
1992#if 0 2000#if 0
1993 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); 2001 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime );
1994 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); 2002 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday );
1995 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); 2003 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate );
1996 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); 2004 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage );
1997 QString dummy = KOPrefs::instance()->mUserDateFormatLong; 2005 QString dummy = KOPrefs::instance()->mUserDateFormatLong;
1998 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); 2006 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") ));
1999 dummy = KOPrefs::instance()->mUserDateFormatShort; 2007 dummy = KOPrefs::instance()->mUserDateFormatShort;
2000 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 2008 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
2001 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, 2009 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving,
2002 KOPrefs::instance()->mDaylightsavingStart, 2010 KOPrefs::instance()->mDaylightsavingStart,
2003 KOPrefs::instance()->mDaylightsavingEnd ); 2011 KOPrefs::instance()->mDaylightsavingEnd );
2004 KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId ); 2012 KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId );
2005#endif 2013#endif
2006} 2014}
2007void CalendarView::updateConfig() 2015void CalendarView::updateConfig()
2008{ 2016{
2009 writeLocale(); 2017 writeLocale();
2010 if ( KOPrefs::instance()->mUseAppColors ) 2018 if ( KOPrefs::instance()->mUseAppColors )
2011 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 2019 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
2012 emit configChanged(); 2020 emit configChanged();
2013 mTodoList->updateConfig(); 2021 mTodoList->updateConfig();
2014 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 2022 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
2015 mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 2023 mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
2016 // To make the "fill window" configurations work 2024 // To make the "fill window" configurations work
2017 //mViewManager->raiseCurrentView(); 2025 //mViewManager->raiseCurrentView();
2018} 2026}
2019 2027
2020 2028
2021void CalendarView::eventChanged(Event *event) 2029void CalendarView::eventChanged(Event *event)
2022{ 2030{
2023 changeEventDisplay(event,KOGlobals::EVENTEDITED); 2031 changeEventDisplay(event,KOGlobals::EVENTEDITED);
2024 //updateUnmanagedViews(); 2032 //updateUnmanagedViews();
2025} 2033}
2026 2034
2027void CalendarView::eventAdded(Event *event) 2035void CalendarView::eventAdded(Event *event)
2028{ 2036{
2029 changeEventDisplay(event,KOGlobals::EVENTADDED); 2037 changeEventDisplay(event,KOGlobals::EVENTADDED);
2030} 2038}
2031 2039
2032void CalendarView::eventToBeDeleted(Event *) 2040void CalendarView::eventToBeDeleted(Event *)
2033{ 2041{
2034 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 2042 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
2035} 2043}
2036 2044
2037void CalendarView::eventDeleted() 2045void CalendarView::eventDeleted()
2038{ 2046{
2039 changeEventDisplay(0,KOGlobals::EVENTDELETED); 2047 changeEventDisplay(0,KOGlobals::EVENTDELETED);
2040} 2048}
2041void CalendarView::changeTodoDisplay(Todo *which, int action) 2049void CalendarView::changeTodoDisplay(Todo *which, int action)
2042{ 2050{
2043 changeIncidenceDisplay((Incidence *)which, action); 2051 changeIncidenceDisplay((Incidence *)which, action);
2044 mDateNavigator->updateView(); //LR 2052 mDateNavigator->updateView(); //LR
2045 //mDialogManager->updateSearchDialog(); 2053 //mDialogManager->updateSearchDialog();
2046 2054
2047 if (which) { 2055 if (which) {
2048 mViewManager->updateWNview(); 2056 mViewManager->updateWNview();
2049 //mTodoList->updateView(); 2057 //mTodoList->updateView();
2050 } 2058 }
2051 2059
2052} 2060}
2053 2061
2054void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 2062void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
2055{ 2063{
2056 updateUnmanagedViews(); 2064 updateUnmanagedViews();
2057 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 2065 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
2058 if ( action == KOGlobals::EVENTDELETED ) { //delete 2066 if ( action == KOGlobals::EVENTDELETED ) { //delete
2059 mCalendar->checkAlarmForIncidence( 0, true ); 2067 mCalendar->checkAlarmForIncidence( 0, true );
2060 if ( mEventViewerDialog ) 2068 if ( mEventViewerDialog )
2061 mEventViewerDialog->hide(); 2069 mEventViewerDialog->hide();
2062 } 2070 }
2063 else 2071 else
2064 mCalendar->checkAlarmForIncidence( which , false ); 2072 mCalendar->checkAlarmForIncidence( which , false );
2065} 2073}
2066 2074
2067// most of the changeEventDisplays() right now just call the view's 2075// most of the changeEventDisplays() right now just call the view's
2068// total update mode, but they SHOULD be recoded to be more refresh-efficient. 2076// total update mode, but they SHOULD be recoded to be more refresh-efficient.
2069void CalendarView::changeEventDisplay(Event *which, int action) 2077void CalendarView::changeEventDisplay(Event *which, int action)
2070{ 2078{
2071 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 2079 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
2072 changeIncidenceDisplay((Incidence *)which, action); 2080 changeIncidenceDisplay((Incidence *)which, action);
2073 mDateNavigator->updateView(); 2081 mDateNavigator->updateView();
2074 //mDialogManager->updateSearchDialog(); 2082 //mDialogManager->updateSearchDialog();
2075 2083
2076 if (which) { 2084 if (which) {
2077 // If there is an event view visible update the display 2085 // If there is an event view visible update the display
2078 mViewManager->currentView()->changeEventDisplay(which,action); 2086 mViewManager->currentView()->changeEventDisplay(which,action);
2079 // TODO: check, if update needed 2087 // TODO: check, if update needed
2080 // if (which->getTodoStatus()) { 2088 // if (which->getTodoStatus()) {
2081 mTodoList->updateView(); 2089 mTodoList->updateView();
2082 // } 2090 // }
2083 } else { 2091 } else {
2084 mViewManager->currentView()->updateView(); 2092 mViewManager->currentView()->updateView();
2085 } 2093 }
2086} 2094}
2087 2095
2088 2096
2089void CalendarView::updateTodoViews() 2097void CalendarView::updateTodoViews()
2090{ 2098{
2091 2099
2092 mTodoList->updateView(); 2100 mTodoList->updateView();
2093 mViewManager->currentView()->updateView(); 2101 mViewManager->currentView()->updateView();
2094 2102
2095} 2103}
2096 2104
2097 2105
2098void CalendarView::updateView(const QDate &start, const QDate &end) 2106void CalendarView::updateView(const QDate &start, const QDate &end)
2099{ 2107{
2100 mTodoList->updateView(); 2108 mTodoList->updateView();
2101 mViewManager->updateView(start, end); 2109 mViewManager->updateView(start, end);
2102 //mDateNavigator->updateView(); 2110 //mDateNavigator->updateView();
2103} 2111}
2104 2112
2105void CalendarView::updateView() 2113void CalendarView::updateView()
2106{ 2114{
2107 DateList tmpList = mNavigator->selectedDates(); 2115 DateList tmpList = mNavigator->selectedDates();
2108 2116
2109 // We assume that the navigator only selects consecutive days. 2117 // We assume that the navigator only selects consecutive days.
2110 updateView( tmpList.first(), tmpList.last() ); 2118 updateView( tmpList.first(), tmpList.last() );
2111} 2119}
2112 2120
2113void CalendarView::updateUnmanagedViews() 2121void CalendarView::updateUnmanagedViews()
2114{ 2122{
2115 mDateNavigator->updateDayMatrix(); 2123 mDateNavigator->updateDayMatrix();
2116} 2124}
2117 2125
2118int CalendarView::msgItemDelete() 2126int CalendarView::msgItemDelete()
2119{ 2127{
2120 return KMessageBox::warningContinueCancel(this, 2128 return KMessageBox::warningContinueCancel(this,
2121 i18n("This item will be\npermanently deleted."), 2129 i18n("This item will be\npermanently deleted."),
2122 i18n("KO/Pi Confirmation"),i18n("Delete")); 2130 i18n("KO/Pi Confirmation"),i18n("Delete"));
2123} 2131}
2124 2132
2125 2133
2126void CalendarView::edit_cut() 2134void CalendarView::edit_cut()
2127{ 2135{
2128 Event *anEvent=0; 2136 Event *anEvent=0;
2129 2137
2130 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2138 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2131 2139
2132 if (mViewManager->currentView()->isEventView()) { 2140 if (mViewManager->currentView()->isEventView()) {
2133 if ( incidence && incidence->type() == "Event" ) { 2141 if ( incidence && incidence->type() == "Event" ) {
2134 anEvent = static_cast<Event *>(incidence); 2142 anEvent = static_cast<Event *>(incidence);
2135 } 2143 }
2136 } 2144 }
2137 2145
2138 if (!anEvent) { 2146 if (!anEvent) {
2139 KNotifyClient::beep(); 2147 KNotifyClient::beep();
2140 return; 2148 return;
2141 } 2149 }
2142 DndFactory factory( mCalendar ); 2150 DndFactory factory( mCalendar );
2143 factory.cutEvent(anEvent); 2151 factory.cutEvent(anEvent);
2144 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2152 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2145} 2153}
2146 2154
2147void CalendarView::edit_copy() 2155void CalendarView::edit_copy()
2148{ 2156{
2149 Event *anEvent=0; 2157 Event *anEvent=0;
2150 2158
2151 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2159 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2152 2160
2153 if (mViewManager->currentView()->isEventView()) { 2161 if (mViewManager->currentView()->isEventView()) {
2154 if ( incidence && incidence->type() == "Event" ) { 2162 if ( incidence && incidence->type() == "Event" ) {
2155 anEvent = static_cast<Event *>(incidence); 2163 anEvent = static_cast<Event *>(incidence);
2156 } 2164 }
2157 } 2165 }
2158 2166
2159 if (!anEvent) { 2167 if (!anEvent) {
2160 KNotifyClient::beep(); 2168 KNotifyClient::beep();
2161 return; 2169 return;
2162 } 2170 }
2163 DndFactory factory( mCalendar ); 2171 DndFactory factory( mCalendar );
2164 factory.copyEvent(anEvent); 2172 factory.copyEvent(anEvent);
2165} 2173}
2166 2174
2167void CalendarView::edit_paste() 2175void CalendarView::edit_paste()
2168{ 2176{
2169 QDate date = mNavigator->selectedDates().first(); 2177 QDate date = mNavigator->selectedDates().first();
2170 2178
2171 DndFactory factory( mCalendar ); 2179 DndFactory factory( mCalendar );
2172 Event *pastedEvent = factory.pasteEvent( date ); 2180 Event *pastedEvent = factory.pasteEvent( date );
2173 2181
2174 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2182 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2175} 2183}
2176 2184
2177void CalendarView::edit_options() 2185void CalendarView::edit_options()
2178{ 2186{
2179 mDialogManager->showOptionsDialog(); 2187 mDialogManager->showOptionsDialog();
2180 //writeSettings(); 2188 //writeSettings();
2181} 2189}
2182 2190
2183void CalendarView::slotSelectPickerDate( QDate d) 2191void CalendarView::slotSelectPickerDate( QDate d)
2184{ 2192{
2185 mDateFrame->hide(); 2193 mDateFrame->hide();
2186 if ( mDatePickerMode == 1 ) { 2194 if ( mDatePickerMode == 1 ) {
2187 mNavigator->slotDaySelect( d ); 2195 mNavigator->slotDaySelect( d );
2188 } else if ( mDatePickerMode == 2 ) { 2196 } else if ( mDatePickerMode == 2 ) {
2189 if ( mMoveIncidence->type() == "Todo" ) { 2197 if ( mMoveIncidence->type() == "Todo" ) {
2190 Todo * to = (Todo *) mMoveIncidence; 2198 Todo * to = (Todo *) mMoveIncidence;
2191 QTime tim; 2199 QTime tim;
2192 if ( to->hasDueDate() ) 2200 if ( to->hasDueDate() )
2193 tim = to->dtDue().time(); 2201 tim = to->dtDue().time();
2194 else { 2202 else {
2195 tim = QTime ( 0,0,0 ); 2203 tim = QTime ( 0,0,0 );
2196 to->setFloats( true ); 2204 to->setFloats( true );
2197 to->setHasDueDate( true ); 2205 to->setHasDueDate( true );
2198 } 2206 }
2199 QDateTime dt ( d,tim ); 2207 QDateTime dt ( d,tim );
2200 to->setDtDue( dt ); 2208 to->setDtDue( dt );
2201 todoChanged( to ); 2209 todoChanged( to );
2202 } else { 2210 } else {
2203 QTime tim = mMoveIncidence->dtStart().time(); 2211 QTime tim = mMoveIncidence->dtStart().time();
2204 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 2212 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
2205 QDateTime dt ( d,tim ); 2213 QDateTime dt ( d,tim );
2206 mMoveIncidence->setDtStart( dt ); 2214 mMoveIncidence->setDtStart( dt );
2207 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 2215 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
2208 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 2216 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
2209 } 2217 }
2210 2218
2211 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 2219 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
2212 } 2220 }
2213} 2221}
2214 2222
2215void CalendarView::removeCategories() 2223void CalendarView::removeCategories()
2216{ 2224{
2217 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2225 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2218 QStringList catList = KOPrefs::instance()->mCustomCategories; 2226 QStringList catList = KOPrefs::instance()->mCustomCategories;
2219 QStringList catIncList; 2227 QStringList catIncList;
2220 QStringList newCatList; 2228 QStringList newCatList;
2221 Incidence* inc = incList.first(); 2229 Incidence* inc = incList.first();
2222 int i; 2230 int i;
2223 int count = 0; 2231 int count = 0;
2224 while ( inc ) { 2232 while ( inc ) {
2225 newCatList.clear(); 2233 newCatList.clear();
2226 catIncList = inc->categories() ; 2234 catIncList = inc->categories() ;
2227 for( i = 0; i< catIncList.count(); ++i ) { 2235 for( i = 0; i< catIncList.count(); ++i ) {
2228 if ( catList.contains (catIncList[i])) 2236 if ( catList.contains (catIncList[i]))
2229 newCatList.append( catIncList[i] ); 2237 newCatList.append( catIncList[i] );
2230 } 2238 }
2231 newCatList.sort(); 2239 newCatList.sort();
2232 inc->setCategories( newCatList.join(",") ); 2240 inc->setCategories( newCatList.join(",") );
2233 inc = incList.next(); 2241 inc = incList.next();
2234 } 2242 }
2235} 2243}
2236 2244
2237int CalendarView::addCategories() 2245int CalendarView::addCategories()
2238{ 2246{
2239 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2247 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2240 QStringList catList = KOPrefs::instance()->mCustomCategories; 2248 QStringList catList = KOPrefs::instance()->mCustomCategories;
2241 QStringList catIncList; 2249 QStringList catIncList;
2242 Incidence* inc = incList.first(); 2250 Incidence* inc = incList.first();
2243 int i; 2251 int i;
2244 int count = 0; 2252 int count = 0;
2245 while ( inc ) { 2253 while ( inc ) {
2246 catIncList = inc->categories() ; 2254 catIncList = inc->categories() ;
2247 for( i = 0; i< catIncList.count(); ++i ) { 2255 for( i = 0; i< catIncList.count(); ++i ) {
2248 if ( !catList.contains (catIncList[i])) { 2256 if ( !catList.contains (catIncList[i])) {
2249 catList.append( catIncList[i] ); 2257 catList.append( catIncList[i] );
2250 //qDebug("add cat %s ", catIncList[i].latin1()); 2258 //qDebug("add cat %s ", catIncList[i].latin1());
2251 ++count; 2259 ++count;
2252 } 2260 }
2253 } 2261 }
2254 inc = incList.next(); 2262 inc = incList.next();
2255 } 2263 }
2256 catList.sort(); 2264 catList.sort();
2257 KOPrefs::instance()->mCustomCategories = catList; 2265 KOPrefs::instance()->mCustomCategories = catList;
2258 return count; 2266 return count;
2259} 2267}
2260 2268
2261void CalendarView::manageCategories() 2269void CalendarView::manageCategories()
2262{ 2270{
2263 KOCatPrefs* cp = new KOCatPrefs(); 2271 KOCatPrefs* cp = new KOCatPrefs();
2264 cp->show(); 2272 cp->show();
2265 int w =cp->sizeHint().width() ; 2273 int w =cp->sizeHint().width() ;
2266 int h = cp->sizeHint().height() ; 2274 int h = cp->sizeHint().height() ;
2267 int dw = QApplication::desktop()->width(); 2275 int dw = QApplication::desktop()->width();
2268 int dh = QApplication::desktop()->height(); 2276 int dh = QApplication::desktop()->height();
2269 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2277 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2270 if ( !cp->exec() ) { 2278 if ( !cp->exec() ) {
2271 delete cp; 2279 delete cp;
2272 return; 2280 return;
2273 } 2281 }
2274 int count = 0; 2282 int count = 0;
2275 if ( cp->addCat() ) { 2283 if ( cp->addCat() ) {
2276 count = addCategories(); 2284 count = addCategories();
2277 if ( count ) { 2285 if ( count ) {
2278 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 2286 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
2279 writeSettings(); 2287 writeSettings();
2280 } 2288 }
2281 } else { 2289 } else {
2282 removeCategories(); 2290 removeCategories();
2283 updateView(); 2291 updateView();
2284 } 2292 }
2285 delete cp; 2293 delete cp;
2286} 2294}
2287 2295
2288void CalendarView::beamIncidence(Incidence * Inc) 2296void CalendarView::beamIncidence(Incidence * Inc)
2289{ 2297{
2290 QPtrList<Incidence> delSel ; 2298 QPtrList<Incidence> delSel ;
2291 delSel.append(Inc); 2299 delSel.append(Inc);
2292 beamIncidenceList( delSel ); 2300 beamIncidenceList( delSel );
2293} 2301}
2294void CalendarView::beamCalendar() 2302void CalendarView::beamCalendar()
2295{ 2303{
2296 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 2304 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
2297 //qDebug("beamCalendar() "); 2305 //qDebug("beamCalendar() ");
2298 beamIncidenceList( delSel ); 2306 beamIncidenceList( delSel );
2299} 2307}
2300void CalendarView::beamFilteredCalendar() 2308void CalendarView::beamFilteredCalendar()
2301{ 2309{
2302 QPtrList<Incidence> delSel = mCalendar->incidences(); 2310 QPtrList<Incidence> delSel = mCalendar->incidences();
2303 //qDebug("beamFilteredCalendar() "); 2311 //qDebug("beamFilteredCalendar() ");
2304 beamIncidenceList( delSel ); 2312 beamIncidenceList( delSel );
2305} 2313}
2306void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 2314void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
2307{ 2315{
2308 if ( beamDialog->exec () == QDialog::Rejected ) 2316 if ( beamDialog->exec () == QDialog::Rejected )
2309 return; 2317 return;
2310 2318
2311 QString fn = "/tmp/kopibeamfile"; 2319 QString fn = "/tmp/kopibeamfile";
2312 QString mes; 2320 QString mes;
2313 bool createbup = true; 2321 bool createbup = true;
2314 if ( createbup ) { 2322 if ( createbup ) {
2315 QString description = "\n"; 2323 QString description = "\n";
2316 CalendarLocal* cal = new CalendarLocal(); 2324 CalendarLocal* cal = new CalendarLocal();
2317 if ( beamDialog->beamLocal() ) 2325 if ( beamDialog->beamLocal() )
2318 cal->setLocalTime(); 2326 cal->setLocalTime();
2319 else 2327 else
2320 cal->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 2328 cal->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
2321 Incidence *incidence = delSel.first(); 2329 Incidence *incidence = delSel.first();
2322 bool addText = false; 2330 bool addText = false;
2323 if ( delSel.count() < 10 ) 2331 if ( delSel.count() < 10 )
2324 addText = true; 2332 addText = true;
2325 else { 2333 else {
2326 description.sprintf(i18n(" %d items?"),delSel.count() ); 2334 description.sprintf(i18n(" %d items?"),delSel.count() );
2327 } 2335 }
2328 while ( incidence ) { 2336 while ( incidence ) {
2329 Incidence *in = incidence->clone(); 2337 Incidence *in = incidence->clone();
2330 if ( ! in->summary().isEmpty() ) { 2338 if ( ! in->summary().isEmpty() ) {
2331 in->setDescription(""); 2339 in->setDescription("");
2332 } else { 2340 } else {
2333 in->setSummary( in->description().left(20)); 2341 in->setSummary( in->description().left(20));
2334 in->setDescription(""); 2342 in->setDescription("");
2335 } 2343 }
2336 if ( addText ) 2344 if ( addText )
2337 description += in->summary() + "\n"; 2345 description += in->summary() + "\n";
2338 cal->addIncidence( in ); 2346 cal->addIncidence( in );
2339 incidence = delSel.next(); 2347 incidence = delSel.next();
2340 } 2348 }
2341 if ( beamDialog->beamVcal() ) { 2349 if ( beamDialog->beamVcal() ) {
2342 fn += ".vcs"; 2350 fn += ".vcs";
2343 FileStorage storage( cal, fn, new VCalFormat ); 2351 FileStorage storage( cal, fn, new VCalFormat );
2344 storage.save(); 2352 storage.save();
2345 } else { 2353 } else {
2346 fn += ".ics"; 2354 fn += ".ics";
2347 FileStorage storage( cal, fn, new ICalFormat( ) ); 2355 FileStorage storage( cal, fn, new ICalFormat( ) );
2348 storage.save(); 2356 storage.save();
2349 } 2357 }
2350 delete cal; 2358 delete cal;
2351 mes = i18n("KO/Pi: Ready for beaming"); 2359 mes = i18n("KO/Pi: Ready for beaming");
2352 topLevelWidget()->setCaption(mes); 2360 topLevelWidget()->setCaption(mes);
2353 KApplication::convert2latin1( fn ); 2361 KApplication::convert2latin1( fn );
2354#ifndef DESKTOP_VERSION 2362#ifndef DESKTOP_VERSION
2355 Ir *ir = new Ir( this ); 2363 Ir *ir = new Ir( this );
2356 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 2364 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
2357 ir->send( fn, description, "text/x-vCalendar" ); 2365 ir->send( fn, description, "text/x-vCalendar" );
2358#endif 2366#endif
2359 } 2367 }
2360} 2368}
2361void CalendarView::beamDone( Ir *ir ) 2369void CalendarView::beamDone( Ir *ir )
2362{ 2370{
2363#ifndef DESKTOP_VERSION 2371#ifndef DESKTOP_VERSION
2364 delete ir; 2372 delete ir;
2365#endif 2373#endif
2366 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); 2374 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") );
2367 topLevelWidget()->raise(); 2375 topLevelWidget()->raise();
2368} 2376}
2369 2377
2370void CalendarView::moveIncidence(Incidence * inc ) 2378void CalendarView::moveIncidence(Incidence * inc )
2371{ 2379{
2372 if ( !inc ) return; 2380 if ( !inc ) return;
2373 // qDebug("showDatePickerForIncidence( ) "); 2381 // qDebug("showDatePickerForIncidence( ) ");
2374 if ( mDateFrame->isVisible() ) 2382 if ( mDateFrame->isVisible() )
2375 mDateFrame->hide(); 2383 mDateFrame->hide();
2376 else { 2384 else {
2377 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ; 2385 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ;
2378 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ; 2386 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ;
2379 int dw = QApplication::desktop()->width(); 2387 int dw = QApplication::desktop()->width();
2380 int dh = QApplication::desktop()->height(); 2388 int dh = QApplication::desktop()->height();
2381 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2389 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2382 mDateFrame->show(); 2390 mDateFrame->show();
2383 } 2391 }
2384 mDatePickerMode = 2; 2392 mDatePickerMode = 2;
2385 mMoveIncidence = inc ; 2393 mMoveIncidence = inc ;
2386 QDate da; 2394 QDate da;
2387 if ( mMoveIncidence->type() == "Todo" ) { 2395 if ( mMoveIncidence->type() == "Todo" ) {
2388 Todo * to = (Todo *) mMoveIncidence; 2396 Todo * to = (Todo *) mMoveIncidence;
2389 if ( to->hasDueDate() ) 2397 if ( to->hasDueDate() )
2390 da = to->dtDue().date(); 2398 da = to->dtDue().date();
2391 else 2399 else
2392 da = QDate::currentDate(); 2400 da = QDate::currentDate();
2393 } else { 2401 } else {
2394 da = mMoveIncidence->dtStart().date(); 2402 da = mMoveIncidence->dtStart().date();
2395 } 2403 }
2396 mDatePicker->setDate( da ); 2404 mDatePicker->setDate( da );
2397} 2405}
2398void CalendarView::showDatePicker( ) 2406void CalendarView::showDatePicker( )
2399{ 2407{
2400 //qDebug("CalendarView::showDatePicker( ) "); 2408 //qDebug("CalendarView::showDatePicker( ) ");
2401 if ( mDateFrame->isVisible() ) 2409 if ( mDateFrame->isVisible() )
2402 mDateFrame->hide(); 2410 mDateFrame->hide();
2403 else { 2411 else {
2404 int w =mDatePicker->sizeHint().width() ; 2412 int w =mDatePicker->sizeHint().width() ;
2405 int h = mDatePicker->sizeHint().height() ; 2413 int h = mDatePicker->sizeHint().height() ;
2406 int dw = QApplication::desktop()->width(); 2414 int dw = QApplication::desktop()->width();
2407 int dh = QApplication::desktop()->height(); 2415 int dh = QApplication::desktop()->height();
2408 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2416 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2409 mDateFrame->show(); 2417 mDateFrame->show();
2410 } 2418 }
2411 mDatePickerMode = 1; 2419 mDatePickerMode = 1;
2412 mDatePicker->setDate( mNavigator->selectedDates().first() ); 2420 mDatePicker->setDate( mNavigator->selectedDates().first() );
2413} 2421}
2414 2422
2415void CalendarView::showEventEditor() 2423void CalendarView::showEventEditor()
2416{ 2424{
2417#ifdef DESKTOP_VERSION 2425#ifdef DESKTOP_VERSION
2418 mEventEditor->show(); 2426 mEventEditor->show();
2419#else 2427#else
2420 mEventEditor->showMaximized(); 2428 mEventEditor->showMaximized();
2421#endif 2429#endif
2422} 2430}
2423void CalendarView::showTodoEditor() 2431void CalendarView::showTodoEditor()
2424{ 2432{
2425#ifdef DESKTOP_VERSION 2433#ifdef DESKTOP_VERSION
2426 mTodoEditor->show(); 2434 mTodoEditor->show();
2427#else 2435#else
2428 mTodoEditor->showMaximized(); 2436 mTodoEditor->showMaximized();
2429#endif 2437#endif
2430} 2438}
2431 2439
2432void CalendarView::cloneIncidence() 2440void CalendarView::cloneIncidence()
2433{ 2441{
2434 Incidence *incidence = currentSelection(); 2442 Incidence *incidence = currentSelection();
2435 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2443 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2436 if ( incidence ) { 2444 if ( incidence ) {
2437 cloneIncidence(incidence); 2445 cloneIncidence(incidence);
2438 } 2446 }
2439} 2447}
2440void CalendarView::moveIncidence() 2448void CalendarView::moveIncidence()
2441{ 2449{
2442 Incidence *incidence = currentSelection(); 2450 Incidence *incidence = currentSelection();
2443 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2451 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2444 if ( incidence ) { 2452 if ( incidence ) {
2445 moveIncidence(incidence); 2453 moveIncidence(incidence);
2446 } 2454 }
2447} 2455}
2448void CalendarView::beamIncidence() 2456void CalendarView::beamIncidence()
2449{ 2457{
2450 Incidence *incidence = currentSelection(); 2458 Incidence *incidence = currentSelection();
2451 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2459 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2452 if ( incidence ) { 2460 if ( incidence ) {
2453 beamIncidence(incidence); 2461 beamIncidence(incidence);
2454 } 2462 }
2455} 2463}
2456void CalendarView::toggleCancelIncidence() 2464void CalendarView::toggleCancelIncidence()
2457{ 2465{
2458 Incidence *incidence = currentSelection(); 2466 Incidence *incidence = currentSelection();
2459 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2467 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2460 if ( incidence ) { 2468 if ( incidence ) {
2461 cancelIncidence(incidence); 2469 cancelIncidence(incidence);
2462 } 2470 }
2463} 2471}
2464 2472
2465 2473
2466void CalendarView::cancelIncidence(Incidence * inc ) 2474void CalendarView::cancelIncidence(Incidence * inc )
2467{ 2475{
2468 inc->setCancelled( ! inc->cancelled() ); 2476 inc->setCancelled( ! inc->cancelled() );
2469 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 2477 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
2470 updateView(); 2478 updateView();
2471} 2479}
2472void CalendarView::cloneIncidence(Incidence * orgInc ) 2480void CalendarView::cloneIncidence(Incidence * orgInc )
2473{ 2481{
2474 Incidence * newInc = orgInc->clone(); 2482 Incidence * newInc = orgInc->clone();
2475 newInc->recreate(); 2483 newInc->recreate();
2476 2484
2477 if ( newInc->type() == "Todo" ) { 2485 if ( newInc->type() == "Todo" ) {
2478 Todo* t = (Todo*) newInc; 2486 Todo* t = (Todo*) newInc;
2479 mTodoEditor->editTodo( t ); 2487 mTodoEditor->editTodo( t );
2480 showTodoEditor(); 2488 showTodoEditor();
2481 if ( mTodoEditor->exec() ) { 2489 if ( mTodoEditor->exec() ) {
2482 mCalendar->addTodo( t ); 2490 mCalendar->addTodo( t );
2483 updateView(); 2491 updateView();
2484 } else { 2492 } else {
2485 delete t; 2493 delete t;
2486 } 2494 }
2487 } 2495 }
2488 else { 2496 else {
2489 Event* e = (Event*) newInc; 2497 Event* e = (Event*) newInc;
2490 mEventEditor->editEvent( e ); 2498 mEventEditor->editEvent( e );
2491 showEventEditor(); 2499 showEventEditor();
2492 if ( mEventEditor->exec() ) { 2500 if ( mEventEditor->exec() ) {
2493 mCalendar->addEvent( e ); 2501 mCalendar->addEvent( e );
2494 updateView(); 2502 updateView();
2495 } else { 2503 } else {
2496 delete e; 2504 delete e;
2497 } 2505 }
2498 } 2506 }
2499} 2507}
2500 2508
2501void CalendarView::newEvent() 2509void CalendarView::newEvent()
2502{ 2510{
2503 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 2511 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
2504 KOAgendaView *aView = mViewManager->agendaView(); 2512 KOAgendaView *aView = mViewManager->agendaView();
2505 if (aView) { 2513 if (aView) {
2506 if (aView->selectionStart().isValid()) { 2514 if (aView->selectionStart().isValid()) {
2507 if (aView->selectedIsAllDay()) { 2515 if (aView->selectedIsAllDay()) {
2508 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 2516 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
2509 } else { 2517 } else {
2510 newEvent(aView->selectionStart(),aView->selectionEnd()); 2518 newEvent(aView->selectionStart(),aView->selectionEnd());
2511 } 2519 }
2512 return; 2520 return;
2513 } 2521 }
2514 } 2522 }
2515 2523
2516 QDate date = mNavigator->selectedDates().first(); 2524 QDate date = mNavigator->selectedDates().first();
2517 QDateTime current = QDateTime::currentDateTime(); 2525 QDateTime current = QDateTime::currentDateTime();
2518 if ( date <= current.date() ) { 2526 if ( date <= current.date() ) {
2519 int hour = current.time().hour() +1; 2527 int hour = current.time().hour() +1;
2520 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 2528 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
2521 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2529 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2522 } else 2530 } else
2523 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 2531 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
2524 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 2532 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
2525 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2533 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2526} 2534}
2527 2535
2528void CalendarView::newEvent(QDateTime fh) 2536void CalendarView::newEvent(QDateTime fh)
2529{ 2537{
2530 newEvent(fh, 2538 newEvent(fh,
2531 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 2539 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
2532} 2540}
2533 2541
2534void CalendarView::newEvent(QDate dt) 2542void CalendarView::newEvent(QDate dt)
2535{ 2543{
2536 newEvent(QDateTime(dt, QTime(0,0,0)), 2544 newEvent(QDateTime(dt, QTime(0,0,0)),
2537 QDateTime(dt, QTime(0,0,0)), true); 2545 QDateTime(dt, QTime(0,0,0)), true);
2538} 2546}
2539 2547
2540void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 2548void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
2541{ 2549{
2542 2550
2543 mEventEditor->newEvent(fromHint,toHint,allDay); 2551 mEventEditor->newEvent(fromHint,toHint,allDay);
2544 if ( mFilterView->filtersEnabled() ) { 2552 if ( mFilterView->filtersEnabled() ) {
2545 CalFilter *filter = mFilterView->selectedFilter(); 2553 CalFilter *filter = mFilterView->selectedFilter();
2546 if (filter && filter->showCategories()) { 2554 if (filter && filter->showCategories()) {
2547 mEventEditor->setCategories(filter->categoryList().join(",") ); 2555 mEventEditor->setCategories(filter->categoryList().join(",") );
2548 } 2556 }
2549 if ( filter ) 2557 if ( filter )
2550 mEventEditor->setSecrecy( filter->getSecrecy() ); 2558 mEventEditor->setSecrecy( filter->getSecrecy() );
2551 } 2559 }
2552 showEventEditor(); 2560 showEventEditor();
2553} 2561}
2554void CalendarView::todoAdded(Todo * t) 2562void CalendarView::todoAdded(Todo * t)
2555{ 2563{
2556 2564
2557 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 2565 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
2558 updateTodoViews(); 2566 updateTodoViews();
2559} 2567}
2560void CalendarView::todoChanged(Todo * t) 2568void CalendarView::todoChanged(Todo * t)
2561{ 2569{
2562 emit todoModified( t, 4 ); 2570 emit todoModified( t, 4 );
2563 // updateTodoViews(); 2571 // updateTodoViews();
2564} 2572}
2565void CalendarView::todoToBeDeleted(Todo *) 2573void CalendarView::todoToBeDeleted(Todo *)
2566{ 2574{
2567 //qDebug("todoToBeDeleted(Todo *) "); 2575 //qDebug("todoToBeDeleted(Todo *) ");
2568 updateTodoViews(); 2576 updateTodoViews();
2569} 2577}
2570void CalendarView::todoDeleted() 2578void CalendarView::todoDeleted()
2571{ 2579{
2572 //qDebug(" todoDeleted()"); 2580 //qDebug(" todoDeleted()");
2573 updateTodoViews(); 2581 updateTodoViews();
2574} 2582}
2575 2583
2576 2584
2577 2585
2578void CalendarView::newTodo() 2586void CalendarView::newTodo()
2579{ 2587{
2580 2588
2581 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true); 2589 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true);
2582 if ( mFilterView->filtersEnabled() ) { 2590 if ( mFilterView->filtersEnabled() ) {
2583 CalFilter *filter = mFilterView->selectedFilter(); 2591 CalFilter *filter = mFilterView->selectedFilter();
2584 if (filter && filter->showCategories()) { 2592 if (filter && filter->showCategories()) {
2585 mTodoEditor->setCategories(filter->categoryList().join(",") ); 2593 mTodoEditor->setCategories(filter->categoryList().join(",") );
2586 } 2594 }
2587 if ( filter ) 2595 if ( filter )
2588 mTodoEditor->setSecrecy( filter->getSecrecy() ); 2596 mTodoEditor->setSecrecy( filter->getSecrecy() );
2589 } 2597 }
2590 showTodoEditor(); 2598 showTodoEditor();
2591} 2599}
2592 2600
2593void CalendarView::newSubTodo() 2601void CalendarView::newSubTodo()
2594{ 2602{
2595 Todo *todo = selectedTodo(); 2603 Todo *todo = selectedTodo();
2596 if ( todo ) newSubTodo( todo ); 2604 if ( todo ) newSubTodo( todo );
2597} 2605}
2598 2606
2599void CalendarView::newSubTodo(Todo *parentEvent) 2607void CalendarView::newSubTodo(Todo *parentEvent)
2600{ 2608{
2601 2609
2602 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true); 2610 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true);
2603 showTodoEditor(); 2611 showTodoEditor();
2604} 2612}
2605 2613
2606void CalendarView::newFloatingEvent() 2614void CalendarView::newFloatingEvent()
2607{ 2615{
2608 DateList tmpList = mNavigator->selectedDates(); 2616 DateList tmpList = mNavigator->selectedDates();
2609 QDate date = tmpList.first(); 2617 QDate date = tmpList.first();
2610 2618
2611 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 2619 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
2612 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 2620 QDateTime( date, QTime( 12, 0, 0 ) ), true );
2613} 2621}
2614 2622
2615 2623
2616void CalendarView::editEvent( Event *event ) 2624void CalendarView::editEvent( Event *event )
2617{ 2625{
2618 2626
2619 if ( !event ) return; 2627 if ( !event ) return;
2620 if ( event->isReadOnly() ) { 2628 if ( event->isReadOnly() ) {
2621 showEvent( event ); 2629 showEvent( event );
2622 return; 2630 return;
2623 } 2631 }
2624 mEventEditor->editEvent( event , mFlagEditDescription); 2632 mEventEditor->editEvent( event , mFlagEditDescription);
2625 showEventEditor(); 2633 showEventEditor();
2626} 2634}
2627void CalendarView::editJournal( Journal *jour ) 2635void CalendarView::editJournal( Journal *jour )
2628{ 2636{
2629 if ( !jour ) return; 2637 if ( !jour ) return;
2630 mDialogManager->hideSearchDialog(); 2638 mDialogManager->hideSearchDialog();
2631 mViewManager->showJournalView(); 2639 mViewManager->showJournalView();
2632 mNavigator->slotDaySelect( jour->dtStart().date() ); 2640 mNavigator->slotDaySelect( jour->dtStart().date() );
2633} 2641}
2634void CalendarView::editTodo( Todo *todo ) 2642void CalendarView::editTodo( Todo *todo )
2635{ 2643{
2636 if ( !todo ) return; 2644 if ( !todo ) return;
2637 2645
2638 if ( todo->isReadOnly() ) { 2646 if ( todo->isReadOnly() ) {
2639 showTodo( todo ); 2647 showTodo( todo );
2640 return; 2648 return;
2641 } 2649 }
2642 mTodoEditor->editTodo( todo ,mFlagEditDescription); 2650 mTodoEditor->editTodo( todo ,mFlagEditDescription);
2643 showTodoEditor(); 2651 showTodoEditor();
2644 2652
2645} 2653}
2646 2654
2647KOEventViewerDialog* CalendarView::getEventViewerDialog() 2655KOEventViewerDialog* CalendarView::getEventViewerDialog()
2648{ 2656{
2649 if ( !mEventViewerDialog ) { 2657 if ( !mEventViewerDialog ) {
2650 mEventViewerDialog = new KOEventViewerDialog(this); 2658 mEventViewerDialog = new KOEventViewerDialog(this);
2651 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 2659 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
2652 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 2660 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
2653 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 2661 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
2654 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 2662 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
2655 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 2663 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
2656 viewManager(), SLOT( showAgendaView( bool ) ) ); 2664 viewManager(), SLOT( showAgendaView( bool ) ) );
2657 mEventViewerDialog->resize( 640, 480 ); 2665 mEventViewerDialog->resize( 640, 480 );
2658 2666
2659 } 2667 }
2660 return mEventViewerDialog; 2668 return mEventViewerDialog;
2661} 2669}
2662void CalendarView::showEvent(Event *event) 2670void CalendarView::showEvent(Event *event)
2663{ 2671{
2664 getEventViewerDialog()->setEvent(event); 2672 getEventViewerDialog()->setEvent(event);
2665 getEventViewerDialog()->showMe(); 2673 getEventViewerDialog()->showMe();
2666} 2674}
2667 2675
2668void CalendarView::showTodo(Todo *event) 2676void CalendarView::showTodo(Todo *event)
2669{ 2677{
2670 getEventViewerDialog()->setTodo(event); 2678 getEventViewerDialog()->setTodo(event);
2671 getEventViewerDialog()->showMe(); 2679 getEventViewerDialog()->showMe();
2672} 2680}
2673void CalendarView::showJournal( Journal *jour ) 2681void CalendarView::showJournal( Journal *jour )
2674{ 2682{
2675 getEventViewerDialog()->setJournal(jour); 2683 getEventViewerDialog()->setJournal(jour);
2676 getEventViewerDialog()->showMe(); 2684 getEventViewerDialog()->showMe();
2677 2685
2678} 2686}
2679// void CalendarView::todoModified (Todo *event, int changed) 2687// void CalendarView::todoModified (Todo *event, int changed)
2680// { 2688// {
2681// // if (mDialogList.find (event) != mDialogList.end ()) { 2689// // if (mDialogList.find (event) != mDialogList.end ()) {
2682// // kdDebug() << "Todo modified and open" << endl; 2690// // kdDebug() << "Todo modified and open" << endl;
2683// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 2691// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
2684// // temp->modified (changed); 2692// // temp->modified (changed);
2685 2693
2686// // } 2694// // }
2687 2695
2688// mViewManager->updateView(); 2696// mViewManager->updateView();
2689// } 2697// }
2690 2698
2691void CalendarView::appointment_show() 2699void CalendarView::appointment_show()
2692{ 2700{
2693 Event *anEvent = 0; 2701 Event *anEvent = 0;
2694 2702
2695 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2703 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2696 2704
2697 if (mViewManager->currentView()->isEventView()) { 2705 if (mViewManager->currentView()->isEventView()) {
2698 if ( incidence && incidence->type() == "Event" ) { 2706 if ( incidence && incidence->type() == "Event" ) {
2699 anEvent = static_cast<Event *>(incidence); 2707 anEvent = static_cast<Event *>(incidence);
2700 } 2708 }
2701 } 2709 }
2702 2710
2703 if (!anEvent) { 2711 if (!anEvent) {
2704 KNotifyClient::beep(); 2712 KNotifyClient::beep();
2705 return; 2713 return;
2706 } 2714 }
2707 2715
2708 showEvent(anEvent); 2716 showEvent(anEvent);
2709} 2717}
2710 2718
2711void CalendarView::appointment_edit() 2719void CalendarView::appointment_edit()
2712{ 2720{
2713 Event *anEvent = 0; 2721 Event *anEvent = 0;
2714 2722
2715 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2723 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2716 2724
2717 if (mViewManager->currentView()->isEventView()) { 2725 if (mViewManager->currentView()->isEventView()) {
2718 if ( incidence && incidence->type() == "Event" ) { 2726 if ( incidence && incidence->type() == "Event" ) {
2719 anEvent = static_cast<Event *>(incidence); 2727 anEvent = static_cast<Event *>(incidence);
2720 } 2728 }
2721 } 2729 }
2722 2730
2723 if (!anEvent) { 2731 if (!anEvent) {
2724 KNotifyClient::beep(); 2732 KNotifyClient::beep();
2725 return; 2733 return;
2726 } 2734 }
2727 2735
2728 editEvent(anEvent); 2736 editEvent(anEvent);
2729} 2737}
2730 2738
2731void CalendarView::appointment_delete() 2739void CalendarView::appointment_delete()
2732{ 2740{
2733 Event *anEvent = 0; 2741 Event *anEvent = 0;
2734 2742
2735 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2743 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2736 2744
2737 if (mViewManager->currentView()->isEventView()) { 2745 if (mViewManager->currentView()->isEventView()) {
2738 if ( incidence && incidence->type() == "Event" ) { 2746 if ( incidence && incidence->type() == "Event" ) {
2739 anEvent = static_cast<Event *>(incidence); 2747 anEvent = static_cast<Event *>(incidence);
2740 } 2748 }
2741 } 2749 }
2742 2750
2743 if (!anEvent) { 2751 if (!anEvent) {
2744 KNotifyClient::beep(); 2752 KNotifyClient::beep();
2745 return; 2753 return;
2746 } 2754 }
2747 2755
2748 deleteEvent(anEvent); 2756 deleteEvent(anEvent);
2749} 2757}
2750 2758
2751void CalendarView::todo_resub( Todo * parent, Todo * sub ) 2759void CalendarView::todo_resub( Todo * parent, Todo * sub )
2752{ 2760{
2753 if (!sub) return; 2761 if (!sub) return;
2754 if (!parent) return; 2762 if (!parent) return;
2755 if ( sub->relatedTo() ) 2763 if ( sub->relatedTo() )
2756 sub->relatedTo()->removeRelation(sub); 2764 sub->relatedTo()->removeRelation(sub);
2757 sub->setRelatedTo(parent); 2765 sub->setRelatedTo(parent);
2758 sub->setRelatedToUid(parent->uid()); 2766 sub->setRelatedToUid(parent->uid());
2759 parent->addRelation(sub); 2767 parent->addRelation(sub);
2760 sub->updated(); 2768 sub->updated();
2761 parent->updated(); 2769 parent->updated();
2762 setModified(true); 2770 setModified(true);
2763 updateView(); 2771 updateView();
2764} 2772}
2765void CalendarView::todo_unsub(Todo *anTodo ) 2773void CalendarView::todo_unsub(Todo *anTodo )
2766{ 2774{
2767 // Todo *anTodo = selectedTodo(); 2775 // Todo *anTodo = selectedTodo();
2768 if (!anTodo) return; 2776 if (!anTodo) return;
2769 if (!anTodo->relatedTo()) return; 2777 if (!anTodo->relatedTo()) return;
2770 anTodo->relatedTo()->removeRelation(anTodo); 2778 anTodo->relatedTo()->removeRelation(anTodo);
2771 anTodo->setRelatedTo(0); 2779 anTodo->setRelatedTo(0);
2772 anTodo->updated(); 2780 anTodo->updated();
2773 anTodo->setRelatedToUid(""); 2781 anTodo->setRelatedToUid("");
2774 setModified(true); 2782 setModified(true);
2775 updateView(); 2783 updateView();
2776} 2784}
2777 2785
2778void CalendarView::deleteTodo(Todo *todo) 2786void CalendarView::deleteTodo(Todo *todo)
2779{ 2787{
2780 if (!todo) { 2788 if (!todo) {
2781 KNotifyClient::beep(); 2789 KNotifyClient::beep();
2782 return; 2790 return;
2783 } 2791 }
2784 if (KOPrefs::instance()->mConfirm) { 2792 if (KOPrefs::instance()->mConfirm) {
2785 switch (msgItemDelete()) { 2793 switch (msgItemDelete()) {
2786 case KMessageBox::Continue: // OK 2794 case KMessageBox::Continue: // OK
2787 if (!todo->relations().isEmpty()) { 2795 if (!todo->relations().isEmpty()) {
2788 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), 2796 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."),
2789 i18n("Delete To-Do")); 2797 i18n("Delete To-Do"));
2790 } else { 2798 } else {
2791 checkExternalId( todo ); 2799 checkExternalId( todo );
2792 calendar()->deleteTodo(todo); 2800 calendar()->deleteTodo(todo);
2793 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2801 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2794 updateView(); 2802 updateView();
2795 } 2803 }
2796 break; 2804 break;
2797 } // switch 2805 } // switch
2798 } else { 2806 } else {
2799 if (!todo->relations().isEmpty()) { 2807 if (!todo->relations().isEmpty()) {
2800 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), 2808 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."),
2801 i18n("Delete To-Do")); 2809 i18n("Delete To-Do"));
2802 } else { 2810 } else {
2803 checkExternalId( todo ); 2811 checkExternalId( todo );
2804 mCalendar->deleteTodo(todo); 2812 mCalendar->deleteTodo(todo);
2805 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2813 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2806 updateView(); 2814 updateView();
2807 } 2815 }
2808 } 2816 }
2809 emit updateSearchDialog(); 2817 emit updateSearchDialog();
2810} 2818}
2811void CalendarView::deleteJournal(Journal *jour) 2819void CalendarView::deleteJournal(Journal *jour)
2812{ 2820{
2813 if (!jour) { 2821 if (!jour) {
2814 KNotifyClient::beep(); 2822 KNotifyClient::beep();
2815 return; 2823 return;
2816 } 2824 }
2817 if (KOPrefs::instance()->mConfirm) { 2825 if (KOPrefs::instance()->mConfirm) {
2818 switch (msgItemDelete()) { 2826 switch (msgItemDelete()) {
2819 case KMessageBox::Continue: // OK 2827 case KMessageBox::Continue: // OK
2820 calendar()->deleteJournal(jour); 2828 calendar()->deleteJournal(jour);
2821 updateView(); 2829 updateView();
2822 break; 2830 break;
2823 } // switch 2831 } // switch
2824 } else { 2832 } else {
2825 calendar()->deleteJournal(jour);; 2833 calendar()->deleteJournal(jour);;
2826 updateView(); 2834 updateView();
2827 } 2835 }
2828 emit updateSearchDialog(); 2836 emit updateSearchDialog();
2829} 2837}
2830 2838
2831void CalendarView::deleteEvent(Event *anEvent) 2839void CalendarView::deleteEvent(Event *anEvent)
2832{ 2840{
2833 if (!anEvent) { 2841 if (!anEvent) {
2834 KNotifyClient::beep(); 2842 KNotifyClient::beep();
2835 return; 2843 return;
2836 } 2844 }
2837 2845
2838 if (anEvent->recurrence()->doesRecur()) { 2846 if (anEvent->recurrence()->doesRecur()) {
2839 QDate itemDate = mViewManager->currentSelectionDate(); 2847 QDate itemDate = mViewManager->currentSelectionDate();
2840 int km; 2848 int km;
2841 if (!itemDate.isValid()) { 2849 if (!itemDate.isValid()) {
2842 //kdDebug() << "Date Not Valid" << endl; 2850 //kdDebug() << "Date Not Valid" << endl;
2843 if (KOPrefs::instance()->mConfirm) { 2851 if (KOPrefs::instance()->mConfirm) {
2844 km = KMessageBox::warningContinueCancel(this,anEvent->summary() + 2852 km = KMessageBox::warningContinueCancel(this,anEvent->summary() +
2845 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 2853 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
2846 i18n("KO/Pi Confirmation"),i18n("Delete All")); 2854 i18n("KO/Pi Confirmation"),i18n("Delete All"));
2847 if ( km == KMessageBox::Continue ) 2855 if ( km == KMessageBox::Continue )
2848 km = KMessageBox::No; // No = all below 2856 km = KMessageBox::No; // No = all below
2849 } else 2857 } else
2850 km = KMessageBox::No; 2858 km = KMessageBox::No;
2851 } else { 2859 } else {
2852 km = KMessageBox::warningYesNoCancel(this,anEvent->summary() + 2860 km = KMessageBox::warningYesNoCancel(this,anEvent->summary() +
2853 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 2861 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
2854 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 2862 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
2855 i18n("KO/Pi Confirmation"),i18n("Current"), 2863 i18n("KO/Pi Confirmation"),i18n("Current"),
2856 i18n("All")); 2864 i18n("All"));
2857 } 2865 }
2858 switch(km) { 2866 switch(km) {
2859 2867
2860 case KMessageBox::No: // Continue // all 2868 case KMessageBox::No: // Continue // all
2861 //qDebug("KMessageBox::No "); 2869 //qDebug("KMessageBox::No ");
2862 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2870 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2863 schedule(Scheduler::Cancel,anEvent); 2871 schedule(Scheduler::Cancel,anEvent);
2864 2872
2865 checkExternalId( anEvent); 2873 checkExternalId( anEvent);
2866 mCalendar->deleteEvent(anEvent); 2874 mCalendar->deleteEvent(anEvent);
2867 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 2875 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
2868 break; 2876 break;
2869 2877
2870 // Disabled because it does not work 2878 // Disabled because it does not work
2871 //#if 0 2879 //#if 0
2872 case KMessageBox::Yes: // just this one 2880 case KMessageBox::Yes: // just this one
2873 //QDate qd = mNavigator->selectedDates().first(); 2881 //QDate qd = mNavigator->selectedDates().first();
2874 //if (!qd.isValid()) { 2882 //if (!qd.isValid()) {
2875 // kdDebug() << "no date selected, or invalid date" << endl; 2883 // kdDebug() << "no date selected, or invalid date" << endl;
2876 // KNotifyClient::beep(); 2884 // KNotifyClient::beep();
2877 // return; 2885 // return;
2878 //} 2886 //}
2879 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 2887 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
2880 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 2888 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
2881 anEvent->addExDate(itemDate); 2889 anEvent->addExDate(itemDate);
2882 int duration = anEvent->recurrence()->duration(); 2890 int duration = anEvent->recurrence()->duration();
2883 if ( duration > 0 ) { 2891 if ( duration > 0 ) {
2884 anEvent->recurrence()->setDuration( duration - 1 ); 2892 anEvent->recurrence()->setDuration( duration - 1 );
2885 } 2893 }
2886 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 2894 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
2887 } 2895 }
2888 break; 2896 break;
2889 //#endif 2897 //#endif
2890 } // switch 2898 } // switch
2891 } else { 2899 } else {
2892 if (KOPrefs::instance()->mConfirm) { 2900 if (KOPrefs::instance()->mConfirm) {
2893 switch (KMessageBox::warningContinueCancel(this,anEvent->summary() + 2901 switch (KMessageBox::warningContinueCancel(this,anEvent->summary() +
2894 i18n("\nAre you sure you want\nto delete this event?"), 2902 i18n("\nAre you sure you want\nto delete this event?"),
2895 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 2903 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
2896 case KMessageBox::Continue: // OK 2904 case KMessageBox::Continue: // OK
2897 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2905 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2898 schedule(Scheduler::Cancel,anEvent); 2906 schedule(Scheduler::Cancel,anEvent);
2899 checkExternalId( anEvent); 2907 checkExternalId( anEvent);
2900 mCalendar->deleteEvent(anEvent); 2908 mCalendar->deleteEvent(anEvent);
2901 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2909 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2902 break; 2910 break;
2903 } // switch 2911 } // switch
2904 } else { 2912 } else {
2905 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2913 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2906 schedule(Scheduler::Cancel,anEvent); 2914 schedule(Scheduler::Cancel,anEvent);
2907 checkExternalId( anEvent); 2915 checkExternalId( anEvent);
2908 mCalendar->deleteEvent(anEvent); 2916 mCalendar->deleteEvent(anEvent);
2909 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2917 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2910 } 2918 }
2911 } // if-else 2919 } // if-else
2912 emit updateSearchDialog(); 2920 emit updateSearchDialog();
2913} 2921}
2914 2922
2915bool CalendarView::deleteEvent(const QString &uid) 2923bool CalendarView::deleteEvent(const QString &uid)
2916{ 2924{
2917 Event *ev = mCalendar->event(uid); 2925 Event *ev = mCalendar->event(uid);
2918 if (ev) { 2926 if (ev) {
2919 deleteEvent(ev); 2927 deleteEvent(ev);
2920 return true; 2928 return true;
2921 } else { 2929 } else {
2922 return false; 2930 return false;
2923 } 2931 }
2924} 2932}
2925 2933
2926/*****************************************************************************/ 2934/*****************************************************************************/
2927 2935
2928void CalendarView::action_mail() 2936void CalendarView::action_mail()
2929{ 2937{
2930#ifndef KORG_NOMAIL 2938#ifndef KORG_NOMAIL
2931 KOMailClient mailClient; 2939 KOMailClient mailClient;
2932 2940
2933 Incidence *incidence = currentSelection(); 2941 Incidence *incidence = currentSelection();
2934 2942
2935 if (!incidence) { 2943 if (!incidence) {
2936 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 2944 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
2937 return; 2945 return;
2938 } 2946 }
2939 if(incidence->attendeeCount() == 0 ) { 2947 if(incidence->attendeeCount() == 0 ) {
2940 KMessageBox::sorry(this, 2948 KMessageBox::sorry(this,
2941 i18n("Can't generate mail:\nNo attendees defined.\n")); 2949 i18n("Can't generate mail:\nNo attendees defined.\n"));
2942 return; 2950 return;
2943 } 2951 }
2944 2952
2945 CalendarLocal cal_tmp; 2953 CalendarLocal cal_tmp;
2946 Event *event = 0; 2954 Event *event = 0;
2947 Event *ev = 0; 2955 Event *ev = 0;
2948 if ( incidence && incidence->type() == "Event" ) { 2956 if ( incidence && incidence->type() == "Event" ) {
2949 event = static_cast<Event *>(incidence); 2957 event = static_cast<Event *>(incidence);
2950 ev = new Event(*event); 2958 ev = new Event(*event);
2951 cal_tmp.addEvent(ev); 2959 cal_tmp.addEvent(ev);
2952 } 2960 }
2953 ICalFormat mForm(); 2961 ICalFormat mForm();
2954 QString attachment = mForm.toString( &cal_tmp ); 2962 QString attachment = mForm.toString( &cal_tmp );
2955 if (ev) delete(ev); 2963 if (ev) delete(ev);
2956 2964
2957 mailClient.mailAttendees(currentSelection(), attachment); 2965 mailClient.mailAttendees(currentSelection(), attachment);
2958 2966
2959#endif 2967#endif
2960 2968
2961#if 0 2969#if 0
2962 Event *anEvent = 0; 2970 Event *anEvent = 0;
2963 if (mViewManager->currentView()->isEventView()) { 2971 if (mViewManager->currentView()->isEventView()) {
2964 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); 2972 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
2965 } 2973 }
2966 2974
2967 if (!anEvent) { 2975 if (!anEvent) {
2968 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 2976 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
2969 return; 2977 return;
2970 } 2978 }
2971 if(anEvent->attendeeCount() == 0 ) { 2979 if(anEvent->attendeeCount() == 0 ) {
2972 KMessageBox::sorry(this, 2980 KMessageBox::sorry(this,
2973 i18n("Can't generate mail:\nNo attendees defined.\n")); 2981 i18n("Can't generate mail:\nNo attendees defined.\n"));
2974 return; 2982 return;
2975 } 2983 }
2976 2984
2977 mailobject.emailEvent(anEvent); 2985 mailobject.emailEvent(anEvent);
2978#endif 2986#endif
2979} 2987}
2980 2988
2981 2989
2982void CalendarView::schedule_publish(Incidence *incidence) 2990void CalendarView::schedule_publish(Incidence *incidence)
2983{ 2991{
2984 Event *event = 0; 2992 Event *event = 0;
2985 Todo *todo = 0; 2993 Todo *todo = 0;
2986 2994
2987 if (incidence == 0) { 2995 if (incidence == 0) {
2988 incidence = mViewManager->currentView()->selectedIncidences().first(); 2996 incidence = mViewManager->currentView()->selectedIncidences().first();
2989 if (incidence == 0) { 2997 if (incidence == 0) {
2990 incidence = mTodoList->selectedIncidences().first(); 2998 incidence = mTodoList->selectedIncidences().first();
2991 } 2999 }
2992 } 3000 }
2993 if ( incidence && incidence->type() == "Event" ) { 3001 if ( incidence && incidence->type() == "Event" ) {
2994 event = static_cast<Event *>(incidence); 3002 event = static_cast<Event *>(incidence);
2995 } else { 3003 } else {
2996 if ( incidence && incidence->type() == "Todo" ) { 3004 if ( incidence && incidence->type() == "Todo" ) {
2997 todo = static_cast<Todo *>(incidence); 3005 todo = static_cast<Todo *>(incidence);
2998 } 3006 }
2999 } 3007 }
3000 3008
3001 if (!event && !todo) { 3009 if (!event && !todo) {
3002 KMessageBox::sorry(this,i18n("No event selected.")); 3010 KMessageBox::sorry(this,i18n("No event selected."));
3003 return; 3011 return;
3004 } 3012 }
3005 3013
3006 PublishDialog *publishdlg = new PublishDialog(); 3014 PublishDialog *publishdlg = new PublishDialog();
3007 if (incidence->attendeeCount()>0) { 3015 if (incidence->attendeeCount()>0) {
3008 QPtrList<Attendee> attendees = incidence->attendees(); 3016 QPtrList<Attendee> attendees = incidence->attendees();
3009 attendees.first(); 3017 attendees.first();
3010 while ( attendees.current()!=0 ) { 3018 while ( attendees.current()!=0 ) {
3011 publishdlg->addAttendee(attendees.current()); 3019 publishdlg->addAttendee(attendees.current());
3012 attendees.next(); 3020 attendees.next();
3013 } 3021 }
3014 } 3022 }
3015 bool send = true; 3023 bool send = true;
3016 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 3024 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
3017 if ( publishdlg->exec() != QDialog::Accepted ) 3025 if ( publishdlg->exec() != QDialog::Accepted )
3018 send = false; 3026 send = false;
3019 } 3027 }
3020 if ( send ) { 3028 if ( send ) {
3021 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3029 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3022 if ( event ) { 3030 if ( event ) {
3023 Event *ev = new Event(*event); 3031 Event *ev = new Event(*event);
3024 ev->registerObserver(0); 3032 ev->registerObserver(0);
3025 ev->clearAttendees(); 3033 ev->clearAttendees();
3026 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3034 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3027 delete(ev); 3035 delete(ev);
3028 } 3036 }
3029 } else { 3037 } else {
3030 if ( todo ) { 3038 if ( todo ) {
3031 Todo *ev = new Todo(*todo); 3039 Todo *ev = new Todo(*todo);
3032 ev->registerObserver(0); 3040 ev->registerObserver(0);
3033 ev->clearAttendees(); 3041 ev->clearAttendees();
3034 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3042 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3035 delete(ev); 3043 delete(ev);
3036 } 3044 }
3037 } 3045 }
3038 } 3046 }
3039 } 3047 }
3040 delete publishdlg; 3048 delete publishdlg;
3041} 3049}
3042 3050
3043void CalendarView::schedule_request(Incidence *incidence) 3051void CalendarView::schedule_request(Incidence *incidence)
3044{ 3052{
3045 schedule(Scheduler::Request,incidence); 3053 schedule(Scheduler::Request,incidence);
3046} 3054}
3047 3055
3048void CalendarView::schedule_refresh(Incidence *incidence) 3056void CalendarView::schedule_refresh(Incidence *incidence)
3049{ 3057{
3050 schedule(Scheduler::Refresh,incidence); 3058 schedule(Scheduler::Refresh,incidence);
3051} 3059}
3052 3060
3053void CalendarView::schedule_cancel(Incidence *incidence) 3061void CalendarView::schedule_cancel(Incidence *incidence)
3054{ 3062{
3055 schedule(Scheduler::Cancel,incidence); 3063 schedule(Scheduler::Cancel,incidence);
3056} 3064}
3057 3065
3058void CalendarView::schedule_add(Incidence *incidence) 3066void CalendarView::schedule_add(Incidence *incidence)
3059{ 3067{
3060 schedule(Scheduler::Add,incidence); 3068 schedule(Scheduler::Add,incidence);
3061} 3069}
3062 3070
3063void CalendarView::schedule_reply(Incidence *incidence) 3071void CalendarView::schedule_reply(Incidence *incidence)
3064{ 3072{
3065 schedule(Scheduler::Reply,incidence); 3073 schedule(Scheduler::Reply,incidence);
3066} 3074}
3067 3075
3068void CalendarView::schedule_counter(Incidence *incidence) 3076void CalendarView::schedule_counter(Incidence *incidence)
3069{ 3077{
3070 schedule(Scheduler::Counter,incidence); 3078 schedule(Scheduler::Counter,incidence);
3071} 3079}
3072 3080
3073void CalendarView::schedule_declinecounter(Incidence *incidence) 3081void CalendarView::schedule_declinecounter(Incidence *incidence)
3074{ 3082{
3075 schedule(Scheduler::Declinecounter,incidence); 3083 schedule(Scheduler::Declinecounter,incidence);
3076} 3084}
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index a3977d7..eeb5f48 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -1,441 +1,457 @@
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) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2000,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#include <stdlib.h> 22#include <stdlib.h>
23#include <time.h> 23#include <time.h>
24 24
25#include <kdebug.h> 25#include <kdebug.h>
26#include <kglobal.h> 26#include <kglobal.h>
27#include <klocale.h> 27#include <klocale.h>
28 28
29#include "exceptions.h" 29#include "exceptions.h"
30#include "calfilter.h" 30#include "calfilter.h"
31 31
32#include "calendar.h" 32#include "calendar.h"
33#include "syncdefines.h" 33#include "syncdefines.h"
34 34
35using namespace KCal; 35using namespace KCal;
36 36
37Calendar::Calendar() 37Calendar::Calendar()
38{ 38{
39 39
40 init(); 40 init();
41 setTimeZoneId( i18n (" 00:00 Europe/London(UTC)") ); 41 setTimeZoneId( i18n (" 00:00 Europe/London(UTC)") );
42} 42}
43 43
44Calendar::Calendar( const QString &timeZoneId ) 44Calendar::Calendar( const QString &timeZoneId )
45{ 45{
46 46
47 init(); 47 init();
48 setTimeZoneId(timeZoneId); 48 setTimeZoneId(timeZoneId);
49} 49}
50 50
51void Calendar::init() 51void Calendar::init()
52{ 52{
53 mObserver = 0; 53 mObserver = 0;
54 mNewObserver = false; 54 mNewObserver = false;
55 55
56 mModified = false; 56 mModified = false;
57 57
58 // Setup default filter, which does nothing 58 // Setup default filter, which does nothing
59 mDefaultFilter = new CalFilter; 59 mDefaultFilter = new CalFilter;
60 mFilter = mDefaultFilter; 60 mFilter = mDefaultFilter;
61 mFilter->setEnabled(false); 61 mFilter->setEnabled(false);
62 62
63 // initialize random numbers. This is a hack, and not 63 // initialize random numbers. This is a hack, and not
64 // even that good of one at that. 64 // even that good of one at that.
65// srandom(time(0)); 65// srandom(time(0));
66 66
67 // user information... 67 // user information...
68 setOwner(i18n("Unknown Name")); 68 setOwner(i18n("Unknown Name"));
69 setEmail(i18n("unknown@nowhere")); 69 setEmail(i18n("unknown@nowhere"));
70 70
71#if 0 71#if 0
72 tmpStr = KOPrefs::instance()->mTimeZone; 72 tmpStr = KOPrefs::instance()->mTimeZone;
73// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; 73// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl;
74 int dstSetting = KOPrefs::instance()->mDaylightSavings; 74 int dstSetting = KOPrefs::instance()->mDaylightSavings;
75 extern long int timezone; 75 extern long int timezone;
76 struct tm *now; 76 struct tm *now;
77 time_t curtime; 77 time_t curtime;
78 curtime = time(0); 78 curtime = time(0);
79 now = localtime(&curtime); 79 now = localtime(&curtime);
80 int hourOff = - ((timezone / 60) / 60); 80 int hourOff = - ((timezone / 60) / 60);
81 if (now->tm_isdst) 81 if (now->tm_isdst)
82 hourOff += 1; 82 hourOff += 1;
83 QString tzStr; 83 QString tzStr;
84 tzStr.sprintf("%.2d%.2d", 84 tzStr.sprintf("%.2d%.2d",
85 hourOff, 85 hourOff,
86 abs((timezone / 60) % 60)); 86 abs((timezone / 60) % 60));
87 87
88 // if no time zone was in the config file, write what we just discovered. 88 // if no time zone was in the config file, write what we just discovered.
89 if (tmpStr.isEmpty()) { 89 if (tmpStr.isEmpty()) {
90// KOPrefs::instance()->mTimeZone = tzStr; 90// KOPrefs::instance()->mTimeZone = tzStr;
91 } else { 91 } else {
92 tzStr = tmpStr; 92 tzStr = tmpStr;
93 } 93 }
94 94
95 // if daylight savings has changed since last load time, we need 95 // if daylight savings has changed since last load time, we need
96 // to rewrite these settings to the config file. 96 // to rewrite these settings to the config file.
97 if ((now->tm_isdst && !dstSetting) || 97 if ((now->tm_isdst && !dstSetting) ||
98 (!now->tm_isdst && dstSetting)) { 98 (!now->tm_isdst && dstSetting)) {
99 KOPrefs::instance()->mTimeZone = tzStr; 99 KOPrefs::instance()->mTimeZone = tzStr;
100 KOPrefs::instance()->mDaylightSavings = now->tm_isdst; 100 KOPrefs::instance()->mDaylightSavings = now->tm_isdst;
101 } 101 }
102 102
103 setTimeZone(tzStr); 103 setTimeZone(tzStr);
104#endif 104#endif
105 105
106// KOPrefs::instance()->writeConfig(); 106// KOPrefs::instance()->writeConfig();
107} 107}
108 108
109Calendar::~Calendar() 109Calendar::~Calendar()
110{ 110{
111 delete mDefaultFilter; 111 delete mDefaultFilter;
112} 112}
113 113
114const QString &Calendar::getOwner() const 114const QString &Calendar::getOwner() const
115{ 115{
116 return mOwner; 116 return mOwner;
117} 117}
118 118
119void Calendar::setOwner(const QString &os) 119void Calendar::setOwner(const QString &os)
120{ 120{
121 int i; 121 int i;
122 mOwner = os; 122 mOwner = os;
123 i = mOwner.find(','); 123 i = mOwner.find(',');
124 if (i != -1) 124 if (i != -1)
125 mOwner = mOwner.left(i); 125 mOwner = mOwner.left(i);
126 126
127 setModified( true ); 127 setModified( true );
128} 128}
129 129
130void Calendar::setTimeZone(const QString & tz) 130void Calendar::setTimeZone(const QString & tz)
131{ 131{
132 bool neg = FALSE; 132 bool neg = FALSE;
133 int hours, minutes; 133 int hours, minutes;
134 QString tmpStr(tz); 134 QString tmpStr(tz);
135 135
136 if (tmpStr.left(1) == "-") 136 if (tmpStr.left(1) == "-")
137 neg = TRUE; 137 neg = TRUE;
138 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") 138 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+")
139 tmpStr.remove(0, 1); 139 tmpStr.remove(0, 1);
140 hours = tmpStr.left(2).toInt(); 140 hours = tmpStr.left(2).toInt();
141 if (tmpStr.length() > 2) 141 if (tmpStr.length() > 2)
142 minutes = tmpStr.right(2).toInt(); 142 minutes = tmpStr.right(2).toInt();
143 else 143 else
144 minutes = 0; 144 minutes = 0;
145 mTimeZone = (60*hours+minutes); 145 mTimeZone = (60*hours+minutes);
146 if (neg) 146 if (neg)
147 mTimeZone = -mTimeZone; 147 mTimeZone = -mTimeZone;
148 mLocalTime = false; 148 mLocalTime = false;
149 149
150 setModified( true ); 150 setModified( true );
151} 151}
152 152
153QString Calendar::getTimeZoneStr() const 153QString Calendar::getTimeZoneStr() const
154{ 154{
155 if (mLocalTime) 155 if (mLocalTime)
156 return ""; 156 return "";
157 QString tmpStr; 157 QString tmpStr;
158 int hours = abs(mTimeZone / 60); 158 int hours = abs(mTimeZone / 60);
159 int minutes = abs(mTimeZone % 60); 159 int minutes = abs(mTimeZone % 60);
160 bool neg = mTimeZone < 0; 160 bool neg = mTimeZone < 0;
161 161
162 tmpStr.sprintf("%c%.2d%.2d", 162 tmpStr.sprintf("%c%.2d%.2d",
163 (neg ? '-' : '+'), 163 (neg ? '-' : '+'),
164 hours, minutes); 164 hours, minutes);
165 return tmpStr; 165 return tmpStr;
166} 166}
167 167
168void Calendar::setTimeZone(int tz) 168void Calendar::setTimeZone(int tz)
169{ 169{
170 mTimeZone = tz; 170 mTimeZone = tz;
171 mLocalTime = false; 171 mLocalTime = false;
172 172
173 setModified( true ); 173 setModified( true );
174} 174}
175 175
176int Calendar::getTimeZone() const 176int Calendar::getTimeZone() const
177{ 177{
178 return mTimeZone; 178 return mTimeZone;
179} 179}
180 180
181void Calendar::setTimeZoneId(const QString &id) 181void Calendar::setTimeZoneId(const QString &id)
182{ 182{
183 mTimeZoneId = id; 183 mTimeZoneId = id;
184 mLocalTime = false; 184 mLocalTime = false;
185 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); 185 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId);
186 if ( mTimeZone > 1000) 186 if ( mTimeZone > 1000)
187 setLocalTime(); 187 setLocalTime();
188 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); 188 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone);
189 setModified( true ); 189 setModified( true );
190} 190}
191 191
192QString Calendar::timeZoneId() const 192QString Calendar::timeZoneId() const
193{ 193{
194 return mTimeZoneId; 194 return mTimeZoneId;
195} 195}
196 196
197void Calendar::setLocalTime() 197void Calendar::setLocalTime()
198{ 198{
199 //qDebug("Calendar::setLocalTime() "); 199 //qDebug("Calendar::setLocalTime() ");
200 mLocalTime = true; 200 mLocalTime = true;
201 mTimeZone = 0; 201 mTimeZone = 0;
202 mTimeZoneId = ""; 202 mTimeZoneId = "";
203 203
204 setModified( true ); 204 setModified( true );
205} 205}
206 206
207bool Calendar::isLocalTime() const 207bool Calendar::isLocalTime() const
208{ 208{
209 return mLocalTime; 209 return mLocalTime;
210} 210}
211 211
212const QString &Calendar::getEmail() 212const QString &Calendar::getEmail()
213{ 213{
214 return mOwnerEmail; 214 return mOwnerEmail;
215} 215}
216 216
217void Calendar::setEmail(const QString &e) 217void Calendar::setEmail(const QString &e)
218{ 218{
219 mOwnerEmail = e; 219 mOwnerEmail = e;
220 220
221 setModified( true ); 221 setModified( true );
222} 222}
223 223
224void Calendar::setFilter(CalFilter *filter) 224void Calendar::setFilter(CalFilter *filter)
225{ 225{
226 mFilter = filter; 226 mFilter = filter;
227} 227}
228 228
229CalFilter *Calendar::filter() 229CalFilter *Calendar::filter()
230{ 230{
231 return mFilter; 231 return mFilter;
232} 232}
233 233
234QPtrList<Incidence> Calendar::incidences() 234QPtrList<Incidence> Calendar::incidences()
235{ 235{
236 QPtrList<Incidence> incidences; 236 QPtrList<Incidence> incidences;
237 237
238 Incidence *i; 238 Incidence *i;
239 239
240 QPtrList<Event> e = events(); 240 QPtrList<Event> e = events();
241 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 241 for( i = e.first(); i; i = e.next() ) incidences.append( i );
242 242
243 QPtrList<Todo> t = todos(); 243 QPtrList<Todo> t = todos();
244 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 244 for( i = t.first(); i; i = t.next() ) incidences.append( i );
245 245
246 QPtrList<Journal> j = journals(); 246 QPtrList<Journal> j = journals();
247 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 247 for( i = j.first(); i; i = j.next() ) incidences.append( i );
248 248
249 return incidences; 249 return incidences;
250} 250}
251
252void Calendar::resetPilotStat()
253{
254 QPtrList<Incidence> incidences;
255
256 Incidence *i;
257
258 QPtrList<Event> e = rawEvents();
259 for( i = e.first(); i; i = e.next() ) i->setPilotId( 0 );
260
261 QPtrList<Todo> t = rawTodos();
262 for( i = t.first(); i; i = t.next() ) i->setPilotId( 0 );
263
264 QPtrList<Journal> j = journals();
265 for( i = j.first(); i; i = j.next() ) i->setPilotId( 0 );
266}
251void Calendar::resetTempSyncStat() 267void Calendar::resetTempSyncStat()
252{ 268{
253 QPtrList<Incidence> incidences; 269 QPtrList<Incidence> incidences;
254 270
255 Incidence *i; 271 Incidence *i;
256 272
257 QPtrList<Event> e = rawEvents(); 273 QPtrList<Event> e = rawEvents();
258 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 274 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
259 275
260 QPtrList<Todo> t = rawTodos(); 276 QPtrList<Todo> t = rawTodos();
261 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 277 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
262 278
263 QPtrList<Journal> j = journals(); 279 QPtrList<Journal> j = journals();
264 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 280 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
265} 281}
266QPtrList<Incidence> Calendar::rawIncidences() 282QPtrList<Incidence> Calendar::rawIncidences()
267{ 283{
268 QPtrList<Incidence> incidences; 284 QPtrList<Incidence> incidences;
269 285
270 Incidence *i; 286 Incidence *i;
271 287
272 QPtrList<Event> e = rawEvents(); 288 QPtrList<Event> e = rawEvents();
273 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 289 for( i = e.first(); i; i = e.next() ) incidences.append( i );
274 290
275 QPtrList<Todo> t = rawTodos(); 291 QPtrList<Todo> t = rawTodos();
276 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 292 for( i = t.first(); i; i = t.next() ) incidences.append( i );
277 293
278 QPtrList<Journal> j = journals(); 294 QPtrList<Journal> j = journals();
279 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 295 for( i = j.first(); i; i = j.next() ) incidences.append( i );
280 296
281 return incidences; 297 return incidences;
282} 298}
283 299
284QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) 300QPtrList<Event> Calendar::events( const QDate &date, bool sorted )
285{ 301{
286 QPtrList<Event> el = rawEventsForDate(date,sorted); 302 QPtrList<Event> el = rawEventsForDate(date,sorted);
287 mFilter->apply(&el); 303 mFilter->apply(&el);
288 return el; 304 return el;
289} 305}
290 306
291QPtrList<Event> Calendar::events( const QDateTime &qdt ) 307QPtrList<Event> Calendar::events( const QDateTime &qdt )
292{ 308{
293 QPtrList<Event> el = rawEventsForDate(qdt); 309 QPtrList<Event> el = rawEventsForDate(qdt);
294 mFilter->apply(&el); 310 mFilter->apply(&el);
295 return el; 311 return el;
296} 312}
297 313
298QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, 314QPtrList<Event> Calendar::events( const QDate &start, const QDate &end,
299 bool inclusive) 315 bool inclusive)
300{ 316{
301 QPtrList<Event> el = rawEvents(start,end,inclusive); 317 QPtrList<Event> el = rawEvents(start,end,inclusive);
302 mFilter->apply(&el); 318 mFilter->apply(&el);
303 return el; 319 return el;
304} 320}
305 321
306QPtrList<Event> Calendar::events() 322QPtrList<Event> Calendar::events()
307{ 323{
308 QPtrList<Event> el = rawEvents(); 324 QPtrList<Event> el = rawEvents();
309 mFilter->apply(&el); 325 mFilter->apply(&el);
310 return el; 326 return el;
311} 327}
312 328
313 329
314bool Calendar::addIncidence(Incidence *i) 330bool Calendar::addIncidence(Incidence *i)
315{ 331{
316 Incidence::AddVisitor<Calendar> v(this); 332 Incidence::AddVisitor<Calendar> v(this);
317 333
318 return i->accept(v); 334 return i->accept(v);
319} 335}
320void Calendar::deleteIncidence(Incidence *in) 336void Calendar::deleteIncidence(Incidence *in)
321{ 337{
322 if ( in->type() == "Event" ) 338 if ( in->type() == "Event" )
323 deleteEvent( (Event*) in ); 339 deleteEvent( (Event*) in );
324 else if ( in->type() =="Todo" ) 340 else if ( in->type() =="Todo" )
325 deleteTodo( (Todo*) in); 341 deleteTodo( (Todo*) in);
326 else if ( in->type() =="Journal" ) 342 else if ( in->type() =="Journal" )
327 deleteJournal( (Journal*) in ); 343 deleteJournal( (Journal*) in );
328} 344}
329 345
330Incidence* Calendar::incidence( const QString& uid ) 346Incidence* Calendar::incidence( const QString& uid )
331{ 347{
332 Incidence* i; 348 Incidence* i;
333 349
334 if( (i = todo( uid )) != 0 ) 350 if( (i = todo( uid )) != 0 )
335 return i; 351 return i;
336 if( (i = event( uid )) != 0 ) 352 if( (i = event( uid )) != 0 )
337 return i; 353 return i;
338 if( (i = journal( uid )) != 0 ) 354 if( (i = journal( uid )) != 0 )
339 return i; 355 return i;
340 356
341 return 0; 357 return 0;
342} 358}
343 359
344QPtrList<Todo> Calendar::todos() 360QPtrList<Todo> Calendar::todos()
345{ 361{
346 QPtrList<Todo> tl = rawTodos(); 362 QPtrList<Todo> tl = rawTodos();
347 mFilter->apply( &tl ); 363 mFilter->apply( &tl );
348 return tl; 364 return tl;
349} 365}
350 366
351// When this is called, the todo have already been added to the calendar. 367// When this is called, the todo have already been added to the calendar.
352// This method is only about linking related todos 368// This method is only about linking related todos
353void Calendar::setupRelations( Incidence *incidence ) 369void Calendar::setupRelations( Incidence *incidence )
354{ 370{
355 QString uid = incidence->uid(); 371 QString uid = incidence->uid();
356 //qDebug("Calendar::setupRelations "); 372 //qDebug("Calendar::setupRelations ");
357 // First, go over the list of orphans and see if this is their parent 373 // First, go over the list of orphans and see if this is their parent
358 while( Incidence* i = mOrphans[ uid ] ) { 374 while( Incidence* i = mOrphans[ uid ] ) {
359 mOrphans.remove( uid ); 375 mOrphans.remove( uid );
360 i->setRelatedTo( incidence ); 376 i->setRelatedTo( incidence );
361 incidence->addRelation( i ); 377 incidence->addRelation( i );
362 mOrphanUids.remove( i->uid() ); 378 mOrphanUids.remove( i->uid() );
363 } 379 }
364 380
365 // Now see about this incidences parent 381 // Now see about this incidences parent
366 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { 382 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) {
367 // This incidence has a uid it is related to, but is not registered to it yet 383 // This incidence has a uid it is related to, but is not registered to it yet
368 // Try to find it 384 // Try to find it
369 Incidence* parent = this->incidence( incidence->relatedToUid() ); 385 Incidence* parent = this->incidence( incidence->relatedToUid() );
370 if( parent ) { 386 if( parent ) {
371 // Found it 387 // Found it
372 incidence->setRelatedTo( parent ); 388 incidence->setRelatedTo( parent );
373 parent->addRelation( incidence ); 389 parent->addRelation( incidence );
374 } else { 390 } else {
375 // Not found, put this in the mOrphans list 391 // Not found, put this in the mOrphans list
376 mOrphans.insert( incidence->relatedToUid(), incidence ); 392 mOrphans.insert( incidence->relatedToUid(), incidence );
377 mOrphanUids.insert( incidence->uid(), incidence ); 393 mOrphanUids.insert( incidence->uid(), incidence );
378 } 394 }
379 } 395 }
380} 396}
381 397
382// If a task with subtasks is deleted, move it's subtasks to the orphans list 398// If a task with subtasks is deleted, move it's subtasks to the orphans list
383void Calendar::removeRelations( Incidence *incidence ) 399void Calendar::removeRelations( Incidence *incidence )
384{ 400{
385 // qDebug("Calendar::removeRelations "); 401 // qDebug("Calendar::removeRelations ");
386 QString uid = incidence->uid(); 402 QString uid = incidence->uid();
387 403
388 QPtrList<Incidence> relations = incidence->relations(); 404 QPtrList<Incidence> relations = incidence->relations();
389 for( Incidence* i = relations.first(); i; i = relations.next() ) 405 for( Incidence* i = relations.first(); i; i = relations.next() )
390 if( !mOrphanUids.find( i->uid() ) ) { 406 if( !mOrphanUids.find( i->uid() ) ) {
391 mOrphans.insert( uid, i ); 407 mOrphans.insert( uid, i );
392 mOrphanUids.insert( i->uid(), i ); 408 mOrphanUids.insert( i->uid(), i );
393 i->setRelatedTo( 0 ); 409 i->setRelatedTo( 0 );
394 i->setRelatedToUid( uid ); 410 i->setRelatedToUid( uid );
395 } 411 }
396 412
397 // If this incidence is related to something else, tell that about it 413 // If this incidence is related to something else, tell that about it
398 if( incidence->relatedTo() ) 414 if( incidence->relatedTo() )
399 incidence->relatedTo()->removeRelation( incidence ); 415 incidence->relatedTo()->removeRelation( incidence );
400 416
401 // Remove this one from the orphans list 417 // Remove this one from the orphans list
402 if( mOrphanUids.remove( uid ) ) 418 if( mOrphanUids.remove( uid ) )
403 // This incidence is located in the orphans list - it should be removed 419 // This incidence is located in the orphans list - it should be removed
404 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { 420 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) {
405 // Removing wasn't that easy 421 // Removing wasn't that easy
406 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { 422 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) {
407 if( it.current()->uid() == uid ) { 423 if( it.current()->uid() == uid ) {
408 mOrphans.remove( it.currentKey() ); 424 mOrphans.remove( it.currentKey() );
409 break; 425 break;
410 } 426 }
411 } 427 }
412 } 428 }
413} 429}
414 430
415void Calendar::registerObserver( Observer *observer ) 431void Calendar::registerObserver( Observer *observer )
416{ 432{
417 mObserver = observer; 433 mObserver = observer;
418 mNewObserver = true; 434 mNewObserver = true;
419} 435}
420 436
421void Calendar::setModified( bool modified ) 437void Calendar::setModified( bool modified )
422{ 438{
423 if ( mObserver ) mObserver->calendarModified( modified, this ); 439 if ( mObserver ) mObserver->calendarModified( modified, this );
424 if ( modified != mModified || mNewObserver ) { 440 if ( modified != mModified || mNewObserver ) {
425 mNewObserver = false; 441 mNewObserver = false;
426 // if ( mObserver ) mObserver->calendarModified( modified, this ); 442 // if ( mObserver ) mObserver->calendarModified( modified, this );
427 mModified = modified; 443 mModified = modified;
428 } 444 }
429} 445}
430 446
431void Calendar::setLoadedProductId( const QString &id ) 447void Calendar::setLoadedProductId( const QString &id )
432{ 448{
433 mLoadedProductId = id; 449 mLoadedProductId = id;
434} 450}
435 451
436QString Calendar::loadedProductId() 452QString Calendar::loadedProductId()
437{ 453{
438 return mLoadedProductId; 454 return mLoadedProductId;
439} 455}
440 456
441//#include "calendar.moc" 457//#include "calendar.moc"
diff --git a/libkcal/calendar.h b/libkcal/calendar.h
index c45d81f..d5294eb 100644
--- a/libkcal/calendar.h
+++ b/libkcal/calendar.h
@@ -1,351 +1,352 @@
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 void deleteIncidence(Incidence *in); 68 void deleteIncidence(Incidence *in);
69 void resetTempSyncStat(); 69 void resetTempSyncStat();
70 void resetPilotStat();
70 /** 71 /**
71 Clears out the current calendar, freeing all used memory etc. 72 Clears out the current calendar, freeing all used memory etc.
72 */ 73 */
73 virtual void close() = 0; 74 virtual void close() = 0;
74 75
75 /** 76 /**
76 Sync changes in memory to persistant storage. 77 Sync changes in memory to persistant storage.
77 */ 78 */
78 virtual void save() = 0; 79 virtual void save() = 0;
79 virtual QPtrList<Event> getExternLastSyncEvents() = 0; 80 virtual QPtrList<Event> getExternLastSyncEvents() = 0;
80 virtual bool isSaving() { return false; } 81 virtual bool isSaving() { return false; }
81 82
82 /** 83 /**
83 Return the owner of the calendar's full name. 84 Return the owner of the calendar's full name.
84 */ 85 */
85 const QString &getOwner() const; 86 const QString &getOwner() const;
86 /** 87 /**
87 Set the owner of the calendar. Should be owner's full name. 88 Set the owner of the calendar. Should be owner's full name.
88 */ 89 */
89 void setOwner( const QString &os ); 90 void setOwner( const QString &os );
90 /** 91 /**
91 Return the email address of the calendar owner. 92 Return the email address of the calendar owner.
92 */ 93 */
93 const QString &getEmail(); 94 const QString &getEmail();
94 /** 95 /**
95 Set the email address of the calendar owner. 96 Set the email address of the calendar owner.
96 */ 97 */
97 void setEmail( const QString & ); 98 void setEmail( const QString & );
98 99
99 /** 100 /**
100 Set time zone from a timezone string (e.g. -2:00) 101 Set time zone from a timezone string (e.g. -2:00)
101 */ 102 */
102 void setTimeZone( const QString &tz ); 103 void setTimeZone( const QString &tz );
103 /** 104 /**
104 Set time zone from a minutes value (e.g. -60) 105 Set time zone from a minutes value (e.g. -60)
105 */ 106 */
106 void setTimeZone( int tz ); 107 void setTimeZone( int tz );
107 /** 108 /**
108 Return time zone as offest in minutes. 109 Return time zone as offest in minutes.
109 */ 110 */
110 int getTimeZone() const; 111 int getTimeZone() const;
111 /** 112 /**
112 Compute an ISO 8601 format string from the time zone. 113 Compute an ISO 8601 format string from the time zone.
113 */ 114 */
114 QString getTimeZoneStr() const; 115 QString getTimeZoneStr() const;
115 /** 116 /**
116 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal 117 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal
117 values). 118 values).
118 */ 119 */
119 void setTimeZoneId( const QString & ); 120 void setTimeZoneId( const QString & );
120 /** 121 /**
121 Return time zone id. 122 Return time zone id.
122 */ 123 */
123 QString timeZoneId() const; 124 QString timeZoneId() const;
124 /** 125 /**
125 Use local time, not UTC or a time zone. 126 Use local time, not UTC or a time zone.
126 */ 127 */
127 void setLocalTime(); 128 void setLocalTime();
128 /** 129 /**
129 Return whether local time is being used. 130 Return whether local time is being used.
130 */ 131 */
131 bool isLocalTime() const; 132 bool isLocalTime() const;
132 133
133 /** 134 /**
134 Add an incidence to calendar. 135 Add an incidence to calendar.
135 136
136 @return true on success, false on error. 137 @return true on success, false on error.
137 */ 138 */
138 virtual bool addIncidence( Incidence * ); 139 virtual bool addIncidence( Incidence * );
139 /** 140 /**
140 Return filtered list of all incidences of this calendar. 141 Return filtered list of all incidences of this calendar.
141 */ 142 */
142 virtual QPtrList<Incidence> incidences(); 143 virtual QPtrList<Incidence> incidences();
143 144
144 /** 145 /**
145 Return unfiltered list of all incidences of this calendar. 146 Return unfiltered list of all incidences of this calendar.
146 */ 147 */
147 virtual QPtrList<Incidence> rawIncidences(); 148 virtual QPtrList<Incidence> rawIncidences();
148 149
149 /** 150 /**
150 Adds a Event to this calendar object. 151 Adds a Event to this calendar object.
151 @param anEvent a pointer to the event to add 152 @param anEvent a pointer to the event to add
152 153
153 @return true on success, false on error. 154 @return true on success, false on error.
154 */ 155 */
155 virtual bool addEventNoDup( Event *event ) = 0; 156 virtual bool addEventNoDup( Event *event ) = 0;
156 virtual bool addAnniversaryNoDup( Event *event ) = 0; 157 virtual bool addAnniversaryNoDup( Event *event ) = 0;
157 virtual bool addEvent( Event *anEvent ) = 0; 158 virtual bool addEvent( Event *anEvent ) = 0;
158 /** 159 /**
159 Delete event from calendar. 160 Delete event from calendar.
160 */ 161 */
161 virtual void deleteEvent( Event * ) = 0; 162 virtual void deleteEvent( Event * ) = 0;
162 /** 163 /**
163 Retrieves an event on the basis of the unique string ID. 164 Retrieves an event on the basis of the unique string ID.
164 */ 165 */
165 virtual Event *event( const QString &UniqueStr ) = 0; 166 virtual Event *event( const QString &UniqueStr ) = 0;
166 virtual Event *event( QString, QString ) = 0; 167 virtual Event *event( QString, QString ) = 0;
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 The calendar filter is applied. 171 The calendar filter is applied.
171 */ 172 */
172 QPtrList<Event> events( const QDate &date, bool sorted = false); 173 QPtrList<Event> events( const QDate &date, bool sorted = false);
173 /** 174 /**
174 Get events, which occur on the given date. 175 Get events, which occur on the given date.
175 The calendar filter is applied. 176 The calendar filter is applied.
176 */ 177 */
177 QPtrList<Event> events( const QDateTime &qdt ); 178 QPtrList<Event> events( const QDateTime &qdt );
178 /** 179 /**
179 Get events in a range of dates. If inclusive is set to true, only events 180 Get events in a range of dates. If inclusive is set to true, only events
180 are returned, which are completely included in the range. 181 are returned, which are completely included in the range.
181 The calendar filter is applied. 182 The calendar filter is applied.
182 */ 183 */
183 QPtrList<Event> events( const QDate &start, const QDate &end, 184 QPtrList<Event> events( const QDate &start, const QDate &end,
184 bool inclusive = false); 185 bool inclusive = false);
185 /** 186 /**
186 Return filtered list of all events in calendar. 187 Return filtered list of all events in calendar.
187 */ 188 */
188 virtual QPtrList<Event> events(); 189 virtual QPtrList<Event> events();
189 /** 190 /**
190 Return unfiltered list of all events in calendar. 191 Return unfiltered list of all events in calendar.
191 */ 192 */
192 virtual QPtrList<Event> rawEvents() = 0; 193 virtual QPtrList<Event> rawEvents() = 0;
193 194
194 /** 195 /**
195 Add a todo to the todolist. 196 Add a todo to the todolist.
196 197
197 @return true on success, false on error. 198 @return true on success, false on error.
198 */ 199 */
199 virtual bool addTodo( Todo *todo ) = 0; 200 virtual bool addTodo( Todo *todo ) = 0;
200 virtual bool addTodoNoDup( Todo *todo ) = 0; 201 virtual bool addTodoNoDup( Todo *todo ) = 0;
201 /** 202 /**
202 Remove a todo from the todolist. 203 Remove a todo from the todolist.
203 */ 204 */
204 virtual void deleteTodo( Todo * ) = 0; 205 virtual void deleteTodo( Todo * ) = 0;
205 virtual void deleteJournal( Journal * ) = 0; 206 virtual void deleteJournal( Journal * ) = 0;
206 /** 207 /**
207 Return filterd list of todos. 208 Return filterd list of todos.
208 */ 209 */
209 virtual QPtrList<Todo> todos(); 210 virtual QPtrList<Todo> todos();
210 /** 211 /**
211 Searches todolist for an event with this unique string identifier, 212 Searches todolist for an event with this unique string identifier,
212 returns a pointer or null. 213 returns a pointer or null.
213 */ 214 */
214 virtual Todo *todo( const QString &uid ) = 0; 215 virtual Todo *todo( const QString &uid ) = 0;
215 virtual Todo *todo( QString, QString ) = 0; 216 virtual Todo *todo( QString, QString ) = 0;
216 /** 217 /**
217 Returns list of todos due on the specified date. 218 Returns list of todos due on the specified date.
218 */ 219 */
219 virtual QPtrList<Todo> todos( const QDate &date ) = 0; 220 virtual QPtrList<Todo> todos( const QDate &date ) = 0;
220 /** 221 /**
221 Return unfiltered list of todos. 222 Return unfiltered list of todos.
222 */ 223 */
223 virtual QPtrList<Todo> rawTodos() = 0; 224 virtual QPtrList<Todo> rawTodos() = 0;
224 225
225 /** 226 /**
226 Add a Journal entry to calendar. 227 Add a Journal entry to calendar.
227 228
228 @return true on success, false on error. 229 @return true on success, false on error.
229 */ 230 */
230 virtual bool addJournal( Journal * ) = 0; 231 virtual bool addJournal( Journal * ) = 0;
231 /** 232 /**
232 Return Journal for given date. 233 Return Journal for given date.
233 */ 234 */
234 virtual Journal *journal( const QDate & ) = 0; 235 virtual Journal *journal( const QDate & ) = 0;
235 /** 236 /**
236 Return Journal with given UID. 237 Return Journal with given UID.
237 */ 238 */
238 virtual Journal *journal( const QString &UID ) = 0; 239 virtual Journal *journal( const QString &UID ) = 0;
239 /** 240 /**
240 Return list of all Journal entries. 241 Return list of all Journal entries.
241 */ 242 */
242 virtual QPtrList<Journal> journals() = 0; 243 virtual QPtrList<Journal> journals() = 0;
243 244
244 /** 245 /**
245 Searches all incidence types for an incidence with this unique 246 Searches all incidence types for an incidence with this unique
246 string identifier, returns a pointer or null. 247 string identifier, returns a pointer or null.
247 */ 248 */
248 Incidence* incidence( const QString&UID ); 249 Incidence* incidence( const QString&UID );
249 250
250 /** 251 /**
251 Setup relations for an incidence. 252 Setup relations for an incidence.
252 */ 253 */
253 virtual void setupRelations( Incidence * ); 254 virtual void setupRelations( Incidence * );
254 /** 255 /**
255 Remove all relations to an incidence 256 Remove all relations to an incidence
256 */ 257 */
257 virtual void removeRelations( Incidence * ); 258 virtual void removeRelations( Incidence * );
258 259
259 /** 260 /**
260 Set calendar filter, which filters events for the events() functions. 261 Set calendar filter, which filters events for the events() functions.
261 The Filter object is owned by the caller. 262 The Filter object is owned by the caller.
262 */ 263 */
263 void setFilter( CalFilter * ); 264 void setFilter( CalFilter * );
264 /** 265 /**
265 Return calendar filter. 266 Return calendar filter.
266 */ 267 */
267 CalFilter *filter(); 268 CalFilter *filter();
268 virtual QDateTime nextAlarm( int daysTo ) = 0; 269 virtual QDateTime nextAlarm( int daysTo ) = 0;
269 virtual QString nextSummary( ) const = 0; 270 virtual QString nextSummary( ) const = 0;
270 virtual void reInitAlarmSettings() = 0; 271 virtual void reInitAlarmSettings() = 0;
271 virtual QDateTime nextAlarmEventDateTime() const = 0; 272 virtual QDateTime nextAlarmEventDateTime() const = 0;
272 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; 273 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0;
273 /** 274 /**
274 Return all alarms, which ocur in the given time interval. 275 Return all alarms, which ocur in the given time interval.
275 */ 276 */
276 virtual Alarm::List alarms( const QDateTime &from, 277 virtual Alarm::List alarms( const QDateTime &from,
277 const QDateTime &to ) = 0; 278 const QDateTime &to ) = 0;
278 279
279 class Observer { 280 class Observer {
280 public: 281 public:
281 virtual void calendarModified( bool, Calendar * ) = 0; 282 virtual void calendarModified( bool, Calendar * ) = 0;
282 }; 283 };
283 284
284 void registerObserver( Observer * ); 285 void registerObserver( Observer * );
285 286
286 void setModified( bool ); 287 void setModified( bool );
287 288
288 /** 289 /**
289 Set product id returned by loadedProductId(). This function is only 290 Set product id returned by loadedProductId(). This function is only
290 useful for the calendar loading code. 291 useful for the calendar loading code.
291 */ 292 */
292 void setLoadedProductId( const QString & ); 293 void setLoadedProductId( const QString & );
293 /** 294 /**
294 Return product id taken from file that has been loaded. Returns 295 Return product id taken from file that has been loaded. Returns
295 QString::null, if no calendar has been loaded. 296 QString::null, if no calendar has been loaded.
296 */ 297 */
297 QString loadedProductId(); 298 QString loadedProductId();
298 299
299 signals: 300 signals:
300 void calendarChanged(); 301 void calendarChanged();
301 void calendarSaved(); 302 void calendarSaved();
302 void calendarLoaded(); 303 void calendarLoaded();
303 void addAlarm(const QDateTime &qdt, const QString &noti ); 304 void addAlarm(const QDateTime &qdt, const QString &noti );
304 void removeAlarm(const QDateTime &qdt, const QString &noti ); 305 void removeAlarm(const QDateTime &qdt, const QString &noti );
305 306
306 protected: 307 protected:
307 /** 308 /**
308 Get unfiltered events, which occur on the given date. 309 Get unfiltered events, which occur on the given date.
309 */ 310 */
310 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; 311 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0;
311 /** 312 /**
312 Get unfiltered events, which occur on the given date. 313 Get unfiltered events, which occur on the given date.
313 */ 314 */
314 virtual QPtrList<Event> rawEventsForDate( const QDate &date, 315 virtual QPtrList<Event> rawEventsForDate( const QDate &date,
315 bool sorted = false ) = 0; 316 bool sorted = false ) = 0;
316 /** 317 /**
317 Get events in a range of dates. If inclusive is set to true, only events 318 Get events in a range of dates. If inclusive is set to true, only events
318 are returned, which are completely included in the range. 319 are returned, which are completely included in the range.
319 */ 320 */
320 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, 321 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end,
321 bool inclusive = false ) = 0; 322 bool inclusive = false ) = 0;
322 Incidence *mNextAlarmIncidence; 323 Incidence *mNextAlarmIncidence;
323 324
324private: 325private:
325 void init(); 326 void init();
326 327
327 QString mOwner; // who the calendar belongs to 328 QString mOwner; // who the calendar belongs to
328 QString mOwnerEmail; // email address of the owner 329 QString mOwnerEmail; // email address of the owner
329 int mTimeZone; // timezone OFFSET from GMT (MINUTES) 330 int mTimeZone; // timezone OFFSET from GMT (MINUTES)
330 bool mLocalTime; // use local time, not UTC or a time zone 331 bool mLocalTime; // use local time, not UTC or a time zone
331 332
332 CalFilter *mFilter; 333 CalFilter *mFilter;
333 CalFilter *mDefaultFilter; 334 CalFilter *mDefaultFilter;
334 335
335 QString mTimeZoneId; 336 QString mTimeZoneId;
336 337
337 Observer *mObserver; 338 Observer *mObserver;
338 bool mNewObserver; 339 bool mNewObserver;
339 340
340 bool mModified; 341 bool mModified;
341 342
342 QString mLoadedProductId; 343 QString mLoadedProductId;
343 344
344 // This list is used to put together related todos 345 // This list is used to put together related todos
345 QDict<Incidence> mOrphans; 346 QDict<Incidence> mOrphans;
346 QDict<Incidence> mOrphanUids; 347 QDict<Incidence> mOrphanUids;
347}; 348};
348 349
349} 350}
350 351
351#endif 352#endif