summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-06-03 23:47:47 (UTC)
committer zautrix <zautrix>2005-06-03 23:47:47 (UTC)
commit0e0ac7a92ac2fe052b3e72d49e505a078b05e7f3 (patch) (unidiff)
tree01c96ae843e7a988d6957a5353616b42e0b322da
parentaa0f7df485c3ff0c298d4924ac1e8a5e9e6da627 (diff)
downloadkdepimpi-0e0ac7a92ac2fe052b3e72d49e505a078b05e7f3.zip
kdepimpi-0e0ac7a92ac2fe052b3e72d49e505a078b05e7f3.tar.gz
kdepimpi-0e0ac7a92ac2fe052b3e72d49e505a078b05e7f3.tar.bz2
fixxx
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp30
1 files changed, 17 insertions, 13 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index c01be9b..5132f98 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,4317 +1,4321 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Requires the Qt and KDE widget libraries, available at no cost at 4 Requires the Qt and KDE widget libraries, available at no cost at
5 http://www.troll.no and http://www.kde.org respectively 5 http://www.troll.no and http://www.kde.org respectively
6 6
7 Copyright (c) 1997, 1998, 1999 7 Copyright (c) 1997, 1998, 1999
8 Preston Brown (preton.brown@yale.edu) 8 Preston Brown (preton.brown@yale.edu)
9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl) 9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl)
10 Ian Dawes (iadawes@globalserve.net) 10 Ian Dawes (iadawes@globalserve.net)
11 Laszlo Boloni (boloni@cs.purdue.edu) 11 Laszlo Boloni (boloni@cs.purdue.edu)
12 12
13 Copyright (c) 2000, 2001, 2002 13 Copyright (c) 2000, 2001, 2002
14 Cornelius Schumacher <schumacher@kde.org> 14 Cornelius Schumacher <schumacher@kde.org>
15 15
16 This program is free software; you can redistribute it and/or modify 16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by 17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or 18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version. 19 (at your option) any later version.
20 20
21 This program is distributed in the hope that it will be useful, 21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
24 GNU General Public License for more details. 24 GNU General Public License for more details.
25 25
26 You should have received a copy of the GNU General Public License 26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software 27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#include <stdlib.h> 31#include <stdlib.h>
32 32
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qradiobutton.h> 34#include <qradiobutton.h>
35#include <qbuttongroup.h> 35#include <qbuttongroup.h>
36#include <qlayout.h> 36#include <qlayout.h>
37#include <qclipboard.h> 37#include <qclipboard.h>
38#include <qcursor.h> 38#include <qcursor.h>
39#include <qmessagebox.h> 39#include <qmessagebox.h>
40#include <qprogressbar.h> 40#include <qprogressbar.h>
41#include <qmultilineedit.h> 41#include <qmultilineedit.h>
42#include <qtimer.h> 42#include <qtimer.h>
43#include <qwidgetstack.h> 43#include <qwidgetstack.h>
44#include <qptrlist.h> 44#include <qptrlist.h>
45#include <qregexp.h> 45#include <qregexp.h>
46#include <qgroupbox.h> 46#include <qgroupbox.h>
47#include <qfile.h> 47#include <qfile.h>
48#include <qdir.h> 48#include <qdir.h>
49#ifndef KORG_NOSPLITTER 49#ifndef KORG_NOSPLITTER
50#include <qsplitter.h> 50#include <qsplitter.h>
51#endif 51#endif
52 52
53#include <kglobal.h> 53#include <kglobal.h>
54#include <kdebug.h> 54#include <kdebug.h>
55#include <kstandarddirs.h> 55#include <kstandarddirs.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57#include <kmessagebox.h> 57#include <kmessagebox.h>
58#include <knotifyclient.h> 58#include <knotifyclient.h>
59#include <kconfig.h> 59#include <kconfig.h>
60 60
61#include <libkdepim/ksyncprefsdialog.h> 61#include <libkdepim/ksyncprefsdialog.h>
62#include <krun.h> 62#include <krun.h>
63#include <kdirwatch.h> 63#include <kdirwatch.h>
64#include <libkdepim/kdatepicker.h> 64#include <libkdepim/kdatepicker.h>
65#include <libkdepim/ksyncprofile.h> 65#include <libkdepim/ksyncprofile.h>
66#include <libkdepim/kpimglobalprefs.h> 66#include <libkdepim/kpimglobalprefs.h>
67 67
68#include <libkcal/vcaldrag.h> 68#include <libkcal/vcaldrag.h>
69#include <libkcal/icaldrag.h> 69#include <libkcal/icaldrag.h>
70#include <libkcal/icalformat.h> 70#include <libkcal/icalformat.h>
71#include <libkcal/vcalformat.h> 71#include <libkcal/vcalformat.h>
72#include <libkcal/scheduler.h> 72#include <libkcal/scheduler.h>
73#include <libkcal/calendarlocal.h> 73#include <libkcal/calendarlocal.h>
74#include <libkcal/journal.h> 74#include <libkcal/journal.h>
75#include <libkcal/calfilter.h> 75#include <libkcal/calfilter.h>
76#include <libkcal/attendee.h> 76#include <libkcal/attendee.h>
77#include <libkcal/dndfactory.h> 77#include <libkcal/dndfactory.h>
78#include <libkcal/freebusy.h> 78#include <libkcal/freebusy.h>
79#include <libkcal/filestorage.h> 79#include <libkcal/filestorage.h>
80#include <libkcal/calendarresources.h> 80#include <libkcal/calendarresources.h>
81#include <libkcal/qtopiaformat.h> 81#include <libkcal/qtopiaformat.h>
82#include "../kalarmd/alarmdialog.h" 82#include "../kalarmd/alarmdialog.h"
83 83
84#ifndef DESKTOP_VERSION 84#ifndef DESKTOP_VERSION
85#include <libkcal/sharpformat.h> 85#include <libkcal/sharpformat.h>
86#include <externalapphandler.h> 86#include <externalapphandler.h>
87#endif 87#endif
88#include <libkcal/phoneformat.h> 88#include <libkcal/phoneformat.h>
89#ifndef KORG_NOMAIL 89#ifndef KORG_NOMAIL
90#include "komailclient.h" 90#include "komailclient.h"
91#endif 91#endif
92#ifndef KORG_NOPRINTER 92#ifndef KORG_NOPRINTER
93#include "calprinter.h" 93#include "calprinter.h"
94#endif 94#endif
95#ifndef KORG_NOPLUGINS 95#ifndef KORG_NOPLUGINS
96#include "kocore.h" 96#include "kocore.h"
97#endif 97#endif
98#include "koeventeditor.h" 98#include "koeventeditor.h"
99#include "kotodoeditor.h" 99#include "kotodoeditor.h"
100#include "koprefs.h" 100#include "koprefs.h"
101#include "koeventviewerdialog.h" 101#include "koeventviewerdialog.h"
102#include "publishdialog.h" 102#include "publishdialog.h"
103#include "kofilterview.h" 103#include "kofilterview.h"
104#include "koglobals.h" 104#include "koglobals.h"
105#include "koviewmanager.h" 105#include "koviewmanager.h"
106#include "koagendaview.h" 106#include "koagendaview.h"
107#include "kodialogmanager.h" 107#include "kodialogmanager.h"
108#include "outgoingdialog.h" 108#include "outgoingdialog.h"
109#include "incomingdialog.h" 109#include "incomingdialog.h"
110#include "datenavigatorcontainer.h" 110#include "datenavigatorcontainer.h"
111#include "statusdialog.h" 111#include "statusdialog.h"
112#include "kdatenavigator.h" 112#include "kdatenavigator.h"
113#include "kotodoview.h" 113#include "kotodoview.h"
114#include "datenavigator.h" 114#include "datenavigator.h"
115#include "resourceview.h" 115#include "resourceview.h"
116#include "navigatorbar.h" 116#include "navigatorbar.h"
117#include "searchdialog.h" 117#include "searchdialog.h"
118#include "mainwindow.h" 118#include "mainwindow.h"
119 119
120#include "calendarview.h" 120#include "calendarview.h"
121#ifndef DESKTOP_VERSION 121#ifndef DESKTOP_VERSION
122#include <qtopia/alarmserver.h> 122#include <qtopia/alarmserver.h>
123#endif 123#endif
124#ifndef _WIN32_ 124#ifndef _WIN32_
125#include <stdlib.h> 125#include <stdlib.h>
126#include <stdio.h> 126#include <stdio.h>
127#include <unistd.h> 127#include <unistd.h>
128#else 128#else
129#include <qprocess.h> 129#include <qprocess.h>
130#endif 130#endif
131 131
132#ifdef DESKTOP_VERSION 132#ifdef DESKTOP_VERSION
133#include <kabc/stdaddressbook.h> 133#include <kabc/stdaddressbook.h>
134#endif 134#endif
135using namespace KOrg; 135using namespace KOrg;
136using namespace KCal; 136using namespace KCal;
137extern int globalFlagBlockAgenda; 137extern int globalFlagBlockAgenda;
138extern int globalFlagBlockStartup; 138extern int globalFlagBlockStartup;
139 139
140 140
141MissedAlarmTextBrowser::MissedAlarmTextBrowser(QWidget *parent, QPtrList<Incidence> alarms,QDateTime start ) : QTextBrowser(parent) 141MissedAlarmTextBrowser::MissedAlarmTextBrowser(QWidget *parent, QPtrList<Incidence> alarms,QDateTime start ) : QTextBrowser(parent)
142 142
143{ 143{
144 mAlarms = alarms; 144 mAlarms = alarms;
145 setBackgroundColor( QColor( 86, 153, 205 ) ); 145 setBackgroundColor( QColor( 86, 153, 205 ) );
146 QString mText = "<table width=\"100%\">\n"; 146 QString mText = "<table width=\"100%\">\n";
147 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>"; 147 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>";
148#ifdef DESKTOP_VERSION 148#ifdef DESKTOP_VERSION
149 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h1>";
150#else
151 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h2>"; 149 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h2>";
150#else
151 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h3>";
152#endif 152#endif
153 // mText += "<img src=\""; 153 // mText += "<img src=\"";
154 // mText += ipath; 154 // mText += ipath;
155 // mText += "\">"; 155 // mText += "\">";
156 //mEventDate = QDate::currentDate(); 156 //mEventDate = QDate::currentDate();
157#ifdef DESKTOP_VERSION 157#ifdef DESKTOP_VERSION
158 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h1>";
159#else
160 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h2>"; 158 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h2>";
159#else
160 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h3>";
161#endif 161#endif
162 mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>"; 162 mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>";
163 163
164 Incidence * inc = getNextInc( start ); 164 Incidence * inc = getNextInc( start );
165 int time = 0; 165 int time = 0;
166 mText += "<table>"; 166 mText += "<table>";
167 while ( inc ) { 167 while ( inc ) {
168 QDateTime dt ; 168 QDateTime dt ;
169 QString tempText = "<a "; 169 QString tempText = "<a ";
170 bool ok; 170 bool ok;
171 dt = inc->getNextOccurence( start, &ok ); 171 dt = inc->getNextOccurence( start, &ok );
172 if ( !ok ) continue; 172 if ( !ok ) continue;
173 if ( inc->type() == "Event" ) { 173 if ( inc->type() == "Event" ) {
174 tempText += "href=\"event:"; 174 tempText += "href=\"event:";
175 } else if ( inc->type() == "Todo" ) { 175 } else if ( inc->type() == "Todo" ) {
176 tempText += "href=\"todo:"; 176 tempText += "href=\"todo:";
177 } 177 }
178 tempText += inc->uid() + "\">"; 178 tempText += inc->uid() + "\">";
179 if ( inc->type() == "Todo" ) 179 if ( inc->type() == "Todo" )
180 tempText += i18n("Todo: "); 180 tempText += i18n("Todo: ");
181 if ( inc->summary().length() > 0 ) 181 if ( inc->summary().length() > 0 )
182 tempText += inc->summary(); 182 tempText += inc->summary();
183 else 183 else
184 tempText += i18n("-no summary-"); 184 tempText += i18n("-no summary-");
185 QString timestr; 185 QString timestr;
186 if (!inc->doesFloat()) 186 if (!inc->doesFloat())
187 timestr = KGlobal::locale()->formatDateTime( dt, KOPrefs::instance()->mShortDateInViewer) +": "; 187 timestr = KGlobal::locale()->formatDateTime( dt, KOPrefs::instance()->mShortDateInViewer) +": ";
188 else 188 else
189 timestr = KGlobal::locale()->formatDate( dt.date() , KOPrefs::instance()->mShortDateInViewer) +": "; 189 timestr = KGlobal::locale()->formatDate( dt.date() , KOPrefs::instance()->mShortDateInViewer) +": ";
190 if ( dt.date() == QDate::currentDate() && time == 0 ) { 190 if ( dt.date() == QDate::currentDate() && time == 0 ) {
191 time = 1; 191 time = 1;
192 mText +="</table>"; 192 mText +="</table>";
193 mText += "</td></tr>\n<tr bgcolor=\"#FFDC64\"><td>"; 193 mText += "</td></tr>\n<tr bgcolor=\"#FFDC64\"><td>";
194 mText += "<table>"; 194 mText += "<table>";
195 195
196 } 196 }
197 if ( dt.date() > QDate::currentDate() && time != 2 ) { 197 if ( dt.date() > QDate::currentDate() && time != 2 ) {
198 time = 2; 198 time = 2;
199 mText +="</table>"; 199 mText +="</table>";
200 mText += "</td></tr>\n<tr bgcolor=\"#6AFF6A\"><td>"; 200 mText += "</td></tr>\n<tr bgcolor=\"#6AFF6A\"><td>";
201 mText += "<table>"; 201 mText += "<table>";
202 } 202 }
203 mText +="<tr><td><b>"; 203 mText +="<tr><td><b>";
204 mText += timestr; 204 mText += timestr;
205 mText += "</b></td><td>"; 205 mText += "</b></td><td>";
206 mText += tempText; 206 mText += tempText;
207 mText += "</td></tr>\n"; 207 mText += "</td></tr>\n";
208 inc = getNextInc( start ); 208 inc = getNextInc( start );
209 } 209 }
210 mText +="</table>"; 210 mText +="</table>";
211 setText( mText ); 211 setText( mText );
212} 212}
213 213
214Incidence * MissedAlarmTextBrowser::getNextInc( QDateTime start ) 214Incidence * MissedAlarmTextBrowser::getNextInc( QDateTime start )
215{ 215{
216 QDateTime dt ; 216 QDateTime dt ;
217 Incidence * retInc; 217 Incidence * retInc;
218 Incidence * inc = mAlarms.first(); 218 Incidence * inc = mAlarms.first();
219 if ( inc == 0 ) 219 if ( inc == 0 )
220 return 0; 220 return 0;
221 bool ok; 221 bool ok;
222 dt = inc->getNextOccurence( start, &ok ); 222 dt = inc->getNextOccurence( start, &ok );
223 if ( ! ok ) return 0; 223 if ( ! ok ) return 0;
224 QDateTime dtn ; 224 QDateTime dtn ;
225 retInc = inc; 225 retInc = inc;
226 inc = mAlarms.next(); 226 inc = mAlarms.next();
227 while ( inc ) { 227 while ( inc ) {
228 dtn = inc->getNextOccurence( start, &ok ); 228 dtn = inc->getNextOccurence( start, &ok );
229 if ( ! ok ) return 0; 229 if ( ! ok ) return 0;
230 if ( dtn < dt ) { 230 if ( dtn < dt ) {
231 dt = dtn; 231 dt = dtn;
232 retInc = inc; 232 retInc = inc;
233 } 233 }
234 inc = mAlarms.next(); 234 inc = mAlarms.next();
235 } 235 }
236 mAlarms.remove( retInc ); 236 mAlarms.remove( retInc );
237 return retInc; 237 return retInc;
238 238
239} 239}
240void MissedAlarmTextBrowser::setSource(const QString & n) 240void MissedAlarmTextBrowser::setSource(const QString & n)
241{ 241{
242 if (n.startsWith("event:")) { 242 if (n.startsWith("event:")) {
243#ifdef DESKTOP_VERSION 243#ifdef DESKTOP_VERSION
244 emit showIncidence(n.mid(8)); 244 emit showIncidence(n.mid(8));
245#else 245#else
246 emit showIncidence(n.mid(6)); 246 emit showIncidence(n.mid(6));
247#endif 247#endif
248 return; 248 return;
249 } else if (n.startsWith("todo:")) { 249 } else if (n.startsWith("todo:")) {
250#ifdef DESKTOP_VERSION 250#ifdef DESKTOP_VERSION
251 emit showIncidence(n.mid(7)); 251 emit showIncidence(n.mid(7));
252#else 252#else
253 emit showIncidence(n.mid(5)); 253 emit showIncidence(n.mid(5));
254#endif 254#endif
255 return; 255 return;
256 } 256 }
257} 257}
258 258
259 259
260class KOBeamPrefs : public QDialog 260class KOBeamPrefs : public QDialog
261{ 261{
262 public: 262 public:
263 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : 263 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) :
264 QDialog( parent, name, true ) 264 QDialog( parent, name, true )
265 { 265 {
266 setCaption( i18n("Beam Options") ); 266 setCaption( i18n("Beam Options") );
267 QVBoxLayout* lay = new QVBoxLayout( this ); 267 QVBoxLayout* lay = new QVBoxLayout( this );
268 lay->setSpacing( 3 ); 268 lay->setSpacing( 3 );
269 lay->setMargin( 3 ); 269 lay->setMargin( 3 );
270 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); 270 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this );
271 lay->addWidget( format ); 271 lay->addWidget( format );
272 format->setExclusive ( true ) ; 272 format->setExclusive ( true ) ;
273 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); 273 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this );
274 lay->addWidget( time ); time->setExclusive ( true ) ; 274 lay->addWidget( time ); time->setExclusive ( true ) ;
275 vcal = new QRadioButton(" vCalendar ", format ); 275 vcal = new QRadioButton(" vCalendar ", format );
276 ical = new QRadioButton(" iCalendar ", format ); 276 ical = new QRadioButton(" iCalendar ", format );
277 vcal->setChecked( true ); 277 vcal->setChecked( true );
278 tz = new QRadioButton(i18n(" With timezone "), time ); 278 tz = new QRadioButton(i18n(" With timezone "), time );
279 local = new QRadioButton(i18n(" Local time "), time ); 279 local = new QRadioButton(i18n(" Local time "), time );
280 tz->setChecked( true ); 280 tz->setChecked( true );
281 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); 281 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this );
282 lay->addWidget( ok ); 282 lay->addWidget( ok );
283 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 283 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
284 lay->addWidget( cancel ); 284 lay->addWidget( cancel );
285 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 285 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
286 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 286 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
287 resize( 200, 200 ); 287 resize( 200, 200 );
288 } 288 }
289 289
290 bool beamVcal() { return vcal->isChecked(); } 290 bool beamVcal() { return vcal->isChecked(); }
291 bool beamLocal() { return local->isChecked(); } 291 bool beamLocal() { return local->isChecked(); }
292private: 292private:
293 QRadioButton* vcal, *ical, *local, *tz; 293 QRadioButton* vcal, *ical, *local, *tz;
294}; 294};
295class KOCatPrefs : public QDialog 295class KOCatPrefs : public QDialog
296{ 296{
297 public: 297 public:
298 KOCatPrefs( QWidget *parent=0, const char *name=0 ) : 298 KOCatPrefs( QWidget *parent=0, const char *name=0 ) :
299 QDialog( parent, name, true ) 299 QDialog( parent, name, true )
300 { 300 {
301 setCaption( i18n("Manage new Categories") ); 301 setCaption( i18n("Manage new Categories") );
302 QVBoxLayout* lay = new QVBoxLayout( this ); 302 QVBoxLayout* lay = new QVBoxLayout( this );
303 lay->setSpacing( 3 ); 303 lay->setSpacing( 3 );
304 lay->setMargin( 3 ); 304 lay->setMargin( 3 );
305 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 ); 305 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 );
306 lay->addWidget( lab ); 306 lay->addWidget( lab );
307 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); 307 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this );
308 lay->addWidget( format ); 308 lay->addWidget( format );
309 format->setExclusive ( true ) ; 309 format->setExclusive ( true ) ;
310 addCatBut = new QRadioButton(i18n("Add to category list"), format ); 310 addCatBut = new QRadioButton(i18n("Add to category list"), format );
311 new QRadioButton(i18n("Remove from Events/Todos"), format ); 311 new QRadioButton(i18n("Remove from Events/Todos"), format );
312 addCatBut->setChecked( true ); 312 addCatBut->setChecked( true );
313 QPushButton * ok = new QPushButton( i18n("OK"), this ); 313 QPushButton * ok = new QPushButton( i18n("OK"), this );
314 lay->addWidget( ok ); 314 lay->addWidget( ok );
315 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 315 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
316 lay->addWidget( cancel ); 316 lay->addWidget( cancel );
317 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 317 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
318 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 318 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
319 resize( 200, 200 ); 319 resize( 200, 200 );
320 } 320 }
321 321
322 bool addCat() { return addCatBut->isChecked(); } 322 bool addCat() { return addCatBut->isChecked(); }
323private: 323private:
324 QRadioButton* addCatBut; 324 QRadioButton* addCatBut;
325}; 325};
326 326
327 327
328 328
329CalendarView::CalendarView( CalendarResources *calendar, 329CalendarView::CalendarView( CalendarResources *calendar,
330 QWidget *parent, const char *name ) 330 QWidget *parent, const char *name )
331 : CalendarViewBase( parent, name ), 331 : CalendarViewBase( parent, name ),
332 mCalendar( calendar ), 332 mCalendar( calendar ),
333 mResourceManager( calendar->resourceManager() ) 333 mResourceManager( calendar->resourceManager() )
334{ 334{
335 335
336 mEventEditor = 0; 336 mEventEditor = 0;
337 mTodoEditor = 0; 337 mTodoEditor = 0;
338 338
339 init(); 339 init();
340} 340}
341 341
342CalendarView::CalendarView( Calendar *calendar, 342CalendarView::CalendarView( Calendar *calendar,
343 QWidget *parent, const char *name ) 343 QWidget *parent, const char *name )
344 : CalendarViewBase( parent, name ), 344 : CalendarViewBase( parent, name ),
345 mCalendar( calendar ), 345 mCalendar( calendar ),
346 mResourceManager( 0 ) 346 mResourceManager( 0 )
347{ 347{
348 348
349 mEventEditor = 0; 349 mEventEditor = 0;
350 mTodoEditor = 0; 350 mTodoEditor = 0;
351 init(); 351 init();
352} 352}
353 353
354void CalendarView::init() 354void CalendarView::init()
355{ 355{
356 mNextAlarmDateTime = QDateTime::currentDateTime(); 356 mNextAlarmDateTime = QDateTime::currentDateTime();
357 setFocusPolicy ( NoFocus ); 357 setFocusPolicy ( NoFocus );
358 mViewerCallerIsSearchDialog = false; 358 mViewerCallerIsSearchDialog = false;
359 mBlockShowDates = false; 359 mBlockShowDates = false;
360 beamDialog = new KOBeamPrefs(); 360 beamDialog = new KOBeamPrefs();
361 mDatePickerMode = 0; 361 mDatePickerMode = 0;
362 mCurrentSyncDevice = ""; 362 mCurrentSyncDevice = "";
363 writeLocale(); 363 writeLocale();
364 mViewManager = new KOViewManager( this ); 364 mViewManager = new KOViewManager( this );
365 mDialogManager = new KODialogManager( this ); 365 mDialogManager = new KODialogManager( this );
366 mEventViewerDialog = 0; 366 mEventViewerDialog = 0;
367 mModified = false; 367 mModified = false;
368 mReadOnly = false; 368 mReadOnly = false;
369 mSelectedIncidence = 0; 369 mSelectedIncidence = 0;
370 mCalPrinter = 0; 370 mCalPrinter = 0;
371 mFilters.setAutoDelete(true); 371 mFilters.setAutoDelete(true);
372 372
373 mCalendar->registerObserver( this ); 373 mCalendar->registerObserver( this );
374 // TODO: Make sure that view is updated, when calendar is changed. 374 // TODO: Make sure that view is updated, when calendar is changed.
375 375
376 mStorage = new FileStorage( mCalendar ); 376 mStorage = new FileStorage( mCalendar );
377 mNavigator = new DateNavigator( this, "datevav", mViewManager ); 377 mNavigator = new DateNavigator( this, "datevav", mViewManager );
378 378
379 QBoxLayout *topLayout = (QBoxLayout*)layout(); 379 QBoxLayout *topLayout = (QBoxLayout*)layout();
380#ifndef KORG_NOSPLITTER 380#ifndef KORG_NOSPLITTER
381 // create the main layout frames. 381 // create the main layout frames.
382 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); 382 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner");
383 topLayout->addWidget(mPanner); 383 topLayout->addWidget(mPanner);
384 384
385 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, 385 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner,
386 "CalendarView::LeftFrame"); 386 "CalendarView::LeftFrame");
387 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); 387 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize);
388 388
389 mDateNavigator = new DateNavigatorContainer( mLeftSplitter, 389 mDateNavigator = new DateNavigatorContainer( mLeftSplitter,
390 "CalendarView::DateNavigator" ); 390 "CalendarView::DateNavigator" );
391 391
392 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); 392 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize);
393 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); 393 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2");
394 mTodoList->setNavigator( mNavigator ); 394 mTodoList->setNavigator( mNavigator );
395 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); 395 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView");
396 396
397#ifdef KORG_NORESOURCEVIEW 397#ifdef KORG_NORESOURCEVIEW
398 mResourceView = 0; 398 mResourceView = 0;
399#else 399#else
400 if ( mResourceManager ) { 400 if ( mResourceManager ) {
401 mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); 401 mResourceView = new ResourceView( mResourceManager, mLeftSplitter );
402 mResourceView->updateView(); 402 mResourceView->updateView();
403 connect( mResourceView, SIGNAL( resourcesChanged() ), 403 connect( mResourceView, SIGNAL( resourcesChanged() ),
404 SLOT( updateView() ) ); 404 SLOT( updateView() ) );
405 } else { 405 } else {
406 mResourceView = 0; 406 mResourceView = 0;
407 } 407 }
408#endif 408#endif
409 QWidget *rightBox = new QWidget( mPanner ); 409 QWidget *rightBox = new QWidget( mPanner );
410 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 410 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
411 411
412 mRightFrame = new QWidgetStack( rightBox ); 412 mRightFrame = new QWidgetStack( rightBox );
413 rightLayout->addWidget( mRightFrame, 1 ); 413 rightLayout->addWidget( mRightFrame, 1 );
414 414
415 mLeftFrame = mLeftSplitter; 415 mLeftFrame = mLeftSplitter;
416#else 416#else
417 //QWidget *mainBox = new QWidget( this ); 417 //QWidget *mainBox = new QWidget( this );
418 //QWidget *leftFrame = new QWidget( mainBox ); 418 //QWidget *leftFrame = new QWidget( mainBox );
419 //QBoxLayout * mainBoxLayout; 419 //QBoxLayout * mainBoxLayout;
420 if ( KOPrefs::instance()->mVerticalScreen ) { 420 if ( KOPrefs::instance()->mVerticalScreen ) {
421 //mainBoxLayout = new QVBoxLayout(mainBox); 421 //mainBoxLayout = new QVBoxLayout(mainBox);
422 //leftFrameLayout = new QHBoxLayout(leftFrame ); 422 //leftFrameLayout = new QHBoxLayout(leftFrame );
423 mMainFrame = new KDGanttMinimizeSplitter( Qt::Vertical, this ); 423 mMainFrame = new KDGanttMinimizeSplitter( Qt::Vertical, this );
424 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 424 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
425 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, mMainFrame);; 425 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, mMainFrame);;
426 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 426 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
427 } else { 427 } else {
428 //mainBoxLayout = new QHBoxLayout(mainBox); 428 //mainBoxLayout = new QHBoxLayout(mainBox);
429 //leftFrameLayout = new QVBoxLayout(leftFrame ); 429 //leftFrameLayout = new QVBoxLayout(leftFrame );
430 mMainFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 430 mMainFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
431 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Left); 431 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Left);
432 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Vertical, mMainFrame); 432 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Vertical, mMainFrame);
433 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 433 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
434 } 434 }
435 mMainFrame->setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) ); 435 mMainFrame->setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) );
436 //QBoxLayout * leftFrameLayout; 436 //QBoxLayout * leftFrameLayout;
437 topLayout->addWidget( mMainFrame ); 437 topLayout->addWidget( mMainFrame );
438 //mainBoxLayout->addWidget (mLeftFrame); 438 //mainBoxLayout->addWidget (mLeftFrame);
439 mDateNavigator = new DateNavigatorContainer( mLeftFrame, 439 mDateNavigator = new DateNavigatorContainer( mLeftFrame,
440 "CalendarView::DateNavigator" ); 440 "CalendarView::DateNavigator" );
441#if 0 441#if 0
442 // FIXME 442 // FIXME
443 mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE, 443 mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE,
444 "CalendarView::DateNavigator", QDate::currentDate()); 444 "CalendarView::DateNavigator", QDate::currentDate());
445#endif 445#endif
446 // mDateNavigator->blockSignals( true ); 446 // mDateNavigator->blockSignals( true );
447 //leftFrameLayout->addWidget( mDateNavigator ); 447 //leftFrameLayout->addWidget( mDateNavigator );
448 mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall"); 448 mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall");
449 mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView"); 449 mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView");
450 mTodoList->setNavigator( mNavigator ); 450 mTodoList->setNavigator( mNavigator );
451#if 0 451#if 0
452 if ( QApplication::desktop()->width() < 480 ) { 452 if ( QApplication::desktop()->width() < 480 ) {
453 leftFrameLayout->addWidget(mFilterView); 453 leftFrameLayout->addWidget(mFilterView);
454 leftFrameLayout->addWidget(mTodoList, 2 ); 454 leftFrameLayout->addWidget(mTodoList, 2 );
455 455
456 } else { 456 } else {
457 leftFrameLayout->addWidget(mTodoList,2 ); 457 leftFrameLayout->addWidget(mTodoList,2 );
458 leftFrameLayout->addWidget(mFilterView ); 458 leftFrameLayout->addWidget(mFilterView );
459 } 459 }
460#endif 460#endif
461 mFilterView->hide(); 461 mFilterView->hide();
462 QWidget *rightBox = new QWidget( mMainFrame ); 462 QWidget *rightBox = new QWidget( mMainFrame );
463 //mainBoxLayout->addWidget ( rightBox, 10 ); 463 //mainBoxLayout->addWidget ( rightBox, 10 );
464 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 464 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
465 mRightFrame = new QWidgetStack( rightBox ); 465 mRightFrame = new QWidgetStack( rightBox );
466 rightLayout->addWidget( mRightFrame, 10 ); 466 rightLayout->addWidget( mRightFrame, 10 );
467 467
468 //mLeftFrame = (QWidget *)leftFrame; 468 //mLeftFrame = (QWidget *)leftFrame;
469 if ( KOPrefs::instance()->mVerticalScreen ) { 469 if ( KOPrefs::instance()->mVerticalScreen ) {
470 //mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() ); 470 //mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() );
471 //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() ); 471 //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() );
472 //mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); 472 //mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() );
473 //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); 473 //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() );
474 } else { 474 } else {
475 //mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() ); 475 //mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() );
476 //mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); 476 //mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() );
477 //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); 477 //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() );
478 } 478 }
479 if ( !KOPrefs::instance()->mShowDateNavigator) 479 if ( !KOPrefs::instance()->mShowDateNavigator)
480 mDateNavigator->hide(); 480 mDateNavigator->hide();
481 //qDebug("Calendarview Size %d %d ", width(), height()); 481 //qDebug("Calendarview Size %d %d ", width(), height());
482#endif 482#endif
483 483
484 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 484 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
485 SLOT( showDates( const KCal::DateList & ) ) ); 485 SLOT( showDates( const KCal::DateList & ) ) );
486 486
487 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 487 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
488 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 488 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
489 489
490 490
491 491
492 connect( mDateNavigator, SIGNAL( showMonth( const QDate & ) ), 492 connect( mDateNavigator, SIGNAL( showMonth( const QDate & ) ),
493 mViewManager, SLOT( showMonth( const QDate & ) ) ); 493 mViewManager, SLOT( showMonth( const QDate & ) ) );
494 494
495 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), 495 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ),
496 mNavigator, SLOT( selectWeek( const QDate & ) ) ); 496 mNavigator, SLOT( selectWeek( const QDate & ) ) );
497 497
498 connect( mDateNavigator, SIGNAL( goPrevYear() ), 498 connect( mDateNavigator, SIGNAL( goPrevYear() ),
499 mNavigator, SLOT( selectPreviousYear() ) ); 499 mNavigator, SLOT( selectPreviousYear() ) );
500 connect( mDateNavigator, SIGNAL( goNextYear() ), 500 connect( mDateNavigator, SIGNAL( goNextYear() ),
501 mNavigator, SLOT( selectNextYear() ) ); 501 mNavigator, SLOT( selectNextYear() ) );
502 connect( mDateNavigator, SIGNAL( goPrevMonth() ), 502 connect( mDateNavigator, SIGNAL( goPrevMonth() ),
503 mNavigator, SLOT( selectPreviousMonth() ) ); 503 mNavigator, SLOT( selectPreviousMonth() ) );
504 connect( mDateNavigator, SIGNAL( goNextMonth() ), 504 connect( mDateNavigator, SIGNAL( goNextMonth() ),
505 mNavigator, SLOT( selectNextMonth() ) ); 505 mNavigator, SLOT( selectNextMonth() ) );
506 506
507 connect( mDateNavigator, SIGNAL( goPrevious() ), 507 connect( mDateNavigator, SIGNAL( goPrevious() ),
508 mNavigator, SLOT( selectPrevious() ) ); 508 mNavigator, SLOT( selectPrevious() ) );
509 connect( mDateNavigator, SIGNAL( goNext() ), 509 connect( mDateNavigator, SIGNAL( goNext() ),
510 mNavigator, SLOT( selectNext() ) ); 510 mNavigator, SLOT( selectNext() ) );
511 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), 511 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ),
512 mNavigator, SLOT( slotMonthSelect( int ) ) ); 512 mNavigator, SLOT( slotMonthSelect( int ) ) );
513 513
514 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 514 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
515 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 515 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
516#if 0 516#if 0
517 connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ), 517 connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ),
518 SLOT( incidenceAdded( Incidence *) ) ); 518 SLOT( incidenceAdded( Incidence *) ) );
519#endif 519#endif
520 // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); 520 // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView()));
521 521
522 connect( this, SIGNAL( configChanged() ), 522 connect( this, SIGNAL( configChanged() ),
523 mDateNavigator, SLOT( updateConfig() ) ); 523 mDateNavigator, SLOT( updateConfig() ) );
524 524
525 connect( mTodoList, SIGNAL( newTodoSignal() ), 525 connect( mTodoList, SIGNAL( newTodoSignal() ),
526 SLOT( newTodo() ) ); 526 SLOT( newTodo() ) );
527 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), 527 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ),
528 SLOT( newSubTodo( Todo * ) ) ); 528 SLOT( newSubTodo( Todo * ) ) );
529 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), 529 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ),
530 SLOT( editTodo( Todo * ) ) ); 530 SLOT( editTodo( Todo * ) ) );
531 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), 531 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ),
532 SLOT( showTodo( Todo *) ) ); 532 SLOT( showTodo( Todo *) ) );
533 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), 533 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ),
534 SLOT( deleteTodo( Todo *) ) ); 534 SLOT( deleteTodo( Todo *) ) );
535 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); 535 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) );
536 connect( mTodoList, SIGNAL( purgeCompletedSignal() ), 536 connect( mTodoList, SIGNAL( purgeCompletedSignal() ),
537 SLOT( purgeCompleted() ) ); 537 SLOT( purgeCompleted() ) );
538 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), 538 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ),
539 SIGNAL( todoModified( Todo *, int ) ) ); 539 SIGNAL( todoModified( Todo *, int ) ) );
540 540
541 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), 541 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ),
542 this, SLOT ( cloneIncidence( Incidence * ) ) ); 542 this, SLOT ( cloneIncidence( Incidence * ) ) );
543 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), 543 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ),
544 this, SLOT (cancelIncidence( Incidence * ) ) ); 544 this, SLOT (cancelIncidence( Incidence * ) ) );
545 545
546 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), 546 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ),
547 this, SLOT ( moveIncidence( Incidence * ) ) ); 547 this, SLOT ( moveIncidence( Incidence * ) ) );
548 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), 548 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ),
549 this, SLOT ( beamIncidence( Incidence * ) ) ); 549 this, SLOT ( beamIncidence( Incidence * ) ) );
550 550
551 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), 551 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ),
552 this, SLOT ( todo_unsub( Todo * ) ) ); 552 this, SLOT ( todo_unsub( Todo * ) ) );
553 553
554 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), 554 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ),
555 this, SLOT ( todo_resub( Todo *,Todo * ) ) ); 555 this, SLOT ( todo_resub( Todo *,Todo * ) ) );
556 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, 556 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList,
557 SLOT( updateTodo( Todo *, int ) ) ); 557 SLOT( updateTodo( Todo *, int ) ) );
558 connect( this, SIGNAL( todoModified( Todo *, int )), this, 558 connect( this, SIGNAL( todoModified( Todo *, int )), this,
559 SLOT( changeTodoDisplay( Todo *, int ) ) ); 559 SLOT( changeTodoDisplay( Todo *, int ) ) );
560 560
561 561
562 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); 562 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) );
563 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); 563 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) );
564 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); 564 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) );
565 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); 565 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) );
566 566
567 567
568 568
569 569
570 570
571 connect(QApplication::clipboard(),SIGNAL(dataChanged()), 571 connect(QApplication::clipboard(),SIGNAL(dataChanged()),
572 SLOT(checkClipboard())); 572 SLOT(checkClipboard()));
573 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), 573 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ),
574 SLOT( processTodoListSelection( Incidence * ) ) ); 574 SLOT( processTodoListSelection( Incidence * ) ) );
575 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); 575 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
576 576
577 // kdDebug() << "CalendarView::CalendarView() done" << endl; 577 // kdDebug() << "CalendarView::CalendarView() done" << endl;
578 578
579 mDateFrame = new QVBox(0,0,WType_Popup); 579 mDateFrame = new QVBox(0,0,WType_Popup);
580 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 580 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
581 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 581 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
582 mDateFrame->setLineWidth(3); 582 mDateFrame->setLineWidth(3);
583 mDateFrame->hide(); 583 mDateFrame->hide();
584 mDateFrame->setCaption( i18n( "Pick a date to display")); 584 mDateFrame->setCaption( i18n( "Pick a date to display"));
585 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); 585 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() );
586 586
587 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); 587 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate)));
588 588
589 mEventEditor = mDialogManager->getEventEditor(); 589 mEventEditor = mDialogManager->getEventEditor();
590 mTodoEditor = mDialogManager->getTodoEditor(); 590 mTodoEditor = mDialogManager->getTodoEditor();
591 591
592 mFlagEditDescription = false; 592 mFlagEditDescription = false;
593 593
594 mSuspendTimer = new QTimer( this ); 594 mSuspendTimer = new QTimer( this );
595 mAlarmTimer = new QTimer( this ); 595 mAlarmTimer = new QTimer( this );
596 mRecheckAlarmTimer = new QTimer( this ); 596 mRecheckAlarmTimer = new QTimer( this );
597 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); 597 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) );
598 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 598 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
599 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 599 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
600 mAlarmDialog = new AlarmDialog( this ); 600 mAlarmDialog = new AlarmDialog( this );
601 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 601 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
602 mAlarmDialog->setServerNotification( false ); 602 mAlarmDialog->setServerNotification( false );
603 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 603 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
604 604
605 605
606#ifndef DESKTOP_VERSION 606#ifndef DESKTOP_VERSION
607//US listen for arriving address resultsets 607//US listen for arriving address resultsets
608 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), 608 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)),
609 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); 609 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)));
610#endif 610#endif
611 mDateNavigator->setCalendar( mCalendar ); 611 mDateNavigator->setCalendar( mCalendar );
612} 612}
613 613
614 614
615CalendarView::~CalendarView() 615CalendarView::~CalendarView()
616{ 616{
617 // kdDebug() << "~CalendarView()" << endl; 617 // kdDebug() << "~CalendarView()" << endl;
618 //qDebug("CalendarView::~CalendarView() "); 618 //qDebug("CalendarView::~CalendarView() ");
619 delete mDialogManager; 619 delete mDialogManager;
620 delete mViewManager; 620 delete mViewManager;
621 delete mStorage; 621 delete mStorage;
622 delete mDateFrame ; 622 delete mDateFrame ;
623 delete beamDialog; 623 delete beamDialog;
624 delete mEventViewerDialog; 624 delete mEventViewerDialog;
625 //kdDebug() << "~CalendarView() done" << endl; 625 //kdDebug() << "~CalendarView() done" << endl;
626} 626}
627void CalendarView::checkAlarms() 627void CalendarView::checkAlarms()
628{ 628{
629 KConfig *config = KOGlobals::config(); 629 KConfig *config = KOGlobals::config();
630 config->setGroup( "AppRun" ); 630 config->setGroup( "AppRun" );
631 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 631 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
632 int secs = config->readNumEntry( "LatestProgramStop" ) - 30; 632 int secs = config->readNumEntry( "LatestProgramStop" ) - 30;
633 secs -= ( 3600 * 24*3 ); // debug only 633 secs -= ( 3600 * 24*3 ); // debug only
634 QDateTime latest = dt.addSecs ( secs ); 634 QDateTime latest = dt.addSecs ( secs );
635 qDebug("KO: Last termination on %s ", latest.toString().latin1()); 635 qDebug("KO: Last termination on %s ", latest.toString().latin1());
636 QPtrList<Incidence> el = mCalendar->rawIncidences(); 636 QPtrList<Incidence> el = mCalendar->rawIncidences();
637 QPtrList<Incidence> al; 637 QPtrList<Incidence> al;
638 Incidence* inL = el.first(); 638 Incidence* inL = el.first();
639 while ( inL ) { 639 while ( inL ) {
640 bool ok = false; 640 bool ok = false;
641 int offset = 0; 641 int offset = 0;
642 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ; 642 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ;
643 if ( ok ) { 643 if ( ok ) {
644 //qDebug("OK %s",next.toString().latin1()); 644 //qDebug("OK %s",next.toString().latin1());
645 if ( next < QDateTime::currentDateTime() ) { 645 if ( next < QDateTime::currentDateTime() ) {
646 al.append( inL ); 646 al.append( inL );
647 qDebug("found missed alarm: %s ", inL->summary().latin1() ); 647 qDebug("found missed alarm: %s ", inL->summary().latin1() );
648 } 648 }
649 } 649 }
650 inL = el.next(); 650 inL = el.next();
651 } 651 }
652 if ( al.count() ) { 652 if ( al.count() ) {
653 QDialog dia ( this, "huhu", true ); 653 QDialog* dia = new QDialog( this, "huhu", false );
654 dia.setCaption( i18n("KO/Pi: Missing alarm notification!") ); 654 dia->setCaption( i18n("KO/Pi: Missing alarm notification!") );
655 QVBoxLayout* lay = new QVBoxLayout( &dia ); 655 QVBoxLayout* lay = new QVBoxLayout( dia );
656 lay->setSpacing( 3 ); 656 lay->setSpacing( 0 );
657 lay->setMargin( 3 ); 657 lay->setMargin( 0 );
658 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( &dia, al, latest ); 658 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest );
659 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); 659 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) ));
660 lay->addWidget( matb ); 660 lay->addWidget( matb );
661 dia.resize(240,240); 661 int si = 220;
662 dia.exec(); 662 if ( QApplication::desktop()->width() > 470 )
663 si = 400;
664 dia->resize(si,si/2);
665 dia->setBackgroundColor( QColor( 255, 255, 255 ) );
666 dia->show();
663 667
664 } 668 }
665} 669}
666void CalendarView::showDay( QDate d ) 670void CalendarView::showDay( QDate d )
667{ 671{
668 dateNavigator()->blockSignals( true ); 672 dateNavigator()->blockSignals( true );
669 dateNavigator()->selectDate( d ); 673 dateNavigator()->selectDate( d );
670 dateNavigator()->blockSignals( false ); 674 dateNavigator()->blockSignals( false );
671 mViewManager->showDayView(); 675 mViewManager->showDayView();
672 //dateNavigator()->selectDate( d ); 676 //dateNavigator()->selectDate( d );
673} 677}
674void CalendarView::timerAlarm() 678void CalendarView::timerAlarm()
675{ 679{
676 //qDebug("CalendarView::timerAlarm() "); 680 //qDebug("CalendarView::timerAlarm() ");
677 computeAlarm(mAlarmNotification ); 681 computeAlarm(mAlarmNotification );
678} 682}
679 683
680void CalendarView::suspendAlarm() 684void CalendarView::suspendAlarm()
681{ 685{
682 //qDebug(" CalendarView::suspendAlarm() "); 686 //qDebug(" CalendarView::suspendAlarm() ");
683 computeAlarm(mSuspendAlarmNotification ); 687 computeAlarm(mSuspendAlarmNotification );
684 688
685} 689}
686 690
687void CalendarView::startAlarm( QString mess , QString filename) 691void CalendarView::startAlarm( QString mess , QString filename)
688{ 692{
689 693
690 topLevelWidget()->showNormal(); 694 topLevelWidget()->showNormal();
691 topLevelWidget()->setActiveWindow(); 695 topLevelWidget()->setActiveWindow();
692 topLevelWidget()->raise(); 696 topLevelWidget()->raise();
693 697
694 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 698 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
695 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); 699 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) );
696 700
697} 701}
698 702
699void CalendarView::checkNextTimerAlarm() 703void CalendarView::checkNextTimerAlarm()
700{ 704{
701 mCalendar->checkAlarmForIncidence( 0, true ); 705 mCalendar->checkAlarmForIncidence( 0, true );
702} 706}
703 707
704void CalendarView::computeAlarm( QString msg ) 708void CalendarView::computeAlarm( QString msg )
705{ 709{
706 710
707 QString mess = msg; 711 QString mess = msg;
708 QString mAlarmMessage = mess.mid( 9 ); 712 QString mAlarmMessage = mess.mid( 9 );
709 QString filename = MainWindow::resourcePath(); 713 QString filename = MainWindow::resourcePath();
710 filename += "koalarm.wav"; 714 filename += "koalarm.wav";
711 QString tempfilename; 715 QString tempfilename;
712 if ( mess.left( 13 ) == "suspend_alarm") { 716 if ( mess.left( 13 ) == "suspend_alarm") {
713 bool error = false; 717 bool error = false;
714 int len = mess.mid( 13 ).find("+++"); 718 int len = mess.mid( 13 ).find("+++");
715 if ( len < 2 ) 719 if ( len < 2 )
716 error = true; 720 error = true;
717 else { 721 else {
718 tempfilename = mess.mid( 13, len ); 722 tempfilename = mess.mid( 13, len );
719 if ( !QFile::exists( tempfilename ) ) 723 if ( !QFile::exists( tempfilename ) )
720 error = true; 724 error = true;
721 } 725 }
722 if ( ! error ) { 726 if ( ! error ) {
723 filename = tempfilename; 727 filename = tempfilename;
724 } 728 }
725 mAlarmMessage = mess.mid( 13+len+3 ); 729 mAlarmMessage = mess.mid( 13+len+3 );
726 //qDebug("suspend file %s ",tempfilename.latin1() ); 730 //qDebug("suspend file %s ",tempfilename.latin1() );
727 startAlarm( mAlarmMessage, filename); 731 startAlarm( mAlarmMessage, filename);
728 return; 732 return;
729 } 733 }
730 if ( mess.left( 11 ) == "timer_alarm") { 734 if ( mess.left( 11 ) == "timer_alarm") {
731 //mTimerTime = 0; 735 //mTimerTime = 0;
732 startAlarm( mess.mid( 11 ), filename ); 736 startAlarm( mess.mid( 11 ), filename );
733 return; 737 return;
734 } 738 }
735 if ( mess.left( 10 ) == "proc_alarm") { 739 if ( mess.left( 10 ) == "proc_alarm") {
736 bool error = false; 740 bool error = false;
737 int len = mess.mid( 10 ).find("+++"); 741 int len = mess.mid( 10 ).find("+++");
738 if ( len < 2 ) 742 if ( len < 2 )
739 error = true; 743 error = true;
740 else { 744 else {
741 tempfilename = mess.mid( 10, len ); 745 tempfilename = mess.mid( 10, len );
742 if ( !QFile::exists( tempfilename ) ) 746 if ( !QFile::exists( tempfilename ) )
743 error = true; 747 error = true;
744 } 748 }
745 if ( error ) { 749 if ( error ) {
746 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 750 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
747 mAlarmMessage += mess.mid( 10+len+3+9 ); 751 mAlarmMessage += mess.mid( 10+len+3+9 );
748 } else { 752 } else {
749 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 753 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
750 //qDebug("-----system command %s ",tempfilename.latin1() ); 754 //qDebug("-----system command %s ",tempfilename.latin1() );
751#ifndef _WIN32_ 755#ifndef _WIN32_
752 if ( vfork () == 0 ) { 756 if ( vfork () == 0 ) {
753 execl ( tempfilename.latin1(), 0 ); 757 execl ( tempfilename.latin1(), 0 );
754 return; 758 return;
755 } 759 }
756#else 760#else
757 QProcess* p = new QProcess(); 761 QProcess* p = new QProcess();
758 p->addArgument( tempfilename.latin1() ); 762 p->addArgument( tempfilename.latin1() );
759 p->start(); 763 p->start();
760 return; 764 return;
761#endif 765#endif
762 766
763 return; 767 return;
764 } 768 }
765 769
766 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 770 //qDebug("+++++++system command %s ",tempfilename.latin1() );
767 } 771 }
768 if ( mess.left( 11 ) == "audio_alarm") { 772 if ( mess.left( 11 ) == "audio_alarm") {
769 bool error = false; 773 bool error = false;
770 int len = mess.mid( 11 ).find("+++"); 774 int len = mess.mid( 11 ).find("+++");
771 if ( len < 2 ) 775 if ( len < 2 )
772 error = true; 776 error = true;
773 else { 777 else {
774 tempfilename = mess.mid( 11, len ); 778 tempfilename = mess.mid( 11, len );
775 if ( !QFile::exists( tempfilename ) ) 779 if ( !QFile::exists( tempfilename ) )
776 error = true; 780 error = true;
777 } 781 }
778 if ( ! error ) { 782 if ( ! error ) {
779 filename = tempfilename; 783 filename = tempfilename;
780 } 784 }
781 mAlarmMessage = mess.mid( 11+len+3+9 ); 785 mAlarmMessage = mess.mid( 11+len+3+9 );
782 //qDebug("audio file command %s ",tempfilename.latin1() ); 786 //qDebug("audio file command %s ",tempfilename.latin1() );
783 } 787 }
784 if ( mess.left( 9 ) == "cal_alarm") { 788 if ( mess.left( 9 ) == "cal_alarm") {
785 mAlarmMessage = mess.mid( 9 ) ; 789 mAlarmMessage = mess.mid( 9 ) ;
786 } 790 }
787 791
788 startAlarm( mAlarmMessage, filename ); 792 startAlarm( mAlarmMessage, filename );
789 793
790 794
791} 795}
792 796
793void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 797void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
794{ 798{
795 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 799 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
796 800
797 mSuspendAlarmNotification = noti; 801 mSuspendAlarmNotification = noti;
798 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 802 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
799 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 803 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
800 mSuspendTimer->start( ms , true ); 804 mSuspendTimer->start( ms , true );
801 805
802} 806}
803 807
804void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 808void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
805{ 809{
806 mNextAlarmDateTime = qdt; 810 mNextAlarmDateTime = qdt;
807 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 811 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
808 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 812 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
809#ifndef DESKTOP_VERSION 813#ifndef DESKTOP_VERSION
810 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); 814 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() );
811#endif 815#endif
812 return; 816 return;
813 } 817 }
814 int maxSec; 818 int maxSec;
815 //maxSec = 5; //testing only 819 //maxSec = 5; //testing only
816 maxSec = 86400+3600; // one day+1hour 820 maxSec = 86400+3600; // one day+1hour
817 mAlarmNotification = noti; 821 mAlarmNotification = noti;
818 int sec = QDateTime::currentDateTime().secsTo( qdt ); 822 int sec = QDateTime::currentDateTime().secsTo( qdt );
819 if ( sec > maxSec ) { 823 if ( sec > maxSec ) {
820 mRecheckAlarmTimer->start( maxSec * 1000 ); 824 mRecheckAlarmTimer->start( maxSec * 1000 );
821 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 825 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
822 return; 826 return;
823 } else { 827 } else {
824 mRecheckAlarmTimer->stop(); 828 mRecheckAlarmTimer->stop();
825 } 829 }
826 //qDebug("Alarm timer started with secs: %d ", sec); 830 //qDebug("Alarm timer started with secs: %d ", sec);
827 mAlarmTimer->start( sec *1000 , true ); 831 mAlarmTimer->start( sec *1000 , true );
828 832
829} 833}
830// called by mRecheckAlarmTimer to get next alarm 834// called by mRecheckAlarmTimer to get next alarm
831// we need this, because a QTimer has only a max range of 25 days 835// we need this, because a QTimer has only a max range of 25 days
832void CalendarView::recheckTimerAlarm() 836void CalendarView::recheckTimerAlarm()
833{ 837{
834 mAlarmTimer->stop(); 838 mAlarmTimer->stop();
835 mRecheckAlarmTimer->stop(); 839 mRecheckAlarmTimer->stop();
836 mCalendar->checkAlarmForIncidence( 0, true ); 840 mCalendar->checkAlarmForIncidence( 0, true );
837} 841}
838void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 842void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
839{ 843{
840 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 844 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
841 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 845 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
842#ifndef DESKTOP_VERSION 846#ifndef DESKTOP_VERSION
843 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 847 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
844#endif 848#endif
845 return; 849 return;
846 } 850 }
847 mAlarmTimer->stop(); 851 mAlarmTimer->stop();
848} 852}
849void CalendarView::selectWeekNum ( int num ) 853void CalendarView::selectWeekNum ( int num )
850{ 854{
851 dateNavigator()->blockSignals( true ); 855 dateNavigator()->blockSignals( true );
852 dateNavigator()->selectWeek( num ); 856 dateNavigator()->selectWeek( num );
853 dateNavigator()->blockSignals( false ); 857 dateNavigator()->blockSignals( false );
854 mViewManager->showWeekView(); 858 mViewManager->showWeekView();
855} 859}
856KOViewManager *CalendarView::viewManager() 860KOViewManager *CalendarView::viewManager()
857{ 861{
858 return mViewManager; 862 return mViewManager;
859} 863}
860 864
861KODialogManager *CalendarView::dialogManager() 865KODialogManager *CalendarView::dialogManager()
862{ 866{
863 return mDialogManager; 867 return mDialogManager;
864} 868}
865 869
866QDate CalendarView::startDate() 870QDate CalendarView::startDate()
867{ 871{
868 DateList dates = mNavigator->selectedDates(); 872 DateList dates = mNavigator->selectedDates();
869 873
870 return dates.first(); 874 return dates.first();
871} 875}
872 876
873QDate CalendarView::endDate() 877QDate CalendarView::endDate()
874{ 878{
875 DateList dates = mNavigator->selectedDates(); 879 DateList dates = mNavigator->selectedDates();
876 880
877 return dates.last(); 881 return dates.last();
878} 882}
879 883
880 884
881void CalendarView::createPrinter() 885void CalendarView::createPrinter()
882{ 886{
883#ifndef KORG_NOPRINTER 887#ifndef KORG_NOPRINTER
884 if (!mCalPrinter) { 888 if (!mCalPrinter) {
885 mCalPrinter = new CalPrinter(this, mCalendar); 889 mCalPrinter = new CalPrinter(this, mCalendar);
886 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 890 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
887 } 891 }
888#endif 892#endif
889} 893}
890 894
891 895
892//KOPrefs::instance()->mWriteBackFile 896//KOPrefs::instance()->mWriteBackFile
893//KOPrefs::instance()->mWriteBackExistingOnly 897//KOPrefs::instance()->mWriteBackExistingOnly
894 898
895// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 899// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
896// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 900// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
897// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 901// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
898// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 902// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
899// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 903// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
900// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 904// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
901 905
902int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 906int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
903{ 907{
904 908
905 // 0 equal 909 // 0 equal
906 // 1 take local 910 // 1 take local
907 // 2 take remote 911 // 2 take remote
908 // 3 cancel 912 // 3 cancel
909 QDateTime lastSync = mLastCalendarSync; 913 QDateTime lastSync = mLastCalendarSync;
910 QDateTime localMod = local->lastModified(); 914 QDateTime localMod = local->lastModified();
911 QDateTime remoteMod = remote->lastModified(); 915 QDateTime remoteMod = remote->lastModified();
912 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 916 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
913 bool remCh, locCh; 917 bool remCh, locCh;
914 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 918 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
915 //if ( remCh ) 919 //if ( remCh )
916 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 920 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
917 locCh = ( localMod > mLastCalendarSync ); 921 locCh = ( localMod > mLastCalendarSync );
918 if ( !remCh && ! locCh ) { 922 if ( !remCh && ! locCh ) {
919 //qDebug("both not changed "); 923 //qDebug("both not changed ");
920 lastSync = localMod.addDays(1); 924 lastSync = localMod.addDays(1);
921 if ( mode <= SYNC_PREF_ASK ) 925 if ( mode <= SYNC_PREF_ASK )
922 return 0; 926 return 0;
923 } else { 927 } else {
924 if ( locCh ) { 928 if ( locCh ) {
925 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 929 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
926 lastSync = localMod.addDays( -1 ); 930 lastSync = localMod.addDays( -1 );
927 if ( !remCh ) 931 if ( !remCh )
928 remoteMod = ( lastSync.addDays( -1 ) ); 932 remoteMod = ( lastSync.addDays( -1 ) );
929 } else { 933 } else {
930 //qDebug(" not loc changed "); 934 //qDebug(" not loc changed ");
931 lastSync = localMod.addDays( 1 ); 935 lastSync = localMod.addDays( 1 );
932 if ( remCh ) 936 if ( remCh )
933 remoteMod =( lastSync.addDays( 1 ) ); 937 remoteMod =( lastSync.addDays( 1 ) );
934 938
935 } 939 }
936 } 940 }
937 full = true; 941 full = true;
938 if ( mode < SYNC_PREF_ASK ) 942 if ( mode < SYNC_PREF_ASK )
939 mode = SYNC_PREF_ASK; 943 mode = SYNC_PREF_ASK;
940 } else { 944 } else {
941 if ( localMod == remoteMod ) 945 if ( localMod == remoteMod )
942 // if ( local->revision() == remote->revision() ) 946 // if ( local->revision() == remote->revision() )
943 return 0; 947 return 0;
944 948
945 } 949 }
946 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 950 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
947 951
948 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 952 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
949 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 953 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
950 //full = true; //debug only 954 //full = true; //debug only
951 if ( full ) { 955 if ( full ) {
952 bool equ = false; 956 bool equ = false;
953 if ( local->type() == "Event" ) { 957 if ( local->type() == "Event" ) {
954 equ = (*((Event*) local) == *((Event*) remote)); 958 equ = (*((Event*) local) == *((Event*) remote));
955 } 959 }
956 else if ( local->type() =="Todo" ) 960 else if ( local->type() =="Todo" )
957 equ = (*((Todo*) local) == (*(Todo*) remote)); 961 equ = (*((Todo*) local) == (*(Todo*) remote));
958 else if ( local->type() =="Journal" ) 962 else if ( local->type() =="Journal" )
959 equ = (*((Journal*) local) == *((Journal*) remote)); 963 equ = (*((Journal*) local) == *((Journal*) remote));
960 if ( equ ) { 964 if ( equ ) {
961 //qDebug("equal "); 965 //qDebug("equal ");
962 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 966 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
963 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 967 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
964 } 968 }
965 if ( mode < SYNC_PREF_FORCE_LOCAL ) 969 if ( mode < SYNC_PREF_FORCE_LOCAL )
966 return 0; 970 return 0;
967 971
968 }//else //debug only 972 }//else //debug only
969 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 973 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
970 } 974 }
971 int result; 975 int result;
972 bool localIsNew; 976 bool localIsNew;
973 //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() ); 977 //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() );
974 978
975 979
976 // ************************************************ 980 // ************************************************
977 // ************************************************ 981 // ************************************************
978 // ************************************************ 982 // ************************************************
979 // We may have that lastSync > remoteMod AND lastSync > localMod 983 // We may have that lastSync > remoteMod AND lastSync > localMod
980 // BUT remoteMod != localMod 984 // BUT remoteMod != localMod
981 985
982 986
983 if ( full && mode < SYNC_PREF_NEWEST ) 987 if ( full && mode < SYNC_PREF_NEWEST )
984 mode = SYNC_PREF_ASK; 988 mode = SYNC_PREF_ASK;
985 989
986 switch( mode ) { 990 switch( mode ) {
987 case SYNC_PREF_LOCAL: 991 case SYNC_PREF_LOCAL:
988 if ( lastSync > remoteMod ) 992 if ( lastSync > remoteMod )
989 return 1; 993 return 1;
990 if ( lastSync > localMod ) 994 if ( lastSync > localMod )
991 return 2; 995 return 2;
992 return 1; 996 return 1;
993 break; 997 break;
994 case SYNC_PREF_REMOTE: 998 case SYNC_PREF_REMOTE:
995 if ( lastSync > localMod ) 999 if ( lastSync > localMod )
996 return 2; 1000 return 2;
997 if ( lastSync > remoteMod ) 1001 if ( lastSync > remoteMod )
998 return 1; 1002 return 1;
999 return 2; 1003 return 2;
1000 break; 1004 break;
1001 case SYNC_PREF_NEWEST: 1005 case SYNC_PREF_NEWEST:
1002 if ( localMod >= remoteMod ) 1006 if ( localMod >= remoteMod )
1003 return 1; 1007 return 1;
1004 else 1008 else
1005 return 2; 1009 return 2;
1006 break; 1010 break;
1007 case SYNC_PREF_ASK: 1011 case SYNC_PREF_ASK:
1008 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1012 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1009 if ( lastSync > remoteMod && lastSync > localMod) 1013 if ( lastSync > remoteMod && lastSync > localMod)
1010 return 0; 1014 return 0;
1011 if ( lastSync > remoteMod ) 1015 if ( lastSync > remoteMod )
1012 return 1; 1016 return 1;
1013 if ( lastSync > localMod ) 1017 if ( lastSync > localMod )
1014 return 2; 1018 return 2;
1015 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1019 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1016 localIsNew = localMod >= remoteMod; 1020 localIsNew = localMod >= remoteMod;
1017 if ( localIsNew ) 1021 if ( localIsNew )
1018 getEventViewerDialog()->setColorMode( 1 ); 1022 getEventViewerDialog()->setColorMode( 1 );
1019 else 1023 else
1020 getEventViewerDialog()->setColorMode( 2 ); 1024 getEventViewerDialog()->setColorMode( 2 );
1021 getEventViewerDialog()->setIncidence(local); 1025 getEventViewerDialog()->setIncidence(local);
1022 if ( localIsNew ) 1026 if ( localIsNew )
1023 getEventViewerDialog()->setColorMode( 2 ); 1027 getEventViewerDialog()->setColorMode( 2 );
1024 else 1028 else
1025 getEventViewerDialog()->setColorMode( 1 ); 1029 getEventViewerDialog()->setColorMode( 1 );
1026 getEventViewerDialog()->addIncidence(remote); 1030 getEventViewerDialog()->addIncidence(remote);
1027 getEventViewerDialog()->setColorMode( 0 ); 1031 getEventViewerDialog()->setColorMode( 0 );
1028 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 1032 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
1029 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 1033 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
1030 getEventViewerDialog()->showMe(); 1034 getEventViewerDialog()->showMe();
1031 result = getEventViewerDialog()->executeS( localIsNew ); 1035 result = getEventViewerDialog()->executeS( localIsNew );
1032 return result; 1036 return result;
1033 1037
1034 break; 1038 break;
1035 case SYNC_PREF_FORCE_LOCAL: 1039 case SYNC_PREF_FORCE_LOCAL:
1036 return 1; 1040 return 1;
1037 break; 1041 break;
1038 case SYNC_PREF_FORCE_REMOTE: 1042 case SYNC_PREF_FORCE_REMOTE:
1039 return 2; 1043 return 2;
1040 break; 1044 break;
1041 1045
1042 default: 1046 default:
1043 // SYNC_PREF_TAKE_BOTH not implemented 1047 // SYNC_PREF_TAKE_BOTH not implemented
1044 break; 1048 break;
1045 } 1049 }
1046 return 0; 1050 return 0;
1047} 1051}
1048Event* CalendarView::getLastSyncEvent() 1052Event* CalendarView::getLastSyncEvent()
1049{ 1053{
1050 Event* lse; 1054 Event* lse;
1051 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 1055 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
1052 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 1056 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
1053 if (!lse) { 1057 if (!lse) {
1054 lse = new Event(); 1058 lse = new Event();
1055 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 1059 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
1056 QString sum = ""; 1060 QString sum = "";
1057 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 1061 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
1058 sum = "E: "; 1062 sum = "E: ";
1059 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 1063 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
1060 lse->setDtStart( mLastCalendarSync ); 1064 lse->setDtStart( mLastCalendarSync );
1061 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1065 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1062 lse->setCategories( i18n("SyncEvent") ); 1066 lse->setCategories( i18n("SyncEvent") );
1063 lse->setReadOnly( true ); 1067 lse->setReadOnly( true );
1064 mCalendar->addEvent( lse ); 1068 mCalendar->addEvent( lse );
1065 } 1069 }
1066 1070
1067 return lse; 1071 return lse;
1068 1072
1069} 1073}
1070 1074
1071// we check, if the to delete event has a id for a profile 1075// we check, if the to delete event has a id for a profile
1072// if yes, we set this id in the profile to delete 1076// if yes, we set this id in the profile to delete
1073void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 1077void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
1074{ 1078{
1075 if ( lastSync.count() == 0 ) { 1079 if ( lastSync.count() == 0 ) {
1076 //qDebug(" lastSync.count() == 0"); 1080 //qDebug(" lastSync.count() == 0");
1077 return; 1081 return;
1078 } 1082 }
1079 if ( toDelete->type() == "Journal" ) 1083 if ( toDelete->type() == "Journal" )
1080 return; 1084 return;
1081 1085
1082 Event* eve = lastSync.first(); 1086 Event* eve = lastSync.first();
1083 1087
1084 while ( eve ) { 1088 while ( eve ) {
1085 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 1089 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
1086 if ( !id.isEmpty() ) { 1090 if ( !id.isEmpty() ) {
1087 QString des = eve->description(); 1091 QString des = eve->description();
1088 QString pref = "e"; 1092 QString pref = "e";
1089 if ( toDelete->type() == "Todo" ) 1093 if ( toDelete->type() == "Todo" )
1090 pref = "t"; 1094 pref = "t";
1091 des += pref+ id + ","; 1095 des += pref+ id + ",";
1092 eve->setReadOnly( false ); 1096 eve->setReadOnly( false );
1093 eve->setDescription( des ); 1097 eve->setDescription( des );
1094 //qDebug("setdes %s ", des.latin1()); 1098 //qDebug("setdes %s ", des.latin1());
1095 eve->setReadOnly( true ); 1099 eve->setReadOnly( true );
1096 } 1100 }
1097 eve = lastSync.next(); 1101 eve = lastSync.next();
1098 } 1102 }
1099 1103
1100} 1104}
1101void CalendarView::checkExternalId( Incidence * inc ) 1105void CalendarView::checkExternalId( Incidence * inc )
1102{ 1106{
1103 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 1107 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
1104 checkExternSyncEvent( lastSync, inc ); 1108 checkExternSyncEvent( lastSync, inc );
1105 1109
1106} 1110}
1107bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 1111bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
1108{ 1112{
1109 bool syncOK = true; 1113 bool syncOK = true;
1110 int addedEvent = 0; 1114 int addedEvent = 0;
1111 int addedEventR = 0; 1115 int addedEventR = 0;
1112 int deletedEventR = 0; 1116 int deletedEventR = 0;
1113 int deletedEventL = 0; 1117 int deletedEventL = 0;
1114 int changedLocal = 0; 1118 int changedLocal = 0;
1115 int changedRemote = 0; 1119 int changedRemote = 0;
1116 int filteredIN = 0; 1120 int filteredIN = 0;
1117 int filteredOUT = 0; 1121 int filteredOUT = 0;
1118 //QPtrList<Event> el = local->rawEvents(); 1122 //QPtrList<Event> el = local->rawEvents();
1119 Event* eventR; 1123 Event* eventR;
1120 QString uid; 1124 QString uid;
1121 int take; 1125 int take;
1122 Event* eventL; 1126 Event* eventL;
1123 Event* eventRSync; 1127 Event* eventRSync;
1124 Event* eventLSync; 1128 Event* eventLSync;
1125 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 1129 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
1126 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 1130 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
1127 bool fullDateRange = false; 1131 bool fullDateRange = false;
1128 local->resetTempSyncStat(); 1132 local->resetTempSyncStat();
1129 mLastCalendarSync = QDateTime::currentDateTime(); 1133 mLastCalendarSync = QDateTime::currentDateTime();
1130 if ( mSyncManager->syncWithDesktop() ) { 1134 if ( mSyncManager->syncWithDesktop() ) {
1131 remote->resetPilotStat(1); 1135 remote->resetPilotStat(1);
1132 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1136 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1133 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 1137 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
1134 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 1138 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
1135 } else { 1139 } else {
1136 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 1140 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
1137 } 1141 }
1138 } 1142 }
1139 QDateTime modifiedCalendar = mLastCalendarSync; 1143 QDateTime modifiedCalendar = mLastCalendarSync;
1140 eventLSync = getLastSyncEvent(); 1144 eventLSync = getLastSyncEvent();
1141 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 1145 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
1142 if ( eventR ) { 1146 if ( eventR ) {
1143 eventRSync = (Event*) eventR->clone(); 1147 eventRSync = (Event*) eventR->clone();
1144 remote->deleteEvent(eventR ); 1148 remote->deleteEvent(eventR );
1145 1149
1146 } else { 1150 } else {
1147 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 1151 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
1148 eventRSync = (Event*)eventLSync->clone(); 1152 eventRSync = (Event*)eventLSync->clone();
1149 } else { 1153 } else {
1150 fullDateRange = true; 1154 fullDateRange = true;
1151 eventRSync = new Event(); 1155 eventRSync = new Event();
1152 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 1156 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
1153 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 1157 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
1154 eventRSync->setDtStart( mLastCalendarSync ); 1158 eventRSync->setDtStart( mLastCalendarSync );
1155 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1159 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1156 eventRSync->setCategories( i18n("SyncEvent") ); 1160 eventRSync->setCategories( i18n("SyncEvent") );
1157 } 1161 }
1158 } 1162 }
1159 if ( eventLSync->dtStart() == mLastCalendarSync ) 1163 if ( eventLSync->dtStart() == mLastCalendarSync )
1160 fullDateRange = true; 1164 fullDateRange = true;
1161 1165
1162 if ( ! fullDateRange ) { 1166 if ( ! fullDateRange ) {
1163 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 1167 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
1164 1168
1165 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 1169 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
1166 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 1170 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
1167 fullDateRange = true; 1171 fullDateRange = true;
1168 } 1172 }
1169 } 1173 }
1170 if ( mSyncManager->syncWithDesktop() ) { 1174 if ( mSyncManager->syncWithDesktop() ) {
1171 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 1175 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
1172 } 1176 }
1173 if ( fullDateRange ) 1177 if ( fullDateRange )
1174 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 1178 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
1175 else 1179 else
1176 mLastCalendarSync = eventLSync->dtStart(); 1180 mLastCalendarSync = eventLSync->dtStart();
1177 // for resyncing if own file has changed 1181 // for resyncing if own file has changed
1178 if ( mCurrentSyncDevice == "deleteaftersync" ) { 1182 if ( mCurrentSyncDevice == "deleteaftersync" ) {
1179 mLastCalendarSync = loadedFileVersion; 1183 mLastCalendarSync = loadedFileVersion;
1180 //qDebug("setting mLastCalendarSync "); 1184 //qDebug("setting mLastCalendarSync ");
1181 } 1185 }
1182 //qDebug("*************************** "); 1186 //qDebug("*************************** ");
1183 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1187 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1184 QPtrList<Incidence> er = remote->rawIncidences(); 1188 QPtrList<Incidence> er = remote->rawIncidences();
1185 Incidence* inR = er.first(); 1189 Incidence* inR = er.first();
1186 Incidence* inL; 1190 Incidence* inL;
1187 QProgressBar bar( er.count(),0 ); 1191 QProgressBar bar( er.count(),0 );
1188 bar.setCaption (i18n("Syncing - close to abort!") ); 1192 bar.setCaption (i18n("Syncing - close to abort!") );
1189 1193
1190 // ************** setting up filter ************* 1194 // ************** setting up filter *************
1191 CalFilter *filterIN = 0; 1195 CalFilter *filterIN = 0;
1192 CalFilter *filterOUT = 0; 1196 CalFilter *filterOUT = 0;
1193 CalFilter *filter = mFilters.first(); 1197 CalFilter *filter = mFilters.first();
1194 while(filter) { 1198 while(filter) {
1195 if ( filter->name() == mSyncManager->mFilterInCal ) 1199 if ( filter->name() == mSyncManager->mFilterInCal )
1196 filterIN = filter; 1200 filterIN = filter;
1197 if ( filter->name() == mSyncManager->mFilterOutCal ) 1201 if ( filter->name() == mSyncManager->mFilterOutCal )
1198 filterOUT = filter; 1202 filterOUT = filter;
1199 filter = mFilters.next(); 1203 filter = mFilters.next();
1200 } 1204 }
1201 int w = 300; 1205 int w = 300;
1202 if ( QApplication::desktop()->width() < 320 ) 1206 if ( QApplication::desktop()->width() < 320 )
1203 w = 220; 1207 w = 220;
1204 int h = bar.sizeHint().height() ; 1208 int h = bar.sizeHint().height() ;
1205 int dw = QApplication::desktop()->width(); 1209 int dw = QApplication::desktop()->width();
1206 int dh = QApplication::desktop()->height(); 1210 int dh = QApplication::desktop()->height();
1207 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1211 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1208 bar.show(); 1212 bar.show();
1209 int modulo = (er.count()/10)+1; 1213 int modulo = (er.count()/10)+1;
1210 int incCounter = 0; 1214 int incCounter = 0;
1211 while ( inR ) { 1215 while ( inR ) {
1212 if ( ! bar.isVisible() ) 1216 if ( ! bar.isVisible() )
1213 return false; 1217 return false;
1214 if ( incCounter % modulo == 0 ) 1218 if ( incCounter % modulo == 0 )
1215 bar.setProgress( incCounter ); 1219 bar.setProgress( incCounter );
1216 ++incCounter; 1220 ++incCounter;
1217 uid = inR->uid(); 1221 uid = inR->uid();
1218 bool skipIncidence = false; 1222 bool skipIncidence = false;
1219 if ( uid.left(15) == QString("last-syncEvent-") ) 1223 if ( uid.left(15) == QString("last-syncEvent-") )
1220 skipIncidence = true; 1224 skipIncidence = true;
1221 QString idS; 1225 QString idS;
1222 qApp->processEvents(); 1226 qApp->processEvents();
1223 if ( !skipIncidence ) { 1227 if ( !skipIncidence ) {
1224 inL = local->incidence( uid ); 1228 inL = local->incidence( uid );
1225 if ( inL ) { // maybe conflict - same uid in both calendars 1229 if ( inL ) { // maybe conflict - same uid in both calendars
1226 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1230 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1227 //qDebug("take %d %s ", take, inL->summary().latin1()); 1231 //qDebug("take %d %s ", take, inL->summary().latin1());
1228 if ( take == 3 ) 1232 if ( take == 3 )
1229 return false; 1233 return false;
1230 if ( take == 1 ) {// take local ********************** 1234 if ( take == 1 ) {// take local **********************
1231 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1235 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1232 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1236 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1233 else 1237 else
1234 idS = inR->IDStr(); 1238 idS = inR->IDStr();
1235 remote->deleteIncidence( inR ); 1239 remote->deleteIncidence( inR );
1236 inR = inL->clone(); 1240 inR = inL->clone();
1237 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1241 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1238 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1242 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1239 inR->setIDStr( idS ); 1243 inR->setIDStr( idS );
1240 remote->addIncidence( inR ); 1244 remote->addIncidence( inR );
1241 if ( mSyncManager->syncWithDesktop() ) 1245 if ( mSyncManager->syncWithDesktop() )
1242 inR->setPilotId( 2 ); 1246 inR->setPilotId( 2 );
1243 ++changedRemote; 1247 ++changedRemote;
1244 } else {// take remote ********************** 1248 } else {// take remote **********************
1245 idS = inL->IDStr(); 1249 idS = inL->IDStr();
1246 int pid = inL->pilotId(); 1250 int pid = inL->pilotId();
1247 local->deleteIncidence( inL ); 1251 local->deleteIncidence( inL );
1248 inL = inR->clone(); 1252 inL = inR->clone();
1249 if ( mSyncManager->syncWithDesktop() ) 1253 if ( mSyncManager->syncWithDesktop() )
1250 inL->setPilotId( pid ); 1254 inL->setPilotId( pid );
1251 inL->setIDStr( idS ); 1255 inL->setIDStr( idS );
1252 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1256 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1253 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1257 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1254 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1258 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1255 } 1259 }
1256 local->addIncidence( inL ); 1260 local->addIncidence( inL );
1257 ++changedLocal; 1261 ++changedLocal;
1258 } 1262 }
1259 } 1263 }
1260 } else { // no conflict ********** add or delete remote 1264 } else { // no conflict ********** add or delete remote
1261 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1265 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1262 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1266 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1263 QString des = eventLSync->description(); 1267 QString des = eventLSync->description();
1264 QString pref = "e"; 1268 QString pref = "e";
1265 if ( inR->type() == "Todo" ) 1269 if ( inR->type() == "Todo" )
1266 pref = "t"; 1270 pref = "t";
1267 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1271 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1268 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1272 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1269 //remote->deleteIncidence( inR ); 1273 //remote->deleteIncidence( inR );
1270 ++deletedEventR; 1274 ++deletedEventR;
1271 } else { 1275 } else {
1272 inR->setLastModified( modifiedCalendar ); 1276 inR->setLastModified( modifiedCalendar );
1273 inL = inR->clone(); 1277 inL = inR->clone();
1274 inL->setIDStr( ":" ); 1278 inL->setIDStr( ":" );
1275 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1279 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1276 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1280 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1277 local->addIncidence( inL ); 1281 local->addIncidence( inL );
1278 ++addedEvent; 1282 ++addedEvent;
1279 1283
1280 } 1284 }
1281 } else { 1285 } else {
1282 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1286 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1283 inR->setLastModified( modifiedCalendar ); 1287 inR->setLastModified( modifiedCalendar );
1284 inL = inR->clone(); 1288 inL = inR->clone();
1285 inL->setIDStr( ":" ); 1289 inL->setIDStr( ":" );
1286 local->addIncidence( inL ); 1290 local->addIncidence( inL );
1287 ++addedEvent; 1291 ++addedEvent;
1288 1292
1289 } else { 1293 } else {
1290 checkExternSyncEvent(eventRSyncSharp, inR); 1294 checkExternSyncEvent(eventRSyncSharp, inR);
1291 remote->deleteIncidence( inR ); 1295 remote->deleteIncidence( inR );
1292 ++deletedEventR; 1296 ++deletedEventR;
1293 } 1297 }
1294 } 1298 }
1295 } else { 1299 } else {
1296 ++filteredIN; 1300 ++filteredIN;
1297 } 1301 }
1298 } 1302 }
1299 } 1303 }
1300 inR = er.next(); 1304 inR = er.next();
1301 } 1305 }
1302 QPtrList<Incidence> el = local->rawIncidences(); 1306 QPtrList<Incidence> el = local->rawIncidences();
1303 inL = el.first(); 1307 inL = el.first();
1304 modulo = (el.count()/10)+1; 1308 modulo = (el.count()/10)+1;
1305 bar.setCaption (i18n("Add / remove events") ); 1309 bar.setCaption (i18n("Add / remove events") );
1306 bar.setTotalSteps ( el.count() ) ; 1310 bar.setTotalSteps ( el.count() ) ;
1307 bar.show(); 1311 bar.show();
1308 incCounter = 0; 1312 incCounter = 0;
1309 1313
1310 while ( inL ) { 1314 while ( inL ) {
1311 1315
1312 qApp->processEvents(); 1316 qApp->processEvents();
1313 if ( ! bar.isVisible() ) 1317 if ( ! bar.isVisible() )
1314 return false; 1318 return false;
1315 if ( incCounter % modulo == 0 ) 1319 if ( incCounter % modulo == 0 )
1316 bar.setProgress( incCounter ); 1320 bar.setProgress( incCounter );
1317 ++incCounter; 1321 ++incCounter;
1318 uid = inL->uid(); 1322 uid = inL->uid();
1319 bool skipIncidence = false; 1323 bool skipIncidence = false;
1320 if ( uid.left(15) == QString("last-syncEvent-") ) 1324 if ( uid.left(15) == QString("last-syncEvent-") )
1321 skipIncidence = true; 1325 skipIncidence = true;
1322 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1326 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1323 skipIncidence = true; 1327 skipIncidence = true;
1324 if ( !skipIncidence ) { 1328 if ( !skipIncidence ) {
1325 inR = remote->incidence( uid ); 1329 inR = remote->incidence( uid );
1326 if ( ! inR ) { 1330 if ( ! inR ) {
1327 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1331 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1328 // no conflict ********** add or delete local 1332 // no conflict ********** add or delete local
1329 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1333 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1330 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1334 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1331 checkExternSyncEvent(eventLSyncSharp, inL); 1335 checkExternSyncEvent(eventLSyncSharp, inL);
1332 local->deleteIncidence( inL ); 1336 local->deleteIncidence( inL );
1333 ++deletedEventL; 1337 ++deletedEventL;
1334 } else { 1338 } else {
1335 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1339 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1336 inL->removeID(mCurrentSyncDevice ); 1340 inL->removeID(mCurrentSyncDevice );
1337 ++addedEventR; 1341 ++addedEventR;
1338 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1342 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1339 inL->setLastModified( modifiedCalendar ); 1343 inL->setLastModified( modifiedCalendar );
1340 inR = inL->clone(); 1344 inR = inL->clone();
1341 inR->setIDStr( ":" ); 1345 inR->setIDStr( ":" );
1342 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1346 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1343 remote->addIncidence( inR ); 1347 remote->addIncidence( inR );
1344 } 1348 }
1345 } 1349 }
1346 } else { 1350 } else {
1347 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1351 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1348 checkExternSyncEvent(eventLSyncSharp, inL); 1352 checkExternSyncEvent(eventLSyncSharp, inL);
1349 local->deleteIncidence( inL ); 1353 local->deleteIncidence( inL );
1350 ++deletedEventL; 1354 ++deletedEventL;
1351 } else { 1355 } else {
1352 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1356 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1353 ++addedEventR; 1357 ++addedEventR;
1354 inL->setLastModified( modifiedCalendar ); 1358 inL->setLastModified( modifiedCalendar );
1355 inR = inL->clone(); 1359 inR = inL->clone();
1356 inR->setIDStr( ":" ); 1360 inR->setIDStr( ":" );
1357 remote->addIncidence( inR ); 1361 remote->addIncidence( inR );
1358 } 1362 }
1359 } 1363 }
1360 } 1364 }
1361 } else { 1365 } else {
1362 ++filteredOUT; 1366 ++filteredOUT;
1363 } 1367 }
1364 } 1368 }
1365 } 1369 }
1366 inL = el.next(); 1370 inL = el.next();
1367 } 1371 }
1368 int delFut = 0; 1372 int delFut = 0;
1369 int remRem = 0; 1373 int remRem = 0;
1370 if ( mSyncManager->mWriteBackInFuture ) { 1374 if ( mSyncManager->mWriteBackInFuture ) {
1371 er = remote->rawIncidences(); 1375 er = remote->rawIncidences();
1372 remRem = er.count(); 1376 remRem = er.count();
1373 inR = er.first(); 1377 inR = er.first();
1374 QDateTime dt; 1378 QDateTime dt;
1375 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1379 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1376 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1380 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1377 while ( inR ) { 1381 while ( inR ) {
1378 if ( inR->type() == "Todo" ) { 1382 if ( inR->type() == "Todo" ) {
1379 Todo * t = (Todo*)inR; 1383 Todo * t = (Todo*)inR;
1380 if ( t->hasDueDate() ) 1384 if ( t->hasDueDate() )
1381 dt = t->dtDue(); 1385 dt = t->dtDue();
1382 else 1386 else
1383 dt = cur.addSecs( 62 ); 1387 dt = cur.addSecs( 62 );
1384 } 1388 }
1385 else if (inR->type() == "Event" ) { 1389 else if (inR->type() == "Event" ) {
1386 bool ok; 1390 bool ok;
1387 dt = inR->getNextOccurence( cur, &ok ); 1391 dt = inR->getNextOccurence( cur, &ok );
1388 if ( !ok ) 1392 if ( !ok )
1389 dt = cur.addSecs( -62 ); 1393 dt = cur.addSecs( -62 );
1390 } 1394 }
1391 else 1395 else
1392 dt = inR->dtStart(); 1396 dt = inR->dtStart();
1393 if ( dt < cur || dt > end ) { 1397 if ( dt < cur || dt > end ) {
1394 remote->deleteIncidence( inR ); 1398 remote->deleteIncidence( inR );
1395 ++delFut; 1399 ++delFut;
1396 } 1400 }
1397 inR = er.next(); 1401 inR = er.next();
1398 } 1402 }
1399 } 1403 }
1400 bar.hide(); 1404 bar.hide();
1401 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1405 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1402 eventLSync->setReadOnly( false ); 1406 eventLSync->setReadOnly( false );
1403 eventLSync->setDtStart( mLastCalendarSync ); 1407 eventLSync->setDtStart( mLastCalendarSync );
1404 eventRSync->setDtStart( mLastCalendarSync ); 1408 eventRSync->setDtStart( mLastCalendarSync );
1405 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1409 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1406 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1410 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1407 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1411 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1408 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1412 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1409 eventLSync->setReadOnly( true ); 1413 eventLSync->setReadOnly( true );
1410 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1414 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1411 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1415 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1412 remote->addEvent( eventRSync ); 1416 remote->addEvent( eventRSync );
1413 else 1417 else
1414 delete eventRSync; 1418 delete eventRSync;
1415 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1419 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1416 QString mes; 1420 QString mes;
1417 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT ); 1421 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT );
1418 QString delmess; 1422 QString delmess;
1419 if ( delFut ) { 1423 if ( delFut ) {
1420 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut); 1424 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut);
1421 mes += delmess; 1425 mes += delmess;
1422 } 1426 }
1423 mes = i18n("Local calendar changed!\n") +mes; 1427 mes = i18n("Local calendar changed!\n") +mes;
1424 mCalendar->checkAlarmForIncidence( 0, true ); 1428 mCalendar->checkAlarmForIncidence( 0, true );
1425 qDebug( mes ); 1429 qDebug( mes );
1426 if ( mSyncManager->mShowSyncSummary ) { 1430 if ( mSyncManager->mShowSyncSummary ) {
1427 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1431 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1428 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1432 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1429 qDebug("KO: WB cancelled "); 1433 qDebug("KO: WB cancelled ");
1430 mSyncManager->mWriteBackFile = false; 1434 mSyncManager->mWriteBackFile = false;
1431 return syncOK; 1435 return syncOK;
1432 } 1436 }
1433 } 1437 }
1434 return syncOK; 1438 return syncOK;
1435} 1439}
1436 1440
1437void CalendarView::setSyncDevice( QString s ) 1441void CalendarView::setSyncDevice( QString s )
1438{ 1442{
1439 mCurrentSyncDevice= s; 1443 mCurrentSyncDevice= s;
1440} 1444}
1441void CalendarView::setSyncName( QString s ) 1445void CalendarView::setSyncName( QString s )
1442{ 1446{
1443 mCurrentSyncName= s; 1447 mCurrentSyncName= s;
1444} 1448}
1445bool CalendarView::syncCalendar(QString filename, int mode) 1449bool CalendarView::syncCalendar(QString filename, int mode)
1446{ 1450{
1447 //qDebug("syncCalendar %s ", filename.latin1()); 1451 //qDebug("syncCalendar %s ", filename.latin1());
1448 mGlobalSyncMode = SYNC_MODE_NORMAL; 1452 mGlobalSyncMode = SYNC_MODE_NORMAL;
1449 CalendarLocal* calendar = new CalendarLocal(); 1453 CalendarLocal* calendar = new CalendarLocal();
1450 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1454 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1451 FileStorage* storage = new FileStorage( calendar ); 1455 FileStorage* storage = new FileStorage( calendar );
1452 bool syncOK = false; 1456 bool syncOK = false;
1453 storage->setFileName( filename ); 1457 storage->setFileName( filename );
1454 // qDebug("loading ... "); 1458 // qDebug("loading ... ");
1455 if ( storage->load() ) { 1459 if ( storage->load() ) {
1456 getEventViewerDialog()->setSyncMode( true ); 1460 getEventViewerDialog()->setSyncMode( true );
1457 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1461 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1458 getEventViewerDialog()->setSyncMode( false ); 1462 getEventViewerDialog()->setSyncMode( false );
1459 if ( syncOK ) { 1463 if ( syncOK ) {
1460 if ( mSyncManager->mWriteBackFile ) 1464 if ( mSyncManager->mWriteBackFile )
1461 { 1465 {
1462 storage->setSaveFormat( new ICalFormat() ); 1466 storage->setSaveFormat( new ICalFormat() );
1463 storage->save(); 1467 storage->save();
1464 } 1468 }
1465 } 1469 }
1466 setModified( true ); 1470 setModified( true );
1467 } 1471 }
1468 delete storage; 1472 delete storage;
1469 delete calendar; 1473 delete calendar;
1470 if ( syncOK ) 1474 if ( syncOK )
1471 updateView(); 1475 updateView();
1472 return syncOK; 1476 return syncOK;
1473} 1477}
1474 1478
1475void CalendarView::syncExternal( int mode ) 1479void CalendarView::syncExternal( int mode )
1476{ 1480{
1477 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1481 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1478 1482
1479 qApp->processEvents(); 1483 qApp->processEvents();
1480 CalendarLocal* calendar = new CalendarLocal(); 1484 CalendarLocal* calendar = new CalendarLocal();
1481 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1485 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1482 bool syncOK = false; 1486 bool syncOK = false;
1483 bool loadSuccess = false; 1487 bool loadSuccess = false;
1484 PhoneFormat* phoneFormat = 0; 1488 PhoneFormat* phoneFormat = 0;
1485 emit tempDisableBR(true); 1489 emit tempDisableBR(true);
1486#ifndef DESKTOP_VERSION 1490#ifndef DESKTOP_VERSION
1487 SharpFormat* sharpFormat = 0; 1491 SharpFormat* sharpFormat = 0;
1488 if ( mode == 0 ) { // sharp 1492 if ( mode == 0 ) { // sharp
1489 sharpFormat = new SharpFormat () ; 1493 sharpFormat = new SharpFormat () ;
1490 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1494 loadSuccess = sharpFormat->load( calendar, mCalendar );
1491 1495
1492 } else 1496 } else
1493#endif 1497#endif
1494 if ( mode == 1 ) { // phone 1498 if ( mode == 1 ) { // phone
1495 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1499 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1496 mSyncManager->mPhoneDevice, 1500 mSyncManager->mPhoneDevice,
1497 mSyncManager->mPhoneConnection, 1501 mSyncManager->mPhoneConnection,
1498 mSyncManager->mPhoneModel); 1502 mSyncManager->mPhoneModel);
1499 loadSuccess = phoneFormat->load( calendar,mCalendar); 1503 loadSuccess = phoneFormat->load( calendar,mCalendar);
1500 1504
1501 } else { 1505 } else {
1502 emit tempDisableBR(false); 1506 emit tempDisableBR(false);
1503 return; 1507 return;
1504 } 1508 }
1505 if ( loadSuccess ) { 1509 if ( loadSuccess ) {
1506 getEventViewerDialog()->setSyncMode( true ); 1510 getEventViewerDialog()->setSyncMode( true );
1507 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1511 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1508 getEventViewerDialog()->setSyncMode( false ); 1512 getEventViewerDialog()->setSyncMode( false );
1509 qApp->processEvents(); 1513 qApp->processEvents();
1510 if ( syncOK ) { 1514 if ( syncOK ) {
1511 if ( mSyncManager->mWriteBackFile ) 1515 if ( mSyncManager->mWriteBackFile )
1512 { 1516 {
1513 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1517 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1514 Incidence* inc = iL.first(); 1518 Incidence* inc = iL.first();
1515 if ( phoneFormat ) { 1519 if ( phoneFormat ) {
1516 while ( inc ) { 1520 while ( inc ) {
1517 inc->removeID(mCurrentSyncDevice); 1521 inc->removeID(mCurrentSyncDevice);
1518 inc = iL.next(); 1522 inc = iL.next();
1519 } 1523 }
1520 } 1524 }
1521#ifndef DESKTOP_VERSION 1525#ifndef DESKTOP_VERSION
1522 if ( sharpFormat ) 1526 if ( sharpFormat )
1523 sharpFormat->save(calendar); 1527 sharpFormat->save(calendar);
1524#endif 1528#endif
1525 if ( phoneFormat ) 1529 if ( phoneFormat )
1526 phoneFormat->save(calendar); 1530 phoneFormat->save(calendar);
1527 iL = calendar->rawIncidences(); 1531 iL = calendar->rawIncidences();
1528 inc = iL.first(); 1532 inc = iL.first();
1529 Incidence* loc; 1533 Incidence* loc;
1530 while ( inc ) { 1534 while ( inc ) {
1531 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1535 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1532 loc = mCalendar->incidence(inc->uid() ); 1536 loc = mCalendar->incidence(inc->uid() );
1533 if ( loc ) { 1537 if ( loc ) {
1534 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1538 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1535 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1539 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1536 } 1540 }
1537 } 1541 }
1538 inc = iL.next(); 1542 inc = iL.next();
1539 } 1543 }
1540 Incidence* lse = getLastSyncEvent(); 1544 Incidence* lse = getLastSyncEvent();
1541 if ( lse ) { 1545 if ( lse ) {
1542 lse->setReadOnly( false ); 1546 lse->setReadOnly( false );
1543 lse->setDescription( "" ); 1547 lse->setDescription( "" );
1544 lse->setReadOnly( true ); 1548 lse->setReadOnly( true );
1545 } 1549 }
1546 } 1550 }
1547 } else { 1551 } else {
1548 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1552 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1549 } 1553 }
1550 setModified( true ); 1554 setModified( true );
1551 } else { 1555 } else {
1552 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1556 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1553 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1557 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1554 question, i18n("Ok")) ; 1558 question, i18n("Ok")) ;
1555 1559
1556 } 1560 }
1557 delete calendar; 1561 delete calendar;
1558 updateView(); 1562 updateView();
1559 emit tempDisableBR(false); 1563 emit tempDisableBR(false);
1560 return ;//syncOK; 1564 return ;//syncOK;
1561 1565
1562} 1566}
1563 1567
1564bool CalendarView::importBday() 1568bool CalendarView::importBday()
1565{ 1569{
1566#ifndef KORG_NOKABC 1570#ifndef KORG_NOKABC
1567 1571
1568#ifdef DESKTOP_VERSION 1572#ifdef DESKTOP_VERSION
1569 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1573 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1570 KABC::AddressBook::Iterator it; 1574 KABC::AddressBook::Iterator it;
1571 int count = 0; 1575 int count = 0;
1572 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1576 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1573 ++count; 1577 ++count;
1574 } 1578 }
1575 QProgressBar bar(count,0 ); 1579 QProgressBar bar(count,0 );
1576 int w = 300; 1580 int w = 300;
1577 if ( QApplication::desktop()->width() < 320 ) 1581 if ( QApplication::desktop()->width() < 320 )
1578 w = 220; 1582 w = 220;
1579 int h = bar.sizeHint().height() ; 1583 int h = bar.sizeHint().height() ;
1580 int dw = QApplication::desktop()->width(); 1584 int dw = QApplication::desktop()->width();
1581 int dh = QApplication::desktop()->height(); 1585 int dh = QApplication::desktop()->height();
1582 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1586 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1583 bar.show(); 1587 bar.show();
1584 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1588 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1585 qApp->processEvents(); 1589 qApp->processEvents();
1586 count = 0; 1590 count = 0;
1587 int addCount = 0; 1591 int addCount = 0;
1588 KCal::Attendee* a = 0; 1592 KCal::Attendee* a = 0;
1589 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1593 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1590 if ( ! bar.isVisible() ) 1594 if ( ! bar.isVisible() )
1591 return false; 1595 return false;
1592 bar.setProgress( count++ ); 1596 bar.setProgress( count++ );
1593 qApp->processEvents(); 1597 qApp->processEvents();
1594 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1598 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1595 if ( (*it).birthday().date().isValid() ){ 1599 if ( (*it).birthday().date().isValid() ){
1596 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1600 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1597 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1601 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1598 ++addCount; 1602 ++addCount;
1599 } 1603 }
1600 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1604 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1601 if ( anni.isValid() ){ 1605 if ( anni.isValid() ){
1602 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1606 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1603 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1607 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1604 ++addCount; 1608 ++addCount;
1605 } 1609 }
1606 } 1610 }
1607 updateView(); 1611 updateView();
1608 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1612 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1609#else //DESKTOP_VERSION 1613#else //DESKTOP_VERSION
1610 1614
1611 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1615 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1612 // the result should now arrive through method insertBirthdays 1616 // the result should now arrive through method insertBirthdays
1613 1617
1614#endif //DESKTOP_VERSION 1618#endif //DESKTOP_VERSION
1615 1619
1616#endif //KORG_NOKABC 1620#endif //KORG_NOKABC
1617 1621
1618 1622
1619 return true; 1623 return true;
1620} 1624}
1621 1625
1622// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1626// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1623void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1627void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1624 const QStringList& anniversaryList, const QStringList& realNameList, 1628 const QStringList& anniversaryList, const QStringList& realNameList,
1625 const QStringList& emailList, const QStringList& assembledNameList, 1629 const QStringList& emailList, const QStringList& assembledNameList,
1626 const QStringList& uidList) 1630 const QStringList& uidList)
1627{ 1631{
1628 //qDebug("KO::CalendarView::insertBirthdays"); 1632 //qDebug("KO::CalendarView::insertBirthdays");
1629 if (uid == this->name()) 1633 if (uid == this->name())
1630 { 1634 {
1631 int count = birthdayList.count(); 1635 int count = birthdayList.count();
1632 int addCount = 0; 1636 int addCount = 0;
1633 KCal::Attendee* a = 0; 1637 KCal::Attendee* a = 0;
1634 1638
1635 //qDebug("CalView 1 %i", count); 1639 //qDebug("CalView 1 %i", count);
1636 1640
1637 QProgressBar bar(count,0 ); 1641 QProgressBar bar(count,0 );
1638 int w = 300; 1642 int w = 300;
1639 if ( QApplication::desktop()->width() < 320 ) 1643 if ( QApplication::desktop()->width() < 320 )
1640 w = 220; 1644 w = 220;
1641 int h = bar.sizeHint().height() ; 1645 int h = bar.sizeHint().height() ;
1642 int dw = QApplication::desktop()->width(); 1646 int dw = QApplication::desktop()->width();
1643 int dh = QApplication::desktop()->height(); 1647 int dh = QApplication::desktop()->height();
1644 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1648 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1645 bar.show(); 1649 bar.show();
1646 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1650 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1647 qApp->processEvents(); 1651 qApp->processEvents();
1648 1652
1649 QDate birthday; 1653 QDate birthday;
1650 QDate anniversary; 1654 QDate anniversary;
1651 QString realName; 1655 QString realName;
1652 QString email; 1656 QString email;
1653 QString assembledName; 1657 QString assembledName;
1654 QString uid; 1658 QString uid;
1655 bool ok = true; 1659 bool ok = true;
1656 for ( int i = 0; i < count; i++) 1660 for ( int i = 0; i < count; i++)
1657 { 1661 {
1658 if ( ! bar.isVisible() ) 1662 if ( ! bar.isVisible() )
1659 return; 1663 return;
1660 bar.setProgress( i ); 1664 bar.setProgress( i );
1661 qApp->processEvents(); 1665 qApp->processEvents();
1662 1666
1663 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1667 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1664 if (!ok) { 1668 if (!ok) {
1665 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1669 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1666 } 1670 }
1667 1671
1668 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1672 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1669 if (!ok) { 1673 if (!ok) {
1670 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1674 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1671 } 1675 }
1672 realName = realNameList[i]; 1676 realName = realNameList[i];
1673 email = emailList[i]; 1677 email = emailList[i];
1674 assembledName = assembledNameList[i]; 1678 assembledName = assembledNameList[i];
1675 uid = uidList[i]; 1679 uid = uidList[i];
1676 //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() ); 1680 //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() );
1677 1681
1678 if ( birthday.isValid() ){ 1682 if ( birthday.isValid() ){
1679 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1683 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1680 KCal::Attendee::ReqParticipant,uid) ; 1684 KCal::Attendee::ReqParticipant,uid) ;
1681 if ( addAnniversary( birthday, assembledName, a, true ) ) 1685 if ( addAnniversary( birthday, assembledName, a, true ) )
1682 ++addCount; 1686 ++addCount;
1683 } 1687 }
1684 1688
1685 if ( anniversary.isValid() ){ 1689 if ( anniversary.isValid() ){
1686 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1690 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1687 KCal::Attendee::ReqParticipant,uid) ; 1691 KCal::Attendee::ReqParticipant,uid) ;
1688 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1692 if ( addAnniversary( anniversary, assembledName, a, false ) )
1689 ++addCount; 1693 ++addCount;
1690 } 1694 }
1691 } 1695 }
1692 1696
1693 updateView(); 1697 updateView();
1694 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1698 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1695 1699
1696 } 1700 }
1697 1701
1698} 1702}
1699 1703
1700 1704
1701 1705
1702bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1706bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1703{ 1707{
1704 //qDebug("addAnni "); 1708 //qDebug("addAnni ");
1705 Event * ev = new Event(); 1709 Event * ev = new Event();
1706 ev->setOrganizer(KOPrefs::instance()->email()); 1710 ev->setOrganizer(KOPrefs::instance()->email());
1707 if ( a ) { 1711 if ( a ) {
1708 ev->addAttendee( a ); 1712 ev->addAttendee( a );
1709 } 1713 }
1710 QString kind; 1714 QString kind;
1711 if ( birthday ) { 1715 if ( birthday ) {
1712 kind = i18n( "Birthday" ); 1716 kind = i18n( "Birthday" );
1713 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 1717 ev->setSummary( name + " (" + QString::number(date.year()) +")");
1714 } 1718 }
1715 else { 1719 else {
1716 kind = i18n( "Anniversary" ); 1720 kind = i18n( "Anniversary" );
1717 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 1721 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
1718 } 1722 }
1719 ev->setCategories( kind ); 1723 ev->setCategories( kind );
1720 ev->setDtStart( QDateTime(date) ); 1724 ev->setDtStart( QDateTime(date) );
1721 ev->setDtEnd( QDateTime(date) ); 1725 ev->setDtEnd( QDateTime(date) );
1722 ev->setFloats( true ); 1726 ev->setFloats( true );
1723 Recurrence * rec = ev->recurrence(); 1727 Recurrence * rec = ev->recurrence();
1724 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1728 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1725 rec->addYearlyNum( date.month() ); 1729 rec->addYearlyNum( date.month() );
1726 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1730 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1727 delete ev; 1731 delete ev;
1728 return false; 1732 return false;
1729 } 1733 }
1730 return true; 1734 return true;
1731 1735
1732} 1736}
1733bool CalendarView::importQtopia( const QString &categories, 1737bool CalendarView::importQtopia( const QString &categories,
1734 const QString &datebook, 1738 const QString &datebook,
1735 const QString &todolist ) 1739 const QString &todolist )
1736{ 1740{
1737 1741
1738 QtopiaFormat qtopiaFormat; 1742 QtopiaFormat qtopiaFormat;
1739 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1743 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1740 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1744 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1741 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1745 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1742 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1746 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1743 1747
1744 updateView(); 1748 updateView();
1745 return true; 1749 return true;
1746 1750
1747#if 0 1751#if 0
1748 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1752 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1749 mCurrentSyncDevice = "qtopia-XML"; 1753 mCurrentSyncDevice = "qtopia-XML";
1750 if ( mSyncManager->mAskForPreferences ) 1754 if ( mSyncManager->mAskForPreferences )
1751 edit_sync_options(); 1755 edit_sync_options();
1752 qApp->processEvents(); 1756 qApp->processEvents();
1753 CalendarLocal* calendar = new CalendarLocal(); 1757 CalendarLocal* calendar = new CalendarLocal();
1754 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1758 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1755 bool syncOK = false; 1759 bool syncOK = false;
1756 QtopiaFormat qtopiaFormat; 1760 QtopiaFormat qtopiaFormat;
1757 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1761 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1758 bool loadOk = true; 1762 bool loadOk = true;
1759 if ( !categories.isEmpty() ) 1763 if ( !categories.isEmpty() )
1760 loadOk = qtopiaFormat.load( calendar, categories ); 1764 loadOk = qtopiaFormat.load( calendar, categories );
1761 if ( loadOk && !datebook.isEmpty() ) 1765 if ( loadOk && !datebook.isEmpty() )
1762 loadOk = qtopiaFormat.load( calendar, datebook ); 1766 loadOk = qtopiaFormat.load( calendar, datebook );
1763 if ( loadOk && !todolist.isEmpty() ) 1767 if ( loadOk && !todolist.isEmpty() )
1764 loadOk = qtopiaFormat.load( calendar, todolist ); 1768 loadOk = qtopiaFormat.load( calendar, todolist );
1765 1769
1766 if ( loadOk ) { 1770 if ( loadOk ) {
1767 getEventViewerDialog()->setSyncMode( true ); 1771 getEventViewerDialog()->setSyncMode( true );
1768 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1772 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1769 getEventViewerDialog()->setSyncMode( false ); 1773 getEventViewerDialog()->setSyncMode( false );
1770 qApp->processEvents(); 1774 qApp->processEvents();
1771 if ( syncOK ) { 1775 if ( syncOK ) {
1772 if ( mSyncManager->mWriteBackFile ) 1776 if ( mSyncManager->mWriteBackFile )
1773 { 1777 {
1774 // write back XML file 1778 // write back XML file
1775 1779
1776 } 1780 }
1777 setModified( true ); 1781 setModified( true );
1778 } 1782 }
1779 } else { 1783 } else {
1780 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1784 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1781 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1785 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1782 question, i18n("Ok")) ; 1786 question, i18n("Ok")) ;
1783 } 1787 }
1784 delete calendar; 1788 delete calendar;
1785 updateView(); 1789 updateView();
1786 return syncOK; 1790 return syncOK;
1787 1791
1788 1792
1789#endif 1793#endif
1790 1794
1791} 1795}
1792 1796
1793void CalendarView::setSyncEventsReadOnly() 1797void CalendarView::setSyncEventsReadOnly()
1794{ 1798{
1795 Event * ev; 1799 Event * ev;
1796 QPtrList<Event> eL = mCalendar->rawEvents(); 1800 QPtrList<Event> eL = mCalendar->rawEvents();
1797 ev = eL.first(); 1801 ev = eL.first();
1798 while ( ev ) { 1802 while ( ev ) {
1799 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1803 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1800 ev->setReadOnly( true ); 1804 ev->setReadOnly( true );
1801 ev = eL.next(); 1805 ev = eL.next();
1802 } 1806 }
1803} 1807}
1804bool CalendarView::openCalendar(QString filename, bool merge) 1808bool CalendarView::openCalendar(QString filename, bool merge)
1805{ 1809{
1806 1810
1807 if (filename.isEmpty()) { 1811 if (filename.isEmpty()) {
1808 return false; 1812 return false;
1809 } 1813 }
1810 1814
1811 if (!QFile::exists(filename)) { 1815 if (!QFile::exists(filename)) {
1812 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1816 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1813 return false; 1817 return false;
1814 } 1818 }
1815 1819
1816 globalFlagBlockAgenda = 1; 1820 globalFlagBlockAgenda = 1;
1817 if (!merge) { 1821 if (!merge) {
1818 mTodoList->clearList(); 1822 mTodoList->clearList();
1819 mViewManager->setDocumentId( filename ); 1823 mViewManager->setDocumentId( filename );
1820 mCalendar->close(); 1824 mCalendar->close();
1821 } 1825 }
1822 mStorage->setFileName( filename ); 1826 mStorage->setFileName( filename );
1823 1827
1824 if ( mStorage->load() ) { 1828 if ( mStorage->load() ) {
1825 if ( merge ) ;//setModified( true ); 1829 if ( merge ) ;//setModified( true );
1826 else { 1830 else {
1827 //setModified( true ); 1831 //setModified( true );
1828 mViewManager->setDocumentId( filename ); 1832 mViewManager->setDocumentId( filename );
1829 mDialogManager->setDocumentId( filename ); 1833 mDialogManager->setDocumentId( filename );
1830 mTodoList->setDocumentId( filename ); 1834 mTodoList->setDocumentId( filename );
1831 } 1835 }
1832 globalFlagBlockAgenda = 2; 1836 globalFlagBlockAgenda = 2;
1833 // if ( getLastSyncEvent() ) 1837 // if ( getLastSyncEvent() )
1834 // getLastSyncEvent()->setReadOnly( true ); 1838 // getLastSyncEvent()->setReadOnly( true );
1835 mCalendar->reInitAlarmSettings(); 1839 mCalendar->reInitAlarmSettings();
1836 setSyncEventsReadOnly(); 1840 setSyncEventsReadOnly();
1837 updateUnmanagedViews(); 1841 updateUnmanagedViews();
1838 updateView(); 1842 updateView();
1839 if ( filename != MainWindow::defaultFileName() ) { 1843 if ( filename != MainWindow::defaultFileName() ) {
1840 saveCalendar( MainWindow::defaultFileName() ); 1844 saveCalendar( MainWindow::defaultFileName() );
1841 } else { 1845 } else {
1842 QFileInfo finf ( MainWindow::defaultFileName()); 1846 QFileInfo finf ( MainWindow::defaultFileName());
1843 if ( finf.exists() ) { 1847 if ( finf.exists() ) {
1844 setLoadedFileVersion( finf.lastModified () ); 1848 setLoadedFileVersion( finf.lastModified () );
1845 } 1849 }
1846 } 1850 }
1847 return true; 1851 return true;
1848 } else { 1852 } else {
1849 // while failing to load, the calendar object could 1853 // while failing to load, the calendar object could
1850 // have become partially populated. Clear it out. 1854 // have become partially populated. Clear it out.
1851 if ( !merge ) { 1855 if ( !merge ) {
1852 mCalendar->close(); 1856 mCalendar->close();
1853 mViewManager->setDocumentId( filename ); 1857 mViewManager->setDocumentId( filename );
1854 mDialogManager->setDocumentId( filename ); 1858 mDialogManager->setDocumentId( filename );
1855 mTodoList->setDocumentId( filename ); 1859 mTodoList->setDocumentId( filename );
1856 } 1860 }
1857 1861
1858 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1862 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1859 1863
1860 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 1864 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
1861 globalFlagBlockAgenda = 2; 1865 globalFlagBlockAgenda = 2;
1862 mCalendar->reInitAlarmSettings(); 1866 mCalendar->reInitAlarmSettings();
1863 setSyncEventsReadOnly(); 1867 setSyncEventsReadOnly();
1864 updateUnmanagedViews(); 1868 updateUnmanagedViews();
1865 updateView(); 1869 updateView();
1866 } 1870 }
1867 return false; 1871 return false;
1868} 1872}
1869void CalendarView::showOpenError() 1873void CalendarView::showOpenError()
1870{ 1874{
1871 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 1875 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
1872} 1876}
1873void CalendarView::setLoadedFileVersion(QDateTime dt) 1877void CalendarView::setLoadedFileVersion(QDateTime dt)
1874{ 1878{
1875 loadedFileVersion = dt; 1879 loadedFileVersion = dt;
1876} 1880}
1877bool CalendarView::checkFileChanged(QString fn) 1881bool CalendarView::checkFileChanged(QString fn)
1878{ 1882{
1879 QFileInfo finf ( fn ); 1883 QFileInfo finf ( fn );
1880 if ( !finf.exists() ) 1884 if ( !finf.exists() )
1881 return true; 1885 return true;
1882 QDateTime dt = finf.lastModified (); 1886 QDateTime dt = finf.lastModified ();
1883 if ( dt <= loadedFileVersion ) 1887 if ( dt <= loadedFileVersion )
1884 return false; 1888 return false;
1885 return true; 1889 return true;
1886 1890
1887} 1891}
1888void CalendarView::watchSavedFile() 1892void CalendarView::watchSavedFile()
1889{ 1893{
1890 QFileInfo finf ( MainWindow::defaultFileName()); 1894 QFileInfo finf ( MainWindow::defaultFileName());
1891 if ( !finf.exists() ) 1895 if ( !finf.exists() )
1892 return; 1896 return;
1893 QDateTime dt = finf.lastModified (); 1897 QDateTime dt = finf.lastModified ();
1894 if ( dt < loadedFileVersion ) { 1898 if ( dt < loadedFileVersion ) {
1895 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 1899 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
1896 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 1900 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
1897 return; 1901 return;
1898 } 1902 }
1899 loadedFileVersion = dt; 1903 loadedFileVersion = dt;
1900} 1904}
1901 1905
1902bool CalendarView::checkFileVersion(QString fn) 1906bool CalendarView::checkFileVersion(QString fn)
1903{ 1907{
1904 QFileInfo finf ( fn ); 1908 QFileInfo finf ( fn );
1905 if ( !finf.exists() ) 1909 if ( !finf.exists() )
1906 return true; 1910 return true;
1907 QDateTime dt = finf.lastModified (); 1911 QDateTime dt = finf.lastModified ();
1908 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1912 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1909 //qDebug("file on disk version %s",dt.toString().latin1()); 1913 //qDebug("file on disk version %s",dt.toString().latin1());
1910 if ( dt <= loadedFileVersion ) 1914 if ( dt <= loadedFileVersion )
1911 return true; 1915 return true;
1912 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)) , 1916 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)) ,
1913 i18n("KO/Pi Warning"),i18n("Overwrite"), 1917 i18n("KO/Pi Warning"),i18n("Overwrite"),
1914 i18n("Sync+save")); 1918 i18n("Sync+save"));
1915 1919
1916 if ( km == KMessageBox::Cancel ) 1920 if ( km == KMessageBox::Cancel )
1917 return false; 1921 return false;
1918 if ( km == KMessageBox::Yes ) 1922 if ( km == KMessageBox::Yes )
1919 return true; 1923 return true;
1920 1924
1921 setSyncDevice("deleteaftersync" ); 1925 setSyncDevice("deleteaftersync" );
1922 mSyncManager->mAskForPreferences = true; 1926 mSyncManager->mAskForPreferences = true;
1923 mSyncManager->mSyncAlgoPrefs = 3; 1927 mSyncManager->mSyncAlgoPrefs = 3;
1924 mSyncManager->mWriteBackFile = false; 1928 mSyncManager->mWriteBackFile = false;
1925 mSyncManager->mWriteBackExistingOnly = false; 1929 mSyncManager->mWriteBackExistingOnly = false;
1926 mSyncManager->mShowSyncSummary = false; 1930 mSyncManager->mShowSyncSummary = false;
1927 syncCalendar( fn, 3 ); 1931 syncCalendar( fn, 3 );
1928 Event * e = getLastSyncEvent(); 1932 Event * e = getLastSyncEvent();
1929 mCalendar->deleteEvent ( e ); 1933 mCalendar->deleteEvent ( e );
1930 updateView(); 1934 updateView();
1931 return true; 1935 return true;
1932} 1936}
1933 1937
1934bool CalendarView::saveCalendar( QString filename ) 1938bool CalendarView::saveCalendar( QString filename )
1935{ 1939{
1936 1940
1937 // Store back all unsaved data into calendar object 1941 // Store back all unsaved data into calendar object
1938 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 1942 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
1939 if ( mViewManager->currentView() ) 1943 if ( mViewManager->currentView() )
1940 mViewManager->currentView()->flushView(); 1944 mViewManager->currentView()->flushView();
1941 1945
1942 1946
1943 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 1947 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
1944 mStorage->setSaveFormat( new ICalFormat() ); 1948 mStorage->setSaveFormat( new ICalFormat() );
1945 mStorage->setFileName( filename ); 1949 mStorage->setFileName( filename );
1946 bool success; 1950 bool success;
1947 success = mStorage->save(); 1951 success = mStorage->save();
1948 if ( !success ) { 1952 if ( !success ) {
1949 return false; 1953 return false;
1950 } 1954 }
1951 if ( filename == MainWindow::defaultFileName() ) { 1955 if ( filename == MainWindow::defaultFileName() ) {
1952 setLoadedFileVersion( lfv ); 1956 setLoadedFileVersion( lfv );
1953 watchSavedFile(); 1957 watchSavedFile();
1954 } 1958 }
1955 return true; 1959 return true;
1956} 1960}
1957 1961
1958void CalendarView::closeCalendar() 1962void CalendarView::closeCalendar()
1959{ 1963{
1960 1964
1961 // child windows no longer valid 1965 // child windows no longer valid
1962 emit closingDown(); 1966 emit closingDown();
1963 1967
1964 mCalendar->close(); 1968 mCalendar->close();
1965 setModified(false); 1969 setModified(false);
1966 updateView(); 1970 updateView();
1967} 1971}
1968 1972
1969void CalendarView::archiveCalendar() 1973void CalendarView::archiveCalendar()
1970{ 1974{
1971 mDialogManager->showArchiveDialog(); 1975 mDialogManager->showArchiveDialog();
1972} 1976}
1973 1977
1974 1978
1975void CalendarView::readSettings() 1979void CalendarView::readSettings()
1976{ 1980{
1977 1981
1978 1982
1979 // mViewManager->showAgendaView(); 1983 // mViewManager->showAgendaView();
1980 QString str; 1984 QString str;
1981 //qDebug("CalendarView::readSettings() "); 1985 //qDebug("CalendarView::readSettings() ");
1982 // read settings from the KConfig, supplying reasonable 1986 // read settings from the KConfig, supplying reasonable
1983 // defaults where none are to be found 1987 // defaults where none are to be found
1984 KConfig *config = KOGlobals::config(); 1988 KConfig *config = KOGlobals::config();
1985#ifndef KORG_NOSPLITTER 1989#ifndef KORG_NOSPLITTER
1986 config->setGroup("KOrganizer Geometry"); 1990 config->setGroup("KOrganizer Geometry");
1987 1991
1988 QValueList<int> sizes = config->readIntListEntry("Separator1"); 1992 QValueList<int> sizes = config->readIntListEntry("Separator1");
1989 if (sizes.count() != 2) { 1993 if (sizes.count() != 2) {
1990 sizes << mDateNavigator->minimumSizeHint().width(); 1994 sizes << mDateNavigator->minimumSizeHint().width();
1991 sizes << 300; 1995 sizes << 300;
1992 } 1996 }
1993 mPanner->setSizes(sizes); 1997 mPanner->setSizes(sizes);
1994 1998
1995 sizes = config->readIntListEntry("Separator2"); 1999 sizes = config->readIntListEntry("Separator2");
1996 if ( ( mResourceView && sizes.count() == 4 ) || 2000 if ( ( mResourceView && sizes.count() == 4 ) ||
1997 ( !mResourceView && sizes.count() == 3 ) ) { 2001 ( !mResourceView && sizes.count() == 3 ) ) {
1998 mLeftSplitter->setSizes(sizes); 2002 mLeftSplitter->setSizes(sizes);
1999 } 2003 }
2000#endif 2004#endif
2001 globalFlagBlockAgenda = 1; 2005 globalFlagBlockAgenda = 1;
2002 mViewManager->showAgendaView(); 2006 mViewManager->showAgendaView();
2003 //mViewManager->readSettings( config ); 2007 //mViewManager->readSettings( config );
2004 mTodoList->restoreLayout(config,QString("Todo Layout")); 2008 mTodoList->restoreLayout(config,QString("Todo Layout"));
2005 readFilterSettings(config); 2009 readFilterSettings(config);
2006 2010
2007#ifdef DESKTOP_VERSION 2011#ifdef DESKTOP_VERSION
2008 config->setGroup("WidgetLayout"); 2012 config->setGroup("WidgetLayout");
2009 QStringList list; 2013 QStringList list;
2010 list = config->readListEntry("MainLayout"); 2014 list = config->readListEntry("MainLayout");
2011 int x,y,w,h; 2015 int x,y,w,h;
2012 if ( ! list.isEmpty() ) { 2016 if ( ! list.isEmpty() ) {
2013 x = list[0].toInt(); 2017 x = list[0].toInt();
2014 y = list[1].toInt(); 2018 y = list[1].toInt();
2015 w = list[2].toInt(); 2019 w = list[2].toInt();
2016 h = list[3].toInt(); 2020 h = list[3].toInt();
2017 KApplication::testCoords( &x,&y,&w,&h ); 2021 KApplication::testCoords( &x,&y,&w,&h );
2018 topLevelWidget()->setGeometry(x,y,w,h); 2022 topLevelWidget()->setGeometry(x,y,w,h);
2019 2023
2020 } else { 2024 } else {
2021 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 2025 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
2022 } 2026 }
2023 list = config->readListEntry("EditEventLayout"); 2027 list = config->readListEntry("EditEventLayout");
2024 if ( ! list.isEmpty() ) { 2028 if ( ! list.isEmpty() ) {
2025 x = list[0].toInt(); 2029 x = list[0].toInt();
2026 y = list[1].toInt(); 2030 y = list[1].toInt();
2027 w = list[2].toInt(); 2031 w = list[2].toInt();
2028 h = list[3].toInt(); 2032 h = list[3].toInt();
2029 KApplication::testCoords( &x,&y,&w,&h ); 2033 KApplication::testCoords( &x,&y,&w,&h );
2030 mEventEditor->setGeometry(x,y,w,h); 2034 mEventEditor->setGeometry(x,y,w,h);
2031 2035
2032 } 2036 }
2033 list = config->readListEntry("EditTodoLayout"); 2037 list = config->readListEntry("EditTodoLayout");
2034 if ( ! list.isEmpty() ) { 2038 if ( ! list.isEmpty() ) {
2035 x = list[0].toInt(); 2039 x = list[0].toInt();
2036 y = list[1].toInt(); 2040 y = list[1].toInt();
2037 w = list[2].toInt(); 2041 w = list[2].toInt();
2038 h = list[3].toInt(); 2042 h = list[3].toInt();
2039 KApplication::testCoords( &x,&y,&w,&h ); 2043 KApplication::testCoords( &x,&y,&w,&h );
2040 mTodoEditor->setGeometry(x,y,w,h); 2044 mTodoEditor->setGeometry(x,y,w,h);
2041 2045
2042 } 2046 }
2043 list = config->readListEntry("ViewerLayout"); 2047 list = config->readListEntry("ViewerLayout");
2044 if ( ! list.isEmpty() ) { 2048 if ( ! list.isEmpty() ) {
2045 x = list[0].toInt(); 2049 x = list[0].toInt();
2046 y = list[1].toInt(); 2050 y = list[1].toInt();
2047 w = list[2].toInt(); 2051 w = list[2].toInt();
2048 h = list[3].toInt(); 2052 h = list[3].toInt();
2049 KApplication::testCoords( &x,&y,&w,&h ); 2053 KApplication::testCoords( &x,&y,&w,&h );
2050 getEventViewerDialog()->setGeometry(x,y,w,h); 2054 getEventViewerDialog()->setGeometry(x,y,w,h);
2051 } 2055 }
2052#endif 2056#endif
2053 config->setGroup( "Views" ); 2057 config->setGroup( "Views" );
2054 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 2058 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
2055 2059
2056 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame"); 2060 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame");
2057 2061
2058 int resetval = 0; 2062 int resetval = 0;
2059 int maxVal = 0; 2063 int maxVal = 0;
2060 if (sizes.count() != 3) { 2064 if (sizes.count() != 3) {
2061 if ( KOPrefs::instance()->mVerticalScreen ) { 2065 if ( KOPrefs::instance()->mVerticalScreen ) {
2062 resetval = mDateNavigator->sizeHint().width()+2; 2066 resetval = mDateNavigator->sizeHint().width()+2;
2063 } else { 2067 } else {
2064 resetval = mDateNavigator->sizeHint().height()+2; 2068 resetval = mDateNavigator->sizeHint().height()+2;
2065 } 2069 }
2066 } 2070 }
2067 if ( resetval ) { 2071 if ( resetval ) {
2068 sizes.clear(); 2072 sizes.clear();
2069 if ( KOPrefs::instance()->mVerticalScreen ) { 2073 if ( KOPrefs::instance()->mVerticalScreen ) {
2070 maxVal = QApplication::desktop()->width() -10; 2074 maxVal = QApplication::desktop()->width() -10;
2071 } else { 2075 } else {
2072 maxVal = QApplication::desktop()->height()-10; 2076 maxVal = QApplication::desktop()->height()-10;
2073 } 2077 }
2074 sizes << resetval; 2078 sizes << resetval;
2075 if ( maxVal < resetval + resetval) 2079 if ( maxVal < resetval + resetval)
2076 resetval = maxVal - resetval; 2080 resetval = maxVal - resetval;
2077 sizes << resetval; 2081 sizes << resetval;
2078 sizes << 100; 2082 sizes << 100;
2079 } 2083 }
2080 mLeftFrame->setSizes(sizes); 2084 mLeftFrame->setSizes(sizes);
2081 sizes = config->readIntListEntry("Main Splitter Frame"); 2085 sizes = config->readIntListEntry("Main Splitter Frame");
2082 resetval = 0; 2086 resetval = 0;
2083 maxVal = 0; 2087 maxVal = 0;
2084 if (sizes.count() != 2) { 2088 if (sizes.count() != 2) {
2085 if ( !KOPrefs::instance()->mVerticalScreen ) { 2089 if ( !KOPrefs::instance()->mVerticalScreen ) {
2086 resetval = mDateNavigator->sizeHint().width()+2; 2090 resetval = mDateNavigator->sizeHint().width()+2;
2087 } else { 2091 } else {
2088 resetval = mDateNavigator->sizeHint().height()+2; 2092 resetval = mDateNavigator->sizeHint().height()+2;
2089 } 2093 }
2090 } 2094 }
2091 if ( resetval ) { 2095 if ( resetval ) {
2092 sizes.clear(); 2096 sizes.clear();
2093 if ( !KOPrefs::instance()->mVerticalScreen ) { 2097 if ( !KOPrefs::instance()->mVerticalScreen ) {
2094 maxVal = QApplication::desktop()->width() -10; 2098 maxVal = QApplication::desktop()->width() -10;
2095 } else { 2099 } else {
2096 maxVal = QApplication::desktop()->height()-10; 2100 maxVal = QApplication::desktop()->height()-10;
2097 } 2101 }
2098 sizes << resetval; 2102 sizes << resetval;
2099 if ( maxVal < resetval + resetval) 2103 if ( maxVal < resetval + resetval)
2100 resetval = maxVal - resetval; 2104 resetval = maxVal - resetval;
2101 sizes << resetval; 2105 sizes << resetval;
2102 } 2106 }
2103 mMainFrame->setSizes(sizes); 2107 mMainFrame->setSizes(sizes);
2104 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 2108 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
2105 else if ( dateCount == 7 ) mNavigator->selectWeek(); 2109 else if ( dateCount == 7 ) mNavigator->selectWeek();
2106 else mNavigator->selectDates( dateCount ); 2110 else mNavigator->selectDates( dateCount );
2107 // mViewManager->readSettings( config ); 2111 // mViewManager->readSettings( config );
2108 updateConfig(); 2112 updateConfig();
2109 globalFlagBlockAgenda = 2; 2113 globalFlagBlockAgenda = 2;
2110 mViewManager->readSettings( config ); 2114 mViewManager->readSettings( config );
2111 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) ); 2115 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) );
2112} 2116}
2113 2117
2114 2118
2115void CalendarView::writeSettings() 2119void CalendarView::writeSettings()
2116{ 2120{
2117 // kdDebug() << "CalendarView::writeSettings" << endl; 2121 // kdDebug() << "CalendarView::writeSettings" << endl;
2118 2122
2119 KConfig *config = KOGlobals::config(); 2123 KConfig *config = KOGlobals::config();
2120 2124
2121 mViewManager->writeSettings( config ); 2125 mViewManager->writeSettings( config );
2122 mTodoList->saveLayout(config,QString("Todo Layout")); 2126 mTodoList->saveLayout(config,QString("Todo Layout"));
2123 mDialogManager->writeSettings( config ); 2127 mDialogManager->writeSettings( config );
2124 //KOPrefs::instance()->usrWriteConfig(); 2128 //KOPrefs::instance()->usrWriteConfig();
2125 KOPrefs::instance()->writeConfig(); 2129 KOPrefs::instance()->writeConfig();
2126 2130
2127 writeFilterSettings(config); 2131 writeFilterSettings(config);
2128 config->setGroup( "AppRun" ); 2132 config->setGroup( "AppRun" );
2129 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 2133 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
2130 config->writeEntry( "LatestProgramStop", dt.secsTo( QDateTime::currentDateTime() ) ); 2134 config->writeEntry( "LatestProgramStop", dt.secsTo( QDateTime::currentDateTime() ) );
2131 config->setGroup( "Views" ); 2135 config->setGroup( "Views" );
2132 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 2136 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
2133 2137
2134 QValueList<int> listINT = mLeftFrame->sizes(); 2138 QValueList<int> listINT = mLeftFrame->sizes();
2135 config->writeEntry("Left Splitter Frame",listINT); 2139 config->writeEntry("Left Splitter Frame",listINT);
2136 QValueList<int> listINT2 = mMainFrame->sizes(); 2140 QValueList<int> listINT2 = mMainFrame->sizes();
2137 config->writeEntry("Main Splitter Frame",listINT2); 2141 config->writeEntry("Main Splitter Frame",listINT2);
2138#ifdef DESKTOP_VERSION 2142#ifdef DESKTOP_VERSION
2139 config->setGroup("WidgetLayout"); 2143 config->setGroup("WidgetLayout");
2140 QStringList list ;//= config->readListEntry("MainLayout"); 2144 QStringList list ;//= config->readListEntry("MainLayout");
2141 int x,y,w,h; 2145 int x,y,w,h;
2142 QWidget* wid; 2146 QWidget* wid;
2143 wid = topLevelWidget(); 2147 wid = topLevelWidget();
2144 x = wid->geometry().x(); 2148 x = wid->geometry().x();
2145 y = wid->geometry().y(); 2149 y = wid->geometry().y();
2146 w = wid->width(); 2150 w = wid->width();
2147 h = wid->height(); 2151 h = wid->height();
2148 list.clear(); 2152 list.clear();
2149 list << QString::number( x ); 2153 list << QString::number( x );
2150 list << QString::number( y ); 2154 list << QString::number( y );
2151 list << QString::number( w ); 2155 list << QString::number( w );
2152 list << QString::number( h ); 2156 list << QString::number( h );
2153 config->writeEntry("MainLayout",list ); 2157 config->writeEntry("MainLayout",list );
2154 2158
2155 wid = mEventEditor; 2159 wid = mEventEditor;
2156 x = wid->geometry().x(); 2160 x = wid->geometry().x();
2157 y = wid->geometry().y(); 2161 y = wid->geometry().y();
2158 w = wid->width(); 2162 w = wid->width();
2159 h = wid->height(); 2163 h = wid->height();
2160 list.clear(); 2164 list.clear();
2161 list << QString::number( x ); 2165 list << QString::number( x );
2162 list << QString::number( y ); 2166 list << QString::number( y );
2163 list << QString::number( w ); 2167 list << QString::number( w );
2164 list << QString::number( h ); 2168 list << QString::number( h );
2165 config->writeEntry("EditEventLayout",list ); 2169 config->writeEntry("EditEventLayout",list );
2166 2170
2167 wid = mTodoEditor; 2171 wid = mTodoEditor;
2168 x = wid->geometry().x(); 2172 x = wid->geometry().x();
2169 y = wid->geometry().y(); 2173 y = wid->geometry().y();
2170 w = wid->width(); 2174 w = wid->width();
2171 h = wid->height(); 2175 h = wid->height();
2172 list.clear(); 2176 list.clear();
2173 list << QString::number( x ); 2177 list << QString::number( x );
2174 list << QString::number( y ); 2178 list << QString::number( y );
2175 list << QString::number( w ); 2179 list << QString::number( w );
2176 list << QString::number( h ); 2180 list << QString::number( h );
2177 config->writeEntry("EditTodoLayout",list ); 2181 config->writeEntry("EditTodoLayout",list );
2178 wid = getEventViewerDialog(); 2182 wid = getEventViewerDialog();
2179 x = wid->geometry().x(); 2183 x = wid->geometry().x();
2180 y = wid->geometry().y(); 2184 y = wid->geometry().y();
2181 w = wid->width(); 2185 w = wid->width();
2182 h = wid->height(); 2186 h = wid->height();
2183 list.clear(); 2187 list.clear();
2184 list << QString::number( x ); 2188 list << QString::number( x );
2185 list << QString::number( y ); 2189 list << QString::number( y );
2186 list << QString::number( w ); 2190 list << QString::number( w );
2187 list << QString::number( h ); 2191 list << QString::number( h );
2188 config->writeEntry("ViewerLayout",list ); 2192 config->writeEntry("ViewerLayout",list );
2189 wid = mDialogManager->getSearchDialog(); 2193 wid = mDialogManager->getSearchDialog();
2190 if ( wid ) { 2194 if ( wid ) {
2191 x = wid->geometry().x(); 2195 x = wid->geometry().x();
2192 y = wid->geometry().y(); 2196 y = wid->geometry().y();
2193 w = wid->width(); 2197 w = wid->width();
2194 h = wid->height(); 2198 h = wid->height();
2195 list.clear(); 2199 list.clear();
2196 list << QString::number( x ); 2200 list << QString::number( x );
2197 list << QString::number( y ); 2201 list << QString::number( y );
2198 list << QString::number( w ); 2202 list << QString::number( w );
2199 list << QString::number( h ); 2203 list << QString::number( h );
2200 config->writeEntry("SearchLayout",list ); 2204 config->writeEntry("SearchLayout",list );
2201 } 2205 }
2202#endif 2206#endif
2203 2207
2204 2208
2205 config->sync(); 2209 config->sync();
2206} 2210}
2207 2211
2208void CalendarView::readFilterSettings(KConfig *config) 2212void CalendarView::readFilterSettings(KConfig *config)
2209{ 2213{
2210 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 2214 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
2211 2215
2212 mFilters.clear(); 2216 mFilters.clear();
2213 2217
2214 config->setGroup("General"); 2218 config->setGroup("General");
2215 QStringList filterList = config->readListEntry("CalendarFilters"); 2219 QStringList filterList = config->readListEntry("CalendarFilters");
2216 2220
2217 QStringList::ConstIterator it = filterList.begin(); 2221 QStringList::ConstIterator it = filterList.begin();
2218 QStringList::ConstIterator end = filterList.end(); 2222 QStringList::ConstIterator end = filterList.end();
2219 while(it != end) { 2223 while(it != end) {
2220 // kdDebug() << " filter: " << (*it) << endl; 2224 // kdDebug() << " filter: " << (*it) << endl;
2221 2225
2222 CalFilter *filter; 2226 CalFilter *filter;
2223 filter = new CalFilter(*it); 2227 filter = new CalFilter(*it);
2224 config->setGroup("Filter_" + (*it).utf8()); 2228 config->setGroup("Filter_" + (*it).utf8());
2225 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 2229 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
2226 filter->setCriteria(config->readNumEntry("Criteria",0)); 2230 filter->setCriteria(config->readNumEntry("Criteria",0));
2227 filter->setCategoryList(config->readListEntry("CategoryList")); 2231 filter->setCategoryList(config->readListEntry("CategoryList"));
2228 mFilters.append(filter); 2232 mFilters.append(filter);
2229 2233
2230 ++it; 2234 ++it;
2231 } 2235 }
2232 2236
2233 if (mFilters.count() == 0) { 2237 if (mFilters.count() == 0) {
2234 CalFilter *filter = new CalFilter(i18n("Default")); 2238 CalFilter *filter = new CalFilter(i18n("Default"));
2235 mFilters.append(filter); 2239 mFilters.append(filter);
2236 } 2240 }
2237 mFilterView->updateFilters(); 2241 mFilterView->updateFilters();
2238 config->setGroup("FilterView"); 2242 config->setGroup("FilterView");
2239 2243
2240 mFilterView->blockSignals(true); 2244 mFilterView->blockSignals(true);
2241 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 2245 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
2242 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 2246 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
2243 mFilterView->blockSignals(false); 2247 mFilterView->blockSignals(false);
2244 // We do it manually to avoid it being done twice by the above calls 2248 // We do it manually to avoid it being done twice by the above calls
2245 updateFilter(); 2249 updateFilter();
2246} 2250}
2247 2251
2248void CalendarView::writeFilterSettings(KConfig *config) 2252void CalendarView::writeFilterSettings(KConfig *config)
2249{ 2253{
2250 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 2254 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
2251 2255
2252 QStringList filterList; 2256 QStringList filterList;
2253 2257
2254 CalFilter *filter = mFilters.first(); 2258 CalFilter *filter = mFilters.first();
2255 while(filter) { 2259 while(filter) {
2256 // kdDebug() << " fn: " << filter->name() << endl; 2260 // kdDebug() << " fn: " << filter->name() << endl;
2257 filterList << filter->name(); 2261 filterList << filter->name();
2258 config->setGroup("Filter_" + filter->name().utf8()); 2262 config->setGroup("Filter_" + filter->name().utf8());
2259 config->writeEntry("Criteria",filter->criteria()); 2263 config->writeEntry("Criteria",filter->criteria());
2260 config->writeEntry("CategoryList",filter->categoryList()); 2264 config->writeEntry("CategoryList",filter->categoryList());
2261 filter = mFilters.next(); 2265 filter = mFilters.next();
2262 } 2266 }
2263 config->setGroup("General"); 2267 config->setGroup("General");
2264 config->writeEntry("CalendarFilters",filterList); 2268 config->writeEntry("CalendarFilters",filterList);
2265 2269
2266 config->setGroup("FilterView"); 2270 config->setGroup("FilterView");
2267 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 2271 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
2268 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 2272 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
2269} 2273}
2270 2274
2271 2275
2272void CalendarView::goToday() 2276void CalendarView::goToday()
2273{ 2277{
2274 if ( mViewManager->currentView()->isMonthView() ) 2278 if ( mViewManager->currentView()->isMonthView() )
2275 mNavigator->selectTodayMonth(); 2279 mNavigator->selectTodayMonth();
2276 else 2280 else
2277 mNavigator->selectToday(); 2281 mNavigator->selectToday();
2278} 2282}
2279 2283
2280void CalendarView::goNext() 2284void CalendarView::goNext()
2281{ 2285{
2282 mNavigator->selectNext(); 2286 mNavigator->selectNext();
2283} 2287}
2284 2288
2285void CalendarView::goPrevious() 2289void CalendarView::goPrevious()
2286{ 2290{
2287 mNavigator->selectPrevious(); 2291 mNavigator->selectPrevious();
2288} 2292}
2289void CalendarView::goNextMonth() 2293void CalendarView::goNextMonth()
2290{ 2294{
2291 mNavigator->selectNextMonth(); 2295 mNavigator->selectNextMonth();
2292} 2296}
2293 2297
2294void CalendarView::goPreviousMonth() 2298void CalendarView::goPreviousMonth()
2295{ 2299{
2296 mNavigator->selectPreviousMonth(); 2300 mNavigator->selectPreviousMonth();
2297} 2301}
2298void CalendarView::writeLocale() 2302void CalendarView::writeLocale()
2299{ 2303{
2300 //KPimGlobalPrefs::instance()->setGlobalConfig(); 2304 //KPimGlobalPrefs::instance()->setGlobalConfig();
2301#if 0 2305#if 0
2302 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); 2306 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime );
2303 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); 2307 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday );
2304 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); 2308 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate );
2305 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); 2309 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage );
2306 QString dummy = KOPrefs::instance()->mUserDateFormatLong; 2310 QString dummy = KOPrefs::instance()->mUserDateFormatLong;
2307 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); 2311 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") ));
2308 dummy = KOPrefs::instance()->mUserDateFormatShort; 2312 dummy = KOPrefs::instance()->mUserDateFormatShort;
2309 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 2313 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
2310 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, 2314 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving,
2311 KOPrefs::instance()->mDaylightsavingStart, 2315 KOPrefs::instance()->mDaylightsavingStart,
2312 KOPrefs::instance()->mDaylightsavingEnd ); 2316 KOPrefs::instance()->mDaylightsavingEnd );
2313 KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId ); 2317 KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId );
2314#endif 2318#endif
2315} 2319}
2316void CalendarView::updateConfig() 2320void CalendarView::updateConfig()
2317{ 2321{
2318 writeLocale(); 2322 writeLocale();
2319 if ( KOPrefs::instance()->mUseAppColors ) 2323 if ( KOPrefs::instance()->mUseAppColors )
2320 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 2324 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
2321 emit configChanged(); 2325 emit configChanged();
2322 mTodoList->updateConfig(); 2326 mTodoList->updateConfig();
2323 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 2327 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
2324 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2328 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2325 // To make the "fill window" configurations work 2329 // To make the "fill window" configurations work
2326 //mViewManager->raiseCurrentView(); 2330 //mViewManager->raiseCurrentView();
2327} 2331}
2328 2332
2329 2333
2330void CalendarView::eventChanged(Event *event) 2334void CalendarView::eventChanged(Event *event)
2331{ 2335{
2332 changeEventDisplay(event,KOGlobals::EVENTEDITED); 2336 changeEventDisplay(event,KOGlobals::EVENTEDITED);
2333 //updateUnmanagedViews(); 2337 //updateUnmanagedViews();
2334} 2338}
2335 2339
2336void CalendarView::eventAdded(Event *event) 2340void CalendarView::eventAdded(Event *event)
2337{ 2341{
2338 changeEventDisplay(event,KOGlobals::EVENTADDED); 2342 changeEventDisplay(event,KOGlobals::EVENTADDED);
2339} 2343}
2340 2344
2341void CalendarView::eventToBeDeleted(Event *) 2345void CalendarView::eventToBeDeleted(Event *)
2342{ 2346{
2343 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 2347 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
2344} 2348}
2345 2349
2346void CalendarView::eventDeleted() 2350void CalendarView::eventDeleted()
2347{ 2351{
2348 changeEventDisplay(0,KOGlobals::EVENTDELETED); 2352 changeEventDisplay(0,KOGlobals::EVENTDELETED);
2349} 2353}
2350void CalendarView::changeTodoDisplay(Todo *which, int action) 2354void CalendarView::changeTodoDisplay(Todo *which, int action)
2351{ 2355{
2352 changeIncidenceDisplay((Incidence *)which, action); 2356 changeIncidenceDisplay((Incidence *)which, action);
2353 mDateNavigator->updateView(); //LR 2357 mDateNavigator->updateView(); //LR
2354 //mDialogManager->updateSearchDialog(); 2358 //mDialogManager->updateSearchDialog();
2355 2359
2356 if (which) { 2360 if (which) {
2357 mViewManager->updateWNview(); 2361 mViewManager->updateWNview();
2358 //mTodoList->updateView(); 2362 //mTodoList->updateView();
2359 } 2363 }
2360 2364
2361} 2365}
2362 2366
2363void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 2367void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
2364{ 2368{
2365 updateUnmanagedViews(); 2369 updateUnmanagedViews();
2366 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 2370 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
2367 if ( action == KOGlobals::EVENTDELETED ) { //delete 2371 if ( action == KOGlobals::EVENTDELETED ) { //delete
2368 mCalendar->checkAlarmForIncidence( 0, true ); 2372 mCalendar->checkAlarmForIncidence( 0, true );
2369 if ( mEventViewerDialog ) 2373 if ( mEventViewerDialog )
2370 mEventViewerDialog->hide(); 2374 mEventViewerDialog->hide();
2371 } 2375 }
2372 else 2376 else
2373 mCalendar->checkAlarmForIncidence( which , false ); 2377 mCalendar->checkAlarmForIncidence( which , false );
2374} 2378}
2375 2379
2376// most of the changeEventDisplays() right now just call the view's 2380// most of the changeEventDisplays() right now just call the view's
2377// total update mode, but they SHOULD be recoded to be more refresh-efficient. 2381// total update mode, but they SHOULD be recoded to be more refresh-efficient.
2378void CalendarView::changeEventDisplay(Event *which, int action) 2382void CalendarView::changeEventDisplay(Event *which, int action)
2379{ 2383{
2380 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 2384 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
2381 changeIncidenceDisplay((Incidence *)which, action); 2385 changeIncidenceDisplay((Incidence *)which, action);
2382 mDateNavigator->updateView(); 2386 mDateNavigator->updateView();
2383 //mDialogManager->updateSearchDialog(); 2387 //mDialogManager->updateSearchDialog();
2384 2388
2385 if (which) { 2389 if (which) {
2386 // If there is an event view visible update the display 2390 // If there is an event view visible update the display
2387 mViewManager->currentView()->changeEventDisplay(which,action); 2391 mViewManager->currentView()->changeEventDisplay(which,action);
2388 // TODO: check, if update needed 2392 // TODO: check, if update needed
2389 // if (which->getTodoStatus()) { 2393 // if (which->getTodoStatus()) {
2390 mTodoList->updateView(); 2394 mTodoList->updateView();
2391 // } 2395 // }
2392 } else { 2396 } else {
2393 mViewManager->currentView()->updateView(); 2397 mViewManager->currentView()->updateView();
2394 } 2398 }
2395} 2399}
2396 2400
2397 2401
2398void CalendarView::updateTodoViews() 2402void CalendarView::updateTodoViews()
2399{ 2403{
2400 mTodoList->updateView(); 2404 mTodoList->updateView();
2401 mViewManager->currentView()->updateView(); 2405 mViewManager->currentView()->updateView();
2402 2406
2403} 2407}
2404 2408
2405 2409
2406void CalendarView::updateView(const QDate &start, const QDate &end) 2410void CalendarView::updateView(const QDate &start, const QDate &end)
2407{ 2411{
2408 mTodoList->updateView(); 2412 mTodoList->updateView();
2409 mViewManager->updateView(start, end); 2413 mViewManager->updateView(start, end);
2410 //mDateNavigator->updateView(); 2414 //mDateNavigator->updateView();
2411} 2415}
2412 2416
2413void CalendarView::updateView() 2417void CalendarView::updateView()
2414{ 2418{
2415 DateList tmpList = mNavigator->selectedDates(); 2419 DateList tmpList = mNavigator->selectedDates();
2416 2420
2417 if ( KOPrefs::instance()->mHideNonStartedTodos ) 2421 if ( KOPrefs::instance()->mHideNonStartedTodos )
2418 mTodoList->updateView(); 2422 mTodoList->updateView();
2419 // We assume that the navigator only selects consecutive days. 2423 // We assume that the navigator only selects consecutive days.
2420 updateView( tmpList.first(), tmpList.last() ); 2424 updateView( tmpList.first(), tmpList.last() );
2421} 2425}
2422 2426
2423void CalendarView::updateUnmanagedViews() 2427void CalendarView::updateUnmanagedViews()
2424{ 2428{
2425 mDateNavigator->updateDayMatrix(); 2429 mDateNavigator->updateDayMatrix();
2426} 2430}
2427 2431
2428int CalendarView::msgItemDelete(const QString name) 2432int CalendarView::msgItemDelete(const QString name)
2429{ 2433{
2430 return KMessageBox::warningContinueCancel(this,name +"\n\n"+ 2434 return KMessageBox::warningContinueCancel(this,name +"\n\n"+
2431 i18n("This item will be\npermanently deleted."), 2435 i18n("This item will be\npermanently deleted."),
2432 i18n("KO/Pi Confirmation"),i18n("Delete")); 2436 i18n("KO/Pi Confirmation"),i18n("Delete"));
2433} 2437}
2434 2438
2435 2439
2436void CalendarView::edit_cut() 2440void CalendarView::edit_cut()
2437{ 2441{
2438 Event *anEvent=0; 2442 Event *anEvent=0;
2439 2443
2440 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2444 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2441 2445
2442 if (mViewManager->currentView()->isEventView()) { 2446 if (mViewManager->currentView()->isEventView()) {
2443 if ( incidence && incidence->type() == "Event" ) { 2447 if ( incidence && incidence->type() == "Event" ) {
2444 anEvent = static_cast<Event *>(incidence); 2448 anEvent = static_cast<Event *>(incidence);
2445 } 2449 }
2446 } 2450 }
2447 2451
2448 if (!anEvent) { 2452 if (!anEvent) {
2449 KNotifyClient::beep(); 2453 KNotifyClient::beep();
2450 return; 2454 return;
2451 } 2455 }
2452 DndFactory factory( mCalendar ); 2456 DndFactory factory( mCalendar );
2453 factory.cutIncidence(anEvent); 2457 factory.cutIncidence(anEvent);
2454 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2458 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2455} 2459}
2456 2460
2457void CalendarView::edit_copy() 2461void CalendarView::edit_copy()
2458{ 2462{
2459 Event *anEvent=0; 2463 Event *anEvent=0;
2460 2464
2461 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2465 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2462 2466
2463 if (mViewManager->currentView()->isEventView()) { 2467 if (mViewManager->currentView()->isEventView()) {
2464 if ( incidence && incidence->type() == "Event" ) { 2468 if ( incidence && incidence->type() == "Event" ) {
2465 anEvent = static_cast<Event *>(incidence); 2469 anEvent = static_cast<Event *>(incidence);
2466 } 2470 }
2467 } 2471 }
2468 2472
2469 if (!anEvent) { 2473 if (!anEvent) {
2470 KNotifyClient::beep(); 2474 KNotifyClient::beep();
2471 return; 2475 return;
2472 } 2476 }
2473 DndFactory factory( mCalendar ); 2477 DndFactory factory( mCalendar );
2474 factory.copyIncidence(anEvent); 2478 factory.copyIncidence(anEvent);
2475} 2479}
2476 2480
2477void CalendarView::edit_paste() 2481void CalendarView::edit_paste()
2478{ 2482{
2479 QDate date = mNavigator->selectedDates().first(); 2483 QDate date = mNavigator->selectedDates().first();
2480 2484
2481 DndFactory factory( mCalendar ); 2485 DndFactory factory( mCalendar );
2482 Event *pastedEvent = (Event *)factory.pasteIncidence( date ); 2486 Event *pastedEvent = (Event *)factory.pasteIncidence( date );
2483 2487
2484 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2488 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2485} 2489}
2486 2490
2487void CalendarView::edit_options() 2491void CalendarView::edit_options()
2488{ 2492{
2489 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId; 2493 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId;
2490 emit save(); 2494 emit save();
2491 emit saveStopTimer(); 2495 emit saveStopTimer();
2492 mDialogManager->showOptionsDialog(); 2496 mDialogManager->showOptionsDialog();
2493 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) { 2497 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) {
2494 emit saveStopTimer(); 2498 emit saveStopTimer();
2495 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto apply timezone changes?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"), 2499 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto apply timezone changes?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"),
2496 i18n("Timezone settings"),i18n("Reload"))) { 2500 i18n("Timezone settings"),i18n("Reload"))) {
2497 qDebug("KO: TZ reload cancelled "); 2501 qDebug("KO: TZ reload cancelled ");
2498 return; 2502 return;
2499 } 2503 }
2500 qDebug("KO: Timezone change "); 2504 qDebug("KO: Timezone change ");
2501 openCalendar( MainWindow::defaultFileName() ); 2505 openCalendar( MainWindow::defaultFileName() );
2502 setModified(true); 2506 setModified(true);
2503 } 2507 }
2504 else 2508 else
2505 qDebug("KO: No tz change "); 2509 qDebug("KO: No tz change ");
2506 2510
2507} 2511}
2508 2512
2509 2513
2510void CalendarView::slotSelectPickerDate( QDate d) 2514void CalendarView::slotSelectPickerDate( QDate d)
2511{ 2515{
2512 mDateFrame->hide(); 2516 mDateFrame->hide();
2513 if ( mDatePickerMode == 1 ) { 2517 if ( mDatePickerMode == 1 ) {
2514 mNavigator->slotDaySelect( d ); 2518 mNavigator->slotDaySelect( d );
2515 } else if ( mDatePickerMode == 2 ) { 2519 } else if ( mDatePickerMode == 2 ) {
2516 if ( mMoveIncidence->type() == "Todo" ) { 2520 if ( mMoveIncidence->type() == "Todo" ) {
2517 Todo * to = (Todo *) mMoveIncidence; 2521 Todo * to = (Todo *) mMoveIncidence;
2518 QTime tim; 2522 QTime tim;
2519 int len = 0; 2523 int len = 0;
2520 if ( to->hasStartDate() && to->hasDueDate() ) 2524 if ( to->hasStartDate() && to->hasDueDate() )
2521 len = to->dtStart().secsTo( to->dtDue()); 2525 len = to->dtStart().secsTo( to->dtDue());
2522 if ( to->hasDueDate() ) 2526 if ( to->hasDueDate() )
2523 tim = to->dtDue().time(); 2527 tim = to->dtDue().time();
2524 else { 2528 else {
2525 tim = QTime ( 0,0,0 ); 2529 tim = QTime ( 0,0,0 );
2526 to->setFloats( true ); 2530 to->setFloats( true );
2527 to->setHasDueDate( true ); 2531 to->setHasDueDate( true );
2528 } 2532 }
2529 QDateTime dt ( d,tim ); 2533 QDateTime dt ( d,tim );
2530 to->setDtDue( dt ); 2534 to->setDtDue( dt );
2531 2535
2532 if ( to->hasStartDate() ) { 2536 if ( to->hasStartDate() ) {
2533 if ( len>0 ) 2537 if ( len>0 )
2534 to->setDtStart(to->dtDue().addSecs( -len )); 2538 to->setDtStart(to->dtDue().addSecs( -len ));
2535 else 2539 else
2536 if (to->dtStart() > to->dtDue() ) 2540 if (to->dtStart() > to->dtDue() )
2537 to->setDtStart(to->dtDue().addDays( -3 )); 2541 to->setDtStart(to->dtDue().addDays( -3 ));
2538 } 2542 }
2539 2543
2540 todoChanged( to ); 2544 todoChanged( to );
2541 } else { 2545 } else {
2542 if ( mMoveIncidence->doesRecur() ) { 2546 if ( mMoveIncidence->doesRecur() ) {
2543#if 0 2547#if 0
2544 // PENDING implement this 2548 // PENDING implement this
2545 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate ); 2549 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate );
2546 mCalendar()->addIncidence( newInc ); 2550 mCalendar()->addIncidence( newInc );
2547 if ( mMoveIncidence->type() == "Todo" ) 2551 if ( mMoveIncidence->type() == "Todo" )
2548 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED ); 2552 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED );
2549 else 2553 else
2550 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED); 2554 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED);
2551 mMoveIncidence = newInc; 2555 mMoveIncidence = newInc;
2552 2556
2553#endif 2557#endif
2554 } 2558 }
2555 QTime tim = mMoveIncidence->dtStart().time(); 2559 QTime tim = mMoveIncidence->dtStart().time();
2556 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 2560 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
2557 QDateTime dt ( d,tim ); 2561 QDateTime dt ( d,tim );
2558 mMoveIncidence->setDtStart( dt ); 2562 mMoveIncidence->setDtStart( dt );
2559 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 2563 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
2560 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 2564 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
2561 } 2565 }
2562 2566
2563 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 2567 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
2564 } 2568 }
2565} 2569}
2566 2570
2567void CalendarView::removeCategories() 2571void CalendarView::removeCategories()
2568{ 2572{
2569 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2573 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2570 QStringList catList = KOPrefs::instance()->mCustomCategories; 2574 QStringList catList = KOPrefs::instance()->mCustomCategories;
2571 QStringList catIncList; 2575 QStringList catIncList;
2572 QStringList newCatList; 2576 QStringList newCatList;
2573 Incidence* inc = incList.first(); 2577 Incidence* inc = incList.first();
2574 int i; 2578 int i;
2575 int count = 0; 2579 int count = 0;
2576 while ( inc ) { 2580 while ( inc ) {
2577 newCatList.clear(); 2581 newCatList.clear();
2578 catIncList = inc->categories() ; 2582 catIncList = inc->categories() ;
2579 for( i = 0; i< catIncList.count(); ++i ) { 2583 for( i = 0; i< catIncList.count(); ++i ) {
2580 if ( catList.contains (catIncList[i])) 2584 if ( catList.contains (catIncList[i]))
2581 newCatList.append( catIncList[i] ); 2585 newCatList.append( catIncList[i] );
2582 } 2586 }
2583 newCatList.sort(); 2587 newCatList.sort();
2584 inc->setCategories( newCatList.join(",") ); 2588 inc->setCategories( newCatList.join(",") );
2585 inc = incList.next(); 2589 inc = incList.next();
2586 } 2590 }
2587} 2591}
2588 2592
2589int CalendarView::addCategories() 2593int CalendarView::addCategories()
2590{ 2594{
2591 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2595 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2592 QStringList catList = KOPrefs::instance()->mCustomCategories; 2596 QStringList catList = KOPrefs::instance()->mCustomCategories;
2593 QStringList catIncList; 2597 QStringList catIncList;
2594 Incidence* inc = incList.first(); 2598 Incidence* inc = incList.first();
2595 int i; 2599 int i;
2596 int count = 0; 2600 int count = 0;
2597 while ( inc ) { 2601 while ( inc ) {
2598 catIncList = inc->categories() ; 2602 catIncList = inc->categories() ;
2599 for( i = 0; i< catIncList.count(); ++i ) { 2603 for( i = 0; i< catIncList.count(); ++i ) {
2600 if ( !catList.contains (catIncList[i])) { 2604 if ( !catList.contains (catIncList[i])) {
2601 catList.append( catIncList[i] ); 2605 catList.append( catIncList[i] );
2602 //qDebug("add cat %s ", catIncList[i].latin1()); 2606 //qDebug("add cat %s ", catIncList[i].latin1());
2603 ++count; 2607 ++count;
2604 } 2608 }
2605 } 2609 }
2606 inc = incList.next(); 2610 inc = incList.next();
2607 } 2611 }
2608 catList.sort(); 2612 catList.sort();
2609 KOPrefs::instance()->mCustomCategories = catList; 2613 KOPrefs::instance()->mCustomCategories = catList;
2610 return count; 2614 return count;
2611} 2615}
2612 2616
2613void CalendarView::manageCategories() 2617void CalendarView::manageCategories()
2614{ 2618{
2615 KOCatPrefs* cp = new KOCatPrefs(); 2619 KOCatPrefs* cp = new KOCatPrefs();
2616 cp->show(); 2620 cp->show();
2617 int w =cp->sizeHint().width() ; 2621 int w =cp->sizeHint().width() ;
2618 int h = cp->sizeHint().height() ; 2622 int h = cp->sizeHint().height() ;
2619 int dw = QApplication::desktop()->width(); 2623 int dw = QApplication::desktop()->width();
2620 int dh = QApplication::desktop()->height(); 2624 int dh = QApplication::desktop()->height();
2621 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2625 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2622 if ( !cp->exec() ) { 2626 if ( !cp->exec() ) {
2623 delete cp; 2627 delete cp;
2624 return; 2628 return;
2625 } 2629 }
2626 int count = 0; 2630 int count = 0;
2627 if ( cp->addCat() ) { 2631 if ( cp->addCat() ) {
2628 count = addCategories(); 2632 count = addCategories();
2629 if ( count ) { 2633 if ( count ) {
2630 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 2634 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
2631 writeSettings(); 2635 writeSettings();
2632 } else 2636 } else
2633 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! ")); 2637 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! "));
2634 } else { 2638 } else {
2635 removeCategories(); 2639 removeCategories();
2636 updateView(); 2640 updateView();
2637 } 2641 }
2638 delete cp; 2642 delete cp;
2639} 2643}
2640 2644
2641void CalendarView::beamIncidence(Incidence * Inc) 2645void CalendarView::beamIncidence(Incidence * Inc)
2642{ 2646{
2643 QPtrList<Incidence> delSel ; 2647 QPtrList<Incidence> delSel ;
2644 delSel.append(Inc); 2648 delSel.append(Inc);
2645 beamIncidenceList( delSel ); 2649 beamIncidenceList( delSel );
2646} 2650}
2647void CalendarView::beamCalendar() 2651void CalendarView::beamCalendar()
2648{ 2652{
2649 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 2653 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
2650 //qDebug("beamCalendar() "); 2654 //qDebug("beamCalendar() ");
2651 beamIncidenceList( delSel ); 2655 beamIncidenceList( delSel );
2652} 2656}
2653void CalendarView::beamFilteredCalendar() 2657void CalendarView::beamFilteredCalendar()
2654{ 2658{
2655 QPtrList<Incidence> delSel = mCalendar->incidences(); 2659 QPtrList<Incidence> delSel = mCalendar->incidences();
2656 //qDebug("beamFilteredCalendar() "); 2660 //qDebug("beamFilteredCalendar() ");
2657 beamIncidenceList( delSel ); 2661 beamIncidenceList( delSel );
2658} 2662}
2659void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 2663void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
2660{ 2664{
2661 if ( beamDialog->exec () == QDialog::Rejected ) 2665 if ( beamDialog->exec () == QDialog::Rejected )
2662 return; 2666 return;
2663#ifdef DESKTOP_VERSION 2667#ifdef DESKTOP_VERSION
2664 QString fn = locateLocal( "tmp", "kopibeamfile" ); 2668 QString fn = locateLocal( "tmp", "kopibeamfile" );
2665#else 2669#else
2666 QString fn = "/tmp/kopibeamfile"; 2670 QString fn = "/tmp/kopibeamfile";
2667#endif 2671#endif
2668 QString mes; 2672 QString mes;
2669 bool createbup = true; 2673 bool createbup = true;
2670 if ( createbup ) { 2674 if ( createbup ) {
2671 QString description = "\n"; 2675 QString description = "\n";
2672 CalendarLocal* cal = new CalendarLocal(); 2676 CalendarLocal* cal = new CalendarLocal();
2673 if ( beamDialog->beamLocal() ) 2677 if ( beamDialog->beamLocal() )
2674 cal->setLocalTime(); 2678 cal->setLocalTime();
2675 else 2679 else
2676 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2680 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2677 Incidence *incidence = delSel.first(); 2681 Incidence *incidence = delSel.first();
2678 bool addText = false; 2682 bool addText = false;
2679 if ( delSel.count() < 10 ) 2683 if ( delSel.count() < 10 )
2680 addText = true; 2684 addText = true;
2681 else { 2685 else {
2682 description.sprintf(i18n(" %d items?"),delSel.count() ); 2686 description.sprintf(i18n(" %d items?"),delSel.count() );
2683 } 2687 }
2684 while ( incidence ) { 2688 while ( incidence ) {
2685 Incidence *in = incidence->clone(); 2689 Incidence *in = incidence->clone();
2686 if ( ! in->summary().isEmpty() ) { 2690 if ( ! in->summary().isEmpty() ) {
2687 in->setDescription(""); 2691 in->setDescription("");
2688 } else { 2692 } else {
2689 in->setSummary( in->description().left(20)); 2693 in->setSummary( in->description().left(20));
2690 in->setDescription(""); 2694 in->setDescription("");
2691 } 2695 }
2692 if ( addText ) 2696 if ( addText )
2693 description += in->summary() + "\n"; 2697 description += in->summary() + "\n";
2694 cal->addIncidence( in ); 2698 cal->addIncidence( in );
2695 incidence = delSel.next(); 2699 incidence = delSel.next();
2696 } 2700 }
2697 if ( beamDialog->beamVcal() ) { 2701 if ( beamDialog->beamVcal() ) {
2698 fn += ".vcs"; 2702 fn += ".vcs";
2699 FileStorage storage( cal, fn, new VCalFormat ); 2703 FileStorage storage( cal, fn, new VCalFormat );
2700 storage.save(); 2704 storage.save();
2701 } else { 2705 } else {
2702 fn += ".ics"; 2706 fn += ".ics";
2703 FileStorage storage( cal, fn, new ICalFormat( ) ); 2707 FileStorage storage( cal, fn, new ICalFormat( ) );
2704 storage.save(); 2708 storage.save();
2705 } 2709 }
2706 delete cal; 2710 delete cal;
2707 mes = i18n("KO/Pi: Ready for beaming"); 2711 mes = i18n("KO/Pi: Ready for beaming");
2708 topLevelWidget()->setCaption(mes); 2712 topLevelWidget()->setCaption(mes);
2709 KApplication::convert2latin1( fn ); 2713 KApplication::convert2latin1( fn );
2710#ifndef DESKTOP_VERSION 2714#ifndef DESKTOP_VERSION
2711 Ir *ir = new Ir( this ); 2715 Ir *ir = new Ir( this );
2712 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 2716 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
2713 ir->send( fn, description, "text/x-vCalendar" ); 2717 ir->send( fn, description, "text/x-vCalendar" );
2714#endif 2718#endif
2715 } 2719 }
2716} 2720}
2717void CalendarView::beamDone( Ir *ir ) 2721void CalendarView::beamDone( Ir *ir )
2718{ 2722{
2719#ifndef DESKTOP_VERSION 2723#ifndef DESKTOP_VERSION
2720 delete ir; 2724 delete ir;
2721#endif 2725#endif
2722 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); 2726 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") );
2723 topLevelWidget()->raise(); 2727 topLevelWidget()->raise();
2724} 2728}
2725 2729
2726void CalendarView::moveIncidence(Incidence * inc ) 2730void CalendarView::moveIncidence(Incidence * inc )
2727{ 2731{
2728 if ( !inc ) return; 2732 if ( !inc ) return;
2729 showDatePickerPopup(); 2733 showDatePickerPopup();
2730 mDatePickerMode = 2; 2734 mDatePickerMode = 2;
2731 mMoveIncidence = inc ; 2735 mMoveIncidence = inc ;
2732 QDate da; 2736 QDate da;
2733 if ( mMoveIncidence->type() == "Todo" ) { 2737 if ( mMoveIncidence->type() == "Todo" ) {
2734 Todo * to = (Todo *) mMoveIncidence; 2738 Todo * to = (Todo *) mMoveIncidence;
2735 if ( to->hasDueDate() ) 2739 if ( to->hasDueDate() )
2736 da = to->dtDue().date(); 2740 da = to->dtDue().date();
2737 else 2741 else
2738 da = QDate::currentDate(); 2742 da = QDate::currentDate();
2739 } else { 2743 } else {
2740 da = mMoveIncidence->dtStart().date(); 2744 da = mMoveIncidence->dtStart().date();
2741 } 2745 }
2742 //PENDING set date for recurring incidence to date of recurrence 2746 //PENDING set date for recurring incidence to date of recurrence
2743 //mMoveIncidenceOldDate; 2747 //mMoveIncidenceOldDate;
2744 mDatePicker->setDate( da ); 2748 mDatePicker->setDate( da );
2745} 2749}
2746void CalendarView::showDatePickerPopup() 2750void CalendarView::showDatePickerPopup()
2747{ 2751{
2748 if ( mDateFrame->isVisible() ) 2752 if ( mDateFrame->isVisible() )
2749 mDateFrame->hide(); 2753 mDateFrame->hide();
2750 else { 2754 else {
2751 int offX = 0, offY = 0; 2755 int offX = 0, offY = 0;
2752#ifdef DESKTOP_VERSION 2756#ifdef DESKTOP_VERSION
2753 int w =mDatePicker->sizeHint().width() ; 2757 int w =mDatePicker->sizeHint().width() ;
2754 int h = mDatePicker->sizeHint().height() ; 2758 int h = mDatePicker->sizeHint().height() ;
2755 int dw = topLevelWidget()->width(); 2759 int dw = topLevelWidget()->width();
2756 int dh = topLevelWidget()->height(); 2760 int dh = topLevelWidget()->height();
2757 offX = topLevelWidget()->x(); 2761 offX = topLevelWidget()->x();
2758 offY = topLevelWidget()->y(); 2762 offY = topLevelWidget()->y();
2759#else 2763#else
2760 int w =mDatePicker->sizeHint().width() ; 2764 int w =mDatePicker->sizeHint().width() ;
2761 int h = mDatePicker->sizeHint().height() ; 2765 int h = mDatePicker->sizeHint().height() ;
2762 int dw = QApplication::desktop()->width(); 2766 int dw = QApplication::desktop()->width();
2763 int dh = QApplication::desktop()->height(); 2767 int dh = QApplication::desktop()->height();
2764#endif 2768#endif
2765 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h ); 2769 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h );
2766 mDateFrame->show(); 2770 mDateFrame->show();
2767 } 2771 }
2768} 2772}
2769void CalendarView::showDatePicker( ) 2773void CalendarView::showDatePicker( )
2770{ 2774{
2771 showDatePickerPopup(); 2775 showDatePickerPopup();
2772 mDatePickerMode = 1; 2776 mDatePickerMode = 1;
2773 mDatePicker->setDate( mNavigator->selectedDates().first() ); 2777 mDatePicker->setDate( mNavigator->selectedDates().first() );
2774} 2778}
2775 2779
2776void CalendarView::showEventEditor() 2780void CalendarView::showEventEditor()
2777{ 2781{
2778#ifdef DESKTOP_VERSION 2782#ifdef DESKTOP_VERSION
2779 int x,y,w,h; 2783 int x,y,w,h;
2780 x = mEventEditor->geometry().x(); 2784 x = mEventEditor->geometry().x();
2781 y = mEventEditor->geometry().y(); 2785 y = mEventEditor->geometry().y();
2782 w = mEventEditor->width(); 2786 w = mEventEditor->width();
2783 h = mEventEditor->height(); 2787 h = mEventEditor->height();
2784 mEventEditor->show(); 2788 mEventEditor->show();
2785 mEventEditor->setGeometry(x,y,w,h); 2789 mEventEditor->setGeometry(x,y,w,h);
2786#else 2790#else
2787 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) { 2791 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) {
2788 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 2792 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
2789 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() ); 2793 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() );
2790 qApp->processEvents(); 2794 qApp->processEvents();
2791 delete mEventEditor; 2795 delete mEventEditor;
2792 mEventEditor = mDialogManager->getEventEditor(); 2796 mEventEditor = mDialogManager->getEventEditor();
2793 topLevelWidget()->setCaption( i18n("") ); 2797 topLevelWidget()->setCaption( i18n("") );
2794 } 2798 }
2795 mEventEditor->showMaximized(); 2799 mEventEditor->showMaximized();
2796#endif 2800#endif
2797} 2801}
2798void CalendarView::showTodoEditor() 2802void CalendarView::showTodoEditor()
2799{ 2803{
2800#ifdef DESKTOP_VERSION 2804#ifdef DESKTOP_VERSION
2801 int x,y,w,h; 2805 int x,y,w,h;
2802 x = mTodoEditor->geometry().x(); 2806 x = mTodoEditor->geometry().x();
2803 y = mTodoEditor->geometry().y(); 2807 y = mTodoEditor->geometry().y();
2804 w = mTodoEditor->width(); 2808 w = mTodoEditor->width();
2805 h = mTodoEditor->height(); 2809 h = mTodoEditor->height();
2806 mTodoEditor->show(); 2810 mTodoEditor->show();
2807 mTodoEditor->setGeometry(x,y,w,h); 2811 mTodoEditor->setGeometry(x,y,w,h);
2808#else 2812#else
2809 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) { 2813 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) {
2810 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 2814 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
2811 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() ); 2815 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() );
2812 qApp->processEvents(); 2816 qApp->processEvents();
2813 delete mTodoEditor; 2817 delete mTodoEditor;
2814 mTodoEditor = mDialogManager->getTodoEditor(); 2818 mTodoEditor = mDialogManager->getTodoEditor();
2815 topLevelWidget()->setCaption( i18n("") ); 2819 topLevelWidget()->setCaption( i18n("") );
2816 } 2820 }
2817 mTodoEditor->showMaximized(); 2821 mTodoEditor->showMaximized();
2818#endif 2822#endif
2819} 2823}
2820 2824
2821void CalendarView::cloneIncidence() 2825void CalendarView::cloneIncidence()
2822{ 2826{
2823 Incidence *incidence = currentSelection(); 2827 Incidence *incidence = currentSelection();
2824 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2828 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2825 if ( incidence ) { 2829 if ( incidence ) {
2826 cloneIncidence(incidence); 2830 cloneIncidence(incidence);
2827 } 2831 }
2828} 2832}
2829void CalendarView::moveIncidence() 2833void CalendarView::moveIncidence()
2830{ 2834{
2831 Incidence *incidence = currentSelection(); 2835 Incidence *incidence = currentSelection();
2832 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2836 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2833 if ( incidence ) { 2837 if ( incidence ) {
2834 moveIncidence(incidence); 2838 moveIncidence(incidence);
2835 } 2839 }
2836} 2840}
2837void CalendarView::beamIncidence() 2841void CalendarView::beamIncidence()
2838{ 2842{
2839 Incidence *incidence = currentSelection(); 2843 Incidence *incidence = currentSelection();
2840 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2844 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2841 if ( incidence ) { 2845 if ( incidence ) {
2842 beamIncidence(incidence); 2846 beamIncidence(incidence);
2843 } 2847 }
2844} 2848}
2845void CalendarView::toggleCancelIncidence() 2849void CalendarView::toggleCancelIncidence()
2846{ 2850{
2847 Incidence *incidence = currentSelection(); 2851 Incidence *incidence = currentSelection();
2848 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2852 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2849 if ( incidence ) { 2853 if ( incidence ) {
2850 cancelIncidence(incidence); 2854 cancelIncidence(incidence);
2851 } 2855 }
2852} 2856}
2853 2857
2854 2858
2855void CalendarView::cancelIncidence(Incidence * inc ) 2859void CalendarView::cancelIncidence(Incidence * inc )
2856{ 2860{
2857 inc->setCancelled( ! inc->cancelled() ); 2861 inc->setCancelled( ! inc->cancelled() );
2858 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 2862 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
2859 updateView(); 2863 updateView();
2860} 2864}
2861void CalendarView::cloneIncidence(Incidence * orgInc ) 2865void CalendarView::cloneIncidence(Incidence * orgInc )
2862{ 2866{
2863 Incidence * newInc = orgInc->clone(); 2867 Incidence * newInc = orgInc->clone();
2864 newInc->recreate(); 2868 newInc->recreate();
2865 2869
2866 if ( newInc->type() == "Todo" ) { 2870 if ( newInc->type() == "Todo" ) {
2867 Todo* t = (Todo*) newInc; 2871 Todo* t = (Todo*) newInc;
2868 bool cloneSub = false; 2872 bool cloneSub = false;
2869 if ( orgInc->relations().count() ) { 2873 if ( orgInc->relations().count() ) {
2870 int result = KMessageBox::warningYesNoCancel(this, 2874 int result = KMessageBox::warningYesNoCancel(this,
2871 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( newInc->summary().left ( 25 ) ), 2875 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( newInc->summary().left ( 25 ) ),
2872 i18n("Todo has subtodos"), 2876 i18n("Todo has subtodos"),
2873 i18n("Yes"), 2877 i18n("Yes"),
2874 i18n("No")); 2878 i18n("No"));
2875 2879
2876 if ( result == KMessageBox::Cancel ) { 2880 if ( result == KMessageBox::Cancel ) {
2877 delete t; 2881 delete t;
2878 return; 2882 return;
2879 } 2883 }
2880 if (result == KMessageBox::Yes) cloneSub = true; 2884 if (result == KMessageBox::Yes) cloneSub = true;
2881 } 2885 }
2882 showTodoEditor(); 2886 showTodoEditor();
2883 mTodoEditor->editTodo( t ); 2887 mTodoEditor->editTodo( t );
2884 if ( mTodoEditor->exec() ) { 2888 if ( mTodoEditor->exec() ) {
2885 if ( cloneSub ) { 2889 if ( cloneSub ) {
2886 orgInc->cloneRelations( t ); 2890 orgInc->cloneRelations( t );
2887 mCalendar->addIncidenceBranch( t ); 2891 mCalendar->addIncidenceBranch( t );
2888 updateView(); 2892 updateView();
2889 2893
2890 } else { 2894 } else {
2891 mCalendar->addTodo( t ); 2895 mCalendar->addTodo( t );
2892 updateView(); 2896 updateView();
2893 } 2897 }
2894 } else { 2898 } else {
2895 delete t; 2899 delete t;
2896 } 2900 }
2897 } 2901 }
2898 else { 2902 else {
2899 Event* e = (Event*) newInc; 2903 Event* e = (Event*) newInc;
2900 showEventEditor(); 2904 showEventEditor();
2901 mEventEditor->editEvent( e ); 2905 mEventEditor->editEvent( e );
2902 if ( mEventEditor->exec() ) { 2906 if ( mEventEditor->exec() ) {
2903 mCalendar->addEvent( e ); 2907 mCalendar->addEvent( e );
2904 updateView(); 2908 updateView();
2905 } else { 2909 } else {
2906 delete e; 2910 delete e;
2907 } 2911 }
2908 } 2912 }
2909 setActiveWindow(); 2913 setActiveWindow();
2910} 2914}
2911 2915
2912void CalendarView::newEvent() 2916void CalendarView::newEvent()
2913{ 2917{
2914 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 2918 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
2915 KOAgendaView *aView = mViewManager->agendaView(); 2919 KOAgendaView *aView = mViewManager->agendaView();
2916 if (aView) { 2920 if (aView) {
2917 if (aView->selectionStart().isValid()) { 2921 if (aView->selectionStart().isValid()) {
2918 if (aView->selectedIsAllDay()) { 2922 if (aView->selectedIsAllDay()) {
2919 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 2923 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
2920 } else { 2924 } else {
2921 newEvent(aView->selectionStart(),aView->selectionEnd()); 2925 newEvent(aView->selectionStart(),aView->selectionEnd());
2922 } 2926 }
2923 return; 2927 return;
2924 } 2928 }
2925 } 2929 }
2926 2930
2927 QDate date = mNavigator->selectedDates().first(); 2931 QDate date = mNavigator->selectedDates().first();
2928 QDateTime current = QDateTime::currentDateTime(); 2932 QDateTime current = QDateTime::currentDateTime();
2929 if ( date <= current.date() ) { 2933 if ( date <= current.date() ) {
2930 int hour = current.time().hour() +1; 2934 int hour = current.time().hour() +1;
2931 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 2935 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
2932 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2936 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2933 } else 2937 } else
2934 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 2938 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
2935 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 2939 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
2936 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2940 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2937} 2941}
2938 2942
2939void CalendarView::newEvent(QDateTime fh) 2943void CalendarView::newEvent(QDateTime fh)
2940{ 2944{
2941 newEvent(fh, 2945 newEvent(fh,
2942 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 2946 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
2943} 2947}
2944 2948
2945void CalendarView::newEvent(QDate dt) 2949void CalendarView::newEvent(QDate dt)
2946{ 2950{
2947 newEvent(QDateTime(dt, QTime(0,0,0)), 2951 newEvent(QDateTime(dt, QTime(0,0,0)),
2948 QDateTime(dt, QTime(0,0,0)), true); 2952 QDateTime(dt, QTime(0,0,0)), true);
2949} 2953}
2950void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint) 2954void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint)
2951{ 2955{
2952 newEvent(fromHint, toHint, false); 2956 newEvent(fromHint, toHint, false);
2953} 2957}
2954void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 2958void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
2955{ 2959{
2956 2960
2957 showEventEditor(); 2961 showEventEditor();
2958 mEventEditor->newEvent(fromHint,toHint,allDay); 2962 mEventEditor->newEvent(fromHint,toHint,allDay);
2959 if ( mFilterView->filtersEnabled() ) { 2963 if ( mFilterView->filtersEnabled() ) {
2960 CalFilter *filter = mFilterView->selectedFilter(); 2964 CalFilter *filter = mFilterView->selectedFilter();
2961 if (filter && filter->showCategories()) { 2965 if (filter && filter->showCategories()) {
2962 mEventEditor->setCategories(filter->categoryList().join(",") ); 2966 mEventEditor->setCategories(filter->categoryList().join(",") );
2963 } 2967 }
2964 if ( filter ) 2968 if ( filter )
2965 mEventEditor->setSecrecy( filter->getSecrecy() ); 2969 mEventEditor->setSecrecy( filter->getSecrecy() );
2966 } 2970 }
2967 mEventEditor->exec(); 2971 mEventEditor->exec();
2968 setActiveWindow(); 2972 setActiveWindow();
2969} 2973}
2970void CalendarView::todoAdded(Todo * t) 2974void CalendarView::todoAdded(Todo * t)
2971{ 2975{
2972 2976
2973 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 2977 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
2974 updateTodoViews(); 2978 updateTodoViews();
2975} 2979}
2976void CalendarView::todoChanged(Todo * t) 2980void CalendarView::todoChanged(Todo * t)
2977{ 2981{
2978 emit todoModified( t, 4 ); 2982 emit todoModified( t, 4 );
2979 // updateTodoViews(); 2983 // updateTodoViews();
2980} 2984}
2981void CalendarView::todoToBeDeleted(Todo *) 2985void CalendarView::todoToBeDeleted(Todo *)
2982{ 2986{
2983 //qDebug("todoToBeDeleted(Todo *) "); 2987 //qDebug("todoToBeDeleted(Todo *) ");
2984 updateTodoViews(); 2988 updateTodoViews();
2985} 2989}
2986void CalendarView::todoDeleted() 2990void CalendarView::todoDeleted()
2987{ 2991{
2988 //qDebug(" todoDeleted()"); 2992 //qDebug(" todoDeleted()");
2989 updateTodoViews(); 2993 updateTodoViews();
2990} 2994}
2991 2995
2992 2996
2993void CalendarView::newTodoDateTime( QDateTime dt, bool allday ) 2997void CalendarView::newTodoDateTime( QDateTime dt, bool allday )
2994{ 2998{
2995 showTodoEditor(); 2999 showTodoEditor();
2996 mTodoEditor->newTodo(dt,0,allday); 3000 mTodoEditor->newTodo(dt,0,allday);
2997 if ( mFilterView->filtersEnabled() ) { 3001 if ( mFilterView->filtersEnabled() ) {
2998 CalFilter *filter = mFilterView->selectedFilter(); 3002 CalFilter *filter = mFilterView->selectedFilter();
2999 if (filter && filter->showCategories()) { 3003 if (filter && filter->showCategories()) {
3000 mTodoEditor->setCategories(filter->categoryList().join(",") ); 3004 mTodoEditor->setCategories(filter->categoryList().join(",") );
3001 } 3005 }
3002 if ( filter ) 3006 if ( filter )
3003 mTodoEditor->setSecrecy( filter->getSecrecy() ); 3007 mTodoEditor->setSecrecy( filter->getSecrecy() );
3004 } 3008 }
3005 mTodoEditor->exec(); 3009 mTodoEditor->exec();
3006 setActiveWindow(); 3010 setActiveWindow();
3007} 3011}
3008 3012
3009void CalendarView::newTodo() 3013void CalendarView::newTodo()
3010{ 3014{
3011 newTodoDateTime( QDateTime(),true ); 3015 newTodoDateTime( QDateTime(),true );
3012} 3016}
3013 3017
3014void CalendarView::newSubTodo() 3018void CalendarView::newSubTodo()
3015{ 3019{
3016 Todo *todo = selectedTodo(); 3020 Todo *todo = selectedTodo();
3017 if ( todo ) newSubTodo( todo ); 3021 if ( todo ) newSubTodo( todo );
3018} 3022}
3019 3023
3020void CalendarView::newSubTodo(Todo *parentEvent) 3024void CalendarView::newSubTodo(Todo *parentEvent)
3021{ 3025{
3022 3026
3023 showTodoEditor(); 3027 showTodoEditor();
3024 mTodoEditor->newTodo(QDateTime(),parentEvent,true); 3028 mTodoEditor->newTodo(QDateTime(),parentEvent,true);
3025 mTodoEditor->exec(); 3029 mTodoEditor->exec();
3026 setActiveWindow(); 3030 setActiveWindow();
3027} 3031}
3028 3032
3029void CalendarView::newFloatingEvent() 3033void CalendarView::newFloatingEvent()
3030{ 3034{
3031 DateList tmpList = mNavigator->selectedDates(); 3035 DateList tmpList = mNavigator->selectedDates();
3032 QDate date = tmpList.first(); 3036 QDate date = tmpList.first();
3033 3037
3034 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 3038 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
3035 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 3039 QDateTime( date, QTime( 12, 0, 0 ) ), true );
3036} 3040}
3037 3041
3038 3042
3039void CalendarView::editEvent( Event *event ) 3043void CalendarView::editEvent( Event *event )
3040{ 3044{
3041 3045
3042 if ( !event ) return; 3046 if ( !event ) return;
3043 if ( event->isReadOnly() ) { 3047 if ( event->isReadOnly() ) {
3044 showEvent( event ); 3048 showEvent( event );
3045 return; 3049 return;
3046 } 3050 }
3047 showEventEditor(); 3051 showEventEditor();
3048 mEventEditor->editEvent( event , mFlagEditDescription); 3052 mEventEditor->editEvent( event , mFlagEditDescription);
3049 mEventEditor->exec(); 3053 mEventEditor->exec();
3050 setActiveWindow(); 3054 setActiveWindow();
3051 3055
3052} 3056}
3053void CalendarView::editJournal( Journal *jour ) 3057void CalendarView::editJournal( Journal *jour )
3054{ 3058{
3055 if ( !jour ) return; 3059 if ( !jour ) return;
3056 mDialogManager->hideSearchDialog(); 3060 mDialogManager->hideSearchDialog();
3057 mViewManager->showJournalView(); 3061 mViewManager->showJournalView();
3058 mNavigator->slotDaySelect( jour->dtStart().date() ); 3062 mNavigator->slotDaySelect( jour->dtStart().date() );
3059} 3063}
3060void CalendarView::editTodo( Todo *todo ) 3064void CalendarView::editTodo( Todo *todo )
3061{ 3065{
3062 if ( !todo ) return; 3066 if ( !todo ) return;
3063 3067
3064 if ( todo->isReadOnly() ) { 3068 if ( todo->isReadOnly() ) {
3065 showTodo( todo ); 3069 showTodo( todo );
3066 return; 3070 return;
3067 } 3071 }
3068 showTodoEditor(); 3072 showTodoEditor();
3069 mTodoEditor->editTodo( todo ,mFlagEditDescription); 3073 mTodoEditor->editTodo( todo ,mFlagEditDescription);
3070 mTodoEditor->exec(); 3074 mTodoEditor->exec();
3071 setActiveWindow(); 3075 setActiveWindow();
3072 3076
3073} 3077}
3074 3078
3075KOEventViewerDialog* CalendarView::getEventViewerDialog() 3079KOEventViewerDialog* CalendarView::getEventViewerDialog()
3076{ 3080{
3077 if ( !mEventViewerDialog ) { 3081 if ( !mEventViewerDialog ) {
3078 mEventViewerDialog = new KOEventViewerDialog(0); 3082 mEventViewerDialog = new KOEventViewerDialog(0);
3079 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 3083 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
3080 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 3084 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
3081 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 3085 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
3082 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 3086 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
3083 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 3087 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
3084 viewManager(), SLOT( showAgendaView( bool ) ) ); 3088 viewManager(), SLOT( showAgendaView( bool ) ) );
3085 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()), 3089 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()),
3086 this, SLOT( slotViewerClosed() ) ); 3090 this, SLOT( slotViewerClosed() ) );
3087 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ), 3091 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ),
3088 this, SLOT( todoChanged(Todo *) ) ); 3092 this, SLOT( todoChanged(Todo *) ) );
3089 mEventViewerDialog->resize( 640, 480 ); 3093 mEventViewerDialog->resize( 640, 480 );
3090 3094
3091 } 3095 }
3092 return mEventViewerDialog; 3096 return mEventViewerDialog;
3093} 3097}
3094void CalendarView::showEvent(Event *event) 3098void CalendarView::showEvent(Event *event)
3095{ 3099{
3096 getEventViewerDialog()->setEvent(event); 3100 getEventViewerDialog()->setEvent(event);
3097 getEventViewerDialog()->showMe(); 3101 getEventViewerDialog()->showMe();
3098} 3102}
3099 3103
3100void CalendarView::showTodo(Todo *event) 3104void CalendarView::showTodo(Todo *event)
3101{ 3105{
3102 getEventViewerDialog()->setTodo(event); 3106 getEventViewerDialog()->setTodo(event);
3103 getEventViewerDialog()->showMe(); 3107 getEventViewerDialog()->showMe();
3104} 3108}
3105void CalendarView::showJournal( Journal *jour ) 3109void CalendarView::showJournal( Journal *jour )
3106{ 3110{
3107 getEventViewerDialog()->setJournal(jour); 3111 getEventViewerDialog()->setJournal(jour);
3108 getEventViewerDialog()->showMe(); 3112 getEventViewerDialog()->showMe();
3109 3113
3110} 3114}
3111// void CalendarView::todoModified (Todo *event, int changed) 3115// void CalendarView::todoModified (Todo *event, int changed)
3112// { 3116// {
3113// // if (mDialogList.find (event) != mDialogList.end ()) { 3117// // if (mDialogList.find (event) != mDialogList.end ()) {
3114// // kdDebug() << "Todo modified and open" << endl; 3118// // kdDebug() << "Todo modified and open" << endl;
3115// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 3119// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
3116// // temp->modified (changed); 3120// // temp->modified (changed);
3117 3121
3118// // } 3122// // }
3119 3123
3120// mViewManager->updateView(); 3124// mViewManager->updateView();
3121// } 3125// }
3122 3126
3123void CalendarView::appointment_show() 3127void CalendarView::appointment_show()
3124{ 3128{
3125 Event *anEvent = 0; 3129 Event *anEvent = 0;
3126 3130
3127 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3131 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3128 3132
3129 if (mViewManager->currentView()->isEventView()) { 3133 if (mViewManager->currentView()->isEventView()) {
3130 if ( incidence && incidence->type() == "Event" ) { 3134 if ( incidence && incidence->type() == "Event" ) {
3131 anEvent = static_cast<Event *>(incidence); 3135 anEvent = static_cast<Event *>(incidence);
3132 } 3136 }
3133 } 3137 }
3134 3138
3135 if (!anEvent) { 3139 if (!anEvent) {
3136 KNotifyClient::beep(); 3140 KNotifyClient::beep();
3137 return; 3141 return;
3138 } 3142 }
3139 3143
3140 showEvent(anEvent); 3144 showEvent(anEvent);
3141} 3145}
3142 3146
3143void CalendarView::appointment_edit() 3147void CalendarView::appointment_edit()
3144{ 3148{
3145 Event *anEvent = 0; 3149 Event *anEvent = 0;
3146 3150
3147 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3151 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3148 3152
3149 if (mViewManager->currentView()->isEventView()) { 3153 if (mViewManager->currentView()->isEventView()) {
3150 if ( incidence && incidence->type() == "Event" ) { 3154 if ( incidence && incidence->type() == "Event" ) {
3151 anEvent = static_cast<Event *>(incidence); 3155 anEvent = static_cast<Event *>(incidence);
3152 } 3156 }
3153 } 3157 }
3154 3158
3155 if (!anEvent) { 3159 if (!anEvent) {
3156 KNotifyClient::beep(); 3160 KNotifyClient::beep();
3157 return; 3161 return;
3158 } 3162 }
3159 3163
3160 editEvent(anEvent); 3164 editEvent(anEvent);
3161} 3165}
3162 3166
3163void CalendarView::appointment_delete() 3167void CalendarView::appointment_delete()
3164{ 3168{
3165 Event *anEvent = 0; 3169 Event *anEvent = 0;
3166 3170
3167 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3171 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3168 3172
3169 if (mViewManager->currentView()->isEventView()) { 3173 if (mViewManager->currentView()->isEventView()) {
3170 if ( incidence && incidence->type() == "Event" ) { 3174 if ( incidence && incidence->type() == "Event" ) {
3171 anEvent = static_cast<Event *>(incidence); 3175 anEvent = static_cast<Event *>(incidence);
3172 } 3176 }
3173 } 3177 }
3174 3178
3175 if (!anEvent) { 3179 if (!anEvent) {
3176 KNotifyClient::beep(); 3180 KNotifyClient::beep();
3177 return; 3181 return;
3178 } 3182 }
3179 3183
3180 deleteEvent(anEvent); 3184 deleteEvent(anEvent);
3181} 3185}
3182 3186
3183void CalendarView::todo_resub( Todo * parent, Todo * sub ) 3187void CalendarView::todo_resub( Todo * parent, Todo * sub )
3184{ 3188{
3185 if (!sub) return; 3189 if (!sub) return;
3186 if ( sub->relatedTo() == parent ) 3190 if ( sub->relatedTo() == parent )
3187 return; 3191 return;
3188 sub->setRelatedTo(parent); 3192 sub->setRelatedTo(parent);
3189 sub->updated(); 3193 sub->updated();
3190 setModified(true); 3194 setModified(true);
3191 updateView(); 3195 updateView();
3192} 3196}
3193void CalendarView::todo_unsub(Todo *anTodo ) 3197void CalendarView::todo_unsub(Todo *anTodo )
3194{ 3198{
3195 todo_resub( 0, anTodo ); 3199 todo_resub( 0, anTodo );
3196} 3200}
3197 3201
3198void CalendarView::deleteTodo(Todo *todo) 3202void CalendarView::deleteTodo(Todo *todo)
3199{ 3203{
3200 if (!todo) { 3204 if (!todo) {
3201 KNotifyClient::beep(); 3205 KNotifyClient::beep();
3202 return; 3206 return;
3203 } 3207 }
3204 if (KOPrefs::instance()->mConfirm) { 3208 if (KOPrefs::instance()->mConfirm) {
3205 QString text = todo->summary().left(20); 3209 QString text = todo->summary().left(20);
3206 if (!todo->relations().isEmpty()) { 3210 if (!todo->relations().isEmpty()) {
3207 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!"); 3211 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!");
3208 3212
3209 } 3213 }
3210 switch (msgItemDelete(text)) { 3214 switch (msgItemDelete(text)) {
3211 case KMessageBox::Continue: // OK 3215 case KMessageBox::Continue: // OK
3212 bool deleteT = false; 3216 bool deleteT = false;
3213 if (!todo->relations().isEmpty()) { 3217 if (!todo->relations().isEmpty()) {
3214 deleteT = removeCompletedSubTodos( todo ); 3218 deleteT = removeCompletedSubTodos( todo );
3215 } 3219 }
3216 // deleteT == true: todo already deleted in removeCompletedSubTodos 3220 // deleteT == true: todo already deleted in removeCompletedSubTodos
3217 if ( !deleteT ) { 3221 if ( !deleteT ) {
3218 checkExternalId( todo ); 3222 checkExternalId( todo );
3219 calendar()->deleteTodo(todo); 3223 calendar()->deleteTodo(todo);
3220 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3224 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3221 updateView(); 3225 updateView();
3222 } 3226 }
3223 break; 3227 break;
3224 } // switch 3228 } // switch
3225 } else { 3229 } else {
3226 checkExternalId( todo ); 3230 checkExternalId( todo );
3227 mCalendar->deleteTodo(todo); 3231 mCalendar->deleteTodo(todo);
3228 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3232 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3229 updateView(); 3233 updateView();
3230 } 3234 }
3231 3235
3232 emit updateSearchDialog(); 3236 emit updateSearchDialog();
3233} 3237}
3234void CalendarView::deleteJournal(Journal *jour) 3238void CalendarView::deleteJournal(Journal *jour)
3235{ 3239{
3236 if (!jour) { 3240 if (!jour) {
3237 KNotifyClient::beep(); 3241 KNotifyClient::beep();
3238 return; 3242 return;
3239 } 3243 }
3240 if (KOPrefs::instance()->mConfirm) { 3244 if (KOPrefs::instance()->mConfirm) {
3241 switch (msgItemDelete( jour->description().left(20))) { 3245 switch (msgItemDelete( jour->description().left(20))) {
3242 case KMessageBox::Continue: // OK 3246 case KMessageBox::Continue: // OK
3243 calendar()->deleteJournal(jour); 3247 calendar()->deleteJournal(jour);
3244 updateView(); 3248 updateView();
3245 break; 3249 break;
3246 } // switch 3250 } // switch
3247 } else { 3251 } else {
3248 calendar()->deleteJournal(jour);; 3252 calendar()->deleteJournal(jour);;
3249 updateView(); 3253 updateView();
3250 } 3254 }
3251 emit updateSearchDialog(); 3255 emit updateSearchDialog();
3252} 3256}
3253 3257
3254void CalendarView::deleteEvent(Event *anEvent) 3258void CalendarView::deleteEvent(Event *anEvent)
3255{ 3259{
3256 if (!anEvent) { 3260 if (!anEvent) {
3257 KNotifyClient::beep(); 3261 KNotifyClient::beep();
3258 return; 3262 return;
3259 } 3263 }
3260 3264
3261 if (anEvent->recurrence()->doesRecur()) { 3265 if (anEvent->recurrence()->doesRecur()) {
3262 QDate itemDate = mViewManager->currentSelectionDate(); 3266 QDate itemDate = mViewManager->currentSelectionDate();
3263 int km; 3267 int km;
3264 if (!itemDate.isValid()) { 3268 if (!itemDate.isValid()) {
3265 //kdDebug() << "Date Not Valid" << endl; 3269 //kdDebug() << "Date Not Valid" << endl;
3266 if (KOPrefs::instance()->mConfirm) { 3270 if (KOPrefs::instance()->mConfirm) {
3267 km = KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) + 3271 km = KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) +
3268 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 3272 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
3269 i18n("KO/Pi Confirmation"),i18n("Delete All")); 3273 i18n("KO/Pi Confirmation"),i18n("Delete All"));
3270 if ( km == KMessageBox::Continue ) 3274 if ( km == KMessageBox::Continue )
3271 km = KMessageBox::No; // No = all below 3275 km = KMessageBox::No; // No = all below
3272 } else 3276 } else
3273 km = KMessageBox::No; 3277 km = KMessageBox::No;
3274 } else { 3278 } else {
3275 km = KMessageBox::warningYesNoCancel(this,anEvent->summary().left(25) + 3279 km = KMessageBox::warningYesNoCancel(this,anEvent->summary().left(25) +
3276 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 3280 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
3277 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 3281 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
3278 i18n("KO/Pi Confirmation"),i18n("Current"), 3282 i18n("KO/Pi Confirmation"),i18n("Current"),
3279 i18n("All")); 3283 i18n("All"));
3280 } 3284 }
3281 switch(km) { 3285 switch(km) {
3282 3286
3283 case KMessageBox::No: // Continue // all 3287 case KMessageBox::No: // Continue // all
3284 //qDebug("KMessageBox::No "); 3288 //qDebug("KMessageBox::No ");
3285 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3289 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3286 schedule(Scheduler::Cancel,anEvent); 3290 schedule(Scheduler::Cancel,anEvent);
3287 3291
3288 checkExternalId( anEvent); 3292 checkExternalId( anEvent);
3289 mCalendar->deleteEvent(anEvent); 3293 mCalendar->deleteEvent(anEvent);
3290 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 3294 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
3291 break; 3295 break;
3292 3296
3293 // Disabled because it does not work 3297 // Disabled because it does not work
3294 //#if 0 3298 //#if 0
3295 case KMessageBox::Yes: // just this one 3299 case KMessageBox::Yes: // just this one
3296 //QDate qd = mNavigator->selectedDates().first(); 3300 //QDate qd = mNavigator->selectedDates().first();
3297 //if (!qd.isValid()) { 3301 //if (!qd.isValid()) {
3298 // kdDebug() << "no date selected, or invalid date" << endl; 3302 // kdDebug() << "no date selected, or invalid date" << endl;
3299 // KNotifyClient::beep(); 3303 // KNotifyClient::beep();
3300 // return; 3304 // return;
3301 //} 3305 //}
3302 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 3306 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
3303 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 3307 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
3304 anEvent->addExDate(itemDate); 3308 anEvent->addExDate(itemDate);
3305 int duration = anEvent->recurrence()->duration(); 3309 int duration = anEvent->recurrence()->duration();
3306 if ( duration > 0 ) { 3310 if ( duration > 0 ) {
3307 anEvent->recurrence()->setDuration( duration - 1 ); 3311 anEvent->recurrence()->setDuration( duration - 1 );
3308 } 3312 }
3309 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 3313 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
3310 } 3314 }
3311 break; 3315 break;
3312 //#endif 3316 //#endif
3313 } // switch 3317 } // switch
3314 } else { 3318 } else {
3315 if (KOPrefs::instance()->mConfirm) { 3319 if (KOPrefs::instance()->mConfirm) {
3316 switch (KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) + 3320 switch (KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) +
3317 i18n("\nAre you sure you want\nto delete this event?"), 3321 i18n("\nAre you sure you want\nto delete this event?"),
3318 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 3322 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
3319 case KMessageBox::Continue: // OK 3323 case KMessageBox::Continue: // OK
3320 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3324 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3321 schedule(Scheduler::Cancel,anEvent); 3325 schedule(Scheduler::Cancel,anEvent);
3322 checkExternalId( anEvent); 3326 checkExternalId( anEvent);
3323 mCalendar->deleteEvent(anEvent); 3327 mCalendar->deleteEvent(anEvent);
3324 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3328 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3325 break; 3329 break;
3326 } // switch 3330 } // switch
3327 } else { 3331 } else {
3328 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3332 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3329 schedule(Scheduler::Cancel,anEvent); 3333 schedule(Scheduler::Cancel,anEvent);
3330 checkExternalId( anEvent); 3334 checkExternalId( anEvent);
3331 mCalendar->deleteEvent(anEvent); 3335 mCalendar->deleteEvent(anEvent);
3332 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3336 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3333 } 3337 }
3334 } // if-else 3338 } // if-else
3335 emit updateSearchDialog(); 3339 emit updateSearchDialog();
3336} 3340}
3337 3341
3338bool CalendarView::deleteEvent(const QString &uid) 3342bool CalendarView::deleteEvent(const QString &uid)
3339{ 3343{
3340 Event *ev = mCalendar->event(uid); 3344 Event *ev = mCalendar->event(uid);
3341 if (ev) { 3345 if (ev) {
3342 deleteEvent(ev); 3346 deleteEvent(ev);
3343 return true; 3347 return true;
3344 } else { 3348 } else {
3345 return false; 3349 return false;
3346 } 3350 }
3347} 3351}
3348 3352
3349/*****************************************************************************/ 3353/*****************************************************************************/
3350 3354
3351void CalendarView::action_mail() 3355void CalendarView::action_mail()
3352{ 3356{
3353#ifndef KORG_NOMAIL 3357#ifndef KORG_NOMAIL
3354 KOMailClient mailClient; 3358 KOMailClient mailClient;
3355 3359
3356 Incidence *incidence = currentSelection(); 3360 Incidence *incidence = currentSelection();
3357 3361
3358 if (!incidence) { 3362 if (!incidence) {
3359 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3363 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3360 return; 3364 return;
3361 } 3365 }
3362 if(incidence->attendeeCount() == 0 ) { 3366 if(incidence->attendeeCount() == 0 ) {
3363 KMessageBox::sorry(this, 3367 KMessageBox::sorry(this,
3364 i18n("Can't generate mail:\nNo attendees defined.\n")); 3368 i18n("Can't generate mail:\nNo attendees defined.\n"));
3365 return; 3369 return;
3366 } 3370 }
3367 3371
3368 CalendarLocal cal_tmp; 3372 CalendarLocal cal_tmp;
3369 Event *event = 0; 3373 Event *event = 0;
3370 Event *ev = 0; 3374 Event *ev = 0;
3371 if ( incidence && incidence->type() == "Event" ) { 3375 if ( incidence && incidence->type() == "Event" ) {
3372 event = static_cast<Event *>(incidence); 3376 event = static_cast<Event *>(incidence);
3373 ev = new Event(*event); 3377 ev = new Event(*event);
3374 cal_tmp.addEvent(ev); 3378 cal_tmp.addEvent(ev);
3375 } 3379 }
3376 ICalFormat mForm(); 3380 ICalFormat mForm();
3377 QString attachment = mForm.toString( &cal_tmp ); 3381 QString attachment = mForm.toString( &cal_tmp );
3378 if (ev) delete(ev); 3382 if (ev) delete(ev);
3379 3383
3380 mailClient.mailAttendees(currentSelection(), attachment); 3384 mailClient.mailAttendees(currentSelection(), attachment);
3381 3385
3382#endif 3386#endif
3383 3387
3384#if 0 3388#if 0
3385 Event *anEvent = 0; 3389 Event *anEvent = 0;
3386 if (mViewManager->currentView()->isEventView()) { 3390 if (mViewManager->currentView()->isEventView()) {
3387 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); 3391 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
3388 } 3392 }
3389 3393
3390 if (!anEvent) { 3394 if (!anEvent) {
3391 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3395 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3392 return; 3396 return;
3393 } 3397 }
3394 if(anEvent->attendeeCount() == 0 ) { 3398 if(anEvent->attendeeCount() == 0 ) {
3395 KMessageBox::sorry(this, 3399 KMessageBox::sorry(this,
3396 i18n("Can't generate mail:\nNo attendees defined.\n")); 3400 i18n("Can't generate mail:\nNo attendees defined.\n"));
3397 return; 3401 return;
3398 } 3402 }
3399 3403
3400 mailobject.emailEvent(anEvent); 3404 mailobject.emailEvent(anEvent);
3401#endif 3405#endif
3402} 3406}
3403 3407
3404 3408
3405void CalendarView::schedule_publish(Incidence *incidence) 3409void CalendarView::schedule_publish(Incidence *incidence)
3406{ 3410{
3407 Event *event = 0; 3411 Event *event = 0;
3408 Todo *todo = 0; 3412 Todo *todo = 0;
3409 3413
3410 if (incidence == 0) { 3414 if (incidence == 0) {
3411 incidence = mViewManager->currentView()->selectedIncidences().first(); 3415 incidence = mViewManager->currentView()->selectedIncidences().first();
3412 if (incidence == 0) { 3416 if (incidence == 0) {
3413 incidence = mTodoList->selectedIncidences().first(); 3417 incidence = mTodoList->selectedIncidences().first();
3414 } 3418 }
3415 } 3419 }
3416 if ( incidence && incidence->type() == "Event" ) { 3420 if ( incidence && incidence->type() == "Event" ) {
3417 event = static_cast<Event *>(incidence); 3421 event = static_cast<Event *>(incidence);
3418 } else { 3422 } else {
3419 if ( incidence && incidence->type() == "Todo" ) { 3423 if ( incidence && incidence->type() == "Todo" ) {
3420 todo = static_cast<Todo *>(incidence); 3424 todo = static_cast<Todo *>(incidence);
3421 } 3425 }
3422 } 3426 }
3423 3427
3424 if (!event && !todo) { 3428 if (!event && !todo) {
3425 KMessageBox::sorry(this,i18n("No event selected.")); 3429 KMessageBox::sorry(this,i18n("No event selected."));
3426 return; 3430 return;
3427 } 3431 }
3428 3432
3429 PublishDialog *publishdlg = new PublishDialog(); 3433 PublishDialog *publishdlg = new PublishDialog();
3430 if (incidence->attendeeCount()>0) { 3434 if (incidence->attendeeCount()>0) {
3431 QPtrList<Attendee> attendees = incidence->attendees(); 3435 QPtrList<Attendee> attendees = incidence->attendees();
3432 attendees.first(); 3436 attendees.first();
3433 while ( attendees.current()!=0 ) { 3437 while ( attendees.current()!=0 ) {
3434 publishdlg->addAttendee(attendees.current()); 3438 publishdlg->addAttendee(attendees.current());
3435 attendees.next(); 3439 attendees.next();
3436 } 3440 }
3437 } 3441 }
3438 bool send = true; 3442 bool send = true;
3439 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 3443 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
3440 if ( publishdlg->exec() != QDialog::Accepted ) 3444 if ( publishdlg->exec() != QDialog::Accepted )
3441 send = false; 3445 send = false;
3442 } 3446 }
3443 if ( send ) { 3447 if ( send ) {
3444 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3448 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3445 if ( event ) { 3449 if ( event ) {
3446 Event *ev = new Event(*event); 3450 Event *ev = new Event(*event);
3447 ev->registerObserver(0); 3451 ev->registerObserver(0);
3448 ev->clearAttendees(); 3452 ev->clearAttendees();
3449 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3453 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3450 delete(ev); 3454 delete(ev);
3451 } 3455 }
3452 } else { 3456 } else {
3453 if ( todo ) { 3457 if ( todo ) {
3454 Todo *ev = new Todo(*todo); 3458 Todo *ev = new Todo(*todo);
3455 ev->registerObserver(0); 3459 ev->registerObserver(0);
3456 ev->clearAttendees(); 3460 ev->clearAttendees();
3457 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3461 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3458 delete(ev); 3462 delete(ev);
3459 } 3463 }
3460 } 3464 }
3461 } 3465 }
3462 } 3466 }
3463 delete publishdlg; 3467 delete publishdlg;
3464} 3468}
3465 3469
3466void CalendarView::schedule_request(Incidence *incidence) 3470void CalendarView::schedule_request(Incidence *incidence)
3467{ 3471{
3468 schedule(Scheduler::Request,incidence); 3472 schedule(Scheduler::Request,incidence);
3469} 3473}
3470 3474
3471void CalendarView::schedule_refresh(Incidence *incidence) 3475void CalendarView::schedule_refresh(Incidence *incidence)
3472{ 3476{
3473 schedule(Scheduler::Refresh,incidence); 3477 schedule(Scheduler::Refresh,incidence);
3474} 3478}
3475 3479
3476void CalendarView::schedule_cancel(Incidence *incidence) 3480void CalendarView::schedule_cancel(Incidence *incidence)
3477{ 3481{
3478 schedule(Scheduler::Cancel,incidence); 3482 schedule(Scheduler::Cancel,incidence);
3479} 3483}
3480 3484
3481void CalendarView::schedule_add(Incidence *incidence) 3485void CalendarView::schedule_add(Incidence *incidence)
3482{ 3486{
3483 schedule(Scheduler::Add,incidence); 3487 schedule(Scheduler::Add,incidence);
3484} 3488}
3485 3489
3486void CalendarView::schedule_reply(Incidence *incidence) 3490void CalendarView::schedule_reply(Incidence *incidence)
3487{ 3491{
3488 schedule(Scheduler::Reply,incidence); 3492 schedule(Scheduler::Reply,incidence);
3489} 3493}
3490 3494
3491void CalendarView::schedule_counter(Incidence *incidence) 3495void CalendarView::schedule_counter(Incidence *incidence)
3492{ 3496{
3493 schedule(Scheduler::Counter,incidence); 3497 schedule(Scheduler::Counter,incidence);
3494} 3498}
3495 3499
3496void CalendarView::schedule_declinecounter(Incidence *incidence) 3500void CalendarView::schedule_declinecounter(Incidence *incidence)
3497{ 3501{
3498 schedule(Scheduler::Declinecounter,incidence); 3502 schedule(Scheduler::Declinecounter,incidence);
3499} 3503}
3500 3504
3501void CalendarView::schedule_publish_freebusy(int daysToPublish) 3505void CalendarView::schedule_publish_freebusy(int daysToPublish)
3502{ 3506{
3503 QDateTime start = QDateTime::currentDateTime(); 3507 QDateTime start = QDateTime::currentDateTime();
3504 QDateTime end = start.addDays(daysToPublish); 3508 QDateTime end = start.addDays(daysToPublish);
3505 3509
3506 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); 3510 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
3507 freebusy->setOrganizer(KOPrefs::instance()->email()); 3511 freebusy->setOrganizer(KOPrefs::instance()->email());
3508 3512
3509 3513
3510 PublishDialog *publishdlg = new PublishDialog(); 3514 PublishDialog *publishdlg = new PublishDialog();
3511 if ( publishdlg->exec() == QDialog::Accepted ) { 3515 if ( publishdlg->exec() == QDialog::Accepted ) {
3512 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3516 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3513 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { 3517 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
3514 delete(freebusy); 3518 delete(freebusy);
3515 } 3519 }
3516 } 3520 }
3517 delete publishdlg; 3521 delete publishdlg;
3518} 3522}
3519 3523
3520void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) 3524void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
3521{ 3525{
3522 Event *event = 0; 3526 Event *event = 0;
3523 Todo *todo = 0; 3527 Todo *todo = 0;
3524 3528
3525 if (incidence == 0) { 3529 if (incidence == 0) {
3526 incidence = mViewManager->currentView()->selectedIncidences().first(); 3530 incidence = mViewManager->currentView()->selectedIncidences().first();
3527 if (incidence == 0) { 3531 if (incidence == 0) {
3528 incidence = mTodoList->selectedIncidences().first(); 3532 incidence = mTodoList->selectedIncidences().first();
3529 } 3533 }
3530 } 3534 }
3531 if ( incidence && incidence->type() == "Event" ) { 3535 if ( incidence && incidence->type() == "Event" ) {
3532 event = static_cast<Event *>(incidence); 3536 event = static_cast<Event *>(incidence);
3533 } 3537 }
3534 if ( incidence && incidence->type() == "Todo" ) { 3538 if ( incidence && incidence->type() == "Todo" ) {
3535 todo = static_cast<Todo *>(incidence); 3539 todo = static_cast<Todo *>(incidence);
3536 } 3540 }
3537 3541
3538 if (!event && !todo) { 3542 if (!event && !todo) {
3539 KMessageBox::sorry(this,i18n("No event selected.")); 3543 KMessageBox::sorry(this,i18n("No event selected."));
3540 return; 3544 return;
3541 } 3545 }
3542 3546
3543 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { 3547 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
3544 KMessageBox::sorry(this,i18n("The event has no attendees.")); 3548 KMessageBox::sorry(this,i18n("The event has no attendees."));
3545 return; 3549 return;
3546 } 3550 }
3547 3551
3548 Event *ev = 0; 3552 Event *ev = 0;
3549 if (event) ev = new Event(*event); 3553 if (event) ev = new Event(*event);
3550 Todo *to = 0; 3554 Todo *to = 0;
3551 if (todo) to = new Todo(*todo); 3555 if (todo) to = new Todo(*todo);
3552 3556
3553 if (method == Scheduler::Reply || method == Scheduler::Refresh) { 3557 if (method == Scheduler::Reply || method == Scheduler::Refresh) {
3554 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 3558 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
3555 if (!me) { 3559 if (!me) {
3556 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); 3560 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails."));
3557 return; 3561 return;
3558 } 3562 }
3559 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { 3563 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
3560 StatusDialog *statdlg = new StatusDialog(this); 3564 StatusDialog *statdlg = new StatusDialog(this);
3561 if (!statdlg->exec()==QDialog::Accepted) return; 3565 if (!statdlg->exec()==QDialog::Accepted) return;
3562 me->setStatus( statdlg->status() ); 3566 me->setStatus( statdlg->status() );
3563 delete(statdlg); 3567 delete(statdlg);
3564 } 3568 }
3565 Attendee *menew = new Attendee(*me); 3569 Attendee *menew = new Attendee(*me);
3566 if (ev) { 3570 if (ev) {
3567 ev->clearAttendees(); 3571 ev->clearAttendees();
3568 ev->addAttendee(menew,false); 3572 ev->addAttendee(menew,false);
3569 } else { 3573 } else {
3570 if (to) { 3574 if (to) {
3571 todo->clearAttendees(); 3575 todo->clearAttendees();
3572 todo->addAttendee(menew,false); 3576 todo->addAttendee(menew,false);
3573 } 3577 }
3574 } 3578 }
3575 } 3579 }
3576 3580
3577 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3581 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3578 if (ev) { 3582 if (ev) {
3579 if ( !dlg->addMessage(ev,method) ) delete(ev); 3583 if ( !dlg->addMessage(ev,method) ) delete(ev);
3580 } else { 3584 } else {
3581 if (to) { 3585 if (to) {
3582 if ( !dlg->addMessage(to,method) ) delete(to); 3586 if ( !dlg->addMessage(to,method) ) delete(to);
3583 } 3587 }
3584 } 3588 }
3585} 3589}
3586 3590
3587void CalendarView::openAddressbook() 3591void CalendarView::openAddressbook()
3588{ 3592{
3589 KRun::runCommand("kaddressbook"); 3593 KRun::runCommand("kaddressbook");
3590} 3594}
3591 3595
3592void CalendarView::setModified(bool modified) 3596void CalendarView::setModified(bool modified)
3593{ 3597{
3594 if ( modified ) 3598 if ( modified )
3595 emit signalmodified(); 3599 emit signalmodified();
3596 if (mModified != modified) { 3600 if (mModified != modified) {
3597 mModified = modified; 3601 mModified = modified;
3598 emit modifiedChanged(mModified); 3602 emit modifiedChanged(mModified);
3599 } 3603 }
3600} 3604}
3601 3605
3602bool CalendarView::isReadOnly() 3606bool CalendarView::isReadOnly()
3603{ 3607{
3604 return mReadOnly; 3608 return mReadOnly;
3605} 3609}
3606 3610
3607void CalendarView::setReadOnly(bool readOnly) 3611void CalendarView::setReadOnly(bool readOnly)
3608{ 3612{
3609 if (mReadOnly != readOnly) { 3613 if (mReadOnly != readOnly) {
3610 mReadOnly = readOnly; 3614 mReadOnly = readOnly;
3611 emit readOnlyChanged(mReadOnly); 3615 emit readOnlyChanged(mReadOnly);
3612 } 3616 }
3613} 3617}
3614 3618
3615bool CalendarView::isModified() 3619bool CalendarView::isModified()
3616{ 3620{
3617 return mModified; 3621 return mModified;
3618} 3622}
3619void CalendarView::slotprintSelInc() 3623void CalendarView::slotprintSelInc()
3620{ 3624{
3621 if ( currentSelection() == 0 ) { 3625 if ( currentSelection() == 0 ) {
3622 KMessageBox::sorry(this,i18n("There is nothing selected!")); 3626 KMessageBox::sorry(this,i18n("There is nothing selected!"));
3623 return; 3627 return;
3624 } 3628 }
3625 showIncidence(); 3629 showIncidence();
3626 getEventViewerDialog()->print(); 3630 getEventViewerDialog()->print();
3627 3631
3628} 3632}
3629void CalendarView::printSetup() 3633void CalendarView::printSetup()
3630{ 3634{
3631#ifndef KORG_NOPRINTER 3635#ifndef KORG_NOPRINTER
3632 createPrinter(); 3636 createPrinter();
3633 3637
3634 mCalPrinter->setupPrinter(); 3638 mCalPrinter->setupPrinter();
3635#endif 3639#endif
3636} 3640}
3637 3641
3638void CalendarView::print() 3642void CalendarView::print()
3639{ 3643{
3640#ifndef KORG_NOPRINTER 3644#ifndef KORG_NOPRINTER
3641 createPrinter(); 3645 createPrinter();
3642 3646
3643 DateList tmpDateList = mNavigator->selectedDates(); 3647 DateList tmpDateList = mNavigator->selectedDates();
3644 mCalPrinter->print(CalPrinter::Month, 3648 mCalPrinter->print(CalPrinter::Month,
3645 tmpDateList.first(), tmpDateList.last()); 3649 tmpDateList.first(), tmpDateList.last());
3646#endif 3650#endif
3647} 3651}
3648 3652
3649void CalendarView::printPreview() 3653void CalendarView::printPreview()
3650{ 3654{
3651#ifndef KORG_NOPRINTER 3655#ifndef KORG_NOPRINTER
3652 kdDebug() << "CalendarView::printPreview()" << endl; 3656 kdDebug() << "CalendarView::printPreview()" << endl;
3653 3657
3654 createPrinter(); 3658 createPrinter();
3655 3659
3656 DateList tmpDateList = mNavigator->selectedDates(); 3660 DateList tmpDateList = mNavigator->selectedDates();
3657 3661
3658 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), 3662 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(),
3659 tmpDateList.last()); 3663 tmpDateList.last());
3660#endif 3664#endif
3661} 3665}
3662 3666
3663void CalendarView::exportICalendar() 3667void CalendarView::exportICalendar()
3664{ 3668{
3665 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); 3669 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this);
3666 3670
3667 // Force correct extension 3671 // Force correct extension
3668 if (filename.right(4) != ".ics") filename += ".ics"; 3672 if (filename.right(4) != ".ics") filename += ".ics";
3669 3673
3670 FileStorage storage( mCalendar, filename, new ICalFormat() ); 3674 FileStorage storage( mCalendar, filename, new ICalFormat() );
3671 storage.save(); 3675 storage.save();
3672} 3676}
3673 3677
3674bool CalendarView::exportVCalendar( QString filename ) 3678bool CalendarView::exportVCalendar( QString filename )
3675{ 3679{
3676 if (mCalendar->journals().count() > 0) { 3680 if (mCalendar->journals().count() > 0) {
3677 int result = KMessageBox::warningContinueCancel(this, 3681 int result = KMessageBox::warningContinueCancel(this,
3678 i18n("The journal entries can not be\nexported to a vCalendar file."), 3682 i18n("The journal entries can not be\nexported to a vCalendar file."),
3679 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 3683 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
3680 true); 3684 true);
3681 if (result != KMessageBox::Continue) return false; 3685 if (result != KMessageBox::Continue) return false;
3682 } 3686 }
3683 3687
3684 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); 3688 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this);
3685 3689
3686 // Force correct extension 3690 // Force correct extension
3687 if (filename.right(4) != ".vcs") filename += ".vcs"; 3691 if (filename.right(4) != ".vcs") filename += ".vcs";
3688 3692
3689 FileStorage storage( mCalendar, filename, new VCalFormat ); 3693 FileStorage storage( mCalendar, filename, new VCalFormat );
3690 return storage.save(); 3694 return storage.save();
3691 3695
3692} 3696}
3693 3697
3694void CalendarView::eventUpdated(Incidence *) 3698void CalendarView::eventUpdated(Incidence *)
3695{ 3699{
3696 setModified(); 3700 setModified();
3697 // Don't call updateView here. The code, which has caused the update of the 3701 // Don't call updateView here. The code, which has caused the update of the
3698 // event is responsible for updating the view. 3702 // event is responsible for updating the view.
3699 // updateView(); 3703 // updateView();
3700} 3704}
3701 3705
3702void CalendarView::adaptNavigationUnits() 3706void CalendarView::adaptNavigationUnits()
3703{ 3707{
3704 if (mViewManager->currentView()->isEventView()) { 3708 if (mViewManager->currentView()->isEventView()) {
3705 int days = mViewManager->currentView()->currentDateCount(); 3709 int days = mViewManager->currentView()->currentDateCount();
3706 if (days == 1) { 3710 if (days == 1) {
3707 emit changeNavStringPrev(i18n("&Previous Day")); 3711 emit changeNavStringPrev(i18n("&Previous Day"));
3708 emit changeNavStringNext(i18n("&Next Day")); 3712 emit changeNavStringNext(i18n("&Next Day"));
3709 } else { 3713 } else {
3710 emit changeNavStringPrev(i18n("&Previous Week")); 3714 emit changeNavStringPrev(i18n("&Previous Week"));
3711 emit changeNavStringNext(i18n("&Next Week")); 3715 emit changeNavStringNext(i18n("&Next Week"));
3712 } 3716 }
3713 } 3717 }
3714} 3718}
3715 3719
3716void CalendarView::processMainViewSelection( Incidence *incidence ) 3720void CalendarView::processMainViewSelection( Incidence *incidence )
3717{ 3721{
3718 if ( incidence ) mTodoList->clearSelection(); 3722 if ( incidence ) mTodoList->clearSelection();
3719 processIncidenceSelection( incidence ); 3723 processIncidenceSelection( incidence );
3720} 3724}
3721 3725
3722void CalendarView::processTodoListSelection( Incidence *incidence ) 3726void CalendarView::processTodoListSelection( Incidence *incidence )
3723{ 3727{
3724 if ( incidence && mViewManager->currentView() ) { 3728 if ( incidence && mViewManager->currentView() ) {
3725 mViewManager->currentView()->clearSelection(); 3729 mViewManager->currentView()->clearSelection();
3726 } 3730 }
3727 processIncidenceSelection( incidence ); 3731 processIncidenceSelection( incidence );
3728} 3732}
3729 3733
3730void CalendarView::processIncidenceSelection( Incidence *incidence ) 3734void CalendarView::processIncidenceSelection( Incidence *incidence )
3731{ 3735{
3732 if ( incidence == mSelectedIncidence ) return; 3736 if ( incidence == mSelectedIncidence ) return;
3733 3737
3734 mSelectedIncidence = incidence; 3738 mSelectedIncidence = incidence;
3735 3739
3736 emit incidenceSelected( mSelectedIncidence ); 3740 emit incidenceSelected( mSelectedIncidence );
3737 3741
3738 if ( incidence && incidence->type() == "Event" ) { 3742 if ( incidence && incidence->type() == "Event" ) {
3739 Event *event = static_cast<Event *>( incidence ); 3743 Event *event = static_cast<Event *>( incidence );
3740 if ( event->organizer() == KOPrefs::instance()->email() ) { 3744 if ( event->organizer() == KOPrefs::instance()->email() ) {
3741 emit organizerEventsSelected( true ); 3745 emit organizerEventsSelected( true );
3742 } else { 3746 } else {
3743 emit organizerEventsSelected(false); 3747 emit organizerEventsSelected(false);
3744 } 3748 }
3745 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3749 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3746 KOPrefs::instance()->email() ) ) { 3750 KOPrefs::instance()->email() ) ) {
3747 emit groupEventsSelected( true ); 3751 emit groupEventsSelected( true );
3748 } else { 3752 } else {
3749 emit groupEventsSelected(false); 3753 emit groupEventsSelected(false);
3750 } 3754 }
3751 return; 3755 return;
3752 } else { 3756 } else {
3753 if ( incidence && incidence->type() == "Todo" ) { 3757 if ( incidence && incidence->type() == "Todo" ) {
3754 emit todoSelected( true ); 3758 emit todoSelected( true );
3755 Todo *event = static_cast<Todo *>( incidence ); 3759 Todo *event = static_cast<Todo *>( incidence );
3756 if ( event->organizer() == KOPrefs::instance()->email() ) { 3760 if ( event->organizer() == KOPrefs::instance()->email() ) {
3757 emit organizerEventsSelected( true ); 3761 emit organizerEventsSelected( true );
3758 } else { 3762 } else {
3759 emit organizerEventsSelected(false); 3763 emit organizerEventsSelected(false);
3760 } 3764 }
3761 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3765 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3762 KOPrefs::instance()->email() ) ) { 3766 KOPrefs::instance()->email() ) ) {
3763 emit groupEventsSelected( true ); 3767 emit groupEventsSelected( true );
3764 } else { 3768 } else {
3765 emit groupEventsSelected(false); 3769 emit groupEventsSelected(false);
3766 } 3770 }
3767 return; 3771 return;
3768 } else { 3772 } else {
3769 emit todoSelected( false ); 3773 emit todoSelected( false );
3770 emit organizerEventsSelected(false); 3774 emit organizerEventsSelected(false);
3771 emit groupEventsSelected(false); 3775 emit groupEventsSelected(false);
3772 } 3776 }
3773 return; 3777 return;
3774 } 3778 }
3775 3779
3776 /* if ( incidence && incidence->type() == "Todo" ) { 3780 /* if ( incidence && incidence->type() == "Todo" ) {
3777 emit todoSelected( true ); 3781 emit todoSelected( true );
3778 } else { 3782 } else {
3779 emit todoSelected( false ); 3783 emit todoSelected( false );
3780 }*/ 3784 }*/
3781} 3785}
3782 3786
3783 3787
3784void CalendarView::checkClipboard() 3788void CalendarView::checkClipboard()
3785{ 3789{
3786#ifndef KORG_NODND 3790#ifndef KORG_NODND
3787 if (ICalDrag::canDecode(QApplication::clipboard()->data())) { 3791 if (ICalDrag::canDecode(QApplication::clipboard()->data())) {
3788 emit pasteEnabled(true); 3792 emit pasteEnabled(true);
3789 } else { 3793 } else {
3790 emit pasteEnabled(false); 3794 emit pasteEnabled(false);
3791 } 3795 }
3792#endif 3796#endif
3793} 3797}
3794 3798
3795void CalendarView::showDates(const DateList &selectedDates) 3799void CalendarView::showDates(const DateList &selectedDates)
3796{ 3800{
3797 // kdDebug() << "CalendarView::selectDates()" << endl; 3801 // kdDebug() << "CalendarView::selectDates()" << endl;
3798 3802
3799 3803
3800 if ( !mBlockShowDates ) { 3804 if ( !mBlockShowDates ) {
3801 if ( mViewManager->currentView() ) { 3805 if ( mViewManager->currentView() ) {
3802 updateView( selectedDates.first(), selectedDates.last() ); 3806 updateView( selectedDates.first(), selectedDates.last() );
3803 } else { 3807 } else {
3804 mViewManager->showAgendaView(); 3808 mViewManager->showAgendaView();
3805 } 3809 }
3806 } 3810 }
3807 3811
3808 QDate date = selectedDates.first(); 3812 QDate date = selectedDates.first();
3809 if ( ! date.isValid() ) { 3813 if ( ! date.isValid() ) {
3810 topLevelWidget()->setCaption(""); 3814 topLevelWidget()->setCaption("");
3811 return; 3815 return;
3812 } 3816 }
3813 3817
3814 QString selDates; 3818 QString selDates;
3815 selDates = KGlobal::locale()->formatDate( date, true); 3819 selDates = KGlobal::locale()->formatDate( date, true);
3816 if (selectedDates.first() < selectedDates.last() ) 3820 if (selectedDates.first() < selectedDates.last() )
3817 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); 3821 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true);
3818 else { 3822 else {
3819 QString addString; 3823 QString addString;
3820 if ( date == QDateTime::currentDateTime().date() ) 3824 if ( date == QDateTime::currentDateTime().date() )
3821 addString = i18n("Today"); 3825 addString = i18n("Today");
3822 else if ( date == QDateTime::currentDateTime().date().addDays(1) ) 3826 else if ( date == QDateTime::currentDateTime().date().addDays(1) )
3823 addString = i18n("Tomorrow"); 3827 addString = i18n("Tomorrow");
3824 else if ( date == QDateTime::currentDateTime().date().addDays(-1) ) 3828 else if ( date == QDateTime::currentDateTime().date().addDays(-1) )
3825 addString = i18n("Yesterday"); 3829 addString = i18n("Yesterday");
3826 else if ( date == QDateTime::currentDateTime().date().addDays(-2) ) 3830 else if ( date == QDateTime::currentDateTime().date().addDays(-2) )
3827 addString = i18n("Day before yesterday"); 3831 addString = i18n("Day before yesterday");
3828 else if ( date == QDateTime::currentDateTime().date().addDays(2) ) 3832 else if ( date == QDateTime::currentDateTime().date().addDays(2) )
3829 addString = i18n("Day after tomorrow"); 3833 addString = i18n("Day after tomorrow");
3830 if ( !addString.isEmpty() ) { 3834 if ( !addString.isEmpty() ) {
3831 topLevelWidget()->setCaption( addString+", " + selDates ); 3835 topLevelWidget()->setCaption( addString+", " + selDates );
3832 return; 3836 return;
3833 } 3837 }
3834 } 3838 }
3835 topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); 3839 topLevelWidget()->setCaption( i18n("Dates: ") + selDates );
3836 3840
3837} 3841}
3838 3842
3839QPtrList<CalFilter> CalendarView::filters() 3843QPtrList<CalFilter> CalendarView::filters()
3840{ 3844{
3841 return mFilters; 3845 return mFilters;
3842 3846
3843} 3847}
3844void CalendarView::editFilters() 3848void CalendarView::editFilters()
3845{ 3849{
3846 // kdDebug() << "CalendarView::editFilters()" << endl; 3850 // kdDebug() << "CalendarView::editFilters()" << endl;
3847 3851
3848 CalFilter *filter = mFilters.first(); 3852 CalFilter *filter = mFilters.first();
3849 while(filter) { 3853 while(filter) {
3850 kdDebug() << " Filter: " << filter->name() << endl; 3854 kdDebug() << " Filter: " << filter->name() << endl;
3851 filter = mFilters.next(); 3855 filter = mFilters.next();
3852 } 3856 }
3853 3857
3854 mDialogManager->showFilterEditDialog(&mFilters); 3858 mDialogManager->showFilterEditDialog(&mFilters);
3855} 3859}
3856void CalendarView::toggleFilter() 3860void CalendarView::toggleFilter()
3857{ 3861{
3858 showFilter(! mFilterView->isVisible()); 3862 showFilter(! mFilterView->isVisible());
3859} 3863}
3860 3864
3861KOFilterView *CalendarView::filterView() 3865KOFilterView *CalendarView::filterView()
3862{ 3866{
3863 return mFilterView; 3867 return mFilterView;
3864} 3868}
3865void CalendarView::selectFilter( int fil ) 3869void CalendarView::selectFilter( int fil )
3866{ 3870{
3867 mFilterView->setSelectedFilter( fil ); 3871 mFilterView->setSelectedFilter( fil );
3868} 3872}
3869void CalendarView::showFilter(bool visible) 3873void CalendarView::showFilter(bool visible)
3870{ 3874{
3871 if (visible) mFilterView->show(); 3875 if (visible) mFilterView->show();
3872 else mFilterView->hide(); 3876 else mFilterView->hide();
3873} 3877}
3874void CalendarView::toggleFilerEnabled( ) 3878void CalendarView::toggleFilerEnabled( )
3875{ 3879{
3876 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); 3880 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() );
3877 if ( !mFilterView->filtersEnabled() ) 3881 if ( !mFilterView->filtersEnabled() )
3878 topLevelWidget()->setCaption( i18n("Filter disabled ") ); 3882 topLevelWidget()->setCaption( i18n("Filter disabled ") );
3879 3883
3880} 3884}
3881void CalendarView::updateFilter() 3885void CalendarView::updateFilter()
3882{ 3886{
3883 CalFilter *filter = mFilterView->selectedFilter(); 3887 CalFilter *filter = mFilterView->selectedFilter();
3884 if (filter) { 3888 if (filter) {
3885 QString mess; 3889 QString mess;
3886 if (mFilterView->filtersEnabled()) { 3890 if (mFilterView->filtersEnabled()) {
3887 mess = i18n("Filter selected: ")+filter->name(); 3891 mess = i18n("Filter selected: ")+filter->name();
3888 filter->setEnabled(true); 3892 filter->setEnabled(true);
3889 } 3893 }
3890 else filter->setEnabled(false); 3894 else filter->setEnabled(false);
3891 mCalendar->setFilter(filter); 3895 mCalendar->setFilter(filter);
3892 updateView(); 3896 updateView();
3893 if ( !mess.isEmpty() ) 3897 if ( !mess.isEmpty() )
3894 topLevelWidget()->setCaption( mess ); 3898 topLevelWidget()->setCaption( mess );
3895 3899
3896 } 3900 }
3897} 3901}
3898 3902
3899void CalendarView::filterEdited() 3903void CalendarView::filterEdited()
3900{ 3904{
3901 mFilterView->updateFilters(); 3905 mFilterView->updateFilters();
3902 updateFilter(); 3906 updateFilter();
3903 writeSettings(); 3907 writeSettings();
3904} 3908}
3905 3909
3906 3910
3907void CalendarView::takeOverEvent() 3911void CalendarView::takeOverEvent()
3908{ 3912{
3909 Incidence *incidence = currentSelection(); 3913 Incidence *incidence = currentSelection();
3910 3914
3911 if (!incidence) return; 3915 if (!incidence) return;
3912 3916
3913 incidence->setOrganizer(KOPrefs::instance()->email()); 3917 incidence->setOrganizer(KOPrefs::instance()->email());
3914 incidence->recreate(); 3918 incidence->recreate();
3915 incidence->setReadOnly(false); 3919 incidence->setReadOnly(false);
3916 3920
3917 updateView(); 3921 updateView();
3918} 3922}
3919 3923
3920void CalendarView::takeOverCalendar() 3924void CalendarView::takeOverCalendar()
3921{ 3925{
3922 // TODO: Create Calendar::allIncidences() function and use it here 3926 // TODO: Create Calendar::allIncidences() function and use it here
3923 3927
3924 QPtrList<Event> events = mCalendar->events(); 3928 QPtrList<Event> events = mCalendar->events();
3925 for(uint i=0; i<events.count(); ++i) { 3929 for(uint i=0; i<events.count(); ++i) {
3926 events.at(i)->setOrganizer(KOPrefs::instance()->email()); 3930 events.at(i)->setOrganizer(KOPrefs::instance()->email());
3927 events.at(i)->recreate(); 3931 events.at(i)->recreate();
3928 events.at(i)->setReadOnly(false); 3932 events.at(i)->setReadOnly(false);
3929 } 3933 }
3930 3934
3931 QPtrList<Todo> todos = mCalendar->todos(); 3935 QPtrList<Todo> todos = mCalendar->todos();
3932 for(uint i=0; i<todos.count(); ++i) { 3936 for(uint i=0; i<todos.count(); ++i) {
3933 todos.at(i)->setOrganizer(KOPrefs::instance()->email()); 3937 todos.at(i)->setOrganizer(KOPrefs::instance()->email());
3934 todos.at(i)->recreate(); 3938 todos.at(i)->recreate();
3935 todos.at(i)->setReadOnly(false); 3939 todos.at(i)->setReadOnly(false);
3936 } 3940 }
3937 3941
3938 QPtrList<Journal> journals = mCalendar->journals(); 3942 QPtrList<Journal> journals = mCalendar->journals();
3939 for(uint i=0; i<journals.count(); ++i) { 3943 for(uint i=0; i<journals.count(); ++i) {
3940 journals.at(i)->setOrganizer(KOPrefs::instance()->email()); 3944 journals.at(i)->setOrganizer(KOPrefs::instance()->email());
3941 journals.at(i)->recreate(); 3945 journals.at(i)->recreate();
3942 journals.at(i)->setReadOnly(false); 3946 journals.at(i)->setReadOnly(false);
3943 } 3947 }
3944 3948
3945 updateView(); 3949 updateView();
3946} 3950}
3947 3951
3948void CalendarView::showIntro() 3952void CalendarView::showIntro()
3949{ 3953{
3950 kdDebug() << "To be implemented." << endl; 3954 kdDebug() << "To be implemented." << endl;
3951} 3955}
3952 3956
3953QWidgetStack *CalendarView::viewStack() 3957QWidgetStack *CalendarView::viewStack()
3954{ 3958{
3955 return mRightFrame; 3959 return mRightFrame;
3956} 3960}
3957 3961
3958QWidget *CalendarView::leftFrame() 3962QWidget *CalendarView::leftFrame()
3959{ 3963{
3960 return ( QWidget *)mLeftFrame; 3964 return ( QWidget *)mLeftFrame;
3961} 3965}
3962 3966
3963DateNavigator *CalendarView::dateNavigator() 3967DateNavigator *CalendarView::dateNavigator()
3964{ 3968{
3965 return mNavigator; 3969 return mNavigator;
3966} 3970}
3967 3971
3968KDateNavigator* CalendarView::dateNavigatorWidget() 3972KDateNavigator* CalendarView::dateNavigatorWidget()
3969{ 3973{
3970 return mDateNavigator->navigatorView(); 3974 return mDateNavigator->navigatorView();
3971} 3975}
3972void CalendarView::toggleDateNavigatorWidget() 3976void CalendarView::toggleDateNavigatorWidget()
3973{ 3977{
3974 KOPrefs::instance()->mShowDateNavigator = !KOPrefs::instance()->mShowDateNavigator ; 3978 KOPrefs::instance()->mShowDateNavigator = !KOPrefs::instance()->mShowDateNavigator ;
3975 3979
3976 if (!KOPrefs::instance()->mShowDateNavigator ) 3980 if (!KOPrefs::instance()->mShowDateNavigator )
3977 mDateNavigator->hide(); 3981 mDateNavigator->hide();
3978 else 3982 else
3979 mDateNavigator->show(); 3983 mDateNavigator->show();
3980} 3984}
3981void CalendarView::addView(KOrg::BaseView *view) 3985void CalendarView::addView(KOrg::BaseView *view)
3982{ 3986{
3983 mViewManager->addView(view); 3987 mViewManager->addView(view);
3984} 3988}
3985 3989
3986void CalendarView::showView(KOrg::BaseView *view) 3990void CalendarView::showView(KOrg::BaseView *view)
3987{ 3991{
3988 mViewManager->showView(view, mLeftFrame->isVisible()); 3992 mViewManager->showView(view, mLeftFrame->isVisible());
3989} 3993}
3990 3994
3991Incidence *CalendarView::currentSelection() 3995Incidence *CalendarView::currentSelection()
3992{ 3996{
3993 return mViewManager->currentSelection(); 3997 return mViewManager->currentSelection();
3994} 3998}
3995void CalendarView::toggleAllDaySize() 3999void CalendarView::toggleAllDaySize()
3996{ 4000{
3997 /* 4001 /*
3998 if ( KOPrefs::instance()->mAllDaySize > 47 ) 4002 if ( KOPrefs::instance()->mAllDaySize > 47 )
3999 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2; 4003 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2;
4000 else 4004 else
4001 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2; 4005 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2;
4002 */ 4006 */
4003 viewManager()->agendaView()->toggleAllDay(); 4007 viewManager()->agendaView()->toggleAllDay();
4004} 4008}
4005void CalendarView::toggleExpand() 4009void CalendarView::toggleExpand()
4006{ 4010{
4007 // if ( mLeftFrame->isHidden() ) { 4011 // if ( mLeftFrame->isHidden() ) {
4008 // mLeftFrame->show(); 4012 // mLeftFrame->show();
4009 // emit calendarViewExpanded( false ); 4013 // emit calendarViewExpanded( false );
4010 // } else { 4014 // } else {
4011 // mLeftFrame->hide(); 4015 // mLeftFrame->hide();
4012 // emit calendarViewExpanded( true ); 4016 // emit calendarViewExpanded( true );
4013 // } 4017 // }
4014 //qDebug(" CalendarView::toggleExpand()"); 4018 //qDebug(" CalendarView::toggleExpand()");
4015 globalFlagBlockAgenda = 1; 4019 globalFlagBlockAgenda = 1;
4016 emit calendarViewExpanded( !mLeftFrame->isHidden() ); 4020 emit calendarViewExpanded( !mLeftFrame->isHidden() );
4017 globalFlagBlockAgenda = 5; 4021 globalFlagBlockAgenda = 5;
4018 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() ); 4022 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() );
4019 //mViewManager->showView( 0, true ); 4023 //mViewManager->showView( 0, true );
4020} 4024}
4021 4025
4022void CalendarView::calendarModified( bool modified, Calendar * ) 4026void CalendarView::calendarModified( bool modified, Calendar * )
4023{ 4027{
4024 setModified( modified ); 4028 setModified( modified );
4025} 4029}
4026 4030
4027Todo *CalendarView::selectedTodo() 4031Todo *CalendarView::selectedTodo()
4028{ 4032{
4029 Incidence *incidence = currentSelection(); 4033 Incidence *incidence = currentSelection();
4030 if ( incidence && incidence->type() == "Todo" ) { 4034 if ( incidence && incidence->type() == "Todo" ) {
4031 return static_cast<Todo *>( incidence ); 4035 return static_cast<Todo *>( incidence );
4032 } 4036 }
4033 4037
4034 incidence = mTodoList->selectedIncidences().first(); 4038 incidence = mTodoList->selectedIncidences().first();
4035 if ( incidence && incidence->type() == "Todo" ) { 4039 if ( incidence && incidence->type() == "Todo" ) {
4036 return static_cast<Todo *>( incidence ); 4040 return static_cast<Todo *>( incidence );
4037 } 4041 }
4038 4042
4039 return 0; 4043 return 0;
4040} 4044}
4041 4045
4042void CalendarView::dialogClosing(Incidence *in) 4046void CalendarView::dialogClosing(Incidence *in)
4043{ 4047{
4044 // mDialogList.remove(in); 4048 // mDialogList.remove(in);
4045} 4049}
4046 4050
4047void CalendarView::showIncidence() 4051void CalendarView::showIncidence()
4048{ 4052{
4049 mViewerCallerIsSearchDialog = false; 4053 mViewerCallerIsSearchDialog = false;
4050 Incidence *incidence = currentSelection(); 4054 Incidence *incidence = currentSelection();
4051 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 4055 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
4052 if ( incidence ) { 4056 if ( incidence ) {
4053 ShowIncidenceVisitor v; 4057 ShowIncidenceVisitor v;
4054 v.act( incidence, this ); 4058 v.act( incidence, this );
4055 } 4059 }
4056} 4060}
4057void CalendarView::editIncidenceDescription() 4061void CalendarView::editIncidenceDescription()
4058{ 4062{
4059 mFlagEditDescription = true; 4063 mFlagEditDescription = true;
4060 editIncidence(); 4064 editIncidence();
4061 mFlagEditDescription = false; 4065 mFlagEditDescription = false;
4062} 4066}
4063void CalendarView::editIncidence() 4067void CalendarView::editIncidence()
4064{ 4068{
4065 // qDebug("editIncidence() "); 4069 // qDebug("editIncidence() ");
4066 Incidence *incidence = currentSelection(); 4070 Incidence *incidence = currentSelection();
4067 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 4071 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
4068 if ( incidence ) { 4072 if ( incidence ) {
4069 EditIncidenceVisitor v; 4073 EditIncidenceVisitor v;
4070 v.act( incidence, this ); 4074 v.act( incidence, this );
4071 } 4075 }
4072} 4076}
4073 4077
4074void CalendarView::deleteIncidence() 4078void CalendarView::deleteIncidence()
4075{ 4079{
4076 Incidence *incidence = currentSelection(); 4080 Incidence *incidence = currentSelection();
4077 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 4081 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
4078 if ( incidence ) { 4082 if ( incidence ) {
4079 deleteIncidence(incidence); 4083 deleteIncidence(incidence);
4080 } 4084 }
4081} 4085}
4082void CalendarView::showIncidence(QString uid) 4086void CalendarView::showIncidence(QString uid)
4083{ 4087{
4084 Incidence *inc = mCalendar->incidence( uid ); 4088 Incidence *inc = mCalendar->incidence( uid );
4085 if ( inc ) 4089 if ( inc )
4086 showIncidence( inc ); 4090 showIncidence( inc );
4087} 4091}
4088void CalendarView::showIncidence(Incidence *incidence) 4092void CalendarView::showIncidence(Incidence *incidence)
4089{ 4093{
4090 mViewerCallerIsSearchDialog = false; 4094 mViewerCallerIsSearchDialog = false;
4091 //qDebug("%x %x ",sender (), mDialogManager->getSearchDialog() ); 4095 //qDebug("%x %x ",sender (), mDialogManager->getSearchDialog() );
4092 if ( sender() && mDialogManager->getSearchDialog() ) { 4096 if ( sender() && mDialogManager->getSearchDialog() ) {
4093 if ( sender () == mDialogManager->getSearchDialog()->listview() ) { 4097 if ( sender () == mDialogManager->getSearchDialog()->listview() ) {
4094 mViewerCallerIsSearchDialog = true; 4098 mViewerCallerIsSearchDialog = true;
4095 } 4099 }
4096 } 4100 }
4097 if ( incidence ) { 4101 if ( incidence ) {
4098 ShowIncidenceVisitor v; 4102 ShowIncidenceVisitor v;
4099 v.act( incidence, this ); 4103 v.act( incidence, this );
4100 } 4104 }
4101} 4105}
4102 4106
4103void CalendarView::editIncidence(Incidence *incidence) 4107void CalendarView::editIncidence(Incidence *incidence)
4104{ 4108{
4105 if ( incidence ) { 4109 if ( incidence ) {
4106 4110
4107 EditIncidenceVisitor v; 4111 EditIncidenceVisitor v;
4108 v.act( incidence, this ); 4112 v.act( incidence, this );
4109 4113
4110 } 4114 }
4111} 4115}
4112 4116
4113void CalendarView::deleteIncidence(Incidence *incidence) 4117void CalendarView::deleteIncidence(Incidence *incidence)
4114{ 4118{
4115 //qDebug(" CalendarView::deleteIncidence "); 4119 //qDebug(" CalendarView::deleteIncidence ");
4116 if ( incidence ) { 4120 if ( incidence ) {
4117 DeleteIncidenceVisitor v; 4121 DeleteIncidenceVisitor v;
4118 v.act( incidence, this ); 4122 v.act( incidence, this );
4119 } 4123 }
4120} 4124}
4121 4125
4122 4126
4123void CalendarView::lookForOutgoingMessages() 4127void CalendarView::lookForOutgoingMessages()
4124{ 4128{
4125 OutgoingDialog *ogd = mDialogManager->outgoingDialog(); 4129 OutgoingDialog *ogd = mDialogManager->outgoingDialog();
4126 ogd->loadMessages(); 4130 ogd->loadMessages();
4127} 4131}
4128 4132
4129void CalendarView::lookForIncomingMessages() 4133void CalendarView::lookForIncomingMessages()
4130{ 4134{
4131 IncomingDialog *icd = mDialogManager->incomingDialog(); 4135 IncomingDialog *icd = mDialogManager->incomingDialog();
4132 icd->retrieve(); 4136 icd->retrieve();
4133} 4137}
4134 4138
4135bool CalendarView::removeCompletedSubTodos( Todo* t ) 4139bool CalendarView::removeCompletedSubTodos( Todo* t )
4136{ 4140{
4137 bool deleteTodo = true; 4141 bool deleteTodo = true;
4138 QPtrList<Incidence> subTodos; 4142 QPtrList<Incidence> subTodos;
4139 Incidence *aTodo; 4143 Incidence *aTodo;
4140 subTodos = t->relations(); 4144 subTodos = t->relations();
4141 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) { 4145 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) {
4142 if (! removeCompletedSubTodos( (Todo*) aTodo )) 4146 if (! removeCompletedSubTodos( (Todo*) aTodo ))
4143 deleteTodo = false; 4147 deleteTodo = false;
4144 } 4148 }
4145 if ( deleteTodo ) { 4149 if ( deleteTodo ) {
4146 if ( t->isCompleted() && !t->doesRecur()) { 4150 if ( t->isCompleted() && !t->doesRecur()) {
4147 checkExternalId( t ); 4151 checkExternalId( t );
4148 mCalendar->deleteTodo( t ); 4152 mCalendar->deleteTodo( t );
4149 changeTodoDisplay( t,KOGlobals::EVENTDELETED ); 4153 changeTodoDisplay( t,KOGlobals::EVENTDELETED );
4150 } 4154 }
4151 else 4155 else
4152 deleteTodo = false; 4156 deleteTodo = false;
4153 } 4157 }
4154 return deleteTodo; 4158 return deleteTodo;
4155 4159
4156} 4160}
4157void CalendarView::purgeCompleted() 4161void CalendarView::purgeCompleted()
4158{ 4162{
4159 int result = KMessageBox::warningContinueCancel(this, 4163 int result = KMessageBox::warningContinueCancel(this,
4160 i18n("Delete all completed todos?\n(Completed recurring todos\nwill not be deleted!)"),i18n("Purge Todos"),i18n("Purge")); 4164 i18n("Delete all completed todos?\n(Completed recurring todos\nwill not be deleted!)"),i18n("Purge Todos"),i18n("Purge"));
4161 4165
4162 if (result == KMessageBox::Continue) { 4166 if (result == KMessageBox::Continue) {
4163 4167
4164 QPtrList<Todo> todoCal; 4168 QPtrList<Todo> todoCal;
4165 QPtrList<Todo> rootTodos; 4169 QPtrList<Todo> rootTodos;
4166 //QPtrList<Incidence> rel; 4170 //QPtrList<Incidence> rel;
4167 Todo *aTodo;//, *rTodo; 4171 Todo *aTodo;//, *rTodo;
4168 Incidence *rIncidence; 4172 Incidence *rIncidence;
4169 bool childDelete = false; 4173 bool childDelete = false;
4170 bool deletedOne = true; 4174 bool deletedOne = true;
4171 todoCal = calendar()->todos(); 4175 todoCal = calendar()->todos();
4172 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { 4176 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) {
4173 if ( !aTodo->relatedTo() ) 4177 if ( !aTodo->relatedTo() )
4174 rootTodos.append( aTodo ); 4178 rootTodos.append( aTodo );
4175 } 4179 }
4176 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { 4180 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) {
4177 removeCompletedSubTodos( aTodo ); 4181 removeCompletedSubTodos( aTodo );
4178 } 4182 }
4179 4183
4180 updateView(); 4184 updateView();
4181 } 4185 }
4182} 4186}
4183 4187
4184void CalendarView::slotCalendarChanged() 4188void CalendarView::slotCalendarChanged()
4185{ 4189{
4186 ; 4190 ;
4187} 4191}
4188 4192
4189void CalendarView::keyPressEvent ( QKeyEvent *e) 4193void CalendarView::keyPressEvent ( QKeyEvent *e)
4190{ 4194{
4191 //qDebug(" alendarView::keyPressEvent "); 4195 //qDebug(" alendarView::keyPressEvent ");
4192 e->ignore(); 4196 e->ignore();
4193} 4197}
4194 4198
4195 4199
4196bool CalendarView::sync(KSyncManager* manager, QString filename, int mode) 4200bool CalendarView::sync(KSyncManager* manager, QString filename, int mode)
4197{ 4201{
4198 // mSyncManager = manager; 4202 // mSyncManager = manager;
4199 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) { 4203 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) {
4200 qDebug("KO: SyncKDE request detected!"); 4204 qDebug("KO: SyncKDE request detected!");
4201 } 4205 }
4202 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 4206 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
4203 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 4207 mCurrentSyncName = mSyncManager->getCurrentSyncName();
4204 return syncCalendar( filename, mode ); 4208 return syncCalendar( filename, mode );
4205} 4209}
4206bool CalendarView::syncExternal(KSyncManager* manager, QString resource) 4210bool CalendarView::syncExternal(KSyncManager* manager, QString resource)
4207{ 4211{
4208 //mSyncManager = manager; 4212 //mSyncManager = manager;
4209 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 4213 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
4210 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 4214 mCurrentSyncName = mSyncManager->getCurrentSyncName();
4211 if ( resource == "sharp" ) 4215 if ( resource == "sharp" )
4212 syncExternal( 0 ); 4216 syncExternal( 0 );
4213 if ( resource == "phone" ) 4217 if ( resource == "phone" )
4214 syncExternal( 1 ); 4218 syncExternal( 1 );
4215 // pending setmodified 4219 // pending setmodified
4216 return true; 4220 return true;
4217} 4221}
4218void CalendarView::setSyncManager(KSyncManager* manager) 4222void CalendarView::setSyncManager(KSyncManager* manager)
4219{ 4223{
4220 mSyncManager = manager; 4224 mSyncManager = manager;
4221} 4225}
4222 4226
4223void CalendarView::removeSyncInfo( QString syncProfile) 4227void CalendarView::removeSyncInfo( QString syncProfile)
4224{ 4228{
4225 qDebug("KO: removeSyncInfo for profile %s ", syncProfile.latin1()); 4229 qDebug("KO: removeSyncInfo for profile %s ", syncProfile.latin1());
4226 mCalendar->removeSyncInfo( syncProfile ); 4230 mCalendar->removeSyncInfo( syncProfile );
4227 4231
4228} 4232}
4229 4233
4230void CalendarView::undo_delete() 4234void CalendarView::undo_delete()
4231{ 4235{
4232 //qDebug("undo_delete() "); 4236 //qDebug("undo_delete() ");
4233 Incidence* undo = mCalendar->undoIncidence(); 4237 Incidence* undo = mCalendar->undoIncidence();
4234 if ( !undo ) { 4238 if ( !undo ) {
4235 KMessageBox::sorry(this,i18n("There is nothing to undo!"), 4239 KMessageBox::sorry(this,i18n("There is nothing to undo!"),
4236 i18n("KO/Pi")); 4240 i18n("KO/Pi"));
4237 return; 4241 return;
4238 } 4242 }
4239 if ( KMessageBox::Continue ==KMessageBox::warningContinueCancel(this,undo->summary().left(25) + 4243 if ( KMessageBox::Continue ==KMessageBox::warningContinueCancel(this,undo->summary().left(25) +
4240 i18n("\nAre you sure you want\nto restore this?"), 4244 i18n("\nAre you sure you want\nto restore this?"),
4241 i18n("KO/Pi Confirmation"),i18n("Restore"))) { 4245 i18n("KO/Pi Confirmation"),i18n("Restore"))) {
4242 mCalendar->undoDeleteIncidence(); 4246 mCalendar->undoDeleteIncidence();
4243 updateView(); 4247 updateView();
4244 } 4248 }
4245} 4249}
4246 4250
4247void CalendarView::slotViewerClosed() 4251void CalendarView::slotViewerClosed()
4248{ 4252{
4249 QTimer::singleShot( 50, this, SLOT ( resetFocus() ) ); 4253 QTimer::singleShot( 50, this, SLOT ( resetFocus() ) );
4250} 4254}
4251 4255
4252void CalendarView::resetFocus() 4256void CalendarView::resetFocus()
4253{ 4257{
4254 if ( mViewerCallerIsSearchDialog ) { 4258 if ( mViewerCallerIsSearchDialog ) {
4255 if ( mDialogManager->getSearchDialog()->isVisible() ){ 4259 if ( mDialogManager->getSearchDialog()->isVisible() ){
4256 mDialogManager->getSearchDialog()->raise(); 4260 mDialogManager->getSearchDialog()->raise();
4257 mDialogManager->getSearchDialog()->setActiveWindow(); 4261 mDialogManager->getSearchDialog()->setActiveWindow();
4258 mDialogManager->getSearchDialog()->listview()->resetFocus(); 4262 mDialogManager->getSearchDialog()->listview()->resetFocus();
4259 } else 4263 } else
4260 mViewerCallerIsSearchDialog = false; 4264 mViewerCallerIsSearchDialog = false;
4261 } 4265 }
4262 if ( !mViewerCallerIsSearchDialog ) { 4266 if ( !mViewerCallerIsSearchDialog ) {
4263 //mViewManager->currentView()->setFocus(); 4267 //mViewManager->currentView()->setFocus();
4264 //qDebug("sssssssssssssssset focus "); 4268 //qDebug("sssssssssssssssset focus ");
4265 topLevelWidget()->raise(); 4269 topLevelWidget()->raise();
4266 setActiveWindow(); 4270 setActiveWindow();
4267 //setFocus(); 4271 //setFocus();
4268 } 4272 }
4269 mViewerCallerIsSearchDialog = false; 4273 mViewerCallerIsSearchDialog = false;
4270} 4274}
4271 4275
4272void CalendarView::showNextAlarms() 4276void CalendarView::showNextAlarms()
4273{ 4277{
4274 QString message; 4278 QString message;
4275 QDateTime nextAl = mCalendar->nextAlarmEventDateTime(); 4279 QDateTime nextAl = mCalendar->nextAlarmEventDateTime();
4276 if ( nextAl.isValid() && mNextAlarmDateTime > QDateTime::currentDateTime() ) { 4280 if ( nextAl.isValid() && mNextAlarmDateTime > QDateTime::currentDateTime() ) {
4277 QString sum = mCalendar->nextSummary(); 4281 QString sum = mCalendar->nextSummary();
4278 QDateTime nextA = mNextAlarmDateTime; 4282 QDateTime nextA = mNextAlarmDateTime;
4279 QDateTime cur = QDateTime::currentDateTime(); 4283 QDateTime cur = QDateTime::currentDateTime();
4280 int secs = cur.secsTo( nextA ); 4284 int secs = cur.secsTo( nextA );
4281 int min = secs /60; 4285 int min = secs /60;
4282 int hours = min /60; 4286 int hours = min /60;
4283 min = min % 60; 4287 min = min % 60;
4284 int days = hours /24; 4288 int days = hours /24;
4285 hours = hours % 24; 4289 hours = hours % 24;
4286 4290
4287 //message = i18n("The next alarm is in:\n"); 4291 //message = i18n("The next alarm is in:\n");
4288 if ( days > 1 ) 4292 if ( days > 1 )
4289 message += i18n("%1 days\n").arg( days ); 4293 message += i18n("%1 days\n").arg( days );
4290 else if ( days == 1 ) 4294 else if ( days == 1 )
4291 message += i18n("1 day\n"); 4295 message += i18n("1 day\n");
4292 if ( hours > 1 ) 4296 if ( hours > 1 )
4293 message += i18n("%1 hours\n").arg( hours ); 4297 message += i18n("%1 hours\n").arg( hours );
4294 else if ( hours == 1 ) 4298 else if ( hours == 1 )
4295 message += i18n("1 hour\n"); 4299 message += i18n("1 hour\n");
4296 if ( min > 1 ) 4300 if ( min > 1 )
4297 message += i18n("%1 minutes\n").arg( min ); 4301 message += i18n("%1 minutes\n").arg( min );
4298 else if ( min == 1 ) 4302 else if ( min == 1 )
4299 message += i18n("1 minute\n"); 4303 message += i18n("1 minute\n");
4300 if ( message.isEmpty() ) 4304 if ( message.isEmpty() )
4301 message = i18n("The next alarm is in\nless than one minute!"); 4305 message = i18n("The next alarm is in\nless than one minute!");
4302 else 4306 else
4303 message = i18n("The next alarm is in:\n") + message; 4307 message = i18n("The next alarm is in:\n") + message;
4304 message += i18n("\n(%1)\n\n%2\n(%3)\n").arg( KGlobal::locale()->formatDateTime(nextA , false)).arg(sum ).arg( KGlobal::locale()->formatDateTime(nextAl , false)) ; 4308 message += i18n("\n(%1)\n\n%2\n(%3)\n").arg( KGlobal::locale()->formatDateTime(nextA , false)).arg(sum ).arg( KGlobal::locale()->formatDateTime(nextAl , false)) ;
4305 } else { 4309 } else {
4306 message = i18n("There is no next alarm."); 4310 message = i18n("There is no next alarm.");
4307 4311
4308 } 4312 }
4309#ifdef DESKTOP_VERSION 4313#ifdef DESKTOP_VERSION
4310 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 4314 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
4311 message += i18n("\nThe internal alarm notification is disabled!\n"); 4315 message += i18n("\nThe internal alarm notification is disabled!\n");
4312 message += i18n("Enable it in the settings menu, TAB alarm."); 4316 message += i18n("Enable it in the settings menu, TAB alarm.");
4313 } 4317 }
4314 4318
4315#endif 4319#endif
4316 KMessageBox::information( this, message); 4320 KMessageBox::information( this, message);
4317} 4321}