summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-17 18:08:43 (UTC)
committer zautrix <zautrix>2004-10-17 18:08:43 (UTC)
commit6f6d1d58938539215bb4fcb5b97cf9fb089a11ef (patch) (unidiff)
tree9937fe24c3fa3f29421b39a58b393e893a11636a
parentd92f58ffa1937af8a4240b9d235da15f5f352769 (diff)
downloadkdepimpi-6f6d1d58938539215bb4fcb5b97cf9fb089a11ef.zip
kdepimpi-6f6d1d58938539215bb4fcb5b97cf9fb089a11ef.tar.gz
kdepimpi-6f6d1d58938539215bb4fcb5b97cf9fb089a11ef.tar.bz2
more KDE sync fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kde2file/caldump/main.cpp38
-rw-r--r--korganizer/calendarview.cpp29
-rw-r--r--korganizer/calendarview.h1
-rw-r--r--libkcal/calendar.cpp8
-rw-r--r--libkcal/calendar.h2
5 files changed, 42 insertions, 36 deletions
diff --git a/kde2file/caldump/main.cpp b/kde2file/caldump/main.cpp
index 755e792..be1735b 100644
--- a/kde2file/caldump/main.cpp
+++ b/kde2file/caldump/main.cpp
@@ -1,255 +1,253 @@
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#include <qapplication.h>
58 59
59#include <stdlib.h> 60#include <stdlib.h>
60#include <iostream> 61#include <iostream>
61 62
62using namespace KCal; 63using namespace KCal;
63using namespace std; 64using namespace std;
64 65
65static const char progName[] = "kdecalendar"; 66static const char progName[] = "kdecalendar";
66static const char progDisplay[] = "KDE_Calendar"; 67static const char progDisplay[] = "KDE_Calendar";
67static const char progVersion[] = "33.1/3"; 68static const char progVersion[] = "33.1/3";
68static const char progDesc[] = "A command line interface to KDE calendars"; 69static const char progDesc[] = "A command line interface to KDE calendars";
69 70
70 71
71static KCmdLineOptions options[] = 72static KCmdLineOptions options[] =
72 { 73 {
73 { "dump", 74 { "dump",
74 I18N_NOOP( "Dumps calendar" ), 0 }, 75 I18N_NOOP( "Dumps calendar" ), 0 },
75 { "read", 76 { "read",
76 I18N_NOOP( "Reads calendar" ), 0 }, 77 I18N_NOOP( "Reads calendar" ), 0 },
77 KCmdLineLastOption 78 KCmdLineLastOption
78 }; 79 };
79 80
80int main( int argc, char *argv[] ) 81int main( int argc, char *argv[] )
81{ 82{
82 KAboutData aboutData( 83 KAboutData aboutData(
83 progName, // internal program name 84 progName, // internal program name
84 I18N_NOOP( progDisplay ), // displayable program name. 85 I18N_NOOP( progDisplay ), // displayable program name.
85 progVersion, // version string 86 progVersion, // version string
86 I18N_NOOP( progDesc ), // short porgram description 87 I18N_NOOP( progDesc ), // short porgram description
87 KAboutData::License_GPL, // license type 88 KAboutData::License_GPL, // license type
88 "(c) 2004, Lutz Rogowski", // copyright statement 89 "(c) 2004, Lutz Rogowski", // copyright statement
89 0, // any free form text 90 0, // any free form text
90 "", // program home page address 91 "", // program home page address
91 "bugs.kde.org" // bug report email address 92 "bugs.kde.org" // bug report email address
92 ); 93 );
93 94
94 95
95 // KCmdLineArgs::init() final 'true' argument indicates no commandline options 96 // KCmdLineArgs::init() final 'true' argument indicates no commandline options
96 // for QApplication/KApplication (no KDE or Qt options) 97 // for QApplication/KApplication (no KDE or Qt options)
97 KCmdLineArgs::init( argc, argv, &aboutData, true ); 98 KCmdLineArgs::init( argc, argv, &aboutData, true );
98 KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. 99 KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
99 100
100 KInstance ins ( progName ); 101 KInstance ins ( progName );
101 102
102 KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); 103 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
103 104
104 bool read = false; 105 bool read = false;
105 if ( args->isSet( "read" ) ) { 106 if ( args->isSet( "read" ) ) {
106 read = true; 107 read = true;
107 qDebug("read "); 108 qDebug("read ");
108 } 109 }
109 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; 110 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics";
110 CalendarResources *calendarResource = 0; 111 CalendarResources *calendarResource = 0;
111 CalendarLocal *localCalendar = 0; 112 CalendarLocal *localCalendar = 0;
112 KConfig c( locate( "config", "korganizerrc" ) ); 113 KConfig c( locate( "config", "korganizerrc" ) );
113 c.setGroup( "Time & Date" ); 114 c.setGroup( "Time & Date" );
114 QString tz = c.readEntry( "TimeZoneId" ); 115 QString tz = c.readEntry( "TimeZoneId" );
115 calendarResource = new CalendarResources( tz ); 116 calendarResource = new CalendarResources( tz );
116 calendarResource->readConfig(); 117 calendarResource->readConfig();
117 calendarResource->load(); 118 calendarResource->load();
118 qDebug("************************************* "); 119 qDebug("************************************* ");
119 qDebug("**************kdecaldump************* "); 120 qDebug("**************kdecaldump************* ");
120 qDebug("************************************* "); 121 qDebug("************************************* ");
121 qDebug("Using timezone ID: %s", calendarResource->timeZoneId().latin1()); 122 qDebug("Using timezone ID: %s", calendarResource->timeZoneId().latin1());
122 123
123 if ( !read ) { 124 if ( !read ) {
124 localCalendar = new CalendarLocal(); 125 localCalendar = new CalendarLocal();
125 localCalendar->setTimeZoneId( calendarResource->timeZoneId()); 126 localCalendar->setTimeZoneId( calendarResource->timeZoneId());
126 KCal::Incidence::List allInc = calendarResource->rawIncidences(); 127 KCal::Incidence::List allInc = calendarResource->rawIncidences();
127 Incidence::List::ConstIterator it; 128 Incidence::List::ConstIterator it;
128 int num = 0; 129 int num = 0;
129 for( it = allInc.begin(); it != allInc.end(); ++it ) { 130 for( it = allInc.begin(); it != allInc.end(); ++it ) {
130 ResourceCalendar * re = calendarResource->resource( (*it) ); 131 ResourceCalendar * re = calendarResource->resource( (*it) );
131 if ( re && !re->readOnly() ) { 132 if ( re && !re->readOnly() ) {
132 ++num; 133 ++num;
133 Incidence* cl = (*it)->clone(); 134 Incidence* cl = (*it)->clone();
134 cl->setLastModified( (*it)->lastModified() ); 135 cl->setLastModified( (*it)->lastModified() );
135 if ( cl->type() == "Journal" ) 136 if ( cl->type() == "Journal" )
136 localCalendar->addJournal( (Journal *) cl ); 137 localCalendar->addJournal( (Journal *) cl );
137 else if ( cl->type() == "Todo" ) 138 else if ( cl->type() == "Todo" )
138 localCalendar->addTodo( (Todo *) cl ); 139 localCalendar->addTodo( (Todo *) cl );
139 else if ( cl->type() == "Event" ) 140 else if ( cl->type() == "Event" )
140 localCalendar->addEvent( (Event *) cl ); 141 localCalendar->addEvent( (Event *) cl );
141 } 142 }
142 } 143 }
143 144
144 FileStorage* storage = new FileStorage( calendarResource ); 145 FileStorage* storage = new FileStorage( calendarResource );
145 storage->setFileName( fileName ); 146 storage->setFileName( fileName );
146 storage->setSaveFormat( new ICalFormat() ); 147 storage->setSaveFormat( new ICalFormat() );
147 storage->save(); 148 storage->save();
148 delete storage; 149 delete storage;
149 qDebug("************************************* "); 150 qDebug("************************************* ");
150 qDebug("************kdecaldump*************** "); 151 qDebug("************kdecaldump*************** ");
151 qDebug("************************************* "); 152 qDebug("************************************* ");
152 qDebug("%d calendar entries dumped to file %s", num, fileName.latin1()); 153 qDebug("%d calendar entries dumped to file %s", num, fileName.latin1());
153 154
154 } else { 155 } else {
155 qDebug("*************************load"); 156 qDebug("************load");
156 localCalendar = new CalendarLocal(); 157 localCalendar = new CalendarLocal();
157 localCalendar->setTimeZoneId( calendarResource->timeZoneId()); 158 localCalendar->setTimeZoneId( calendarResource->timeZoneId());
158 FileStorage* storage = new FileStorage( localCalendar ); 159 FileStorage* storage = new FileStorage( localCalendar );
159 storage->setFileName( fileName ); 160 storage->setFileName( fileName );
160 int num = 0; 161 int num = 0;
161 int del = 0; 162 int del = 0;
162 int add = 0; 163 int add = 0;
163 if ( storage->load() ) { 164 if ( storage->load() ) {
164 qDebug("*************************loaded!"); 165 qDebug("***********loaded!");
165 KCal::Incidence::List newInc = localCalendar->rawIncidences(); 166 KCal::Incidence::List newInc = localCalendar->rawIncidences();
166 Incidence::List::ConstIterator it; 167 Incidence::List::ConstIterator it;
167 for( it = newInc.begin(); it != newInc.end(); ++it ) { 168 for( it = newInc.begin(); it != newInc.end(); ++it ) {
168 if ( (*it)->pilotId() > 0 ) { //changed 169 if ( (*it)->pilotId() > 1 ) { //changed
169 Incidence* cl = (*it)->clone(); 170 qDebug("*********pilot id %d %s ",(*it)->pilotId() ,(*it)->summary().latin1());
170 Incidence *incOld = calendarResource->incidence( cl->uid() ); 171 Incidence *incOld = calendarResource->incidence( (*it)->uid() );
171 ResourceCalendar * res = 0; 172 ResourceCalendar * res = 0;
172 if ( incOld ) 173 if ( incOld )
173 res = calendarResource->resource( incOld ); 174 res = calendarResource->resource( incOld );
174 if ( res ) { 175 if ( res ) {
176 Incidence* cl = (*it)->clone();
175 cl->setPilotId( incOld->pilotId() ); 177 cl->setPilotId( incOld->pilotId() );
176 ++num; 178 ++num;
177 if ( incOld->type() == "Journal" ) 179 if ( incOld->type() == "Journal" )
178 calendarResource->deleteJournal( (Journal *) incOld ); 180 calendarResource->deleteJournal( (Journal *) incOld );
179 else if ( incOld->type() == "Todo" ) 181 else if ( incOld->type() == "Todo" )
180 calendarResource->deleteTodo( (Todo *) incOld ); 182 calendarResource->deleteTodo( (Todo *) incOld );
181 else if ( incOld->type() == "Event" ) 183 else if ( incOld->type() == "Event" )
182 calendarResource->deleteEvent( (Event *) incOld ); 184 calendarResource->deleteEvent( (Event *) incOld );
183 185 qDebug("*********change incidence %s ",cl->summary().latin1());
184 if ( cl->type() == "Journal" ) 186 if ( cl->type() == "Journal" )
185 calendarResource->addJournal( (Journal *) cl, res ); 187 calendarResource->addJournal( (Journal *) cl, res );
186 else if ( cl->type() == "Todo" ) 188 else if ( cl->type() == "Todo" )
187 calendarResource->addTodo( (Todo *) cl, res ); 189 calendarResource->addTodo( (Todo *) cl, res );
188 else if ( cl->type() == "Event" ) 190 else if ( cl->type() == "Event" )
189 calendarResource->addEvent( (Event *) cl, res ); 191 calendarResource->addEvent( (Event *) cl, res );
190 192
191 } else { 193 } else {
192 if ( incOld ) { 194 Incidence* cl = (*it)->clone();
193 qDebug("ERROR: no resource found for old incidence "); 195 qDebug("*********add incidence %s ",cl->summary().latin1());
194 if ( incOld->type() == "Journal" ) 196 calendarResource->addIncidence( cl );
195 calendarResource->deleteJournal( (Journal *) incOld ); 197 ++add;
196 else if ( incOld->type() == "Todo" ) 198 }
197 calendarResource->deleteTodo( (Todo *) incOld ); 199 } else { // maybe added
198 else if ( incOld->type() == "Event" ) 200 Incidence *incOld = calendarResource->incidence( (*it)->uid() );
199 calendarResource->deleteEvent( (Event *) incOld ); 201 if ( !incOld ) { //added
200 202 Incidence* cl = (*it)->clone();
201 } 203 qDebug("*********add incidence %s ",cl->summary().latin1());
202 calendarResource->addIncidence( cl ); 204 calendarResource->addIncidence( cl );
203 ++add; 205 ++add;
204 } 206 }
205 } else { // added
206 Incidence* cl = (*it)->clone();
207 calendarResource->addIncidence( cl );
208 ++add;
209 } 207 }
210 } 208 }
211 KCal::Incidence::List allInc = calendarResource->rawIncidences(); 209 KCal::Incidence::List allInc = calendarResource->rawIncidences();
212 210
213 for( it = allInc.begin(); it != allInc.end(); ++it ) { 211 for( it = allInc.begin(); it != allInc.end(); ++it ) {
214 ResourceCalendar * re = calendarResource->resource( (*it) ); 212 ResourceCalendar * re = calendarResource->resource( (*it) );
215 if ( re && !re->readOnly() ) { 213 if ( re && !re->readOnly() ) {
216 Incidence* cl = localCalendar->incidence( (*it)->uid() ); 214 Incidence* cl = localCalendar->incidence( (*it)->uid() );
217 if ( !cl ) { 215 if ( !cl ) {
218 ++del; 216 ++del;
219 cl = (*it); 217 cl = (*it);
220 if ( cl->type() == "Journal" ) 218 if ( cl->type() == "Journal" )
221 calendarResource->deleteJournal( (Journal *) cl ); 219 calendarResource->deleteJournal( (Journal *) cl );
222 else if ( cl->type() == "Todo" ) 220 else if ( cl->type() == "Todo" )
223 calendarResource->deleteTodo( (Todo *) cl ); 221 calendarResource->deleteTodo( (Todo *) cl );
224 else if ( cl->type() == "Event" ) 222 else if ( cl->type() == "Event" )
225 calendarResource->deleteEvent( (Event *) cl ); 223 calendarResource->deleteEvent( (Event *) cl );
226 //QDateTime lm = cl->lastModified(); 224 //QDateTime lm = cl->lastModified();
227 //cl->setResources( (*it)->resources() ); 225 //cl->setResources( (*it)->resources() );
228 //cl->setLastModified(lm); 226 //cl->setLastModified(lm);
229 } 227 }
230 } 228 }
231 } 229 }
232 230
233 calendarResource->save(); 231 calendarResource->save();
234 qDebug("************************************* "); 232 qDebug("************************************* ");
235 qDebug("************kdecaldump*************** "); 233 qDebug("************kdecaldump*************** ");
236 qDebug("************************************* "); 234 qDebug("************************************* ");
237 qDebug("Calendar entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", num,del, add, fileName.latin1()); 235 qDebug("Calendar entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", num,del, add, fileName.latin1());
238 236
239 } else 237 } else
240 qDebug("ERROR loading file %s",fileName.latin1() ); 238 qDebug("ERROR loading file %s",fileName.latin1() );
241 239
242 } 240 }
243 241
244 if ( localCalendar ) { 242 if ( localCalendar ) {
245 localCalendar->close(); 243 localCalendar->close();
246 delete localCalendar; 244 delete localCalendar;
247 } 245 }
248 if ( calendarResource ) { 246 if ( calendarResource ) {
249 calendarResource->close(); 247 calendarResource->close();
250 delete calendarResource; 248 delete calendarResource;
251 } 249 }
252 250
253 qDebug("ente "); 251 qDebug("ente ");
254 return 0; 252 return 0;
255} 253}
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index f727cd4..ff1db2c 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,3756 +1,3763 @@
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 935 if ( mSyncKDE )
936 //Needed for KDE - OL sync 936 remote->resetPilotStat(1);
937 local->resetPilotStat();
938 remote->resetPilotStat();
939#endif
940 mLastCalendarSync = QDateTime::currentDateTime(); 937 mLastCalendarSync = QDateTime::currentDateTime();
941 QDateTime modifiedCalendar = mLastCalendarSync;; 938 QDateTime modifiedCalendar = mLastCalendarSync;;
942 eventLSync = getLastSyncEvent(); 939 eventLSync = getLastSyncEvent();
943 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 940 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
944 if ( eventR ) { 941 if ( eventR ) {
945 eventRSync = (Event*) eventR->clone(); 942 eventRSync = (Event*) eventR->clone();
946 remote->deleteEvent(eventR ); 943 remote->deleteEvent(eventR );
947 944
948 } else { 945 } else {
949 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 946 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
950 eventRSync = (Event*)eventLSync->clone(); 947 eventRSync = (Event*)eventLSync->clone();
951 } else { 948 } else {
952 fullDateRange = true; 949 fullDateRange = true;
953 eventRSync = new Event(); 950 eventRSync = new Event();
954 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 951 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
955 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 952 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
956 eventRSync->setDtStart( mLastCalendarSync ); 953 eventRSync->setDtStart( mLastCalendarSync );
957 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 954 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
958 eventRSync->setCategories( i18n("SyncEvent") ); 955 eventRSync->setCategories( i18n("SyncEvent") );
959 } 956 }
960 } 957 }
961 if ( eventLSync->dtStart() == mLastCalendarSync ) 958 if ( eventLSync->dtStart() == mLastCalendarSync )
962 fullDateRange = true; 959 fullDateRange = true;
963 960
964 if ( ! fullDateRange ) { 961 if ( ! fullDateRange ) {
965 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 962 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
966 963
967 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 964 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
968 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 965 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
969 fullDateRange = true; 966 fullDateRange = true;
970 } 967 }
971 } 968 }
972 if ( fullDateRange ) 969 if ( fullDateRange && !mSyncKDE )
973 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 970 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
974 else 971 else
975 mLastCalendarSync = eventLSync->dtStart(); 972 mLastCalendarSync = eventLSync->dtStart();
976 // for resyncing if own file has changed 973 // for resyncing if own file has changed
977 if ( mCurrentSyncDevice == "deleteaftersync" ) { 974 if ( mCurrentSyncDevice == "deleteaftersync" ) {
978 mLastCalendarSync = loadedFileVersion; 975 mLastCalendarSync = loadedFileVersion;
979 qDebug("setting mLastCalendarSync "); 976 qDebug("setting mLastCalendarSync ");
980 } 977 }
981 //qDebug("*************************** "); 978 //qDebug("*************************** ");
982 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); 979 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() );
983 QPtrList<Incidence> er = remote->rawIncidences(); 980 QPtrList<Incidence> er = remote->rawIncidences();
984 Incidence* inR = er.first(); 981 Incidence* inR = er.first();
985 Incidence* inL; 982 Incidence* inL;
986 QProgressBar bar( er.count(),0 ); 983 QProgressBar bar( er.count(),0 );
987 bar.setCaption (i18n("Syncing - close to abort!") ); 984 bar.setCaption (i18n("Syncing - close to abort!") );
988 985
989 int w = 300; 986 int w = 300;
990 if ( QApplication::desktop()->width() < 320 ) 987 if ( QApplication::desktop()->width() < 320 )
991 w = 220; 988 w = 220;
992 int h = bar.sizeHint().height() ; 989 int h = bar.sizeHint().height() ;
993 int dw = QApplication::desktop()->width(); 990 int dw = QApplication::desktop()->width();
994 int dh = QApplication::desktop()->height(); 991 int dh = QApplication::desktop()->height();
995 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 992 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
996 bar.show(); 993 bar.show();
997 int modulo = (er.count()/10)+1; 994 int modulo = (er.count()/10)+1;
998 int incCounter = 0; 995 int incCounter = 0;
999 while ( inR ) { 996 while ( inR ) {
1000 if ( ! bar.isVisible() ) 997 if ( ! bar.isVisible() )
1001 return false; 998 return false;
1002 if ( incCounter % modulo == 0 ) 999 if ( incCounter % modulo == 0 )
1003 bar.setProgress( incCounter ); 1000 bar.setProgress( incCounter );
1004 ++incCounter; 1001 ++incCounter;
1005 uid = inR->uid(); 1002 uid = inR->uid();
1006 bool skipIncidence = false; 1003 bool skipIncidence = false;
1007 if ( uid.left(15) == QString("last-syncEvent-") ) 1004 if ( uid.left(15) == QString("last-syncEvent-") )
1008 skipIncidence = true; 1005 skipIncidence = true;
1009 QString idS; 1006 QString idS;
1010 qApp->processEvents(); 1007 qApp->processEvents();
1011 if ( !skipIncidence ) { 1008 if ( !skipIncidence ) {
1012 inL = local->incidence( uid ); 1009 inL = local->incidence( uid );
1013 if ( inL ) { // maybe conflict - same uid in both calendars 1010 if ( inL ) { // maybe conflict - same uid in both calendars
1014 int maxrev = inL->revision(); 1011 int maxrev = inL->revision();
1015 if ( maxrev < inR->revision() ) 1012 if ( maxrev < inR->revision() )
1016 maxrev = inR->revision(); 1013 maxrev = inR->revision();
1017 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1014 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1018 //qDebug("take %d %s ", take, inL->summary().latin1()); 1015 //qDebug("take %d %s ", take, inL->summary().latin1());
1019 if ( take == 3 ) 1016 if ( take == 3 )
1020 return false; 1017 return false;
1021 if ( take == 1 ) {// take local 1018 if ( take == 1 ) {// take local
1022 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1019 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1023 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1020 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1024 else 1021 else
1025 idS = inR->IDStr(); 1022 idS = inR->IDStr();
1026 remote->deleteIncidence( inR ); 1023 remote->deleteIncidence( inR );
1027 if ( inL->revision() < maxrev ) 1024 if ( inL->revision() < maxrev )
1028 inL->setRevision( maxrev ); 1025 inL->setRevision( maxrev );
1029 inR = inL->clone(); 1026 inR = inL->clone();
1030 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1027 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1031 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1028 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1032 inR->setIDStr( idS ); 1029 inR->setIDStr( idS );
1033 remote->addIncidence( inR ); 1030 remote->addIncidence( inR );
1034#ifdef DESKTOP_VERSION 1031 if ( mSyncKDE )
1035 inR->setPilotId( 1 ); 1032 inR->setPilotId( 2 );
1036#endif
1037 ++changedRemote; 1033 ++changedRemote;
1038 } else { 1034 } else {
1039 if ( inR->revision() < maxrev ) 1035 if ( inR->revision() < maxrev )
1040 inR->setRevision( maxrev ); 1036 inR->setRevision( maxrev );
1041 idS = inL->IDStr(); 1037 idS = inL->IDStr();
1038 int pid = inL->pilotId();
1042 local->deleteIncidence( inL ); 1039 local->deleteIncidence( inL );
1043 inL = inR->clone(); 1040 inL = inR->clone();
1041 if ( mSyncKDE )
1042 inL->setPilotId( pid );
1044 inL->setIDStr( idS ); 1043 inL->setIDStr( idS );
1045 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1044 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1046 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1045 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1047 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1046 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1048 } 1047 }
1049 local->addIncidence( inL ); 1048 local->addIncidence( inL );
1050 ++changedLocal; 1049 ++changedLocal;
1051 } 1050 }
1052 } 1051 }
1053 } else { // no conflict 1052 } else { // no conflict
1054 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1053 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1055 QString des = eventLSync->description(); 1054 QString des = eventLSync->description();
1056 QString pref = "e"; 1055 QString pref = "e";
1057 if ( inR->type() == "Todo" ) 1056 if ( inR->type() == "Todo" )
1058 pref = "t"; 1057 pref = "t";
1059 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1058 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1060 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1059 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1061 //remote->deleteIncidence( inR ); 1060 //remote->deleteIncidence( inR );
1062 ++deletedEventR; 1061 ++deletedEventR;
1063 } else { 1062 } else {
1064 inR->setLastModified( modifiedCalendar ); 1063 inR->setLastModified( modifiedCalendar );
1065 inL = inR->clone(); 1064 inL = inR->clone();
1066 local->addIncidence( inL ); 1065 local->addIncidence( inL );
1067 ++addedEvent; 1066 ++addedEvent;
1068 } 1067 }
1069 } else { 1068 } else {
1070 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1069 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1071 inR->setLastModified( modifiedCalendar ); 1070 inR->setLastModified( modifiedCalendar );
1072 local->addIncidence( inR->clone() ); 1071 local->addIncidence( inR->clone() );
1073 ++addedEvent; 1072 ++addedEvent;
1074 } else { 1073 } else {
1075 checkExternSyncEvent(eventRSyncSharp, inR); 1074 checkExternSyncEvent(eventRSyncSharp, inR);
1076 remote->deleteIncidence( inR ); 1075 remote->deleteIncidence( inR );
1077 ++deletedEventR; 1076 ++deletedEventR;
1078 } 1077 }
1079 } 1078 }
1080 } 1079 }
1081 } 1080 }
1082 inR = er.next(); 1081 inR = er.next();
1083 } 1082 }
1084 QPtrList<Incidence> el = local->rawIncidences(); 1083 QPtrList<Incidence> el = local->rawIncidences();
1085 inL = el.first(); 1084 inL = el.first();
1086 modulo = (el.count()/10)+1; 1085 modulo = (el.count()/10)+1;
1087 bar.setCaption (i18n("Add / remove events") ); 1086 bar.setCaption (i18n("Add / remove events") );
1088 bar.setTotalSteps ( el.count() ) ; 1087 bar.setTotalSteps ( el.count() ) ;
1089 bar.show(); 1088 bar.show();
1090 incCounter = 0; 1089 incCounter = 0;
1091 1090
1092 while ( inL ) { 1091 while ( inL ) {
1093 1092
1094 qApp->processEvents(); 1093 qApp->processEvents();
1095 if ( ! bar.isVisible() ) 1094 if ( ! bar.isVisible() )
1096 return false; 1095 return false;
1097 if ( incCounter % modulo == 0 ) 1096 if ( incCounter % modulo == 0 )
1098 bar.setProgress( incCounter ); 1097 bar.setProgress( incCounter );
1099 ++incCounter; 1098 ++incCounter;
1100 uid = inL->uid(); 1099 uid = inL->uid();
1101 bool skipIncidence = false; 1100 bool skipIncidence = false;
1102 if ( uid.left(15) == QString("last-syncEvent-") ) 1101 if ( uid.left(15) == QString("last-syncEvent-") )
1103 skipIncidence = true; 1102 skipIncidence = true;
1104 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1103 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1105 skipIncidence = true; 1104 skipIncidence = true;
1106 if ( !skipIncidence ) { 1105 if ( !skipIncidence ) {
1107 inR = remote->incidence( uid ); 1106 inR = remote->incidence( uid );
1108 if ( ! inR ) { 1107 if ( ! inR ) {
1109 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1108 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1110 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1109 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1111 checkExternSyncEvent(eventLSyncSharp, inL); 1110 checkExternSyncEvent(eventLSyncSharp, inL);
1112 local->deleteIncidence( inL ); 1111 local->deleteIncidence( inL );
1113 ++deletedEventL; 1112 ++deletedEventL;
1114 } else { 1113 } else {
1115 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1114 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1116 inL->removeID(mCurrentSyncDevice ); 1115 inL->removeID(mCurrentSyncDevice );
1117 ++addedEventR; 1116 ++addedEventR;
1118 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1117 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1119 inL->setLastModified( modifiedCalendar ); 1118 inL->setLastModified( modifiedCalendar );
1120 inR = inL->clone(); 1119 inR = inL->clone();
1121 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1120 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1122 remote->addIncidence( inR ); 1121 remote->addIncidence( inR );
1123 } 1122 }
1124 } 1123 }
1125 } else { 1124 } else {
1126 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1125 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1127 checkExternSyncEvent(eventLSyncSharp, inL); 1126 checkExternSyncEvent(eventLSyncSharp, inL);
1128 local->deleteIncidence( inL ); 1127 local->deleteIncidence( inL );
1129 ++deletedEventL; 1128 ++deletedEventL;
1130 } else { 1129 } else {
1131 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1130 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1132 ++addedEventR; 1131 ++addedEventR;
1133 inL->setLastModified( modifiedCalendar ); 1132 inL->setLastModified( modifiedCalendar );
1134 remote->addIncidence( inL->clone() ); 1133 remote->addIncidence( inL->clone() );
1135 } 1134 }
1136 } 1135 }
1137 } 1136 }
1138 } 1137 }
1139 } 1138 }
1140 inL = el.next(); 1139 inL = el.next();
1141 } 1140 }
1142 int delFut = 0; 1141 int delFut = 0;
1143 int remRem = 0; 1142 int remRem = 0;
1144 if ( mSyncManager->mWriteBackInFuture ) { 1143 if ( mSyncManager->mWriteBackInFuture ) {
1145 er = remote->rawIncidences(); 1144 er = remote->rawIncidences();
1146 remRem = er.count(); 1145 remRem = er.count();
1147 inR = er.first(); 1146 inR = er.first();
1148 QDateTime dt; 1147 QDateTime dt;
1149 QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); 1148 QDateTime cur = QDateTime::currentDateTime().addDays( -7 );
1150 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 ); 1149 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 );
1151 while ( inR ) { 1150 while ( inR ) {
1152 if ( inR->type() == "Todo" ) { 1151 if ( inR->type() == "Todo" ) {
1153 Todo * t = (Todo*)inR; 1152 Todo * t = (Todo*)inR;
1154 if ( t->hasDueDate() ) 1153 if ( t->hasDueDate() )
1155 dt = t->dtDue(); 1154 dt = t->dtDue();
1156 else 1155 else
1157 dt = cur.addSecs( 62 ); 1156 dt = cur.addSecs( 62 );
1158 } 1157 }
1159 else if (inR->type() == "Event" ) { 1158 else if (inR->type() == "Event" ) {
1160 bool ok; 1159 bool ok;
1161 dt = inR->getNextOccurence( cur, &ok ); 1160 dt = inR->getNextOccurence( cur, &ok );
1162 if ( !ok ) 1161 if ( !ok )
1163 dt = cur.addSecs( -62 ); 1162 dt = cur.addSecs( -62 );
1164 } 1163 }
1165 else 1164 else
1166 dt = inR->dtStart(); 1165 dt = inR->dtStart();
1167 if ( dt < cur || dt > end ) { 1166 if ( dt < cur || dt > end ) {
1168 remote->deleteIncidence( inR ); 1167 remote->deleteIncidence( inR );
1169 ++delFut; 1168 ++delFut;
1170 } 1169 }
1171 inR = er.next(); 1170 inR = er.next();
1172 } 1171 }
1173 } 1172 }
1174 bar.hide(); 1173 bar.hide();
1175 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1174 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1176 eventLSync->setReadOnly( false ); 1175 eventLSync->setReadOnly( false );
1177 eventLSync->setDtStart( mLastCalendarSync ); 1176 eventLSync->setDtStart( mLastCalendarSync );
1178 eventRSync->setDtStart( mLastCalendarSync ); 1177 eventRSync->setDtStart( mLastCalendarSync );
1179 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1178 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1180 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1179 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1181 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1180 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1182 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1181 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1183 eventLSync->setReadOnly( true ); 1182 eventLSync->setReadOnly( true );
1184 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 1183 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncKDE) // kde is abnormal...
1185 remote->addEvent( eventRSync ); 1184 remote->addEvent( eventRSync );
1185 else
1186 delete eventRSync;
1186 QString mes; 1187 QString mes;
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 ); 1188 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 );
1188 QString delmess; 1189 QString delmess;
1189 if ( delFut ) { 1190 if ( 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); 1191 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);
1191 mes += delmess; 1192 mes += delmess;
1192 } 1193 }
1193 if ( mSyncManager->mShowSyncSummary ) { 1194 if ( mSyncManager->mShowSyncSummary ) {
1194 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1195 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1195 } 1196 }
1196 qDebug( mes ); 1197 qDebug( mes );
1197 mCalendar->checkAlarmForIncidence( 0, true ); 1198 mCalendar->checkAlarmForIncidence( 0, true );
1198 return syncOK; 1199 return syncOK;
1199} 1200}
1200 1201
1201void CalendarView::setSyncDevice( QString s ) 1202void CalendarView::setSyncDevice( QString s )
1202{ 1203{
1203 mCurrentSyncDevice= s; 1204 mCurrentSyncDevice= s;
1204} 1205}
1205void CalendarView::setSyncName( QString s ) 1206void CalendarView::setSyncName( QString s )
1206{ 1207{
1207 mCurrentSyncName= s; 1208 mCurrentSyncName= s;
1208} 1209}
1209bool CalendarView::syncCalendar(QString filename, int mode) 1210bool CalendarView::syncCalendar(QString filename, int mode)
1210{ 1211{
1211 //qDebug("syncCalendar %s ", filename.latin1()); 1212 //qDebug("syncCalendar %s ", filename.latin1());
1212 mGlobalSyncMode = SYNC_MODE_NORMAL; 1213 mGlobalSyncMode = SYNC_MODE_NORMAL;
1213 CalendarLocal* calendar = new CalendarLocal(); 1214 CalendarLocal* calendar = new CalendarLocal();
1214 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1215 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1215 FileStorage* storage = new FileStorage( calendar ); 1216 FileStorage* storage = new FileStorage( calendar );
1216 bool syncOK = false; 1217 bool syncOK = false;
1217 storage->setFileName( filename ); 1218 storage->setFileName( filename );
1218 // qDebug("loading ... "); 1219 // qDebug("loading ... ");
1219 if ( storage->load() ) { 1220 if ( storage->load() ) {
1220 getEventViewerDialog()->setSyncMode( true ); 1221 getEventViewerDialog()->setSyncMode( true );
1221 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1222 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1222 getEventViewerDialog()->setSyncMode( false ); 1223 getEventViewerDialog()->setSyncMode( false );
1223 if ( syncOK ) { 1224 if ( syncOK ) {
1224 if ( mSyncManager->mWriteBackFile ) 1225 if ( mSyncManager->mWriteBackFile )
1225 { 1226 {
1226 storage->setSaveFormat( new ICalFormat() ); 1227 storage->setSaveFormat( new ICalFormat() );
1227 storage->save(); 1228 storage->save();
1228 } 1229 }
1229 } 1230 }
1230 setModified( true ); 1231 setModified( true );
1231 } 1232 }
1232 delete storage; 1233 delete storage;
1233 delete calendar; 1234 delete calendar;
1234 if ( syncOK ) 1235 if ( syncOK )
1235 updateView(); 1236 updateView();
1236 return syncOK; 1237 return syncOK;
1237} 1238}
1238 1239
1239void CalendarView::syncExternal( int mode ) 1240void CalendarView::syncExternal( int mode )
1240{ 1241{
1241 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1242 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1242 1243
1243 qApp->processEvents(); 1244 qApp->processEvents();
1244 CalendarLocal* calendar = new CalendarLocal(); 1245 CalendarLocal* calendar = new CalendarLocal();
1245 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1246 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1246 bool syncOK = false; 1247 bool syncOK = false;
1247 bool loadSuccess = false; 1248 bool loadSuccess = false;
1248 PhoneFormat* phoneFormat = 0; 1249 PhoneFormat* phoneFormat = 0;
1249#ifndef DESKTOP_VERSION 1250#ifndef DESKTOP_VERSION
1250 SharpFormat* sharpFormat = 0; 1251 SharpFormat* sharpFormat = 0;
1251 if ( mode == 0 ) { // sharp 1252 if ( mode == 0 ) { // sharp
1252 sharpFormat = new SharpFormat () ; 1253 sharpFormat = new SharpFormat () ;
1253 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1254 loadSuccess = sharpFormat->load( calendar, mCalendar );
1254 1255
1255 } else 1256 } else
1256#endif 1257#endif
1257 if ( mode == 1 ) { // phone 1258 if ( mode == 1 ) { // phone
1258 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1259 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1259 mSyncManager->mPhoneDevice, 1260 mSyncManager->mPhoneDevice,
1260 mSyncManager->mPhoneConnection, 1261 mSyncManager->mPhoneConnection,
1261 mSyncManager->mPhoneModel); 1262 mSyncManager->mPhoneModel);
1262 loadSuccess = phoneFormat->load( calendar,mCalendar); 1263 loadSuccess = phoneFormat->load( calendar,mCalendar);
1263 1264
1264 } else 1265 } else
1265 return; 1266 return;
1266 if ( loadSuccess ) { 1267 if ( loadSuccess ) {
1267 getEventViewerDialog()->setSyncMode( true ); 1268 getEventViewerDialog()->setSyncMode( true );
1268 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1269 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1269 getEventViewerDialog()->setSyncMode( false ); 1270 getEventViewerDialog()->setSyncMode( false );
1270 qApp->processEvents(); 1271 qApp->processEvents();
1271 if ( syncOK ) { 1272 if ( syncOK ) {
1272 if ( mSyncManager->mWriteBackFile ) 1273 if ( mSyncManager->mWriteBackFile )
1273 { 1274 {
1274 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1275 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1275 Incidence* inc = iL.first(); 1276 Incidence* inc = iL.first();
1276 if ( phoneFormat ) { 1277 if ( phoneFormat ) {
1277 while ( inc ) { 1278 while ( inc ) {
1278 inc->removeID(mCurrentSyncDevice); 1279 inc->removeID(mCurrentSyncDevice);
1279 inc = iL.next(); 1280 inc = iL.next();
1280 } 1281 }
1281 } 1282 }
1282#ifndef DESKTOP_VERSION 1283#ifndef DESKTOP_VERSION
1283 if ( sharpFormat ) 1284 if ( sharpFormat )
1284 sharpFormat->save(calendar); 1285 sharpFormat->save(calendar);
1285#endif 1286#endif
1286 if ( phoneFormat ) 1287 if ( phoneFormat )
1287 phoneFormat->save(calendar); 1288 phoneFormat->save(calendar);
1288 iL = calendar->rawIncidences(); 1289 iL = calendar->rawIncidences();
1289 inc = iL.first(); 1290 inc = iL.first();
1290 Incidence* loc; 1291 Incidence* loc;
1291 while ( inc ) { 1292 while ( inc ) {
1292 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1293 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1293 loc = mCalendar->incidence(inc->uid() ); 1294 loc = mCalendar->incidence(inc->uid() );
1294 if ( loc ) { 1295 if ( loc ) {
1295 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1296 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1296 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1297 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1297 } 1298 }
1298 } 1299 }
1299 inc = iL.next(); 1300 inc = iL.next();
1300 } 1301 }
1301 Incidence* lse = getLastSyncEvent(); 1302 Incidence* lse = getLastSyncEvent();
1302 if ( lse ) { 1303 if ( lse ) {
1303 lse->setReadOnly( false ); 1304 lse->setReadOnly( false );
1304 lse->setDescription( "" ); 1305 lse->setDescription( "" );
1305 lse->setReadOnly( true ); 1306 lse->setReadOnly( true );
1306 } 1307 }
1307 } 1308 }
1308 } 1309 }
1309 setModified( true ); 1310 setModified( true );
1310 } else { 1311 } else {
1311 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1312 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1312 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1313 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1313 question, i18n("Ok")) ; 1314 question, i18n("Ok")) ;
1314 1315
1315 } 1316 }
1316 delete calendar; 1317 delete calendar;
1317 updateView(); 1318 updateView();
1318 return ;//syncOK; 1319 return ;//syncOK;
1319 1320
1320} 1321}
1321 1322
1322bool CalendarView::importBday() 1323bool CalendarView::importBday()
1323{ 1324{
1324#ifndef KORG_NOKABC 1325#ifndef KORG_NOKABC
1325 1326
1326#ifdef DESKTOP_VERSION 1327#ifdef DESKTOP_VERSION
1327 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1328 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1328 KABC::AddressBook::Iterator it; 1329 KABC::AddressBook::Iterator it;
1329 int count = 0; 1330 int count = 0;
1330 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1331 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1331 ++count; 1332 ++count;
1332 } 1333 }
1333 QProgressBar bar(count,0 ); 1334 QProgressBar bar(count,0 );
1334 int w = 300; 1335 int w = 300;
1335 if ( QApplication::desktop()->width() < 320 ) 1336 if ( QApplication::desktop()->width() < 320 )
1336 w = 220; 1337 w = 220;
1337 int h = bar.sizeHint().height() ; 1338 int h = bar.sizeHint().height() ;
1338 int dw = QApplication::desktop()->width(); 1339 int dw = QApplication::desktop()->width();
1339 int dh = QApplication::desktop()->height(); 1340 int dh = QApplication::desktop()->height();
1340 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1341 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1341 bar.show(); 1342 bar.show();
1342 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1343 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1343 qApp->processEvents(); 1344 qApp->processEvents();
1344 count = 0; 1345 count = 0;
1345 int addCount = 0; 1346 int addCount = 0;
1346 KCal::Attendee* a = 0; 1347 KCal::Attendee* a = 0;
1347 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1348 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1348 if ( ! bar.isVisible() ) 1349 if ( ! bar.isVisible() )
1349 return false; 1350 return false;
1350 bar.setProgress( count++ ); 1351 bar.setProgress( count++ );
1351 qApp->processEvents(); 1352 qApp->processEvents();
1352 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1353 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1353 if ( (*it).birthday().date().isValid() ){ 1354 if ( (*it).birthday().date().isValid() ){
1354 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1355 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1355 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1356 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1356 ++addCount; 1357 ++addCount;
1357 } 1358 }
1358 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1359 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1359 if ( anni.isValid() ){ 1360 if ( anni.isValid() ){
1360 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1361 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1361 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1362 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1362 ++addCount; 1363 ++addCount;
1363 } 1364 }
1364 } 1365 }
1365 updateView(); 1366 updateView();
1366 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1367 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1367#else //DESKTOP_VERSION 1368#else //DESKTOP_VERSION
1368 1369
1369 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1370 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1370 // the result should now arrive through method insertBirthdays 1371 // the result should now arrive through method insertBirthdays
1371 1372
1372#endif //DESKTOP_VERSION 1373#endif //DESKTOP_VERSION
1373 1374
1374#endif //KORG_NOKABC 1375#endif //KORG_NOKABC
1375 1376
1376 1377
1377 return true; 1378 return true;
1378} 1379}
1379 1380
1380// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1381// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1381void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1382void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1382 const QStringList& anniversaryList, const QStringList& realNameList, 1383 const QStringList& anniversaryList, const QStringList& realNameList,
1383 const QStringList& emailList, const QStringList& assembledNameList, 1384 const QStringList& emailList, const QStringList& assembledNameList,
1384 const QStringList& uidList) 1385 const QStringList& uidList)
1385{ 1386{
1386 qDebug("CalendarView::insertBirthdays"); 1387 qDebug("CalendarView::insertBirthdays");
1387 if (uid == this->name()) 1388 if (uid == this->name())
1388 { 1389 {
1389 int count = birthdayList.count(); 1390 int count = birthdayList.count();
1390 int addCount = 0; 1391 int addCount = 0;
1391 KCal::Attendee* a = 0; 1392 KCal::Attendee* a = 0;
1392 1393
1393 qDebug("CalView 1 %i", count); 1394 qDebug("CalView 1 %i", count);
1394 1395
1395 QProgressBar bar(count,0 ); 1396 QProgressBar bar(count,0 );
1396 int w = 300; 1397 int w = 300;
1397 if ( QApplication::desktop()->width() < 320 ) 1398 if ( QApplication::desktop()->width() < 320 )
1398 w = 220; 1399 w = 220;
1399 int h = bar.sizeHint().height() ; 1400 int h = bar.sizeHint().height() ;
1400 int dw = QApplication::desktop()->width(); 1401 int dw = QApplication::desktop()->width();
1401 int dh = QApplication::desktop()->height(); 1402 int dh = QApplication::desktop()->height();
1402 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1403 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1403 bar.show(); 1404 bar.show();
1404 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1405 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1405 qApp->processEvents(); 1406 qApp->processEvents();
1406 1407
1407 QDate birthday; 1408 QDate birthday;
1408 QDate anniversary; 1409 QDate anniversary;
1409 QString realName; 1410 QString realName;
1410 QString email; 1411 QString email;
1411 QString assembledName; 1412 QString assembledName;
1412 QString uid; 1413 QString uid;
1413 bool ok = true; 1414 bool ok = true;
1414 for ( int i = 0; i < count; i++) 1415 for ( int i = 0; i < count; i++)
1415 { 1416 {
1416 if ( ! bar.isVisible() ) 1417 if ( ! bar.isVisible() )
1417 return; 1418 return;
1418 bar.setProgress( i ); 1419 bar.setProgress( i );
1419 qApp->processEvents(); 1420 qApp->processEvents();
1420 1421
1421 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1422 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1422 if (!ok) { 1423 if (!ok) {
1423 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1424 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1424 } 1425 }
1425 1426
1426 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1427 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1427 if (!ok) { 1428 if (!ok) {
1428 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1429 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1429 } 1430 }
1430 realName = realNameList[i]; 1431 realName = realNameList[i];
1431 email = emailList[i]; 1432 email = emailList[i];
1432 assembledName = assembledNameList[i]; 1433 assembledName = assembledNameList[i];
1433 uid = uidList[i]; 1434 uid = uidList[i];
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() ); 1435 //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() );
1435 1436
1436 if ( birthday.isValid() ){ 1437 if ( birthday.isValid() ){
1437 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1438 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1438 KCal::Attendee::ReqParticipant,uid) ; 1439 KCal::Attendee::ReqParticipant,uid) ;
1439 if ( addAnniversary( birthday, assembledName, a, true ) ) 1440 if ( addAnniversary( birthday, assembledName, a, true ) )
1440 ++addCount; 1441 ++addCount;
1441 } 1442 }
1442 1443
1443 if ( anniversary.isValid() ){ 1444 if ( anniversary.isValid() ){
1444 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1445 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1445 KCal::Attendee::ReqParticipant,uid) ; 1446 KCal::Attendee::ReqParticipant,uid) ;
1446 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1447 if ( addAnniversary( anniversary, assembledName, a, false ) )
1447 ++addCount; 1448 ++addCount;
1448 } 1449 }
1449 } 1450 }
1450 1451
1451 updateView(); 1452 updateView();
1452 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1453 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1453 1454
1454 } 1455 }
1455 1456
1456} 1457}
1457 1458
1458 1459
1459 1460
1460bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1461bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1461{ 1462{
1462 //qDebug("addAnni "); 1463 //qDebug("addAnni ");
1463 Event * ev = new Event(); 1464 Event * ev = new Event();
1464 if ( a ) { 1465 if ( a ) {
1465 ev->addAttendee( a ); 1466 ev->addAttendee( a );
1466 } 1467 }
1467 QString kind; 1468 QString kind;
1468 if ( birthday ) 1469 if ( birthday )
1469 kind = i18n( "Birthday" ); 1470 kind = i18n( "Birthday" );
1470 else 1471 else
1471 kind = i18n( "Anniversary" ); 1472 kind = i18n( "Anniversary" );
1472 ev->setSummary( name + " - " + kind ); 1473 ev->setSummary( name + " - " + kind );
1473 ev->setOrganizer( "nobody@nowhere" ); 1474 ev->setOrganizer( "nobody@nowhere" );
1474 ev->setCategories( kind ); 1475 ev->setCategories( kind );
1475 ev->setDtStart( QDateTime(date) ); 1476 ev->setDtStart( QDateTime(date) );
1476 ev->setDtEnd( QDateTime(date) ); 1477 ev->setDtEnd( QDateTime(date) );
1477 ev->setFloats( true ); 1478 ev->setFloats( true );
1478 Recurrence * rec = ev->recurrence(); 1479 Recurrence * rec = ev->recurrence();
1479 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1480 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1480 rec->addYearlyNum( date.month() ); 1481 rec->addYearlyNum( date.month() );
1481 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1482 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1482 delete ev; 1483 delete ev;
1483 return false; 1484 return false;
1484 } 1485 }
1485 return true; 1486 return true;
1486 1487
1487} 1488}
1488bool CalendarView::importQtopia( const QString &categories, 1489bool CalendarView::importQtopia( const QString &categories,
1489 const QString &datebook, 1490 const QString &datebook,
1490 const QString &todolist ) 1491 const QString &todolist )
1491{ 1492{
1492 1493
1493 QtopiaFormat qtopiaFormat; 1494 QtopiaFormat qtopiaFormat;
1494 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1495 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1495 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1496 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1496 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1497 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1497 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1498 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1498 1499
1499 updateView(); 1500 updateView();
1500 return true; 1501 return true;
1501 1502
1502#if 0 1503#if 0
1503 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1504 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1504 mCurrentSyncDevice = "qtopia-XML"; 1505 mCurrentSyncDevice = "qtopia-XML";
1505 if ( mSyncManager->mAskForPreferences ) 1506 if ( mSyncManager->mAskForPreferences )
1506 edit_sync_options(); 1507 edit_sync_options();
1507 qApp->processEvents(); 1508 qApp->processEvents();
1508 CalendarLocal* calendar = new CalendarLocal(); 1509 CalendarLocal* calendar = new CalendarLocal();
1509 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1510 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1510 bool syncOK = false; 1511 bool syncOK = false;
1511 QtopiaFormat qtopiaFormat; 1512 QtopiaFormat qtopiaFormat;
1512 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1513 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1513 bool loadOk = true; 1514 bool loadOk = true;
1514 if ( !categories.isEmpty() ) 1515 if ( !categories.isEmpty() )
1515 loadOk = qtopiaFormat.load( calendar, categories ); 1516 loadOk = qtopiaFormat.load( calendar, categories );
1516 if ( loadOk && !datebook.isEmpty() ) 1517 if ( loadOk && !datebook.isEmpty() )
1517 loadOk = qtopiaFormat.load( calendar, datebook ); 1518 loadOk = qtopiaFormat.load( calendar, datebook );
1518 if ( loadOk && !todolist.isEmpty() ) 1519 if ( loadOk && !todolist.isEmpty() )
1519 loadOk = qtopiaFormat.load( calendar, todolist ); 1520 loadOk = qtopiaFormat.load( calendar, todolist );
1520 1521
1521 if ( loadOk ) { 1522 if ( loadOk ) {
1522 getEventViewerDialog()->setSyncMode( true ); 1523 getEventViewerDialog()->setSyncMode( true );
1523 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1524 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1524 getEventViewerDialog()->setSyncMode( false ); 1525 getEventViewerDialog()->setSyncMode( false );
1525 qApp->processEvents(); 1526 qApp->processEvents();
1526 if ( syncOK ) { 1527 if ( syncOK ) {
1527 if ( mSyncManager->mWriteBackFile ) 1528 if ( mSyncManager->mWriteBackFile )
1528 { 1529 {
1529 // write back XML file 1530 // write back XML file
1530 1531
1531 } 1532 }
1532 setModified( true ); 1533 setModified( true );
1533 } 1534 }
1534 } else { 1535 } else {
1535 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1536 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1536 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1537 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1537 question, i18n("Ok")) ; 1538 question, i18n("Ok")) ;
1538 } 1539 }
1539 delete calendar; 1540 delete calendar;
1540 updateView(); 1541 updateView();
1541 return syncOK; 1542 return syncOK;
1542 1543
1543 1544
1544#endif 1545#endif
1545 1546
1546} 1547}
1547 1548
1548void CalendarView::setSyncEventsReadOnly() 1549void CalendarView::setSyncEventsReadOnly()
1549{ 1550{
1550 Event * ev; 1551 Event * ev;
1551 QPtrList<Event> eL = mCalendar->rawEvents(); 1552 QPtrList<Event> eL = mCalendar->rawEvents();
1552 ev = eL.first(); 1553 ev = eL.first();
1553 while ( ev ) { 1554 while ( ev ) {
1554 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1555 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1555 ev->setReadOnly( true ); 1556 ev->setReadOnly( true );
1556 ev = eL.next(); 1557 ev = eL.next();
1557 } 1558 }
1558} 1559}
1559bool CalendarView::openCalendar(QString filename, bool merge) 1560bool CalendarView::openCalendar(QString filename, bool merge)
1560{ 1561{
1561 1562
1562 if (filename.isEmpty()) { 1563 if (filename.isEmpty()) {
1563 return false; 1564 return false;
1564 } 1565 }
1565 1566
1566 if (!QFile::exists(filename)) { 1567 if (!QFile::exists(filename)) {
1567 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1568 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1568 return false; 1569 return false;
1569 } 1570 }
1570 1571
1571 globalFlagBlockAgenda = 1; 1572 globalFlagBlockAgenda = 1;
1572 if (!merge) mCalendar->close(); 1573 if (!merge) mCalendar->close();
1573 1574
1574 mStorage->setFileName( filename ); 1575 mStorage->setFileName( filename );
1575 1576
1576 if ( mStorage->load() ) { 1577 if ( mStorage->load() ) {
1577 if ( merge ) ;//setModified( true ); 1578 if ( merge ) ;//setModified( true );
1578 else { 1579 else {
1579 //setModified( true ); 1580 //setModified( true );
1580 mViewManager->setDocumentId( filename ); 1581 mViewManager->setDocumentId( filename );
1581 mDialogManager->setDocumentId( filename ); 1582 mDialogManager->setDocumentId( filename );
1582 mTodoList->setDocumentId( filename ); 1583 mTodoList->setDocumentId( filename );
1583 } 1584 }
1584 globalFlagBlockAgenda = 2; 1585 globalFlagBlockAgenda = 2;
1585 // if ( getLastSyncEvent() ) 1586 // if ( getLastSyncEvent() )
1586 // getLastSyncEvent()->setReadOnly( true ); 1587 // getLastSyncEvent()->setReadOnly( true );
1587 mCalendar->reInitAlarmSettings(); 1588 mCalendar->reInitAlarmSettings();
1588 setSyncEventsReadOnly(); 1589 setSyncEventsReadOnly();
1589 updateUnmanagedViews(); 1590 updateUnmanagedViews();
1590 updateView(); 1591 updateView();
1591 if ( filename != MainWindow::defaultFileName() ) { 1592 if ( filename != MainWindow::defaultFileName() ) {
1592 saveCalendar( MainWindow::defaultFileName() ); 1593 saveCalendar( MainWindow::defaultFileName() );
1593 } else { 1594 } else {
1594 QFileInfo finf ( MainWindow::defaultFileName()); 1595 QFileInfo finf ( MainWindow::defaultFileName());
1595 if ( finf.exists() ) { 1596 if ( finf.exists() ) {
1596 setLoadedFileVersion( finf.lastModified () ); 1597 setLoadedFileVersion( finf.lastModified () );
1597 } 1598 }
1598 } 1599 }
1599 return true; 1600 return true;
1600 } else { 1601 } else {
1601 // while failing to load, the calendar object could 1602 // while failing to load, the calendar object could
1602 // have become partially populated. Clear it out. 1603 // have become partially populated. Clear it out.
1603 if ( !merge ) { 1604 if ( !merge ) {
1604 mCalendar->close(); 1605 mCalendar->close();
1605 mViewManager->setDocumentId( filename ); 1606 mViewManager->setDocumentId( filename );
1606 mDialogManager->setDocumentId( filename ); 1607 mDialogManager->setDocumentId( filename );
1607 mTodoList->setDocumentId( filename ); 1608 mTodoList->setDocumentId( filename );
1608 } 1609 }
1609 1610
1610 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1611 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1611 1612
1612 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 1613 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
1613 globalFlagBlockAgenda = 2; 1614 globalFlagBlockAgenda = 2;
1614 mCalendar->reInitAlarmSettings(); 1615 mCalendar->reInitAlarmSettings();
1615 setSyncEventsReadOnly(); 1616 setSyncEventsReadOnly();
1616 updateUnmanagedViews(); 1617 updateUnmanagedViews();
1617 updateView(); 1618 updateView();
1618 } 1619 }
1619 return false; 1620 return false;
1620} 1621}
1621void CalendarView::showOpenError() 1622void CalendarView::showOpenError()
1622{ 1623{
1623 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 1624 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
1624} 1625}
1625void CalendarView::setLoadedFileVersion(QDateTime dt) 1626void CalendarView::setLoadedFileVersion(QDateTime dt)
1626{ 1627{
1627 loadedFileVersion = dt; 1628 loadedFileVersion = dt;
1628} 1629}
1629bool CalendarView::checkFileChanged(QString fn) 1630bool CalendarView::checkFileChanged(QString fn)
1630{ 1631{
1631 QFileInfo finf ( fn ); 1632 QFileInfo finf ( fn );
1632 if ( !finf.exists() ) 1633 if ( !finf.exists() )
1633 return true; 1634 return true;
1634 QDateTime dt = finf.lastModified (); 1635 QDateTime dt = finf.lastModified ();
1635 if ( dt <= loadedFileVersion ) 1636 if ( dt <= loadedFileVersion )
1636 return false; 1637 return false;
1637 return true; 1638 return true;
1638 1639
1639} 1640}
1640void CalendarView::watchSavedFile() 1641void CalendarView::watchSavedFile()
1641{ 1642{
1642 QFileInfo finf ( MainWindow::defaultFileName()); 1643 QFileInfo finf ( MainWindow::defaultFileName());
1643 if ( !finf.exists() ) 1644 if ( !finf.exists() )
1644 return; 1645 return;
1645 QDateTime dt = finf.lastModified (); 1646 QDateTime dt = finf.lastModified ();
1646 if ( dt < loadedFileVersion ) { 1647 if ( dt < loadedFileVersion ) {
1647 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 1648 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
1648 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 1649 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
1649 return; 1650 return;
1650 } 1651 }
1651 loadedFileVersion = dt; 1652 loadedFileVersion = dt;
1652} 1653}
1653 1654
1654bool CalendarView::checkFileVersion(QString fn) 1655bool CalendarView::checkFileVersion(QString fn)
1655{ 1656{
1656 QFileInfo finf ( fn ); 1657 QFileInfo finf ( fn );
1657 if ( !finf.exists() ) 1658 if ( !finf.exists() )
1658 return true; 1659 return true;
1659 QDateTime dt = finf.lastModified (); 1660 QDateTime dt = finf.lastModified ();
1660 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1661 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1661 //qDebug("file on disk version %s",dt.toString().latin1()); 1662 //qDebug("file on disk version %s",dt.toString().latin1());
1662 if ( dt <= loadedFileVersion ) 1663 if ( dt <= loadedFileVersion )
1663 return true; 1664 return 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)) , 1665 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)) ,
1665 i18n("KO/Pi Warning"),i18n("Overwrite"), 1666 i18n("KO/Pi Warning"),i18n("Overwrite"),
1666 i18n("Sync+save")); 1667 i18n("Sync+save"));
1667 1668
1668 if ( km == KMessageBox::Cancel ) 1669 if ( km == KMessageBox::Cancel )
1669 return false; 1670 return false;
1670 if ( km == KMessageBox::Yes ) 1671 if ( km == KMessageBox::Yes )
1671 return true; 1672 return true;
1672 1673
1673 setSyncDevice("deleteaftersync" ); 1674 setSyncDevice("deleteaftersync" );
1674 mSyncManager->mAskForPreferences = true; 1675 mSyncManager->mAskForPreferences = true;
1675 mSyncManager->mSyncAlgoPrefs = 3; 1676 mSyncManager->mSyncAlgoPrefs = 3;
1676 mSyncManager->mWriteBackFile = false; 1677 mSyncManager->mWriteBackFile = false;
1677 mSyncManager->mWriteBackExistingOnly = false; 1678 mSyncManager->mWriteBackExistingOnly = false;
1678 mSyncManager->mShowSyncSummary = false; 1679 mSyncManager->mShowSyncSummary = false;
1679 syncCalendar( fn, 3 ); 1680 syncCalendar( fn, 3 );
1680 Event * e = getLastSyncEvent(); 1681 Event * e = getLastSyncEvent();
1681 mCalendar->deleteEvent ( e ); 1682 mCalendar->deleteEvent ( e );
1682 updateView(); 1683 updateView();
1683 return true; 1684 return true;
1684} 1685}
1685 1686
1686bool CalendarView::saveCalendar( QString filename ) 1687bool CalendarView::saveCalendar( QString filename )
1687{ 1688{
1688 1689
1689 // Store back all unsaved data into calendar object 1690 // Store back all unsaved data into calendar object
1690 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 1691 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
1691 if ( mViewManager->currentView() ) 1692 if ( mViewManager->currentView() )
1692 mViewManager->currentView()->flushView(); 1693 mViewManager->currentView()->flushView();
1693 1694
1694 1695
1695 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 1696 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
1696 mStorage->setSaveFormat( new ICalFormat() ); 1697 mStorage->setSaveFormat( new ICalFormat() );
1697 mStorage->setFileName( filename ); 1698 mStorage->setFileName( filename );
1698 bool success; 1699 bool success;
1699 success = mStorage->save(); 1700 success = mStorage->save();
1700 if ( !success ) { 1701 if ( !success ) {
1701 return false; 1702 return false;
1702 } 1703 }
1703 if ( filename == MainWindow::defaultFileName() ) { 1704 if ( filename == MainWindow::defaultFileName() ) {
1704 setLoadedFileVersion( lfv ); 1705 setLoadedFileVersion( lfv );
1705 watchSavedFile(); 1706 watchSavedFile();
1706 } 1707 }
1707 return true; 1708 return true;
1708} 1709}
1709 1710
1710void CalendarView::closeCalendar() 1711void CalendarView::closeCalendar()
1711{ 1712{
1712 1713
1713 // child windows no longer valid 1714 // child windows no longer valid
1714 emit closingDown(); 1715 emit closingDown();
1715 1716
1716 mCalendar->close(); 1717 mCalendar->close();
1717 setModified(false); 1718 setModified(false);
1718 updateView(); 1719 updateView();
1719} 1720}
1720 1721
1721void CalendarView::archiveCalendar() 1722void CalendarView::archiveCalendar()
1722{ 1723{
1723 mDialogManager->showArchiveDialog(); 1724 mDialogManager->showArchiveDialog();
1724} 1725}
1725 1726
1726 1727
1727void CalendarView::readSettings() 1728void CalendarView::readSettings()
1728{ 1729{
1729 1730
1730 1731
1731 // mViewManager->showAgendaView(); 1732 // mViewManager->showAgendaView();
1732 QString str; 1733 QString str;
1733 //qDebug("CalendarView::readSettings() "); 1734 //qDebug("CalendarView::readSettings() ");
1734 // read settings from the KConfig, supplying reasonable 1735 // read settings from the KConfig, supplying reasonable
1735 // defaults where none are to be found 1736 // defaults where none are to be found
1736 KConfig *config = KOGlobals::config(); 1737 KConfig *config = KOGlobals::config();
1737#ifndef KORG_NOSPLITTER 1738#ifndef KORG_NOSPLITTER
1738 config->setGroup("KOrganizer Geometry"); 1739 config->setGroup("KOrganizer Geometry");
1739 1740
1740 QValueList<int> sizes = config->readIntListEntry("Separator1"); 1741 QValueList<int> sizes = config->readIntListEntry("Separator1");
1741 if (sizes.count() != 2) { 1742 if (sizes.count() != 2) {
1742 sizes << mDateNavigator->minimumSizeHint().width(); 1743 sizes << mDateNavigator->minimumSizeHint().width();
1743 sizes << 300; 1744 sizes << 300;
1744 } 1745 }
1745 mPanner->setSizes(sizes); 1746 mPanner->setSizes(sizes);
1746 1747
1747 sizes = config->readIntListEntry("Separator2"); 1748 sizes = config->readIntListEntry("Separator2");
1748 if ( ( mResourceView && sizes.count() == 4 ) || 1749 if ( ( mResourceView && sizes.count() == 4 ) ||
1749 ( !mResourceView && sizes.count() == 3 ) ) { 1750 ( !mResourceView && sizes.count() == 3 ) ) {
1750 mLeftSplitter->setSizes(sizes); 1751 mLeftSplitter->setSizes(sizes);
1751 } 1752 }
1752#endif 1753#endif
1753 globalFlagBlockAgenda = 1; 1754 globalFlagBlockAgenda = 1;
1754 mViewManager->showAgendaView(); 1755 mViewManager->showAgendaView();
1755 //mViewManager->readSettings( config ); 1756 //mViewManager->readSettings( config );
1756 mTodoList->restoreLayout(config,QString("Todo Layout")); 1757 mTodoList->restoreLayout(config,QString("Todo Layout"));
1757 readFilterSettings(config); 1758 readFilterSettings(config);
1758 config->setGroup( "Views" ); 1759 config->setGroup( "Views" );
1759 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 1760 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
1760 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 1761 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
1761 else if ( dateCount == 7 ) mNavigator->selectWeek(); 1762 else if ( dateCount == 7 ) mNavigator->selectWeek();
1762 else mNavigator->selectDates( dateCount ); 1763 else mNavigator->selectDates( dateCount );
1763 // mViewManager->readSettings( config ); 1764 // mViewManager->readSettings( config );
1764 updateConfig(); 1765 updateConfig();
1765 globalFlagBlockAgenda = 2; 1766 globalFlagBlockAgenda = 2;
1766 mViewManager->readSettings( config ); 1767 mViewManager->readSettings( config );
1767#ifdef DESKTOP_VERSION 1768#ifdef DESKTOP_VERSION
1768 config->setGroup("WidgetLayout"); 1769 config->setGroup("WidgetLayout");
1769 QStringList list; 1770 QStringList list;
1770 list = config->readListEntry("MainLayout"); 1771 list = config->readListEntry("MainLayout");
1771 int x,y,w,h; 1772 int x,y,w,h;
1772 if ( ! list.isEmpty() ) { 1773 if ( ! list.isEmpty() ) {
1773 x = list[0].toInt(); 1774 x = list[0].toInt();
1774 y = list[1].toInt(); 1775 y = list[1].toInt();
1775 w = list[2].toInt(); 1776 w = list[2].toInt();
1776 h = list[3].toInt(); 1777 h = list[3].toInt();
1777 topLevelWidget()->setGeometry(x,y,w,h); 1778 topLevelWidget()->setGeometry(x,y,w,h);
1778 1779
1779 } else { 1780 } else {
1780 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 1781 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
1781 } 1782 }
1782 list = config->readListEntry("EditEventLayout"); 1783 list = config->readListEntry("EditEventLayout");
1783 if ( ! list.isEmpty() ) { 1784 if ( ! list.isEmpty() ) {
1784 x = list[0].toInt(); 1785 x = list[0].toInt();
1785 y = list[1].toInt(); 1786 y = list[1].toInt();
1786 w = list[2].toInt(); 1787 w = list[2].toInt();
1787 h = list[3].toInt(); 1788 h = list[3].toInt();
1788 mEventEditor->setGeometry(x,y,w,h); 1789 mEventEditor->setGeometry(x,y,w,h);
1789 1790
1790 } 1791 }
1791 list = config->readListEntry("EditTodoLayout"); 1792 list = config->readListEntry("EditTodoLayout");
1792 if ( ! list.isEmpty() ) { 1793 if ( ! list.isEmpty() ) {
1793 x = list[0].toInt(); 1794 x = list[0].toInt();
1794 y = list[1].toInt(); 1795 y = list[1].toInt();
1795 w = list[2].toInt(); 1796 w = list[2].toInt();
1796 h = list[3].toInt(); 1797 h = list[3].toInt();
1797 mTodoEditor->setGeometry(x,y,w,h); 1798 mTodoEditor->setGeometry(x,y,w,h);
1798 1799
1799 } 1800 }
1800 list = config->readListEntry("ViewerLayout"); 1801 list = config->readListEntry("ViewerLayout");
1801 if ( ! list.isEmpty() ) { 1802 if ( ! list.isEmpty() ) {
1802 x = list[0].toInt(); 1803 x = list[0].toInt();
1803 y = list[1].toInt(); 1804 y = list[1].toInt();
1804 w = list[2].toInt(); 1805 w = list[2].toInt();
1805 h = list[3].toInt(); 1806 h = list[3].toInt();
1806 getEventViewerDialog()->setGeometry(x,y,w,h); 1807 getEventViewerDialog()->setGeometry(x,y,w,h);
1807 } 1808 }
1808#endif 1809#endif
1809 1810
1810} 1811}
1811 1812
1812 1813
1813void CalendarView::writeSettings() 1814void CalendarView::writeSettings()
1814{ 1815{
1815 // kdDebug() << "CalendarView::writeSettings" << endl; 1816 // kdDebug() << "CalendarView::writeSettings" << endl;
1816 1817
1817 KConfig *config = KOGlobals::config(); 1818 KConfig *config = KOGlobals::config();
1818 1819
1819#ifndef KORG_NOSPLITTER 1820#ifndef KORG_NOSPLITTER
1820 config->setGroup("KOrganizer Geometry"); 1821 config->setGroup("KOrganizer Geometry");
1821 1822
1822 QValueList<int> list = mPanner->sizes(); 1823 QValueList<int> list = mPanner->sizes();
1823 config->writeEntry("Separator1",list); 1824 config->writeEntry("Separator1",list);
1824 1825
1825 list = mLeftSplitter->sizes(); 1826 list = mLeftSplitter->sizes();
1826 config->writeEntry("Separator2",list); 1827 config->writeEntry("Separator2",list);
1827#endif 1828#endif
1828 1829
1829 mViewManager->writeSettings( config ); 1830 mViewManager->writeSettings( config );
1830 mTodoList->saveLayout(config,QString("Todo Layout")); 1831 mTodoList->saveLayout(config,QString("Todo Layout"));
1831 mDialogManager->writeSettings( config ); 1832 mDialogManager->writeSettings( config );
1832 //KOPrefs::instance()->usrWriteConfig(); 1833 //KOPrefs::instance()->usrWriteConfig();
1833 KOPrefs::instance()->writeConfig(); 1834 KOPrefs::instance()->writeConfig();
1834 1835
1835 writeFilterSettings(config); 1836 writeFilterSettings(config);
1836 1837
1837 config->setGroup( "Views" ); 1838 config->setGroup( "Views" );
1838 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 1839 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
1839 1840
1840#ifdef DESKTOP_VERSION 1841#ifdef DESKTOP_VERSION
1841 config->setGroup("WidgetLayout"); 1842 config->setGroup("WidgetLayout");
1842 QStringList list ;//= config->readListEntry("MainLayout"); 1843 QStringList list ;//= config->readListEntry("MainLayout");
1843 int x,y,w,h; 1844 int x,y,w,h;
1844 QWidget* wid; 1845 QWidget* wid;
1845 wid = topLevelWidget(); 1846 wid = topLevelWidget();
1846 x = wid->geometry().x(); 1847 x = wid->geometry().x();
1847 y = wid->geometry().y(); 1848 y = wid->geometry().y();
1848 w = wid->width(); 1849 w = wid->width();
1849 h = wid->height(); 1850 h = wid->height();
1850 list.clear(); 1851 list.clear();
1851 list << QString::number( x ); 1852 list << QString::number( x );
1852 list << QString::number( y ); 1853 list << QString::number( y );
1853 list << QString::number( w ); 1854 list << QString::number( w );
1854 list << QString::number( h ); 1855 list << QString::number( h );
1855 config->writeEntry("MainLayout",list ); 1856 config->writeEntry("MainLayout",list );
1856 1857
1857 wid = mEventEditor; 1858 wid = mEventEditor;
1858 x = wid->geometry().x(); 1859 x = wid->geometry().x();
1859 y = wid->geometry().y(); 1860 y = wid->geometry().y();
1860 w = wid->width(); 1861 w = wid->width();
1861 h = wid->height(); 1862 h = wid->height();
1862 list.clear(); 1863 list.clear();
1863 list << QString::number( x ); 1864 list << QString::number( x );
1864 list << QString::number( y ); 1865 list << QString::number( y );
1865 list << QString::number( w ); 1866 list << QString::number( w );
1866 list << QString::number( h ); 1867 list << QString::number( h );
1867 config->writeEntry("EditEventLayout",list ); 1868 config->writeEntry("EditEventLayout",list );
1868 1869
1869 wid = mTodoEditor; 1870 wid = mTodoEditor;
1870 x = wid->geometry().x(); 1871 x = wid->geometry().x();
1871 y = wid->geometry().y(); 1872 y = wid->geometry().y();
1872 w = wid->width(); 1873 w = wid->width();
1873 h = wid->height(); 1874 h = wid->height();
1874 list.clear(); 1875 list.clear();
1875 list << QString::number( x ); 1876 list << QString::number( x );
1876 list << QString::number( y ); 1877 list << QString::number( y );
1877 list << QString::number( w ); 1878 list << QString::number( w );
1878 list << QString::number( h ); 1879 list << QString::number( h );
1879 config->writeEntry("EditTodoLayout",list ); 1880 config->writeEntry("EditTodoLayout",list );
1880 wid = getEventViewerDialog(); 1881 wid = getEventViewerDialog();
1881 x = wid->geometry().x(); 1882 x = wid->geometry().x();
1882 y = wid->geometry().y(); 1883 y = wid->geometry().y();
1883 w = wid->width(); 1884 w = wid->width();
1884 h = wid->height(); 1885 h = wid->height();
1885 list.clear(); 1886 list.clear();
1886 list << QString::number( x ); 1887 list << QString::number( x );
1887 list << QString::number( y ); 1888 list << QString::number( y );
1888 list << QString::number( w ); 1889 list << QString::number( w );
1889 list << QString::number( h ); 1890 list << QString::number( h );
1890 config->writeEntry("ViewerLayout",list ); 1891 config->writeEntry("ViewerLayout",list );
1891 wid = mDialogManager->getSearchDialog(); 1892 wid = mDialogManager->getSearchDialog();
1892 if ( wid ) { 1893 if ( wid ) {
1893 x = wid->geometry().x(); 1894 x = wid->geometry().x();
1894 y = wid->geometry().y(); 1895 y = wid->geometry().y();
1895 w = wid->width(); 1896 w = wid->width();
1896 h = wid->height(); 1897 h = wid->height();
1897 list.clear(); 1898 list.clear();
1898 list << QString::number( x ); 1899 list << QString::number( x );
1899 list << QString::number( y ); 1900 list << QString::number( y );
1900 list << QString::number( w ); 1901 list << QString::number( w );
1901 list << QString::number( h ); 1902 list << QString::number( h );
1902 config->writeEntry("SearchLayout",list ); 1903 config->writeEntry("SearchLayout",list );
1903 } 1904 }
1904#endif 1905#endif
1905 1906
1906 1907
1907 config->sync(); 1908 config->sync();
1908} 1909}
1909 1910
1910void CalendarView::readFilterSettings(KConfig *config) 1911void CalendarView::readFilterSettings(KConfig *config)
1911{ 1912{
1912 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 1913 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
1913 1914
1914 mFilters.clear(); 1915 mFilters.clear();
1915 1916
1916 config->setGroup("General"); 1917 config->setGroup("General");
1917 QStringList filterList = config->readListEntry("CalendarFilters"); 1918 QStringList filterList = config->readListEntry("CalendarFilters");
1918 1919
1919 QStringList::ConstIterator it = filterList.begin(); 1920 QStringList::ConstIterator it = filterList.begin();
1920 QStringList::ConstIterator end = filterList.end(); 1921 QStringList::ConstIterator end = filterList.end();
1921 while(it != end) { 1922 while(it != end) {
1922 // kdDebug() << " filter: " << (*it) << endl; 1923 // kdDebug() << " filter: " << (*it) << endl;
1923 1924
1924 CalFilter *filter; 1925 CalFilter *filter;
1925 filter = new CalFilter(*it); 1926 filter = new CalFilter(*it);
1926 config->setGroup("Filter_" + (*it)); 1927 config->setGroup("Filter_" + (*it));
1927 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 1928 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
1928 filter->setCriteria(config->readNumEntry("Criteria",0)); 1929 filter->setCriteria(config->readNumEntry("Criteria",0));
1929 filter->setCategoryList(config->readListEntry("CategoryList")); 1930 filter->setCategoryList(config->readListEntry("CategoryList"));
1930 mFilters.append(filter); 1931 mFilters.append(filter);
1931 1932
1932 ++it; 1933 ++it;
1933 } 1934 }
1934 1935
1935 if (mFilters.count() == 0) { 1936 if (mFilters.count() == 0) {
1936 CalFilter *filter = new CalFilter(i18n("Default")); 1937 CalFilter *filter = new CalFilter(i18n("Default"));
1937 mFilters.append(filter); 1938 mFilters.append(filter);
1938 } 1939 }
1939 mFilterView->updateFilters(); 1940 mFilterView->updateFilters();
1940 config->setGroup("FilterView"); 1941 config->setGroup("FilterView");
1941 1942
1942 mFilterView->blockSignals(true); 1943 mFilterView->blockSignals(true);
1943 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 1944 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
1944 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 1945 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
1945 mFilterView->blockSignals(false); 1946 mFilterView->blockSignals(false);
1946 // We do it manually to avoid it being done twice by the above calls 1947 // We do it manually to avoid it being done twice by the above calls
1947 updateFilter(); 1948 updateFilter();
1948} 1949}
1949 1950
1950void CalendarView::writeFilterSettings(KConfig *config) 1951void CalendarView::writeFilterSettings(KConfig *config)
1951{ 1952{
1952 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 1953 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
1953 1954
1954 QStringList filterList; 1955 QStringList filterList;
1955 1956
1956 CalFilter *filter = mFilters.first(); 1957 CalFilter *filter = mFilters.first();
1957 while(filter) { 1958 while(filter) {
1958 // kdDebug() << " fn: " << filter->name() << endl; 1959 // kdDebug() << " fn: " << filter->name() << endl;
1959 filterList << filter->name(); 1960 filterList << filter->name();
1960 config->setGroup("Filter_" + filter->name()); 1961 config->setGroup("Filter_" + filter->name());
1961 config->writeEntry("Criteria",filter->criteria()); 1962 config->writeEntry("Criteria",filter->criteria());
1962 config->writeEntry("CategoryList",filter->categoryList()); 1963 config->writeEntry("CategoryList",filter->categoryList());
1963 filter = mFilters.next(); 1964 filter = mFilters.next();
1964 } 1965 }
1965 config->setGroup("General"); 1966 config->setGroup("General");
1966 config->writeEntry("CalendarFilters",filterList); 1967 config->writeEntry("CalendarFilters",filterList);
1967 1968
1968 config->setGroup("FilterView"); 1969 config->setGroup("FilterView");
1969 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 1970 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
1970 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 1971 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
1971} 1972}
1972 1973
1973 1974
1974void CalendarView::goToday() 1975void CalendarView::goToday()
1975{ 1976{
1976 mNavigator->selectToday(); 1977 mNavigator->selectToday();
1977} 1978}
1978 1979
1979void CalendarView::goNext() 1980void CalendarView::goNext()
1980{ 1981{
1981 mNavigator->selectNext(); 1982 mNavigator->selectNext();
1982} 1983}
1983 1984
1984void CalendarView::goPrevious() 1985void CalendarView::goPrevious()
1985{ 1986{
1986 mNavigator->selectPrevious(); 1987 mNavigator->selectPrevious();
1987} 1988}
1988void CalendarView::goNextMonth() 1989void CalendarView::goNextMonth()
1989{ 1990{
1990 mNavigator->selectNextMonth(); 1991 mNavigator->selectNextMonth();
1991} 1992}
1992 1993
1993void CalendarView::goPreviousMonth() 1994void CalendarView::goPreviousMonth()
1994{ 1995{
1995 mNavigator->selectPreviousMonth(); 1996 mNavigator->selectPreviousMonth();
1996} 1997}
1997void CalendarView::writeLocale() 1998void CalendarView::writeLocale()
1998{ 1999{
1999 //KPimGlobalPrefs::instance()->setGlobalConfig(); 2000 //KPimGlobalPrefs::instance()->setGlobalConfig();
2000#if 0 2001#if 0
2001 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); 2002 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime );
2002 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); 2003 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday );
2003 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); 2004 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate );
2004 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); 2005 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage );
2005 QString dummy = KOPrefs::instance()->mUserDateFormatLong; 2006 QString dummy = KOPrefs::instance()->mUserDateFormatLong;
2006 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); 2007 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") ));
2007 dummy = KOPrefs::instance()->mUserDateFormatShort; 2008 dummy = KOPrefs::instance()->mUserDateFormatShort;
2008 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 2009 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
2009 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, 2010 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving,
2010 KOPrefs::instance()->mDaylightsavingStart, 2011 KOPrefs::instance()->mDaylightsavingStart,
2011 KOPrefs::instance()->mDaylightsavingEnd ); 2012 KOPrefs::instance()->mDaylightsavingEnd );
2012 KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId ); 2013 KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId );
2013#endif 2014#endif
2014} 2015}
2015void CalendarView::updateConfig() 2016void CalendarView::updateConfig()
2016{ 2017{
2017 writeLocale(); 2018 writeLocale();
2018 if ( KOPrefs::instance()->mUseAppColors ) 2019 if ( KOPrefs::instance()->mUseAppColors )
2019 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 2020 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
2020 emit configChanged(); 2021 emit configChanged();
2021 mTodoList->updateConfig(); 2022 mTodoList->updateConfig();
2022 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 2023 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
2023 mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 2024 mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
2024 // To make the "fill window" configurations work 2025 // To make the "fill window" configurations work
2025 //mViewManager->raiseCurrentView(); 2026 //mViewManager->raiseCurrentView();
2026} 2027}
2027 2028
2028 2029
2029void CalendarView::eventChanged(Event *event) 2030void CalendarView::eventChanged(Event *event)
2030{ 2031{
2031 changeEventDisplay(event,KOGlobals::EVENTEDITED); 2032 changeEventDisplay(event,KOGlobals::EVENTEDITED);
2032 //updateUnmanagedViews(); 2033 //updateUnmanagedViews();
2033} 2034}
2034 2035
2035void CalendarView::eventAdded(Event *event) 2036void CalendarView::eventAdded(Event *event)
2036{ 2037{
2037 changeEventDisplay(event,KOGlobals::EVENTADDED); 2038 changeEventDisplay(event,KOGlobals::EVENTADDED);
2038} 2039}
2039 2040
2040void CalendarView::eventToBeDeleted(Event *) 2041void CalendarView::eventToBeDeleted(Event *)
2041{ 2042{
2042 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 2043 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
2043} 2044}
2044 2045
2045void CalendarView::eventDeleted() 2046void CalendarView::eventDeleted()
2046{ 2047{
2047 changeEventDisplay(0,KOGlobals::EVENTDELETED); 2048 changeEventDisplay(0,KOGlobals::EVENTDELETED);
2048} 2049}
2049void CalendarView::changeTodoDisplay(Todo *which, int action) 2050void CalendarView::changeTodoDisplay(Todo *which, int action)
2050{ 2051{
2051 changeIncidenceDisplay((Incidence *)which, action); 2052 changeIncidenceDisplay((Incidence *)which, action);
2052 mDateNavigator->updateView(); //LR 2053 mDateNavigator->updateView(); //LR
2053 //mDialogManager->updateSearchDialog(); 2054 //mDialogManager->updateSearchDialog();
2054 2055
2055 if (which) { 2056 if (which) {
2056 mViewManager->updateWNview(); 2057 mViewManager->updateWNview();
2057 //mTodoList->updateView(); 2058 //mTodoList->updateView();
2058 } 2059 }
2059 2060
2060} 2061}
2061 2062
2062void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 2063void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
2063{ 2064{
2064 updateUnmanagedViews(); 2065 updateUnmanagedViews();
2065 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 2066 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
2066 if ( action == KOGlobals::EVENTDELETED ) { //delete 2067 if ( action == KOGlobals::EVENTDELETED ) { //delete
2067 mCalendar->checkAlarmForIncidence( 0, true ); 2068 mCalendar->checkAlarmForIncidence( 0, true );
2068 if ( mEventViewerDialog ) 2069 if ( mEventViewerDialog )
2069 mEventViewerDialog->hide(); 2070 mEventViewerDialog->hide();
2070 } 2071 }
2071 else 2072 else
2072 mCalendar->checkAlarmForIncidence( which , false ); 2073 mCalendar->checkAlarmForIncidence( which , false );
2073} 2074}
2074 2075
2075// most of the changeEventDisplays() right now just call the view's 2076// most of the changeEventDisplays() right now just call the view's
2076// total update mode, but they SHOULD be recoded to be more refresh-efficient. 2077// total update mode, but they SHOULD be recoded to be more refresh-efficient.
2077void CalendarView::changeEventDisplay(Event *which, int action) 2078void CalendarView::changeEventDisplay(Event *which, int action)
2078{ 2079{
2079 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 2080 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
2080 changeIncidenceDisplay((Incidence *)which, action); 2081 changeIncidenceDisplay((Incidence *)which, action);
2081 mDateNavigator->updateView(); 2082 mDateNavigator->updateView();
2082 //mDialogManager->updateSearchDialog(); 2083 //mDialogManager->updateSearchDialog();
2083 2084
2084 if (which) { 2085 if (which) {
2085 // If there is an event view visible update the display 2086 // If there is an event view visible update the display
2086 mViewManager->currentView()->changeEventDisplay(which,action); 2087 mViewManager->currentView()->changeEventDisplay(which,action);
2087 // TODO: check, if update needed 2088 // TODO: check, if update needed
2088 // if (which->getTodoStatus()) { 2089 // if (which->getTodoStatus()) {
2089 mTodoList->updateView(); 2090 mTodoList->updateView();
2090 // } 2091 // }
2091 } else { 2092 } else {
2092 mViewManager->currentView()->updateView(); 2093 mViewManager->currentView()->updateView();
2093 } 2094 }
2094} 2095}
2095 2096
2096 2097
2097void CalendarView::updateTodoViews() 2098void CalendarView::updateTodoViews()
2098{ 2099{
2099 2100
2100 mTodoList->updateView(); 2101 mTodoList->updateView();
2101 mViewManager->currentView()->updateView(); 2102 mViewManager->currentView()->updateView();
2102 2103
2103} 2104}
2104 2105
2105 2106
2106void CalendarView::updateView(const QDate &start, const QDate &end) 2107void CalendarView::updateView(const QDate &start, const QDate &end)
2107{ 2108{
2108 mTodoList->updateView(); 2109 mTodoList->updateView();
2109 mViewManager->updateView(start, end); 2110 mViewManager->updateView(start, end);
2110 //mDateNavigator->updateView(); 2111 //mDateNavigator->updateView();
2111} 2112}
2112 2113
2113void CalendarView::updateView() 2114void CalendarView::updateView()
2114{ 2115{
2115 DateList tmpList = mNavigator->selectedDates(); 2116 DateList tmpList = mNavigator->selectedDates();
2116 2117
2117 // We assume that the navigator only selects consecutive days. 2118 // We assume that the navigator only selects consecutive days.
2118 updateView( tmpList.first(), tmpList.last() ); 2119 updateView( tmpList.first(), tmpList.last() );
2119} 2120}
2120 2121
2121void CalendarView::updateUnmanagedViews() 2122void CalendarView::updateUnmanagedViews()
2122{ 2123{
2123 mDateNavigator->updateDayMatrix(); 2124 mDateNavigator->updateDayMatrix();
2124} 2125}
2125 2126
2126int CalendarView::msgItemDelete() 2127int CalendarView::msgItemDelete()
2127{ 2128{
2128 return KMessageBox::warningContinueCancel(this, 2129 return KMessageBox::warningContinueCancel(this,
2129 i18n("This item will be\npermanently deleted."), 2130 i18n("This item will be\npermanently deleted."),
2130 i18n("KO/Pi Confirmation"),i18n("Delete")); 2131 i18n("KO/Pi Confirmation"),i18n("Delete"));
2131} 2132}
2132 2133
2133 2134
2134void CalendarView::edit_cut() 2135void CalendarView::edit_cut()
2135{ 2136{
2136 Event *anEvent=0; 2137 Event *anEvent=0;
2137 2138
2138 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2139 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2139 2140
2140 if (mViewManager->currentView()->isEventView()) { 2141 if (mViewManager->currentView()->isEventView()) {
2141 if ( incidence && incidence->type() == "Event" ) { 2142 if ( incidence && incidence->type() == "Event" ) {
2142 anEvent = static_cast<Event *>(incidence); 2143 anEvent = static_cast<Event *>(incidence);
2143 } 2144 }
2144 } 2145 }
2145 2146
2146 if (!anEvent) { 2147 if (!anEvent) {
2147 KNotifyClient::beep(); 2148 KNotifyClient::beep();
2148 return; 2149 return;
2149 } 2150 }
2150 DndFactory factory( mCalendar ); 2151 DndFactory factory( mCalendar );
2151 factory.cutEvent(anEvent); 2152 factory.cutEvent(anEvent);
2152 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2153 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2153} 2154}
2154 2155
2155void CalendarView::edit_copy() 2156void CalendarView::edit_copy()
2156{ 2157{
2157 Event *anEvent=0; 2158 Event *anEvent=0;
2158 2159
2159 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2160 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2160 2161
2161 if (mViewManager->currentView()->isEventView()) { 2162 if (mViewManager->currentView()->isEventView()) {
2162 if ( incidence && incidence->type() == "Event" ) { 2163 if ( incidence && incidence->type() == "Event" ) {
2163 anEvent = static_cast<Event *>(incidence); 2164 anEvent = static_cast<Event *>(incidence);
2164 } 2165 }
2165 } 2166 }
2166 2167
2167 if (!anEvent) { 2168 if (!anEvent) {
2168 KNotifyClient::beep(); 2169 KNotifyClient::beep();
2169 return; 2170 return;
2170 } 2171 }
2171 DndFactory factory( mCalendar ); 2172 DndFactory factory( mCalendar );
2172 factory.copyEvent(anEvent); 2173 factory.copyEvent(anEvent);
2173} 2174}
2174 2175
2175void CalendarView::edit_paste() 2176void CalendarView::edit_paste()
2176{ 2177{
2177 QDate date = mNavigator->selectedDates().first(); 2178 QDate date = mNavigator->selectedDates().first();
2178 2179
2179 DndFactory factory( mCalendar ); 2180 DndFactory factory( mCalendar );
2180 Event *pastedEvent = factory.pasteEvent( date ); 2181 Event *pastedEvent = factory.pasteEvent( date );
2181 2182
2182 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2183 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2183} 2184}
2184 2185
2185void CalendarView::edit_options() 2186void CalendarView::edit_options()
2186{ 2187{
2187 mDialogManager->showOptionsDialog(); 2188 mDialogManager->showOptionsDialog();
2188 //writeSettings(); 2189 //writeSettings();
2189} 2190}
2190 2191
2191void CalendarView::slotSelectPickerDate( QDate d) 2192void CalendarView::slotSelectPickerDate( QDate d)
2192{ 2193{
2193 mDateFrame->hide(); 2194 mDateFrame->hide();
2194 if ( mDatePickerMode == 1 ) { 2195 if ( mDatePickerMode == 1 ) {
2195 mNavigator->slotDaySelect( d ); 2196 mNavigator->slotDaySelect( d );
2196 } else if ( mDatePickerMode == 2 ) { 2197 } else if ( mDatePickerMode == 2 ) {
2197 if ( mMoveIncidence->type() == "Todo" ) { 2198 if ( mMoveIncidence->type() == "Todo" ) {
2198 Todo * to = (Todo *) mMoveIncidence; 2199 Todo * to = (Todo *) mMoveIncidence;
2199 QTime tim; 2200 QTime tim;
2200 if ( to->hasDueDate() ) 2201 if ( to->hasDueDate() )
2201 tim = to->dtDue().time(); 2202 tim = to->dtDue().time();
2202 else { 2203 else {
2203 tim = QTime ( 0,0,0 ); 2204 tim = QTime ( 0,0,0 );
2204 to->setFloats( true ); 2205 to->setFloats( true );
2205 to->setHasDueDate( true ); 2206 to->setHasDueDate( true );
2206 } 2207 }
2207 QDateTime dt ( d,tim ); 2208 QDateTime dt ( d,tim );
2208 to->setDtDue( dt ); 2209 to->setDtDue( dt );
2209 todoChanged( to ); 2210 todoChanged( to );
2210 } else { 2211 } else {
2211 QTime tim = mMoveIncidence->dtStart().time(); 2212 QTime tim = mMoveIncidence->dtStart().time();
2212 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 2213 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
2213 QDateTime dt ( d,tim ); 2214 QDateTime dt ( d,tim );
2214 mMoveIncidence->setDtStart( dt ); 2215 mMoveIncidence->setDtStart( dt );
2215 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 2216 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
2216 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 2217 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
2217 } 2218 }
2218 2219
2219 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 2220 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
2220 } 2221 }
2221} 2222}
2222 2223
2223void CalendarView::removeCategories() 2224void CalendarView::removeCategories()
2224{ 2225{
2225 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2226 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2226 QStringList catList = KOPrefs::instance()->mCustomCategories; 2227 QStringList catList = KOPrefs::instance()->mCustomCategories;
2227 QStringList catIncList; 2228 QStringList catIncList;
2228 QStringList newCatList; 2229 QStringList newCatList;
2229 Incidence* inc = incList.first(); 2230 Incidence* inc = incList.first();
2230 int i; 2231 int i;
2231 int count = 0; 2232 int count = 0;
2232 while ( inc ) { 2233 while ( inc ) {
2233 newCatList.clear(); 2234 newCatList.clear();
2234 catIncList = inc->categories() ; 2235 catIncList = inc->categories() ;
2235 for( i = 0; i< catIncList.count(); ++i ) { 2236 for( i = 0; i< catIncList.count(); ++i ) {
2236 if ( catList.contains (catIncList[i])) 2237 if ( catList.contains (catIncList[i]))
2237 newCatList.append( catIncList[i] ); 2238 newCatList.append( catIncList[i] );
2238 } 2239 }
2239 newCatList.sort(); 2240 newCatList.sort();
2240 inc->setCategories( newCatList.join(",") ); 2241 inc->setCategories( newCatList.join(",") );
2241 inc = incList.next(); 2242 inc = incList.next();
2242 } 2243 }
2243} 2244}
2244 2245
2245int CalendarView::addCategories() 2246int CalendarView::addCategories()
2246{ 2247{
2247 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2248 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2248 QStringList catList = KOPrefs::instance()->mCustomCategories; 2249 QStringList catList = KOPrefs::instance()->mCustomCategories;
2249 QStringList catIncList; 2250 QStringList catIncList;
2250 Incidence* inc = incList.first(); 2251 Incidence* inc = incList.first();
2251 int i; 2252 int i;
2252 int count = 0; 2253 int count = 0;
2253 while ( inc ) { 2254 while ( inc ) {
2254 catIncList = inc->categories() ; 2255 catIncList = inc->categories() ;
2255 for( i = 0; i< catIncList.count(); ++i ) { 2256 for( i = 0; i< catIncList.count(); ++i ) {
2256 if ( !catList.contains (catIncList[i])) { 2257 if ( !catList.contains (catIncList[i])) {
2257 catList.append( catIncList[i] ); 2258 catList.append( catIncList[i] );
2258 //qDebug("add cat %s ", catIncList[i].latin1()); 2259 //qDebug("add cat %s ", catIncList[i].latin1());
2259 ++count; 2260 ++count;
2260 } 2261 }
2261 } 2262 }
2262 inc = incList.next(); 2263 inc = incList.next();
2263 } 2264 }
2264 catList.sort(); 2265 catList.sort();
2265 KOPrefs::instance()->mCustomCategories = catList; 2266 KOPrefs::instance()->mCustomCategories = catList;
2266 return count; 2267 return count;
2267} 2268}
2268 2269
2269void CalendarView::manageCategories() 2270void CalendarView::manageCategories()
2270{ 2271{
2271 KOCatPrefs* cp = new KOCatPrefs(); 2272 KOCatPrefs* cp = new KOCatPrefs();
2272 cp->show(); 2273 cp->show();
2273 int w =cp->sizeHint().width() ; 2274 int w =cp->sizeHint().width() ;
2274 int h = cp->sizeHint().height() ; 2275 int h = cp->sizeHint().height() ;
2275 int dw = QApplication::desktop()->width(); 2276 int dw = QApplication::desktop()->width();
2276 int dh = QApplication::desktop()->height(); 2277 int dh = QApplication::desktop()->height();
2277 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2278 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2278 if ( !cp->exec() ) { 2279 if ( !cp->exec() ) {
2279 delete cp; 2280 delete cp;
2280 return; 2281 return;
2281 } 2282 }
2282 int count = 0; 2283 int count = 0;
2283 if ( cp->addCat() ) { 2284 if ( cp->addCat() ) {
2284 count = addCategories(); 2285 count = addCategories();
2285 if ( count ) { 2286 if ( count ) {
2286 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 2287 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
2287 writeSettings(); 2288 writeSettings();
2288 } 2289 }
2289 } else { 2290 } else {
2290 removeCategories(); 2291 removeCategories();
2291 updateView(); 2292 updateView();
2292 } 2293 }
2293 delete cp; 2294 delete cp;
2294} 2295}
2295 2296
2296void CalendarView::beamIncidence(Incidence * Inc) 2297void CalendarView::beamIncidence(Incidence * Inc)
2297{ 2298{
2298 QPtrList<Incidence> delSel ; 2299 QPtrList<Incidence> delSel ;
2299 delSel.append(Inc); 2300 delSel.append(Inc);
2300 beamIncidenceList( delSel ); 2301 beamIncidenceList( delSel );
2301} 2302}
2302void CalendarView::beamCalendar() 2303void CalendarView::beamCalendar()
2303{ 2304{
2304 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 2305 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
2305 //qDebug("beamCalendar() "); 2306 //qDebug("beamCalendar() ");
2306 beamIncidenceList( delSel ); 2307 beamIncidenceList( delSel );
2307} 2308}
2308void CalendarView::beamFilteredCalendar() 2309void CalendarView::beamFilteredCalendar()
2309{ 2310{
2310 QPtrList<Incidence> delSel = mCalendar->incidences(); 2311 QPtrList<Incidence> delSel = mCalendar->incidences();
2311 //qDebug("beamFilteredCalendar() "); 2312 //qDebug("beamFilteredCalendar() ");
2312 beamIncidenceList( delSel ); 2313 beamIncidenceList( delSel );
2313} 2314}
2314void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 2315void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
2315{ 2316{
2316 if ( beamDialog->exec () == QDialog::Rejected ) 2317 if ( beamDialog->exec () == QDialog::Rejected )
2317 return; 2318 return;
2318 2319
2319 QString fn = "/tmp/kopibeamfile"; 2320 QString fn = "/tmp/kopibeamfile";
2320 QString mes; 2321 QString mes;
2321 bool createbup = true; 2322 bool createbup = true;
2322 if ( createbup ) { 2323 if ( createbup ) {
2323 QString description = "\n"; 2324 QString description = "\n";
2324 CalendarLocal* cal = new CalendarLocal(); 2325 CalendarLocal* cal = new CalendarLocal();
2325 if ( beamDialog->beamLocal() ) 2326 if ( beamDialog->beamLocal() )
2326 cal->setLocalTime(); 2327 cal->setLocalTime();
2327 else 2328 else
2328 cal->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 2329 cal->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
2329 Incidence *incidence = delSel.first(); 2330 Incidence *incidence = delSel.first();
2330 bool addText = false; 2331 bool addText = false;
2331 if ( delSel.count() < 10 ) 2332 if ( delSel.count() < 10 )
2332 addText = true; 2333 addText = true;
2333 else { 2334 else {
2334 description.sprintf(i18n(" %d items?"),delSel.count() ); 2335 description.sprintf(i18n(" %d items?"),delSel.count() );
2335 } 2336 }
2336 while ( incidence ) { 2337 while ( incidence ) {
2337 Incidence *in = incidence->clone(); 2338 Incidence *in = incidence->clone();
2338 if ( ! in->summary().isEmpty() ) { 2339 if ( ! in->summary().isEmpty() ) {
2339 in->setDescription(""); 2340 in->setDescription("");
2340 } else { 2341 } else {
2341 in->setSummary( in->description().left(20)); 2342 in->setSummary( in->description().left(20));
2342 in->setDescription(""); 2343 in->setDescription("");
2343 } 2344 }
2344 if ( addText ) 2345 if ( addText )
2345 description += in->summary() + "\n"; 2346 description += in->summary() + "\n";
2346 cal->addIncidence( in ); 2347 cal->addIncidence( in );
2347 incidence = delSel.next(); 2348 incidence = delSel.next();
2348 } 2349 }
2349 if ( beamDialog->beamVcal() ) { 2350 if ( beamDialog->beamVcal() ) {
2350 fn += ".vcs"; 2351 fn += ".vcs";
2351 FileStorage storage( cal, fn, new VCalFormat ); 2352 FileStorage storage( cal, fn, new VCalFormat );
2352 storage.save(); 2353 storage.save();
2353 } else { 2354 } else {
2354 fn += ".ics"; 2355 fn += ".ics";
2355 FileStorage storage( cal, fn, new ICalFormat( ) ); 2356 FileStorage storage( cal, fn, new ICalFormat( ) );
2356 storage.save(); 2357 storage.save();
2357 } 2358 }
2358 delete cal; 2359 delete cal;
2359 mes = i18n("KO/Pi: Ready for beaming"); 2360 mes = i18n("KO/Pi: Ready for beaming");
2360 topLevelWidget()->setCaption(mes); 2361 topLevelWidget()->setCaption(mes);
2361 KApplication::convert2latin1( fn ); 2362 KApplication::convert2latin1( fn );
2362#ifndef DESKTOP_VERSION 2363#ifndef DESKTOP_VERSION
2363 Ir *ir = new Ir( this ); 2364 Ir *ir = new Ir( this );
2364 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 2365 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
2365 ir->send( fn, description, "text/x-vCalendar" ); 2366 ir->send( fn, description, "text/x-vCalendar" );
2366#endif 2367#endif
2367 } 2368 }
2368} 2369}
2369void CalendarView::beamDone( Ir *ir ) 2370void CalendarView::beamDone( Ir *ir )
2370{ 2371{
2371#ifndef DESKTOP_VERSION 2372#ifndef DESKTOP_VERSION
2372 delete ir; 2373 delete ir;
2373#endif 2374#endif
2374 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); 2375 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") );
2375 topLevelWidget()->raise(); 2376 topLevelWidget()->raise();
2376} 2377}
2377 2378
2378void CalendarView::moveIncidence(Incidence * inc ) 2379void CalendarView::moveIncidence(Incidence * inc )
2379{ 2380{
2380 if ( !inc ) return; 2381 if ( !inc ) return;
2381 // qDebug("showDatePickerForIncidence( ) "); 2382 // qDebug("showDatePickerForIncidence( ) ");
2382 if ( mDateFrame->isVisible() ) 2383 if ( mDateFrame->isVisible() )
2383 mDateFrame->hide(); 2384 mDateFrame->hide();
2384 else { 2385 else {
2385 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ; 2386 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ;
2386 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ; 2387 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ;
2387 int dw = QApplication::desktop()->width(); 2388 int dw = QApplication::desktop()->width();
2388 int dh = QApplication::desktop()->height(); 2389 int dh = QApplication::desktop()->height();
2389 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2390 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2390 mDateFrame->show(); 2391 mDateFrame->show();
2391 } 2392 }
2392 mDatePickerMode = 2; 2393 mDatePickerMode = 2;
2393 mMoveIncidence = inc ; 2394 mMoveIncidence = inc ;
2394 QDate da; 2395 QDate da;
2395 if ( mMoveIncidence->type() == "Todo" ) { 2396 if ( mMoveIncidence->type() == "Todo" ) {
2396 Todo * to = (Todo *) mMoveIncidence; 2397 Todo * to = (Todo *) mMoveIncidence;
2397 if ( to->hasDueDate() ) 2398 if ( to->hasDueDate() )
2398 da = to->dtDue().date(); 2399 da = to->dtDue().date();
2399 else 2400 else
2400 da = QDate::currentDate(); 2401 da = QDate::currentDate();
2401 } else { 2402 } else {
2402 da = mMoveIncidence->dtStart().date(); 2403 da = mMoveIncidence->dtStart().date();
2403 } 2404 }
2404 mDatePicker->setDate( da ); 2405 mDatePicker->setDate( da );
2405} 2406}
2406void CalendarView::showDatePicker( ) 2407void CalendarView::showDatePicker( )
2407{ 2408{
2408 //qDebug("CalendarView::showDatePicker( ) "); 2409 //qDebug("CalendarView::showDatePicker( ) ");
2409 if ( mDateFrame->isVisible() ) 2410 if ( mDateFrame->isVisible() )
2410 mDateFrame->hide(); 2411 mDateFrame->hide();
2411 else { 2412 else {
2412 int w =mDatePicker->sizeHint().width() ; 2413 int w =mDatePicker->sizeHint().width() ;
2413 int h = mDatePicker->sizeHint().height() ; 2414 int h = mDatePicker->sizeHint().height() ;
2414 int dw = QApplication::desktop()->width(); 2415 int dw = QApplication::desktop()->width();
2415 int dh = QApplication::desktop()->height(); 2416 int dh = QApplication::desktop()->height();
2416 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2417 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2417 mDateFrame->show(); 2418 mDateFrame->show();
2418 } 2419 }
2419 mDatePickerMode = 1; 2420 mDatePickerMode = 1;
2420 mDatePicker->setDate( mNavigator->selectedDates().first() ); 2421 mDatePicker->setDate( mNavigator->selectedDates().first() );
2421} 2422}
2422 2423
2423void CalendarView::showEventEditor() 2424void CalendarView::showEventEditor()
2424{ 2425{
2425#ifdef DESKTOP_VERSION 2426#ifdef DESKTOP_VERSION
2426 mEventEditor->show(); 2427 mEventEditor->show();
2427#else 2428#else
2428 mEventEditor->showMaximized(); 2429 mEventEditor->showMaximized();
2429#endif 2430#endif
2430} 2431}
2431void CalendarView::showTodoEditor() 2432void CalendarView::showTodoEditor()
2432{ 2433{
2433#ifdef DESKTOP_VERSION 2434#ifdef DESKTOP_VERSION
2434 mTodoEditor->show(); 2435 mTodoEditor->show();
2435#else 2436#else
2436 mTodoEditor->showMaximized(); 2437 mTodoEditor->showMaximized();
2437#endif 2438#endif
2438} 2439}
2439 2440
2440void CalendarView::cloneIncidence() 2441void CalendarView::cloneIncidence()
2441{ 2442{
2442 Incidence *incidence = currentSelection(); 2443 Incidence *incidence = currentSelection();
2443 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2444 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2444 if ( incidence ) { 2445 if ( incidence ) {
2445 cloneIncidence(incidence); 2446 cloneIncidence(incidence);
2446 } 2447 }
2447} 2448}
2448void CalendarView::moveIncidence() 2449void CalendarView::moveIncidence()
2449{ 2450{
2450 Incidence *incidence = currentSelection(); 2451 Incidence *incidence = currentSelection();
2451 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2452 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2452 if ( incidence ) { 2453 if ( incidence ) {
2453 moveIncidence(incidence); 2454 moveIncidence(incidence);
2454 } 2455 }
2455} 2456}
2456void CalendarView::beamIncidence() 2457void CalendarView::beamIncidence()
2457{ 2458{
2458 Incidence *incidence = currentSelection(); 2459 Incidence *incidence = currentSelection();
2459 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2460 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2460 if ( incidence ) { 2461 if ( incidence ) {
2461 beamIncidence(incidence); 2462 beamIncidence(incidence);
2462 } 2463 }
2463} 2464}
2464void CalendarView::toggleCancelIncidence() 2465void CalendarView::toggleCancelIncidence()
2465{ 2466{
2466 Incidence *incidence = currentSelection(); 2467 Incidence *incidence = currentSelection();
2467 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2468 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2468 if ( incidence ) { 2469 if ( incidence ) {
2469 cancelIncidence(incidence); 2470 cancelIncidence(incidence);
2470 } 2471 }
2471} 2472}
2472 2473
2473 2474
2474void CalendarView::cancelIncidence(Incidence * inc ) 2475void CalendarView::cancelIncidence(Incidence * inc )
2475{ 2476{
2476 inc->setCancelled( ! inc->cancelled() ); 2477 inc->setCancelled( ! inc->cancelled() );
2477 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 2478 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
2478 updateView(); 2479 updateView();
2479} 2480}
2480void CalendarView::cloneIncidence(Incidence * orgInc ) 2481void CalendarView::cloneIncidence(Incidence * orgInc )
2481{ 2482{
2482 Incidence * newInc = orgInc->clone(); 2483 Incidence * newInc = orgInc->clone();
2483 newInc->recreate(); 2484 newInc->recreate();
2484 2485
2485 if ( newInc->type() == "Todo" ) { 2486 if ( newInc->type() == "Todo" ) {
2486 Todo* t = (Todo*) newInc; 2487 Todo* t = (Todo*) newInc;
2487 mTodoEditor->editTodo( t ); 2488 mTodoEditor->editTodo( t );
2488 showTodoEditor(); 2489 showTodoEditor();
2489 if ( mTodoEditor->exec() ) { 2490 if ( mTodoEditor->exec() ) {
2490 mCalendar->addTodo( t ); 2491 mCalendar->addTodo( t );
2491 updateView(); 2492 updateView();
2492 } else { 2493 } else {
2493 delete t; 2494 delete t;
2494 } 2495 }
2495 } 2496 }
2496 else { 2497 else {
2497 Event* e = (Event*) newInc; 2498 Event* e = (Event*) newInc;
2498 mEventEditor->editEvent( e ); 2499 mEventEditor->editEvent( e );
2499 showEventEditor(); 2500 showEventEditor();
2500 if ( mEventEditor->exec() ) { 2501 if ( mEventEditor->exec() ) {
2501 mCalendar->addEvent( e ); 2502 mCalendar->addEvent( e );
2502 updateView(); 2503 updateView();
2503 } else { 2504 } else {
2504 delete e; 2505 delete e;
2505 } 2506 }
2506 } 2507 }
2507} 2508}
2508 2509
2509void CalendarView::newEvent() 2510void CalendarView::newEvent()
2510{ 2511{
2511 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 2512 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
2512 KOAgendaView *aView = mViewManager->agendaView(); 2513 KOAgendaView *aView = mViewManager->agendaView();
2513 if (aView) { 2514 if (aView) {
2514 if (aView->selectionStart().isValid()) { 2515 if (aView->selectionStart().isValid()) {
2515 if (aView->selectedIsAllDay()) { 2516 if (aView->selectedIsAllDay()) {
2516 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 2517 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
2517 } else { 2518 } else {
2518 newEvent(aView->selectionStart(),aView->selectionEnd()); 2519 newEvent(aView->selectionStart(),aView->selectionEnd());
2519 } 2520 }
2520 return; 2521 return;
2521 } 2522 }
2522 } 2523 }
2523 2524
2524 QDate date = mNavigator->selectedDates().first(); 2525 QDate date = mNavigator->selectedDates().first();
2525 QDateTime current = QDateTime::currentDateTime(); 2526 QDateTime current = QDateTime::currentDateTime();
2526 if ( date <= current.date() ) { 2527 if ( date <= current.date() ) {
2527 int hour = current.time().hour() +1; 2528 int hour = current.time().hour() +1;
2528 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 2529 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
2529 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2530 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2530 } else 2531 } else
2531 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 2532 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
2532 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 2533 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
2533 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2534 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2534} 2535}
2535 2536
2536void CalendarView::newEvent(QDateTime fh) 2537void CalendarView::newEvent(QDateTime fh)
2537{ 2538{
2538 newEvent(fh, 2539 newEvent(fh,
2539 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 2540 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
2540} 2541}
2541 2542
2542void CalendarView::newEvent(QDate dt) 2543void CalendarView::newEvent(QDate dt)
2543{ 2544{
2544 newEvent(QDateTime(dt, QTime(0,0,0)), 2545 newEvent(QDateTime(dt, QTime(0,0,0)),
2545 QDateTime(dt, QTime(0,0,0)), true); 2546 QDateTime(dt, QTime(0,0,0)), true);
2546} 2547}
2547 2548
2548void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 2549void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
2549{ 2550{
2550 2551
2551 mEventEditor->newEvent(fromHint,toHint,allDay); 2552 mEventEditor->newEvent(fromHint,toHint,allDay);
2552 if ( mFilterView->filtersEnabled() ) { 2553 if ( mFilterView->filtersEnabled() ) {
2553 CalFilter *filter = mFilterView->selectedFilter(); 2554 CalFilter *filter = mFilterView->selectedFilter();
2554 if (filter && filter->showCategories()) { 2555 if (filter && filter->showCategories()) {
2555 mEventEditor->setCategories(filter->categoryList().join(",") ); 2556 mEventEditor->setCategories(filter->categoryList().join(",") );
2556 } 2557 }
2557 if ( filter ) 2558 if ( filter )
2558 mEventEditor->setSecrecy( filter->getSecrecy() ); 2559 mEventEditor->setSecrecy( filter->getSecrecy() );
2559 } 2560 }
2560 showEventEditor(); 2561 showEventEditor();
2561} 2562}
2562void CalendarView::todoAdded(Todo * t) 2563void CalendarView::todoAdded(Todo * t)
2563{ 2564{
2564 2565
2565 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 2566 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
2566 updateTodoViews(); 2567 updateTodoViews();
2567} 2568}
2568void CalendarView::todoChanged(Todo * t) 2569void CalendarView::todoChanged(Todo * t)
2569{ 2570{
2570 emit todoModified( t, 4 ); 2571 emit todoModified( t, 4 );
2571 // updateTodoViews(); 2572 // updateTodoViews();
2572} 2573}
2573void CalendarView::todoToBeDeleted(Todo *) 2574void CalendarView::todoToBeDeleted(Todo *)
2574{ 2575{
2575 //qDebug("todoToBeDeleted(Todo *) "); 2576 //qDebug("todoToBeDeleted(Todo *) ");
2576 updateTodoViews(); 2577 updateTodoViews();
2577} 2578}
2578void CalendarView::todoDeleted() 2579void CalendarView::todoDeleted()
2579{ 2580{
2580 //qDebug(" todoDeleted()"); 2581 //qDebug(" todoDeleted()");
2581 updateTodoViews(); 2582 updateTodoViews();
2582} 2583}
2583 2584
2584 2585
2585 2586
2586void CalendarView::newTodo() 2587void CalendarView::newTodo()
2587{ 2588{
2588 2589
2589 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true); 2590 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true);
2590 if ( mFilterView->filtersEnabled() ) { 2591 if ( mFilterView->filtersEnabled() ) {
2591 CalFilter *filter = mFilterView->selectedFilter(); 2592 CalFilter *filter = mFilterView->selectedFilter();
2592 if (filter && filter->showCategories()) { 2593 if (filter && filter->showCategories()) {
2593 mTodoEditor->setCategories(filter->categoryList().join(",") ); 2594 mTodoEditor->setCategories(filter->categoryList().join(",") );
2594 } 2595 }
2595 if ( filter ) 2596 if ( filter )
2596 mTodoEditor->setSecrecy( filter->getSecrecy() ); 2597 mTodoEditor->setSecrecy( filter->getSecrecy() );
2597 } 2598 }
2598 showTodoEditor(); 2599 showTodoEditor();
2599} 2600}
2600 2601
2601void CalendarView::newSubTodo() 2602void CalendarView::newSubTodo()
2602{ 2603{
2603 Todo *todo = selectedTodo(); 2604 Todo *todo = selectedTodo();
2604 if ( todo ) newSubTodo( todo ); 2605 if ( todo ) newSubTodo( todo );
2605} 2606}
2606 2607
2607void CalendarView::newSubTodo(Todo *parentEvent) 2608void CalendarView::newSubTodo(Todo *parentEvent)
2608{ 2609{
2609 2610
2610 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true); 2611 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true);
2611 showTodoEditor(); 2612 showTodoEditor();
2612} 2613}
2613 2614
2614void CalendarView::newFloatingEvent() 2615void CalendarView::newFloatingEvent()
2615{ 2616{
2616 DateList tmpList = mNavigator->selectedDates(); 2617 DateList tmpList = mNavigator->selectedDates();
2617 QDate date = tmpList.first(); 2618 QDate date = tmpList.first();
2618 2619
2619 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 2620 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
2620 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 2621 QDateTime( date, QTime( 12, 0, 0 ) ), true );
2621} 2622}
2622 2623
2623 2624
2624void CalendarView::editEvent( Event *event ) 2625void CalendarView::editEvent( Event *event )
2625{ 2626{
2626 2627
2627 if ( !event ) return; 2628 if ( !event ) return;
2628 if ( event->isReadOnly() ) { 2629 if ( event->isReadOnly() ) {
2629 showEvent( event ); 2630 showEvent( event );
2630 return; 2631 return;
2631 } 2632 }
2632 mEventEditor->editEvent( event , mFlagEditDescription); 2633 mEventEditor->editEvent( event , mFlagEditDescription);
2633 showEventEditor(); 2634 showEventEditor();
2634} 2635}
2635void CalendarView::editJournal( Journal *jour ) 2636void CalendarView::editJournal( Journal *jour )
2636{ 2637{
2637 if ( !jour ) return; 2638 if ( !jour ) return;
2638 mDialogManager->hideSearchDialog(); 2639 mDialogManager->hideSearchDialog();
2639 mViewManager->showJournalView(); 2640 mViewManager->showJournalView();
2640 mNavigator->slotDaySelect( jour->dtStart().date() ); 2641 mNavigator->slotDaySelect( jour->dtStart().date() );
2641} 2642}
2642void CalendarView::editTodo( Todo *todo ) 2643void CalendarView::editTodo( Todo *todo )
2643{ 2644{
2644 if ( !todo ) return; 2645 if ( !todo ) return;
2645 2646
2646 if ( todo->isReadOnly() ) { 2647 if ( todo->isReadOnly() ) {
2647 showTodo( todo ); 2648 showTodo( todo );
2648 return; 2649 return;
2649 } 2650 }
2650 mTodoEditor->editTodo( todo ,mFlagEditDescription); 2651 mTodoEditor->editTodo( todo ,mFlagEditDescription);
2651 showTodoEditor(); 2652 showTodoEditor();
2652 2653
2653} 2654}
2654 2655
2655KOEventViewerDialog* CalendarView::getEventViewerDialog() 2656KOEventViewerDialog* CalendarView::getEventViewerDialog()
2656{ 2657{
2657 if ( !mEventViewerDialog ) { 2658 if ( !mEventViewerDialog ) {
2658 mEventViewerDialog = new KOEventViewerDialog(this); 2659 mEventViewerDialog = new KOEventViewerDialog(this);
2659 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 2660 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
2660 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 2661 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
2661 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 2662 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
2662 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 2663 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
2663 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 2664 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
2664 viewManager(), SLOT( showAgendaView( bool ) ) ); 2665 viewManager(), SLOT( showAgendaView( bool ) ) );
2665 mEventViewerDialog->resize( 640, 480 ); 2666 mEventViewerDialog->resize( 640, 480 );
2666 2667
2667 } 2668 }
2668 return mEventViewerDialog; 2669 return mEventViewerDialog;
2669} 2670}
2670void CalendarView::showEvent(Event *event) 2671void CalendarView::showEvent(Event *event)
2671{ 2672{
2672 getEventViewerDialog()->setEvent(event); 2673 getEventViewerDialog()->setEvent(event);
2673 getEventViewerDialog()->showMe(); 2674 getEventViewerDialog()->showMe();
2674} 2675}
2675 2676
2676void CalendarView::showTodo(Todo *event) 2677void CalendarView::showTodo(Todo *event)
2677{ 2678{
2678 getEventViewerDialog()->setTodo(event); 2679 getEventViewerDialog()->setTodo(event);
2679 getEventViewerDialog()->showMe(); 2680 getEventViewerDialog()->showMe();
2680} 2681}
2681void CalendarView::showJournal( Journal *jour ) 2682void CalendarView::showJournal( Journal *jour )
2682{ 2683{
2683 getEventViewerDialog()->setJournal(jour); 2684 getEventViewerDialog()->setJournal(jour);
2684 getEventViewerDialog()->showMe(); 2685 getEventViewerDialog()->showMe();
2685 2686
2686} 2687}
2687// void CalendarView::todoModified (Todo *event, int changed) 2688// void CalendarView::todoModified (Todo *event, int changed)
2688// { 2689// {
2689// // if (mDialogList.find (event) != mDialogList.end ()) { 2690// // if (mDialogList.find (event) != mDialogList.end ()) {
2690// // kdDebug() << "Todo modified and open" << endl; 2691// // kdDebug() << "Todo modified and open" << endl;
2691// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 2692// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
2692// // temp->modified (changed); 2693// // temp->modified (changed);
2693 2694
2694// // } 2695// // }
2695 2696
2696// mViewManager->updateView(); 2697// mViewManager->updateView();
2697// } 2698// }
2698 2699
2699void CalendarView::appointment_show() 2700void CalendarView::appointment_show()
2700{ 2701{
2701 Event *anEvent = 0; 2702 Event *anEvent = 0;
2702 2703
2703 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2704 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2704 2705
2705 if (mViewManager->currentView()->isEventView()) { 2706 if (mViewManager->currentView()->isEventView()) {
2706 if ( incidence && incidence->type() == "Event" ) { 2707 if ( incidence && incidence->type() == "Event" ) {
2707 anEvent = static_cast<Event *>(incidence); 2708 anEvent = static_cast<Event *>(incidence);
2708 } 2709 }
2709 } 2710 }
2710 2711
2711 if (!anEvent) { 2712 if (!anEvent) {
2712 KNotifyClient::beep(); 2713 KNotifyClient::beep();
2713 return; 2714 return;
2714 } 2715 }
2715 2716
2716 showEvent(anEvent); 2717 showEvent(anEvent);
2717} 2718}
2718 2719
2719void CalendarView::appointment_edit() 2720void CalendarView::appointment_edit()
2720{ 2721{
2721 Event *anEvent = 0; 2722 Event *anEvent = 0;
2722 2723
2723 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2724 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2724 2725
2725 if (mViewManager->currentView()->isEventView()) { 2726 if (mViewManager->currentView()->isEventView()) {
2726 if ( incidence && incidence->type() == "Event" ) { 2727 if ( incidence && incidence->type() == "Event" ) {
2727 anEvent = static_cast<Event *>(incidence); 2728 anEvent = static_cast<Event *>(incidence);
2728 } 2729 }
2729 } 2730 }
2730 2731
2731 if (!anEvent) { 2732 if (!anEvent) {
2732 KNotifyClient::beep(); 2733 KNotifyClient::beep();
2733 return; 2734 return;
2734 } 2735 }
2735 2736
2736 editEvent(anEvent); 2737 editEvent(anEvent);
2737} 2738}
2738 2739
2739void CalendarView::appointment_delete() 2740void CalendarView::appointment_delete()
2740{ 2741{
2741 Event *anEvent = 0; 2742 Event *anEvent = 0;
2742 2743
2743 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2744 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2744 2745
2745 if (mViewManager->currentView()->isEventView()) { 2746 if (mViewManager->currentView()->isEventView()) {
2746 if ( incidence && incidence->type() == "Event" ) { 2747 if ( incidence && incidence->type() == "Event" ) {
2747 anEvent = static_cast<Event *>(incidence); 2748 anEvent = static_cast<Event *>(incidence);
2748 } 2749 }
2749 } 2750 }
2750 2751
2751 if (!anEvent) { 2752 if (!anEvent) {
2752 KNotifyClient::beep(); 2753 KNotifyClient::beep();
2753 return; 2754 return;
2754 } 2755 }
2755 2756
2756 deleteEvent(anEvent); 2757 deleteEvent(anEvent);
2757} 2758}
2758 2759
2759void CalendarView::todo_resub( Todo * parent, Todo * sub ) 2760void CalendarView::todo_resub( Todo * parent, Todo * sub )
2760{ 2761{
2761 if (!sub) return; 2762 if (!sub) return;
2762 if (!parent) return; 2763 if (!parent) return;
2763 if ( sub->relatedTo() ) 2764 if ( sub->relatedTo() )
2764 sub->relatedTo()->removeRelation(sub); 2765 sub->relatedTo()->removeRelation(sub);
2765 sub->setRelatedTo(parent); 2766 sub->setRelatedTo(parent);
2766 sub->setRelatedToUid(parent->uid()); 2767 sub->setRelatedToUid(parent->uid());
2767 parent->addRelation(sub); 2768 parent->addRelation(sub);
2768 sub->updated(); 2769 sub->updated();
2769 parent->updated(); 2770 parent->updated();
2770 setModified(true); 2771 setModified(true);
2771 updateView(); 2772 updateView();
2772} 2773}
2773void CalendarView::todo_unsub(Todo *anTodo ) 2774void CalendarView::todo_unsub(Todo *anTodo )
2774{ 2775{
2775 // Todo *anTodo = selectedTodo(); 2776 // Todo *anTodo = selectedTodo();
2776 if (!anTodo) return; 2777 if (!anTodo) return;
2777 if (!anTodo->relatedTo()) return; 2778 if (!anTodo->relatedTo()) return;
2778 anTodo->relatedTo()->removeRelation(anTodo); 2779 anTodo->relatedTo()->removeRelation(anTodo);
2779 anTodo->setRelatedTo(0); 2780 anTodo->setRelatedTo(0);
2780 anTodo->updated(); 2781 anTodo->updated();
2781 anTodo->setRelatedToUid(""); 2782 anTodo->setRelatedToUid("");
2782 setModified(true); 2783 setModified(true);
2783 updateView(); 2784 updateView();
2784} 2785}
2785 2786
2786void CalendarView::deleteTodo(Todo *todo) 2787void CalendarView::deleteTodo(Todo *todo)
2787{ 2788{
2788 if (!todo) { 2789 if (!todo) {
2789 KNotifyClient::beep(); 2790 KNotifyClient::beep();
2790 return; 2791 return;
2791 } 2792 }
2792 if (KOPrefs::instance()->mConfirm) { 2793 if (KOPrefs::instance()->mConfirm) {
2793 switch (msgItemDelete()) { 2794 switch (msgItemDelete()) {
2794 case KMessageBox::Continue: // OK 2795 case KMessageBox::Continue: // OK
2795 if (!todo->relations().isEmpty()) { 2796 if (!todo->relations().isEmpty()) {
2796 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), 2797 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."),
2797 i18n("Delete To-Do")); 2798 i18n("Delete To-Do"));
2798 } else { 2799 } else {
2799 checkExternalId( todo ); 2800 checkExternalId( todo );
2800 calendar()->deleteTodo(todo); 2801 calendar()->deleteTodo(todo);
2801 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2802 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2802 updateView(); 2803 updateView();
2803 } 2804 }
2804 break; 2805 break;
2805 } // switch 2806 } // switch
2806 } else { 2807 } else {
2807 if (!todo->relations().isEmpty()) { 2808 if (!todo->relations().isEmpty()) {
2808 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), 2809 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."),
2809 i18n("Delete To-Do")); 2810 i18n("Delete To-Do"));
2810 } else { 2811 } else {
2811 checkExternalId( todo ); 2812 checkExternalId( todo );
2812 mCalendar->deleteTodo(todo); 2813 mCalendar->deleteTodo(todo);
2813 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2814 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2814 updateView(); 2815 updateView();
2815 } 2816 }
2816 } 2817 }
2817 emit updateSearchDialog(); 2818 emit updateSearchDialog();
2818} 2819}
2819void CalendarView::deleteJournal(Journal *jour) 2820void CalendarView::deleteJournal(Journal *jour)
2820{ 2821{
2821 if (!jour) { 2822 if (!jour) {
2822 KNotifyClient::beep(); 2823 KNotifyClient::beep();
2823 return; 2824 return;
2824 } 2825 }
2825 if (KOPrefs::instance()->mConfirm) { 2826 if (KOPrefs::instance()->mConfirm) {
2826 switch (msgItemDelete()) { 2827 switch (msgItemDelete()) {
2827 case KMessageBox::Continue: // OK 2828 case KMessageBox::Continue: // OK
2828 calendar()->deleteJournal(jour); 2829 calendar()->deleteJournal(jour);
2829 updateView(); 2830 updateView();
2830 break; 2831 break;
2831 } // switch 2832 } // switch
2832 } else { 2833 } else {
2833 calendar()->deleteJournal(jour);; 2834 calendar()->deleteJournal(jour);;
2834 updateView(); 2835 updateView();
2835 } 2836 }
2836 emit updateSearchDialog(); 2837 emit updateSearchDialog();
2837} 2838}
2838 2839
2839void CalendarView::deleteEvent(Event *anEvent) 2840void CalendarView::deleteEvent(Event *anEvent)
2840{ 2841{
2841 if (!anEvent) { 2842 if (!anEvent) {
2842 KNotifyClient::beep(); 2843 KNotifyClient::beep();
2843 return; 2844 return;
2844 } 2845 }
2845 2846
2846 if (anEvent->recurrence()->doesRecur()) { 2847 if (anEvent->recurrence()->doesRecur()) {
2847 QDate itemDate = mViewManager->currentSelectionDate(); 2848 QDate itemDate = mViewManager->currentSelectionDate();
2848 int km; 2849 int km;
2849 if (!itemDate.isValid()) { 2850 if (!itemDate.isValid()) {
2850 //kdDebug() << "Date Not Valid" << endl; 2851 //kdDebug() << "Date Not Valid" << endl;
2851 if (KOPrefs::instance()->mConfirm) { 2852 if (KOPrefs::instance()->mConfirm) {
2852 km = KMessageBox::warningContinueCancel(this,anEvent->summary() + 2853 km = KMessageBox::warningContinueCancel(this,anEvent->summary() +
2853 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 2854 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
2854 i18n("KO/Pi Confirmation"),i18n("Delete All")); 2855 i18n("KO/Pi Confirmation"),i18n("Delete All"));
2855 if ( km == KMessageBox::Continue ) 2856 if ( km == KMessageBox::Continue )
2856 km = KMessageBox::No; // No = all below 2857 km = KMessageBox::No; // No = all below
2857 } else 2858 } else
2858 km = KMessageBox::No; 2859 km = KMessageBox::No;
2859 } else { 2860 } else {
2860 km = KMessageBox::warningYesNoCancel(this,anEvent->summary() + 2861 km = KMessageBox::warningYesNoCancel(this,anEvent->summary() +
2861 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 2862 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
2862 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 2863 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
2863 i18n("KO/Pi Confirmation"),i18n("Current"), 2864 i18n("KO/Pi Confirmation"),i18n("Current"),
2864 i18n("All")); 2865 i18n("All"));
2865 } 2866 }
2866 switch(km) { 2867 switch(km) {
2867 2868
2868 case KMessageBox::No: // Continue // all 2869 case KMessageBox::No: // Continue // all
2869 //qDebug("KMessageBox::No "); 2870 //qDebug("KMessageBox::No ");
2870 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2871 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2871 schedule(Scheduler::Cancel,anEvent); 2872 schedule(Scheduler::Cancel,anEvent);
2872 2873
2873 checkExternalId( anEvent); 2874 checkExternalId( anEvent);
2874 mCalendar->deleteEvent(anEvent); 2875 mCalendar->deleteEvent(anEvent);
2875 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 2876 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
2876 break; 2877 break;
2877 2878
2878 // Disabled because it does not work 2879 // Disabled because it does not work
2879 //#if 0 2880 //#if 0
2880 case KMessageBox::Yes: // just this one 2881 case KMessageBox::Yes: // just this one
2881 //QDate qd = mNavigator->selectedDates().first(); 2882 //QDate qd = mNavigator->selectedDates().first();
2882 //if (!qd.isValid()) { 2883 //if (!qd.isValid()) {
2883 // kdDebug() << "no date selected, or invalid date" << endl; 2884 // kdDebug() << "no date selected, or invalid date" << endl;
2884 // KNotifyClient::beep(); 2885 // KNotifyClient::beep();
2885 // return; 2886 // return;
2886 //} 2887 //}
2887 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 2888 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
2888 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 2889 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
2889 anEvent->addExDate(itemDate); 2890 anEvent->addExDate(itemDate);
2890 int duration = anEvent->recurrence()->duration(); 2891 int duration = anEvent->recurrence()->duration();
2891 if ( duration > 0 ) { 2892 if ( duration > 0 ) {
2892 anEvent->recurrence()->setDuration( duration - 1 ); 2893 anEvent->recurrence()->setDuration( duration - 1 );
2893 } 2894 }
2894 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 2895 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
2895 } 2896 }
2896 break; 2897 break;
2897 //#endif 2898 //#endif
2898 } // switch 2899 } // switch
2899 } else { 2900 } else {
2900 if (KOPrefs::instance()->mConfirm) { 2901 if (KOPrefs::instance()->mConfirm) {
2901 switch (KMessageBox::warningContinueCancel(this,anEvent->summary() + 2902 switch (KMessageBox::warningContinueCancel(this,anEvent->summary() +
2902 i18n("\nAre you sure you want\nto delete this event?"), 2903 i18n("\nAre you sure you want\nto delete this event?"),
2903 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 2904 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
2904 case KMessageBox::Continue: // OK 2905 case KMessageBox::Continue: // OK
2905 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2906 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2906 schedule(Scheduler::Cancel,anEvent); 2907 schedule(Scheduler::Cancel,anEvent);
2907 checkExternalId( anEvent); 2908 checkExternalId( anEvent);
2908 mCalendar->deleteEvent(anEvent); 2909 mCalendar->deleteEvent(anEvent);
2909 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2910 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2910 break; 2911 break;
2911 } // switch 2912 } // switch
2912 } else { 2913 } else {
2913 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2914 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2914 schedule(Scheduler::Cancel,anEvent); 2915 schedule(Scheduler::Cancel,anEvent);
2915 checkExternalId( anEvent); 2916 checkExternalId( anEvent);
2916 mCalendar->deleteEvent(anEvent); 2917 mCalendar->deleteEvent(anEvent);
2917 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2918 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2918 } 2919 }
2919 } // if-else 2920 } // if-else
2920 emit updateSearchDialog(); 2921 emit updateSearchDialog();
2921} 2922}
2922 2923
2923bool CalendarView::deleteEvent(const QString &uid) 2924bool CalendarView::deleteEvent(const QString &uid)
2924{ 2925{
2925 Event *ev = mCalendar->event(uid); 2926 Event *ev = mCalendar->event(uid);
2926 if (ev) { 2927 if (ev) {
2927 deleteEvent(ev); 2928 deleteEvent(ev);
2928 return true; 2929 return true;
2929 } else { 2930 } else {
2930 return false; 2931 return false;
2931 } 2932 }
2932} 2933}
2933 2934
2934/*****************************************************************************/ 2935/*****************************************************************************/
2935 2936
2936void CalendarView::action_mail() 2937void CalendarView::action_mail()
2937{ 2938{
2938#ifndef KORG_NOMAIL 2939#ifndef KORG_NOMAIL
2939 KOMailClient mailClient; 2940 KOMailClient mailClient;
2940 2941
2941 Incidence *incidence = currentSelection(); 2942 Incidence *incidence = currentSelection();
2942 2943
2943 if (!incidence) { 2944 if (!incidence) {
2944 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 2945 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
2945 return; 2946 return;
2946 } 2947 }
2947 if(incidence->attendeeCount() == 0 ) { 2948 if(incidence->attendeeCount() == 0 ) {
2948 KMessageBox::sorry(this, 2949 KMessageBox::sorry(this,
2949 i18n("Can't generate mail:\nNo attendees defined.\n")); 2950 i18n("Can't generate mail:\nNo attendees defined.\n"));
2950 return; 2951 return;
2951 } 2952 }
2952 2953
2953 CalendarLocal cal_tmp; 2954 CalendarLocal cal_tmp;
2954 Event *event = 0; 2955 Event *event = 0;
2955 Event *ev = 0; 2956 Event *ev = 0;
2956 if ( incidence && incidence->type() == "Event" ) { 2957 if ( incidence && incidence->type() == "Event" ) {
2957 event = static_cast<Event *>(incidence); 2958 event = static_cast<Event *>(incidence);
2958 ev = new Event(*event); 2959 ev = new Event(*event);
2959 cal_tmp.addEvent(ev); 2960 cal_tmp.addEvent(ev);
2960 } 2961 }
2961 ICalFormat mForm(); 2962 ICalFormat mForm();
2962 QString attachment = mForm.toString( &cal_tmp ); 2963 QString attachment = mForm.toString( &cal_tmp );
2963 if (ev) delete(ev); 2964 if (ev) delete(ev);
2964 2965
2965 mailClient.mailAttendees(currentSelection(), attachment); 2966 mailClient.mailAttendees(currentSelection(), attachment);
2966 2967
2967#endif 2968#endif
2968 2969
2969#if 0 2970#if 0
2970 Event *anEvent = 0; 2971 Event *anEvent = 0;
2971 if (mViewManager->currentView()->isEventView()) { 2972 if (mViewManager->currentView()->isEventView()) {
2972 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); 2973 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
2973 } 2974 }
2974 2975
2975 if (!anEvent) { 2976 if (!anEvent) {
2976 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 2977 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
2977 return; 2978 return;
2978 } 2979 }
2979 if(anEvent->attendeeCount() == 0 ) { 2980 if(anEvent->attendeeCount() == 0 ) {
2980 KMessageBox::sorry(this, 2981 KMessageBox::sorry(this,
2981 i18n("Can't generate mail:\nNo attendees defined.\n")); 2982 i18n("Can't generate mail:\nNo attendees defined.\n"));
2982 return; 2983 return;
2983 } 2984 }
2984 2985
2985 mailobject.emailEvent(anEvent); 2986 mailobject.emailEvent(anEvent);
2986#endif 2987#endif
2987} 2988}
2988 2989
2989 2990
2990void CalendarView::schedule_publish(Incidence *incidence) 2991void CalendarView::schedule_publish(Incidence *incidence)
2991{ 2992{
2992 Event *event = 0; 2993 Event *event = 0;
2993 Todo *todo = 0; 2994 Todo *todo = 0;
2994 2995
2995 if (incidence == 0) { 2996 if (incidence == 0) {
2996 incidence = mViewManager->currentView()->selectedIncidences().first(); 2997 incidence = mViewManager->currentView()->selectedIncidences().first();
2997 if (incidence == 0) { 2998 if (incidence == 0) {
2998 incidence = mTodoList->selectedIncidences().first(); 2999 incidence = mTodoList->selectedIncidences().first();
2999 } 3000 }
3000 } 3001 }
3001 if ( incidence && incidence->type() == "Event" ) { 3002 if ( incidence && incidence->type() == "Event" ) {
3002 event = static_cast<Event *>(incidence); 3003 event = static_cast<Event *>(incidence);
3003 } else { 3004 } else {
3004 if ( incidence && incidence->type() == "Todo" ) { 3005 if ( incidence && incidence->type() == "Todo" ) {
3005 todo = static_cast<Todo *>(incidence); 3006 todo = static_cast<Todo *>(incidence);
3006 } 3007 }
3007 } 3008 }
3008 3009
3009 if (!event && !todo) { 3010 if (!event && !todo) {
3010 KMessageBox::sorry(this,i18n("No event selected.")); 3011 KMessageBox::sorry(this,i18n("No event selected."));
3011 return; 3012 return;
3012 } 3013 }
3013 3014
3014 PublishDialog *publishdlg = new PublishDialog(); 3015 PublishDialog *publishdlg = new PublishDialog();
3015 if (incidence->attendeeCount()>0) { 3016 if (incidence->attendeeCount()>0) {
3016 QPtrList<Attendee> attendees = incidence->attendees(); 3017 QPtrList<Attendee> attendees = incidence->attendees();
3017 attendees.first(); 3018 attendees.first();
3018 while ( attendees.current()!=0 ) { 3019 while ( attendees.current()!=0 ) {
3019 publishdlg->addAttendee(attendees.current()); 3020 publishdlg->addAttendee(attendees.current());
3020 attendees.next(); 3021 attendees.next();
3021 } 3022 }
3022 } 3023 }
3023 bool send = true; 3024 bool send = true;
3024 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 3025 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
3025 if ( publishdlg->exec() != QDialog::Accepted ) 3026 if ( publishdlg->exec() != QDialog::Accepted )
3026 send = false; 3027 send = false;
3027 } 3028 }
3028 if ( send ) { 3029 if ( send ) {
3029 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3030 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3030 if ( event ) { 3031 if ( event ) {
3031 Event *ev = new Event(*event); 3032 Event *ev = new Event(*event);
3032 ev->registerObserver(0); 3033 ev->registerObserver(0);
3033 ev->clearAttendees(); 3034 ev->clearAttendees();
3034 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3035 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3035 delete(ev); 3036 delete(ev);
3036 } 3037 }
3037 } else { 3038 } else {
3038 if ( todo ) { 3039 if ( todo ) {
3039 Todo *ev = new Todo(*todo); 3040 Todo *ev = new Todo(*todo);
3040 ev->registerObserver(0); 3041 ev->registerObserver(0);
3041 ev->clearAttendees(); 3042 ev->clearAttendees();
3042 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3043 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3043 delete(ev); 3044 delete(ev);
3044 } 3045 }
3045 } 3046 }
3046 } 3047 }
3047 } 3048 }
3048 delete publishdlg; 3049 delete publishdlg;
3049} 3050}
3050 3051
3051void CalendarView::schedule_request(Incidence *incidence) 3052void CalendarView::schedule_request(Incidence *incidence)
3052{ 3053{
3053 schedule(Scheduler::Request,incidence); 3054 schedule(Scheduler::Request,incidence);
3054} 3055}
3055 3056
3056void CalendarView::schedule_refresh(Incidence *incidence) 3057void CalendarView::schedule_refresh(Incidence *incidence)
3057{ 3058{
3058 schedule(Scheduler::Refresh,incidence); 3059 schedule(Scheduler::Refresh,incidence);
3059} 3060}
3060 3061
3061void CalendarView::schedule_cancel(Incidence *incidence) 3062void CalendarView::schedule_cancel(Incidence *incidence)
3062{ 3063{
3063 schedule(Scheduler::Cancel,incidence); 3064 schedule(Scheduler::Cancel,incidence);
3064} 3065}
3065 3066
3066void CalendarView::schedule_add(Incidence *incidence) 3067void CalendarView::schedule_add(Incidence *incidence)
3067{ 3068{
3068 schedule(Scheduler::Add,incidence); 3069 schedule(Scheduler::Add,incidence);
3069} 3070}
3070 3071
3071void CalendarView::schedule_reply(Incidence *incidence) 3072void CalendarView::schedule_reply(Incidence *incidence)
3072{ 3073{
3073 schedule(Scheduler::Reply,incidence); 3074 schedule(Scheduler::Reply,incidence);
3074} 3075}
3075 3076
3076void CalendarView::schedule_counter(Incidence *incidence) 3077void CalendarView::schedule_counter(Incidence *incidence)
3077{ 3078{
3078 schedule(Scheduler::Counter,incidence); 3079 schedule(Scheduler::Counter,incidence);
3079} 3080}
3080 3081
3081void CalendarView::schedule_declinecounter(Incidence *incidence) 3082void CalendarView::schedule_declinecounter(Incidence *incidence)
3082{ 3083{
3083 schedule(Scheduler::Declinecounter,incidence); 3084 schedule(Scheduler::Declinecounter,incidence);
3084} 3085}
3085 3086
3086void CalendarView::schedule_publish_freebusy(int daysToPublish) 3087void CalendarView::schedule_publish_freebusy(int daysToPublish)
3087{ 3088{
3088 QDateTime start = QDateTime::currentDateTime(); 3089 QDateTime start = QDateTime::currentDateTime();
3089 QDateTime end = start.addDays(daysToPublish); 3090 QDateTime end = start.addDays(daysToPublish);
3090 3091
3091 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); 3092 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
3092 freebusy->setOrganizer(KOPrefs::instance()->email()); 3093 freebusy->setOrganizer(KOPrefs::instance()->email());
3093 3094
3094 3095
3095 PublishDialog *publishdlg = new PublishDialog(); 3096 PublishDialog *publishdlg = new PublishDialog();
3096 if ( publishdlg->exec() == QDialog::Accepted ) { 3097 if ( publishdlg->exec() == QDialog::Accepted ) {
3097 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3098 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3098 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { 3099 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
3099 delete(freebusy); 3100 delete(freebusy);
3100 } 3101 }
3101 } 3102 }
3102 delete publishdlg; 3103 delete publishdlg;
3103} 3104}
3104 3105
3105void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) 3106void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
3106{ 3107{
3107 Event *event = 0; 3108 Event *event = 0;
3108 Todo *todo = 0; 3109 Todo *todo = 0;
3109 3110
3110 if (incidence == 0) { 3111 if (incidence == 0) {
3111 incidence = mViewManager->currentView()->selectedIncidences().first(); 3112 incidence = mViewManager->currentView()->selectedIncidences().first();
3112 if (incidence == 0) { 3113 if (incidence == 0) {
3113 incidence = mTodoList->selectedIncidences().first(); 3114 incidence = mTodoList->selectedIncidences().first();
3114 } 3115 }
3115 } 3116 }
3116 if ( incidence && incidence->type() == "Event" ) { 3117 if ( incidence && incidence->type() == "Event" ) {
3117 event = static_cast<Event *>(incidence); 3118 event = static_cast<Event *>(incidence);
3118 } 3119 }
3119 if ( incidence && incidence->type() == "Todo" ) { 3120 if ( incidence && incidence->type() == "Todo" ) {
3120 todo = static_cast<Todo *>(incidence); 3121 todo = static_cast<Todo *>(incidence);
3121 } 3122 }
3122 3123
3123 if (!event && !todo) { 3124 if (!event && !todo) {
3124 KMessageBox::sorry(this,i18n("No event selected.")); 3125 KMessageBox::sorry(this,i18n("No event selected."));
3125 return; 3126 return;
3126 } 3127 }
3127 3128
3128 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { 3129 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
3129 KMessageBox::sorry(this,i18n("The event has no attendees.")); 3130 KMessageBox::sorry(this,i18n("The event has no attendees."));
3130 return; 3131 return;
3131 } 3132 }
3132 3133
3133 Event *ev = 0; 3134 Event *ev = 0;
3134 if (event) ev = new Event(*event); 3135 if (event) ev = new Event(*event);
3135 Todo *to = 0; 3136 Todo *to = 0;
3136 if (todo) to = new Todo(*todo); 3137 if (todo) to = new Todo(*todo);
3137 3138
3138 if (method == Scheduler::Reply || method == Scheduler::Refresh) { 3139 if (method == Scheduler::Reply || method == Scheduler::Refresh) {
3139 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 3140 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
3140 if (!me) { 3141 if (!me) {
3141 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); 3142 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails."));
3142 return; 3143 return;
3143 } 3144 }
3144 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { 3145 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
3145 StatusDialog *statdlg = new StatusDialog(this); 3146 StatusDialog *statdlg = new StatusDialog(this);
3146 if (!statdlg->exec()==QDialog::Accepted) return; 3147 if (!statdlg->exec()==QDialog::Accepted) return;
3147 me->setStatus( statdlg->status() ); 3148 me->setStatus( statdlg->status() );
3148 delete(statdlg); 3149 delete(statdlg);
3149 } 3150 }
3150 Attendee *menew = new Attendee(*me); 3151 Attendee *menew = new Attendee(*me);
3151 if (ev) { 3152 if (ev) {
3152 ev->clearAttendees(); 3153 ev->clearAttendees();
3153 ev->addAttendee(menew,false); 3154 ev->addAttendee(menew,false);
3154 } else { 3155 } else {
3155 if (to) { 3156 if (to) {
3156 todo->clearAttendees(); 3157 todo->clearAttendees();
3157 todo->addAttendee(menew,false); 3158 todo->addAttendee(menew,false);
3158 } 3159 }
3159 } 3160 }
3160 } 3161 }
3161 3162
3162 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3163 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3163 if (ev) { 3164 if (ev) {
3164 if ( !dlg->addMessage(ev,method) ) delete(ev); 3165 if ( !dlg->addMessage(ev,method) ) delete(ev);
3165 } else { 3166 } else {
3166 if (to) { 3167 if (to) {
3167 if ( !dlg->addMessage(to,method) ) delete(to); 3168 if ( !dlg->addMessage(to,method) ) delete(to);
3168 } 3169 }
3169 } 3170 }
3170} 3171}
3171 3172
3172void CalendarView::openAddressbook() 3173void CalendarView::openAddressbook()
3173{ 3174{
3174 KRun::runCommand("kaddressbook"); 3175 KRun::runCommand("kaddressbook");
3175} 3176}
3176 3177
3177void CalendarView::setModified(bool modified) 3178void CalendarView::setModified(bool modified)
3178{ 3179{
3179 if ( modified ) 3180 if ( modified )
3180 emit signalmodified(); 3181 emit signalmodified();
3181 if (mModified != modified) { 3182 if (mModified != modified) {
3182 mModified = modified; 3183 mModified = modified;
3183 emit modifiedChanged(mModified); 3184 emit modifiedChanged(mModified);
3184 } 3185 }
3185} 3186}
3186 3187
3187bool CalendarView::isReadOnly() 3188bool CalendarView::isReadOnly()
3188{ 3189{
3189 return mReadOnly; 3190 return mReadOnly;
3190} 3191}
3191 3192
3192void CalendarView::setReadOnly(bool readOnly) 3193void CalendarView::setReadOnly(bool readOnly)
3193{ 3194{
3194 if (mReadOnly != readOnly) { 3195 if (mReadOnly != readOnly) {
3195 mReadOnly = readOnly; 3196 mReadOnly = readOnly;
3196 emit readOnlyChanged(mReadOnly); 3197 emit readOnlyChanged(mReadOnly);
3197 } 3198 }
3198} 3199}
3199 3200
3200bool CalendarView::isModified() 3201bool CalendarView::isModified()
3201{ 3202{
3202 return mModified; 3203 return mModified;
3203} 3204}
3204 3205
3205void CalendarView::printSetup() 3206void CalendarView::printSetup()
3206{ 3207{
3207#ifndef KORG_NOPRINTER 3208#ifndef KORG_NOPRINTER
3208 createPrinter(); 3209 createPrinter();
3209 3210
3210 mCalPrinter->setupPrinter(); 3211 mCalPrinter->setupPrinter();
3211#endif 3212#endif
3212} 3213}
3213 3214
3214void CalendarView::print() 3215void CalendarView::print()
3215{ 3216{
3216#ifndef KORG_NOPRINTER 3217#ifndef KORG_NOPRINTER
3217 createPrinter(); 3218 createPrinter();
3218 3219
3219 DateList tmpDateList = mNavigator->selectedDates(); 3220 DateList tmpDateList = mNavigator->selectedDates();
3220 mCalPrinter->print(CalPrinter::Month, 3221 mCalPrinter->print(CalPrinter::Month,
3221 tmpDateList.first(), tmpDateList.last()); 3222 tmpDateList.first(), tmpDateList.last());
3222#endif 3223#endif
3223} 3224}
3224 3225
3225void CalendarView::printPreview() 3226void CalendarView::printPreview()
3226{ 3227{
3227#ifndef KORG_NOPRINTER 3228#ifndef KORG_NOPRINTER
3228 kdDebug() << "CalendarView::printPreview()" << endl; 3229 kdDebug() << "CalendarView::printPreview()" << endl;
3229 3230
3230 createPrinter(); 3231 createPrinter();
3231 3232
3232 DateList tmpDateList = mNavigator->selectedDates(); 3233 DateList tmpDateList = mNavigator->selectedDates();
3233 3234
3234 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), 3235 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(),
3235 tmpDateList.last()); 3236 tmpDateList.last());
3236#endif 3237#endif
3237} 3238}
3238 3239
3239void CalendarView::exportICalendar() 3240void CalendarView::exportICalendar()
3240{ 3241{
3241 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); 3242 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this);
3242 3243
3243 // Force correct extension 3244 // Force correct extension
3244 if (filename.right(4) != ".ics") filename += ".ics"; 3245 if (filename.right(4) != ".ics") filename += ".ics";
3245 3246
3246 FileStorage storage( mCalendar, filename, new ICalFormat() ); 3247 FileStorage storage( mCalendar, filename, new ICalFormat() );
3247 storage.save(); 3248 storage.save();
3248} 3249}
3249 3250
3250bool CalendarView::exportVCalendar( QString filename ) 3251bool CalendarView::exportVCalendar( QString filename )
3251{ 3252{
3252 if (mCalendar->journals().count() > 0) { 3253 if (mCalendar->journals().count() > 0) {
3253 int result = KMessageBox::warningContinueCancel(this, 3254 int result = KMessageBox::warningContinueCancel(this,
3254 i18n("The journal entries can not be\nexported to a vCalendar file."), 3255 i18n("The journal entries can not be\nexported to a vCalendar file."),
3255 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 3256 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
3256 true); 3257 true);
3257 if (result != KMessageBox::Continue) return false; 3258 if (result != KMessageBox::Continue) return false;
3258 } 3259 }
3259 3260
3260 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); 3261 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this);
3261 3262
3262 // Force correct extension 3263 // Force correct extension
3263 if (filename.right(4) != ".vcs") filename += ".vcs"; 3264 if (filename.right(4) != ".vcs") filename += ".vcs";
3264 3265
3265 FileStorage storage( mCalendar, filename, new VCalFormat ); 3266 FileStorage storage( mCalendar, filename, new VCalFormat );
3266 return storage.save(); 3267 return storage.save();
3267 3268
3268} 3269}
3269 3270
3270void CalendarView::eventUpdated(Incidence *) 3271void CalendarView::eventUpdated(Incidence *)
3271{ 3272{
3272 setModified(); 3273 setModified();
3273 // Don't call updateView here. The code, which has caused the update of the 3274 // Don't call updateView here. The code, which has caused the update of the
3274 // event is responsible for updating the view. 3275 // event is responsible for updating the view.
3275 // updateView(); 3276 // updateView();
3276} 3277}
3277 3278
3278void CalendarView::adaptNavigationUnits() 3279void CalendarView::adaptNavigationUnits()
3279{ 3280{
3280 if (mViewManager->currentView()->isEventView()) { 3281 if (mViewManager->currentView()->isEventView()) {
3281 int days = mViewManager->currentView()->currentDateCount(); 3282 int days = mViewManager->currentView()->currentDateCount();
3282 if (days == 1) { 3283 if (days == 1) {
3283 emit changeNavStringPrev(i18n("&Previous Day")); 3284 emit changeNavStringPrev(i18n("&Previous Day"));
3284 emit changeNavStringNext(i18n("&Next Day")); 3285 emit changeNavStringNext(i18n("&Next Day"));
3285 } else { 3286 } else {
3286 emit changeNavStringPrev(i18n("&Previous Week")); 3287 emit changeNavStringPrev(i18n("&Previous Week"));
3287 emit changeNavStringNext(i18n("&Next Week")); 3288 emit changeNavStringNext(i18n("&Next Week"));
3288 } 3289 }
3289 } 3290 }
3290} 3291}
3291 3292
3292void CalendarView::processMainViewSelection( Incidence *incidence ) 3293void CalendarView::processMainViewSelection( Incidence *incidence )
3293{ 3294{
3294 if ( incidence ) mTodoList->clearSelection(); 3295 if ( incidence ) mTodoList->clearSelection();
3295 processIncidenceSelection( incidence ); 3296 processIncidenceSelection( incidence );
3296} 3297}
3297 3298
3298void CalendarView::processTodoListSelection( Incidence *incidence ) 3299void CalendarView::processTodoListSelection( Incidence *incidence )
3299{ 3300{
3300 if ( incidence && mViewManager->currentView() ) { 3301 if ( incidence && mViewManager->currentView() ) {
3301 mViewManager->currentView()->clearSelection(); 3302 mViewManager->currentView()->clearSelection();
3302 } 3303 }
3303 processIncidenceSelection( incidence ); 3304 processIncidenceSelection( incidence );
3304} 3305}
3305 3306
3306void CalendarView::processIncidenceSelection( Incidence *incidence ) 3307void CalendarView::processIncidenceSelection( Incidence *incidence )
3307{ 3308{
3308 if ( incidence == mSelectedIncidence ) return; 3309 if ( incidence == mSelectedIncidence ) return;
3309 3310
3310 mSelectedIncidence = incidence; 3311 mSelectedIncidence = incidence;
3311 3312
3312 emit incidenceSelected( mSelectedIncidence ); 3313 emit incidenceSelected( mSelectedIncidence );
3313 3314
3314 if ( incidence && incidence->type() == "Event" ) { 3315 if ( incidence && incidence->type() == "Event" ) {
3315 Event *event = static_cast<Event *>( incidence ); 3316 Event *event = static_cast<Event *>( incidence );
3316 if ( event->organizer() == KOPrefs::instance()->email() ) { 3317 if ( event->organizer() == KOPrefs::instance()->email() ) {
3317 emit organizerEventsSelected( true ); 3318 emit organizerEventsSelected( true );
3318 } else { 3319 } else {
3319 emit organizerEventsSelected(false); 3320 emit organizerEventsSelected(false);
3320 } 3321 }
3321 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3322 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3322 KOPrefs::instance()->email() ) ) { 3323 KOPrefs::instance()->email() ) ) {
3323 emit groupEventsSelected( true ); 3324 emit groupEventsSelected( true );
3324 } else { 3325 } else {
3325 emit groupEventsSelected(false); 3326 emit groupEventsSelected(false);
3326 } 3327 }
3327 return; 3328 return;
3328 } else { 3329 } else {
3329 if ( incidence && incidence->type() == "Todo" ) { 3330 if ( incidence && incidence->type() == "Todo" ) {
3330 emit todoSelected( true ); 3331 emit todoSelected( true );
3331 Todo *event = static_cast<Todo *>( incidence ); 3332 Todo *event = static_cast<Todo *>( incidence );
3332 if ( event->organizer() == KOPrefs::instance()->email() ) { 3333 if ( event->organizer() == KOPrefs::instance()->email() ) {
3333 emit organizerEventsSelected( true ); 3334 emit organizerEventsSelected( true );
3334 } else { 3335 } else {
3335 emit organizerEventsSelected(false); 3336 emit organizerEventsSelected(false);
3336 } 3337 }
3337 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3338 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3338 KOPrefs::instance()->email() ) ) { 3339 KOPrefs::instance()->email() ) ) {
3339 emit groupEventsSelected( true ); 3340 emit groupEventsSelected( true );
3340 } else { 3341 } else {
3341 emit groupEventsSelected(false); 3342 emit groupEventsSelected(false);
3342 } 3343 }
3343 return; 3344 return;
3344 } else { 3345 } else {
3345 emit todoSelected( false ); 3346 emit todoSelected( false );
3346 emit organizerEventsSelected(false); 3347 emit organizerEventsSelected(false);
3347 emit groupEventsSelected(false); 3348 emit groupEventsSelected(false);
3348 } 3349 }
3349 return; 3350 return;
3350 } 3351 }
3351 3352
3352 /* if ( incidence && incidence->type() == "Todo" ) { 3353 /* if ( incidence && incidence->type() == "Todo" ) {
3353 emit todoSelected( true ); 3354 emit todoSelected( true );
3354 } else { 3355 } else {
3355 emit todoSelected( false ); 3356 emit todoSelected( false );
3356 }*/ 3357 }*/
3357} 3358}
3358 3359
3359 3360
3360void CalendarView::checkClipboard() 3361void CalendarView::checkClipboard()
3361{ 3362{
3362#ifndef KORG_NODND 3363#ifndef KORG_NODND
3363 if (ICalDrag::canDecode(QApplication::clipboard()->data())) { 3364 if (ICalDrag::canDecode(QApplication::clipboard()->data())) {
3364 emit pasteEnabled(true); 3365 emit pasteEnabled(true);
3365 } else { 3366 } else {
3366 emit pasteEnabled(false); 3367 emit pasteEnabled(false);
3367 } 3368 }
3368#endif 3369#endif
3369} 3370}
3370 3371
3371void CalendarView::showDates(const DateList &selectedDates) 3372void CalendarView::showDates(const DateList &selectedDates)
3372{ 3373{
3373 // kdDebug() << "CalendarView::selectDates()" << endl; 3374 // kdDebug() << "CalendarView::selectDates()" << endl;
3374 3375
3375 if ( mViewManager->currentView() ) { 3376 if ( mViewManager->currentView() ) {
3376 updateView( selectedDates.first(), selectedDates.last() ); 3377 updateView( selectedDates.first(), selectedDates.last() );
3377 } else { 3378 } else {
3378 mViewManager->showAgendaView(); 3379 mViewManager->showAgendaView();
3379 } 3380 }
3380 3381
3381 QString selDates; 3382 QString selDates;
3382 selDates = KGlobal::locale()->formatDate( selectedDates.first(), true); 3383 selDates = KGlobal::locale()->formatDate( selectedDates.first(), true);
3383 if (selectedDates.first() < selectedDates.last() ) 3384 if (selectedDates.first() < selectedDates.last() )
3384 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); 3385 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true);
3385 topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); 3386 topLevelWidget()->setCaption( i18n("Dates: ") + selDates );
3386 3387
3387} 3388}
3388 3389
3389QPtrList<CalFilter> CalendarView::filters() 3390QPtrList<CalFilter> CalendarView::filters()
3390{ 3391{
3391 return mFilters; 3392 return mFilters;
3392 3393
3393} 3394}
3394void CalendarView::editFilters() 3395void CalendarView::editFilters()
3395{ 3396{
3396 // kdDebug() << "CalendarView::editFilters()" << endl; 3397 // kdDebug() << "CalendarView::editFilters()" << endl;
3397 3398
3398 CalFilter *filter = mFilters.first(); 3399 CalFilter *filter = mFilters.first();
3399 while(filter) { 3400 while(filter) {
3400 kdDebug() << " Filter: " << filter->name() << endl; 3401 kdDebug() << " Filter: " << filter->name() << endl;
3401 filter = mFilters.next(); 3402 filter = mFilters.next();
3402 } 3403 }
3403 3404
3404 mDialogManager->showFilterEditDialog(&mFilters); 3405 mDialogManager->showFilterEditDialog(&mFilters);
3405} 3406}
3406void CalendarView::toggleFilter() 3407void CalendarView::toggleFilter()
3407{ 3408{
3408 showFilter(! mFilterView->isVisible()); 3409 showFilter(! mFilterView->isVisible());
3409} 3410}
3410 3411
3411KOFilterView *CalendarView::filterView() 3412KOFilterView *CalendarView::filterView()
3412{ 3413{
3413 return mFilterView; 3414 return mFilterView;
3414} 3415}
3415void CalendarView::selectFilter( int fil ) 3416void CalendarView::selectFilter( int fil )
3416{ 3417{
3417 mFilterView->setSelectedFilter( fil ); 3418 mFilterView->setSelectedFilter( fil );
3418} 3419}
3419void CalendarView::showFilter(bool visible) 3420void CalendarView::showFilter(bool visible)
3420{ 3421{
3421 if (visible) mFilterView->show(); 3422 if (visible) mFilterView->show();
3422 else mFilterView->hide(); 3423 else mFilterView->hide();
3423} 3424}
3424void CalendarView::toggleFilerEnabled( ) 3425void CalendarView::toggleFilerEnabled( )
3425{ 3426{
3426 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); 3427 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() );
3427 if ( !mFilterView->filtersEnabled() ) 3428 if ( !mFilterView->filtersEnabled() )
3428 topLevelWidget()->setCaption( i18n("Filter disabled ") ); 3429 topLevelWidget()->setCaption( i18n("Filter disabled ") );
3429 3430
3430} 3431}
3431void CalendarView::updateFilter() 3432void CalendarView::updateFilter()
3432{ 3433{
3433 CalFilter *filter = mFilterView->selectedFilter(); 3434 CalFilter *filter = mFilterView->selectedFilter();
3434 if (filter) { 3435 if (filter) {
3435 if (mFilterView->filtersEnabled()) { 3436 if (mFilterView->filtersEnabled()) {
3436 topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() ); 3437 topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() );
3437 filter->setEnabled(true); 3438 filter->setEnabled(true);
3438 } 3439 }
3439 else filter->setEnabled(false); 3440 else filter->setEnabled(false);
3440 mCalendar->setFilter(filter); 3441 mCalendar->setFilter(filter);
3441 updateView(); 3442 updateView();
3442 } 3443 }
3443} 3444}
3444 3445
3445void CalendarView::filterEdited() 3446void CalendarView::filterEdited()
3446{ 3447{
3447 mFilterView->updateFilters(); 3448 mFilterView->updateFilters();
3448 updateFilter(); 3449 updateFilter();
3449 writeSettings(); 3450 writeSettings();
3450} 3451}
3451 3452
3452 3453
3453void CalendarView::takeOverEvent() 3454void CalendarView::takeOverEvent()
3454{ 3455{
3455 Incidence *incidence = currentSelection(); 3456 Incidence *incidence = currentSelection();
3456 3457
3457 if (!incidence) return; 3458 if (!incidence) return;
3458 3459
3459 incidence->setOrganizer(KOPrefs::instance()->email()); 3460 incidence->setOrganizer(KOPrefs::instance()->email());
3460 incidence->recreate(); 3461 incidence->recreate();
3461 incidence->setReadOnly(false); 3462 incidence->setReadOnly(false);
3462 3463
3463 updateView(); 3464 updateView();
3464} 3465}
3465 3466
3466void CalendarView::takeOverCalendar() 3467void CalendarView::takeOverCalendar()
3467{ 3468{
3468 // TODO: Create Calendar::allIncidences() function and use it here 3469 // TODO: Create Calendar::allIncidences() function and use it here
3469 3470
3470 QPtrList<Event> events = mCalendar->events(); 3471 QPtrList<Event> events = mCalendar->events();
3471 for(uint i=0; i<events.count(); ++i) { 3472 for(uint i=0; i<events.count(); ++i) {
3472 events.at(i)->setOrganizer(KOPrefs::instance()->email()); 3473 events.at(i)->setOrganizer(KOPrefs::instance()->email());
3473 events.at(i)->recreate(); 3474 events.at(i)->recreate();
3474 events.at(i)->setReadOnly(false); 3475 events.at(i)->setReadOnly(false);
3475 } 3476 }
3476 3477
3477 QPtrList<Todo> todos = mCalendar->todos(); 3478 QPtrList<Todo> todos = mCalendar->todos();
3478 for(uint i=0; i<todos.count(); ++i) { 3479 for(uint i=0; i<todos.count(); ++i) {
3479 todos.at(i)->setOrganizer(KOPrefs::instance()->email()); 3480 todos.at(i)->setOrganizer(KOPrefs::instance()->email());
3480 todos.at(i)->recreate(); 3481 todos.at(i)->recreate();
3481 todos.at(i)->setReadOnly(false); 3482 todos.at(i)->setReadOnly(false);
3482 } 3483 }
3483 3484
3484 QPtrList<Journal> journals = mCalendar->journals(); 3485 QPtrList<Journal> journals = mCalendar->journals();
3485 for(uint i=0; i<journals.count(); ++i) { 3486 for(uint i=0; i<journals.count(); ++i) {
3486 journals.at(i)->setOrganizer(KOPrefs::instance()->email()); 3487 journals.at(i)->setOrganizer(KOPrefs::instance()->email());
3487 journals.at(i)->recreate(); 3488 journals.at(i)->recreate();
3488 journals.at(i)->setReadOnly(false); 3489 journals.at(i)->setReadOnly(false);
3489 } 3490 }
3490 3491
3491 updateView(); 3492 updateView();
3492} 3493}
3493 3494
3494void CalendarView::showIntro() 3495void CalendarView::showIntro()
3495{ 3496{
3496 kdDebug() << "To be implemented." << endl; 3497 kdDebug() << "To be implemented." << endl;
3497} 3498}
3498 3499
3499QWidgetStack *CalendarView::viewStack() 3500QWidgetStack *CalendarView::viewStack()
3500{ 3501{
3501 return mRightFrame; 3502 return mRightFrame;
3502} 3503}
3503 3504
3504QWidget *CalendarView::leftFrame() 3505QWidget *CalendarView::leftFrame()
3505{ 3506{
3506 return mLeftFrame; 3507 return mLeftFrame;
3507} 3508}
3508 3509
3509DateNavigator *CalendarView::dateNavigator() 3510DateNavigator *CalendarView::dateNavigator()
3510{ 3511{
3511 return mNavigator; 3512 return mNavigator;
3512} 3513}
3513 3514
3514KDateNavigator* CalendarView::dateNavigatorWidget() 3515KDateNavigator* CalendarView::dateNavigatorWidget()
3515{ 3516{
3516 return mDateNavigator; 3517 return mDateNavigator;
3517} 3518}
3518void CalendarView::toggleDateNavigatorWidget() 3519void CalendarView::toggleDateNavigatorWidget()
3519{ 3520{
3520 if (mDateNavigator->isVisible()) 3521 if (mDateNavigator->isVisible())
3521 mDateNavigator->hide(); 3522 mDateNavigator->hide();
3522 else 3523 else
3523 mDateNavigator->show(); 3524 mDateNavigator->show();
3524} 3525}
3525void CalendarView::addView(KOrg::BaseView *view) 3526void CalendarView::addView(KOrg::BaseView *view)
3526{ 3527{
3527 mViewManager->addView(view); 3528 mViewManager->addView(view);
3528} 3529}
3529 3530
3530void CalendarView::showView(KOrg::BaseView *view) 3531void CalendarView::showView(KOrg::BaseView *view)
3531{ 3532{
3532 mViewManager->showView(view, mLeftFrame->isVisible()); 3533 mViewManager->showView(view, mLeftFrame->isVisible());
3533} 3534}
3534 3535
3535Incidence *CalendarView::currentSelection() 3536Incidence *CalendarView::currentSelection()
3536{ 3537{
3537 return mViewManager->currentSelection(); 3538 return mViewManager->currentSelection();
3538} 3539}
3539void CalendarView::toggleAllDaySize() 3540void CalendarView::toggleAllDaySize()
3540{ 3541{
3541 /* 3542 /*
3542 if ( KOPrefs::instance()->mAllDaySize > 47 ) 3543 if ( KOPrefs::instance()->mAllDaySize > 47 )
3543 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2; 3544 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2;
3544 else 3545 else
3545 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2; 3546 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2;
3546 */ 3547 */
3547 viewManager()->agendaView()->toggleAllDay(); 3548 viewManager()->agendaView()->toggleAllDay();
3548} 3549}
3549void CalendarView::toggleExpand() 3550void CalendarView::toggleExpand()
3550{ 3551{
3551 // if ( mLeftFrame->isHidden() ) { 3552 // if ( mLeftFrame->isHidden() ) {
3552 // mLeftFrame->show(); 3553 // mLeftFrame->show();
3553 // emit calendarViewExpanded( false ); 3554 // emit calendarViewExpanded( false );
3554 // } else { 3555 // } else {
3555 // mLeftFrame->hide(); 3556 // mLeftFrame->hide();
3556 // emit calendarViewExpanded( true ); 3557 // emit calendarViewExpanded( true );
3557 // } 3558 // }
3558 3559
3559 globalFlagBlockAgenda = 1; 3560 globalFlagBlockAgenda = 1;
3560 emit calendarViewExpanded( !mLeftFrame->isHidden() ); 3561 emit calendarViewExpanded( !mLeftFrame->isHidden() );
3561 globalFlagBlockAgenda = 5; 3562 globalFlagBlockAgenda = 5;
3562 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() ); 3563 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() );
3563 //mViewManager->showView( 0, true ); 3564 //mViewManager->showView( 0, true );
3564} 3565}
3565 3566
3566void CalendarView::calendarModified( bool modified, Calendar * ) 3567void CalendarView::calendarModified( bool modified, Calendar * )
3567{ 3568{
3568 setModified( modified ); 3569 setModified( modified );
3569} 3570}
3570 3571
3571Todo *CalendarView::selectedTodo() 3572Todo *CalendarView::selectedTodo()
3572{ 3573{
3573 Incidence *incidence = currentSelection(); 3574 Incidence *incidence = currentSelection();
3574 if ( incidence && incidence->type() == "Todo" ) { 3575 if ( incidence && incidence->type() == "Todo" ) {
3575 return static_cast<Todo *>( incidence ); 3576 return static_cast<Todo *>( incidence );
3576 } 3577 }
3577 3578
3578 incidence = mTodoList->selectedIncidences().first(); 3579 incidence = mTodoList->selectedIncidences().first();
3579 if ( incidence && incidence->type() == "Todo" ) { 3580 if ( incidence && incidence->type() == "Todo" ) {
3580 return static_cast<Todo *>( incidence ); 3581 return static_cast<Todo *>( incidence );
3581 } 3582 }
3582 3583
3583 return 0; 3584 return 0;
3584} 3585}
3585 3586
3586void CalendarView::dialogClosing(Incidence *in) 3587void CalendarView::dialogClosing(Incidence *in)
3587{ 3588{
3588 // mDialogList.remove(in); 3589 // mDialogList.remove(in);
3589} 3590}
3590 3591
3591void CalendarView::showIncidence() 3592void CalendarView::showIncidence()
3592{ 3593{
3593 Incidence *incidence = currentSelection(); 3594 Incidence *incidence = currentSelection();
3594 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3595 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3595 if ( incidence ) { 3596 if ( incidence ) {
3596 ShowIncidenceVisitor v; 3597 ShowIncidenceVisitor v;
3597 v.act( incidence, this ); 3598 v.act( incidence, this );
3598 } 3599 }
3599} 3600}
3600void CalendarView::editIncidenceDescription() 3601void CalendarView::editIncidenceDescription()
3601{ 3602{
3602 mFlagEditDescription = true; 3603 mFlagEditDescription = true;
3603 editIncidence(); 3604 editIncidence();
3604 mFlagEditDescription = false; 3605 mFlagEditDescription = false;
3605} 3606}
3606void CalendarView::editIncidence() 3607void CalendarView::editIncidence()
3607{ 3608{
3608 // qDebug("editIncidence() "); 3609 // qDebug("editIncidence() ");
3609 Incidence *incidence = currentSelection(); 3610 Incidence *incidence = currentSelection();
3610 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3611 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3611 if ( incidence ) { 3612 if ( incidence ) {
3612 EditIncidenceVisitor v; 3613 EditIncidenceVisitor v;
3613 v.act( incidence, this ); 3614 v.act( incidence, this );
3614 } 3615 }
3615} 3616}
3616 3617
3617void CalendarView::deleteIncidence() 3618void CalendarView::deleteIncidence()
3618{ 3619{
3619 Incidence *incidence = currentSelection(); 3620 Incidence *incidence = currentSelection();
3620 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3621 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3621 if ( incidence ) { 3622 if ( incidence ) {
3622 deleteIncidence(incidence); 3623 deleteIncidence(incidence);
3623 } 3624 }
3624} 3625}
3625 3626
3626void CalendarView::showIncidence(Incidence *incidence) 3627void CalendarView::showIncidence(Incidence *incidence)
3627{ 3628{
3628 if ( incidence ) { 3629 if ( incidence ) {
3629 ShowIncidenceVisitor v; 3630 ShowIncidenceVisitor v;
3630 v.act( incidence, this ); 3631 v.act( incidence, this );
3631 } 3632 }
3632} 3633}
3633 3634
3634void CalendarView::editIncidence(Incidence *incidence) 3635void CalendarView::editIncidence(Incidence *incidence)
3635{ 3636{
3636 if ( incidence ) { 3637 if ( incidence ) {
3637 3638
3638 EditIncidenceVisitor v; 3639 EditIncidenceVisitor v;
3639 v.act( incidence, this ); 3640 v.act( incidence, this );
3640 3641
3641 } 3642 }
3642} 3643}
3643 3644
3644void CalendarView::deleteIncidence(Incidence *incidence) 3645void CalendarView::deleteIncidence(Incidence *incidence)
3645{ 3646{
3646 //qDebug(" CalendarView::deleteIncidence "); 3647 //qDebug(" CalendarView::deleteIncidence ");
3647 if ( incidence ) { 3648 if ( incidence ) {
3648 DeleteIncidenceVisitor v; 3649 DeleteIncidenceVisitor v;
3649 v.act( incidence, this ); 3650 v.act( incidence, this );
3650 } 3651 }
3651} 3652}
3652 3653
3653 3654
3654void CalendarView::lookForOutgoingMessages() 3655void CalendarView::lookForOutgoingMessages()
3655{ 3656{
3656 OutgoingDialog *ogd = mDialogManager->outgoingDialog(); 3657 OutgoingDialog *ogd = mDialogManager->outgoingDialog();
3657 ogd->loadMessages(); 3658 ogd->loadMessages();
3658} 3659}
3659 3660
3660void CalendarView::lookForIncomingMessages() 3661void CalendarView::lookForIncomingMessages()
3661{ 3662{
3662 IncomingDialog *icd = mDialogManager->incomingDialog(); 3663 IncomingDialog *icd = mDialogManager->incomingDialog();
3663 icd->retrieve(); 3664 icd->retrieve();
3664} 3665}
3665 3666
3666bool CalendarView::removeCompletedSubTodos( Todo* t ) 3667bool CalendarView::removeCompletedSubTodos( Todo* t )
3667{ 3668{
3668 bool deleteTodo = true; 3669 bool deleteTodo = true;
3669 QPtrList<Incidence> subTodos; 3670 QPtrList<Incidence> subTodos;
3670 Incidence *aTodo; 3671 Incidence *aTodo;
3671 subTodos = t->relations(); 3672 subTodos = t->relations();
3672 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) { 3673 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) {
3673 if (! removeCompletedSubTodos( (Todo*) aTodo )) 3674 if (! removeCompletedSubTodos( (Todo*) aTodo ))
3674 deleteTodo = false; 3675 deleteTodo = false;
3675 } 3676 }
3676 if ( deleteTodo ) { 3677 if ( deleteTodo ) {
3677 if ( t->isCompleted() ) { 3678 if ( t->isCompleted() ) {
3678 checkExternalId( t ); 3679 checkExternalId( t );
3679 mCalendar->deleteTodo( t ); 3680 mCalendar->deleteTodo( t );
3680 changeTodoDisplay( t,KOGlobals::EVENTDELETED ); 3681 changeTodoDisplay( t,KOGlobals::EVENTDELETED );
3681 } 3682 }
3682 else 3683 else
3683 deleteTodo = false; 3684 deleteTodo = false;
3684 } 3685 }
3685 return deleteTodo; 3686 return deleteTodo;
3686 3687
3687} 3688}
3688void CalendarView::purgeCompleted() 3689void CalendarView::purgeCompleted()
3689{ 3690{
3690 int result = KMessageBox::warningContinueCancel(this, 3691 int result = KMessageBox::warningContinueCancel(this,
3691 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge")); 3692 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge"));
3692 3693
3693 if (result == KMessageBox::Continue) { 3694 if (result == KMessageBox::Continue) {
3694 3695
3695 QPtrList<Todo> todoCal; 3696 QPtrList<Todo> todoCal;
3696 QPtrList<Todo> rootTodos; 3697 QPtrList<Todo> rootTodos;
3697 //QPtrList<Incidence> rel; 3698 //QPtrList<Incidence> rel;
3698 Todo *aTodo;//, *rTodo; 3699 Todo *aTodo;//, *rTodo;
3699 Incidence *rIncidence; 3700 Incidence *rIncidence;
3700 bool childDelete = false; 3701 bool childDelete = false;
3701 bool deletedOne = true; 3702 bool deletedOne = true;
3702 todoCal = calendar()->todos(); 3703 todoCal = calendar()->todos();
3703 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { 3704 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) {
3704 if ( !aTodo->relatedTo() ) 3705 if ( !aTodo->relatedTo() )
3705 rootTodos.append( aTodo ); 3706 rootTodos.append( aTodo );
3706 } 3707 }
3707 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { 3708 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) {
3708 removeCompletedSubTodos( aTodo ); 3709 removeCompletedSubTodos( aTodo );
3709 } 3710 }
3710 3711
3711 updateView(); 3712 updateView();
3712 } 3713 }
3713} 3714}
3714 3715
3715void CalendarView::slotCalendarChanged() 3716void CalendarView::slotCalendarChanged()
3716{ 3717{
3717 ; 3718 ;
3718} 3719}
3719 3720
3720NavigatorBar *CalendarView::navigatorBar() 3721NavigatorBar *CalendarView::navigatorBar()
3721{ 3722{
3722 return mNavigatorBar; 3723 return mNavigatorBar;
3723} 3724}
3724 3725
3725 3726
3726 3727
3727void CalendarView::keyPressEvent ( QKeyEvent *e) 3728void CalendarView::keyPressEvent ( QKeyEvent *e)
3728{ 3729{
3729 //qDebug(" alendarView::keyPressEvent "); 3730 //qDebug(" alendarView::keyPressEvent ");
3730 e->ignore(); 3731 e->ignore();
3731} 3732}
3732 3733
3733 3734
3734bool CalendarView::sync(KSyncManager* manager, QString filename, int mode) 3735bool CalendarView::sync(KSyncManager* manager, QString filename, int mode)
3735{ 3736{
3736 // mSyncManager = manager; 3737 // mSyncManager = manager;
3738 mSyncKDE = false;
3739 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) {
3740 qDebug("SyncKDE request detected!");
3741 mSyncKDE = true;
3742 }
3737 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 3743 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
3738 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 3744 mCurrentSyncName = mSyncManager->getCurrentSyncName();
3739 return syncCalendar( filename, mode ); 3745 return syncCalendar( filename, mode );
3740} 3746}
3741bool CalendarView::syncExternal(KSyncManager* manager, QString resource) 3747bool CalendarView::syncExternal(KSyncManager* manager, QString resource)
3742{ 3748{
3749 mSyncKDE = false;
3743 //mSyncManager = manager; 3750 //mSyncManager = manager;
3744 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 3751 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
3745 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 3752 mCurrentSyncName = mSyncManager->getCurrentSyncName();
3746 if ( resource == "sharp" ) 3753 if ( resource == "sharp" )
3747 syncExternal( 0 ); 3754 syncExternal( 0 );
3748 if ( resource == "phone" ) 3755 if ( resource == "phone" )
3749 syncExternal( 1 ); 3756 syncExternal( 1 );
3750 // pending setmodified 3757 // pending setmodified
3751 return true; 3758 return true;
3752} 3759}
3753void CalendarView::setSyncManager(KSyncManager* manager) 3760void CalendarView::setSyncManager(KSyncManager* manager)
3754{ 3761{
3755 mSyncManager = manager; 3762 mSyncManager = manager;
3756} 3763}
diff --git a/korganizer/calendarview.h b/korganizer/calendarview.h
index 9f56cc8..1cd896d 100644
--- a/korganizer/calendarview.h
+++ b/korganizer/calendarview.h
@@ -1,603 +1,604 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000, 2001 3 Copyright (c) 2000, 2001
4 Cornelius Schumacher <schumacher@kde.org> 4 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or 8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software 17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 19
20 As a special exception, permission is given to link this program 20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable, 21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution. 22 without including the source code for Qt in the source distribution.
23*/ 23*/
24#ifndef CALENDARVIEW_H 24#ifndef CALENDARVIEW_H
25#define CALENDARVIEW_H 25#define CALENDARVIEW_H
26 26
27#include <qframe.h> 27#include <qframe.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#include <qwidget.h> 29#include <qwidget.h>
30#include <qptrlist.h> 30#include <qptrlist.h>
31#include <qvbox.h> 31#include <qvbox.h>
32#include <qmap.h> 32#include <qmap.h>
33#ifndef DESKTOP_VERSION 33#ifndef DESKTOP_VERSION
34#include <qtopia/ir.h> 34#include <qtopia/ir.h>
35#else 35#else
36#define Ir char 36#define Ir char
37#endif 37#endif
38#include <libkcal/calendar.h> 38#include <libkcal/calendar.h>
39#include <libkcal/scheduler.h> 39#include <libkcal/scheduler.h>
40#include <libkcal/calendarresources.h> 40#include <libkcal/calendarresources.h>
41#include <libkcal/resourcecalendar.h> 41#include <libkcal/resourcecalendar.h>
42 42
43#include <korganizer/calendarviewbase.h> 43#include <korganizer/calendarviewbase.h>
44 44
45#include <ksyncmanager.h> 45#include <ksyncmanager.h>
46 46
47class QWidgetStack; 47class QWidgetStack;
48class QSplitter; 48class QSplitter;
49 49
50class CalPrinter; 50class CalPrinter;
51class KOFilterView; 51class KOFilterView;
52class KOViewManager; 52class KOViewManager;
53class KODialogManager; 53class KODialogManager;
54class KOTodoView; 54class KOTodoView;
55class KDateNavigator; 55class KDateNavigator;
56class DateNavigator; 56class DateNavigator;
57class KOIncidenceEditor; 57class KOIncidenceEditor;
58class KDatePicker; 58class KDatePicker;
59class ResourceView; 59class ResourceView;
60class NavigatorBar; 60class NavigatorBar;
61class KOEventEditor; 61class KOEventEditor;
62class KOTodoEditor ; 62class KOTodoEditor ;
63class KOEventViewerDialog; 63class KOEventViewerDialog;
64class KOBeamPrefs; 64class KOBeamPrefs;
65class KSyncProfile; 65class KSyncProfile;
66class AlarmDialog; 66class AlarmDialog;
67class KCal::Attendee; 67class KCal::Attendee;
68 68
69namespace KCal { class FileStorage; } 69namespace KCal { class FileStorage; }
70 70
71using namespace KCal; 71using namespace KCal;
72 72
73/** 73/**
74 This is the main calendar widget. It provides the different vies on t he 74 This is the main calendar widget. It provides the different vies on t he
75 calendar data as well as the date navigator. It also handles synchronisation 75 calendar data as well as the date navigator. It also handles synchronisation
76 of the different views and controls the different dialogs like preferences, 76 of the different views and controls the different dialogs like preferences,
77 event editor, search dialog etc. 77 event editor, search dialog etc.
78 78
79 @short main calendar view widget 79 @short main calendar view widget
80 @author Cornelius Schumacher 80 @author Cornelius Schumacher
81*/ 81*/
82class CalendarView : public KOrg::CalendarViewBase, public KCal::Calendar::Observer, public KSyncInterface 82class CalendarView : public KOrg::CalendarViewBase, public KCal::Calendar::Observer, public KSyncInterface
83{ 83{
84 Q_OBJECT 84 Q_OBJECT
85 public: 85 public:
86 /** 86 /**
87 Constructs a new calendar view widget. 87 Constructs a new calendar view widget.
88 88
89 @param calendar calendar document 89 @param calendar calendar document
90 @param parent parent window 90 @param parent parent window
91 @param name Qt internal widget object name 91 @param name Qt internal widget object name
92 */ 92 */
93 CalendarView( CalendarResources *calendar, QWidget *parent = 0, 93 CalendarView( CalendarResources *calendar, QWidget *parent = 0,
94 const char *name = 0 ); 94 const char *name = 0 );
95 CalendarView( Calendar *calendar, QWidget *parent = 0, 95 CalendarView( Calendar *calendar, QWidget *parent = 0,
96 const char *name = 0 ); 96 const char *name = 0 );
97 virtual ~CalendarView(); 97 virtual ~CalendarView();
98 98
99 Calendar *calendar() { return mCalendar; } 99 Calendar *calendar() { return mCalendar; }
100 100
101 KOViewManager *viewManager(); 101 KOViewManager *viewManager();
102 KODialogManager *dialogManager(); 102 KODialogManager *dialogManager();
103 103
104 QDate startDate(); 104 QDate startDate();
105 QDate endDate(); 105 QDate endDate();
106 106
107 QWidgetStack *viewStack(); 107 QWidgetStack *viewStack();
108 QWidget *leftFrame(); 108 QWidget *leftFrame();
109 NavigatorBar *navigatorBar(); 109 NavigatorBar *navigatorBar();
110 110
111 DateNavigator *dateNavigator(); 111 DateNavigator *dateNavigator();
112 KDateNavigator *dateNavigatorWidget(); 112 KDateNavigator *dateNavigatorWidget();
113 113
114 void addView(KOrg::BaseView *); 114 void addView(KOrg::BaseView *);
115 void showView(KOrg::BaseView *); 115 void showView(KOrg::BaseView *);
116 KOEventViewerDialog* getEventViewerDialog(); 116 KOEventViewerDialog* getEventViewerDialog();
117 Incidence *currentSelection(); 117 Incidence *currentSelection();
118 118
119 signals: 119 signals:
120 /** This todo has been modified */ 120 /** This todo has been modified */
121 void todoModified(Todo *, int); 121 void todoModified(Todo *, int);
122 122
123 /** when change is made to options dialog, the topwidget will catch this 123 /** when change is made to options dialog, the topwidget will catch this
124 * and emit this signal which notifies all widgets which have registered 124 * and emit this signal which notifies all widgets which have registered
125 * for notification to update their settings. */ 125 * for notification to update their settings. */
126 void configChanged(); 126 void configChanged();
127 /** emitted when the topwidget is closing down, so that any attached 127 /** emitted when the topwidget is closing down, so that any attached
128 child windows can also close. */ 128 child windows can also close. */
129 void closingDown(); 129 void closingDown();
130 /** emitted right before we die */ 130 /** emitted right before we die */
131 void closed(QWidget *); 131 void closed(QWidget *);
132 132
133 /** Emitted when state of modified flag changes */ 133 /** Emitted when state of modified flag changes */
134 void modifiedChanged(bool); 134 void modifiedChanged(bool);
135 void signalmodified(); 135 void signalmodified();
136 136
137 /** Emitted when state of read-only flag changes */ 137 /** Emitted when state of read-only flag changes */
138 void readOnlyChanged(bool); 138 void readOnlyChanged(bool);
139 139
140 /** Emitted when the unit of navigation changes */ 140 /** Emitted when the unit of navigation changes */
141 void changeNavStringPrev(const QString &); 141 void changeNavStringPrev(const QString &);
142 void changeNavStringNext(const QString &); 142 void changeNavStringNext(const QString &);
143 143
144 /** Emitted when state of events selection has changed and user is organizer*/ 144 /** Emitted when state of events selection has changed and user is organizer*/
145 void organizerEventsSelected(bool); 145 void organizerEventsSelected(bool);
146 /** Emitted when state of events selection has changed and user is attendee*/ 146 /** Emitted when state of events selection has changed and user is attendee*/
147 void groupEventsSelected(bool); 147 void groupEventsSelected(bool);
148 /** 148 /**
149 Emitted when an incidence gets selected. If the selection is cleared the 149 Emitted when an incidence gets selected. If the selection is cleared the
150 signal is emitted with 0 as argument. 150 signal is emitted with 0 as argument.
151 */ 151 */
152 void incidenceSelected( Incidence * ); 152 void incidenceSelected( Incidence * );
153 /** Emitted, when a todoitem is selected or deselected. */ 153 /** Emitted, when a todoitem is selected or deselected. */
154 void todoSelected( bool ); 154 void todoSelected( bool );
155 155
156 /** 156 /**
157 Emitted, when clipboard content changes. Parameter indicates if paste 157 Emitted, when clipboard content changes. Parameter indicates if paste
158 is possible or not. 158 is possible or not.
159 */ 159 */
160 void pasteEnabled(bool); 160 void pasteEnabled(bool);
161 161
162 /** Emitted, when the number of incoming messages has changed. */ 162 /** Emitted, when the number of incoming messages has changed. */
163 void numIncomingChanged(int); 163 void numIncomingChanged(int);
164 164
165 /** Emitted, when the number of outgoing messages has changed. */ 165 /** Emitted, when the number of outgoing messages has changed. */
166 void numOutgoingChanged(int); 166 void numOutgoingChanged(int);
167 167
168 /** Send status message, which can e.g. be displayed in the status bar. */ 168 /** Send status message, which can e.g. be displayed in the status bar. */
169 void statusMessage(const QString &); 169 void statusMessage(const QString &);
170 170
171 void calendarViewExpanded( bool ); 171 void calendarViewExpanded( bool );
172 void updateSearchDialog(); 172 void updateSearchDialog();
173 173
174 174
175 public slots: 175 public slots:
176 void showOpenError(); 176 void showOpenError();
177 void watchSavedFile(); 177 void watchSavedFile();
178 void recheckTimerAlarm(); 178 void recheckTimerAlarm();
179 void checkNextTimerAlarm(); 179 void checkNextTimerAlarm();
180 void addAlarm(const QDateTime &qdt, const QString &noti ); 180 void addAlarm(const QDateTime &qdt, const QString &noti );
181 void addSuspendAlarm(const QDateTime &qdt, const QString &noti ); 181 void addSuspendAlarm(const QDateTime &qdt, const QString &noti );
182 void removeAlarm(const QDateTime &qdt, const QString &noti ); 182 void removeAlarm(const QDateTime &qdt, const QString &noti );
183 183
184 /** options dialog made a changed to the configuration. we catch this 184 /** options dialog made a changed to the configuration. we catch this
185 * and notify all widgets which need to update their configuration. */ 185 * and notify all widgets which need to update their configuration. */
186 void updateConfig(); 186 void updateConfig();
187 187
188 void insertBirthdays(const QString& uid, const QStringList& birthdayList, 188 void insertBirthdays(const QString& uid, const QStringList& birthdayList,
189 const QStringList& anniversaryList, const QStringList& realNameList, 189 const QStringList& anniversaryList, const QStringList& realNameList,
190 const QStringList& emailList, const QStringList& assembledNameList, 190 const QStringList& emailList, const QStringList& assembledNameList,
191 const QStringList& uidList); 191 const QStringList& uidList);
192 192
193 /** 193 /**
194 Load calendar from file \a filename. If \a merge is true, load 194 Load calendar from file \a filename. If \a merge is true, load
195 calendar into existing one, if it is false, clear calendar, before 195 calendar into existing one, if it is false, clear calendar, before
196 loading. Return true, if calendar could be successfully loaded. 196 loading. Return true, if calendar could be successfully loaded.
197 */ 197 */
198 bool openCalendar(QString filename, bool merge=false); 198 bool openCalendar(QString filename, bool merge=false);
199 bool syncCalendar(QString filename,int mode = 0 ); 199 bool syncCalendar(QString filename,int mode = 0 );
200 200
201 /** 201 /**
202 Save calendar data to file. Return true if calendar could be 202 Save calendar data to file. Return true if calendar could be
203 successfully saved. 203 successfully saved.
204 */ 204 */
205 bool saveCalendar(QString filename); 205 bool saveCalendar(QString filename);
206 206
207 /** 207 /**
208 Close calendar. Clear calendar data and reset views to display an empty 208 Close calendar. Clear calendar data and reset views to display an empty
209 calendar. 209 calendar.
210 */ 210 */
211 void closeCalendar(); 211 void closeCalendar();
212 212
213 /** Archive old events of calendar */ 213 /** Archive old events of calendar */
214 void archiveCalendar(); 214 void archiveCalendar();
215 215
216 void showIncidence(); 216 void showIncidence();
217 void editIncidence(); 217 void editIncidence();
218 void editIncidenceDescription(); 218 void editIncidenceDescription();
219 void deleteIncidence(); 219 void deleteIncidence();
220 void cloneIncidence(); 220 void cloneIncidence();
221 void moveIncidence(); 221 void moveIncidence();
222 void beamIncidence(); 222 void beamIncidence();
223 void toggleCancelIncidence(); 223 void toggleCancelIncidence();
224 224
225 /** create an editeventwin with supplied date/time, and if bool is true, 225 /** create an editeventwin with supplied date/time, and if bool is true,
226 * make the event take all day. */ 226 * make the event take all day. */
227 void newEvent(QDateTime, QDateTime, bool allDay = false); 227 void newEvent(QDateTime, QDateTime, bool allDay = false);
228 void newEvent(QDateTime fh); 228 void newEvent(QDateTime fh);
229 void newEvent(QDate dt); 229 void newEvent(QDate dt);
230 /** create new event without having a date hint. Takes current date as 230 /** create new event without having a date hint. Takes current date as
231 default hint. */ 231 default hint. */
232 void newEvent(); 232 void newEvent();
233 void newFloatingEvent(); 233 void newFloatingEvent();
234 234
235 /** Create a read-only viewer dialog for the supplied incidence. It calls the correct showXXX method*/ 235 /** Create a read-only viewer dialog for the supplied incidence. It calls the correct showXXX method*/
236 void showIncidence(Incidence *); 236 void showIncidence(Incidence *);
237 /** Create an editor for the supplied incidence. It calls the correct editXXX method*/ 237 /** Create an editor for the supplied incidence. It calls the correct editXXX method*/
238 void editIncidence(Incidence *); 238 void editIncidence(Incidence *);
239 /** Delete the supplied incidence. It calls the correct deleteXXX method*/ 239 /** Delete the supplied incidence. It calls the correct deleteXXX method*/
240 void deleteIncidence(Incidence *); 240 void deleteIncidence(Incidence *);
241 void cloneIncidence(Incidence *); 241 void cloneIncidence(Incidence *);
242 void cancelIncidence(Incidence *); 242 void cancelIncidence(Incidence *);
243 /** Create an editor for the supplied event. */ 243 /** Create an editor for the supplied event. */
244 void editEvent(Event *); 244 void editEvent(Event *);
245 /** Delete the supplied event. */ 245 /** Delete the supplied event. */
246 void deleteEvent(Event *); 246 void deleteEvent(Event *);
247 /** Delete the event with the given unique ID. Returns false, if event wasn't 247 /** Delete the event with the given unique ID. Returns false, if event wasn't
248 found. */ 248 found. */
249 bool deleteEvent(const QString &uid); 249 bool deleteEvent(const QString &uid);
250 /** Create a read-only viewer dialog for the supplied event. */ 250 /** Create a read-only viewer dialog for the supplied event. */
251 void showEvent(Event *); 251 void showEvent(Event *);
252 252
253 void editJournal(Journal *); 253 void editJournal(Journal *);
254 void showJournal(Journal *); 254 void showJournal(Journal *);
255 void deleteJournal(Journal *); 255 void deleteJournal(Journal *);
256 /** Create an editor dialog for a todo */ 256 /** Create an editor dialog for a todo */
257 void editTodo(Todo *); 257 void editTodo(Todo *);
258 /** Create a read-only viewer dialog for the supplied todo */ 258 /** Create a read-only viewer dialog for the supplied todo */
259 void showTodo(Todo *); 259 void showTodo(Todo *);
260 /** create new todo */ 260 /** create new todo */
261 void newTodo(); 261 void newTodo();
262 /** create new todo with a parent todo */ 262 /** create new todo with a parent todo */
263 void newSubTodo(); 263 void newSubTodo();
264 /** create new todo with a parent todo */ 264 /** create new todo with a parent todo */
265 void newSubTodo(Todo *); 265 void newSubTodo(Todo *);
266 /** Delete todo */ 266 /** Delete todo */
267 void deleteTodo(Todo *); 267 void deleteTodo(Todo *);
268 268
269 269
270 /** Check if clipboard contains vCalendar event. The signal pasteEnabled() is 270 /** Check if clipboard contains vCalendar event. The signal pasteEnabled() is
271 * emitted as result. */ 271 * emitted as result. */
272 void checkClipboard(); 272 void checkClipboard();
273 273
274 /** using the KConfig associated with the kapp variable, read in the 274 /** using the KConfig associated with the kapp variable, read in the
275 * settings from the config file. 275 * settings from the config file.
276 */ 276 */
277 void readSettings(); 277 void readSettings();
278 278
279 /** write current state to config file. */ 279 /** write current state to config file. */
280 void writeSettings(); 280 void writeSettings();
281 281
282 /** read settings for calendar filters */ 282 /** read settings for calendar filters */
283 void readFilterSettings(KConfig *config); 283 void readFilterSettings(KConfig *config);
284 284
285 /** write settings for calendar filters */ 285 /** write settings for calendar filters */
286 void writeFilterSettings(KConfig *config); 286 void writeFilterSettings(KConfig *config);
287 287
288 /** passes on the message that an event has changed to the currently 288 /** passes on the message that an event has changed to the currently
289 * activated view so that it can make appropriate display changes. */ 289 * activated view so that it can make appropriate display changes. */
290 void changeEventDisplay(Event *, int); 290 void changeEventDisplay(Event *, int);
291 void changeIncidenceDisplay(Incidence *, int); 291 void changeIncidenceDisplay(Incidence *, int);
292 void changeTodoDisplay(Todo *, int); 292 void changeTodoDisplay(Todo *, int);
293 293
294 void eventAdded(Event *); 294 void eventAdded(Event *);
295 void eventChanged(Event *); 295 void eventChanged(Event *);
296 void eventToBeDeleted(Event *); 296 void eventToBeDeleted(Event *);
297 void eventDeleted(); 297 void eventDeleted();
298 298
299 void todoAdded(Todo *); 299 void todoAdded(Todo *);
300 void todoChanged(Todo *); 300 void todoChanged(Todo *);
301 void todoToBeDeleted(Todo *); 301 void todoToBeDeleted(Todo *);
302 void todoDeleted(); 302 void todoDeleted();
303 303
304 void updateView(const QDate &start, const QDate &end); 304 void updateView(const QDate &start, const QDate &end);
305 void updateView(); 305 void updateView();
306 306
307 /** Full update of visible todo views */ 307 /** Full update of visible todo views */
308 void updateTodoViews(); 308 void updateTodoViews();
309 309
310 void updateUnmanagedViews(); 310 void updateUnmanagedViews();
311 311
312 /** cut the current appointment to the clipboard */ 312 /** cut the current appointment to the clipboard */
313 void edit_cut(); 313 void edit_cut();
314 314
315 /** copy the current appointment(s) to the clipboard */ 315 /** copy the current appointment(s) to the clipboard */
316 void edit_copy(); 316 void edit_copy();
317 317
318 /** paste the current vobject(s) in the clipboard buffer into calendar */ 318 /** paste the current vobject(s) in the clipboard buffer into calendar */
319 void edit_paste(); 319 void edit_paste();
320 320
321 /** edit viewing and configuration options. */ 321 /** edit viewing and configuration options. */
322 void edit_options(); 322 void edit_options();
323 /** 323 /**
324 Functions for printing, previewing a print, and setting up printing 324 Functions for printing, previewing a print, and setting up printing
325 parameters. 325 parameters.
326 */ 326 */
327 void print(); 327 void print();
328 void printSetup(); 328 void printSetup();
329 void printPreview(); 329 void printPreview();
330 330
331 /** Export as iCalendar file */ 331 /** Export as iCalendar file */
332 void exportICalendar(); 332 void exportICalendar();
333 333
334 /** Export as vCalendar file */ 334 /** Export as vCalendar file */
335 bool exportVCalendar( QString fn); 335 bool exportVCalendar( QString fn);
336 336
337 /** pop up a dialog to show an existing appointment. */ 337 /** pop up a dialog to show an existing appointment. */
338 void appointment_show(); 338 void appointment_show();
339 /** 339 /**
340 * pop up an Appointment Dialog to edit an existing appointment.Get 340 * pop up an Appointment Dialog to edit an existing appointment.Get
341 * information on the appointment from the list of unique IDs that is 341 * information on the appointment from the list of unique IDs that is
342 * currently in the View, called currIds. 342 * currently in the View, called currIds.
343 */ 343 */
344 void appointment_edit(); 344 void appointment_edit();
345 /** 345 /**
346 * pop up dialog confirming deletion of currently selected event in the 346 * pop up dialog confirming deletion of currently selected event in the
347 * View. 347 * View.
348 */ 348 */
349 void appointment_delete(); 349 void appointment_delete();
350 350
351 /** mails the currently selected event to a particular user as a vCalendar 351 /** mails the currently selected event to a particular user as a vCalendar
352 attachment. */ 352 attachment. */
353 void action_mail(); 353 void action_mail();
354 354
355 /* frees a subtodo from it's relation */ 355 /* frees a subtodo from it's relation */
356 void todo_unsub( Todo * ); 356 void todo_unsub( Todo * );
357 void todo_resub( Todo * parent, Todo * sub ); 357 void todo_resub( Todo * parent, Todo * sub );
358 358
359 /** Take ownership of selected event. */ 359 /** Take ownership of selected event. */
360 void takeOverEvent(); 360 void takeOverEvent();
361 361
362 /** Take ownership of all events in calendar. */ 362 /** Take ownership of all events in calendar. */
363 void takeOverCalendar(); 363 void takeOverCalendar();
364 364
365 /** query whether or not the calendar is "dirty". */ 365 /** query whether or not the calendar is "dirty". */
366 bool isModified(); 366 bool isModified();
367 /** set the state of calendar. Modified means "dirty", i.e. needing a save. */ 367 /** set the state of calendar. Modified means "dirty", i.e. needing a save. */
368 void setModified(bool modified=true); 368 void setModified(bool modified=true);
369 369
370 /** query if the calendar is read-only. */ 370 /** query if the calendar is read-only. */
371 bool isReadOnly(); 371 bool isReadOnly();
372 /** set state of calendar to read-only */ 372 /** set state of calendar to read-only */
373 void setReadOnly(bool readOnly=true); 373 void setReadOnly(bool readOnly=true);
374 374
375 void eventUpdated(Incidence *); 375 void eventUpdated(Incidence *);
376 376
377 /* iTIP scheduling actions */ 377 /* iTIP scheduling actions */
378 void schedule_publish(Incidence *incidence = 0); 378 void schedule_publish(Incidence *incidence = 0);
379 void schedule_request(Incidence *incidence = 0); 379 void schedule_request(Incidence *incidence = 0);
380 void schedule_refresh(Incidence *incidence = 0); 380 void schedule_refresh(Incidence *incidence = 0);
381 void schedule_cancel(Incidence *incidence = 0); 381 void schedule_cancel(Incidence *incidence = 0);
382 void schedule_add(Incidence *incidence = 0); 382 void schedule_add(Incidence *incidence = 0);
383 void schedule_reply(Incidence *incidence = 0); 383 void schedule_reply(Incidence *incidence = 0);
384 void schedule_counter(Incidence *incidence = 0); 384 void schedule_counter(Incidence *incidence = 0);
385 void schedule_declinecounter(Incidence *incidence = 0); 385 void schedule_declinecounter(Incidence *incidence = 0);
386 void schedule_publish_freebusy(int daysToPublish = 30); 386 void schedule_publish_freebusy(int daysToPublish = 30);
387 387
388 void openAddressbook(); 388 void openAddressbook();
389 389
390 void editFilters(); 390 void editFilters();
391 void toggleFilerEnabled(); 391 void toggleFilerEnabled();
392 QPtrList<CalFilter> filters(); 392 QPtrList<CalFilter> filters();
393 void toggleFilter(); 393 void toggleFilter();
394 void showFilter(bool visible); 394 void showFilter(bool visible);
395 void updateFilter(); 395 void updateFilter();
396 void filterEdited(); 396 void filterEdited();
397 void selectFilter( int ); 397 void selectFilter( int );
398 KOFilterView *filterView(); 398 KOFilterView *filterView();
399 399
400 void showIntro(); 400 void showIntro();
401 401
402 /** Move the curdatepient view date to today */ 402 /** Move the curdatepient view date to today */
403 void goToday(); 403 void goToday();
404 404
405 /** Move to the next date(s) in the current view */ 405 /** Move to the next date(s) in the current view */
406 void goNext(); 406 void goNext();
407 407
408 /** Move to the previous date(s) in the current view */ 408 /** Move to the previous date(s) in the current view */
409 void goPrevious(); 409 void goPrevious();
410 /** Move to the next date(s) in the current view */ 410 /** Move to the next date(s) in the current view */
411 void goNextMonth(); 411 void goNextMonth();
412 412
413 /** Move to the previous date(s) in the current view */ 413 /** Move to the previous date(s) in the current view */
414 void goPreviousMonth(); 414 void goPreviousMonth();
415 415
416 void toggleExpand(); 416 void toggleExpand();
417 void toggleDateNavigatorWidget(); 417 void toggleDateNavigatorWidget();
418 void toggleAllDaySize(); 418 void toggleAllDaySize();
419 void dialogClosing(Incidence *); 419 void dialogClosing(Incidence *);
420 420
421 /** Look for new messages in the inbox */ 421 /** Look for new messages in the inbox */
422 void lookForIncomingMessages(); 422 void lookForIncomingMessages();
423 /** Look for new messages in the outbox */ 423 /** Look for new messages in the outbox */
424 void lookForOutgoingMessages(); 424 void lookForOutgoingMessages();
425 425
426 void processMainViewSelection( Incidence * ); 426 void processMainViewSelection( Incidence * );
427 void processTodoListSelection( Incidence * ); 427 void processTodoListSelection( Incidence * );
428 428
429 void processIncidenceSelection( Incidence * ); 429 void processIncidenceSelection( Incidence * );
430 430
431 void purgeCompleted(); 431 void purgeCompleted();
432 bool removeCompletedSubTodos( Todo* ); 432 bool removeCompletedSubTodos( Todo* );
433 void slotCalendarChanged(); 433 void slotCalendarChanged();
434 bool importBday(); 434 bool importBday();
435 bool addAnniversary( QDate data, QString name, KCal::Attendee* a , bool birthday ); 435 bool addAnniversary( QDate data, QString name, KCal::Attendee* a , bool birthday );
436 bool importQtopia( const QString &categoriesFile, 436 bool importQtopia( const QString &categoriesFile,
437 const QString &datebookFile, 437 const QString &datebookFile,
438 const QString &tasklistFile ); 438 const QString &tasklistFile );
439 void syncExternal( int mode ); 439 void syncExternal( int mode );
440 void slotSelectPickerDate( QDate ) ; 440 void slotSelectPickerDate( QDate ) ;
441 void showDatePicker( ) ; 441 void showDatePicker( ) ;
442 void moveIncidence(Incidence *) ; 442 void moveIncidence(Incidence *) ;
443 void beamIncidence(Incidence *) ; 443 void beamIncidence(Incidence *) ;
444 void beamCalendar() ; 444 void beamCalendar() ;
445 void beamFilteredCalendar() ; 445 void beamFilteredCalendar() ;
446 void beamIncidenceList(QPtrList<Incidence>) ; 446 void beamIncidenceList(QPtrList<Incidence>) ;
447 void manageCategories(); 447 void manageCategories();
448 int addCategories(); 448 int addCategories();
449 void removeCategories(); 449 void removeCategories();
450 void setSyncDevice( QString ); 450 void setSyncDevice( QString );
451 void setSyncName( QString ); 451 void setSyncName( QString );
452 protected slots: 452 protected slots:
453 void timerAlarm(); 453 void timerAlarm();
454 void suspendAlarm(); 454 void suspendAlarm();
455 void beamDone( Ir *ir ); 455 void beamDone( Ir *ir );
456 /** Select a view or adapt the current view to display the specified dates. */ 456 /** Select a view or adapt the current view to display the specified dates. */
457 void showDates( const KCal::DateList & ); 457 void showDates( const KCal::DateList & );
458 void selectWeekNum ( int ); 458 void selectWeekNum ( int );
459 459
460 public: 460 public:
461 // show a standard warning 461 // show a standard warning
462 // returns KMsgBox::yesNoCancel() 462 // returns KMsgBox::yesNoCancel()
463 int msgCalModified(); 463 int msgCalModified();
464 virtual bool sync(KSyncManager* manager, QString filename, int mode); 464 virtual bool sync(KSyncManager* manager, QString filename, int mode);
465 465
466 virtual bool syncExternal(KSyncManager* manager, QString resource); 466 virtual bool syncExternal(KSyncManager* manager, QString resource);
467 void setSyncManager(KSyncManager* manager); 467 void setSyncManager(KSyncManager* manager);
468 void setLoadedFileVersion(QDateTime); 468 void setLoadedFileVersion(QDateTime);
469 bool checkFileVersion(QString fn); 469 bool checkFileVersion(QString fn);
470 bool checkFileChanged(QString fn); 470 bool checkFileChanged(QString fn);
471 Event* getLastSyncEvent(); 471 Event* getLastSyncEvent();
472 /** Adapt navigation units correpsonding to step size of navigation of the 472 /** Adapt navigation units correpsonding to step size of navigation of the
473 * current view. 473 * current view.
474 */ 474 */
475 void adaptNavigationUnits(); 475 void adaptNavigationUnits();
476 bool synchronizeCalendar( Calendar* local, Calendar* remote, int mode ); 476 bool synchronizeCalendar( Calendar* local, Calendar* remote, int mode );
477 int takeEvent( Incidence* local, Incidence* remote, int mode, bool full = false ); 477 int takeEvent( Incidence* local, Incidence* remote, int mode, bool full = false );
478 //Attendee* getYourAttendee(Event *event); 478 //Attendee* getYourAttendee(Event *event);
479 protected: 479 protected:
480 void schedule(Scheduler::Method, Incidence *incidence = 0); 480 void schedule(Scheduler::Method, Incidence *incidence = 0);
481 481
482 // returns KMsgBox::OKCandel() 482 // returns KMsgBox::OKCandel()
483 int msgItemDelete(); 483 int msgItemDelete();
484 void showEventEditor(); 484 void showEventEditor();
485 void showTodoEditor(); 485 void showTodoEditor();
486 void writeLocale(); 486 void writeLocale();
487 Todo *selectedTodo(); 487 Todo *selectedTodo();
488 488
489 private: 489 private:
490 bool mSyncKDE;
490 KSyncManager* mSyncManager; 491 KSyncManager* mSyncManager;
491 AlarmDialog * mAlarmDialog; 492 AlarmDialog * mAlarmDialog;
492 QString mAlarmNotification; 493 QString mAlarmNotification;
493 QString mSuspendAlarmNotification; 494 QString mSuspendAlarmNotification;
494 QTimer* mSuspendTimer; 495 QTimer* mSuspendTimer;
495 QTimer* mAlarmTimer; 496 QTimer* mAlarmTimer;
496 QTimer* mRecheckAlarmTimer; 497 QTimer* mRecheckAlarmTimer;
497 void computeAlarm( QString ); 498 void computeAlarm( QString );
498 void startAlarm( QString, QString ); 499 void startAlarm( QString, QString );
499 void setSyncEventsReadOnly(); 500 void setSyncEventsReadOnly();
500 501
501 QDateTime loadedFileVersion; 502 QDateTime loadedFileVersion;
502 void checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ); 503 void checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete );
503 void checkExternalId( Incidence * inc ); 504 void checkExternalId( Incidence * inc );
504 int mGlobalSyncMode; 505 int mGlobalSyncMode;
505 QString mCurrentSyncDevice; 506 QString mCurrentSyncDevice;
506 QString mCurrentSyncName; 507 QString mCurrentSyncName;
507 KOBeamPrefs* beamDialog; 508 KOBeamPrefs* beamDialog;
508 void init(); 509 void init();
509 int mDatePickerMode; 510 int mDatePickerMode;
510 bool mFlagEditDescription; 511 bool mFlagEditDescription;
511 QDateTime mLastCalendarSync; 512 QDateTime mLastCalendarSync;
512 void createPrinter(); 513 void createPrinter();
513 514
514 void calendarModified( bool, Calendar * ); 515 void calendarModified( bool, Calendar * );
515 516
516 CalPrinter *mCalPrinter; 517 CalPrinter *mCalPrinter;
517 518
518 QSplitter *mPanner; 519 QSplitter *mPanner;
519 QSplitter *mLeftSplitter; 520 QSplitter *mLeftSplitter;
520 QWidget *mLeftFrame; 521 QWidget *mLeftFrame;
521 QWidgetStack *mRightFrame; 522 QWidgetStack *mRightFrame;
522 523
523 KDatePicker* mDatePicker; 524 KDatePicker* mDatePicker;
524 QVBox* mDateFrame; 525 QVBox* mDateFrame;
525 NavigatorBar *mNavigatorBar; 526 NavigatorBar *mNavigatorBar;
526 527
527 KDateNavigator *mDateNavigator; // widget showing small month view. 528 KDateNavigator *mDateNavigator; // widget showing small month view.
528 529
529 KOFilterView *mFilterView; 530 KOFilterView *mFilterView;
530 531
531 ResourceView *mResourceView; 532 ResourceView *mResourceView;
532 533
533 // calendar object for this viewing instance 534 // calendar object for this viewing instance
534 Calendar *mCalendar; 535 Calendar *mCalendar;
535 536
536 CalendarResourceManager *mResourceManager; 537 CalendarResourceManager *mResourceManager;
537 538
538 FileStorage *mStorage; 539 FileStorage *mStorage;
539 540
540 DateNavigator *mNavigator; 541 DateNavigator *mNavigator;
541 542
542 KOViewManager *mViewManager; 543 KOViewManager *mViewManager;
543 KODialogManager *mDialogManager; 544 KODialogManager *mDialogManager;
544 545
545 // Calendar filters 546 // Calendar filters
546 QPtrList<CalFilter> mFilters; 547 QPtrList<CalFilter> mFilters;
547 548
548 // various housekeeping variables. 549 // various housekeeping variables.
549 bool mModified; // flag indicating if calendar is modified 550 bool mModified; // flag indicating if calendar is modified
550 bool mReadOnly; // flag indicating if calendar is read-only 551 bool mReadOnly; // flag indicating if calendar is read-only
551 QDate mSaveSingleDate; 552 QDate mSaveSingleDate;
552 553
553 Incidence *mSelectedIncidence; 554 Incidence *mSelectedIncidence;
554 Incidence *mMoveIncidence; 555 Incidence *mMoveIncidence;
555 KOTodoView *mTodoList; 556 KOTodoView *mTodoList;
556 KOEventEditor * mEventEditor; 557 KOEventEditor * mEventEditor;
557 KOTodoEditor * mTodoEditor; 558 KOTodoEditor * mTodoEditor;
558 KOEventViewerDialog * mEventViewerDialog; 559 KOEventViewerDialog * mEventViewerDialog;
559 void keyPressEvent ( QKeyEvent *e) ; 560 void keyPressEvent ( QKeyEvent *e) ;
560 //QMap<Incidence*,KOIncidenceEditor*> mDialogList; 561 //QMap<Incidence*,KOIncidenceEditor*> mDialogList;
561}; 562};
562 563
563 564
564class CalendarViewVisitor : public Incidence::Visitor 565class CalendarViewVisitor : public Incidence::Visitor
565{ 566{
566 public: 567 public:
567 CalendarViewVisitor() : mView( 0 ) {} 568 CalendarViewVisitor() : mView( 0 ) {}
568 569
569 bool act( Incidence *incidence, CalendarView *view ) 570 bool act( Incidence *incidence, CalendarView *view )
570 { 571 {
571 mView = view; 572 mView = view;
572 return incidence->accept( *this ); 573 return incidence->accept( *this );
573 } 574 }
574 575
575 protected: 576 protected:
576 CalendarView *mView; 577 CalendarView *mView;
577}; 578};
578 579
579class ShowIncidenceVisitor : public CalendarViewVisitor 580class ShowIncidenceVisitor : public CalendarViewVisitor
580{ 581{
581 protected: 582 protected:
582 bool visit( Event *event ) { mView->showEvent( event ); return true; } 583 bool visit( Event *event ) { mView->showEvent( event ); return true; }
583 bool visit( Todo *todo ) { mView->showTodo( todo ); return true; } 584 bool visit( Todo *todo ) { mView->showTodo( todo ); return true; }
584 bool visit( Journal * j ) { mView->showJournal( j );return true; } 585 bool visit( Journal * j ) { mView->showJournal( j );return true; }
585}; 586};
586 587
587class EditIncidenceVisitor : public CalendarViewVisitor 588class EditIncidenceVisitor : public CalendarViewVisitor
588{ 589{
589 protected: 590 protected:
590 bool visit( Event *event ) { mView->editEvent( event ); return true; } 591 bool visit( Event *event ) { mView->editEvent( event ); return true; }
591 bool visit( Todo *todo ) { mView->editTodo( todo ); return true; } 592 bool visit( Todo *todo ) { mView->editTodo( todo ); return true; }
592 bool visit( Journal *j ) { mView->editJournal( j); return true; } 593 bool visit( Journal *j ) { mView->editJournal( j); return true; }
593}; 594};
594 595
595class DeleteIncidenceVisitor : public CalendarViewVisitor 596class DeleteIncidenceVisitor : public CalendarViewVisitor
596{ 597{
597 protected: 598 protected:
598 bool visit( Event *event ) { mView->deleteEvent( event ); return true; } 599 bool visit( Event *event ) { mView->deleteEvent( event ); return true; }
599 bool visit( Todo *todo ) { mView->deleteTodo( todo ); return true; } 600 bool visit( Todo *todo ) { mView->deleteTodo( todo ); return true; }
600 bool visit( Journal * j) {mView->deleteJournal( j ); return true; } 601 bool visit( Journal * j) {mView->deleteJournal( j ); return true; }
601}; 602};
602 603
603#endif 604#endif
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index eeb5f48..52daaaa 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -1,457 +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 251
252void Calendar::resetPilotStat() 252void Calendar::resetPilotStat(int id )
253{ 253{
254 QPtrList<Incidence> incidences; 254 QPtrList<Incidence> incidences;
255 255
256 Incidence *i; 256 Incidence *i;
257 257
258 QPtrList<Event> e = rawEvents(); 258 QPtrList<Event> e = rawEvents();
259 for( i = e.first(); i; i = e.next() ) i->setPilotId( 0 ); 259 for( i = e.first(); i; i = e.next() ) i->setPilotId( id );
260 260
261 QPtrList<Todo> t = rawTodos(); 261 QPtrList<Todo> t = rawTodos();
262 for( i = t.first(); i; i = t.next() ) i->setPilotId( 0 ); 262 for( i = t.first(); i; i = t.next() ) i->setPilotId( id );
263 263
264 QPtrList<Journal> j = journals(); 264 QPtrList<Journal> j = journals();
265 for( i = j.first(); i; i = j.next() ) i->setPilotId( 0 ); 265 for( i = j.first(); i; i = j.next() ) i->setPilotId( id );
266} 266}
267void Calendar::resetTempSyncStat() 267void Calendar::resetTempSyncStat()
268{ 268{
269 QPtrList<Incidence> incidences; 269 QPtrList<Incidence> incidences;
270 270
271 Incidence *i; 271 Incidence *i;
272 272
273 QPtrList<Event> e = rawEvents(); 273 QPtrList<Event> e = rawEvents();
274 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 );
275 275
276 QPtrList<Todo> t = rawTodos(); 276 QPtrList<Todo> t = rawTodos();
277 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 );
278 278
279 QPtrList<Journal> j = journals(); 279 QPtrList<Journal> j = journals();
280 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 );
281} 281}
282QPtrList<Incidence> Calendar::rawIncidences() 282QPtrList<Incidence> Calendar::rawIncidences()
283{ 283{
284 QPtrList<Incidence> incidences; 284 QPtrList<Incidence> incidences;
285 285
286 Incidence *i; 286 Incidence *i;
287 287
288 QPtrList<Event> e = rawEvents(); 288 QPtrList<Event> e = rawEvents();
289 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 289 for( i = e.first(); i; i = e.next() ) incidences.append( i );
290 290
291 QPtrList<Todo> t = rawTodos(); 291 QPtrList<Todo> t = rawTodos();
292 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 292 for( i = t.first(); i; i = t.next() ) incidences.append( i );
293 293
294 QPtrList<Journal> j = journals(); 294 QPtrList<Journal> j = journals();
295 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 295 for( i = j.first(); i; i = j.next() ) incidences.append( i );
296 296
297 return incidences; 297 return incidences;
298} 298}
299 299
300QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) 300QPtrList<Event> Calendar::events( const QDate &date, bool sorted )
301{ 301{
302 QPtrList<Event> el = rawEventsForDate(date,sorted); 302 QPtrList<Event> el = rawEventsForDate(date,sorted);
303 mFilter->apply(&el); 303 mFilter->apply(&el);
304 return el; 304 return el;
305} 305}
306 306
307QPtrList<Event> Calendar::events( const QDateTime &qdt ) 307QPtrList<Event> Calendar::events( const QDateTime &qdt )
308{ 308{
309 QPtrList<Event> el = rawEventsForDate(qdt); 309 QPtrList<Event> el = rawEventsForDate(qdt);
310 mFilter->apply(&el); 310 mFilter->apply(&el);
311 return el; 311 return el;
312} 312}
313 313
314QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, 314QPtrList<Event> Calendar::events( const QDate &start, const QDate &end,
315 bool inclusive) 315 bool inclusive)
316{ 316{
317 QPtrList<Event> el = rawEvents(start,end,inclusive); 317 QPtrList<Event> el = rawEvents(start,end,inclusive);
318 mFilter->apply(&el); 318 mFilter->apply(&el);
319 return el; 319 return el;
320} 320}
321 321
322QPtrList<Event> Calendar::events() 322QPtrList<Event> Calendar::events()
323{ 323{
324 QPtrList<Event> el = rawEvents(); 324 QPtrList<Event> el = rawEvents();
325 mFilter->apply(&el); 325 mFilter->apply(&el);
326 return el; 326 return el;
327} 327}
328 328
329 329
330bool Calendar::addIncidence(Incidence *i) 330bool Calendar::addIncidence(Incidence *i)
331{ 331{
332 Incidence::AddVisitor<Calendar> v(this); 332 Incidence::AddVisitor<Calendar> v(this);
333 333
334 return i->accept(v); 334 return i->accept(v);
335} 335}
336void Calendar::deleteIncidence(Incidence *in) 336void Calendar::deleteIncidence(Incidence *in)
337{ 337{
338 if ( in->type() == "Event" ) 338 if ( in->type() == "Event" )
339 deleteEvent( (Event*) in ); 339 deleteEvent( (Event*) in );
340 else if ( in->type() =="Todo" ) 340 else if ( in->type() =="Todo" )
341 deleteTodo( (Todo*) in); 341 deleteTodo( (Todo*) in);
342 else if ( in->type() =="Journal" ) 342 else if ( in->type() =="Journal" )
343 deleteJournal( (Journal*) in ); 343 deleteJournal( (Journal*) in );
344} 344}
345 345
346Incidence* Calendar::incidence( const QString& uid ) 346Incidence* Calendar::incidence( const QString& uid )
347{ 347{
348 Incidence* i; 348 Incidence* i;
349 349
350 if( (i = todo( uid )) != 0 ) 350 if( (i = todo( uid )) != 0 )
351 return i; 351 return i;
352 if( (i = event( uid )) != 0 ) 352 if( (i = event( uid )) != 0 )
353 return i; 353 return i;
354 if( (i = journal( uid )) != 0 ) 354 if( (i = journal( uid )) != 0 )
355 return i; 355 return i;
356 356
357 return 0; 357 return 0;
358} 358}
359 359
360QPtrList<Todo> Calendar::todos() 360QPtrList<Todo> Calendar::todos()
361{ 361{
362 QPtrList<Todo> tl = rawTodos(); 362 QPtrList<Todo> tl = rawTodos();
363 mFilter->apply( &tl ); 363 mFilter->apply( &tl );
364 return tl; 364 return tl;
365} 365}
366 366
367// 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.
368// This method is only about linking related todos 368// This method is only about linking related todos
369void Calendar::setupRelations( Incidence *incidence ) 369void Calendar::setupRelations( Incidence *incidence )
370{ 370{
371 QString uid = incidence->uid(); 371 QString uid = incidence->uid();
372 //qDebug("Calendar::setupRelations "); 372 //qDebug("Calendar::setupRelations ");
373 // 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
374 while( Incidence* i = mOrphans[ uid ] ) { 374 while( Incidence* i = mOrphans[ uid ] ) {
375 mOrphans.remove( uid ); 375 mOrphans.remove( uid );
376 i->setRelatedTo( incidence ); 376 i->setRelatedTo( incidence );
377 incidence->addRelation( i ); 377 incidence->addRelation( i );
378 mOrphanUids.remove( i->uid() ); 378 mOrphanUids.remove( i->uid() );
379 } 379 }
380 380
381 // Now see about this incidences parent 381 // Now see about this incidences parent
382 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { 382 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) {
383 // 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
384 // Try to find it 384 // Try to find it
385 Incidence* parent = this->incidence( incidence->relatedToUid() ); 385 Incidence* parent = this->incidence( incidence->relatedToUid() );
386 if( parent ) { 386 if( parent ) {
387 // Found it 387 // Found it
388 incidence->setRelatedTo( parent ); 388 incidence->setRelatedTo( parent );
389 parent->addRelation( incidence ); 389 parent->addRelation( incidence );
390 } else { 390 } else {
391 // Not found, put this in the mOrphans list 391 // Not found, put this in the mOrphans list
392 mOrphans.insert( incidence->relatedToUid(), incidence ); 392 mOrphans.insert( incidence->relatedToUid(), incidence );
393 mOrphanUids.insert( incidence->uid(), incidence ); 393 mOrphanUids.insert( incidence->uid(), incidence );
394 } 394 }
395 } 395 }
396} 396}
397 397
398// 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
399void Calendar::removeRelations( Incidence *incidence ) 399void Calendar::removeRelations( Incidence *incidence )
400{ 400{
401 // qDebug("Calendar::removeRelations "); 401 // qDebug("Calendar::removeRelations ");
402 QString uid = incidence->uid(); 402 QString uid = incidence->uid();
403 403
404 QPtrList<Incidence> relations = incidence->relations(); 404 QPtrList<Incidence> relations = incidence->relations();
405 for( Incidence* i = relations.first(); i; i = relations.next() ) 405 for( Incidence* i = relations.first(); i; i = relations.next() )
406 if( !mOrphanUids.find( i->uid() ) ) { 406 if( !mOrphanUids.find( i->uid() ) ) {
407 mOrphans.insert( uid, i ); 407 mOrphans.insert( uid, i );
408 mOrphanUids.insert( i->uid(), i ); 408 mOrphanUids.insert( i->uid(), i );
409 i->setRelatedTo( 0 ); 409 i->setRelatedTo( 0 );
410 i->setRelatedToUid( uid ); 410 i->setRelatedToUid( uid );
411 } 411 }
412 412
413 // 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
414 if( incidence->relatedTo() ) 414 if( incidence->relatedTo() )
415 incidence->relatedTo()->removeRelation( incidence ); 415 incidence->relatedTo()->removeRelation( incidence );
416 416
417 // Remove this one from the orphans list 417 // Remove this one from the orphans list
418 if( mOrphanUids.remove( uid ) ) 418 if( mOrphanUids.remove( uid ) )
419 // 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
420 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { 420 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) {
421 // Removing wasn't that easy 421 // Removing wasn't that easy
422 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { 422 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) {
423 if( it.current()->uid() == uid ) { 423 if( it.current()->uid() == uid ) {
424 mOrphans.remove( it.currentKey() ); 424 mOrphans.remove( it.currentKey() );
425 break; 425 break;
426 } 426 }
427 } 427 }
428 } 428 }
429} 429}
430 430
431void Calendar::registerObserver( Observer *observer ) 431void Calendar::registerObserver( Observer *observer )
432{ 432{
433 mObserver = observer; 433 mObserver = observer;
434 mNewObserver = true; 434 mNewObserver = true;
435} 435}
436 436
437void Calendar::setModified( bool modified ) 437void Calendar::setModified( bool modified )
438{ 438{
439 if ( mObserver ) mObserver->calendarModified( modified, this ); 439 if ( mObserver ) mObserver->calendarModified( modified, this );
440 if ( modified != mModified || mNewObserver ) { 440 if ( modified != mModified || mNewObserver ) {
441 mNewObserver = false; 441 mNewObserver = false;
442 // if ( mObserver ) mObserver->calendarModified( modified, this ); 442 // if ( mObserver ) mObserver->calendarModified( modified, this );
443 mModified = modified; 443 mModified = modified;
444 } 444 }
445} 445}
446 446
447void Calendar::setLoadedProductId( const QString &id ) 447void Calendar::setLoadedProductId( const QString &id )
448{ 448{
449 mLoadedProductId = id; 449 mLoadedProductId = id;
450} 450}
451 451
452QString Calendar::loadedProductId() 452QString Calendar::loadedProductId()
453{ 453{
454 return mLoadedProductId; 454 return mLoadedProductId;
455} 455}
456 456
457//#include "calendar.moc" 457//#include "calendar.moc"
diff --git a/libkcal/calendar.h b/libkcal/calendar.h
index d5294eb..b801186 100644
--- a/libkcal/calendar.h
+++ b/libkcal/calendar.h
@@ -1,352 +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 void resetPilotStat(int id);
71 /** 71 /**
72 Clears out the current calendar, freeing all used memory etc. 72 Clears out the current calendar, freeing all used memory etc.
73 */ 73 */
74 virtual void close() = 0; 74 virtual void close() = 0;
75 75
76 /** 76 /**
77 Sync changes in memory to persistant storage. 77 Sync changes in memory to persistant storage.
78 */ 78 */
79 virtual void save() = 0; 79 virtual void save() = 0;
80 virtual QPtrList<Event> getExternLastSyncEvents() = 0; 80 virtual QPtrList<Event> getExternLastSyncEvents() = 0;
81 virtual bool isSaving() { return false; } 81 virtual bool isSaving() { return false; }
82 82
83 /** 83 /**
84 Return the owner of the calendar's full name. 84 Return the owner of the calendar's full name.
85 */ 85 */
86 const QString &getOwner() const; 86 const QString &getOwner() const;
87 /** 87 /**
88 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.
89 */ 89 */
90 void setOwner( const QString &os ); 90 void setOwner( const QString &os );
91 /** 91 /**
92 Return the email address of the calendar owner. 92 Return the email address of the calendar owner.
93 */ 93 */
94 const QString &getEmail(); 94 const QString &getEmail();
95 /** 95 /**
96 Set the email address of the calendar owner. 96 Set the email address of the calendar owner.
97 */ 97 */
98 void setEmail( const QString & ); 98 void setEmail( const QString & );
99 99
100 /** 100 /**
101 Set time zone from a timezone string (e.g. -2:00) 101 Set time zone from a timezone string (e.g. -2:00)
102 */ 102 */
103 void setTimeZone( const QString &tz ); 103 void setTimeZone( const QString &tz );
104 /** 104 /**
105 Set time zone from a minutes value (e.g. -60) 105 Set time zone from a minutes value (e.g. -60)
106 */ 106 */
107 void setTimeZone( int tz ); 107 void setTimeZone( int tz );
108 /** 108 /**
109 Return time zone as offest in minutes. 109 Return time zone as offest in minutes.
110 */ 110 */
111 int getTimeZone() const; 111 int getTimeZone() const;
112 /** 112 /**
113 Compute an ISO 8601 format string from the time zone. 113 Compute an ISO 8601 format string from the time zone.
114 */ 114 */
115 QString getTimeZoneStr() const; 115 QString getTimeZoneStr() const;
116 /** 116 /**
117 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
118 values). 118 values).
119 */ 119 */
120 void setTimeZoneId( const QString & ); 120 void setTimeZoneId( const QString & );
121 /** 121 /**
122 Return time zone id. 122 Return time zone id.
123 */ 123 */
124 QString timeZoneId() const; 124 QString timeZoneId() const;
125 /** 125 /**
126 Use local time, not UTC or a time zone. 126 Use local time, not UTC or a time zone.
127 */ 127 */
128 void setLocalTime(); 128 void setLocalTime();
129 /** 129 /**
130 Return whether local time is being used. 130 Return whether local time is being used.
131 */ 131 */
132 bool isLocalTime() const; 132 bool isLocalTime() const;
133 133
134 /** 134 /**
135 Add an incidence to calendar. 135 Add an incidence to calendar.
136 136
137 @return true on success, false on error. 137 @return true on success, false on error.
138 */ 138 */
139 virtual bool addIncidence( Incidence * ); 139 virtual bool addIncidence( Incidence * );
140 /** 140 /**
141 Return filtered list of all incidences of this calendar. 141 Return filtered list of all incidences of this calendar.
142 */ 142 */
143 virtual QPtrList<Incidence> incidences(); 143 virtual QPtrList<Incidence> incidences();
144 144
145 /** 145 /**
146 Return unfiltered list of all incidences of this calendar. 146 Return unfiltered list of all incidences of this calendar.
147 */ 147 */
148 virtual QPtrList<Incidence> rawIncidences(); 148 virtual QPtrList<Incidence> rawIncidences();
149 149
150 /** 150 /**
151 Adds a Event to this calendar object. 151 Adds a Event to this calendar object.
152 @param anEvent a pointer to the event to add 152 @param anEvent a pointer to the event to add
153 153
154 @return true on success, false on error. 154 @return true on success, false on error.
155 */ 155 */
156 virtual bool addEventNoDup( Event *event ) = 0; 156 virtual bool addEventNoDup( Event *event ) = 0;
157 virtual bool addAnniversaryNoDup( Event *event ) = 0; 157 virtual bool addAnniversaryNoDup( Event *event ) = 0;
158 virtual bool addEvent( Event *anEvent ) = 0; 158 virtual bool addEvent( Event *anEvent ) = 0;
159 /** 159 /**
160 Delete event from calendar. 160 Delete event from calendar.
161 */ 161 */
162 virtual void deleteEvent( Event * ) = 0; 162 virtual void deleteEvent( Event * ) = 0;
163 /** 163 /**
164 Retrieves an event on the basis of the unique string ID. 164 Retrieves an event on the basis of the unique string ID.
165 */ 165 */
166 virtual Event *event( const QString &UniqueStr ) = 0; 166 virtual Event *event( const QString &UniqueStr ) = 0;
167 virtual Event *event( QString, QString ) = 0; 167 virtual Event *event( QString, QString ) = 0;
168 /** 168 /**
169 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
170 date specified. useful for dayView, etc. etc. 170 date specified. useful for dayView, etc. etc.
171 The calendar filter is applied. 171 The calendar filter is applied.
172 */ 172 */
173 QPtrList<Event> events( const QDate &date, bool sorted = false); 173 QPtrList<Event> events( const QDate &date, bool sorted = false);
174 /** 174 /**
175 Get events, which occur on the given date. 175 Get events, which occur on the given date.
176 The calendar filter is applied. 176 The calendar filter is applied.
177 */ 177 */
178 QPtrList<Event> events( const QDateTime &qdt ); 178 QPtrList<Event> events( const QDateTime &qdt );
179 /** 179 /**
180 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
181 are returned, which are completely included in the range. 181 are returned, which are completely included in the range.
182 The calendar filter is applied. 182 The calendar filter is applied.
183 */ 183 */
184 QPtrList<Event> events( const QDate &start, const QDate &end, 184 QPtrList<Event> events( const QDate &start, const QDate &end,
185 bool inclusive = false); 185 bool inclusive = false);
186 /** 186 /**
187 Return filtered list of all events in calendar. 187 Return filtered list of all events in calendar.
188 */ 188 */
189 virtual QPtrList<Event> events(); 189 virtual QPtrList<Event> events();
190 /** 190 /**
191 Return unfiltered list of all events in calendar. 191 Return unfiltered list of all events in calendar.
192 */ 192 */
193 virtual QPtrList<Event> rawEvents() = 0; 193 virtual QPtrList<Event> rawEvents() = 0;
194 194
195 /** 195 /**
196 Add a todo to the todolist. 196 Add a todo to the todolist.
197 197
198 @return true on success, false on error. 198 @return true on success, false on error.
199 */ 199 */
200 virtual bool addTodo( Todo *todo ) = 0; 200 virtual bool addTodo( Todo *todo ) = 0;
201 virtual bool addTodoNoDup( Todo *todo ) = 0; 201 virtual bool addTodoNoDup( Todo *todo ) = 0;
202 /** 202 /**
203 Remove a todo from the todolist. 203 Remove a todo from the todolist.
204 */ 204 */
205 virtual void deleteTodo( Todo * ) = 0; 205 virtual void deleteTodo( Todo * ) = 0;
206 virtual void deleteJournal( Journal * ) = 0; 206 virtual void deleteJournal( Journal * ) = 0;
207 /** 207 /**
208 Return filterd list of todos. 208 Return filterd list of todos.
209 */ 209 */
210 virtual QPtrList<Todo> todos(); 210 virtual QPtrList<Todo> todos();
211 /** 211 /**
212 Searches todolist for an event with this unique string identifier, 212 Searches todolist for an event with this unique string identifier,
213 returns a pointer or null. 213 returns a pointer or null.
214 */ 214 */
215 virtual Todo *todo( const QString &uid ) = 0; 215 virtual Todo *todo( const QString &uid ) = 0;
216 virtual Todo *todo( QString, QString ) = 0; 216 virtual Todo *todo( QString, QString ) = 0;
217 /** 217 /**
218 Returns list of todos due on the specified date. 218 Returns list of todos due on the specified date.
219 */ 219 */
220 virtual QPtrList<Todo> todos( const QDate &date ) = 0; 220 virtual QPtrList<Todo> todos( const QDate &date ) = 0;
221 /** 221 /**
222 Return unfiltered list of todos. 222 Return unfiltered list of todos.
223 */ 223 */
224 virtual QPtrList<Todo> rawTodos() = 0; 224 virtual QPtrList<Todo> rawTodos() = 0;
225 225
226 /** 226 /**
227 Add a Journal entry to calendar. 227 Add a Journal entry to calendar.
228 228
229 @return true on success, false on error. 229 @return true on success, false on error.
230 */ 230 */
231 virtual bool addJournal( Journal * ) = 0; 231 virtual bool addJournal( Journal * ) = 0;
232 /** 232 /**
233 Return Journal for given date. 233 Return Journal for given date.
234 */ 234 */
235 virtual Journal *journal( const QDate & ) = 0; 235 virtual Journal *journal( const QDate & ) = 0;
236 /** 236 /**
237 Return Journal with given UID. 237 Return Journal with given UID.
238 */ 238 */
239 virtual Journal *journal( const QString &UID ) = 0; 239 virtual Journal *journal( const QString &UID ) = 0;
240 /** 240 /**
241 Return list of all Journal entries. 241 Return list of all Journal entries.
242 */ 242 */
243 virtual QPtrList<Journal> journals() = 0; 243 virtual QPtrList<Journal> journals() = 0;
244 244
245 /** 245 /**
246 Searches all incidence types for an incidence with this unique 246 Searches all incidence types for an incidence with this unique
247 string identifier, returns a pointer or null. 247 string identifier, returns a pointer or null.
248 */ 248 */
249 Incidence* incidence( const QString&UID ); 249 Incidence* incidence( const QString&UID );
250 250
251 /** 251 /**
252 Setup relations for an incidence. 252 Setup relations for an incidence.
253 */ 253 */
254 virtual void setupRelations( Incidence * ); 254 virtual void setupRelations( Incidence * );
255 /** 255 /**
256 Remove all relations to an incidence 256 Remove all relations to an incidence
257 */ 257 */
258 virtual void removeRelations( Incidence * ); 258 virtual void removeRelations( Incidence * );
259 259
260 /** 260 /**
261 Set calendar filter, which filters events for the events() functions. 261 Set calendar filter, which filters events for the events() functions.
262 The Filter object is owned by the caller. 262 The Filter object is owned by the caller.
263 */ 263 */
264 void setFilter( CalFilter * ); 264 void setFilter( CalFilter * );
265 /** 265 /**
266 Return calendar filter. 266 Return calendar filter.
267 */ 267 */
268 CalFilter *filter(); 268 CalFilter *filter();
269 virtual QDateTime nextAlarm( int daysTo ) = 0; 269 virtual QDateTime nextAlarm( int daysTo ) = 0;
270 virtual QString nextSummary( ) const = 0; 270 virtual QString nextSummary( ) const = 0;
271 virtual void reInitAlarmSettings() = 0; 271 virtual void reInitAlarmSettings() = 0;
272 virtual QDateTime nextAlarmEventDateTime() const = 0; 272 virtual QDateTime nextAlarmEventDateTime() const = 0;
273 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; 273 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0;
274 /** 274 /**
275 Return all alarms, which ocur in the given time interval. 275 Return all alarms, which ocur in the given time interval.
276 */ 276 */
277 virtual Alarm::List alarms( const QDateTime &from, 277 virtual Alarm::List alarms( const QDateTime &from,
278 const QDateTime &to ) = 0; 278 const QDateTime &to ) = 0;
279 279
280 class Observer { 280 class Observer {
281 public: 281 public:
282 virtual void calendarModified( bool, Calendar * ) = 0; 282 virtual void calendarModified( bool, Calendar * ) = 0;
283 }; 283 };
284 284
285 void registerObserver( Observer * ); 285 void registerObserver( Observer * );
286 286
287 void setModified( bool ); 287 void setModified( bool );
288 288
289 /** 289 /**
290 Set product id returned by loadedProductId(). This function is only 290 Set product id returned by loadedProductId(). This function is only
291 useful for the calendar loading code. 291 useful for the calendar loading code.
292 */ 292 */
293 void setLoadedProductId( const QString & ); 293 void setLoadedProductId( const QString & );
294 /** 294 /**
295 Return product id taken from file that has been loaded. Returns 295 Return product id taken from file that has been loaded. Returns
296 QString::null, if no calendar has been loaded. 296 QString::null, if no calendar has been loaded.
297 */ 297 */
298 QString loadedProductId(); 298 QString loadedProductId();
299 299
300 signals: 300 signals:
301 void calendarChanged(); 301 void calendarChanged();
302 void calendarSaved(); 302 void calendarSaved();
303 void calendarLoaded(); 303 void calendarLoaded();
304 void addAlarm(const QDateTime &qdt, const QString &noti ); 304 void addAlarm(const QDateTime &qdt, const QString &noti );
305 void removeAlarm(const QDateTime &qdt, const QString &noti ); 305 void removeAlarm(const QDateTime &qdt, const QString &noti );
306 306
307 protected: 307 protected:
308 /** 308 /**
309 Get unfiltered events, which occur on the given date. 309 Get unfiltered events, which occur on the given date.
310 */ 310 */
311 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; 311 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0;
312 /** 312 /**
313 Get unfiltered events, which occur on the given date. 313 Get unfiltered events, which occur on the given date.
314 */ 314 */
315 virtual QPtrList<Event> rawEventsForDate( const QDate &date, 315 virtual QPtrList<Event> rawEventsForDate( const QDate &date,
316 bool sorted = false ) = 0; 316 bool sorted = false ) = 0;
317 /** 317 /**
318 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
319 are returned, which are completely included in the range. 319 are returned, which are completely included in the range.
320 */ 320 */
321 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, 321 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end,
322 bool inclusive = false ) = 0; 322 bool inclusive = false ) = 0;
323 Incidence *mNextAlarmIncidence; 323 Incidence *mNextAlarmIncidence;
324 324
325private: 325private:
326 void init(); 326 void init();
327 327
328 QString mOwner; // who the calendar belongs to 328 QString mOwner; // who the calendar belongs to
329 QString mOwnerEmail; // email address of the owner 329 QString mOwnerEmail; // email address of the owner
330 int mTimeZone; // timezone OFFSET from GMT (MINUTES) 330 int mTimeZone; // timezone OFFSET from GMT (MINUTES)
331 bool mLocalTime; // use local time, not UTC or a time zone 331 bool mLocalTime; // use local time, not UTC or a time zone
332 332
333 CalFilter *mFilter; 333 CalFilter *mFilter;
334 CalFilter *mDefaultFilter; 334 CalFilter *mDefaultFilter;
335 335
336 QString mTimeZoneId; 336 QString mTimeZoneId;
337 337
338 Observer *mObserver; 338 Observer *mObserver;
339 bool mNewObserver; 339 bool mNewObserver;
340 340
341 bool mModified; 341 bool mModified;
342 342
343 QString mLoadedProductId; 343 QString mLoadedProductId;
344 344
345 // This list is used to put together related todos 345 // This list is used to put together related todos
346 QDict<Incidence> mOrphans; 346 QDict<Incidence> mOrphans;
347 QDict<Incidence> mOrphanUids; 347 QDict<Incidence> mOrphanUids;
348}; 348};
349 349
350} 350}
351 351
352#endif 352#endif