summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp3
-rw-r--r--korganizer/kotodoview.cpp31
2 files changed, 21 insertions, 13 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index ab69158..5a2482e 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,4820 +1,4821 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Requires the Qt and KDE widget libraries, available at no cost at 4 Requires the Qt and KDE widget libraries, available at no cost at
5 http://www.troll.no and http://www.kde.org respectively 5 http://www.troll.no and http://www.kde.org respectively
6 6
7 Copyright (c) 1997, 1998, 1999 7 Copyright (c) 1997, 1998, 1999
8 Preston Brown (preton.brown@yale.edu) 8 Preston Brown (preton.brown@yale.edu)
9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl) 9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl)
10 Ian Dawes (iadawes@globalserve.net) 10 Ian Dawes (iadawes@globalserve.net)
11 Laszlo Boloni (boloni@cs.purdue.edu) 11 Laszlo Boloni (boloni@cs.purdue.edu)
12 12
13 Copyright (c) 2000, 2001, 2002 13 Copyright (c) 2000, 2001, 2002
14 Cornelius Schumacher <schumacher@kde.org> 14 Cornelius Schumacher <schumacher@kde.org>
15 15
16 This program is free software; you can redistribute it and/or modify 16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by 17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or 18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version. 19 (at your option) any later version.
20 20
21 This program is distributed in the hope that it will be useful, 21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
24 GNU General Public License for more details. 24 GNU General Public License for more details.
25 25
26 You should have received a copy of the GNU General Public License 26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software 27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#include <stdlib.h> 31#include <stdlib.h>
32 32
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qradiobutton.h> 34#include <qradiobutton.h>
35#include <qbuttongroup.h> 35#include <qbuttongroup.h>
36#include <qlayout.h> 36#include <qlayout.h>
37#include <qclipboard.h> 37#include <qclipboard.h>
38#include <qcursor.h> 38#include <qcursor.h>
39#include <qmessagebox.h> 39#include <qmessagebox.h>
40#include <qprogressbar.h> 40#include <qprogressbar.h>
41#include <qmultilineedit.h> 41#include <qmultilineedit.h>
42#include <qtimer.h> 42#include <qtimer.h>
43#include <qwidgetstack.h> 43#include <qwidgetstack.h>
44#include <qptrlist.h> 44#include <qptrlist.h>
45#include <qregexp.h> 45#include <qregexp.h>
46#include <qgroupbox.h> 46#include <qgroupbox.h>
47#include <qfile.h> 47#include <qfile.h>
48#include <qdir.h> 48#include <qdir.h>
49#ifndef KORG_NOSPLITTER 49#ifndef KORG_NOSPLITTER
50#include <qsplitter.h> 50#include <qsplitter.h>
51#endif 51#endif
52 52
53#include <kglobal.h> 53#include <kglobal.h>
54#include <kdebug.h> 54#include <kdebug.h>
55#include <kstandarddirs.h> 55#include <kstandarddirs.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57#include <kmessagebox.h> 57#include <kmessagebox.h>
58#include <knotifyclient.h> 58#include <knotifyclient.h>
59#include <kconfig.h> 59#include <kconfig.h>
60 60
61#include <libkdepim/ksyncprefsdialog.h> 61#include <libkdepim/ksyncprefsdialog.h>
62#include <krun.h> 62#include <krun.h>
63#include <kdirwatch.h> 63#include <kdirwatch.h>
64#include <libkdepim/kdatepicker.h> 64#include <libkdepim/kdatepicker.h>
65#include <libkdepim/ksyncprofile.h> 65#include <libkdepim/ksyncprofile.h>
66#include <libkdepim/kpimglobalprefs.h> 66#include <libkdepim/kpimglobalprefs.h>
67 67
68#include <libkcal/vcaldrag.h> 68#include <libkcal/vcaldrag.h>
69#include <libkcal/icaldrag.h> 69#include <libkcal/icaldrag.h>
70#include <libkcal/icalformat.h> 70#include <libkcal/icalformat.h>
71#include <libkcal/vcalformat.h> 71#include <libkcal/vcalformat.h>
72#include <libkcal/scheduler.h> 72#include <libkcal/scheduler.h>
73#include <libkcal/calendarlocal.h> 73#include <libkcal/calendarlocal.h>
74#include <libkcal/journal.h> 74#include <libkcal/journal.h>
75#include <libkcal/calfilter.h> 75#include <libkcal/calfilter.h>
76#include <libkcal/attendee.h> 76#include <libkcal/attendee.h>
77#include <libkcal/dndfactory.h> 77#include <libkcal/dndfactory.h>
78#include <libkcal/freebusy.h> 78#include <libkcal/freebusy.h>
79#include <libkcal/filestorage.h> 79#include <libkcal/filestorage.h>
80#include <libkcal/calendarresources.h> 80#include <libkcal/calendarresources.h>
81#include <libkcal/qtopiaformat.h> 81#include <libkcal/qtopiaformat.h>
82#include "../kalarmd/alarmdialog.h" 82#include "../kalarmd/alarmdialog.h"
83 83
84#ifndef DESKTOP_VERSION 84#ifndef DESKTOP_VERSION
85#include <libkcal/sharpformat.h> 85#include <libkcal/sharpformat.h>
86#include <externalapphandler.h> 86#include <externalapphandler.h>
87#endif 87#endif
88#include <libkcal/phoneformat.h> 88#include <libkcal/phoneformat.h>
89#ifndef KORG_NOMAIL 89#ifndef KORG_NOMAIL
90#include "komailclient.h" 90#include "komailclient.h"
91#endif 91#endif
92#ifndef KORG_NOPRINTER 92#ifndef KORG_NOPRINTER
93#include "calprinter.h" 93#include "calprinter.h"
94#endif 94#endif
95#ifndef KORG_NOPLUGINS 95#ifndef KORG_NOPLUGINS
96#include "kocore.h" 96#include "kocore.h"
97#endif 97#endif
98#include "koeventeditor.h" 98#include "koeventeditor.h"
99#include "kotodoeditor.h" 99#include "kotodoeditor.h"
100#include "koprefs.h" 100#include "koprefs.h"
101#include "koeventviewerdialog.h" 101#include "koeventviewerdialog.h"
102#include "publishdialog.h" 102#include "publishdialog.h"
103#include "kofilterview.h" 103#include "kofilterview.h"
104#include "koglobals.h" 104#include "koglobals.h"
105#include "koviewmanager.h" 105#include "koviewmanager.h"
106#include "koagendaview.h" 106#include "koagendaview.h"
107#include "koagenda.h" 107#include "koagenda.h"
108#include "kodialogmanager.h" 108#include "kodialogmanager.h"
109#include "outgoingdialog.h" 109#include "outgoingdialog.h"
110#include "incomingdialog.h" 110#include "incomingdialog.h"
111#include "datenavigatorcontainer.h" 111#include "datenavigatorcontainer.h"
112#include "statusdialog.h" 112#include "statusdialog.h"
113#include "kdatenavigator.h" 113#include "kdatenavigator.h"
114#include "kotodoview.h" 114#include "kotodoview.h"
115#include "datenavigator.h" 115#include "datenavigator.h"
116#include "resourceview.h" 116#include "resourceview.h"
117#include "navigatorbar.h" 117#include "navigatorbar.h"
118#include "searchdialog.h" 118#include "searchdialog.h"
119#include "mainwindow.h" 119#include "mainwindow.h"
120#include "categoryeditdialog.h" 120#include "categoryeditdialog.h"
121 121
122#include "calendarview.h" 122#include "calendarview.h"
123#ifndef DESKTOP_VERSION 123#ifndef DESKTOP_VERSION
124#include <qtopia/alarmserver.h> 124#include <qtopia/alarmserver.h>
125#endif 125#endif
126#ifndef _WIN32_ 126#ifndef _WIN32_
127#include <stdlib.h> 127#include <stdlib.h>
128#include <stdio.h> 128#include <stdio.h>
129#include <unistd.h> 129#include <unistd.h>
130#else 130#else
131#include <qprocess.h> 131#include <qprocess.h>
132#endif 132#endif
133 133
134#ifdef DESKTOP_VERSION 134#ifdef DESKTOP_VERSION
135#include <kabc/stdaddressbook.h> 135#include <kabc/stdaddressbook.h>
136#endif 136#endif
137using namespace KOrg; 137using namespace KOrg;
138using namespace KCal; 138using namespace KCal;
139extern int globalFlagBlockAgenda; 139extern int globalFlagBlockAgenda;
140extern int globalFlagBlockStartup; 140extern int globalFlagBlockStartup;
141 141
142 142
143MissedAlarmTextBrowser::MissedAlarmTextBrowser(QWidget *parent, QPtrList<Incidence> alarms,QDateTime start ) : QTextBrowser(parent) 143MissedAlarmTextBrowser::MissedAlarmTextBrowser(QWidget *parent, QPtrList<Incidence> alarms,QDateTime start ) : QTextBrowser(parent)
144 144
145{ 145{
146 mAlarms = alarms; 146 mAlarms = alarms;
147 viewport()->setBackgroundColor( QColor( 255, 255, 255 ) ); 147 viewport()->setBackgroundColor( QColor( 255, 255, 255 ) );
148 QString mText = "<table width=\"100%\">\n"; 148 QString mText = "<table width=\"100%\">\n";
149 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>"; 149 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>";
150#ifdef DESKTOP_VERSION 150#ifdef DESKTOP_VERSION
151 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h2>"; 151 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h2>";
152#else 152#else
153 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h3>"; 153 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h3>";
154#endif 154#endif
155 // mText += "<img src=\""; 155 // mText += "<img src=\"";
156 // mText += ipath; 156 // mText += ipath;
157 // mText += "\">"; 157 // mText += "\">";
158 //mEventDate = QDate::currentDate(); 158 //mEventDate = QDate::currentDate();
159#ifdef DESKTOP_VERSION 159#ifdef DESKTOP_VERSION
160 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h2>"; 160 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h2>";
161#else 161#else
162 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h3>"; 162 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h3>";
163#endif 163#endif
164 //mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>"; 164 //mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>";
165 165
166 Incidence * inc = getNextInc( start ); 166 Incidence * inc = getNextInc( start );
167 int time = 0; 167 int time = 0;
168 //mText += "<table>"; 168 //mText += "<table>";
169 while ( inc ) { 169 while ( inc ) {
170 QDateTime dt ; 170 QDateTime dt ;
171 QString tempText = "<a "; 171 QString tempText = "<a ";
172 bool ok; 172 bool ok;
173 dt = inc->getNextOccurence( start, &ok ); 173 dt = inc->getNextOccurence( start, &ok );
174 if ( !ok ) continue; 174 if ( !ok ) continue;
175 if ( inc->typeID() == eventID ) { 175 if ( inc->typeID() == eventID ) {
176 tempText += "href=\"event:"; 176 tempText += "href=\"event:";
177 } else if ( inc->typeID() == todoID ) { 177 } else if ( inc->typeID() == todoID ) {
178 tempText += "href=\"todo:"; 178 tempText += "href=\"todo:";
179 } 179 }
180 tempText += inc->uid() + "\">"; 180 tempText += inc->uid() + "\">";
181 if ( inc->typeID() == todoID ) 181 if ( inc->typeID() == todoID )
182 tempText += i18n("Todo: "); 182 tempText += i18n("Todo: ");
183 if ( inc->summary().length() > 0 ) 183 if ( inc->summary().length() > 0 )
184 tempText += inc->summary(); 184 tempText += inc->summary();
185 else 185 else
186 tempText += i18n("-no summary-"); 186 tempText += i18n("-no summary-");
187 QString timestr; 187 QString timestr;
188 if (!inc->doesFloat()) 188 if (!inc->doesFloat())
189 timestr = KGlobal::locale()->formatDateTime( dt, KOPrefs::instance()->mShortDateInViewer) +": "; 189 timestr = KGlobal::locale()->formatDateTime( dt, KOPrefs::instance()->mShortDateInViewer) +": ";
190 else 190 else
191 timestr = KGlobal::locale()->formatDate( dt.date() , KOPrefs::instance()->mShortDateInViewer) +": "; 191 timestr = KGlobal::locale()->formatDate( dt.date() , KOPrefs::instance()->mShortDateInViewer) +": ";
192 if ( dt.date() < QDate::currentDate() && time == 0 ) { 192 if ( dt.date() < QDate::currentDate() && time == 0 ) {
193 mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>"; 193 mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>";
194 mText += "<table>"; 194 mText += "<table>";
195 time = 1; 195 time = 1;
196 } 196 }
197 if ( dt.date() == QDate::currentDate() && time <= 1 ) { 197 if ( dt.date() == QDate::currentDate() && time <= 1 ) {
198 if ( time > 0 ) 198 if ( time > 0 )
199 mText +="</table>"; 199 mText +="</table>";
200 mText += "</td></tr>\n<tr bgcolor=\"#FFDC64\"><td>"; 200 mText += "</td></tr>\n<tr bgcolor=\"#FFDC64\"><td>";
201 mText += "<table>"; 201 mText += "<table>";
202 time = 2; 202 time = 2;
203 203
204 } 204 }
205 if ( dt.date() > QDate::currentDate() && time <= 2 ) { 205 if ( dt.date() > QDate::currentDate() && time <= 2 ) {
206 if ( time > 0 ) 206 if ( time > 0 )
207 mText +="</table>"; 207 mText +="</table>";
208 mText += "</td></tr>\n<tr bgcolor=\"#6AFF6A\"><td>"; 208 mText += "</td></tr>\n<tr bgcolor=\"#6AFF6A\"><td>";
209 mText += "<table>"; 209 mText += "<table>";
210 time = 3; 210 time = 3;
211 } 211 }
212 mText +="<tr><td><b>"; 212 mText +="<tr><td><b>";
213 mText += timestr; 213 mText += timestr;
214 mText += "</b></td><td>"; 214 mText += "</b></td><td>";
215 mText += tempText; 215 mText += tempText;
216 mText += "</td></tr>\n"; 216 mText += "</td></tr>\n";
217 inc = getNextInc( start ); 217 inc = getNextInc( start );
218 } 218 }
219 mText +="</table>"; 219 mText +="</table>";
220 setText( mText ); 220 setText( mText );
221} 221}
222 222
223MissedAlarmTextBrowser::~MissedAlarmTextBrowser() 223MissedAlarmTextBrowser::~MissedAlarmTextBrowser()
224{ 224{
225 //qDebug("delete MissedAlarmTextBrowser::~MissedAlarmTextBrowser() "); 225 //qDebug("delete MissedAlarmTextBrowser::~MissedAlarmTextBrowser() ");
226} 226}
227Incidence * MissedAlarmTextBrowser::getNextInc( QDateTime start ) 227Incidence * MissedAlarmTextBrowser::getNextInc( QDateTime start )
228{ 228{
229 QDateTime dt ; 229 QDateTime dt ;
230 Incidence * retInc; 230 Incidence * retInc;
231 Incidence * inc = mAlarms.first(); 231 Incidence * inc = mAlarms.first();
232 if ( inc == 0 ) 232 if ( inc == 0 )
233 return 0; 233 return 0;
234 bool ok; 234 bool ok;
235 dt = inc->getNextOccurence( start, &ok ); 235 dt = inc->getNextOccurence( start, &ok );
236 if ( ! ok ) return 0; 236 if ( ! ok ) return 0;
237 QDateTime dtn ; 237 QDateTime dtn ;
238 retInc = inc; 238 retInc = inc;
239 inc = mAlarms.next(); 239 inc = mAlarms.next();
240 while ( inc ) { 240 while ( inc ) {
241 dtn = inc->getNextOccurence( start, &ok ); 241 dtn = inc->getNextOccurence( start, &ok );
242 if ( ! ok ) return 0; 242 if ( ! ok ) return 0;
243 if ( dtn < dt ) { 243 if ( dtn < dt ) {
244 dt = dtn; 244 dt = dtn;
245 retInc = inc; 245 retInc = inc;
246 } 246 }
247 inc = mAlarms.next(); 247 inc = mAlarms.next();
248 } 248 }
249 mAlarms.remove( retInc ); 249 mAlarms.remove( retInc );
250 return retInc; 250 return retInc;
251 251
252} 252}
253void MissedAlarmTextBrowser::setSource(const QString & n) 253void MissedAlarmTextBrowser::setSource(const QString & n)
254{ 254{
255 if (n.startsWith("event:")) { 255 if (n.startsWith("event:")) {
256#ifdef DESKTOP_VERSION 256#ifdef DESKTOP_VERSION
257 emit showIncidence(n.mid(8)); 257 emit showIncidence(n.mid(8));
258#else 258#else
259 emit showIncidence(n.mid(6)); 259 emit showIncidence(n.mid(6));
260#endif 260#endif
261 return; 261 return;
262 } else if (n.startsWith("todo:")) { 262 } else if (n.startsWith("todo:")) {
263#ifdef DESKTOP_VERSION 263#ifdef DESKTOP_VERSION
264 emit showIncidence(n.mid(7)); 264 emit showIncidence(n.mid(7));
265#else 265#else
266 emit showIncidence(n.mid(5)); 266 emit showIncidence(n.mid(5));
267#endif 267#endif
268 return; 268 return;
269 } 269 }
270} 270}
271 271
272 272
273class KOBeamPrefs : public QDialog 273class KOBeamPrefs : public QDialog
274{ 274{
275 public: 275 public:
276 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : 276 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) :
277 QDialog( parent, name, true ) 277 QDialog( parent, name, true )
278 { 278 {
279 setCaption( i18n("Beam Options") ); 279 setCaption( i18n("Beam Options") );
280 QVBoxLayout* lay = new QVBoxLayout( this ); 280 QVBoxLayout* lay = new QVBoxLayout( this );
281 lay->setSpacing( 3 ); 281 lay->setSpacing( 3 );
282 lay->setMargin( 3 ); 282 lay->setMargin( 3 );
283 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); 283 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this );
284 lay->addWidget( format ); 284 lay->addWidget( format );
285 format->setExclusive ( true ) ; 285 format->setExclusive ( true ) ;
286 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); 286 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this );
287 lay->addWidget( time ); time->setExclusive ( true ) ; 287 lay->addWidget( time ); time->setExclusive ( true ) ;
288 vcal = new QRadioButton(" vCalendar ", format ); 288 vcal = new QRadioButton(" vCalendar ", format );
289 ical = new QRadioButton(" iCalendar ", format ); 289 ical = new QRadioButton(" iCalendar ", format );
290 vcal->setChecked( true ); 290 vcal->setChecked( true );
291 tz = new QRadioButton(i18n(" With timezone "), time ); 291 tz = new QRadioButton(i18n(" With timezone "), time );
292 local = new QRadioButton(i18n(" Local time "), time ); 292 local = new QRadioButton(i18n(" Local time "), time );
293 tz->setChecked( true ); 293 tz->setChecked( true );
294 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); 294 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this );
295 lay->addWidget( ok ); 295 lay->addWidget( ok );
296 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 296 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
297 lay->addWidget( cancel ); 297 lay->addWidget( cancel );
298 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 298 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
299 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 299 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
300 resize( 200, 200 ); 300 resize( 200, 200 );
301 } 301 }
302 302
303 bool beamVcal() { return vcal->isChecked(); } 303 bool beamVcal() { return vcal->isChecked(); }
304 bool beamLocal() { return local->isChecked(); } 304 bool beamLocal() { return local->isChecked(); }
305private: 305private:
306 QRadioButton* vcal, *ical, *local, *tz; 306 QRadioButton* vcal, *ical, *local, *tz;
307}; 307};
308class KOCatPrefs : public QDialog 308class KOCatPrefs : public QDialog
309{ 309{
310 public: 310 public:
311 KOCatPrefs( QWidget *parent=0, const char *name=0 ) : 311 KOCatPrefs( QWidget *parent=0, const char *name=0 ) :
312 QDialog( parent, name, true ) 312 QDialog( parent, name, true )
313 { 313 {
314 setCaption( i18n("Manage new Categories") ); 314 setCaption( i18n("Manage new Categories") );
315 QVBoxLayout* lay = new QVBoxLayout( this ); 315 QVBoxLayout* lay = new QVBoxLayout( this );
316 lay->setSpacing( 3 ); 316 lay->setSpacing( 3 );
317 lay->setMargin( 3 ); 317 lay->setMargin( 3 );
318 QLabel * lab = new QLabel( i18n("After importing/loading/syncing there may be new categories in events or todos which are not added automatically to the category list. Please choose what to do <b>now</b>:"), this ); 318 QLabel * lab = new QLabel( i18n("After importing/loading/syncing there may be new categories in events or todos which are not added automatically to the category list. Please choose what to do <b>now</b>:"), this );
319 lay->addWidget( lab ); 319 lay->addWidget( lab );
320 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); 320 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this );
321 lay->addWidget( format ); 321 lay->addWidget( format );
322 format->setExclusive ( true ) ; 322 format->setExclusive ( true ) ;
323 addCatBut = new QRadioButton(i18n("Add to category list"), format ); 323 addCatBut = new QRadioButton(i18n("Add to category list"), format );
324 new QRadioButton(i18n("Remove from Events/Todos"), format ); 324 new QRadioButton(i18n("Remove from Events/Todos"), format );
325 addCatBut->setChecked( true ); 325 addCatBut->setChecked( true );
326 QPushButton * ok = new QPushButton( i18n("Change category list now!"), this ); 326 QPushButton * ok = new QPushButton( i18n("Change category list now!"), this );
327 lay->addWidget( ok ); 327 lay->addWidget( ok );
328 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 328 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
329 lay->addWidget( cancel ); 329 lay->addWidget( cancel );
330 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 330 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
331 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 331 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
332 resize( 200, 200 ); 332 resize( 200, 200 );
333 } 333 }
334 334
335 bool addCat() { return addCatBut->isChecked(); } 335 bool addCat() { return addCatBut->isChecked(); }
336private: 336private:
337 QRadioButton* addCatBut; 337 QRadioButton* addCatBut;
338}; 338};
339 339
340 340
341 341
342CalendarView::CalendarView( CalendarResources *calendar, 342CalendarView::CalendarView( CalendarResources *calendar,
343 QWidget *parent, const char *name ) 343 QWidget *parent, const char *name )
344 : CalendarViewBase( parent, name ), 344 : CalendarViewBase( parent, name ),
345 mCalendar( calendar ), 345 mCalendar( calendar ),
346 mResourceManager( calendar->resourceManager() ) 346 mResourceManager( calendar->resourceManager() )
347{ 347{
348 348
349 mEventEditor = 0; 349 mEventEditor = 0;
350 mTodoEditor = 0; 350 mTodoEditor = 0;
351 351
352 init(); 352 init();
353} 353}
354 354
355CalendarView::CalendarView( Calendar *calendar, 355CalendarView::CalendarView( Calendar *calendar,
356 QWidget *parent, const char *name ) 356 QWidget *parent, const char *name )
357 : CalendarViewBase( parent, name ), 357 : CalendarViewBase( parent, name ),
358 mCalendar( calendar ), 358 mCalendar( calendar ),
359 mResourceManager( 0 ) 359 mResourceManager( 0 )
360{ 360{
361 361
362 mEventEditor = 0; 362 mEventEditor = 0;
363 mTodoEditor = 0; 363 mTodoEditor = 0;
364 init(); 364 init();
365} 365}
366 366
367void CalendarView::init() 367void CalendarView::init()
368{ 368{
369 mNextAlarmDateTime = QDateTime::currentDateTime(); 369 mNextAlarmDateTime = QDateTime::currentDateTime();
370 //setFocusPolicy ( NoFocus ); 370 //setFocusPolicy ( NoFocus );
371 mViewerCallerIsSearchDialog = false; 371 mViewerCallerIsSearchDialog = false;
372 mBlockShowDates = false; 372 mBlockShowDates = false;
373 373
374 mDatePickerMode = 0; 374 mDatePickerMode = 0;
375 mCurrentSyncDevice = ""; 375 mCurrentSyncDevice = "";
376 mViewManager = new KOViewManager( this ); 376 mViewManager = new KOViewManager( this );
377 mDialogManager = new KODialogManager( this ); 377 mDialogManager = new KODialogManager( this );
378 mEventViewerDialog = 0; 378 mEventViewerDialog = 0;
379 mModified = false; 379 mModified = false;
380 mReadOnly = false; 380 mReadOnly = false;
381 mSelectedIncidence = 0; 381 mSelectedIncidence = 0;
382 mCalPrinter = 0; 382 mCalPrinter = 0;
383 mFilters.setAutoDelete(true); 383 mFilters.setAutoDelete(true);
384 384
385 mCalendar->registerObserver( this ); 385 mCalendar->registerObserver( this );
386 // TODO: Make sure that view is updated, when calendar is changed. 386 // TODO: Make sure that view is updated, when calendar is changed.
387 387
388 mStorage = new FileStorage( mCalendar ); 388 mStorage = new FileStorage( mCalendar );
389 mNavigator = new DateNavigator( this, "datevav", mViewManager ); 389 mNavigator = new DateNavigator( this, "datevav", mViewManager );
390 390
391 QBoxLayout *topLayout = (QBoxLayout*)layout(); 391 QBoxLayout *topLayout = (QBoxLayout*)layout();
392#ifndef KORG_NOSPLITTER 392#ifndef KORG_NOSPLITTER
393 // create the main layout frames. 393 // create the main layout frames.
394 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); 394 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner");
395 topLayout->addWidget(mPanner); 395 topLayout->addWidget(mPanner);
396 396
397 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, 397 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner,
398 "CalendarView::LeftFrame"); 398 "CalendarView::LeftFrame");
399 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); 399 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize);
400 400
401 mDateNavigator = new DateNavigatorContainer( mLeftSplitter, 401 mDateNavigator = new DateNavigatorContainer( mLeftSplitter,
402 "CalendarView::DateNavigator" ); 402 "CalendarView::DateNavigator" );
403 403
404 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); 404 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize);
405 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); 405 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2");
406 mTodoList->setNavigator( mNavigator ); 406 mTodoList->setNavigator( mNavigator );
407 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); 407 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView");
408 408
409#ifdef KORG_NORESOURCEVIEW 409#ifdef KORG_NORESOURCEVIEW
410 mResourceView = 0; 410 mResourceView = 0;
411#else 411#else
412 if ( mResourceManager ) { 412 if ( mResourceManager ) {
413 mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); 413 mResourceView = new ResourceView( mResourceManager, mLeftSplitter );
414 mResourceView->updateView(); 414 mResourceView->updateView();
415 connect( mResourceView, SIGNAL( resourcesChanged() ), 415 connect( mResourceView, SIGNAL( resourcesChanged() ),
416 SLOT( updateView() ) ); 416 SLOT( updateView() ) );
417 } else { 417 } else {
418 mResourceView = 0; 418 mResourceView = 0;
419 } 419 }
420#endif 420#endif
421 QWidget *rightBox = new QWidget( mPanner ); 421 QWidget *rightBox = new QWidget( mPanner );
422 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 422 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
423 423
424 mRightFrame = new QWidgetStack( rightBox ); 424 mRightFrame = new QWidgetStack( rightBox );
425 rightLayout->addWidget( mRightFrame, 1 ); 425 rightLayout->addWidget( mRightFrame, 1 );
426 426
427 mLeftFrame = mLeftSplitter; 427 mLeftFrame = mLeftSplitter;
428#else 428#else
429 //QWidget *mainBox = new QWidget( this ); 429 //QWidget *mainBox = new QWidget( this );
430 //QWidget *leftFrame = new QWidget( mainBox ); 430 //QWidget *leftFrame = new QWidget( mainBox );
431 //QBoxLayout * mainBoxLayout; 431 //QBoxLayout * mainBoxLayout;
432 if ( KOPrefs::instance()->mVerticalScreen ) { 432 if ( KOPrefs::instance()->mVerticalScreen ) {
433 //mainBoxLayout = new QVBoxLayout(mainBox); 433 //mainBoxLayout = new QVBoxLayout(mainBox);
434 //leftFrameLayout = new QHBoxLayout(leftFrame ); 434 //leftFrameLayout = new QHBoxLayout(leftFrame );
435 mMainFrame = new KDGanttMinimizeSplitter( Qt::Vertical, this ); 435 mMainFrame = new KDGanttMinimizeSplitter( Qt::Vertical, this );
436 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 436 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
437 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, mMainFrame);; 437 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, mMainFrame);;
438 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 438 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
439 } else { 439 } else {
440 //mainBoxLayout = new QHBoxLayout(mainBox); 440 //mainBoxLayout = new QHBoxLayout(mainBox);
441 //leftFrameLayout = new QVBoxLayout(leftFrame ); 441 //leftFrameLayout = new QVBoxLayout(leftFrame );
442 mMainFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 442 mMainFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
443 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Left); 443 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Left);
444 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Vertical, mMainFrame); 444 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Vertical, mMainFrame);
445 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 445 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
446 } 446 }
447 mMainFrame->setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) ); 447 mMainFrame->setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) );
448 //QBoxLayout * leftFrameLayout; 448 //QBoxLayout * leftFrameLayout;
449 topLayout->addWidget( mMainFrame ); 449 topLayout->addWidget( mMainFrame );
450#ifdef DESKTOP_VERSION 450#ifdef DESKTOP_VERSION
451 mDateScrollBar = new QScrollBar ( 1, 365, 1,30, 200,QScrollBar::Horizontal, this ); 451 mDateScrollBar = new QScrollBar ( 1, 365, 1,30, 200,QScrollBar::Horizontal, this );
452 topLayout->addWidget( mDateScrollBar ); 452 topLayout->addWidget( mDateScrollBar );
453 connect( mDateScrollBar, SIGNAL( valueChanged ( int ) ),this, SLOT( scrollBarValue( int )) ); 453 connect( mDateScrollBar, SIGNAL( valueChanged ( int ) ),this, SLOT( scrollBarValue( int )) );
454 if ( QApplication::desktop()->width() < 800 ) 454 if ( QApplication::desktop()->width() < 800 )
455 mDateScrollBar->hide(); 455 mDateScrollBar->hide();
456#endif 456#endif
457 //mainBoxLayout->addWidget (mLeftFrame); 457 //mainBoxLayout->addWidget (mLeftFrame);
458 mDateNavigator = new DateNavigatorContainer( mLeftFrame, 458 mDateNavigator = new DateNavigatorContainer( mLeftFrame,
459 "CalendarView::DateNavigator" ); 459 "CalendarView::DateNavigator" );
460#if 0 460#if 0
461 // FIXME 461 // FIXME
462 mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE, 462 mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE,
463 "CalendarView::DateNavigator", QDate::currentDate()); 463 "CalendarView::DateNavigator", QDate::currentDate());
464#endif 464#endif
465 // mDateNavigator->blockSignals( true ); 465 // mDateNavigator->blockSignals( true );
466 //leftFrameLayout->addWidget( mDateNavigator ); 466 //leftFrameLayout->addWidget( mDateNavigator );
467 mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall"); 467 mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall");
468 mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView"); 468 mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView");
469 mCalEditView = new KOCalEditView(mLeftFrame,"CalendarView::CaleditView"); 469 mCalEditView = new KOCalEditView(mLeftFrame,"CalendarView::CaleditView");
470 connect( mCalEditView, SIGNAL( calendarEnabled (int,bool) ),mCalendar, SLOT( setCalendarEnabled(int,bool)) ); 470 connect( mCalEditView, SIGNAL( calendarEnabled (int,bool) ),mCalendar, SLOT( setCalendarEnabled(int,bool)) );
471 connect( mCalEditView, SIGNAL( alarmEnabled(int,bool) ),mCalendar, SLOT( setAlarmEnabled(int,bool)) ); 471 connect( mCalEditView, SIGNAL( alarmEnabled(int,bool) ),mCalendar, SLOT( setAlarmEnabled(int,bool)) );
472 connect( mCalEditView, SIGNAL( calendarReadonly(int,bool) ),this, SLOT( setCalReadOnly(int,bool)) ); 472 connect( mCalEditView, SIGNAL( calendarReadonly(int,bool) ),this, SLOT( setCalReadOnly(int,bool)) );
473 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mCalendar, SLOT( setDefaultCalendar(int)) ); 473 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mCalendar, SLOT( setDefaultCalendar(int)) );
474 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mViewManager, SLOT( setDefaultCalendar(int)) ); 474 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mViewManager, SLOT( setDefaultCalendar(int)) );
475 connect( mCalEditView, SIGNAL( removeCalendar(int) ),mCalendar, SLOT( setCalendarRemove(int)) ); 475 connect( mCalEditView, SIGNAL( removeCalendar(int) ),mCalendar, SLOT( setCalendarRemove(int)) );
476 connect( mCalEditView, SIGNAL( calendarAdded(int) ),this, SLOT( addCalendarId(int)) ); 476 connect( mCalEditView, SIGNAL( calendarAdded(int) ),this, SLOT( addCalendarId(int)) );
477 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateView()) ); 477 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateView()) );
478 connect( mCalEditView, SIGNAL( checkCalendar() ),this, SLOT( checkFiles() )); 478 connect( mCalEditView, SIGNAL( checkCalendar() ),this, SLOT( checkFiles() ));
479 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateUnmanagedViews()) ); 479 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateUnmanagedViews()) );
480 480
481 mTodoList->setNavigator( mNavigator ); 481 mTodoList->setNavigator( mNavigator );
482#if 0 482#if 0
483 if ( QApplication::desktop()->width() < 480 ) { 483 if ( QApplication::desktop()->width() < 480 ) {
484 leftFrameLayout->addWidget(mFilterView); 484 leftFrameLayout->addWidget(mFilterView);
485 leftFrameLayout->addWidget(mTodoList, 2 ); 485 leftFrameLayout->addWidget(mTodoList, 2 );
486 486
487 } else { 487 } else {
488 leftFrameLayout->addWidget(mTodoList,2 ); 488 leftFrameLayout->addWidget(mTodoList,2 );
489 leftFrameLayout->addWidget(mFilterView ); 489 leftFrameLayout->addWidget(mFilterView );
490 } 490 }
491#endif 491#endif
492 mFilterView->hide(); 492 mFilterView->hide();
493 mCalEditView->hide(); 493 mCalEditView->hide();
494 QWidget *rightBox = new QWidget( mMainFrame ); 494 QWidget *rightBox = new QWidget( mMainFrame );
495 //mainBoxLayout->addWidget ( rightBox, 10 ); 495 //mainBoxLayout->addWidget ( rightBox, 10 );
496 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 496 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
497 mRightFrame = new QWidgetStack( rightBox ); 497 mRightFrame = new QWidgetStack( rightBox );
498 rightLayout->addWidget( mRightFrame, 10 ); 498 rightLayout->addWidget( mRightFrame, 10 );
499 499
500 //mLeftFrame = (QWidget *)leftFrame; 500 //mLeftFrame = (QWidget *)leftFrame;
501 if ( KOPrefs::instance()->mVerticalScreen ) { 501 if ( KOPrefs::instance()->mVerticalScreen ) {
502 //mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() ); 502 //mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() );
503 //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() ); 503 //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() );
504 //mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); 504 //mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() );
505 //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); 505 //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() );
506 } else { 506 } else {
507 //mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() ); 507 //mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() );
508 //mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); 508 //mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() );
509 //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); 509 //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() );
510 } 510 }
511 if ( !KOPrefs::instance()->mShowDateNavigator) 511 if ( !KOPrefs::instance()->mShowDateNavigator)
512 mDateNavigator->hide(); 512 mDateNavigator->hide();
513 //qDebug("Calendarview Size %d %d ", width(), height()); 513 //qDebug("Calendarview Size %d %d ", width(), height());
514#endif 514#endif
515 515
516 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 516 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
517 SLOT( showDates( const KCal::DateList & ) ) ); 517 SLOT( showDates( const KCal::DateList & ) ) );
518 518
519 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 519 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
520 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 520 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
521 521
522 522
523 523
524 connect( mDateNavigator, SIGNAL( showMonth( const QDate & ) ), 524 connect( mDateNavigator, SIGNAL( showMonth( const QDate & ) ),
525 mViewManager, SLOT( showMonth( const QDate & ) ) ); 525 mViewManager, SLOT( showMonth( const QDate & ) ) );
526 526
527 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), 527 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ),
528 mNavigator, SLOT( selectWeek( const QDate & ) ) ); 528 mNavigator, SLOT( selectWeek( const QDate & ) ) );
529 529
530 connect( mDateNavigator, SIGNAL( goPrevYear() ), 530 connect( mDateNavigator, SIGNAL( goPrevYear() ),
531 mNavigator, SLOT( selectPreviousYear() ) ); 531 mNavigator, SLOT( selectPreviousYear() ) );
532 connect( mDateNavigator, SIGNAL( goNextYear() ), 532 connect( mDateNavigator, SIGNAL( goNextYear() ),
533 mNavigator, SLOT( selectNextYear() ) ); 533 mNavigator, SLOT( selectNextYear() ) );
534 connect( mDateNavigator, SIGNAL( goPrevMonth() ), 534 connect( mDateNavigator, SIGNAL( goPrevMonth() ),
535 mNavigator, SLOT( selectPreviousMonth() ) ); 535 mNavigator, SLOT( selectPreviousMonth() ) );
536 connect( mDateNavigator, SIGNAL( goNextMonth() ), 536 connect( mDateNavigator, SIGNAL( goNextMonth() ),
537 mNavigator, SLOT( selectNextMonth() ) ); 537 mNavigator, SLOT( selectNextMonth() ) );
538 538
539 connect( mDateNavigator, SIGNAL( goPrevious() ), 539 connect( mDateNavigator, SIGNAL( goPrevious() ),
540 mNavigator, SLOT( selectPrevious() ) ); 540 mNavigator, SLOT( selectPrevious() ) );
541 connect( mDateNavigator, SIGNAL( goNext() ), 541 connect( mDateNavigator, SIGNAL( goNext() ),
542 mNavigator, SLOT( selectNext() ) ); 542 mNavigator, SLOT( selectNext() ) );
543 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), 543 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ),
544 mNavigator, SLOT( slotMonthSelect( int ) ) ); 544 mNavigator, SLOT( slotMonthSelect( int ) ) );
545 545
546 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 546 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
547 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 547 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
548#if 0 548#if 0
549 connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ), 549 connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ),
550 SLOT( incidenceAdded( Incidence *) ) ); 550 SLOT( incidenceAdded( Incidence *) ) );
551#endif 551#endif
552 // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); 552 // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView()));
553 553
554 connect( this, SIGNAL( configChanged() ), 554 connect( this, SIGNAL( configChanged() ),
555 mDateNavigator, SLOT( updateConfig() ) ); 555 mDateNavigator, SLOT( updateConfig() ) );
556 556
557 connect( mTodoList, SIGNAL( newTodoSignal() ), 557 connect( mTodoList, SIGNAL( newTodoSignal() ),
558 SLOT( newTodo() ) ); 558 SLOT( newTodo() ) );
559 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), 559 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ),
560 SLOT( newSubTodo( Todo * ) ) ); 560 SLOT( newSubTodo( Todo * ) ) );
561 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), 561 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ),
562 SLOT( editTodo( Todo * ) ) ); 562 SLOT( editTodo( Todo * ) ) );
563 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), 563 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ),
564 SLOT( showTodo( Todo *) ) ); 564 SLOT( showTodo( Todo *) ) );
565 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), 565 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ),
566 SLOT( deleteTodo( Todo *) ) ); 566 SLOT( deleteTodo( Todo *) ) );
567 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); 567 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) );
568 connect( mTodoList, SIGNAL( purgeCompletedSignal() ), 568 connect( mTodoList, SIGNAL( purgeCompletedSignal() ),
569 SLOT( purgeCompleted() ) ); 569 SLOT( purgeCompleted() ) );
570 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), 570 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ),
571 SIGNAL( todoModified( Todo *, int ) ) ); 571 SIGNAL( todoModified( Todo *, int ) ) );
572 572
573 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), 573 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ),
574 this, SLOT ( cloneIncidence( Incidence * ) ) ); 574 this, SLOT ( cloneIncidence( Incidence * ) ) );
575 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), 575 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ),
576 this, SLOT (cancelIncidence( Incidence * ) ) ); 576 this, SLOT (cancelIncidence( Incidence * ) ) );
577 577
578 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), 578 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ),
579 this, SLOT ( moveIncidence( Incidence * ) ) ); 579 this, SLOT ( moveIncidence( Incidence * ) ) );
580 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), 580 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ),
581 this, SLOT ( beamIncidence( Incidence * ) ) ); 581 this, SLOT ( beamIncidence( Incidence * ) ) );
582 582
583 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), 583 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ),
584 this, SLOT ( todo_unsub( Todo * ) ) ); 584 this, SLOT ( todo_unsub( Todo * ) ) );
585 585
586 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), 586 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ),
587 this, SLOT ( todo_resub( Todo *,Todo * ) ) ); 587 this, SLOT ( todo_resub( Todo *,Todo * ) ) );
588 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, 588 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList,
589 SLOT( updateTodo( Todo *, int ) ) ); 589 SLOT( updateTodo( Todo *, int ) ) );
590 connect( this, SIGNAL( todoModified( Todo *, int )), this, 590 connect( this, SIGNAL( todoModified( Todo *, int )), this,
591 SLOT( changeTodoDisplay( Todo *, int ) ) ); 591 SLOT( changeTodoDisplay( Todo *, int ) ) );
592 592
593 593
594 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); 594 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) );
595 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); 595 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) );
596 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); 596 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) );
597 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); 597 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) );
598 598
599 599
600 600
601 601
602 602
603 connect(QApplication::clipboard(),SIGNAL(dataChanged()), 603 connect(QApplication::clipboard(),SIGNAL(dataChanged()),
604 SLOT(checkClipboard())); 604 SLOT(checkClipboard()));
605 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), 605 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ),
606 SLOT( processTodoListSelection( Incidence * ) ) ); 606 SLOT( processTodoListSelection( Incidence * ) ) );
607 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); 607 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
608 608
609 // kdDebug() << "CalendarView::CalendarView() done" << endl; 609 // kdDebug() << "CalendarView::CalendarView() done" << endl;
610 610
611 mDateFrame = new QVBox(0,0,WType_Popup); 611 mDateFrame = new QVBox(0,0,WType_Popup);
612 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 612 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
613 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 613 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
614 mDateFrame->setLineWidth(3); 614 mDateFrame->setLineWidth(3);
615 mDateFrame->hide(); 615 mDateFrame->hide();
616 mDateFrame->setCaption( i18n( "Pick a date to display")); 616 mDateFrame->setCaption( i18n( "Pick a date to display"));
617 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); 617 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() );
618 618
619 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); 619 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate)));
620 620
621 mEventEditor = mDialogManager->getEventEditor(); 621 mEventEditor = mDialogManager->getEventEditor();
622 mTodoEditor = mDialogManager->getTodoEditor(); 622 mTodoEditor = mDialogManager->getTodoEditor();
623 623
624 mFlagEditDescription = false; 624 mFlagEditDescription = false;
625 625
626 mSuspendTimer = new QTimer( this ); 626 mSuspendTimer = new QTimer( this );
627 mAlarmTimer = new QTimer( this ); 627 mAlarmTimer = new QTimer( this );
628 mRecheckAlarmTimer = new QTimer( this ); 628 mRecheckAlarmTimer = new QTimer( this );
629 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); 629 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) );
630 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 630 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
631 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 631 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
632 mAlarmDialog = new AlarmDialog( this ); 632 mAlarmDialog = new AlarmDialog( this );
633 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 633 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
634 mAlarmDialog->setServerNotification( false ); 634 mAlarmDialog->setServerNotification( false );
635 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 635 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
636 636
637 637
638#ifndef DESKTOP_VERSION 638#ifndef DESKTOP_VERSION
639//US listen for arriving address resultsets 639//US listen for arriving address resultsets
640 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), 640 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)),
641 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); 641 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)));
642#endif 642#endif
643 mDateNavigator->setCalendar( mCalendar ); 643 mDateNavigator->setCalendar( mCalendar );
644} 644}
645 645
646 646
647CalendarView::~CalendarView() 647CalendarView::~CalendarView()
648{ 648{
649 // kdDebug() << "~CalendarView()" << endl; 649 // kdDebug() << "~CalendarView()" << endl;
650 //qDebug("CalendarView::~CalendarView() "); 650 //qDebug("CalendarView::~CalendarView() ");
651 delete mDialogManager; 651 delete mDialogManager;
652 delete mViewManager; 652 delete mViewManager;
653 delete mStorage; 653 delete mStorage;
654 delete mDateFrame ; 654 delete mDateFrame ;
655 delete mEventViewerDialog; 655 delete mEventViewerDialog;
656 //kdDebug() << "~CalendarView() done" << endl; 656 //kdDebug() << "~CalendarView() done" << endl;
657} 657}
658void CalendarView::nextConflict( bool all, bool allday ) 658void CalendarView::nextConflict( bool all, bool allday )
659{ 659{
660 660
661 QPtrList<Event> testlist = mCalendar->events(); 661 QPtrList<Event> testlist = mCalendar->events();
662 Event * test = testlist.first(); 662 Event * test = testlist.first();
663 while ( test ) { 663 while ( test ) {
664 test->setTagged( false ); 664 test->setTagged( false );
665 test = testlist.next(); 665 test = testlist.next();
666 } 666 }
667 QTime st ( 0,0,0); 667 QTime st ( 0,0,0);
668 if ( mViewManager->currentView() == mViewManager->agendaView() ) 668 if ( mViewManager->currentView() == mViewManager->agendaView() )
669 st = mViewManager->agendaView()->agenda()->getEndTime(); 669 st = mViewManager->agendaView()->agenda()->getEndTime();
670 //qDebug("time %s ", st.toString().latin1()); 670 //qDebug("time %s ", st.toString().latin1());
671 QDateTime startDT = QDateTime (mNavigator->selectedDates().first(),st); 671 QDateTime startDT = QDateTime (mNavigator->selectedDates().first(),st);
672 QDateTime conflict; 672 QDateTime conflict;
673 QDateTime retVal; 673 QDateTime retVal;
674 bool found = false; 674 bool found = false;
675 Event * cE = 0; 675 Event * cE = 0;
676 Event * cE2 = 0; 676 Event * cE2 = 0;
677 QPtrList<Event> testlist2 = testlist; 677 QPtrList<Event> testlist2 = testlist;
678 test = testlist.first(); 678 test = testlist.first();
679 bool skip = false; 679 bool skip = false;
680 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); 680 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") );
681 while ( test ) { 681 while ( test ) {
682 qApp->processEvents(); 682 qApp->processEvents();
683 skip = false; 683 skip = false;
684 if ( !all ) skip = ( allday != test->doesFloat() ); 684 if ( !all ) skip = ( allday != test->doesFloat() );
685 if ( !skip ) { 685 if ( !skip ) {
686 Event * test2 = testlist2.first(); 686 Event * test2 = testlist2.first();
687 while ( test2 ) { 687 while ( test2 ) {
688 skip = false; 688 skip = false;
689 if ( !all ) skip = ( allday != test2->doesFloat() ); 689 if ( !all ) skip = ( allday != test2->doesFloat() );
690 if ( !skip ) { 690 if ( !skip ) {
691 if ( !test2->isTagged() ) { 691 if ( !test2->isTagged() ) {
692 if ( test->isOverlapping ( test2, &retVal, &startDT ) ) { 692 if ( test->isOverlapping ( test2, &retVal, &startDT ) ) {
693 //qDebug("overlap "); 693 //qDebug("overlap ");
694 if ( ! found ) { 694 if ( ! found ) {
695 if ( retVal >= startDT ) { 695 if ( retVal >= startDT ) {
696 conflict = retVal; 696 conflict = retVal;
697 cE = test; 697 cE = test;
698 cE2 = test2; 698 cE2 = test2;
699 found = true; 699 found = true;
700 } 700 }
701 } else { 701 } else {
702 if ( retVal >= startDT && retVal < conflict ) { 702 if ( retVal >= startDT && retVal < conflict ) {
703 conflict = retVal; 703 conflict = retVal;
704 cE = test; 704 cE = test;
705 cE2 = test2; 705 cE2 = test2;
706 } 706 }
707 } 707 }
708 } 708 }
709 } 709 }
710 } 710 }
711 test2 = testlist2.next(); 711 test2 = testlist2.next();
712 } 712 }
713 } 713 }
714 test->setTagged( true ); 714 test->setTagged( true );
715 test = testlist.next(); 715 test = testlist.next();
716 } 716 }
717 if ( found ) { 717 if ( found ) {
718 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) 718 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 )
719 mViewManager->showDayView(); 719 mViewManager->showDayView();
720 mNavigator->slotDaySelect( conflict.date() ); 720 mNavigator->slotDaySelect( conflict.date() );
721 int hour = conflict.time().hour(); 721 int hour = conflict.time().hour();
722 mViewManager->agendaView()->setStartHour( hour ); 722 mViewManager->agendaView()->setStartHour( hour );
723 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( cE->summary().left( 20 ) ).arg( cE2->summary().left( 20 ) ) ); 723 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( cE->summary().left( 20 ) ).arg( cE2->summary().left( 20 ) ) );
724 return; 724 return;
725 } 725 }
726 726
727 topLevelWidget()->setCaption( i18n("No conflict found") ); 727 topLevelWidget()->setCaption( i18n("No conflict found") );
728 qDebug("No conflict found "); 728 qDebug("No conflict found ");
729 return; 729 return;
730} 730}
731 731
732void CalendarView::conflictAll() 732void CalendarView::conflictAll()
733{ 733{
734 nextConflict ( true, true ); 734 nextConflict ( true, true );
735} 735}
736void CalendarView::conflictAllday() 736void CalendarView::conflictAllday()
737{ 737{
738 nextConflict ( false, true ); 738 nextConflict ( false, true );
739} 739}
740void CalendarView::conflictNotAll() 740void CalendarView::conflictNotAll()
741{ 741{
742 nextConflict ( false, false ); 742 nextConflict ( false, false );
743} 743}
744 744
745void CalendarView::setCalReadOnly( int id, bool readO ) 745void CalendarView::setCalReadOnly( int id, bool readO )
746{ 746{
747 if ( readO ) { 747 if ( readO ) {
748 emit save(); 748 emit save();
749 } 749 }
750 mCalendar->setReadOnly( id, readO ); 750 mCalendar->setReadOnly( id, readO );
751} 751}
752void CalendarView::setScrollBarStep(int val ) 752void CalendarView::setScrollBarStep(int val )
753{ 753{
754#ifdef DESKTOP_VERSION 754#ifdef DESKTOP_VERSION
755 mDateScrollBar->setLineStep ( val ); 755 mDateScrollBar->setLineStep ( val );
756#endif 756#endif
757} 757}
758void CalendarView::scrollBarValue(int val ) 758void CalendarView::scrollBarValue(int val )
759{ 759{
760#ifdef DESKTOP_VERSION 760#ifdef DESKTOP_VERSION
761 if ( QApplication::desktop()->width() < 800 ) return; 761 if ( QApplication::desktop()->width() < 800 ) return;
762 static bool block = false; 762 static bool block = false;
763 if ( block ) return; 763 if ( block ) return;
764 block = true; 764 block = true;
765 int count = mNavigator->selectedDates().count(); 765 int count = mNavigator->selectedDates().count();
766 int day = mNavigator->selectedDates().first().dayOfYear(); 766 int day = mNavigator->selectedDates().first().dayOfYear();
767 int stepdays = val; 767 int stepdays = val;
768 if ( mDateScrollBar->lineStep () <= count ) { 768 if ( mDateScrollBar->lineStep () <= count ) {
769 //val = val/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); 769 //val = val/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep();
770 //qDebug("VAL %d ",val ); 770 //qDebug("VAL %d ",val );
771 stepdays = (val-day)/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); 771 stepdays = (val-day)/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep();
772 stepdays = day+stepdays; 772 stepdays = day+stepdays;
773 if ( stepdays < 0 ) stepdays = 0; 773 if ( stepdays < 0 ) stepdays = 0;
774 } 774 }
775 if ( stepdays == day ) { 775 if ( stepdays == day ) {
776 block = false; 776 block = false;
777 return; 777 return;
778 } 778 }
779 int year = mNavigator->selectedDates().first().year(); 779 int year = mNavigator->selectedDates().first().year();
780 QDate d ( year,1,1 ); 780 QDate d ( year,1,1 );
781 mNavigator->selectDates( d.addDays( stepdays-1) , count ); 781 mNavigator->selectDates( d.addDays( stepdays-1) , count );
782 block = false; 782 block = false;
783#endif 783#endif
784 784
785} 785}
786void CalendarView::updateView(const QDate &start, const QDate &end) 786void CalendarView::updateView(const QDate &start, const QDate &end)
787{ 787{
788#ifdef DESKTOP_VERSION 788#ifdef DESKTOP_VERSION
789 if ( ! mDateScrollBar->draggingSlider () ) { 789 if ( ! mDateScrollBar->draggingSlider () ) {
790 int dof = start.dayOfYear(); 790 int dof = start.dayOfYear();
791 //qDebug("dof %d day %d val %d ", dof, start.dayOfYear(),mDateScrollBar->value() ); 791 //qDebug("dof %d day %d val %d ", dof, start.dayOfYear(),mDateScrollBar->value() );
792 if ( dof != mDateScrollBar->value() ) { 792 if ( dof != mDateScrollBar->value() ) {
793 mDateScrollBar->blockSignals( true ); 793 mDateScrollBar->blockSignals( true );
794 mDateScrollBar->setValue( start.dayOfYear()); 794 mDateScrollBar->setValue( start.dayOfYear());
795 mDateScrollBar->blockSignals( false ); 795 mDateScrollBar->blockSignals( false );
796 } 796 }
797 } 797 }
798#endif 798#endif
799 mTodoList->updateView(); 799 mTodoList->updateView();
800 mViewManager->updateView(start, end); 800 mViewManager->updateView(start, end);
801 //mDateNavigator->updateView(); 801 //mDateNavigator->updateView();
802} 802}
803 803
804 804
805 805
806void CalendarView::checkFiles() 806void CalendarView::checkFiles()
807{ 807{
808 QString message; 808 QString message;
809 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 809 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
810 KopiCalendarFile * cal = calendars.first(); 810 KopiCalendarFile * cal = calendars.first();
811 while ( cal ) { 811 while ( cal ) {
812 if ( cal->mErrorOnLoad ) { 812 if ( cal->mErrorOnLoad ) {
813 message += cal->mName +"\n"+KGlobal::formatMessage ( "(" +i18n( "Filepath: ")+ cal->mFileName+")" ,0 )+"\n"; 813 message += cal->mName +"\n"+KGlobal::formatMessage ( "(" +i18n( "Filepath: ")+ cal->mFileName+")" ,0 )+"\n";
814 } 814 }
815 cal = calendars.next(); 815 cal = calendars.next();
816 } 816 }
817 if ( !message.isEmpty() ) { 817 if ( !message.isEmpty() ) {
818 message = KGlobal::formatMessage( i18n("Calendar(s) not loaded:"),0 )+"\n" + message +KGlobal::formatMessage(i18n("You can try to reload the calendar in the Resource View!"),0); 818 message = KGlobal::formatMessage( i18n("Calendar(s) not loaded:"),0 )+"\n" + message +KGlobal::formatMessage(i18n("You can try to reload the calendar in the Resource View!"),0);
819 KMessageBox::error(this,message, i18n("Loding of calendar(s) failed")); 819 KMessageBox::error(this,message, i18n("Loding of calendar(s) failed"));
820 } 820 }
821 QTimer::singleShot( 2000, this, SLOT ( checkAlarms() )); 821 QTimer::singleShot( 2000, this, SLOT ( checkAlarms() ));
822} 822}
823void CalendarView::checkAlarms() 823void CalendarView::checkAlarms()
824{ 824{
825 825
826 826
827 KConfig *config = KOGlobals::config(); 827 KConfig *config = KOGlobals::config();
828 config->setGroup( "AppRun" ); 828 config->setGroup( "AppRun" );
829 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 829 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
830 int daysto = dt.daysTo( QDate::currentDate() ); 830 int daysto = dt.daysTo( QDate::currentDate() );
831 int days = config->readNumEntry( "LatestProgramStopDays" , daysto); 831 int days = config->readNumEntry( "LatestProgramStopDays" , daysto);
832 dt = dt.addDays( days ); 832 dt = dt.addDays( days );
833 int secto = dt.secsTo( QDateTime::currentDateTime() ); 833 int secto = dt.secsTo( QDateTime::currentDateTime() );
834 int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30; 834 int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30;
835 //qDebug("KO: Reading program stop %d ", secs); 835 //qDebug("KO: Reading program stop %d ", secs);
836 //secs -= ( 3600 * 24*3 ); // debug only 836 //secs -= ( 3600 * 24*3 ); // debug only
837 QDateTime latest = dt.addSecs ( secs ); 837 QDateTime latest = dt.addSecs ( secs );
838 qDebug("KO: Last termination on %s ", latest.toString().latin1()); 838 qDebug("KO: Last termination on %s ", latest.toString().latin1());
839 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 839 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
840 QPtrList<Incidence> el = mCalendar->rawIncidences(); 840 QPtrList<Incidence> el = mCalendar->rawIncidences();
841 QPtrList<Incidence> al; 841 QPtrList<Incidence> al;
842 Incidence* inL = el.first(); 842 Incidence* inL = el.first();
843 QDateTime cur = QDateTime::currentDateTime().addSecs(-59); 843 QDateTime cur = QDateTime::currentDateTime().addSecs(-59);
844 qDebug("KO: Checking alarm until %s ", cur.toString().latin1()); 844 qDebug("KO: Checking alarm until %s ", cur.toString().latin1());
845 while ( inL ) { 845 while ( inL ) {
846 bool ok = false; 846 bool ok = false;
847 int offset = 0; 847 int offset = 0;
848 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ; 848 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ;
849 if ( ok ) { 849 if ( ok ) {
850 //qDebug("OK %s",next.toString().latin1()); 850 //qDebug("OK %s",next.toString().latin1());
851 if ( next < cur ) { 851 if ( next < cur ) {
852 al.append( inL ); 852 al.append( inL );
853 //qDebug("found missed alarm: %s ", inL->summary().latin1() ); 853 //qDebug("found missed alarm: %s ", inL->summary().latin1() );
854 } 854 }
855 } 855 }
856 inL = el.next(); 856 inL = el.next();
857 } 857 }
858 if ( al.count() ) { 858 if ( al.count() ) {
859 QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop ); 859 QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop );
860 dia->setCaption( i18n("KO/Pi: Missing alarms!") ); 860 dia->setCaption( i18n("KO/Pi: Missing alarms!") );
861 QVBoxLayout* lay = new QVBoxLayout( dia ); 861 QVBoxLayout* lay = new QVBoxLayout( dia );
862 lay->setSpacing( 0 ); 862 lay->setSpacing( 0 );
863 lay->setMargin( 0 ); 863 lay->setMargin( 0 );
864 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest ); 864 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest );
865 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); 865 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) ));
866 lay->addWidget( matb ); 866 lay->addWidget( matb );
867 if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) { 867 if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) {
868 int wid = 210; 868 int wid = 210;
869 int x = QApplication::desktop()->width() - wid - 7; 869 int x = QApplication::desktop()->width() - wid - 7;
870 int y = QApplication::desktop()->height() - wid - 70; 870 int y = QApplication::desktop()->height() - wid - 70;
871 dia->setGeometry ( x,y,wid,wid); 871 dia->setGeometry ( x,y,wid,wid);
872 } else { 872 } else {
873 int si = 220; 873 int si = 220;
874 if ( QApplication::desktop()->width() > 470 ) 874 if ( QApplication::desktop()->width() > 470 )
875 si = 400; 875 si = 400;
876 dia->resize(si,si/2); 876 dia->resize(si,si/2);
877 } 877 }
878 dia->setBackgroundColor( QColor( 255, 255, 255 ) ); 878 dia->setBackgroundColor( QColor( 255, 255, 255 ) );
879 dia->show(); 879 dia->show();
880 880
881 } 881 }
882} 882}
883void CalendarView::showDay( QDate d ) 883void CalendarView::showDay( QDate d )
884{ 884{
885 dateNavigator()->blockSignals( true ); 885 dateNavigator()->blockSignals( true );
886 dateNavigator()->selectDate( d ); 886 dateNavigator()->selectDate( d );
887 dateNavigator()->blockSignals( false ); 887 dateNavigator()->blockSignals( false );
888 mViewManager->showDayView(); 888 mViewManager->showDayView();
889 //dateNavigator()->selectDate( d ); 889 //dateNavigator()->selectDate( d );
890} 890}
891void CalendarView::timerAlarm() 891void CalendarView::timerAlarm()
892{ 892{
893 //qDebug("CalendarView::timerAlarm() "); 893 //qDebug("CalendarView::timerAlarm() ");
894 computeAlarm(mAlarmNotification ); 894 computeAlarm(mAlarmNotification );
895} 895}
896 896
897void CalendarView::suspendAlarm() 897void CalendarView::suspendAlarm()
898{ 898{
899 //qDebug(" CalendarView::suspendAlarm() "); 899 //qDebug(" CalendarView::suspendAlarm() ");
900 computeAlarm(mSuspendAlarmNotification ); 900 computeAlarm(mSuspendAlarmNotification );
901 901
902} 902}
903 903
904void CalendarView::startAlarm( QString mess , QString filename) 904void CalendarView::startAlarm( QString mess , QString filename)
905{ 905{
906 906
907 topLevelWidget()->showNormal(); 907 topLevelWidget()->showNormal();
908 topLevelWidget()->setActiveWindow(); 908 topLevelWidget()->setActiveWindow();
909 topLevelWidget()->raise(); 909 topLevelWidget()->raise();
910 910
911 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 911 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
912 QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) ); 912 QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) );
913 913
914} 914}
915 915
916void CalendarView::checkNextTimerAlarm() 916void CalendarView::checkNextTimerAlarm()
917{ 917{
918 mCalendar->checkAlarmForIncidence( 0, true ); 918 mCalendar->checkAlarmForIncidence( 0, true );
919} 919}
920 920
921void CalendarView::computeAlarm( QString msg ) 921void CalendarView::computeAlarm( QString msg )
922{ 922{
923 923
924 QString mess = msg; 924 QString mess = msg;
925 QString mAlarmMessage = mess.mid( 9 ); 925 QString mAlarmMessage = mess.mid( 9 );
926 QString filename = MainWindow::resourcePath(); 926 QString filename = MainWindow::resourcePath();
927 filename += "koalarm.wav"; 927 filename += "koalarm.wav";
928 QString tempfilename; 928 QString tempfilename;
929 if ( mess.left( 13 ) == "suspend_alarm") { 929 if ( mess.left( 13 ) == "suspend_alarm") {
930 bool error = false; 930 bool error = false;
931 int len = mess.mid( 13 ).find("+++"); 931 int len = mess.mid( 13 ).find("+++");
932 if ( len < 2 ) 932 if ( len < 2 )
933 error = true; 933 error = true;
934 else { 934 else {
935 tempfilename = mess.mid( 13, len ); 935 tempfilename = mess.mid( 13, len );
936 if ( !QFile::exists( tempfilename ) ) 936 if ( !QFile::exists( tempfilename ) )
937 error = true; 937 error = true;
938 } 938 }
939 if ( ! error ) { 939 if ( ! error ) {
940 filename = tempfilename; 940 filename = tempfilename;
941 } 941 }
942 mAlarmMessage = mess.mid( 13+len+3 ); 942 mAlarmMessage = mess.mid( 13+len+3 );
943 //qDebug("suspend file %s ",tempfilename.latin1() ); 943 //qDebug("suspend file %s ",tempfilename.latin1() );
944 startAlarm( mAlarmMessage, filename); 944 startAlarm( mAlarmMessage, filename);
945 return; 945 return;
946 } 946 }
947 if ( mess.left( 11 ) == "timer_alarm") { 947 if ( mess.left( 11 ) == "timer_alarm") {
948 //mTimerTime = 0; 948 //mTimerTime = 0;
949 startAlarm( mess.mid( 11 ), filename ); 949 startAlarm( mess.mid( 11 ), filename );
950 return; 950 return;
951 } 951 }
952 if ( mess.left( 10 ) == "proc_alarm") { 952 if ( mess.left( 10 ) == "proc_alarm") {
953 bool error = false; 953 bool error = false;
954 int len = mess.mid( 10 ).find("+++"); 954 int len = mess.mid( 10 ).find("+++");
955 if ( len < 2 ) 955 if ( len < 2 )
956 error = true; 956 error = true;
957 else { 957 else {
958 tempfilename = mess.mid( 10, len ); 958 tempfilename = mess.mid( 10, len );
959 if ( !QFile::exists( tempfilename ) ) 959 if ( !QFile::exists( tempfilename ) )
960 error = true; 960 error = true;
961 } 961 }
962 if ( error ) { 962 if ( error ) {
963 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 963 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
964 mAlarmMessage += mess.mid( 10+len+3+9 ); 964 mAlarmMessage += mess.mid( 10+len+3+9 );
965 } else { 965 } else {
966 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 966 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
967 //qDebug("-----system command %s ",tempfilename.latin1() ); 967 //qDebug("-----system command %s ",tempfilename.latin1() );
968#ifndef _WIN32_ 968#ifndef _WIN32_
969 if ( vfork () == 0 ) { 969 if ( vfork () == 0 ) {
970 execl ( tempfilename.latin1(), 0 ); 970 execl ( tempfilename.latin1(), 0 );
971 return; 971 return;
972 } 972 }
973#else 973#else
974 QProcess* p = new QProcess(); 974 QProcess* p = new QProcess();
975 p->addArgument( tempfilename.latin1() ); 975 p->addArgument( tempfilename.latin1() );
976 p->start(); 976 p->start();
977 return; 977 return;
978#endif 978#endif
979 979
980 return; 980 return;
981 } 981 }
982 982
983 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 983 //qDebug("+++++++system command %s ",tempfilename.latin1() );
984 } 984 }
985 if ( mess.left( 11 ) == "audio_alarm") { 985 if ( mess.left( 11 ) == "audio_alarm") {
986 bool error = false; 986 bool error = false;
987 int len = mess.mid( 11 ).find("+++"); 987 int len = mess.mid( 11 ).find("+++");
988 if ( len < 2 ) 988 if ( len < 2 )
989 error = true; 989 error = true;
990 else { 990 else {
991 tempfilename = mess.mid( 11, len ); 991 tempfilename = mess.mid( 11, len );
992 if ( !QFile::exists( tempfilename ) ) 992 if ( !QFile::exists( tempfilename ) )
993 error = true; 993 error = true;
994 } 994 }
995 if ( ! error ) { 995 if ( ! error ) {
996 filename = tempfilename; 996 filename = tempfilename;
997 } 997 }
998 mAlarmMessage = mess.mid( 11+len+3+9 ); 998 mAlarmMessage = mess.mid( 11+len+3+9 );
999 //qDebug("audio file command %s ",tempfilename.latin1() ); 999 //qDebug("audio file command %s ",tempfilename.latin1() );
1000 } 1000 }
1001 if ( mess.left( 9 ) == "cal_alarm") { 1001 if ( mess.left( 9 ) == "cal_alarm") {
1002 mAlarmMessage = mess.mid( 9 ) ; 1002 mAlarmMessage = mess.mid( 9 ) ;
1003 } 1003 }
1004 1004
1005 startAlarm( mAlarmMessage, filename ); 1005 startAlarm( mAlarmMessage, filename );
1006 1006
1007 1007
1008} 1008}
1009 1009
1010void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 1010void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
1011{ 1011{
1012 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1012 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1013 1013
1014 mSuspendAlarmNotification = noti; 1014 mSuspendAlarmNotification = noti;
1015 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 1015 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
1016 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 1016 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
1017 mSuspendTimer->start( ms , true ); 1017 mSuspendTimer->start( ms , true );
1018 1018
1019} 1019}
1020 1020
1021void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 1021void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
1022{ 1022{
1023 mNextAlarmDateTime = qdt; 1023 mNextAlarmDateTime = qdt;
1024 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1024 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1025 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 1025 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
1026#ifndef DESKTOP_VERSION 1026#ifndef DESKTOP_VERSION
1027 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() ); 1027 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() );
1028#endif 1028#endif
1029 return; 1029 return;
1030 } 1030 }
1031 int maxSec; 1031 int maxSec;
1032 //maxSec = 5; //testing only 1032 //maxSec = 5; //testing only
1033 maxSec = 86400+3600; // one day+1hour 1033 maxSec = 86400+3600; // one day+1hour
1034 mAlarmNotification = noti; 1034 mAlarmNotification = noti;
1035 int sec = QDateTime::currentDateTime().secsTo( qdt ); 1035 int sec = QDateTime::currentDateTime().secsTo( qdt );
1036 if ( sec > maxSec ) { 1036 if ( sec > maxSec ) {
1037 mRecheckAlarmTimer->start( maxSec * 1000 ); 1037 mRecheckAlarmTimer->start( maxSec * 1000 );
1038 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 1038 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
1039 return; 1039 return;
1040 } else { 1040 } else {
1041 mRecheckAlarmTimer->stop(); 1041 mRecheckAlarmTimer->stop();
1042 } 1042 }
1043 //qDebug("Alarm timer started with secs: %d ", sec); 1043 //qDebug("Alarm timer started with secs: %d ", sec);
1044 mAlarmTimer->start( sec *1000 , true ); 1044 mAlarmTimer->start( sec *1000 , true );
1045 1045
1046} 1046}
1047// called by mRecheckAlarmTimer to get next alarm 1047// called by mRecheckAlarmTimer to get next alarm
1048// we need this, because a QTimer has only a max range of 25 days 1048// we need this, because a QTimer has only a max range of 25 days
1049void CalendarView::recheckTimerAlarm() 1049void CalendarView::recheckTimerAlarm()
1050{ 1050{
1051 mAlarmTimer->stop(); 1051 mAlarmTimer->stop();
1052 mRecheckAlarmTimer->stop(); 1052 mRecheckAlarmTimer->stop();
1053 mCalendar->checkAlarmForIncidence( 0, true ); 1053 mCalendar->checkAlarmForIncidence( 0, true );
1054} 1054}
1055#ifndef DESKTOP_VERSION 1055#ifndef DESKTOP_VERSION
1056void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 1056void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
1057#else 1057#else
1058void CalendarView::removeAlarm(const QDateTime &, const QString & ) 1058void CalendarView::removeAlarm(const QDateTime &, const QString & )
1059#endif 1059#endif
1060{ 1060{
1061 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1061 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1062 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 1062 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
1063#ifndef DESKTOP_VERSION 1063#ifndef DESKTOP_VERSION
1064 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() ); 1064 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() );
1065#endif 1065#endif
1066 return; 1066 return;
1067 } 1067 }
1068 mAlarmTimer->stop(); 1068 mAlarmTimer->stop();
1069} 1069}
1070void CalendarView::selectWeekNum ( int num ) 1070void CalendarView::selectWeekNum ( int num )
1071{ 1071{
1072 dateNavigator()->blockSignals( true ); 1072 dateNavigator()->blockSignals( true );
1073 dateNavigator()->selectWeek( num ); 1073 dateNavigator()->selectWeek( num );
1074 dateNavigator()->blockSignals( false ); 1074 dateNavigator()->blockSignals( false );
1075 mViewManager->showWeekView(); 1075 mViewManager->showWeekView();
1076} 1076}
1077KOViewManager *CalendarView::viewManager() 1077KOViewManager *CalendarView::viewManager()
1078{ 1078{
1079 return mViewManager; 1079 return mViewManager;
1080} 1080}
1081 1081
1082KODialogManager *CalendarView::dialogManager() 1082KODialogManager *CalendarView::dialogManager()
1083{ 1083{
1084 return mDialogManager; 1084 return mDialogManager;
1085} 1085}
1086 1086
1087QDate CalendarView::startDate() 1087QDate CalendarView::startDate()
1088{ 1088{
1089 DateList dates = mNavigator->selectedDates(); 1089 DateList dates = mNavigator->selectedDates();
1090 1090
1091 return dates.first(); 1091 return dates.first();
1092} 1092}
1093 1093
1094QDate CalendarView::endDate() 1094QDate CalendarView::endDate()
1095{ 1095{
1096 DateList dates = mNavigator->selectedDates(); 1096 DateList dates = mNavigator->selectedDates();
1097 1097
1098 return dates.last(); 1098 return dates.last();
1099} 1099}
1100 1100
1101 1101
1102void CalendarView::createPrinter() 1102void CalendarView::createPrinter()
1103{ 1103{
1104#ifndef KORG_NOPRINTER 1104#ifndef KORG_NOPRINTER
1105 if (!mCalPrinter) { 1105 if (!mCalPrinter) {
1106 mCalPrinter = new CalPrinter(this, mCalendar); 1106 mCalPrinter = new CalPrinter(this, mCalendar);
1107 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 1107 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
1108 } 1108 }
1109#endif 1109#endif
1110} 1110}
1111 1111
1112 1112
1113//KOPrefs::instance()->mWriteBackFile 1113//KOPrefs::instance()->mWriteBackFile
1114//KOPrefs::instance()->mWriteBackExistingOnly 1114//KOPrefs::instance()->mWriteBackExistingOnly
1115 1115
1116// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 1116// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
1117// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 1117// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
1118// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 1118// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
1119// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 1119// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
1120// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 1120// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
1121// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 1121// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
1122 1122
1123int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 1123int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
1124{ 1124{
1125 1125
1126 // 0 equal 1126 // 0 equal
1127 // 1 take local 1127 // 1 take local
1128 // 2 take remote 1128 // 2 take remote
1129 // 3 cancel 1129 // 3 cancel
1130 QDateTime lastSync = mLastCalendarSync; 1130 QDateTime lastSync = mLastCalendarSync;
1131 QDateTime localMod = local->lastModified(); 1131 QDateTime localMod = local->lastModified();
1132 QDateTime remoteMod = remote->lastModified(); 1132 QDateTime remoteMod = remote->lastModified();
1133 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1133 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1134 bool remCh, locCh; 1134 bool remCh, locCh;
1135 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 1135 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
1136 //if ( remCh ) 1136 //if ( remCh )
1137 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 1137 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
1138 locCh = ( localMod > mLastCalendarSync ); 1138 locCh = ( localMod > mLastCalendarSync );
1139 if ( !remCh && ! locCh ) { 1139 if ( !remCh && ! locCh ) {
1140 //qDebug("both not changed "); 1140 //qDebug("both not changed ");
1141 lastSync = localMod.addDays(1); 1141 lastSync = localMod.addDays(1);
1142 if ( mode <= SYNC_PREF_ASK ) 1142 if ( mode <= SYNC_PREF_ASK )
1143 return 0; 1143 return 0;
1144 } else { 1144 } else {
1145 if ( locCh ) { 1145 if ( locCh ) {
1146 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 1146 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
1147 lastSync = localMod.addDays( -1 ); 1147 lastSync = localMod.addDays( -1 );
1148 if ( !remCh ) 1148 if ( !remCh )
1149 remoteMod = ( lastSync.addDays( -1 ) ); 1149 remoteMod = ( lastSync.addDays( -1 ) );
1150 } else { 1150 } else {
1151 //qDebug(" not loc changed "); 1151 //qDebug(" not loc changed ");
1152 lastSync = localMod.addDays( 1 ); 1152 lastSync = localMod.addDays( 1 );
1153 if ( remCh ) 1153 if ( remCh )
1154 remoteMod =( lastSync.addDays( 1 ) ); 1154 remoteMod =( lastSync.addDays( 1 ) );
1155 1155
1156 } 1156 }
1157 } 1157 }
1158 full = true; 1158 full = true;
1159 if ( mode < SYNC_PREF_ASK ) 1159 if ( mode < SYNC_PREF_ASK )
1160 mode = SYNC_PREF_ASK; 1160 mode = SYNC_PREF_ASK;
1161 } else { 1161 } else {
1162 if ( localMod == remoteMod ) 1162 if ( localMod == remoteMod )
1163 // if ( local->revision() == remote->revision() ) 1163 // if ( local->revision() == remote->revision() )
1164 return 0; 1164 return 0;
1165 1165
1166 } 1166 }
1167 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 1167 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
1168 1168
1169 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 1169 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
1170 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 1170 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
1171 //full = true; //debug only 1171 //full = true; //debug only
1172 if ( full ) { 1172 if ( full ) {
1173 bool equ = false; 1173 bool equ = false;
1174 if ( local->typeID() == eventID ) { 1174 if ( local->typeID() == eventID ) {
1175 equ = (*((Event*) local) == *((Event*) remote)); 1175 equ = (*((Event*) local) == *((Event*) remote));
1176 } 1176 }
1177 else if ( local->typeID() == todoID ) 1177 else if ( local->typeID() == todoID )
1178 equ = (*((Todo*) local) == (*(Todo*) remote)); 1178 equ = (*((Todo*) local) == (*(Todo*) remote));
1179 else if ( local->typeID() == journalID ) 1179 else if ( local->typeID() == journalID )
1180 equ = (*((Journal*) local) == *((Journal*) remote)); 1180 equ = (*((Journal*) local) == *((Journal*) remote));
1181 if ( equ ) { 1181 if ( equ ) {
1182 //qDebug("equal "); 1182 //qDebug("equal ");
1183 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1183 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1184 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 1184 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
1185 } 1185 }
1186 if ( mode < SYNC_PREF_FORCE_LOCAL ) 1186 if ( mode < SYNC_PREF_FORCE_LOCAL )
1187 return 0; 1187 return 0;
1188 1188
1189 }//else //debug only 1189 }//else //debug only
1190 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 1190 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
1191 } 1191 }
1192 int result; 1192 int result;
1193 bool localIsNew; 1193 bool localIsNew;
1194 //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() ); 1194 //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() );
1195 1195
1196 1196
1197 // ************************************************ 1197 // ************************************************
1198 // ************************************************ 1198 // ************************************************
1199 // ************************************************ 1199 // ************************************************
1200 // We may have that lastSync > remoteMod AND lastSync > localMod 1200 // We may have that lastSync > remoteMod AND lastSync > localMod
1201 // BUT remoteMod != localMod 1201 // BUT remoteMod != localMod
1202 1202
1203 1203
1204 if ( full && mode < SYNC_PREF_NEWEST ) 1204 if ( full && mode < SYNC_PREF_NEWEST )
1205 mode = SYNC_PREF_ASK; 1205 mode = SYNC_PREF_ASK;
1206 1206
1207 switch( mode ) { 1207 switch( mode ) {
1208 case SYNC_PREF_LOCAL: 1208 case SYNC_PREF_LOCAL:
1209 if ( lastSync > remoteMod ) 1209 if ( lastSync > remoteMod )
1210 return 1; 1210 return 1;
1211 if ( lastSync > localMod ) 1211 if ( lastSync > localMod )
1212 return 2; 1212 return 2;
1213 return 1; 1213 return 1;
1214 break; 1214 break;
1215 case SYNC_PREF_REMOTE: 1215 case SYNC_PREF_REMOTE:
1216 if ( lastSync > localMod ) 1216 if ( lastSync > localMod )
1217 return 2; 1217 return 2;
1218 if ( lastSync > remoteMod ) 1218 if ( lastSync > remoteMod )
1219 return 1; 1219 return 1;
1220 return 2; 1220 return 2;
1221 break; 1221 break;
1222 case SYNC_PREF_NEWEST: 1222 case SYNC_PREF_NEWEST:
1223 if ( localMod >= remoteMod ) 1223 if ( localMod >= remoteMod )
1224 return 1; 1224 return 1;
1225 else 1225 else
1226 return 2; 1226 return 2;
1227 break; 1227 break;
1228 case SYNC_PREF_ASK: 1228 case SYNC_PREF_ASK:
1229 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1229 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1230 if ( lastSync > remoteMod && lastSync > localMod) 1230 if ( lastSync > remoteMod && lastSync > localMod)
1231 return 0; 1231 return 0;
1232 if ( lastSync > remoteMod ) 1232 if ( lastSync > remoteMod )
1233 return 1; 1233 return 1;
1234 if ( lastSync > localMod ) 1234 if ( lastSync > localMod )
1235 return 2; 1235 return 2;
1236 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1236 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1237 localIsNew = localMod >= remoteMod; 1237 localIsNew = localMod >= remoteMod;
1238 if ( localIsNew ) 1238 if ( localIsNew )
1239 getEventViewerDialog()->setColorMode( 1 ); 1239 getEventViewerDialog()->setColorMode( 1 );
1240 else 1240 else
1241 getEventViewerDialog()->setColorMode( 2 ); 1241 getEventViewerDialog()->setColorMode( 2 );
1242 getEventViewerDialog()->setIncidence(local); 1242 getEventViewerDialog()->setIncidence(local);
1243 if ( localIsNew ) 1243 if ( localIsNew )
1244 getEventViewerDialog()->setColorMode( 2 ); 1244 getEventViewerDialog()->setColorMode( 2 );
1245 else 1245 else
1246 getEventViewerDialog()->setColorMode( 1 ); 1246 getEventViewerDialog()->setColorMode( 1 );
1247 getEventViewerDialog()->addIncidence(remote); 1247 getEventViewerDialog()->addIncidence(remote);
1248 getEventViewerDialog()->setColorMode( 0 ); 1248 getEventViewerDialog()->setColorMode( 0 );
1249 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 1249 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
1250 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 1250 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
1251 getEventViewerDialog()->showMe(); 1251 getEventViewerDialog()->showMe();
1252 result = getEventViewerDialog()->executeS( localIsNew ); 1252 result = getEventViewerDialog()->executeS( localIsNew );
1253 return result; 1253 return result;
1254 1254
1255 break; 1255 break;
1256 case SYNC_PREF_FORCE_LOCAL: 1256 case SYNC_PREF_FORCE_LOCAL:
1257 return 1; 1257 return 1;
1258 break; 1258 break;
1259 case SYNC_PREF_FORCE_REMOTE: 1259 case SYNC_PREF_FORCE_REMOTE:
1260 return 2; 1260 return 2;
1261 break; 1261 break;
1262 1262
1263 default: 1263 default:
1264 // SYNC_PREF_TAKE_BOTH not implemented 1264 // SYNC_PREF_TAKE_BOTH not implemented
1265 break; 1265 break;
1266 } 1266 }
1267 return 0; 1267 return 0;
1268} 1268}
1269Event* CalendarView::getLastSyncEvent() 1269Event* CalendarView::getLastSyncEvent()
1270{ 1270{
1271 Event* lse; 1271 Event* lse;
1272 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 1272 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
1273 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 1273 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
1274 if (!lse) { 1274 if (!lse) {
1275 lse = new Event(); 1275 lse = new Event();
1276 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 1276 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
1277 QString sum = ""; 1277 QString sum = "";
1278 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 1278 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
1279 sum = "E: "; 1279 sum = "E: ";
1280 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 1280 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
1281 lse->setDtStart( mLastCalendarSync ); 1281 lse->setDtStart( mLastCalendarSync );
1282 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1282 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1283 lse->setCategories( i18n("SyncEvent") ); 1283 lse->setCategories( i18n("SyncEvent") );
1284 lse->setReadOnly( true ); 1284 lse->setReadOnly( true );
1285 mCalendar->addEvent( lse ); 1285 mCalendar->addEvent( lse );
1286 } 1286 }
1287 1287
1288 return lse; 1288 return lse;
1289 1289
1290} 1290}
1291 1291
1292// we check, if the to delete event has a id for a profile 1292// we check, if the to delete event has a id for a profile
1293// if yes, we set this id in the profile to delete 1293// if yes, we set this id in the profile to delete
1294void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 1294void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
1295{ 1295{
1296 if ( lastSync.count() == 0 ) { 1296 if ( lastSync.count() == 0 ) {
1297 //qDebug(" lastSync.count() == 0"); 1297 //qDebug(" lastSync.count() == 0");
1298 return; 1298 return;
1299 } 1299 }
1300 if ( toDelete->typeID() == journalID ) 1300 if ( toDelete->typeID() == journalID )
1301 return; 1301 return;
1302 1302
1303 Event* eve = lastSync.first(); 1303 Event* eve = lastSync.first();
1304 1304
1305 while ( eve ) { 1305 while ( eve ) {
1306 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 1306 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
1307 if ( !id.isEmpty() ) { 1307 if ( !id.isEmpty() ) {
1308 QString des = eve->description(); 1308 QString des = eve->description();
1309 QString pref = "e"; 1309 QString pref = "e";
1310 if ( toDelete->typeID() == todoID ) 1310 if ( toDelete->typeID() == todoID )
1311 pref = "t"; 1311 pref = "t";
1312 des += pref+ id + ","; 1312 des += pref+ id + ",";
1313 eve->setReadOnly( false ); 1313 eve->setReadOnly( false );
1314 eve->setDescription( des ); 1314 eve->setDescription( des );
1315 //qDebug("setdes %s ", des.latin1()); 1315 //qDebug("setdes %s ", des.latin1());
1316 eve->setReadOnly( true ); 1316 eve->setReadOnly( true );
1317 } 1317 }
1318 eve = lastSync.next(); 1318 eve = lastSync.next();
1319 } 1319 }
1320 1320
1321} 1321}
1322void CalendarView::checkExternalId( Incidence * inc ) 1322void CalendarView::checkExternalId( Incidence * inc )
1323{ 1323{
1324 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 1324 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
1325 checkExternSyncEvent( lastSync, inc ); 1325 checkExternSyncEvent( lastSync, inc );
1326 1326
1327} 1327}
1328bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 1328bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
1329{ 1329{
1330 bool syncOK = true; 1330 bool syncOK = true;
1331 int addedEvent = 0; 1331 int addedEvent = 0;
1332 int addedEventR = 0; 1332 int addedEventR = 0;
1333 int deletedEventR = 0; 1333 int deletedEventR = 0;
1334 int deletedEventL = 0; 1334 int deletedEventL = 0;
1335 int changedLocal = 0; 1335 int changedLocal = 0;
1336 int changedRemote = 0; 1336 int changedRemote = 0;
1337 int filteredIN = 0; 1337 int filteredIN = 0;
1338 int filteredOUT = 0; 1338 int filteredOUT = 0;
1339 //QPtrList<Event> el = local->rawEvents(); 1339 //QPtrList<Event> el = local->rawEvents();
1340 Event* eventR; 1340 Event* eventR;
1341 QString uid; 1341 QString uid;
1342 int take; 1342 int take;
1343 Event* eventRSync; 1343 Event* eventRSync;
1344 Event* eventLSync; 1344 Event* eventLSync;
1345 clearAllViews(); 1345 clearAllViews();
1346 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 1346 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
1347 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 1347 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
1348 bool fullDateRange = false; 1348 bool fullDateRange = false;
1349 local->resetTempSyncStat(); 1349 local->resetTempSyncStat();
1350 mLastCalendarSync = QDateTime::currentDateTime(); 1350 mLastCalendarSync = QDateTime::currentDateTime();
1351 if ( mSyncManager->syncWithDesktop() ) { 1351 if ( mSyncManager->syncWithDesktop() ) {
1352 remote->resetPilotStat(1); 1352 remote->resetPilotStat(1);
1353 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1353 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1354 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 1354 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
1355 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 1355 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
1356 } else { 1356 } else {
1357 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 1357 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
1358 } 1358 }
1359 } 1359 }
1360 QDateTime modifiedCalendar = mLastCalendarSync; 1360 QDateTime modifiedCalendar = mLastCalendarSync;
1361 eventLSync = getLastSyncEvent(); 1361 eventLSync = getLastSyncEvent();
1362 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 1362 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
1363 if ( eventR ) { 1363 if ( eventR ) {
1364 qDebug("last-syncEvent on remote found "); 1364 qDebug("last-syncEvent on remote found ");
1365 eventRSync = (Event*) eventR->clone(); 1365 eventRSync = (Event*) eventR->clone();
1366 remote->deleteEvent(eventR ); 1366 remote->deleteEvent(eventR );
1367 1367
1368 } else { 1368 } else {
1369 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 1369 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
1370 eventRSync = (Event*)eventLSync->clone(); 1370 eventRSync = (Event*)eventLSync->clone();
1371 } else { 1371 } else {
1372 fullDateRange = true; 1372 fullDateRange = true;
1373 eventRSync = new Event(); 1373 eventRSync = new Event();
1374 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 1374 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
1375 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 1375 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
1376 eventRSync->setDtStart( mLastCalendarSync ); 1376 eventRSync->setDtStart( mLastCalendarSync );
1377 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1377 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1378 eventRSync->setCategories( i18n("SyncEvent") ); 1378 eventRSync->setCategories( i18n("SyncEvent") );
1379 } 1379 }
1380 } 1380 }
1381 if ( eventLSync->dtStart() == mLastCalendarSync ) 1381 if ( eventLSync->dtStart() == mLastCalendarSync )
1382 fullDateRange = true; 1382 fullDateRange = true;
1383 1383
1384 if ( ! fullDateRange ) { 1384 if ( ! fullDateRange ) {
1385 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 1385 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
1386 1386
1387 qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 1387 qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
1388 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 1388 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
1389 fullDateRange = true; 1389 fullDateRange = true;
1390 } 1390 }
1391 } 1391 }
1392 if ( mSyncManager->syncWithDesktop() ) { 1392 if ( mSyncManager->syncWithDesktop() ) {
1393 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 1393 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
1394 } 1394 }
1395 if ( fullDateRange ) 1395 if ( fullDateRange )
1396 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 1396 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
1397 else 1397 else
1398 mLastCalendarSync = eventLSync->dtStart(); 1398 mLastCalendarSync = eventLSync->dtStart();
1399 // for resyncing if own file has changed 1399 // for resyncing if own file has changed
1400 if ( mCurrentSyncDevice == "deleteaftersync" ) { 1400 if ( mCurrentSyncDevice == "deleteaftersync" ) {
1401 mLastCalendarSync = loadedFileVersion; 1401 mLastCalendarSync = loadedFileVersion;
1402 //qDebug("setting mLastCalendarSync "); 1402 //qDebug("setting mLastCalendarSync ");
1403 } 1403 }
1404 //qDebug("*************************** "); 1404 //qDebug("*************************** ");
1405 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1405 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1406 QPtrList<Incidence> er = remote->rawIncidences(); 1406 QPtrList<Incidence> er = remote->rawIncidences();
1407 Incidence* inR = er.first(); 1407 Incidence* inR = er.first();
1408 Incidence* inL; 1408 Incidence* inL;
1409 QProgressBar bar( er.count(),0 ); 1409 QProgressBar bar( er.count(),0 );
1410 bar.setCaption (i18n("Syncing - close to abort!") ); 1410 bar.setCaption (i18n("Syncing - close to abort!") );
1411 1411
1412 // ************** setting up filter ************* 1412 // ************** setting up filter *************
1413 CalFilter *filterIN = 0; 1413 CalFilter *filterIN = 0;
1414 CalFilter *filterOUT = 0; 1414 CalFilter *filterOUT = 0;
1415 CalFilter *filter = mFilters.first(); 1415 CalFilter *filter = mFilters.first();
1416 while(filter) { 1416 while(filter) {
1417 if ( filter->name() == mSyncManager->mFilterInCal ) 1417 if ( filter->name() == mSyncManager->mFilterInCal )
1418 filterIN = filter; 1418 filterIN = filter;
1419 if ( filter->name() == mSyncManager->mFilterOutCal ) 1419 if ( filter->name() == mSyncManager->mFilterOutCal )
1420 filterOUT = filter; 1420 filterOUT = filter;
1421 filter = mFilters.next(); 1421 filter = mFilters.next();
1422 } 1422 }
1423 int w = 300; 1423 int w = 300;
1424 if ( QApplication::desktop()->width() < 320 ) 1424 if ( QApplication::desktop()->width() < 320 )
1425 w = 220; 1425 w = 220;
1426 int h = bar.sizeHint().height() ; 1426 int h = bar.sizeHint().height() ;
1427 int dw = QApplication::desktop()->width(); 1427 int dw = QApplication::desktop()->width();
1428 int dh = QApplication::desktop()->height(); 1428 int dh = QApplication::desktop()->height();
1429 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1429 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1430 bar.show(); 1430 bar.show();
1431 int modulo = (er.count()/10)+1; 1431 int modulo = (er.count()/10)+1;
1432 int incCounter = 0; 1432 int incCounter = 0;
1433 while ( inR ) { 1433 while ( inR ) {
1434 if ( ! bar.isVisible() ) 1434 if ( ! bar.isVisible() )
1435 return false; 1435 return false;
1436 if ( incCounter % modulo == 0 ) 1436 if ( incCounter % modulo == 0 )
1437 bar.setProgress( incCounter ); 1437 bar.setProgress( incCounter );
1438 ++incCounter; 1438 ++incCounter;
1439 uid = inR->uid(); 1439 uid = inR->uid();
1440 bool skipIncidence = false; 1440 bool skipIncidence = false;
1441 if ( uid.left(15) == QString("last-syncEvent-") ) 1441 if ( uid.left(15) == QString("last-syncEvent-") )
1442 skipIncidence = true; 1442 skipIncidence = true;
1443 QString idS; 1443 QString idS;
1444 qApp->processEvents(); 1444 qApp->processEvents();
1445 if ( !skipIncidence ) { 1445 if ( !skipIncidence ) {
1446 inL = local->incidenceForUid( uid , false ); 1446 inL = local->incidenceForUid( uid , false );
1447 if ( inL ) { // maybe conflict - same uid in both calendars 1447 if ( inL ) { // maybe conflict - same uid in both calendars
1448 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1448 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1449 //qDebug("take %d %s ", take, inL->summary().latin1()); 1449 //qDebug("take %d %s ", take, inL->summary().latin1());
1450 if ( take == 3 ) 1450 if ( take == 3 )
1451 return false; 1451 return false;
1452 if ( take == 1 ) {// take local ********************** 1452 if ( take == 1 ) {// take local **********************
1453 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1453 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1454 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1454 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1455 else 1455 else
1456 idS = inR->IDStr(); 1456 idS = inR->IDStr();
1457 int calID = inR->calID(); 1457 int calID = inR->calID();
1458 remote->deleteIncidence( inR ); 1458 remote->deleteIncidence( inR );
1459 inR = inL->clone(); 1459 inR = inL->clone();
1460 inR->setCalID( calID ); 1460 inR->setCalID( calID );
1461 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1461 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1462 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1462 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1463 inR->setIDStr( idS ); 1463 inR->setIDStr( idS );
1464 remote->addIncidence( inR ); 1464 remote->addIncidence( inR );
1465 if ( mSyncManager->syncWithDesktop() ) 1465 if ( mSyncManager->syncWithDesktop() )
1466 inR->setPilotId( 2 ); 1466 inR->setPilotId( 2 );
1467 ++changedRemote; 1467 ++changedRemote;
1468 } else {// take remote ********************** 1468 } else {// take remote **********************
1469 if ( !inL->isReadOnly() ) { 1469 if ( !inL->isReadOnly() ) {
1470 idS = inL->IDStr(); 1470 idS = inL->IDStr();
1471 int pid = inL->pilotId(); 1471 int pid = inL->pilotId();
1472 int calID = inL->calID(); 1472 int calID = inL->calID();
1473 local->deleteIncidence( inL ); 1473 local->deleteIncidence( inL );
1474 inL = inR->clone(); 1474 inL = inR->clone();
1475 inL->setCalID( calID ); 1475 inL->setCalID( calID );
1476 if ( mSyncManager->syncWithDesktop() ) 1476 if ( mSyncManager->syncWithDesktop() )
1477 inL->setPilotId( pid ); 1477 inL->setPilotId( pid );
1478 inL->setIDStr( idS ); 1478 inL->setIDStr( idS );
1479 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1479 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1480 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1480 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1481 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1481 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1482 } 1482 }
1483 local->addIncidence( inL ); 1483 local->addIncidence( inL );
1484 ++changedLocal; 1484 ++changedLocal;
1485 } 1485 }
1486 } 1486 }
1487 } 1487 }
1488 } else { // no conflict ********** add or delete remote 1488 } else { // no conflict ********** add or delete remote
1489 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1489 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1490 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1490 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1491 QString des = eventLSync->description(); 1491 QString des = eventLSync->description();
1492 QString pref = "e"; 1492 QString pref = "e";
1493 if ( inR->typeID() == todoID ) 1493 if ( inR->typeID() == todoID )
1494 pref = "t"; 1494 pref = "t";
1495 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1495 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1496 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1496 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1497 //remote->deleteIncidence( inR ); 1497 //remote->deleteIncidence( inR );
1498 ++deletedEventR; 1498 ++deletedEventR;
1499 } else { 1499 } else {
1500 inR->setLastModified( modifiedCalendar ); 1500 inR->setLastModified( modifiedCalendar );
1501 inL = inR->clone(); 1501 inL = inR->clone();
1502 inL->setIDStr( ":" ); 1502 inL->setIDStr( ":" );
1503 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1503 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1504 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1504 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1505 1505
1506 inL->setCalID( 0 );// add to default cal 1506 inL->setCalID( 0 );// add to default cal
1507 local->addIncidence( inL ); 1507 local->addIncidence( inL );
1508 ++addedEvent; 1508 ++addedEvent;
1509 1509
1510 } 1510 }
1511 } else { 1511 } else {
1512 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1512 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1513 inR->setLastModified( modifiedCalendar ); 1513 inR->setLastModified( modifiedCalendar );
1514 inL = inR->clone(); 1514 inL = inR->clone();
1515 inL->setIDStr( ":" ); 1515 inL->setIDStr( ":" );
1516 inL->setCalID( 0 );// add to default cal 1516 inL->setCalID( 0 );// add to default cal
1517 local->addIncidence( inL ); 1517 local->addIncidence( inL );
1518 ++addedEvent; 1518 ++addedEvent;
1519 1519
1520 } else { 1520 } else {
1521 checkExternSyncEvent(eventRSyncSharp, inR); 1521 checkExternSyncEvent(eventRSyncSharp, inR);
1522 remote->deleteIncidence( inR ); 1522 remote->deleteIncidence( inR );
1523 ++deletedEventR; 1523 ++deletedEventR;
1524 } 1524 }
1525 } 1525 }
1526 } else { 1526 } else {
1527 ++filteredIN; 1527 ++filteredIN;
1528 } 1528 }
1529 } 1529 }
1530 } 1530 }
1531 inR = er.next(); 1531 inR = er.next();
1532 } 1532 }
1533 QPtrList<Incidence> el = local->rawIncidences(); 1533 QPtrList<Incidence> el = local->rawIncidences();
1534 inL = el.first(); 1534 inL = el.first();
1535 modulo = (el.count()/10)+1; 1535 modulo = (el.count()/10)+1;
1536 bar.setCaption (i18n("Add / remove events") ); 1536 bar.setCaption (i18n("Add / remove events") );
1537 bar.setTotalSteps ( el.count() ) ; 1537 bar.setTotalSteps ( el.count() ) ;
1538 bar.show(); 1538 bar.show();
1539 incCounter = 0; 1539 incCounter = 0;
1540 1540
1541 while ( inL ) { 1541 while ( inL ) {
1542 1542
1543 qApp->processEvents(); 1543 qApp->processEvents();
1544 if ( ! bar.isVisible() ) 1544 if ( ! bar.isVisible() )
1545 return false; 1545 return false;
1546 if ( incCounter % modulo == 0 ) 1546 if ( incCounter % modulo == 0 )
1547 bar.setProgress( incCounter ); 1547 bar.setProgress( incCounter );
1548 ++incCounter; 1548 ++incCounter;
1549 uid = inL->uid(); 1549 uid = inL->uid();
1550 bool skipIncidence = false; 1550 bool skipIncidence = false;
1551 if ( uid.left(15) == QString("last-syncEvent-") ) 1551 if ( uid.left(15) == QString("last-syncEvent-") )
1552 skipIncidence = true; 1552 skipIncidence = true;
1553 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) 1553 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID )
1554 skipIncidence = true; 1554 skipIncidence = true;
1555 if ( !skipIncidence ) { 1555 if ( !skipIncidence ) {
1556 inR = remote->incidenceForUid( uid , true ); 1556 inR = remote->incidenceForUid( uid , true );
1557 if ( ! inR ) { 1557 if ( ! inR ) {
1558 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1558 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1559 // no conflict ********** add or delete local 1559 // no conflict ********** add or delete local
1560 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1560 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1561 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1561 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1562 checkExternSyncEvent(eventLSyncSharp, inL); 1562 checkExternSyncEvent(eventLSyncSharp, inL);
1563 local->deleteIncidence( inL ); 1563 local->deleteIncidence( inL );
1564 ++deletedEventL; 1564 ++deletedEventL;
1565 } else { 1565 } else {
1566 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1566 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1567 inL->removeID(mCurrentSyncDevice ); 1567 inL->removeID(mCurrentSyncDevice );
1568 ++addedEventR; 1568 ++addedEventR;
1569 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1569 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1570 inL->setLastModified( modifiedCalendar ); 1570 inL->setLastModified( modifiedCalendar );
1571 inR = inL->clone(); 1571 inR = inL->clone();
1572 inR->setIDStr( ":" ); 1572 inR->setIDStr( ":" );
1573 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1573 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1574 inR->setCalID( 0 );// add to default cal 1574 inR->setCalID( 0 );// add to default cal
1575 remote->addIncidence( inR ); 1575 remote->addIncidence( inR );
1576 } 1576 }
1577 } 1577 }
1578 } else { 1578 } else {
1579 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1579 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1580 checkExternSyncEvent(eventLSyncSharp, inL); 1580 checkExternSyncEvent(eventLSyncSharp, inL);
1581 local->deleteIncidence( inL ); 1581 local->deleteIncidence( inL );
1582 ++deletedEventL; 1582 ++deletedEventL;
1583 } else { 1583 } else {
1584 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1584 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1585 ++addedEventR; 1585 ++addedEventR;
1586 inL->setLastModified( modifiedCalendar ); 1586 inL->setLastModified( modifiedCalendar );
1587 inR = inL->clone(); 1587 inR = inL->clone();
1588 inR->setIDStr( ":" ); 1588 inR->setIDStr( ":" );
1589 inR->setCalID( 0 );// add to default cal 1589 inR->setCalID( 0 );// add to default cal
1590 remote->addIncidence( inR ); 1590 remote->addIncidence( inR );
1591 } 1591 }
1592 } 1592 }
1593 } 1593 }
1594 } else { 1594 } else {
1595 ++filteredOUT; 1595 ++filteredOUT;
1596 } 1596 }
1597 } 1597 }
1598 } 1598 }
1599 inL = el.next(); 1599 inL = el.next();
1600 } 1600 }
1601 int delFut = 0; 1601 int delFut = 0;
1602 int remRem = 0; 1602 int remRem = 0;
1603 if ( mSyncManager->mWriteBackInFuture ) { 1603 if ( mSyncManager->mWriteBackInFuture ) {
1604 er = remote->rawIncidences(); 1604 er = remote->rawIncidences();
1605 remRem = er.count(); 1605 remRem = er.count();
1606 inR = er.first(); 1606 inR = er.first();
1607 QDateTime dt; 1607 QDateTime dt;
1608 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1608 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1609 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1609 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1610 while ( inR ) { 1610 while ( inR ) {
1611 if ( inR->typeID() == todoID ) { 1611 if ( inR->typeID() == todoID ) {
1612 Todo * t = (Todo*)inR; 1612 Todo * t = (Todo*)inR;
1613 if ( t->hasDueDate() ) 1613 if ( t->hasDueDate() )
1614 dt = t->dtDue(); 1614 dt = t->dtDue();
1615 else 1615 else
1616 dt = cur.addSecs( 62 ); 1616 dt = cur.addSecs( 62 );
1617 } 1617 }
1618 else if (inR->typeID() == eventID ) { 1618 else if (inR->typeID() == eventID ) {
1619 bool ok; 1619 bool ok;
1620 dt = inR->getNextOccurence( cur, &ok ); 1620 dt = inR->getNextOccurence( cur, &ok );
1621 if ( !ok ) 1621 if ( !ok )
1622 dt = cur.addSecs( -62 ); 1622 dt = cur.addSecs( -62 );
1623 } 1623 }
1624 else 1624 else
1625 dt = inR->dtStart(); 1625 dt = inR->dtStart();
1626 if ( dt < cur || dt > end ) { 1626 if ( dt < cur || dt > end ) {
1627 remote->deleteIncidence( inR ); 1627 remote->deleteIncidence( inR );
1628 ++delFut; 1628 ++delFut;
1629 } 1629 }
1630 inR = er.next(); 1630 inR = er.next();
1631 } 1631 }
1632 } 1632 }
1633 bar.hide(); 1633 bar.hide();
1634 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1634 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1635 eventLSync->setReadOnly( false ); 1635 eventLSync->setReadOnly( false );
1636 eventLSync->setDtStart( mLastCalendarSync ); 1636 eventLSync->setDtStart( mLastCalendarSync );
1637 eventRSync->setDtStart( mLastCalendarSync ); 1637 eventRSync->setDtStart( mLastCalendarSync );
1638 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1638 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1639 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1639 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1640 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1640 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1641 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1641 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1642 eventLSync->setReadOnly( true ); 1642 eventLSync->setReadOnly( true );
1643 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1643 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1644 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1644 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1645 remote->addEvent( eventRSync ); 1645 remote->addEvent( eventRSync );
1646 else 1646 else
1647 delete eventRSync; 1647 delete eventRSync;
1648 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1648 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1649 QString mes; 1649 QString mes;
1650 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 ); 1650 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 );
1651 QString delmess; 1651 QString delmess;
1652 if ( delFut ) { 1652 if ( delFut ) {
1653 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); 1653 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);
1654 mes += delmess; 1654 mes += delmess;
1655 } 1655 }
1656 mes = i18n("Local calendar changed!\n") +mes; 1656 mes = i18n("Local calendar changed!\n") +mes;
1657 mCalendar->checkAlarmForIncidence( 0, true ); 1657 mCalendar->checkAlarmForIncidence( 0, true );
1658 qDebug( mes ); 1658 qDebug( mes );
1659 if ( mSyncManager->mShowSyncSummary ) { 1659 if ( mSyncManager->mShowSyncSummary ) {
1660 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1660 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1661 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1661 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1662 qDebug("KO: WB cancelled "); 1662 qDebug("KO: WB cancelled ");
1663 mSyncManager->mWriteBackFile = false; 1663 mSyncManager->mWriteBackFile = false;
1664 return syncOK; 1664 return syncOK;
1665 } 1665 }
1666 } 1666 }
1667 return syncOK; 1667 return syncOK;
1668} 1668}
1669 1669
1670void CalendarView::setSyncDevice( QString s ) 1670void CalendarView::setSyncDevice( QString s )
1671{ 1671{
1672 mCurrentSyncDevice= s; 1672 mCurrentSyncDevice= s;
1673} 1673}
1674void CalendarView::setSyncName( QString s ) 1674void CalendarView::setSyncName( QString s )
1675{ 1675{
1676 mCurrentSyncName= s; 1676 mCurrentSyncName= s;
1677} 1677}
1678bool CalendarView::syncCalendar(QString filename, int mode) 1678bool CalendarView::syncCalendar(QString filename, int mode)
1679{ 1679{
1680 //qDebug("syncCalendar %s ", filename.latin1()); 1680 //qDebug("syncCalendar %s ", filename.latin1());
1681 mGlobalSyncMode = SYNC_MODE_NORMAL; 1681 mGlobalSyncMode = SYNC_MODE_NORMAL;
1682 CalendarLocal* calendar = new CalendarLocal(); 1682 CalendarLocal* calendar = new CalendarLocal();
1683 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1683 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1684 FileStorage* storage = new FileStorage( calendar ); 1684 FileStorage* storage = new FileStorage( calendar );
1685 bool syncOK = false; 1685 bool syncOK = false;
1686 storage->setFileName( filename ); 1686 storage->setFileName( filename );
1687 // qDebug("loading ... "); 1687 // qDebug("loading ... ");
1688 if ( storage->load() ) { 1688 if ( storage->load() ) {
1689 getEventViewerDialog()->setSyncMode( true ); 1689 getEventViewerDialog()->setSyncMode( true );
1690 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1690 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1691 getEventViewerDialog()->setSyncMode( false ); 1691 getEventViewerDialog()->setSyncMode( false );
1692 if ( syncOK ) { 1692 if ( syncOK ) {
1693 if ( mSyncManager->mWriteBackFile ) 1693 if ( mSyncManager->mWriteBackFile )
1694 { 1694 {
1695 storage->setSaveFormat( new ICalFormat() ); 1695 storage->setSaveFormat( new ICalFormat() );
1696 storage->save(); 1696 storage->save();
1697 } 1697 }
1698 } 1698 }
1699 setModified( true ); 1699 setModified( true );
1700 } 1700 }
1701 delete storage; 1701 delete storage;
1702 delete calendar; 1702 delete calendar;
1703 if ( syncOK ) 1703 if ( syncOK )
1704 updateView(); 1704 updateView();
1705 return syncOK; 1705 return syncOK;
1706} 1706}
1707 1707
1708void CalendarView::syncExternal( int mode ) 1708void CalendarView::syncExternal( int mode )
1709{ 1709{
1710 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1710 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1711 1711
1712 qApp->processEvents(); 1712 qApp->processEvents();
1713 CalendarLocal* calendar = new CalendarLocal(); 1713 CalendarLocal* calendar = new CalendarLocal();
1714 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1714 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1715 bool syncOK = false; 1715 bool syncOK = false;
1716 bool loadSuccess = false; 1716 bool loadSuccess = false;
1717 PhoneFormat* phoneFormat = 0; 1717 PhoneFormat* phoneFormat = 0;
1718 emit tempDisableBR(true); 1718 emit tempDisableBR(true);
1719#ifndef DESKTOP_VERSION 1719#ifndef DESKTOP_VERSION
1720 SharpFormat* sharpFormat = 0; 1720 SharpFormat* sharpFormat = 0;
1721 if ( mode == 0 ) { // sharp 1721 if ( mode == 0 ) { // sharp
1722 sharpFormat = new SharpFormat () ; 1722 sharpFormat = new SharpFormat () ;
1723 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1723 loadSuccess = sharpFormat->load( calendar, mCalendar );
1724 1724
1725 } else 1725 } else
1726#endif 1726#endif
1727 if ( mode == 1 ) { // phone 1727 if ( mode == 1 ) { // phone
1728 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1728 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1729 mSyncManager->mPhoneDevice, 1729 mSyncManager->mPhoneDevice,
1730 mSyncManager->mPhoneConnection, 1730 mSyncManager->mPhoneConnection,
1731 mSyncManager->mPhoneModel); 1731 mSyncManager->mPhoneModel);
1732 loadSuccess = phoneFormat->load( calendar,mCalendar); 1732 loadSuccess = phoneFormat->load( calendar,mCalendar);
1733 1733
1734 } else { 1734 } else {
1735 emit tempDisableBR(false); 1735 emit tempDisableBR(false);
1736 return; 1736 return;
1737 } 1737 }
1738 if ( loadSuccess ) { 1738 if ( loadSuccess ) {
1739 getEventViewerDialog()->setSyncMode( true ); 1739 getEventViewerDialog()->setSyncMode( true );
1740 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1740 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1741 getEventViewerDialog()->setSyncMode( false ); 1741 getEventViewerDialog()->setSyncMode( false );
1742 qApp->processEvents(); 1742 qApp->processEvents();
1743 if ( syncOK ) { 1743 if ( syncOK ) {
1744 if ( mSyncManager->mWriteBackFile ) 1744 if ( mSyncManager->mWriteBackFile )
1745 { 1745 {
1746 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1746 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1747 Incidence* inc = iL.first(); 1747 Incidence* inc = iL.first();
1748 if ( phoneFormat ) { 1748 if ( phoneFormat ) {
1749 while ( inc ) { 1749 while ( inc ) {
1750 inc->removeID(mCurrentSyncDevice); 1750 inc->removeID(mCurrentSyncDevice);
1751 inc = iL.next(); 1751 inc = iL.next();
1752 } 1752 }
1753 } 1753 }
1754#ifndef DESKTOP_VERSION 1754#ifndef DESKTOP_VERSION
1755 if ( sharpFormat ) 1755 if ( sharpFormat )
1756 sharpFormat->save(calendar); 1756 sharpFormat->save(calendar);
1757#endif 1757#endif
1758 if ( phoneFormat ) 1758 if ( phoneFormat )
1759 phoneFormat->save(calendar); 1759 phoneFormat->save(calendar);
1760 iL = calendar->rawIncidences(); 1760 iL = calendar->rawIncidences();
1761 inc = iL.first(); 1761 inc = iL.first();
1762 Incidence* loc; 1762 Incidence* loc;
1763 while ( inc ) { 1763 while ( inc ) {
1764 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1764 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1765 loc = mCalendar->incidence(inc->uid() ); 1765 loc = mCalendar->incidence(inc->uid() );
1766 if ( loc ) { 1766 if ( loc ) {
1767 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1767 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1768 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1768 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1769 } 1769 }
1770 } 1770 }
1771 inc = iL.next(); 1771 inc = iL.next();
1772 } 1772 }
1773 Incidence* lse = getLastSyncEvent(); 1773 Incidence* lse = getLastSyncEvent();
1774 if ( lse ) { 1774 if ( lse ) {
1775 lse->setReadOnly( false ); 1775 lse->setReadOnly( false );
1776 lse->setDescription( "" ); 1776 lse->setDescription( "" );
1777 lse->setReadOnly( true ); 1777 lse->setReadOnly( true );
1778 } 1778 }
1779 } 1779 }
1780 } else { 1780 } else {
1781 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1781 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1782 } 1782 }
1783 setModified( true ); 1783 setModified( true );
1784 } else { 1784 } else {
1785 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1785 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1786 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1786 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1787 question, i18n("Ok")) ; 1787 question, i18n("Ok")) ;
1788 1788
1789 } 1789 }
1790 delete calendar; 1790 delete calendar;
1791 updateView(); 1791 updateView();
1792 emit tempDisableBR(false); 1792 emit tempDisableBR(false);
1793 return ;//syncOK; 1793 return ;//syncOK;
1794 1794
1795} 1795}
1796 1796
1797bool CalendarView::importBday() 1797bool CalendarView::importBday()
1798{ 1798{
1799#ifndef KORG_NOKABC 1799#ifndef KORG_NOKABC
1800 1800
1801#ifdef DESKTOP_VERSION 1801#ifdef DESKTOP_VERSION
1802 int curCal = mCalendar->defaultCalendar(); 1802 int curCal = mCalendar->defaultCalendar();
1803 int bd = mCalEditView->getBirtdayID(); 1803 int bd = mCalEditView->getBirtdayID();
1804 if ( bd == 0 ) 1804 if ( bd == 0 )
1805 return false; 1805 return false;
1806 mCalendar->setDefaultCalendar( bd ); 1806 mCalendar->setDefaultCalendar( bd );
1807 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1807 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1808 KABC::AddressBook::Iterator it; 1808 KABC::AddressBook::Iterator it;
1809 int count = 0; 1809 int count = 0;
1810 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1810 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1811 ++count; 1811 ++count;
1812 } 1812 }
1813 QProgressBar bar(count,0 ); 1813 QProgressBar bar(count,0 );
1814 int w = 300; 1814 int w = 300;
1815 if ( QApplication::desktop()->width() < 320 ) 1815 if ( QApplication::desktop()->width() < 320 )
1816 w = 220; 1816 w = 220;
1817 int h = bar.sizeHint().height() ; 1817 int h = bar.sizeHint().height() ;
1818 int dw = QApplication::desktop()->width(); 1818 int dw = QApplication::desktop()->width();
1819 int dh = QApplication::desktop()->height(); 1819 int dh = QApplication::desktop()->height();
1820 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1820 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1821 bar.show(); 1821 bar.show();
1822 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1822 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1823 qApp->processEvents(); 1823 qApp->processEvents();
1824 count = 0; 1824 count = 0;
1825 int addCount = 0; 1825 int addCount = 0;
1826 KCal::Attendee* a = 0; 1826 KCal::Attendee* a = 0;
1827 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1827 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1828 if ( ! bar.isVisible() ) 1828 if ( ! bar.isVisible() )
1829 return false; 1829 return false;
1830 bar.setProgress( count++ ); 1830 bar.setProgress( count++ );
1831 qApp->processEvents(); 1831 qApp->processEvents();
1832 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1832 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1833 if ( (*it).birthday().date().isValid() ){ 1833 if ( (*it).birthday().date().isValid() ){
1834 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1834 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1835 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1835 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1836 ++addCount; 1836 ++addCount;
1837 } 1837 }
1838 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1838 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1839 if ( anni.isValid() ){ 1839 if ( anni.isValid() ){
1840 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1840 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1841 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1841 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1842 ++addCount; 1842 ++addCount;
1843 } 1843 }
1844 } 1844 }
1845 mCalendar->setDefaultCalendar( curCal ); 1845 mCalendar->setDefaultCalendar( curCal );
1846 updateView(); 1846 updateView();
1847 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1847 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1848#else //DESKTOP_VERSION 1848#else //DESKTOP_VERSION
1849 1849
1850 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1850 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1851 // the result should now arrive through method insertBirthdays 1851 // the result should now arrive through method insertBirthdays
1852 1852
1853#endif //DESKTOP_VERSION 1853#endif //DESKTOP_VERSION
1854 1854
1855#endif //KORG_NOKABC 1855#endif //KORG_NOKABC
1856 1856
1857 1857
1858 return true; 1858 return true;
1859} 1859}
1860 1860
1861// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1861// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1862void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1862void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1863 const QStringList& anniversaryList, const QStringList& realNameList, 1863 const QStringList& anniversaryList, const QStringList& realNameList,
1864 const QStringList& emailList, const QStringList& assembledNameList, 1864 const QStringList& emailList, const QStringList& assembledNameList,
1865 const QStringList& uidList) 1865 const QStringList& uidList)
1866{ 1866{
1867 1867
1868 //qDebug("KO::CalendarView::insertBirthdays"); 1868 //qDebug("KO::CalendarView::insertBirthdays");
1869 if (uid == this->name()) 1869 if (uid == this->name())
1870 { 1870 {
1871 int curCal = mCalendar->defaultCalendar(); 1871 int curCal = mCalendar->defaultCalendar();
1872 int bd = mCalEditView->getBirtdayID(); 1872 int bd = mCalEditView->getBirtdayID();
1873 if ( bd == 0 ) 1873 if ( bd == 0 )
1874 return; 1874 return;
1875 mCalendar->setDefaultCalendar( bd ); 1875 mCalendar->setDefaultCalendar( bd );
1876 1876
1877 1877
1878 int count = birthdayList.count(); 1878 int count = birthdayList.count();
1879 int addCount = 0; 1879 int addCount = 0;
1880 KCal::Attendee* a = 0; 1880 KCal::Attendee* a = 0;
1881 1881
1882 //qDebug("CalView 1 %i", count); 1882 //qDebug("CalView 1 %i", count);
1883 1883
1884 QProgressBar bar(count,0 ); 1884 QProgressBar bar(count,0 );
1885 int w = 300; 1885 int w = 300;
1886 if ( QApplication::desktop()->width() < 320 ) 1886 if ( QApplication::desktop()->width() < 320 )
1887 w = 220; 1887 w = 220;
1888 int h = bar.sizeHint().height() ; 1888 int h = bar.sizeHint().height() ;
1889 int dw = QApplication::desktop()->width(); 1889 int dw = QApplication::desktop()->width();
1890 int dh = QApplication::desktop()->height(); 1890 int dh = QApplication::desktop()->height();
1891 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1891 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1892 bar.show(); 1892 bar.show();
1893 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1893 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1894 qApp->processEvents(); 1894 qApp->processEvents();
1895 1895
1896 QDate birthday; 1896 QDate birthday;
1897 QDate anniversary; 1897 QDate anniversary;
1898 QString realName; 1898 QString realName;
1899 QString email; 1899 QString email;
1900 QString assembledName; 1900 QString assembledName;
1901 QString uid; 1901 QString uid;
1902 bool ok = true; 1902 bool ok = true;
1903 for ( int i = 0; i < count; i++) 1903 for ( int i = 0; i < count; i++)
1904 { 1904 {
1905 if ( ! bar.isVisible() ) 1905 if ( ! bar.isVisible() )
1906 return; 1906 return;
1907 bar.setProgress( i ); 1907 bar.setProgress( i );
1908 qApp->processEvents(); 1908 qApp->processEvents();
1909 1909
1910 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1910 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1911 if (!ok) { 1911 if (!ok) {
1912 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1912 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1913 } 1913 }
1914 1914
1915 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1915 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1916 if (!ok) { 1916 if (!ok) {
1917 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1917 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1918 } 1918 }
1919 realName = realNameList[i]; 1919 realName = realNameList[i];
1920 email = emailList[i]; 1920 email = emailList[i];
1921 assembledName = assembledNameList[i]; 1921 assembledName = assembledNameList[i];
1922 uid = uidList[i]; 1922 uid = uidList[i];
1923 //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() ); 1923 //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() );
1924 1924
1925 if ( birthday.isValid() ){ 1925 if ( birthday.isValid() ){
1926 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1926 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1927 KCal::Attendee::ReqParticipant,uid) ; 1927 KCal::Attendee::ReqParticipant,uid) ;
1928 if ( addAnniversary( birthday, assembledName, a, true ) ) 1928 if ( addAnniversary( birthday, assembledName, a, true ) )
1929 ++addCount; 1929 ++addCount;
1930 } 1930 }
1931 1931
1932 if ( anniversary.isValid() ){ 1932 if ( anniversary.isValid() ){
1933 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1933 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1934 KCal::Attendee::ReqParticipant,uid) ; 1934 KCal::Attendee::ReqParticipant,uid) ;
1935 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1935 if ( addAnniversary( anniversary, assembledName, a, false ) )
1936 ++addCount; 1936 ++addCount;
1937 } 1937 }
1938 } 1938 }
1939 1939
1940 mCalendar->setDefaultCalendar( curCal ); 1940 mCalendar->setDefaultCalendar( curCal );
1941 updateView(); 1941 updateView();
1942 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1942 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1943 1943
1944 } 1944 }
1945 1945
1946} 1946}
1947 1947
1948 1948
1949 1949
1950bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1950bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1951{ 1951{
1952 //qDebug("addAnni "); 1952 //qDebug("addAnni ");
1953 Event * ev = new Event(); 1953 Event * ev = new Event();
1954 ev->setOrganizer(KOPrefs::instance()->email()); 1954 ev->setOrganizer(KOPrefs::instance()->email());
1955 if ( a ) { 1955 if ( a ) {
1956 ev->addAttendee( a ); 1956 ev->addAttendee( a );
1957 } 1957 }
1958 QString kind; 1958 QString kind;
1959 if ( birthday ) { 1959 if ( birthday ) {
1960 kind = i18n( "Birthday" ); 1960 kind = i18n( "Birthday" );
1961 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 1961 ev->setSummary( name + " (" + QString::number(date.year()) +")");
1962 } 1962 }
1963 else { 1963 else {
1964 kind = i18n( "Anniversary" ); 1964 kind = i18n( "Anniversary" );
1965 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 1965 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
1966 } 1966 }
1967 ev->setCategories( kind ); 1967 ev->setCategories( kind );
1968 ev->setDtStart( QDateTime(date) ); 1968 ev->setDtStart( QDateTime(date) );
1969 ev->setDtEnd( QDateTime(date) ); 1969 ev->setDtEnd( QDateTime(date) );
1970 ev->setFloats( true ); 1970 ev->setFloats( true );
1971 Recurrence * rec = ev->recurrence(); 1971 Recurrence * rec = ev->recurrence();
1972 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1972 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1973 rec->addYearlyNum( date.month() ); 1973 rec->addYearlyNum( date.month() );
1974 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1974 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1975 delete ev; 1975 delete ev;
1976 return false; 1976 return false;
1977 } 1977 }
1978 return true; 1978 return true;
1979 1979
1980} 1980}
1981bool CalendarView::importQtopia( const QString &categories, 1981bool CalendarView::importQtopia( const QString &categories,
1982 const QString &datebook, 1982 const QString &datebook,
1983 const QString &todolist ) 1983 const QString &todolist )
1984{ 1984{
1985 1985
1986 QtopiaFormat qtopiaFormat; 1986 QtopiaFormat qtopiaFormat;
1987 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1987 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1988 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1988 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1989 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1989 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1990 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1990 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1991 1991
1992 updateView(); 1992 updateView();
1993 return true; 1993 return true;
1994 1994
1995#if 0 1995#if 0
1996 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1996 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1997 mCurrentSyncDevice = "qtopia-XML"; 1997 mCurrentSyncDevice = "qtopia-XML";
1998 if ( mSyncManager->mAskForPreferences ) 1998 if ( mSyncManager->mAskForPreferences )
1999 edit_sync_options(); 1999 edit_sync_options();
2000 qApp->processEvents(); 2000 qApp->processEvents();
2001 CalendarLocal* calendar = new CalendarLocal(); 2001 CalendarLocal* calendar = new CalendarLocal();
2002 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2002 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2003 bool syncOK = false; 2003 bool syncOK = false;
2004 QtopiaFormat qtopiaFormat; 2004 QtopiaFormat qtopiaFormat;
2005 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 2005 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
2006 bool loadOk = true; 2006 bool loadOk = true;
2007 if ( !categories.isEmpty() ) 2007 if ( !categories.isEmpty() )
2008 loadOk = qtopiaFormat.load( calendar, categories ); 2008 loadOk = qtopiaFormat.load( calendar, categories );
2009 if ( loadOk && !datebook.isEmpty() ) 2009 if ( loadOk && !datebook.isEmpty() )
2010 loadOk = qtopiaFormat.load( calendar, datebook ); 2010 loadOk = qtopiaFormat.load( calendar, datebook );
2011 if ( loadOk && !todolist.isEmpty() ) 2011 if ( loadOk && !todolist.isEmpty() )
2012 loadOk = qtopiaFormat.load( calendar, todolist ); 2012 loadOk = qtopiaFormat.load( calendar, todolist );
2013 2013
2014 if ( loadOk ) { 2014 if ( loadOk ) {
2015 getEventViewerDialog()->setSyncMode( true ); 2015 getEventViewerDialog()->setSyncMode( true );
2016 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 2016 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
2017 getEventViewerDialog()->setSyncMode( false ); 2017 getEventViewerDialog()->setSyncMode( false );
2018 qApp->processEvents(); 2018 qApp->processEvents();
2019 if ( syncOK ) { 2019 if ( syncOK ) {
2020 if ( mSyncManager->mWriteBackFile ) 2020 if ( mSyncManager->mWriteBackFile )
2021 { 2021 {
2022 // write back XML file 2022 // write back XML file
2023 2023
2024 } 2024 }
2025 setModified( true ); 2025 setModified( true );
2026 } 2026 }
2027 } else { 2027 } else {
2028 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 2028 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
2029 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 2029 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
2030 question, i18n("Ok")) ; 2030 question, i18n("Ok")) ;
2031 } 2031 }
2032 delete calendar; 2032 delete calendar;
2033 updateView(); 2033 updateView();
2034 return syncOK; 2034 return syncOK;
2035 2035
2036 2036
2037#endif 2037#endif
2038 2038
2039} 2039}
2040 2040
2041void CalendarView::setSyncEventsReadOnly() 2041void CalendarView::setSyncEventsReadOnly()
2042{ 2042{
2043 mCalendar->setSyncEventsReadOnly(); 2043 mCalendar->setSyncEventsReadOnly();
2044} 2044}
2045 2045
2046bool CalendarView::loadCalendars() 2046bool CalendarView::loadCalendars()
2047{ 2047{
2048 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2048 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2049 KopiCalendarFile * cal = calendars.first(); 2049 KopiCalendarFile * cal = calendars.first();
2050 mCalendar->setDefaultCalendar( 1 ); 2050 mCalendar->setDefaultCalendar( 1 );
2051 openCalendar( MainWindow::defaultFileName(), false ); 2051 openCalendar( MainWindow::defaultFileName(), false );
2052 cal = calendars.next(); 2052 cal = calendars.next();
2053 while ( cal ) { 2053 while ( cal ) {
2054 addCalendar( cal ); 2054 addCalendar( cal );
2055 cal = calendars.next(); 2055 cal = calendars.next();
2056 } 2056 }
2057 restoreCalendarSettings(); 2057 restoreCalendarSettings();
2058 return true; 2058 return true;
2059} 2059}
2060bool CalendarView::restoreCalendarSettings() 2060bool CalendarView::restoreCalendarSettings()
2061{ 2061{
2062 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2062 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2063 KopiCalendarFile * cal = calendars.first(); 2063 KopiCalendarFile * cal = calendars.first();
2064 while ( cal ) { 2064 while ( cal ) {
2065 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); 2065 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled );
2066 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); 2066 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled );
2067 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); 2067 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly );
2068 if ( cal->isStandard ) 2068 if ( cal->isStandard )
2069 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2069 mCalendar->setDefaultCalendar( cal->mCalNumber );
2070 cal = calendars.next(); 2070 cal = calendars.next();
2071 } 2071 }
2072 setSyncEventsReadOnly(); 2072 setSyncEventsReadOnly();
2073 mCalendar->reInitAlarmSettings(); 2073 mCalendar->reInitAlarmSettings();
2074 updateUnmanagedViews(); 2074 updateUnmanagedViews();
2075 updateView(); 2075 updateView();
2076 return true; 2076 return true;
2077} 2077}
2078void CalendarView::addCalendarId( int id ) 2078void CalendarView::addCalendarId( int id )
2079{ 2079{
2080 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); 2080 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id );
2081 if ( cal ) 2081 if ( cal )
2082 addCalendar( cal ); 2082 addCalendar( cal );
2083} 2083}
2084bool CalendarView::addCalendar( KopiCalendarFile * cal ) 2084bool CalendarView::addCalendar( KopiCalendarFile * cal )
2085{ 2085{
2086 cal->mErrorOnLoad = false; 2086 cal->mErrorOnLoad = false;
2087 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { 2087 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) {
2088 cal->mLoadDt = QDateTime::currentDateTime(); 2088 cal->mLoadDt = QDateTime::currentDateTime();
2089 return true; 2089 return true;
2090 } 2090 }
2091 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() ); 2091 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() );
2092 cal->mErrorOnLoad = true; 2092 cal->mErrorOnLoad = true;
2093 return false; 2093 return false;
2094} 2094}
2095bool CalendarView::openCalendar(QString filename, bool merge) 2095bool CalendarView::openCalendar(QString filename, bool merge)
2096{ 2096{
2097 2097
2098 if (filename.isEmpty()) { 2098 if (filename.isEmpty()) {
2099 return false; 2099 return false;
2100 } 2100 }
2101 2101
2102 if (!QFile::exists(filename)) { 2102 if (!QFile::exists(filename)) {
2103 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 2103 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
2104 return false; 2104 return false;
2105 } 2105 }
2106 2106
2107 globalFlagBlockAgenda = 1; 2107 globalFlagBlockAgenda = 1;
2108 clearAllViews(); 2108 clearAllViews();
2109 if (!merge) { 2109 if (!merge) {
2110 mViewManager->setDocumentId( filename ); 2110 mViewManager->setDocumentId( filename );
2111 mCalendar->close(); 2111 mCalendar->close();
2112 } 2112 }
2113 mStorage->setFileName( filename ); 2113 mStorage->setFileName( filename );
2114 2114
2115 if ( mStorage->load() ) { 2115 if ( mStorage->load() ) {
2116 if ( merge ) ;//setModified( true ); 2116 if ( merge ) ;//setModified( true );
2117 else { 2117 else {
2118 //setModified( true ); 2118 //setModified( true );
2119 mViewManager->setDocumentId( filename ); 2119 mViewManager->setDocumentId( filename );
2120 mDialogManager->setDocumentId( filename ); 2120 mDialogManager->setDocumentId( filename );
2121 mTodoList->setDocumentId( filename ); 2121 mTodoList->setDocumentId( filename );
2122 } 2122 }
2123 globalFlagBlockAgenda = 2; 2123 globalFlagBlockAgenda = 2;
2124 // if ( getLastSyncEvent() ) 2124 // if ( getLastSyncEvent() )
2125 // getLastSyncEvent()->setReadOnly( true ); 2125 // getLastSyncEvent()->setReadOnly( true );
2126 mCalendar->reInitAlarmSettings(); 2126 mCalendar->reInitAlarmSettings();
2127 setSyncEventsReadOnly(); 2127 setSyncEventsReadOnly();
2128 updateUnmanagedViews(); 2128 updateUnmanagedViews();
2129 updateView(); 2129 updateView();
2130 if ( filename != MainWindow::defaultFileName() ) { 2130 if ( filename != MainWindow::defaultFileName() ) {
2131 saveCalendar( MainWindow::defaultFileName() ); 2131 saveCalendar( MainWindow::defaultFileName() );
2132 } else { 2132 } else {
2133 QFileInfo finf ( MainWindow::defaultFileName()); 2133 QFileInfo finf ( MainWindow::defaultFileName());
2134 if ( finf.exists() ) { 2134 if ( finf.exists() ) {
2135 setLoadedFileVersion( finf.lastModified () ); 2135 setLoadedFileVersion( finf.lastModified () );
2136 } 2136 }
2137 } 2137 }
2138 return true; 2138 return true;
2139 } else { 2139 } else {
2140 // while failing to load, the calendar object could 2140 // while failing to load, the calendar object could
2141 // have become partially populated. Clear it out. 2141 // have become partially populated. Clear it out.
2142 if ( !merge ) { 2142 if ( !merge ) {
2143 mCalendar->close(); 2143 mCalendar->close();
2144 mViewManager->setDocumentId( filename ); 2144 mViewManager->setDocumentId( filename );
2145 mDialogManager->setDocumentId( filename ); 2145 mDialogManager->setDocumentId( filename );
2146 mTodoList->setDocumentId( filename ); 2146 mTodoList->setDocumentId( filename );
2147 } 2147 }
2148 2148
2149 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 2149 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
2150 2150
2151 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 2151 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
2152 globalFlagBlockAgenda = 2; 2152 globalFlagBlockAgenda = 2;
2153 mCalendar->reInitAlarmSettings(); 2153 mCalendar->reInitAlarmSettings();
2154 setSyncEventsReadOnly(); 2154 setSyncEventsReadOnly();
2155 updateUnmanagedViews(); 2155 updateUnmanagedViews();
2156 updateView(); 2156 updateView();
2157 } 2157 }
2158 return false; 2158 return false;
2159} 2159}
2160void CalendarView::mergeFile( QString fn ) 2160void CalendarView::mergeFile( QString fn )
2161{ 2161{
2162 clearAllViews(); 2162 clearAllViews();
2163 mCalendar->mergeCalendarFile( fn ); 2163 mCalendar->mergeCalendarFile( fn );
2164 mCalendar->reInitAlarmSettings(); 2164 mCalendar->reInitAlarmSettings();
2165 setSyncEventsReadOnly(); 2165 setSyncEventsReadOnly();
2166 updateUnmanagedViews(); 2166 updateUnmanagedViews();
2167 updateView(); 2167 updateView();
2168} 2168}
2169void CalendarView::showOpenError() 2169void CalendarView::showOpenError()
2170{ 2170{
2171 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 2171 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
2172} 2172}
2173void CalendarView::setLoadedFileVersion(QDateTime dt) 2173void CalendarView::setLoadedFileVersion(QDateTime dt)
2174{ 2174{
2175 loadedFileVersion = dt; 2175 loadedFileVersion = dt;
2176} 2176}
2177bool CalendarView::checkFileChanged(QString fn) 2177bool CalendarView::checkFileChanged(QString fn)
2178{ 2178{
2179 QFileInfo finf ( fn ); 2179 QFileInfo finf ( fn );
2180 if ( !finf.exists() ) 2180 if ( !finf.exists() )
2181 return true; 2181 return true;
2182 QDateTime dt = finf.lastModified (); 2182 QDateTime dt = finf.lastModified ();
2183 if ( dt <= loadedFileVersion ) 2183 if ( dt <= loadedFileVersion )
2184 return false; 2184 return false;
2185 return true; 2185 return true;
2186 2186
2187} 2187}
2188void CalendarView::watchSavedFile() 2188void CalendarView::watchSavedFile()
2189{ 2189{
2190 QFileInfo finf ( MainWindow::defaultFileName()); 2190 QFileInfo finf ( MainWindow::defaultFileName());
2191 if ( !finf.exists() ) 2191 if ( !finf.exists() )
2192 return; 2192 return;
2193 QDateTime dt = finf.lastModified (); 2193 QDateTime dt = finf.lastModified ();
2194 if ( dt < loadedFileVersion ) { 2194 if ( dt < loadedFileVersion ) {
2195 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 2195 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
2196 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 2196 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
2197 return; 2197 return;
2198 } 2198 }
2199 loadedFileVersion = dt; 2199 loadedFileVersion = dt;
2200} 2200}
2201bool CalendarView::checkAllFileVersions() 2201bool CalendarView::checkAllFileVersions()
2202{ 2202{
2203 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2203 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2204 KopiCalendarFile * cal = calendars.first(); 2204 KopiCalendarFile * cal = calendars.first();
2205 mCalendar->setDefaultCalendar( 1 ); 2205 mCalendar->setDefaultCalendar( 1 );
2206 mCalendar->setDefaultCalendarEnabledOnly(); 2206 mCalendar->setDefaultCalendarEnabledOnly();
2207 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2207 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2208 if ( !checkFileVersion(MainWindow::defaultFileName())) { 2208 if ( !checkFileVersion(MainWindow::defaultFileName())) {
2209 restoreCalendarSettings(); 2209 restoreCalendarSettings();
2210 return false; 2210 return false;
2211 } 2211 }
2212 } 2212 }
2213 cal = calendars.next(); 2213 cal = calendars.next();
2214 QDateTime storeTemp = loadedFileVersion; 2214 QDateTime storeTemp = loadedFileVersion;
2215 while ( cal ) { 2215 while ( cal ) {
2216 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2216 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2217 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2217 mCalendar->setDefaultCalendar( cal->mCalNumber );
2218 mCalendar->setDefaultCalendarEnabledOnly(); 2218 mCalendar->setDefaultCalendarEnabledOnly();
2219 loadedFileVersion = cal->mLoadDt.addSecs( 15 ); 2219 loadedFileVersion = cal->mLoadDt.addSecs( 15 );
2220 if ( !checkFileVersion(cal->mFileName )) { 2220 if ( !checkFileVersion(cal->mFileName )) {
2221 loadedFileVersion = storeTemp; 2221 loadedFileVersion = storeTemp;
2222 restoreCalendarSettings(); 2222 restoreCalendarSettings();
2223 return false; 2223 return false;
2224 } 2224 }
2225 } 2225 }
2226 cal = calendars.next(); 2226 cal = calendars.next();
2227 } 2227 }
2228 loadedFileVersion = storeTemp; 2228 loadedFileVersion = storeTemp;
2229 return true; 2229 return true;
2230} 2230}
2231bool CalendarView::checkFileVersion(QString fn) 2231bool CalendarView::checkFileVersion(QString fn)
2232{ 2232{
2233 QFileInfo finf ( fn ); 2233 QFileInfo finf ( fn );
2234 if ( !finf.exists() ) 2234 if ( !finf.exists() )
2235 return true; 2235 return true;
2236 QDateTime dt = finf.lastModified (); 2236 QDateTime dt = finf.lastModified ();
2237 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); 2237 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1());
2238 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); 2238 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1());
2239 if ( dt <= loadedFileVersion ) 2239 if ( dt <= loadedFileVersion )
2240 return true; 2240 return true;
2241 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\non disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(KGlobal::formatMessage(fn,0)).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , 2241 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\non disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(KGlobal::formatMessage(fn,0)).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
2242 i18n("KO/Pi Warning"),i18n("Overwrite"), 2242 i18n("KO/Pi Warning"),i18n("Overwrite"),
2243 i18n("Sync+save")); 2243 i18n("Sync+save"));
2244 2244
2245 if ( km == KMessageBox::Cancel ) 2245 if ( km == KMessageBox::Cancel )
2246 return false; 2246 return false;
2247 if ( km == KMessageBox::Yes ) 2247 if ( km == KMessageBox::Yes )
2248 return true; 2248 return true;
2249 2249
2250 setSyncDevice("deleteaftersync" ); 2250 setSyncDevice("deleteaftersync" );
2251 mSyncManager->mAskForPreferences = true; 2251 mSyncManager->mAskForPreferences = true;
2252 mSyncManager->mSyncAlgoPrefs = 3; 2252 mSyncManager->mSyncAlgoPrefs = 3;
2253 mSyncManager->mWriteBackFile = false; 2253 mSyncManager->mWriteBackFile = false;
2254 mSyncManager->mWriteBackExistingOnly = false; 2254 mSyncManager->mWriteBackExistingOnly = false;
2255 mSyncManager->mShowSyncSummary = false; 2255 mSyncManager->mShowSyncSummary = false;
2256 syncCalendar( fn, 3 ); 2256 syncCalendar( fn, 3 );
2257 Event * e = getLastSyncEvent(); 2257 Event * e = getLastSyncEvent();
2258 if ( e ) 2258 if ( e )
2259 mCalendar->deleteEvent( e ); 2259 mCalendar->deleteEvent( e );
2260 return true; 2260 return true;
2261} 2261}
2262bool CalendarView::saveCalendars() 2262bool CalendarView::saveCalendars()
2263{ 2263{
2264 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2264 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2265 KopiCalendarFile * cal = calendars.first(); 2265 KopiCalendarFile * cal = calendars.first();
2266 mCalendar->setDefaultCalendar( 1 ); 2266 mCalendar->setDefaultCalendar( 1 );
2267 mCalendar->setDefaultCalendarEnabledOnly(); 2267 mCalendar->setDefaultCalendarEnabledOnly();
2268 saveCalendar( MainWindow::defaultFileName() ); 2268 saveCalendar( MainWindow::defaultFileName() );
2269 cal = calendars.next(); 2269 cal = calendars.next();
2270 while ( cal ) { 2270 while ( cal ) {
2271 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2271 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2272 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2272 mCalendar->setDefaultCalendar( cal->mCalNumber );
2273 mCalendar->setDefaultCalendarEnabledOnly(); 2273 mCalendar->setDefaultCalendarEnabledOnly();
2274 if ( saveCalendar( cal->mFileName ) ) 2274 if ( saveCalendar( cal->mFileName ) )
2275 cal->mLoadDt = QDateTime::currentDateTime(); 2275 cal->mLoadDt = QDateTime::currentDateTime();
2276 } 2276 }
2277 cal = calendars.next(); 2277 cal = calendars.next();
2278 } 2278 }
2279 restoreCalendarSettings(); 2279 restoreCalendarSettings();
2280 return true; 2280 return true;
2281} 2281}
2282bool CalendarView::saveCalendar( QString filename ) 2282bool CalendarView::saveCalendar( QString filename )
2283{ 2283{
2284 2284
2285 // Store back all unsaved data into calendar object 2285 // Store back all unsaved data into calendar object
2286 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 2286 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
2287 if ( mViewManager->currentView() ) 2287 if ( mViewManager->currentView() )
2288 mViewManager->currentView()->flushView(); 2288 mViewManager->currentView()->flushView();
2289 2289
2290 2290
2291 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 2291 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
2292 mStorage->setSaveFormat( new ICalFormat() ); 2292 mStorage->setSaveFormat( new ICalFormat() );
2293 mStorage->setFileName( filename ); 2293 mStorage->setFileName( filename );
2294 bool success; 2294 bool success;
2295 success = mStorage->save(); 2295 success = mStorage->save();
2296 if ( !success ) { 2296 if ( !success ) {
2297 return false; 2297 return false;
2298 } 2298 }
2299 if ( filename == MainWindow::defaultFileName() ) { 2299 if ( filename == MainWindow::defaultFileName() ) {
2300 setLoadedFileVersion( lfv ); 2300 setLoadedFileVersion( lfv );
2301 watchSavedFile(); 2301 watchSavedFile();
2302 } 2302 }
2303 return true; 2303 return true;
2304} 2304}
2305 2305
2306void CalendarView::closeCalendar() 2306void CalendarView::closeCalendar()
2307{ 2307{
2308 2308
2309 // child windows no longer valid 2309 // child windows no longer valid
2310 clearAllViews(); 2310 clearAllViews();
2311 emit closingDown(); 2311 emit closingDown();
2312 2312
2313 mCalendar->close(); 2313 mCalendar->close();
2314 setModified(false); 2314 setModified(false);
2315 updateView(); 2315 updateView();
2316} 2316}
2317 2317
2318void CalendarView::archiveCalendar() 2318void CalendarView::archiveCalendar()
2319{ 2319{
2320 mDialogManager->showArchiveDialog(); 2320 mDialogManager->showArchiveDialog();
2321} 2321}
2322 2322
2323 2323
2324void CalendarView::readSettings() 2324void CalendarView::readSettings()
2325{ 2325{
2326 2326
2327 2327
2328 // mViewManager->showAgendaView(); 2328 // mViewManager->showAgendaView();
2329 QString str; 2329 QString str;
2330 //qDebug("CalendarView::readSettings() "); 2330 //qDebug("CalendarView::readSettings() ");
2331 // read settings from the KConfig, supplying reasonable 2331 // read settings from the KConfig, supplying reasonable
2332 // defaults where none are to be found 2332 // defaults where none are to be found
2333 KConfig *config = KOGlobals::config(); 2333 KConfig *config = KOGlobals::config();
2334#ifndef KORG_NOSPLITTER 2334#ifndef KORG_NOSPLITTER
2335 config->setGroup("KOrganizer Geometry"); 2335 config->setGroup("KOrganizer Geometry");
2336 2336
2337 QValueList<int> sizes = config->readIntListEntry("Separator1"); 2337 QValueList<int> sizes = config->readIntListEntry("Separator1");
2338 if (sizes.count() != 2) { 2338 if (sizes.count() != 2) {
2339 sizes << mDateNavigator->minimumSizeHint().width(); 2339 sizes << mDateNavigator->minimumSizeHint().width();
2340 sizes << 300; 2340 sizes << 300;
2341 } 2341 }
2342 mPanner->setSizes(sizes); 2342 mPanner->setSizes(sizes);
2343 2343
2344 sizes = config->readIntListEntry("Separator2"); 2344 sizes = config->readIntListEntry("Separator2");
2345 if ( ( mResourceView && sizes.count() == 4 ) || 2345 if ( ( mResourceView && sizes.count() == 4 ) ||
2346 ( !mResourceView && sizes.count() == 3 ) ) { 2346 ( !mResourceView && sizes.count() == 3 ) ) {
2347 mLeftSplitter->setSizes(sizes); 2347 mLeftSplitter->setSizes(sizes);
2348 } 2348 }
2349#endif 2349#endif
2350 globalFlagBlockAgenda = 1; 2350 globalFlagBlockAgenda = 1;
2351 mViewManager->showAgendaView(); 2351 mViewManager->showAgendaView();
2352 //mViewManager->readSettings( config ); 2352 //mViewManager->readSettings( config );
2353 mTodoList->restoreLayout(config,QString("Todo Layout")); 2353 mTodoList->restoreLayout(config,QString("Todo Layout"));
2354 readFilterSettings(config); 2354 readFilterSettings(config);
2355 2355
2356#ifdef DESKTOP_VERSION 2356#ifdef DESKTOP_VERSION
2357 config->setGroup("WidgetLayout"); 2357 config->setGroup("WidgetLayout");
2358 QStringList list; 2358 QStringList list;
2359 list = config->readListEntry("MainLayout"); 2359 list = config->readListEntry("MainLayout");
2360 int x,y,w,h; 2360 int x,y,w,h;
2361 if ( ! list.isEmpty() ) { 2361 if ( ! list.isEmpty() ) {
2362 x = list[0].toInt(); 2362 x = list[0].toInt();
2363 y = list[1].toInt(); 2363 y = list[1].toInt();
2364 w = list[2].toInt(); 2364 w = list[2].toInt();
2365 h = list[3].toInt(); 2365 h = list[3].toInt();
2366 KApplication::testCoords( &x,&y,&w,&h ); 2366 KApplication::testCoords( &x,&y,&w,&h );
2367 topLevelWidget()->setGeometry(x,y,w,h); 2367 topLevelWidget()->setGeometry(x,y,w,h);
2368 2368
2369 } else { 2369 } else {
2370 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 2370 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
2371 } 2371 }
2372 list = config->readListEntry("EditEventLayout"); 2372 list = config->readListEntry("EditEventLayout");
2373 if ( ! list.isEmpty() ) { 2373 if ( ! list.isEmpty() ) {
2374 x = list[0].toInt(); 2374 x = list[0].toInt();
2375 y = list[1].toInt(); 2375 y = list[1].toInt();
2376 w = list[2].toInt(); 2376 w = list[2].toInt();
2377 h = list[3].toInt(); 2377 h = list[3].toInt();
2378 KApplication::testCoords( &x,&y,&w,&h ); 2378 KApplication::testCoords( &x,&y,&w,&h );
2379 mEventEditor->setGeometry(x,y,w,h); 2379 mEventEditor->setGeometry(x,y,w,h);
2380 2380
2381 } 2381 }
2382 list = config->readListEntry("EditTodoLayout"); 2382 list = config->readListEntry("EditTodoLayout");
2383 if ( ! list.isEmpty() ) { 2383 if ( ! list.isEmpty() ) {
2384 x = list[0].toInt(); 2384 x = list[0].toInt();
2385 y = list[1].toInt(); 2385 y = list[1].toInt();
2386 w = list[2].toInt(); 2386 w = list[2].toInt();
2387 h = list[3].toInt(); 2387 h = list[3].toInt();
2388 KApplication::testCoords( &x,&y,&w,&h ); 2388 KApplication::testCoords( &x,&y,&w,&h );
2389 mTodoEditor->setGeometry(x,y,w,h); 2389 mTodoEditor->setGeometry(x,y,w,h);
2390 2390
2391 } 2391 }
2392 list = config->readListEntry("ViewerLayout"); 2392 list = config->readListEntry("ViewerLayout");
2393 if ( ! list.isEmpty() ) { 2393 if ( ! list.isEmpty() ) {
2394 x = list[0].toInt(); 2394 x = list[0].toInt();
2395 y = list[1].toInt(); 2395 y = list[1].toInt();
2396 w = list[2].toInt(); 2396 w = list[2].toInt();
2397 h = list[3].toInt(); 2397 h = list[3].toInt();
2398 KApplication::testCoords( &x,&y,&w,&h ); 2398 KApplication::testCoords( &x,&y,&w,&h );
2399 getEventViewerDialog()->setGeometry(x,y,w,h); 2399 getEventViewerDialog()->setGeometry(x,y,w,h);
2400 } 2400 }
2401#endif 2401#endif
2402 config->setGroup( "Views" ); 2402 config->setGroup( "Views" );
2403 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 2403 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
2404 2404
2405 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame"); 2405 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame");
2406 2406
2407 int resetval = 0; 2407 int resetval = 0;
2408 int maxVal = 0; 2408 int maxVal = 0;
2409 if (sizes.count() != 3) { 2409 if (sizes.count() != 3) {
2410 if ( KOPrefs::instance()->mVerticalScreen ) { 2410 if ( KOPrefs::instance()->mVerticalScreen ) {
2411 resetval = mDateNavigator->sizeHint().width()+2; 2411 resetval = mDateNavigator->sizeHint().width()+2;
2412 } else { 2412 } else {
2413 resetval = mDateNavigator->sizeHint().height()+2; 2413 resetval = mDateNavigator->sizeHint().height()+2;
2414 } 2414 }
2415 } 2415 }
2416 if ( resetval ) { 2416 if ( resetval ) {
2417 sizes.clear(); 2417 sizes.clear();
2418 if ( KOPrefs::instance()->mVerticalScreen ) { 2418 if ( KOPrefs::instance()->mVerticalScreen ) {
2419 maxVal = QApplication::desktop()->width() -10; 2419 maxVal = QApplication::desktop()->width() -10;
2420 } else { 2420 } else {
2421 maxVal = QApplication::desktop()->height()-10; 2421 maxVal = QApplication::desktop()->height()-10;
2422 } 2422 }
2423 sizes << resetval; 2423 sizes << resetval;
2424 if ( maxVal < resetval + resetval) 2424 if ( maxVal < resetval + resetval)
2425 resetval = maxVal - resetval; 2425 resetval = maxVal - resetval;
2426 sizes << resetval; 2426 sizes << resetval;
2427 sizes << 100; 2427 sizes << 100;
2428 } 2428 }
2429 mLeftFrame->setSizes(sizes); 2429 mLeftFrame->setSizes(sizes);
2430 sizes = config->readIntListEntry("Main Splitter Frame"); 2430 sizes = config->readIntListEntry("Main Splitter Frame");
2431 resetval = 0; 2431 resetval = 0;
2432 maxVal = 0; 2432 maxVal = 0;
2433 if (sizes.count() != 2) { 2433 if (sizes.count() != 2) {
2434 if ( !KOPrefs::instance()->mVerticalScreen ) { 2434 if ( !KOPrefs::instance()->mVerticalScreen ) {
2435 resetval = mDateNavigator->sizeHint().width()+2; 2435 resetval = mDateNavigator->sizeHint().width()+2;
2436 } else { 2436 } else {
2437 resetval = mDateNavigator->sizeHint().height()+2; 2437 resetval = mDateNavigator->sizeHint().height()+2;
2438 } 2438 }
2439 } 2439 }
2440 if ( resetval ) { 2440 if ( resetval ) {
2441 sizes.clear(); 2441 sizes.clear();
2442 if ( !KOPrefs::instance()->mVerticalScreen ) { 2442 if ( !KOPrefs::instance()->mVerticalScreen ) {
2443 maxVal = QApplication::desktop()->width() -10; 2443 maxVal = QApplication::desktop()->width() -10;
2444 } else { 2444 } else {
2445 maxVal = QApplication::desktop()->height()-10; 2445 maxVal = QApplication::desktop()->height()-10;
2446 } 2446 }
2447 sizes << resetval; 2447 sizes << resetval;
2448 if ( maxVal < resetval + resetval) 2448 if ( maxVal < resetval + resetval)
2449 resetval = maxVal - resetval; 2449 resetval = maxVal - resetval;
2450 sizes << resetval; 2450 sizes << resetval;
2451 } 2451 }
2452 mMainFrame->setSizes(sizes); 2452 mMainFrame->setSizes(sizes);
2453 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 2453 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
2454 else if ( dateCount == 7 ) mNavigator->selectWeek(); 2454 else if ( dateCount == 7 ) mNavigator->selectWeek();
2455 else mNavigator->selectDates( dateCount ); 2455 else mNavigator->selectDates( dateCount );
2456 // mViewManager->readSettings( config ); 2456 // mViewManager->readSettings( config );
2457 updateConfig(); 2457 updateConfig();
2458 globalFlagBlockAgenda = 2; 2458 globalFlagBlockAgenda = 2;
2459 mViewManager->readSettings( config ); 2459 mViewManager->readSettings( config );
2460 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) ); 2460 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) );
2461} 2461}
2462 2462
2463void CalendarView::checkSuspendAlarm() 2463void CalendarView::checkSuspendAlarm()
2464{ 2464{
2465 if ( mSuspendTimer->isActive() ) { 2465 if ( mSuspendTimer->isActive() ) {
2466 KMessageBox::information( this, i18n("<b>WARNING:</b> There is a pending suspended alarm!"), i18n("Pending Suspend Alarm")); 2466 KMessageBox::information( this, i18n("<b>WARNING:</b> There is a pending suspended alarm!"), i18n("Pending Suspend Alarm"));
2467 } 2467 }
2468} 2468}
2469void CalendarView::writeSettings() 2469void CalendarView::writeSettings()
2470{ 2470{
2471 // kdDebug() << "CalendarView::writeSettings" << endl; 2471 // kdDebug() << "CalendarView::writeSettings" << endl;
2472 2472
2473 KConfig *config = KOGlobals::config(); 2473 KConfig *config = KOGlobals::config();
2474 2474
2475 mViewManager->writeSettings( config ); 2475 mViewManager->writeSettings( config );
2476 mTodoList->saveLayout(config,QString("Todo Layout")); 2476 mTodoList->saveLayout(config,QString("Todo Layout"));
2477 mDialogManager->writeSettings( config ); 2477 mDialogManager->writeSettings( config );
2478 //KOPrefs::instance()->usrWriteConfig(); 2478 //KOPrefs::instance()->usrWriteConfig();
2479 KOPrefs::instance()->writeConfig(); 2479 KOPrefs::instance()->writeConfig();
2480 2480
2481 writeFilterSettings(config); 2481 writeFilterSettings(config);
2482 config->setGroup( "AppRun" ); 2482 config->setGroup( "AppRun" );
2483 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 2483 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
2484 int days = dt.daysTo( QDate::currentDate() ); 2484 int days = dt.daysTo( QDate::currentDate() );
2485 dt = dt.addDays( days ); 2485 dt = dt.addDays( days );
2486 int secs = dt.secsTo( QDateTime::currentDateTime() ); 2486 int secs = dt.secsTo( QDateTime::currentDateTime() );
2487 config->writeEntry( "LatestProgramStopDays", days ); 2487 config->writeEntry( "LatestProgramStopDays", days );
2488 config->writeEntry( "LatestProgramStopSecs", secs ); 2488 config->writeEntry( "LatestProgramStopSecs", secs );
2489 //qDebug("KO: Writing stop time: %d ", secs); 2489 //qDebug("KO: Writing stop time: %d ", secs);
2490 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 2490 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
2491 //QDateTime latest = dt.addSecs ( secs ); 2491 //QDateTime latest = dt.addSecs ( secs );
2492 //qDebug("KO: Termination on %s ", latest.toString().latin1()); 2492 //qDebug("KO: Termination on %s ", latest.toString().latin1());
2493 config->setGroup( "Views" ); 2493 config->setGroup( "Views" );
2494 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 2494 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
2495 2495
2496#if 0 2496#if 0
2497 qDebug("********************* "); 2497 qDebug("********************* ");
2498 qDebug("Testcode secsto "); 2498 qDebug("Testcode secsto ");
2499 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) ); 2499 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) );
2500 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) ); 2500 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) );
2501 int secsto = dt_nodaylight.secsTo( dt_daylight ); 2501 int secsto = dt_nodaylight.secsTo( dt_daylight );
2502 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto ); 2502 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto );
2503 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() ); 2503 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() );
2504 qDebug("dt daylight %s ",dt_daylight.toString().latin1() ); 2504 qDebug("dt daylight %s ",dt_daylight.toString().latin1() );
2505 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() ); 2505 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() );
2506 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600); 2506 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600);
2507 qDebug("********************* testcode end"); 2507 qDebug("********************* testcode end");
2508 2508
2509#endif 2509#endif
2510 2510
2511 QValueList<int> listINT = mLeftFrame->sizes(); 2511 QValueList<int> listINT = mLeftFrame->sizes();
2512 config->writeEntry("Left Splitter Frame",listINT); 2512 config->writeEntry("Left Splitter Frame",listINT);
2513 QValueList<int> listINT2 = mMainFrame->sizes(); 2513 QValueList<int> listINT2 = mMainFrame->sizes();
2514 config->writeEntry("Main Splitter Frame",listINT2); 2514 config->writeEntry("Main Splitter Frame",listINT2);
2515#ifdef DESKTOP_VERSION 2515#ifdef DESKTOP_VERSION
2516 config->setGroup("WidgetLayout"); 2516 config->setGroup("WidgetLayout");
2517 QStringList list ;//= config->readListEntry("MainLayout"); 2517 QStringList list ;//= config->readListEntry("MainLayout");
2518 int x,y,w,h; 2518 int x,y,w,h;
2519 QWidget* wid; 2519 QWidget* wid;
2520 wid = topLevelWidget(); 2520 wid = topLevelWidget();
2521 x = wid->geometry().x(); 2521 x = wid->geometry().x();
2522 y = wid->geometry().y(); 2522 y = wid->geometry().y();
2523 w = wid->width(); 2523 w = wid->width();
2524 h = wid->height(); 2524 h = wid->height();
2525 list.clear(); 2525 list.clear();
2526 list << QString::number( x ); 2526 list << QString::number( x );
2527 list << QString::number( y ); 2527 list << QString::number( y );
2528 list << QString::number( w ); 2528 list << QString::number( w );
2529 list << QString::number( h ); 2529 list << QString::number( h );
2530 config->writeEntry("MainLayout",list ); 2530 config->writeEntry("MainLayout",list );
2531 2531
2532 wid = mEventEditor; 2532 wid = mEventEditor;
2533 x = wid->geometry().x(); 2533 x = wid->geometry().x();
2534 y = wid->geometry().y(); 2534 y = wid->geometry().y();
2535 w = wid->width(); 2535 w = wid->width();
2536 h = wid->height(); 2536 h = wid->height();
2537 list.clear(); 2537 list.clear();
2538 list << QString::number( x ); 2538 list << QString::number( x );
2539 list << QString::number( y ); 2539 list << QString::number( y );
2540 list << QString::number( w ); 2540 list << QString::number( w );
2541 list << QString::number( h ); 2541 list << QString::number( h );
2542 config->writeEntry("EditEventLayout",list ); 2542 config->writeEntry("EditEventLayout",list );
2543 2543
2544 wid = mTodoEditor; 2544 wid = mTodoEditor;
2545 x = wid->geometry().x(); 2545 x = wid->geometry().x();
2546 y = wid->geometry().y(); 2546 y = wid->geometry().y();
2547 w = wid->width(); 2547 w = wid->width();
2548 h = wid->height(); 2548 h = wid->height();
2549 list.clear(); 2549 list.clear();
2550 list << QString::number( x ); 2550 list << QString::number( x );
2551 list << QString::number( y ); 2551 list << QString::number( y );
2552 list << QString::number( w ); 2552 list << QString::number( w );
2553 list << QString::number( h ); 2553 list << QString::number( h );
2554 config->writeEntry("EditTodoLayout",list ); 2554 config->writeEntry("EditTodoLayout",list );
2555 wid = getEventViewerDialog(); 2555 wid = getEventViewerDialog();
2556 x = wid->geometry().x(); 2556 x = wid->geometry().x();
2557 y = wid->geometry().y(); 2557 y = wid->geometry().y();
2558 w = wid->width(); 2558 w = wid->width();
2559 h = wid->height(); 2559 h = wid->height();
2560 list.clear(); 2560 list.clear();
2561 list << QString::number( x ); 2561 list << QString::number( x );
2562 list << QString::number( y ); 2562 list << QString::number( y );
2563 list << QString::number( w ); 2563 list << QString::number( w );
2564 list << QString::number( h ); 2564 list << QString::number( h );
2565 config->writeEntry("ViewerLayout",list ); 2565 config->writeEntry("ViewerLayout",list );
2566 wid = mDialogManager->getSearchDialog(); 2566 wid = mDialogManager->getSearchDialog();
2567 if ( wid ) { 2567 if ( wid ) {
2568 x = wid->geometry().x(); 2568 x = wid->geometry().x();
2569 y = wid->geometry().y(); 2569 y = wid->geometry().y();
2570 w = wid->width(); 2570 w = wid->width();
2571 h = wid->height(); 2571 h = wid->height();
2572 list.clear(); 2572 list.clear();
2573 list << QString::number( x ); 2573 list << QString::number( x );
2574 list << QString::number( y ); 2574 list << QString::number( y );
2575 list << QString::number( w ); 2575 list << QString::number( w );
2576 list << QString::number( h ); 2576 list << QString::number( h );
2577 config->writeEntry("SearchLayout",list ); 2577 config->writeEntry("SearchLayout",list );
2578 } 2578 }
2579#endif 2579#endif
2580 2580
2581 2581
2582 config->sync(); 2582 config->sync();
2583} 2583}
2584 2584
2585void CalendarView::readFilterSettings(KConfig *config) 2585void CalendarView::readFilterSettings(KConfig *config)
2586{ 2586{
2587 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 2587 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
2588 2588
2589 mFilters.clear(); 2589 mFilters.clear();
2590 2590
2591 config->setGroup("General"); 2591 config->setGroup("General");
2592 QStringList filterList = config->readListEntry("CalendarFilters"); 2592 QStringList filterList = config->readListEntry("CalendarFilters");
2593 2593
2594 QStringList::ConstIterator it = filterList.begin(); 2594 QStringList::ConstIterator it = filterList.begin();
2595 QStringList::ConstIterator end = filterList.end(); 2595 QStringList::ConstIterator end = filterList.end();
2596 while(it != end) { 2596 while(it != end) {
2597 // kdDebug() << " filter: " << (*it) << endl; 2597 // kdDebug() << " filter: " << (*it) << endl;
2598 2598
2599 CalFilter *filter; 2599 CalFilter *filter;
2600 filter = new CalFilter(*it); 2600 filter = new CalFilter(*it);
2601 config->setGroup("Filter_" + (*it).utf8()); 2601 config->setGroup("Filter_" + (*it).utf8());
2602 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 2602 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
2603 filter->setCriteria(config->readNumEntry("Criteria",0)); 2603 filter->setCriteria(config->readNumEntry("Criteria",0));
2604 filter->setCategoryList(config->readListEntry("CategoryList")); 2604 filter->setCategoryList(config->readListEntry("CategoryList"));
2605 mFilters.append(filter); 2605 mFilters.append(filter);
2606 2606
2607 ++it; 2607 ++it;
2608 } 2608 }
2609 2609
2610 if (mFilters.count() == 0) { 2610 if (mFilters.count() == 0) {
2611 CalFilter *filter = new CalFilter(i18n("Default")); 2611 CalFilter *filter = new CalFilter(i18n("Default"));
2612 mFilters.append(filter); 2612 mFilters.append(filter);
2613 } 2613 }
2614 mFilterView->updateFilters(); 2614 mFilterView->updateFilters();
2615 config->setGroup("FilterView"); 2615 config->setGroup("FilterView");
2616 2616
2617 mFilterView->blockSignals(true); 2617 mFilterView->blockSignals(true);
2618 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 2618 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
2619 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 2619 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
2620 mFilterView->blockSignals(false); 2620 mFilterView->blockSignals(false);
2621 // We do it manually to avoid it being done twice by the above calls 2621 // We do it manually to avoid it being done twice by the above calls
2622 updateFilter(); 2622 updateFilter();
2623} 2623}
2624 2624
2625void CalendarView::writeFilterSettings(KConfig *config) 2625void CalendarView::writeFilterSettings(KConfig *config)
2626{ 2626{
2627 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 2627 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
2628 2628
2629 QStringList filterList; 2629 QStringList filterList;
2630 2630
2631 CalFilter *filter = mFilters.first(); 2631 CalFilter *filter = mFilters.first();
2632 while(filter) { 2632 while(filter) {
2633 // kdDebug() << " fn: " << filter->name() << endl; 2633 // kdDebug() << " fn: " << filter->name() << endl;
2634 filterList << filter->name(); 2634 filterList << filter->name();
2635 config->setGroup("Filter_" + filter->name().utf8()); 2635 config->setGroup("Filter_" + filter->name().utf8());
2636 config->writeEntry("Criteria",filter->criteria()); 2636 config->writeEntry("Criteria",filter->criteria());
2637 config->writeEntry("CategoryList",filter->categoryList()); 2637 config->writeEntry("CategoryList",filter->categoryList());
2638 filter = mFilters.next(); 2638 filter = mFilters.next();
2639 } 2639 }
2640 config->setGroup("General"); 2640 config->setGroup("General");
2641 config->writeEntry("CalendarFilters",filterList); 2641 config->writeEntry("CalendarFilters",filterList);
2642 2642
2643 config->setGroup("FilterView"); 2643 config->setGroup("FilterView");
2644 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 2644 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
2645 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 2645 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
2646} 2646}
2647 2647
2648 2648
2649void CalendarView::goToday() 2649void CalendarView::goToday()
2650{ 2650{
2651 if ( mViewManager->currentView()->isMonthView() ) 2651 if ( mViewManager->currentView()->isMonthView() )
2652 mNavigator->selectTodayMonth(); 2652 mNavigator->selectTodayMonth();
2653 else 2653 else
2654 mNavigator->selectToday(); 2654 mNavigator->selectToday();
2655} 2655}
2656 2656
2657void CalendarView::goNext() 2657void CalendarView::goNext()
2658{ 2658{
2659 mNavigator->selectNext(); 2659 mNavigator->selectNext();
2660} 2660}
2661 2661
2662void CalendarView::goPrevious() 2662void CalendarView::goPrevious()
2663{ 2663{
2664 mNavigator->selectPrevious(); 2664 mNavigator->selectPrevious();
2665} 2665}
2666void CalendarView::goNextMonth() 2666void CalendarView::goNextMonth()
2667{ 2667{
2668 mNavigator->selectNextMonth(); 2668 mNavigator->selectNextMonth();
2669} 2669}
2670 2670
2671void CalendarView::goPreviousMonth() 2671void CalendarView::goPreviousMonth()
2672{ 2672{
2673 mNavigator->selectPreviousMonth(); 2673 mNavigator->selectPreviousMonth();
2674} 2674}
2675 2675
2676void CalendarView::updateConfig() 2676void CalendarView::updateConfig()
2677{ 2677{
2678 if ( KOPrefs::instance()->mUseAppColors ) 2678 if ( KOPrefs::instance()->mUseAppColors )
2679 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 2679 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
2680 emit configChanged(); 2680 emit configChanged();
2681 mTodoList->updateConfig(); 2681 mTodoList->updateConfig();
2682 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 2682 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
2683 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2683 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2684 // To make the "fill window" configurations work 2684 // To make the "fill window" configurations work
2685 //mViewManager->raiseCurrentView(); 2685 //mViewManager->raiseCurrentView();
2686} 2686}
2687 2687
2688 2688
2689void CalendarView::eventChanged(Event *event) 2689void CalendarView::eventChanged(Event *event)
2690{ 2690{
2691 changeEventDisplay(event,KOGlobals::EVENTEDITED); 2691 changeEventDisplay(event,KOGlobals::EVENTEDITED);
2692 //updateUnmanagedViews(); 2692 //updateUnmanagedViews();
2693} 2693}
2694 2694
2695void CalendarView::eventAdded(Event *event) 2695void CalendarView::eventAdded(Event *event)
2696{ 2696{
2697 changeEventDisplay(event,KOGlobals::EVENTADDED); 2697 changeEventDisplay(event,KOGlobals::EVENTADDED);
2698} 2698}
2699 2699
2700void CalendarView::eventToBeDeleted(Event *) 2700void CalendarView::eventToBeDeleted(Event *)
2701{ 2701{
2702 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 2702 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
2703} 2703}
2704 2704
2705void CalendarView::eventDeleted() 2705void CalendarView::eventDeleted()
2706{ 2706{
2707 changeEventDisplay(0,KOGlobals::EVENTDELETED); 2707 changeEventDisplay(0,KOGlobals::EVENTDELETED);
2708} 2708}
2709void CalendarView::changeTodoDisplay(Todo *which, int action) 2709void CalendarView::changeTodoDisplay(Todo *which, int action)
2710{ 2710{
2711 changeIncidenceDisplay((Incidence *)which, action); 2711 changeIncidenceDisplay((Incidence *)which, action);
2712 mDateNavigator->updateView(); //LR 2712 mDateNavigator->updateView(); //LR
2713 //mDialogManager->updateSearchDialog(); 2713 //mDialogManager->updateSearchDialog();
2714 2714
2715 if (which) { 2715 if (which) {
2716 mViewManager->updateWNview(); 2716 mViewManager->updateWNview();
2717 //mTodoList->updateView(); 2717 //mTodoList->updateView();
2718 } 2718 }
2719 2719
2720} 2720}
2721 2721
2722void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 2722void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
2723{ 2723{
2724 updateUnmanagedViews(); 2724 updateUnmanagedViews();
2725 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 2725 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
2726 if ( action == KOGlobals::EVENTDELETED ) { //delete 2726 if ( action == KOGlobals::EVENTDELETED ) { //delete
2727 mCalendar->checkAlarmForIncidence( 0, true ); 2727 mCalendar->checkAlarmForIncidence( 0, true );
2728 if ( mEventViewerDialog ) 2728 if ( mEventViewerDialog )
2729 mEventViewerDialog->hide(); 2729 mEventViewerDialog->hide();
2730 } 2730 }
2731 else 2731 else
2732 mCalendar->checkAlarmForIncidence( which , false ); 2732 mCalendar->checkAlarmForIncidence( which , false );
2733} 2733}
2734 2734
2735// most of the changeEventDisplays() right now just call the view's 2735// most of the changeEventDisplays() right now just call the view's
2736// total update mode, but they SHOULD be recoded to be more refresh-efficient. 2736// total update mode, but they SHOULD be recoded to be more refresh-efficient.
2737void CalendarView::changeEventDisplay(Event *which, int action) 2737void CalendarView::changeEventDisplay(Event *which, int action)
2738{ 2738{
2739 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 2739 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
2740 changeIncidenceDisplay((Incidence *)which, action); 2740 changeIncidenceDisplay((Incidence *)which, action);
2741 static bool clearallviews = false; 2741 static bool clearallviews = false;
2742 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) { 2742 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) {
2743 if ( clearallviews ) { 2743 if ( clearallviews ) {
2744 clearAllViews(); 2744 clearAllViews();
2745 clearallviews = false; 2745 clearallviews = false;
2746 } 2746 }
2747 return; 2747 return;
2748 } 2748 }
2749 clearallviews = true; 2749 clearallviews = true;
2750 mDateNavigator->updateView(); 2750 mDateNavigator->updateView();
2751 //mDialogManager->updateSearchDialog(); 2751 //mDialogManager->updateSearchDialog();
2752 if (which) { 2752 if (which) {
2753 // If there is an event view visible update the display 2753 // If there is an event view visible update the display
2754 mViewManager->currentView()->changeEventDisplay(which,action); 2754 mViewManager->currentView()->changeEventDisplay(which,action);
2755 // TODO: check, if update needed 2755 // TODO: check, if update needed
2756 // if (which->getTodoStatus()) { 2756 // if (which->getTodoStatus()) {
2757 mTodoList->updateView(); 2757 mTodoList->updateView();
2758 if ( action != KOGlobals::EVENTDELETED ) { 2758 if ( action != KOGlobals::EVENTDELETED ) {
2759 mConflictingEvent = which ; 2759 mConflictingEvent = which ;
2760 QTimer::singleShot( 1000, this, SLOT ( checkConflictForEvent() ) ); 2760 QTimer::singleShot( 1000, this, SLOT ( checkConflictForEvent() ) );
2761 } 2761 }
2762 // } 2762 // }
2763 } else { 2763 } else {
2764 mViewManager->currentView()->updateView(); 2764 mViewManager->currentView()->updateView();
2765 } 2765 }
2766} 2766}
2767void CalendarView::checkConflictForEvent() 2767void CalendarView::checkConflictForEvent()
2768{ 2768{
2769 2769
2770 if (!KOPrefs::instance()->mConfirm) 2770 if (!KOPrefs::instance()->mConfirm)
2771 return; 2771 return;
2772 if ( ! mConflictingEvent ) return; 2772 if ( ! mConflictingEvent ) return;
2773 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); 2773 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") );
2774 QPtrList<Event> testlist = mCalendar->events(); 2774 QPtrList<Event> testlist = mCalendar->events();
2775 Event * test = testlist.first(); 2775 Event * test = testlist.first();
2776 QDateTime conflict; 2776 QDateTime conflict;
2777 QDateTime retVal; 2777 QDateTime retVal;
2778 bool found = false; 2778 bool found = false;
2779 Event * cE = 0; 2779 Event * cE = 0;
2780 QDateTime current = QDateTime::currentDateTime(); 2780 QDateTime current = QDateTime::currentDateTime();
2781 while ( test ) { 2781 while ( test ) {
2782 qApp->processEvents(); 2782 qApp->processEvents();
2783 if ( !test->doesFloat() ) { 2783 if ( !test->doesFloat() ) {
2784 if ( mConflictingEvent->isOverlapping ( test, &retVal, &current ) ) { 2784 if ( mConflictingEvent->isOverlapping ( test, &retVal, &current ) ) {
2785 if ( ! found ) { 2785 if ( ! found ) {
2786 conflict = retVal; 2786 conflict = retVal;
2787 cE = test; 2787 cE = test;
2788 } else { 2788 } else {
2789 if ( retVal < conflict ) { 2789 if ( retVal < conflict ) {
2790 conflict = retVal; 2790 conflict = retVal;
2791 cE = test; 2791 cE = test;
2792 } 2792 }
2793 } 2793 }
2794 found = true; 2794 found = true;
2795 } 2795 }
2796 } 2796 }
2797 test = testlist.next(); 2797 test = testlist.next();
2798 } 2798 }
2799 if ( found ) { 2799 if ( found ) {
2800 QString mess = i18n("The event\n%1\nconflicts with event\n%2\nat date\n%3.\n").arg(KGlobal::formatMessage ( mConflictingEvent->summary(),0 ) ).arg( KGlobal::formatMessage ( cE->summary(),0 )).arg(KGlobal::locale()->formatDate(conflict.date()) ) ; 2800 QString mess = i18n("The event\n%1\nconflicts with event\n%2\nat date\n%3.\n").arg(KGlobal::formatMessage ( mConflictingEvent->summary(),0 ) ).arg( KGlobal::formatMessage ( cE->summary(),0 )).arg(KGlobal::locale()->formatDate(conflict.date()) ) ;
2801 qApp->processEvents(); 2801 qApp->processEvents();
2802 int km = KMessageBox::warningContinueCancel(this,mess, 2802 int km = KMessageBox::warningContinueCancel(this,mess,
2803 i18n("KO/Pi Conflict delected"),i18n("Show date"),i18n("No problem!")); 2803 i18n("KO/Pi Conflict delected"),i18n("Show date"),i18n("No problem!"));
2804 if ( km != KMessageBox::Continue ) 2804 if ( km != KMessageBox::Continue )
2805 return; 2805 return;
2806 2806
2807 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) 2807 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 )
2808 mViewManager->showDayView(); 2808 mViewManager->showDayView();
2809 mNavigator->slotDaySelect( conflict.date() ); 2809 mNavigator->slotDaySelect( conflict.date() );
2810 int hour = conflict.time().hour(); 2810 int hour = conflict.time().hour();
2811 mViewManager->agendaView()->setStartHour( hour ); 2811 mViewManager->agendaView()->setStartHour( hour );
2812 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( mConflictingEvent->summary().left( 20 ) ).arg( cE->summary().left( 20 ) ) ); 2812 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( mConflictingEvent->summary().left( 20 ) ).arg( cE->summary().left( 20 ) ) );
2813 } 2813 } else
2814 topLevelWidget()->setCaption( i18n("No conflict found") );
2814 mConflictingEvent = 0; 2815 mConflictingEvent = 0;
2815 return; 2816 return;
2816 2817
2817} 2818}
2818 2819
2819void CalendarView::updateTodoViews() 2820void CalendarView::updateTodoViews()
2820{ 2821{
2821 mTodoList->updateView(); 2822 mTodoList->updateView();
2822 mViewManager->currentView()->updateView(); 2823 mViewManager->currentView()->updateView();
2823 2824
2824} 2825}
2825 2826
2826 2827
2827 2828
2828void CalendarView::clearAllViews() 2829void CalendarView::clearAllViews()
2829{ 2830{
2830 mTodoList->clearList(); 2831 mTodoList->clearList();
2831 mViewManager->clearAllViews(); 2832 mViewManager->clearAllViews();
2832 SearchDialog * sd = mDialogManager->getSearchDialog(); 2833 SearchDialog * sd = mDialogManager->getSearchDialog();
2833 if ( sd ) { 2834 if ( sd ) {
2834 KOListView* kol = sd->listview(); 2835 KOListView* kol = sd->listview();
2835 if ( kol ) 2836 if ( kol )
2836 kol->clearList(); 2837 kol->clearList();
2837 } 2838 }
2838} 2839}
2839void CalendarView::updateView() 2840void CalendarView::updateView()
2840{ 2841{
2841 static bool clearallviews = false; 2842 static bool clearallviews = false;
2842 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) { 2843 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) {
2843 if ( clearallviews ) { 2844 if ( clearallviews ) {
2844 clearAllViews(); 2845 clearAllViews();
2845 clearallviews = false; 2846 clearallviews = false;
2846 } 2847 }
2847 return; 2848 return;
2848 } 2849 }
2849 clearallviews = true; 2850 clearallviews = true;
2850 DateList tmpList = mNavigator->selectedDates(); 2851 DateList tmpList = mNavigator->selectedDates();
2851 2852
2852 if ( KOPrefs::instance()->mHideNonStartedTodos ) 2853 if ( KOPrefs::instance()->mHideNonStartedTodos )
2853 mTodoList->updateView(); 2854 mTodoList->updateView();
2854 // We assume that the navigator only selects consecutive days. 2855 // We assume that the navigator only selects consecutive days.
2855 updateView( tmpList.first(), tmpList.last() ); 2856 updateView( tmpList.first(), tmpList.last() );
2856} 2857}
2857 2858
2858void CalendarView::updateUnmanagedViews() 2859void CalendarView::updateUnmanagedViews()
2859{ 2860{
2860 mDateNavigator->updateDayMatrix(); 2861 mDateNavigator->updateDayMatrix();
2861} 2862}
2862 2863
2863int CalendarView::msgItemDelete(const QString name) 2864int CalendarView::msgItemDelete(const QString name)
2864{ 2865{
2865 return KMessageBox::warningContinueCancel(this,name +"\n\n"+ 2866 return KMessageBox::warningContinueCancel(this,name +"\n\n"+
2866 i18n("This item will be\npermanently deleted."), 2867 i18n("This item will be\npermanently deleted."),
2867 i18n("KO/Pi Confirmation"),i18n("Delete")); 2868 i18n("KO/Pi Confirmation"),i18n("Delete"));
2868} 2869}
2869 2870
2870 2871
2871void CalendarView::edit_cut() 2872void CalendarView::edit_cut()
2872{ 2873{
2873 Event *anEvent=0; 2874 Event *anEvent=0;
2874 2875
2875 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2876 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2876 2877
2877 if (mViewManager->currentView()->isEventView()) { 2878 if (mViewManager->currentView()->isEventView()) {
2878 if ( incidence && incidence->typeID() == eventID ) { 2879 if ( incidence && incidence->typeID() == eventID ) {
2879 anEvent = static_cast<Event *>(incidence); 2880 anEvent = static_cast<Event *>(incidence);
2880 } 2881 }
2881 } 2882 }
2882 2883
2883 if (!anEvent) { 2884 if (!anEvent) {
2884 KNotifyClient::beep(); 2885 KNotifyClient::beep();
2885 return; 2886 return;
2886 } 2887 }
2887 DndFactory factory( mCalendar ); 2888 DndFactory factory( mCalendar );
2888 factory.cutIncidence(anEvent); 2889 factory.cutIncidence(anEvent);
2889 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2890 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2890} 2891}
2891 2892
2892void CalendarView::edit_copy() 2893void CalendarView::edit_copy()
2893{ 2894{
2894 Event *anEvent=0; 2895 Event *anEvent=0;
2895 2896
2896 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2897 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2897 2898
2898 if (mViewManager->currentView()->isEventView()) { 2899 if (mViewManager->currentView()->isEventView()) {
2899 if ( incidence && incidence->typeID() == eventID ) { 2900 if ( incidence && incidence->typeID() == eventID ) {
2900 anEvent = static_cast<Event *>(incidence); 2901 anEvent = static_cast<Event *>(incidence);
2901 } 2902 }
2902 } 2903 }
2903 2904
2904 if (!anEvent) { 2905 if (!anEvent) {
2905 KNotifyClient::beep(); 2906 KNotifyClient::beep();
2906 return; 2907 return;
2907 } 2908 }
2908 DndFactory factory( mCalendar ); 2909 DndFactory factory( mCalendar );
2909 factory.copyIncidence(anEvent); 2910 factory.copyIncidence(anEvent);
2910} 2911}
2911 2912
2912void CalendarView::edit_paste() 2913void CalendarView::edit_paste()
2913{ 2914{
2914 QDate date = mNavigator->selectedDates().first(); 2915 QDate date = mNavigator->selectedDates().first();
2915 2916
2916 DndFactory factory( mCalendar ); 2917 DndFactory factory( mCalendar );
2917 Event *pastedEvent = (Event *)factory.pasteIncidence( date ); 2918 Event *pastedEvent = (Event *)factory.pasteIncidence( date );
2918 2919
2919 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2920 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2920} 2921}
2921void CalendarView::edit_global_options() 2922void CalendarView::edit_global_options()
2922{ 2923{
2923 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId; 2924 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId;
2924 emit save(); 2925 emit save();
2925 emit saveStopTimer(); 2926 emit saveStopTimer();
2926 mDialogManager->showGlobalOptionsDialog(); 2927 mDialogManager->showGlobalOptionsDialog();
2927 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) { 2928 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) {
2928 emit saveStopTimer(); 2929 emit saveStopTimer();
2929 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto shift the time of the events?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"), 2930 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto shift the time of the events?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"),
2930 i18n("Timezone settings"),i18n("Reload"))) { 2931 i18n("Timezone settings"),i18n("Reload"))) {
2931 qDebug("KO: TZ reload cancelled "); 2932 qDebug("KO: TZ reload cancelled ");
2932 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2933 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2933 return; 2934 return;
2934 } 2935 }
2935 qDebug("KO: Timezone change "); 2936 qDebug("KO: Timezone change ");
2936 loadCalendars(); 2937 loadCalendars();
2937 setModified(true); 2938 setModified(true);
2938 } 2939 }
2939 else 2940 else
2940 qDebug("KO: No tz change "); 2941 qDebug("KO: No tz change ");
2941} 2942}
2942void CalendarView::edit_options() 2943void CalendarView::edit_options()
2943{ 2944{
2944 mDialogManager->showOptionsDialog(); 2945 mDialogManager->showOptionsDialog();
2945} 2946}
2946 2947
2947 2948
2948void CalendarView::slotSelectPickerDate( QDate d) 2949void CalendarView::slotSelectPickerDate( QDate d)
2949{ 2950{
2950 mDateFrame->hide(); 2951 mDateFrame->hide();
2951 if ( mDatePickerMode == 1 ) { 2952 if ( mDatePickerMode == 1 ) {
2952 mNavigator->slotDaySelect( d ); 2953 mNavigator->slotDaySelect( d );
2953 } else if ( mDatePickerMode == 2 ) { 2954 } else if ( mDatePickerMode == 2 ) {
2954 if ( mMoveIncidence->typeID() == todoID ) { 2955 if ( mMoveIncidence->typeID() == todoID ) {
2955 Todo * to = (Todo *) mMoveIncidence; 2956 Todo * to = (Todo *) mMoveIncidence;
2956 QTime tim; 2957 QTime tim;
2957 int len = 0; 2958 int len = 0;
2958 if ( to->hasStartDate() && to->hasDueDate() ) 2959 if ( to->hasStartDate() && to->hasDueDate() )
2959 len = to->dtStart().secsTo( to->dtDue()); 2960 len = to->dtStart().secsTo( to->dtDue());
2960 if ( to->hasDueDate() ) 2961 if ( to->hasDueDate() )
2961 tim = to->dtDue().time(); 2962 tim = to->dtDue().time();
2962 else { 2963 else {
2963 tim = QTime ( 0,0,0 ); 2964 tim = QTime ( 0,0,0 );
2964 to->setFloats( true ); 2965 to->setFloats( true );
2965 to->setHasDueDate( true ); 2966 to->setHasDueDate( true );
2966 } 2967 }
2967 QDateTime dt ( d,tim ); 2968 QDateTime dt ( d,tim );
2968 to->setDtDue( dt ); 2969 to->setDtDue( dt );
2969 2970
2970 if ( to->hasStartDate() ) { 2971 if ( to->hasStartDate() ) {
2971 if ( len>0 ) 2972 if ( len>0 )
2972 to->setDtStart(to->dtDue().addSecs( -len )); 2973 to->setDtStart(to->dtDue().addSecs( -len ));
2973 else 2974 else
2974 if (to->dtStart() > to->dtDue() ) 2975 if (to->dtStart() > to->dtDue() )
2975 to->setDtStart(to->dtDue().addDays( -3 )); 2976 to->setDtStart(to->dtDue().addDays( -3 ));
2976 } 2977 }
2977 2978
2978 todoChanged( to ); 2979 todoChanged( to );
2979 } else if ( mMoveIncidence->typeID() == eventID ) { 2980 } else if ( mMoveIncidence->typeID() == eventID ) {
2980 if ( mMoveIncidence->doesRecur() ) { 2981 if ( mMoveIncidence->doesRecur() ) {
2981#if 0 2982#if 0
2982 // PENDING implement this 2983 // PENDING implement this
2983 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate ); 2984 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate );
2984 mCalendar()->addIncidence( newInc ); 2985 mCalendar()->addIncidence( newInc );
2985 if ( mMoveIncidence->typeID() == todoID ) 2986 if ( mMoveIncidence->typeID() == todoID )
2986 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED ); 2987 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED );
2987 else 2988 else
2988 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED); 2989 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED);
2989 mMoveIncidence = newInc; 2990 mMoveIncidence = newInc;
2990 2991
2991#endif 2992#endif
2992 } 2993 }
2993 QTime tim = mMoveIncidence->dtStart().time(); 2994 QTime tim = mMoveIncidence->dtStart().time();
2994 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 2995 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
2995 QDateTime dt ( d,tim ); 2996 QDateTime dt ( d,tim );
2996 mMoveIncidence->setDtStart( dt ); 2997 mMoveIncidence->setDtStart( dt );
2997 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 2998 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
2998 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 2999 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
2999 } else if ( mMoveIncidence->typeID() == journalID ) { 3000 } else if ( mMoveIncidence->typeID() == journalID ) {
3000 QTime tim = mMoveIncidence->dtStart().time(); 3001 QTime tim = mMoveIncidence->dtStart().time();
3001 QDateTime dt ( d,tim ); 3002 QDateTime dt ( d,tim );
3002 mMoveIncidence->setDtStart( dt ); 3003 mMoveIncidence->setDtStart( dt );
3003 updateView(); 3004 updateView();
3004 } 3005 }
3005 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 3006 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
3006 } 3007 }
3007} 3008}
3008 3009
3009void CalendarView::removeCategories() 3010void CalendarView::removeCategories()
3010{ 3011{
3011 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 3012 QPtrList<Incidence> incList = mCalendar->rawIncidences();
3012 QStringList catList = KOPrefs::instance()->mCustomCategories; 3013 QStringList catList = KOPrefs::instance()->mCustomCategories;
3013 QStringList catIncList; 3014 QStringList catIncList;
3014 QStringList newCatList; 3015 QStringList newCatList;
3015 Incidence* inc = incList.first(); 3016 Incidence* inc = incList.first();
3016 uint i; 3017 uint i;
3017 while ( inc ) { 3018 while ( inc ) {
3018 newCatList.clear(); 3019 newCatList.clear();
3019 catIncList = inc->categories() ; 3020 catIncList = inc->categories() ;
3020 for( i = 0; i< catIncList.count(); ++i ) { 3021 for( i = 0; i< catIncList.count(); ++i ) {
3021 if ( catList.contains (catIncList[i])) 3022 if ( catList.contains (catIncList[i]))
3022 newCatList.append( catIncList[i] ); 3023 newCatList.append( catIncList[i] );
3023 } 3024 }
3024 newCatList.sort(); 3025 newCatList.sort();
3025 inc->setCategories( newCatList.join(",") ); 3026 inc->setCategories( newCatList.join(",") );
3026 inc = incList.next(); 3027 inc = incList.next();
3027 } 3028 }
3028} 3029}
3029 3030
3030int CalendarView::addCategories() 3031int CalendarView::addCategories()
3031{ 3032{
3032 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 3033 QPtrList<Incidence> incList = mCalendar->rawIncidences();
3033 QStringList catList = KOPrefs::instance()->mCustomCategories; 3034 QStringList catList = KOPrefs::instance()->mCustomCategories;
3034 QStringList catIncList; 3035 QStringList catIncList;
3035 Incidence* inc = incList.first(); 3036 Incidence* inc = incList.first();
3036 uint i; 3037 uint i;
3037 int count = 0; 3038 int count = 0;
3038 while ( inc ) { 3039 while ( inc ) {
3039 catIncList = inc->categories() ; 3040 catIncList = inc->categories() ;
3040 for( i = 0; i< catIncList.count(); ++i ) { 3041 for( i = 0; i< catIncList.count(); ++i ) {
3041 if ( !catList.contains (catIncList[i])) { 3042 if ( !catList.contains (catIncList[i])) {
3042 catList.append( catIncList[i] ); 3043 catList.append( catIncList[i] );
3043 //qDebug("add cat %s ", catIncList[i].latin1()); 3044 //qDebug("add cat %s ", catIncList[i].latin1());
3044 ++count; 3045 ++count;
3045 } 3046 }
3046 } 3047 }
3047 inc = incList.next(); 3048 inc = incList.next();
3048 } 3049 }
3049 catList.sort(); 3050 catList.sort();
3050 KOPrefs::instance()->mCustomCategories = catList; 3051 KOPrefs::instance()->mCustomCategories = catList;
3051 return count; 3052 return count;
3052} 3053}
3053 3054
3054void CalendarView::editCategories() 3055void CalendarView::editCategories()
3055{ 3056{
3056 qDebug("CalendarView::editCategories() "); 3057 qDebug("CalendarView::editCategories() ");
3057 KPIM::CategoryEditDialog ced (KOPrefs::instance(),this ); 3058 KPIM::CategoryEditDialog ced (KOPrefs::instance(),this );
3058 ced.exec(); 3059 ced.exec();
3059} 3060}
3060void CalendarView::manageCategories() 3061void CalendarView::manageCategories()
3061{ 3062{
3062 KOCatPrefs* cp = new KOCatPrefs(); 3063 KOCatPrefs* cp = new KOCatPrefs();
3063 cp->show(); 3064 cp->show();
3064 int w =cp->sizeHint().width() ; 3065 int w =cp->sizeHint().width() ;
3065 int h = cp->sizeHint().height() ; 3066 int h = cp->sizeHint().height() ;
3066 int dw = QApplication::desktop()->width(); 3067 int dw = QApplication::desktop()->width();
3067 int dh = QApplication::desktop()->height(); 3068 int dh = QApplication::desktop()->height();
3068 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 3069 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
3069 if ( !cp->exec() ) { 3070 if ( !cp->exec() ) {
3070 delete cp; 3071 delete cp;
3071 return; 3072 return;
3072 } 3073 }
3073 int count = 0; 3074 int count = 0;
3074 if ( cp->addCat() ) { 3075 if ( cp->addCat() ) {
3075 count = addCategories(); 3076 count = addCategories();
3076 if ( count ) { 3077 if ( count ) {
3077 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 3078 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
3078 writeSettings(); 3079 writeSettings();
3079 } else 3080 } else
3080 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! ")); 3081 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! "));
3081 } else { 3082 } else {
3082 removeCategories(); 3083 removeCategories();
3083 updateView(); 3084 updateView();
3084 } 3085 }
3085 delete cp; 3086 delete cp;
3086} 3087}
3087 3088
3088void CalendarView::beamIncidence(Incidence * Inc) 3089void CalendarView::beamIncidence(Incidence * Inc)
3089{ 3090{
3090 QPtrList<Incidence> delSel ; 3091 QPtrList<Incidence> delSel ;
3091 delSel.append(Inc); 3092 delSel.append(Inc);
3092 beamIncidenceList( delSel ); 3093 beamIncidenceList( delSel );
3093} 3094}
3094void CalendarView::beamCalendar() 3095void CalendarView::beamCalendar()
3095{ 3096{
3096 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 3097 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
3097 //qDebug("beamCalendar() "); 3098 //qDebug("beamCalendar() ");
3098 beamIncidenceList( delSel ); 3099 beamIncidenceList( delSel );
3099} 3100}
3100void CalendarView::beamFilteredCalendar() 3101void CalendarView::beamFilteredCalendar()
3101{ 3102{
3102 QPtrList<Incidence> delSel = mCalendar->incidences(); 3103 QPtrList<Incidence> delSel = mCalendar->incidences();
3103 //qDebug("beamFilteredCalendar() "); 3104 //qDebug("beamFilteredCalendar() ");
3104 beamIncidenceList( delSel ); 3105 beamIncidenceList( delSel );
3105} 3106}
3106void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 3107void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
3107{ 3108{
3108 3109
3109 KOBeamPrefs beamDialog; 3110 KOBeamPrefs beamDialog;
3110 if ( beamDialog.exec () == QDialog::Rejected ) 3111 if ( beamDialog.exec () == QDialog::Rejected )
3111 return; 3112 return;
3112#ifdef DESKTOP_VERSION 3113#ifdef DESKTOP_VERSION
3113 QString fn = locateLocal( "tmp", "kopibeamfile" ); 3114 QString fn = locateLocal( "tmp", "kopibeamfile" );
3114#else 3115#else
3115 QString fn = "/tmp/kopibeamfile"; 3116 QString fn = "/tmp/kopibeamfile";
3116#endif 3117#endif
3117 QString mes; 3118 QString mes;
3118 bool createbup = true; 3119 bool createbup = true;
3119 if ( createbup ) { 3120 if ( createbup ) {
3120 QString description = "\n"; 3121 QString description = "\n";
3121 CalendarLocal* cal = new CalendarLocal(); 3122 CalendarLocal* cal = new CalendarLocal();
3122 if ( beamDialog.beamLocal() ) 3123 if ( beamDialog.beamLocal() )
3123 cal->setLocalTime(); 3124 cal->setLocalTime();
3124 else 3125 else
3125 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 3126 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
3126 Incidence *incidence = delSel.first(); 3127 Incidence *incidence = delSel.first();
3127 bool addText = false; 3128 bool addText = false;
3128 if ( delSel.count() < 10 ) 3129 if ( delSel.count() < 10 )
3129 addText = true; 3130 addText = true;
3130 else { 3131 else {
3131 description.sprintf(i18n(" %d items?"),delSel.count() ); 3132 description.sprintf(i18n(" %d items?"),delSel.count() );
3132 } 3133 }
3133 while ( incidence ) { 3134 while ( incidence ) {
3134 Incidence *in = incidence->clone(); 3135 Incidence *in = incidence->clone();
3135 if ( ! in->summary().isEmpty() ) { 3136 if ( ! in->summary().isEmpty() ) {
3136 in->setDescription(""); 3137 in->setDescription("");
3137 } else { 3138 } else {
3138 in->setSummary( in->description().left(20)); 3139 in->setSummary( in->description().left(20));
3139 in->setDescription(""); 3140 in->setDescription("");
3140 } 3141 }
3141 if ( addText ) 3142 if ( addText )
3142 description += in->summary() + "\n"; 3143 description += in->summary() + "\n";
3143 cal->addIncidence( in ); 3144 cal->addIncidence( in );
3144 incidence = delSel.next(); 3145 incidence = delSel.next();
3145 } 3146 }
3146 if ( beamDialog.beamVcal() ) { 3147 if ( beamDialog.beamVcal() ) {
3147 fn += ".vcs"; 3148 fn += ".vcs";
3148 FileStorage storage( cal, fn, new VCalFormat ); 3149 FileStorage storage( cal, fn, new VCalFormat );
3149 storage.save(); 3150 storage.save();
3150 } else { 3151 } else {
3151 fn += ".ics"; 3152 fn += ".ics";
3152 FileStorage storage( cal, fn, new ICalFormat( ) ); 3153 FileStorage storage( cal, fn, new ICalFormat( ) );
3153 storage.save(); 3154 storage.save();
3154 } 3155 }
3155 delete cal; 3156 delete cal;
3156 mes = i18n("KO/Pi: Ready for beaming"); 3157 mes = i18n("KO/Pi: Ready for beaming");
3157 topLevelWidget()->setCaption(mes); 3158 topLevelWidget()->setCaption(mes);
3158 KApplication::convert2latin1( fn ); 3159 KApplication::convert2latin1( fn );
3159#ifndef DESKTOP_VERSION 3160#ifndef DESKTOP_VERSION
3160 Ir *ir = new Ir( this ); 3161 Ir *ir = new Ir( this );
3161 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 3162 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
3162 ir->send( fn, description, "text/x-vCalendar" ); 3163 ir->send( fn, description, "text/x-vCalendar" );
3163#endif 3164#endif
3164 } 3165 }
3165} 3166}
3166 3167
3167#ifndef DESKTOP_VERSION 3168#ifndef DESKTOP_VERSION
3168void CalendarView::beamDone( Ir *ir ) 3169void CalendarView::beamDone( Ir *ir )
3169{ 3170{
3170 delete ir; 3171 delete ir;
3171 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); 3172 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") );
3172 topLevelWidget()->raise(); 3173 topLevelWidget()->raise();
3173} 3174}
3174#else 3175#else
3175void CalendarView::beamDone( Ir *){;} 3176void CalendarView::beamDone( Ir *){;}
3176#endif 3177#endif
3177void CalendarView::moveIncidence(Incidence * inc ) 3178void CalendarView::moveIncidence(Incidence * inc )
3178{ 3179{
3179 if ( !inc ) return; 3180 if ( !inc ) return;
3180 showDatePickerPopup(); 3181 showDatePickerPopup();
3181 mDatePickerMode = 2; 3182 mDatePickerMode = 2;
3182 mMoveIncidence = inc ; 3183 mMoveIncidence = inc ;
3183 QDate da; 3184 QDate da;
3184 if ( mMoveIncidence->typeID() == todoID ) { 3185 if ( mMoveIncidence->typeID() == todoID ) {
3185 Todo * to = (Todo *) mMoveIncidence; 3186 Todo * to = (Todo *) mMoveIncidence;
3186 if ( to->hasDueDate() ) 3187 if ( to->hasDueDate() )
3187 da = to->dtDue().date(); 3188 da = to->dtDue().date();
3188 else 3189 else
3189 da = QDate::currentDate(); 3190 da = QDate::currentDate();
3190 } else { 3191 } else {
3191 da = mMoveIncidence->dtStart().date(); 3192 da = mMoveIncidence->dtStart().date();
3192 } 3193 }
3193 //PENDING set date for recurring incidence to date of recurrence 3194 //PENDING set date for recurring incidence to date of recurrence
3194 //mMoveIncidenceOldDate; 3195 //mMoveIncidenceOldDate;
3195 mDatePicker->setDate( da ); 3196 mDatePicker->setDate( da );
3196} 3197}
3197void CalendarView::showDatePickerPopup() 3198void CalendarView::showDatePickerPopup()
3198{ 3199{
3199 if ( mDateFrame->isVisible() ) 3200 if ( mDateFrame->isVisible() )
3200 mDateFrame->hide(); 3201 mDateFrame->hide();
3201 else { 3202 else {
3202 int offX = 0, offY = 0; 3203 int offX = 0, offY = 0;
3203#ifdef DESKTOP_VERSION 3204#ifdef DESKTOP_VERSION
3204 int w =mDatePicker->sizeHint().width() ; 3205 int w =mDatePicker->sizeHint().width() ;
3205 int h = mDatePicker->sizeHint().height() ; 3206 int h = mDatePicker->sizeHint().height() ;
3206 int dw = topLevelWidget()->width(); 3207 int dw = topLevelWidget()->width();
3207 int dh = topLevelWidget()->height(); 3208 int dh = topLevelWidget()->height();
3208 offX = topLevelWidget()->x(); 3209 offX = topLevelWidget()->x();
3209 offY = topLevelWidget()->y(); 3210 offY = topLevelWidget()->y();
3210#else 3211#else
3211 int w =mDatePicker->sizeHint().width() ; 3212 int w =mDatePicker->sizeHint().width() ;
3212 int h = mDatePicker->sizeHint().height() ; 3213 int h = mDatePicker->sizeHint().height() ;
3213 int dw = QApplication::desktop()->width(); 3214 int dw = QApplication::desktop()->width();
3214 int dh = QApplication::desktop()->height(); 3215 int dh = QApplication::desktop()->height();
3215#endif 3216#endif
3216 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h ); 3217 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h );
3217 mDateFrame->show(); 3218 mDateFrame->show();
3218 } 3219 }
3219} 3220}
3220void CalendarView::showDatePicker( ) 3221void CalendarView::showDatePicker( )
3221{ 3222{
3222 showDatePickerPopup(); 3223 showDatePickerPopup();
3223 mDatePickerMode = 1; 3224 mDatePickerMode = 1;
3224 mDatePicker->setDate( mNavigator->selectedDates().first() ); 3225 mDatePicker->setDate( mNavigator->selectedDates().first() );
3225} 3226}
3226 3227
3227void CalendarView::showEventEditor() 3228void CalendarView::showEventEditor()
3228{ 3229{
3229#ifdef DESKTOP_VERSION 3230#ifdef DESKTOP_VERSION
3230 int x,y,w,h; 3231 int x,y,w,h;
3231 x = mEventEditor->geometry().x(); 3232 x = mEventEditor->geometry().x();
3232 y = mEventEditor->geometry().y(); 3233 y = mEventEditor->geometry().y();
3233 w = mEventEditor->width(); 3234 w = mEventEditor->width();
3234 h = mEventEditor->height(); 3235 h = mEventEditor->height();
3235 mEventEditor->show(); 3236 mEventEditor->show();
3236 mEventEditor->setGeometry(x,y,w,h); 3237 mEventEditor->setGeometry(x,y,w,h);
3237#else 3238#else
3238 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) { 3239 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) {
3239 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 3240 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
3240 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() ); 3241 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() );
3241 qApp->processEvents(); 3242 qApp->processEvents();
3242 delete mEventEditor; 3243 delete mEventEditor;
3243 mEventEditor = mDialogManager->getEventEditor(); 3244 mEventEditor = mDialogManager->getEventEditor();
3244 topLevelWidget()->setCaption( i18n("") ); 3245 topLevelWidget()->setCaption( i18n("") );
3245 } 3246 }
3246 mEventEditor->showMaximized(); 3247 mEventEditor->showMaximized();
3247#endif 3248#endif
3248} 3249}
3249void CalendarView::showTodoEditor() 3250void CalendarView::showTodoEditor()
3250{ 3251{
3251#ifdef DESKTOP_VERSION 3252#ifdef DESKTOP_VERSION
3252 int x,y,w,h; 3253 int x,y,w,h;
3253 x = mTodoEditor->geometry().x(); 3254 x = mTodoEditor->geometry().x();
3254 y = mTodoEditor->geometry().y(); 3255 y = mTodoEditor->geometry().y();
3255 w = mTodoEditor->width(); 3256 w = mTodoEditor->width();
3256 h = mTodoEditor->height(); 3257 h = mTodoEditor->height();
3257 mTodoEditor->show(); 3258 mTodoEditor->show();
3258 mTodoEditor->setGeometry(x,y,w,h); 3259 mTodoEditor->setGeometry(x,y,w,h);
3259#else 3260#else
3260 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) { 3261 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) {
3261 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 3262 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
3262 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() ); 3263 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() );
3263 qApp->processEvents(); 3264 qApp->processEvents();
3264 delete mTodoEditor; 3265 delete mTodoEditor;
3265 mTodoEditor = mDialogManager->getTodoEditor(); 3266 mTodoEditor = mDialogManager->getTodoEditor();
3266 topLevelWidget()->setCaption( i18n("") ); 3267 topLevelWidget()->setCaption( i18n("") );
3267 } 3268 }
3268 mTodoEditor->showMaximized(); 3269 mTodoEditor->showMaximized();
3269#endif 3270#endif
3270} 3271}
3271 3272
3272void CalendarView::cloneIncidence() 3273void CalendarView::cloneIncidence()
3273{ 3274{
3274 Incidence *incidence = currentSelection(); 3275 Incidence *incidence = currentSelection();
3275 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3276 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3276 if ( incidence ) { 3277 if ( incidence ) {
3277 cloneIncidence(incidence); 3278 cloneIncidence(incidence);
3278 } 3279 }
3279} 3280}
3280void CalendarView::moveIncidence() 3281void CalendarView::moveIncidence()
3281{ 3282{
3282 Incidence *incidence = currentSelection(); 3283 Incidence *incidence = currentSelection();
3283 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3284 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3284 if ( incidence ) { 3285 if ( incidence ) {
3285 moveIncidence(incidence); 3286 moveIncidence(incidence);
3286 } 3287 }
3287} 3288}
3288void CalendarView::beamIncidence() 3289void CalendarView::beamIncidence()
3289{ 3290{
3290 Incidence *incidence = currentSelection(); 3291 Incidence *incidence = currentSelection();
3291 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3292 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3292 if ( incidence ) { 3293 if ( incidence ) {
3293 beamIncidence(incidence); 3294 beamIncidence(incidence);
3294 } 3295 }
3295} 3296}
3296void CalendarView::toggleCancelIncidence() 3297void CalendarView::toggleCancelIncidence()
3297{ 3298{
3298 Incidence *incidence = currentSelection(); 3299 Incidence *incidence = currentSelection();
3299 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3300 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3300 if ( incidence ) { 3301 if ( incidence ) {
3301 cancelIncidence(incidence); 3302 cancelIncidence(incidence);
3302 } 3303 }
3303} 3304}
3304 3305
3305 3306
3306void CalendarView::cancelIncidence(Incidence * inc ) 3307void CalendarView::cancelIncidence(Incidence * inc )
3307{ 3308{
3308 inc->setCancelled( ! inc->cancelled() ); 3309 inc->setCancelled( ! inc->cancelled() );
3309 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 3310 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
3310 updateView(); 3311 updateView();
3311} 3312}
3312void CalendarView::cloneIncidence(Incidence * orgInc ) 3313void CalendarView::cloneIncidence(Incidence * orgInc )
3313{ 3314{
3314 Incidence * newInc = orgInc->clone(); 3315 Incidence * newInc = orgInc->clone();
3315 newInc->recreate(); 3316 newInc->recreate();
3316 3317
3317 if ( newInc->typeID() == todoID ) { 3318 if ( newInc->typeID() == todoID ) {
3318 Todo* t = (Todo*) newInc; 3319 Todo* t = (Todo*) newInc;
3319 bool cloneSub = false; 3320 bool cloneSub = false;
3320 if ( orgInc->relations().count() ) { 3321 if ( orgInc->relations().count() ) {
3321 int result = KMessageBox::warningYesNoCancel(this, 3322 int result = KMessageBox::warningYesNoCancel(this,
3322 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( KGlobal::formatMessage ( newInc->summary(),0 ) ), 3323 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( KGlobal::formatMessage ( newInc->summary(),0 ) ),
3323 i18n("Todo has subtodos"), 3324 i18n("Todo has subtodos"),
3324 i18n("Yes"), 3325 i18n("Yes"),
3325 i18n("No")); 3326 i18n("No"));
3326 3327
3327 if ( result == KMessageBox::Cancel ) { 3328 if ( result == KMessageBox::Cancel ) {
3328 delete t; 3329 delete t;
3329 return; 3330 return;
3330 } 3331 }
3331 if (result == KMessageBox::Yes) cloneSub = true; 3332 if (result == KMessageBox::Yes) cloneSub = true;
3332 } 3333 }
3333 showTodoEditor(); 3334 showTodoEditor();
3334 mTodoEditor->editTodo( t ); 3335 mTodoEditor->editTodo( t );
3335 if ( mTodoEditor->exec() ) { 3336 if ( mTodoEditor->exec() ) {
3336 if ( cloneSub ) { 3337 if ( cloneSub ) {
3337 orgInc->cloneRelations( t ); 3338 orgInc->cloneRelations( t );
3338 mCalendar->addIncidenceBranch( t ); 3339 mCalendar->addIncidenceBranch( t );
3339 updateView(); 3340 updateView();
3340 3341
3341 } else { 3342 } else {
3342 mCalendar->addTodo( t ); 3343 mCalendar->addTodo( t );
3343 updateView(); 3344 updateView();
3344 } 3345 }
3345 } else { 3346 } else {
3346 delete t; 3347 delete t;
3347 } 3348 }
3348 } 3349 }
3349 else if ( newInc->typeID() == eventID ) { 3350 else if ( newInc->typeID() == eventID ) {
3350 Event* e = (Event*) newInc; 3351 Event* e = (Event*) newInc;
3351 showEventEditor(); 3352 showEventEditor();
3352 mEventEditor->editEvent( e ); 3353 mEventEditor->editEvent( e );
3353 if ( mEventEditor->exec() ) { 3354 if ( mEventEditor->exec() ) {
3354 mCalendar->addEvent( e ); 3355 mCalendar->addEvent( e );
3355 updateView(); 3356 updateView();
3356 } else { 3357 } else {
3357 delete e; 3358 delete e;
3358 } 3359 }
3359 } if ( newInc->typeID() == journalID ) { 3360 } if ( newInc->typeID() == journalID ) {
3360 mCalendar->addJournal( (Journal*) newInc ); 3361 mCalendar->addJournal( (Journal*) newInc );
3361 editJournal( (Journal*) newInc ); 3362 editJournal( (Journal*) newInc );
3362 } 3363 }
3363 setActiveWindow(); 3364 setActiveWindow();
3364} 3365}
3365 3366
3366void CalendarView::newEvent() 3367void CalendarView::newEvent()
3367{ 3368{
3368 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 3369 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
3369 KOAgendaView *aView = mViewManager->agendaView(); 3370 KOAgendaView *aView = mViewManager->agendaView();
3370 if (aView) { 3371 if (aView) {
3371 if (aView->selectionStart().isValid()) { 3372 if (aView->selectionStart().isValid()) {
3372 if (aView->selectedIsAllDay()) { 3373 if (aView->selectedIsAllDay()) {
3373 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 3374 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
3374 } else { 3375 } else {
3375 newEvent(aView->selectionStart(),aView->selectionEnd()); 3376 newEvent(aView->selectionStart(),aView->selectionEnd());
3376 } 3377 }
3377 return; 3378 return;
3378 } 3379 }
3379 } 3380 }
3380 3381
3381 QDate date = mNavigator->selectedDates().first(); 3382 QDate date = mNavigator->selectedDates().first();
3382#if 0 3383#if 0
3383 QDateTime current = QDateTime::currentDateTime(); 3384 QDateTime current = QDateTime::currentDateTime();
3384 if ( date <= current.date() ) { 3385 if ( date <= current.date() ) {
3385 int hour = current.time().hour() +1; 3386 int hour = current.time().hour() +1;
3386 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 3387 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
3387 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 3388 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
3388 } else 3389 } else
3389#endif 3390#endif
3390 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 3391 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
3391 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 3392 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
3392 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 3393 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
3393} 3394}
3394 3395
3395void CalendarView::newEvent(QDateTime fh) 3396void CalendarView::newEvent(QDateTime fh)
3396{ 3397{
3397 newEvent(fh, 3398 newEvent(fh,
3398 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 3399 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
3399} 3400}
3400 3401
3401void CalendarView::newEvent(QDate dt) 3402void CalendarView::newEvent(QDate dt)
3402{ 3403{
3403 newEvent(QDateTime(dt, QTime(0,0,0)), 3404 newEvent(QDateTime(dt, QTime(0,0,0)),
3404 QDateTime(dt, QTime(0,0,0)), true); 3405 QDateTime(dt, QTime(0,0,0)), true);
3405} 3406}
3406void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint) 3407void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint)
3407{ 3408{
3408 newEvent(fromHint, toHint, false); 3409 newEvent(fromHint, toHint, false);
3409} 3410}
3410void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 3411void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
3411{ 3412{
3412 3413
3413 showEventEditor(); 3414 showEventEditor();
3414 mEventEditor->newEvent(fromHint,toHint,allDay); 3415 mEventEditor->newEvent(fromHint,toHint,allDay);
3415 if ( mFilterView->filtersEnabled() ) { 3416 if ( mFilterView->filtersEnabled() ) {
3416 CalFilter *filter = mFilterView->selectedFilter(); 3417 CalFilter *filter = mFilterView->selectedFilter();
3417 if (filter && filter->showCategories()) { 3418 if (filter && filter->showCategories()) {
3418 mEventEditor->setCategories(filter->categoryList().join(",") ); 3419 mEventEditor->setCategories(filter->categoryList().join(",") );
3419 } 3420 }
3420 if ( filter ) 3421 if ( filter )
3421 mEventEditor->setSecrecy( filter->getSecrecy() ); 3422 mEventEditor->setSecrecy( filter->getSecrecy() );
3422 } 3423 }
3423 mEventEditor->exec(); 3424 mEventEditor->exec();
3424 setActiveWindow(); 3425 setActiveWindow();
3425} 3426}
3426void CalendarView::todoAdded(Todo * t) 3427void CalendarView::todoAdded(Todo * t)
3427{ 3428{
3428 3429
3429 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 3430 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
3430 updateTodoViews(); 3431 updateTodoViews();
3431} 3432}
3432void CalendarView::todoChanged(Todo * t) 3433void CalendarView::todoChanged(Todo * t)
3433{ 3434{
3434 emit todoModified( t, 4 ); 3435 emit todoModified( t, 4 );
3435 // updateTodoViews(); 3436 // updateTodoViews();
3436} 3437}
3437void CalendarView::todoToBeDeleted(Todo *) 3438void CalendarView::todoToBeDeleted(Todo *)
3438{ 3439{
3439 //qDebug("todoToBeDeleted(Todo *) "); 3440 //qDebug("todoToBeDeleted(Todo *) ");
3440 updateTodoViews(); 3441 updateTodoViews();
3441} 3442}
3442void CalendarView::todoDeleted() 3443void CalendarView::todoDeleted()
3443{ 3444{
3444 //qDebug(" todoDeleted()"); 3445 //qDebug(" todoDeleted()");
3445 updateTodoViews(); 3446 updateTodoViews();
3446} 3447}
3447 3448
3448 3449
3449void CalendarView::newTodoDateTime( QDateTime dt, bool allday ) 3450void CalendarView::newTodoDateTime( QDateTime dt, bool allday )
3450{ 3451{
3451 showTodoEditor(); 3452 showTodoEditor();
3452 mTodoEditor->newTodo(dt,0,allday); 3453 mTodoEditor->newTodo(dt,0,allday);
3453 if ( mFilterView->filtersEnabled() ) { 3454 if ( mFilterView->filtersEnabled() ) {
3454 CalFilter *filter = mFilterView->selectedFilter(); 3455 CalFilter *filter = mFilterView->selectedFilter();
3455 if (filter && filter->showCategories()) { 3456 if (filter && filter->showCategories()) {
3456 mTodoEditor->setCategories(filter->categoryList().join(",") ); 3457 mTodoEditor->setCategories(filter->categoryList().join(",") );
3457 } 3458 }
3458 if ( filter ) 3459 if ( filter )
3459 mTodoEditor->setSecrecy( filter->getSecrecy() ); 3460 mTodoEditor->setSecrecy( filter->getSecrecy() );
3460 } 3461 }
3461 mTodoEditor->exec(); 3462 mTodoEditor->exec();
3462 setActiveWindow(); 3463 setActiveWindow();
3463} 3464}
3464 3465
3465void CalendarView::newTodo() 3466void CalendarView::newTodo()
3466{ 3467{
3467 newTodoDateTime( QDateTime(),true ); 3468 newTodoDateTime( QDateTime(),true );
3468} 3469}
3469 3470
3470void CalendarView::newSubTodo() 3471void CalendarView::newSubTodo()
3471{ 3472{
3472 Todo *todo = selectedTodo(); 3473 Todo *todo = selectedTodo();
3473 if ( todo ) newSubTodo( todo ); 3474 if ( todo ) newSubTodo( todo );
3474} 3475}
3475 3476
3476void CalendarView::newSubTodo(Todo *parentEvent) 3477void CalendarView::newSubTodo(Todo *parentEvent)
3477{ 3478{
3478 3479
3479 showTodoEditor(); 3480 showTodoEditor();
3480 mTodoEditor->newTodo(QDateTime(),parentEvent,true); 3481 mTodoEditor->newTodo(QDateTime(),parentEvent,true);
3481 mTodoEditor->exec(); 3482 mTodoEditor->exec();
3482 setActiveWindow(); 3483 setActiveWindow();
3483} 3484}
3484 3485
3485void CalendarView::newFloatingEvent() 3486void CalendarView::newFloatingEvent()
3486{ 3487{
3487 DateList tmpList = mNavigator->selectedDates(); 3488 DateList tmpList = mNavigator->selectedDates();
3488 QDate date = tmpList.first(); 3489 QDate date = tmpList.first();
3489 3490
3490 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 3491 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
3491 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 3492 QDateTime( date, QTime( 12, 0, 0 ) ), true );
3492} 3493}
3493 3494
3494 3495
3495void CalendarView::editEvent( Event *event ) 3496void CalendarView::editEvent( Event *event )
3496{ 3497{
3497 3498
3498 if ( !event ) return; 3499 if ( !event ) return;
3499 if ( event->isReadOnly() ) { 3500 if ( event->isReadOnly() ) {
3500 showEvent( event ); 3501 showEvent( event );
3501 return; 3502 return;
3502 } 3503 }
3503 showEventEditor(); 3504 showEventEditor();
3504 mEventEditor->editEvent( event , mFlagEditDescription); 3505 mEventEditor->editEvent( event , mFlagEditDescription);
3505 mEventEditor->exec(); 3506 mEventEditor->exec();
3506 setActiveWindow(); 3507 setActiveWindow();
3507 3508
3508} 3509}
3509void CalendarView::editJournal( Journal *jour ) 3510void CalendarView::editJournal( Journal *jour )
3510{ 3511{
3511 if ( !jour ) return; 3512 if ( !jour ) return;
3512 mDialogManager->hideSearchDialog(); 3513 mDialogManager->hideSearchDialog();
3513 mViewManager->showJournalView(); 3514 mViewManager->showJournalView();
3514 mNavigator->slotDaySelect( jour->dtStart().date() ); 3515 mNavigator->slotDaySelect( jour->dtStart().date() );
3515} 3516}
3516void CalendarView::editTodo( Todo *todo ) 3517void CalendarView::editTodo( Todo *todo )
3517{ 3518{
3518 if ( !todo ) return; 3519 if ( !todo ) return;
3519 3520
3520 if ( todo->isReadOnly() ) { 3521 if ( todo->isReadOnly() ) {
3521 showTodo( todo ); 3522 showTodo( todo );
3522 return; 3523 return;
3523 } 3524 }
3524 showTodoEditor(); 3525 showTodoEditor();
3525 mTodoEditor->editTodo( todo ,mFlagEditDescription); 3526 mTodoEditor->editTodo( todo ,mFlagEditDescription);
3526 mTodoEditor->exec(); 3527 mTodoEditor->exec();
3527 setActiveWindow(); 3528 setActiveWindow();
3528 3529
3529} 3530}
3530 3531
3531KOEventViewerDialog* CalendarView::getEventViewerDialog() 3532KOEventViewerDialog* CalendarView::getEventViewerDialog()
3532{ 3533{
3533 if ( !mEventViewerDialog ) { 3534 if ( !mEventViewerDialog ) {
3534 mEventViewerDialog = new KOEventViewerDialog(0); 3535 mEventViewerDialog = new KOEventViewerDialog(0);
3535 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 3536 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
3536 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 3537 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
3537 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 3538 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
3538 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 3539 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
3539 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 3540 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
3540 viewManager(), SLOT( showAgendaView( bool ) ) ); 3541 viewManager(), SLOT( showAgendaView( bool ) ) );
3541 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()), 3542 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()),
3542 this, SLOT( slotViewerClosed() ) ); 3543 this, SLOT( slotViewerClosed() ) );
3543 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ), 3544 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ),
3544 this, SLOT( todoChanged(Todo *) ) ); 3545 this, SLOT( todoChanged(Todo *) ) );
3545 connect( mEventViewerDialog, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); 3546 connect( mEventViewerDialog, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) ));
3546 mEventViewerDialog->resize( 640, 480 ); 3547 mEventViewerDialog->resize( 640, 480 );
3547 3548
3548 } 3549 }
3549 return mEventViewerDialog; 3550 return mEventViewerDialog;
3550} 3551}
3551void CalendarView::showEvent(Event *event) 3552void CalendarView::showEvent(Event *event)
3552{ 3553{
3553 getEventViewerDialog()->setEvent(event); 3554 getEventViewerDialog()->setEvent(event);
3554 getEventViewerDialog()->showMe(); 3555 getEventViewerDialog()->showMe();
3555} 3556}
3556 3557
3557void CalendarView::showTodo(Todo *event) 3558void CalendarView::showTodo(Todo *event)
3558{ 3559{
3559 getEventViewerDialog()->setTodo(event); 3560 getEventViewerDialog()->setTodo(event);
3560 getEventViewerDialog()->showMe(); 3561 getEventViewerDialog()->showMe();
3561} 3562}
3562void CalendarView::showJournal( Journal *jour ) 3563void CalendarView::showJournal( Journal *jour )
3563{ 3564{
3564 getEventViewerDialog()->setJournal(jour); 3565 getEventViewerDialog()->setJournal(jour);
3565 getEventViewerDialog()->showMe(); 3566 getEventViewerDialog()->showMe();
3566 3567
3567} 3568}
3568// void CalendarView::todoModified (Todo *event, int changed) 3569// void CalendarView::todoModified (Todo *event, int changed)
3569// { 3570// {
3570// // if (mDialogList.find (event) != mDialogList.end ()) { 3571// // if (mDialogList.find (event) != mDialogList.end ()) {
3571// // kdDebug() << "Todo modified and open" << endl; 3572// // kdDebug() << "Todo modified and open" << endl;
3572// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 3573// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
3573// // temp->modified (changed); 3574// // temp->modified (changed);
3574 3575
3575// // } 3576// // }
3576 3577
3577// mViewManager->updateView(); 3578// mViewManager->updateView();
3578// } 3579// }
3579 3580
3580void CalendarView::appointment_show() 3581void CalendarView::appointment_show()
3581{ 3582{
3582 Event *anEvent = 0; 3583 Event *anEvent = 0;
3583 3584
3584 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3585 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3585 3586
3586 if (mViewManager->currentView()->isEventView()) { 3587 if (mViewManager->currentView()->isEventView()) {
3587 if ( incidence && incidence->typeID() == eventID ) { 3588 if ( incidence && incidence->typeID() == eventID ) {
3588 anEvent = static_cast<Event *>(incidence); 3589 anEvent = static_cast<Event *>(incidence);
3589 } 3590 }
3590 } 3591 }
3591 3592
3592 if (!anEvent) { 3593 if (!anEvent) {
3593 KNotifyClient::beep(); 3594 KNotifyClient::beep();
3594 return; 3595 return;
3595 } 3596 }
3596 3597
3597 showEvent(anEvent); 3598 showEvent(anEvent);
3598} 3599}
3599 3600
3600void CalendarView::appointment_edit() 3601void CalendarView::appointment_edit()
3601{ 3602{
3602 Event *anEvent = 0; 3603 Event *anEvent = 0;
3603 3604
3604 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3605 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3605 3606
3606 if (mViewManager->currentView()->isEventView()) { 3607 if (mViewManager->currentView()->isEventView()) {
3607 if ( incidence && incidence->typeID() == eventID ) { 3608 if ( incidence && incidence->typeID() == eventID ) {
3608 anEvent = static_cast<Event *>(incidence); 3609 anEvent = static_cast<Event *>(incidence);
3609 } 3610 }
3610 } 3611 }
3611 3612
3612 if (!anEvent) { 3613 if (!anEvent) {
3613 KNotifyClient::beep(); 3614 KNotifyClient::beep();
3614 return; 3615 return;
3615 } 3616 }
3616 3617
3617 editEvent(anEvent); 3618 editEvent(anEvent);
3618} 3619}
3619 3620
3620void CalendarView::appointment_delete() 3621void CalendarView::appointment_delete()
3621{ 3622{
3622 Event *anEvent = 0; 3623 Event *anEvent = 0;
3623 3624
3624 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3625 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3625 3626
3626 if (mViewManager->currentView()->isEventView()) { 3627 if (mViewManager->currentView()->isEventView()) {
3627 if ( incidence && incidence->typeID() == eventID ) { 3628 if ( incidence && incidence->typeID() == eventID ) {
3628 anEvent = static_cast<Event *>(incidence); 3629 anEvent = static_cast<Event *>(incidence);
3629 } 3630 }
3630 } 3631 }
3631 3632
3632 if (!anEvent) { 3633 if (!anEvent) {
3633 KNotifyClient::beep(); 3634 KNotifyClient::beep();
3634 return; 3635 return;
3635 } 3636 }
3636 3637
3637 deleteEvent(anEvent); 3638 deleteEvent(anEvent);
3638} 3639}
3639 3640
3640void CalendarView::todo_resub( Todo * parent, Todo * sub ) 3641void CalendarView::todo_resub( Todo * parent, Todo * sub )
3641{ 3642{
3642 if (!sub) return; 3643 if (!sub) return;
3643 if ( sub->relatedTo() == parent ) 3644 if ( sub->relatedTo() == parent )
3644 return; 3645 return;
3645 sub->setRelatedTo(parent); 3646 sub->setRelatedTo(parent);
3646 sub->updated(); 3647 sub->updated();
3647 setModified(true); 3648 setModified(true);
3648 updateView(); 3649 updateView();
3649} 3650}
3650void CalendarView::todo_unsub(Todo *anTodo ) 3651void CalendarView::todo_unsub(Todo *anTodo )
3651{ 3652{
3652 todo_resub( 0, anTodo ); 3653 todo_resub( 0, anTodo );
3653} 3654}
3654 3655
3655void CalendarView::deleteTodo(Todo *todo) 3656void CalendarView::deleteTodo(Todo *todo)
3656{ 3657{
3657 if (!todo) { 3658 if (!todo) {
3658 KNotifyClient::beep(); 3659 KNotifyClient::beep();
3659 return; 3660 return;
3660 } 3661 }
3661 if (KOPrefs::instance()->mConfirm) { 3662 if (KOPrefs::instance()->mConfirm) {
3662 QString text = KGlobal::formatMessage ( todo->summary(),0 ); 3663 QString text = KGlobal::formatMessage ( todo->summary(),0 );
3663 if (!todo->relations().isEmpty()) { 3664 if (!todo->relations().isEmpty()) {
3664 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!"); 3665 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!");
3665 3666
3666 } 3667 }
3667 switch (msgItemDelete(i18n("Todo:") +"\n"+text)) { 3668 switch (msgItemDelete(i18n("Todo:") +"\n"+text)) {
3668 case KMessageBox::Continue: // OK 3669 case KMessageBox::Continue: // OK
3669 bool deleteT = false; 3670 bool deleteT = false;
3670 if (!todo->relations().isEmpty()) { 3671 if (!todo->relations().isEmpty()) {
3671 deleteT = removeCompletedSubTodos( todo ); 3672 deleteT = removeCompletedSubTodos( todo );
3672 } 3673 }
3673 // deleteT == true: todo already deleted in removeCompletedSubTodos 3674 // deleteT == true: todo already deleted in removeCompletedSubTodos
3674 if ( !deleteT ) { 3675 if ( !deleteT ) {
3675 checkExternalId( todo ); 3676 checkExternalId( todo );
3676 calendar()->deleteTodo(todo); 3677 calendar()->deleteTodo(todo);
3677 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3678 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3678 updateView(); 3679 updateView();
3679 } 3680 }
3680 break; 3681 break;
3681 } // switch 3682 } // switch
3682 } else { 3683 } else {
3683 checkExternalId( todo ); 3684 checkExternalId( todo );
3684 mCalendar->deleteTodo(todo); 3685 mCalendar->deleteTodo(todo);
3685 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3686 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3686 updateView(); 3687 updateView();
3687 } 3688 }
3688 3689
3689 emit updateSearchDialog(); 3690 emit updateSearchDialog();
3690} 3691}
3691void CalendarView::deleteJournal(Journal *jour) 3692void CalendarView::deleteJournal(Journal *jour)
3692{ 3693{
3693 if (!jour) { 3694 if (!jour) {
3694 KNotifyClient::beep(); 3695 KNotifyClient::beep();
3695 return; 3696 return;
3696 } 3697 }
3697 if (KOPrefs::instance()->mConfirm) { 3698 if (KOPrefs::instance()->mConfirm) {
3698 3699
3699 QString des; 3700 QString des;
3700 if ( !jour->summary().isEmpty() ) { 3701 if ( !jour->summary().isEmpty() ) {
3701 des = jour->summary(); 3702 des = jour->summary();
3702 } else { 3703 } else {
3703 des = jour->description().left(30); 3704 des = jour->description().left(30);
3704 des = des.simplifyWhiteSpace (); 3705 des = des.simplifyWhiteSpace ();
3705 des.replace (QRegExp ("\\n"),"" ); 3706 des.replace (QRegExp ("\\n"),"" );
3706 des.replace (QRegExp ("\\r"),"" ); 3707 des.replace (QRegExp ("\\r"),"" );
3707 } 3708 }
3708 switch (msgItemDelete( i18n("Journal:") +"\n"+KGlobal::formatMessage ( des,0 ))) { 3709 switch (msgItemDelete( i18n("Journal:") +"\n"+KGlobal::formatMessage ( des,0 ))) {
3709 case KMessageBox::Continue: // OK 3710 case KMessageBox::Continue: // OK
3710 calendar()->deleteJournal(jour); 3711 calendar()->deleteJournal(jour);
3711 updateView(); 3712 updateView();
3712 break; 3713 break;
3713 } // switch 3714 } // switch
3714 } else { 3715 } else {
3715 calendar()->deleteJournal(jour);; 3716 calendar()->deleteJournal(jour);;
3716 updateView(); 3717 updateView();
3717 } 3718 }
3718 emit updateSearchDialog(); 3719 emit updateSearchDialog();
3719} 3720}
3720 3721
3721void CalendarView::deleteEvent(Event *anEvent) 3722void CalendarView::deleteEvent(Event *anEvent)
3722{ 3723{
3723 if (!anEvent) { 3724 if (!anEvent) {
3724 KNotifyClient::beep(); 3725 KNotifyClient::beep();
3725 return; 3726 return;
3726 } 3727 }
3727 3728
3728 if (anEvent->recurrence()->doesRecur()) { 3729 if (anEvent->recurrence()->doesRecur()) {
3729 QDate itemDate = mViewManager->currentSelectionDate(); 3730 QDate itemDate = mViewManager->currentSelectionDate();
3730 int km; 3731 int km;
3731 if (!itemDate.isValid()) { 3732 if (!itemDate.isValid()) {
3732 //kdDebug() << "Date Not Valid" << endl; 3733 //kdDebug() << "Date Not Valid" << endl;
3733 if (KOPrefs::instance()->mConfirm) { 3734 if (KOPrefs::instance()->mConfirm) {
3734 km = KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 3735 km = KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
3735 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 3736 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
3736 i18n("KO/Pi Confirmation"),i18n("Delete All")); 3737 i18n("KO/Pi Confirmation"),i18n("Delete All"));
3737 if ( km == KMessageBox::Continue ) 3738 if ( km == KMessageBox::Continue )
3738 km = KMessageBox::No; // No = all below 3739 km = KMessageBox::No; // No = all below
3739 } else 3740 } else
3740 km = KMessageBox::No; 3741 km = KMessageBox::No;
3741 } else { 3742 } else {
3742 km = KMessageBox::warningYesNoCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 3743 km = KMessageBox::warningYesNoCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
3743 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 3744 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
3744 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 3745 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
3745 i18n("KO/Pi Confirmation"),i18n("Current"), 3746 i18n("KO/Pi Confirmation"),i18n("Current"),
3746 i18n("All")); 3747 i18n("All"));
3747 } 3748 }
3748 switch(km) { 3749 switch(km) {
3749 3750
3750 case KMessageBox::No: // Continue // all 3751 case KMessageBox::No: // Continue // all
3751 //qDebug("KMessageBox::No "); 3752 //qDebug("KMessageBox::No ");
3752 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3753 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3753 schedule(Scheduler::Cancel,anEvent); 3754 schedule(Scheduler::Cancel,anEvent);
3754 3755
3755 checkExternalId( anEvent); 3756 checkExternalId( anEvent);
3756 mCalendar->deleteEvent(anEvent); 3757 mCalendar->deleteEvent(anEvent);
3757 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 3758 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
3758 break; 3759 break;
3759 3760
3760 // Disabled because it does not work 3761 // Disabled because it does not work
3761 //#if 0 3762 //#if 0
3762 case KMessageBox::Yes: // just this one 3763 case KMessageBox::Yes: // just this one
3763 //QDate qd = mNavigator->selectedDates().first(); 3764 //QDate qd = mNavigator->selectedDates().first();
3764 //if (!qd.isValid()) { 3765 //if (!qd.isValid()) {
3765 // kdDebug() << "no date selected, or invalid date" << endl; 3766 // kdDebug() << "no date selected, or invalid date" << endl;
3766 // KNotifyClient::beep(); 3767 // KNotifyClient::beep();
3767 // return; 3768 // return;
3768 //} 3769 //}
3769 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 3770 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
3770 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 3771 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
3771 anEvent->addExDate(itemDate); 3772 anEvent->addExDate(itemDate);
3772 int duration = anEvent->recurrence()->duration(); 3773 int duration = anEvent->recurrence()->duration();
3773 if ( duration > 0 ) { 3774 if ( duration > 0 ) {
3774 anEvent->recurrence()->setDuration( duration - 1 ); 3775 anEvent->recurrence()->setDuration( duration - 1 );
3775 } 3776 }
3776 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 3777 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
3777 } 3778 }
3778 break; 3779 break;
3779 //#endif 3780 //#endif
3780 } // switch 3781 } // switch
3781 } else { 3782 } else {
3782 if (KOPrefs::instance()->mConfirm) { 3783 if (KOPrefs::instance()->mConfirm) {
3783 switch (KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 3784 switch (KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
3784 i18n("\nAre you sure you want\nto delete this event?"), 3785 i18n("\nAre you sure you want\nto delete this event?"),
3785 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 3786 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
3786 case KMessageBox::Continue: // OK 3787 case KMessageBox::Continue: // OK
3787 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3788 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3788 schedule(Scheduler::Cancel,anEvent); 3789 schedule(Scheduler::Cancel,anEvent);
3789 checkExternalId( anEvent); 3790 checkExternalId( anEvent);
3790 mCalendar->deleteEvent(anEvent); 3791 mCalendar->deleteEvent(anEvent);
3791 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3792 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3792 break; 3793 break;
3793 } // switch 3794 } // switch
3794 } else { 3795 } else {
3795 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3796 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3796 schedule(Scheduler::Cancel,anEvent); 3797 schedule(Scheduler::Cancel,anEvent);
3797 checkExternalId( anEvent); 3798 checkExternalId( anEvent);
3798 mCalendar->deleteEvent(anEvent); 3799 mCalendar->deleteEvent(anEvent);
3799 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3800 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3800 } 3801 }
3801 } // if-else 3802 } // if-else
3802 emit updateSearchDialog(); 3803 emit updateSearchDialog();
3803} 3804}
3804 3805
3805bool CalendarView::deleteEvent(const QString &uid) 3806bool CalendarView::deleteEvent(const QString &uid)
3806{ 3807{
3807 Event *ev = mCalendar->event(uid); 3808 Event *ev = mCalendar->event(uid);
3808 if (ev) { 3809 if (ev) {
3809 deleteEvent(ev); 3810 deleteEvent(ev);
3810 return true; 3811 return true;
3811 } else { 3812 } else {
3812 return false; 3813 return false;
3813 } 3814 }
3814} 3815}
3815 3816
3816/*****************************************************************************/ 3817/*****************************************************************************/
3817 3818
3818void CalendarView::action_mail() 3819void CalendarView::action_mail()
3819{ 3820{
3820#ifndef KORG_NOMAIL 3821#ifndef KORG_NOMAIL
3821 KOMailClient mailClient; 3822 KOMailClient mailClient;
3822 3823
3823 Incidence *incidence = currentSelection(); 3824 Incidence *incidence = currentSelection();
3824 3825
3825 if (!incidence) { 3826 if (!incidence) {
3826 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3827 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3827 return; 3828 return;
3828 } 3829 }
3829 if(incidence->attendeeCount() == 0 ) { 3830 if(incidence->attendeeCount() == 0 ) {
3830 KMessageBox::sorry(this, 3831 KMessageBox::sorry(this,
3831 i18n("Can't generate mail:\nNo attendees defined.\n")); 3832 i18n("Can't generate mail:\nNo attendees defined.\n"));
3832 return; 3833 return;
3833 } 3834 }
3834 3835
3835 CalendarLocal cal_tmp; 3836 CalendarLocal cal_tmp;
3836 Event *event = 0; 3837 Event *event = 0;
3837 Event *ev = 0; 3838 Event *ev = 0;
3838 if ( incidence && incidence->typeID() == eventID ) { 3839 if ( incidence && incidence->typeID() == eventID ) {
3839 event = static_cast<Event *>(incidence); 3840 event = static_cast<Event *>(incidence);
3840 ev = new Event(*event); 3841 ev = new Event(*event);
3841 cal_tmp.addEvent(ev); 3842 cal_tmp.addEvent(ev);
3842 } 3843 }
3843 ICalFormat mForm(); 3844 ICalFormat mForm();
3844 QString attachment = mForm.toString( &cal_tmp ); 3845 QString attachment = mForm.toString( &cal_tmp );
3845 if (ev) delete(ev); 3846 if (ev) delete(ev);
3846 3847
3847 mailClient.mailAttendees(currentSelection(), attachment); 3848 mailClient.mailAttendees(currentSelection(), attachment);
3848 3849
3849#endif 3850#endif
3850 3851
3851#if 0 3852#if 0
3852 Event *anEvent = 0; 3853 Event *anEvent = 0;
3853 if (mViewManager->currentView()->isEventView()) { 3854 if (mViewManager->currentView()->isEventView()) {
3854 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); 3855 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
3855 } 3856 }
3856 3857
3857 if (!anEvent) { 3858 if (!anEvent) {
3858 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3859 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3859 return; 3860 return;
3860 } 3861 }
3861 if(anEvent->attendeeCount() == 0 ) { 3862 if(anEvent->attendeeCount() == 0 ) {
3862 KMessageBox::sorry(this, 3863 KMessageBox::sorry(this,
3863 i18n("Can't generate mail:\nNo attendees defined.\n")); 3864 i18n("Can't generate mail:\nNo attendees defined.\n"));
3864 return; 3865 return;
3865 } 3866 }
3866 3867
3867 mailobject.emailEvent(anEvent); 3868 mailobject.emailEvent(anEvent);
3868#endif 3869#endif
3869} 3870}
3870 3871
3871 3872
3872void CalendarView::schedule_publish(Incidence *incidence) 3873void CalendarView::schedule_publish(Incidence *incidence)
3873{ 3874{
3874 Event *event = 0; 3875 Event *event = 0;
3875 Todo *todo = 0; 3876 Todo *todo = 0;
3876 3877
3877 if (incidence == 0) { 3878 if (incidence == 0) {
3878 incidence = mViewManager->currentView()->selectedIncidences().first(); 3879 incidence = mViewManager->currentView()->selectedIncidences().first();
3879 if (incidence == 0) { 3880 if (incidence == 0) {
3880 incidence = mTodoList->selectedIncidences().first(); 3881 incidence = mTodoList->selectedIncidences().first();
3881 } 3882 }
3882 } 3883 }
3883 if ( incidence && incidence->typeID() == eventID ) { 3884 if ( incidence && incidence->typeID() == eventID ) {
3884 event = static_cast<Event *>(incidence); 3885 event = static_cast<Event *>(incidence);
3885 } else { 3886 } else {
3886 if ( incidence && incidence->typeID() == todoID ) { 3887 if ( incidence && incidence->typeID() == todoID ) {
3887 todo = static_cast<Todo *>(incidence); 3888 todo = static_cast<Todo *>(incidence);
3888 } 3889 }
3889 } 3890 }
3890 3891
3891 if (!event && !todo) { 3892 if (!event && !todo) {
3892 KMessageBox::sorry(this,i18n("No event selected.")); 3893 KMessageBox::sorry(this,i18n("No event selected."));
3893 return; 3894 return;
3894 } 3895 }
3895 3896
3896 PublishDialog *publishdlg = new PublishDialog(); 3897 PublishDialog *publishdlg = new PublishDialog();
3897 if (incidence->attendeeCount()>0) { 3898 if (incidence->attendeeCount()>0) {
3898 QPtrList<Attendee> attendees = incidence->attendees(); 3899 QPtrList<Attendee> attendees = incidence->attendees();
3899 attendees.first(); 3900 attendees.first();
3900 while ( attendees.current()!=0 ) { 3901 while ( attendees.current()!=0 ) {
3901 publishdlg->addAttendee(attendees.current()); 3902 publishdlg->addAttendee(attendees.current());
3902 attendees.next(); 3903 attendees.next();
3903 } 3904 }
3904 } 3905 }
3905 bool send = true; 3906 bool send = true;
3906 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 3907 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
3907 if ( publishdlg->exec() != QDialog::Accepted ) 3908 if ( publishdlg->exec() != QDialog::Accepted )
3908 send = false; 3909 send = false;
3909 } 3910 }
3910 if ( send ) { 3911 if ( send ) {
3911 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3912 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3912 if ( event ) { 3913 if ( event ) {
3913 Event *ev = new Event(*event); 3914 Event *ev = new Event(*event);
3914 ev->registerObserver(0); 3915 ev->registerObserver(0);
3915 ev->clearAttendees(); 3916 ev->clearAttendees();
3916 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3917 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3917 delete(ev); 3918 delete(ev);
3918 } 3919 }
3919 } else { 3920 } else {
3920 if ( todo ) { 3921 if ( todo ) {
3921 Todo *ev = new Todo(*todo); 3922 Todo *ev = new Todo(*todo);
3922 ev->registerObserver(0); 3923 ev->registerObserver(0);
3923 ev->clearAttendees(); 3924 ev->clearAttendees();
3924 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3925 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3925 delete(ev); 3926 delete(ev);
3926 } 3927 }
3927 } 3928 }
3928 } 3929 }
3929 } 3930 }
3930 delete publishdlg; 3931 delete publishdlg;
3931} 3932}
3932 3933
3933void CalendarView::schedule_request(Incidence *incidence) 3934void CalendarView::schedule_request(Incidence *incidence)
3934{ 3935{
3935 schedule(Scheduler::Request,incidence); 3936 schedule(Scheduler::Request,incidence);
3936} 3937}
3937 3938
3938void CalendarView::schedule_refresh(Incidence *incidence) 3939void CalendarView::schedule_refresh(Incidence *incidence)
3939{ 3940{
3940 schedule(Scheduler::Refresh,incidence); 3941 schedule(Scheduler::Refresh,incidence);
3941} 3942}
3942 3943
3943void CalendarView::schedule_cancel(Incidence *incidence) 3944void CalendarView::schedule_cancel(Incidence *incidence)
3944{ 3945{
3945 schedule(Scheduler::Cancel,incidence); 3946 schedule(Scheduler::Cancel,incidence);
3946} 3947}
3947 3948
3948void CalendarView::schedule_add(Incidence *incidence) 3949void CalendarView::schedule_add(Incidence *incidence)
3949{ 3950{
3950 schedule(Scheduler::Add,incidence); 3951 schedule(Scheduler::Add,incidence);
3951} 3952}
3952 3953
3953void CalendarView::schedule_reply(Incidence *incidence) 3954void CalendarView::schedule_reply(Incidence *incidence)
3954{ 3955{
3955 schedule(Scheduler::Reply,incidence); 3956 schedule(Scheduler::Reply,incidence);
3956} 3957}
3957 3958
3958void CalendarView::schedule_counter(Incidence *incidence) 3959void CalendarView::schedule_counter(Incidence *incidence)
3959{ 3960{
3960 schedule(Scheduler::Counter,incidence); 3961 schedule(Scheduler::Counter,incidence);
3961} 3962}
3962 3963
3963void CalendarView::schedule_declinecounter(Incidence *incidence) 3964void CalendarView::schedule_declinecounter(Incidence *incidence)
3964{ 3965{
3965 schedule(Scheduler::Declinecounter,incidence); 3966 schedule(Scheduler::Declinecounter,incidence);
3966} 3967}
3967 3968
3968void CalendarView::schedule_publish_freebusy(int daysToPublish) 3969void CalendarView::schedule_publish_freebusy(int daysToPublish)
3969{ 3970{
3970 QDateTime start = QDateTime::currentDateTime(); 3971 QDateTime start = QDateTime::currentDateTime();
3971 QDateTime end = start.addDays(daysToPublish); 3972 QDateTime end = start.addDays(daysToPublish);
3972 3973
3973 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); 3974 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
3974 freebusy->setOrganizer(KOPrefs::instance()->email()); 3975 freebusy->setOrganizer(KOPrefs::instance()->email());
3975 3976
3976 3977
3977 PublishDialog *publishdlg = new PublishDialog(); 3978 PublishDialog *publishdlg = new PublishDialog();
3978 if ( publishdlg->exec() == QDialog::Accepted ) { 3979 if ( publishdlg->exec() == QDialog::Accepted ) {
3979 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3980 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3980 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { 3981 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
3981 delete(freebusy); 3982 delete(freebusy);
3982 } 3983 }
3983 } 3984 }
3984 delete publishdlg; 3985 delete publishdlg;
3985} 3986}
3986 3987
3987void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) 3988void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
3988{ 3989{
3989 Event *event = 0; 3990 Event *event = 0;
3990 Todo *todo = 0; 3991 Todo *todo = 0;
3991 3992
3992 if (incidence == 0) { 3993 if (incidence == 0) {
3993 incidence = mViewManager->currentView()->selectedIncidences().first(); 3994 incidence = mViewManager->currentView()->selectedIncidences().first();
3994 if (incidence == 0) { 3995 if (incidence == 0) {
3995 incidence = mTodoList->selectedIncidences().first(); 3996 incidence = mTodoList->selectedIncidences().first();
3996 } 3997 }
3997 } 3998 }
3998 if ( incidence && incidence->typeID() == eventID ) { 3999 if ( incidence && incidence->typeID() == eventID ) {
3999 event = static_cast<Event *>(incidence); 4000 event = static_cast<Event *>(incidence);
4000 } 4001 }
4001 if ( incidence && incidence->typeID() == todoID ) { 4002 if ( incidence && incidence->typeID() == todoID ) {
4002 todo = static_cast<Todo *>(incidence); 4003 todo = static_cast<Todo *>(incidence);
4003 } 4004 }
4004 4005
4005 if (!event && !todo) { 4006 if (!event && !todo) {
4006 KMessageBox::sorry(this,i18n("No event selected.")); 4007 KMessageBox::sorry(this,i18n("No event selected."));
4007 return; 4008 return;
4008 } 4009 }
4009 4010
4010 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { 4011 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
4011 KMessageBox::sorry(this,i18n("The event has no attendees.")); 4012 KMessageBox::sorry(this,i18n("The event has no attendees."));
4012 return; 4013 return;
4013 } 4014 }
4014 4015
4015 Event *ev = 0; 4016 Event *ev = 0;
4016 if (event) ev = new Event(*event); 4017 if (event) ev = new Event(*event);
4017 Todo *to = 0; 4018 Todo *to = 0;
4018 if (todo) to = new Todo(*todo); 4019 if (todo) to = new Todo(*todo);
4019 4020
4020 if (method == Scheduler::Reply || method == Scheduler::Refresh) { 4021 if (method == Scheduler::Reply || method == Scheduler::Refresh) {
4021 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 4022 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
4022 if (!me) { 4023 if (!me) {
4023 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); 4024 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails."));
4024 return; 4025 return;
4025 } 4026 }
4026 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { 4027 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
4027 StatusDialog *statdlg = new StatusDialog(this); 4028 StatusDialog *statdlg = new StatusDialog(this);
4028 if (!statdlg->exec()==QDialog::Accepted) return; 4029 if (!statdlg->exec()==QDialog::Accepted) return;
4029 me->setStatus( statdlg->status() ); 4030 me->setStatus( statdlg->status() );
4030 delete(statdlg); 4031 delete(statdlg);
4031 } 4032 }
4032 Attendee *menew = new Attendee(*me); 4033 Attendee *menew = new Attendee(*me);
4033 if (ev) { 4034 if (ev) {
4034 ev->clearAttendees(); 4035 ev->clearAttendees();
4035 ev->addAttendee(menew,false); 4036 ev->addAttendee(menew,false);
4036 } else { 4037 } else {
4037 if (to) { 4038 if (to) {
4038 todo->clearAttendees(); 4039 todo->clearAttendees();
4039 todo->addAttendee(menew,false); 4040 todo->addAttendee(menew,false);
4040 } 4041 }
4041 } 4042 }
4042 } 4043 }
4043 4044
4044 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 4045 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
4045 if (ev) { 4046 if (ev) {
4046 if ( !dlg->addMessage(ev,method) ) delete(ev); 4047 if ( !dlg->addMessage(ev,method) ) delete(ev);
4047 } else { 4048 } else {
4048 if (to) { 4049 if (to) {
4049 if ( !dlg->addMessage(to,method) ) delete(to); 4050 if ( !dlg->addMessage(to,method) ) delete(to);
4050 } 4051 }
4051 } 4052 }
4052} 4053}
4053 4054
4054void CalendarView::openAddressbook() 4055void CalendarView::openAddressbook()
4055{ 4056{
4056 KRun::runCommand("kaddressbook"); 4057 KRun::runCommand("kaddressbook");
4057} 4058}
4058 4059
4059void CalendarView::setModified(bool modified) 4060void CalendarView::setModified(bool modified)
4060{ 4061{
4061 if ( modified ) 4062 if ( modified )
4062 emit signalmodified(); 4063 emit signalmodified();
4063 if (mModified != modified) { 4064 if (mModified != modified) {
4064 mModified = modified; 4065 mModified = modified;
4065 emit modifiedChanged(mModified); 4066 emit modifiedChanged(mModified);
4066 } 4067 }
4067} 4068}
4068 4069
4069bool CalendarView::isReadOnly() 4070bool CalendarView::isReadOnly()
4070{ 4071{
4071 return mReadOnly; 4072 return mReadOnly;
4072} 4073}
4073 4074
4074void CalendarView::setReadOnly(bool readOnly) 4075void CalendarView::setReadOnly(bool readOnly)
4075{ 4076{
4076 if (mReadOnly != readOnly) { 4077 if (mReadOnly != readOnly) {
4077 mReadOnly = readOnly; 4078 mReadOnly = readOnly;
4078 emit readOnlyChanged(mReadOnly); 4079 emit readOnlyChanged(mReadOnly);
4079 } 4080 }
4080} 4081}
4081 4082
4082bool CalendarView::isModified() 4083bool CalendarView::isModified()
4083{ 4084{
4084 return mModified; 4085 return mModified;
4085} 4086}
4086void CalendarView::slotprintSelInc() 4087void CalendarView::slotprintSelInc()
4087{ 4088{
4088 if ( currentSelection() == 0 ) { 4089 if ( currentSelection() == 0 ) {
4089 KMessageBox::sorry(this,i18n("There is nothing selected!")); 4090 KMessageBox::sorry(this,i18n("There is nothing selected!"));
4090 return; 4091 return;
4091 } 4092 }
4092 showIncidence(); 4093 showIncidence();
4093 getEventViewerDialog()->print(); 4094 getEventViewerDialog()->print();
4094 4095
4095} 4096}
4096void CalendarView::printSetup() 4097void CalendarView::printSetup()
4097{ 4098{
4098#ifndef KORG_NOPRINTER 4099#ifndef KORG_NOPRINTER
4099 createPrinter(); 4100 createPrinter();
4100 4101
4101 mCalPrinter->setupPrinter(); 4102 mCalPrinter->setupPrinter();
4102#endif 4103#endif
4103} 4104}
4104 4105
4105void CalendarView::print() 4106void CalendarView::print()
4106{ 4107{
4107#ifndef KORG_NOPRINTER 4108#ifndef KORG_NOPRINTER
4108 createPrinter(); 4109 createPrinter();
4109 4110
4110 DateList tmpDateList = mNavigator->selectedDates(); 4111 DateList tmpDateList = mNavigator->selectedDates();
4111 mCalPrinter->print(CalPrinter::Month, 4112 mCalPrinter->print(CalPrinter::Month,
4112 tmpDateList.first(), tmpDateList.last()); 4113 tmpDateList.first(), tmpDateList.last());
4113#endif 4114#endif
4114} 4115}
4115 4116
4116void CalendarView::printPreview() 4117void CalendarView::printPreview()
4117{ 4118{
4118#ifndef KORG_NOPRINTER 4119#ifndef KORG_NOPRINTER
4119 kdDebug() << "CalendarView::printPreview()" << endl; 4120 kdDebug() << "CalendarView::printPreview()" << endl;
4120 4121
4121 createPrinter(); 4122 createPrinter();
4122 4123
4123 DateList tmpDateList = mNavigator->selectedDates(); 4124 DateList tmpDateList = mNavigator->selectedDates();
4124 4125
4125 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), 4126 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(),
4126 tmpDateList.last()); 4127 tmpDateList.last());
4127#endif 4128#endif
4128} 4129}
4129 4130
4130void CalendarView::exportICalendar() 4131void CalendarView::exportICalendar()
4131{ 4132{
4132 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); 4133 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this);
4133 4134
4134 // Force correct extension 4135 // Force correct extension
4135 if (filename.right(4) != ".ics") filename += ".ics"; 4136 if (filename.right(4) != ".ics") filename += ".ics";
4136 4137
4137 FileStorage storage( mCalendar, filename, new ICalFormat() ); 4138 FileStorage storage( mCalendar, filename, new ICalFormat() );
4138 storage.save(); 4139 storage.save();
4139} 4140}
4140 4141
4141bool CalendarView::exportVCalendar( QString filename ) 4142bool CalendarView::exportVCalendar( QString filename )
4142{ 4143{
4143 if (mCalendar->journals().count() > 0) { 4144 if (mCalendar->journals().count() > 0) {
4144 int result = KMessageBox::warningContinueCancel(this, 4145 int result = KMessageBox::warningContinueCancel(this,
4145 i18n("The journal entries can not be\nexported to a vCalendar file."), 4146 i18n("The journal entries can not be\nexported to a vCalendar file."),
4146 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 4147 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
4147 true); 4148 true);
4148 if (result != KMessageBox::Continue) return false; 4149 if (result != KMessageBox::Continue) return false;
4149 } 4150 }
4150 4151
4151 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); 4152 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this);
4152 4153
4153 // Force correct extension 4154 // Force correct extension
4154 if (filename.right(4) != ".vcs") filename += ".vcs"; 4155 if (filename.right(4) != ".vcs") filename += ".vcs";
4155 4156
4156 FileStorage storage( mCalendar, filename, new VCalFormat ); 4157 FileStorage storage( mCalendar, filename, new VCalFormat );
4157 return storage.save(); 4158 return storage.save();
4158 4159
4159} 4160}
4160 4161
4161void CalendarView::eventUpdated(Incidence *) 4162void CalendarView::eventUpdated(Incidence *)
4162{ 4163{
4163 setModified(); 4164 setModified();
4164 // Don't call updateView here. The code, which has caused the update of the 4165 // Don't call updateView here. The code, which has caused the update of the
4165 // event is responsible for updating the view. 4166 // event is responsible for updating the view.
4166 // updateView(); 4167 // updateView();
4167} 4168}
4168 4169
4169void CalendarView::adaptNavigationUnits() 4170void CalendarView::adaptNavigationUnits()
4170{ 4171{
4171 if (mViewManager->currentView()->isEventView()) { 4172 if (mViewManager->currentView()->isEventView()) {
4172 int days = mViewManager->currentView()->currentDateCount(); 4173 int days = mViewManager->currentView()->currentDateCount();
4173 if (days == 1) { 4174 if (days == 1) {
4174 emit changeNavStringPrev(i18n("&Previous Day")); 4175 emit changeNavStringPrev(i18n("&Previous Day"));
4175 emit changeNavStringNext(i18n("&Next Day")); 4176 emit changeNavStringNext(i18n("&Next Day"));
4176 } else { 4177 } else {
4177 emit changeNavStringPrev(i18n("&Previous Week")); 4178 emit changeNavStringPrev(i18n("&Previous Week"));
4178 emit changeNavStringNext(i18n("&Next Week")); 4179 emit changeNavStringNext(i18n("&Next Week"));
4179 } 4180 }
4180 } 4181 }
4181} 4182}
4182 4183
4183void CalendarView::processMainViewSelection( Incidence *incidence ) 4184void CalendarView::processMainViewSelection( Incidence *incidence )
4184{ 4185{
4185 if ( incidence ) mTodoList->clearSelection(); 4186 if ( incidence ) mTodoList->clearSelection();
4186 processIncidenceSelection( incidence ); 4187 processIncidenceSelection( incidence );
4187} 4188}
4188 4189
4189void CalendarView::processTodoListSelection( Incidence *incidence ) 4190void CalendarView::processTodoListSelection( Incidence *incidence )
4190{ 4191{
4191 if ( incidence && mViewManager->currentView() ) { 4192 if ( incidence && mViewManager->currentView() ) {
4192 mViewManager->currentView()->clearSelection(); 4193 mViewManager->currentView()->clearSelection();
4193 } 4194 }
4194 processIncidenceSelection( incidence ); 4195 processIncidenceSelection( incidence );
4195} 4196}
4196 4197
4197void CalendarView::processIncidenceSelection( Incidence *incidence ) 4198void CalendarView::processIncidenceSelection( Incidence *incidence )
4198{ 4199{
4199 emit incidenceSelected( incidence ); 4200 emit incidenceSelected( incidence );
4200 if ( incidence == mSelectedIncidence ) return; 4201 if ( incidence == mSelectedIncidence ) return;
4201 mSelectedIncidence = incidence; 4202 mSelectedIncidence = incidence;
4202 4203
4203 if ( incidence && incidence->typeID() == eventID ) { 4204 if ( incidence && incidence->typeID() == eventID ) {
4204 Event *event = static_cast<Event *>( incidence ); 4205 Event *event = static_cast<Event *>( incidence );
4205 if ( event->organizer() == KOPrefs::instance()->email() ) { 4206 if ( event->organizer() == KOPrefs::instance()->email() ) {
4206 emit organizerEventsSelected( true ); 4207 emit organizerEventsSelected( true );
4207 } else { 4208 } else {
4208 emit organizerEventsSelected(false); 4209 emit organizerEventsSelected(false);
4209 } 4210 }
4210 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 4211 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
4211 KOPrefs::instance()->email() ) ) { 4212 KOPrefs::instance()->email() ) ) {
4212 emit groupEventsSelected( true ); 4213 emit groupEventsSelected( true );
4213 } else { 4214 } else {
4214 emit groupEventsSelected(false); 4215 emit groupEventsSelected(false);
4215 } 4216 }
4216 return; 4217 return;
4217 } else { 4218 } else {
4218 if ( incidence && incidence->typeID() == todoID ) { 4219 if ( incidence && incidence->typeID() == todoID ) {
4219 emit todoSelected( true ); 4220 emit todoSelected( true );
4220 Todo *event = static_cast<Todo *>( incidence ); 4221 Todo *event = static_cast<Todo *>( incidence );
4221 if ( event->organizer() == KOPrefs::instance()->email() ) { 4222 if ( event->organizer() == KOPrefs::instance()->email() ) {
4222 emit organizerEventsSelected( true ); 4223 emit organizerEventsSelected( true );
4223 } else { 4224 } else {
4224 emit organizerEventsSelected(false); 4225 emit organizerEventsSelected(false);
4225 } 4226 }
4226 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 4227 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
4227 KOPrefs::instance()->email() ) ) { 4228 KOPrefs::instance()->email() ) ) {
4228 emit groupEventsSelected( true ); 4229 emit groupEventsSelected( true );
4229 } else { 4230 } else {
4230 emit groupEventsSelected(false); 4231 emit groupEventsSelected(false);
4231 } 4232 }
4232 return; 4233 return;
4233 } else { 4234 } else {
4234 emit todoSelected( false ); 4235 emit todoSelected( false );
4235 emit organizerEventsSelected(false); 4236 emit organizerEventsSelected(false);
4236 emit groupEventsSelected(false); 4237 emit groupEventsSelected(false);
4237 } 4238 }
4238 return; 4239 return;
4239 } 4240 }
4240 4241
4241 /* if ( incidence && incidence->typeID() == todoID ) { 4242 /* if ( incidence && incidence->typeID() == todoID ) {
4242 emit todoSelected( true ); 4243 emit todoSelected( true );
4243 } else { 4244 } else {
4244 emit todoSelected( false ); 4245 emit todoSelected( false );
4245 }*/ 4246 }*/
4246} 4247}
4247 4248
4248 4249
4249void CalendarView::checkClipboard() 4250void CalendarView::checkClipboard()
4250{ 4251{
4251#ifndef KORG_NODND 4252#ifndef KORG_NODND
4252 if (ICalDrag::canDecode(QApplication::clipboard()->data())) { 4253 if (ICalDrag::canDecode(QApplication::clipboard()->data())) {
4253 emit pasteEnabled(true); 4254 emit pasteEnabled(true);
4254 } else { 4255 } else {
4255 emit pasteEnabled(false); 4256 emit pasteEnabled(false);
4256 } 4257 }
4257#endif 4258#endif
4258} 4259}
4259 4260
4260void CalendarView::showDates(const DateList &selectedDates) 4261void CalendarView::showDates(const DateList &selectedDates)
4261{ 4262{
4262 // kdDebug() << "CalendarView::selectDates()" << endl; 4263 // kdDebug() << "CalendarView::selectDates()" << endl;
4263 4264
4264 4265
4265 if ( !mBlockShowDates ) { 4266 if ( !mBlockShowDates ) {
4266 if ( mViewManager->currentView() ) { 4267 if ( mViewManager->currentView() ) {
4267 updateView( selectedDates.first(), selectedDates.last() ); 4268 updateView( selectedDates.first(), selectedDates.last() );
4268 } else { 4269 } else {
4269 mViewManager->showAgendaView(); 4270 mViewManager->showAgendaView();
4270 } 4271 }
4271 } 4272 }
4272 4273
4273 QDate date = selectedDates.first(); 4274 QDate date = selectedDates.first();
4274 if ( ! date.isValid() ) { 4275 if ( ! date.isValid() ) {
4275 topLevelWidget()->setCaption(""); 4276 topLevelWidget()->setCaption("");
4276 return; 4277 return;
4277 } 4278 }
4278 4279
4279 QString selDates; 4280 QString selDates;
4280 selDates = KGlobal::locale()->formatDate( date, true); 4281 selDates = KGlobal::locale()->formatDate( date, true);
4281 if (selectedDates.first() < selectedDates.last() ) 4282 if (selectedDates.first() < selectedDates.last() )
4282 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); 4283 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true);
4283 else { 4284 else {
4284 QString addString; 4285 QString addString;
4285 if ( date == QDateTime::currentDateTime().date() ) 4286 if ( date == QDateTime::currentDateTime().date() )
4286 addString = i18n("Today"); 4287 addString = i18n("Today");
4287 else if ( date == QDateTime::currentDateTime().date().addDays(1) ) 4288 else if ( date == QDateTime::currentDateTime().date().addDays(1) )
4288 addString = i18n("Tomorrow"); 4289 addString = i18n("Tomorrow");
4289 else if ( date == QDateTime::currentDateTime().date().addDays(-1) ) 4290 else if ( date == QDateTime::currentDateTime().date().addDays(-1) )
4290 addString = i18n("Yesterday"); 4291 addString = i18n("Yesterday");
4291 else if ( date == QDateTime::currentDateTime().date().addDays(-2) ) 4292 else if ( date == QDateTime::currentDateTime().date().addDays(-2) )
4292 addString = i18n("Day before yesterday"); 4293 addString = i18n("Day before yesterday");
4293 else if ( date == QDateTime::currentDateTime().date().addDays(2) ) 4294 else if ( date == QDateTime::currentDateTime().date().addDays(2) )
4294 addString = i18n("Day after tomorrow"); 4295 addString = i18n("Day after tomorrow");
4295 if ( !addString.isEmpty() ) { 4296 if ( !addString.isEmpty() ) {
4296 topLevelWidget()->setCaption( addString+", " + selDates ); 4297 topLevelWidget()->setCaption( addString+", " + selDates );
4297 return; 4298 return;
4298 } 4299 }
4299 } 4300 }
4300 topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); 4301 topLevelWidget()->setCaption( i18n("Dates: ") + selDates );
4301 4302
4302} 4303}
4303 4304
4304QPtrList<CalFilter> CalendarView::filters() 4305QPtrList<CalFilter> CalendarView::filters()
4305{ 4306{
4306 return mFilters; 4307 return mFilters;
4307 4308
4308} 4309}
4309void CalendarView::editFilters() 4310void CalendarView::editFilters()
4310{ 4311{
4311 // kdDebug() << "CalendarView::editFilters()" << endl; 4312 // kdDebug() << "CalendarView::editFilters()" << endl;
4312 4313
4313 CalFilter *filter = mFilters.first(); 4314 CalFilter *filter = mFilters.first();
4314 while(filter) { 4315 while(filter) {
4315 filter = mFilters.next(); 4316 filter = mFilters.next();
4316 } 4317 }
4317 4318
4318 mDialogManager->showFilterEditDialog(&mFilters); 4319 mDialogManager->showFilterEditDialog(&mFilters);
4319 updateFilter(); 4320 updateFilter();
4320} 4321}
4321void CalendarView::toggleFilter() 4322void CalendarView::toggleFilter()
4322{ 4323{
4323 if ( mLeftFrame->isHidden() ) { 4324 if ( mLeftFrame->isHidden() ) {
4324 toggleExpand(); 4325 toggleExpand();
4325 showFilter( true ); 4326 showFilter( true );
4326 } else 4327 } else
4327 showFilter(! mCalEditView->isVisible()); 4328 showFilter(! mCalEditView->isVisible());
4328} 4329}
4329 4330
4330KOFilterView *CalendarView::filterView() 4331KOFilterView *CalendarView::filterView()
4331{ 4332{
4332 return mFilterView; 4333 return mFilterView;
4333} 4334}
4334void CalendarView::selectFilter( int fil ) 4335void CalendarView::selectFilter( int fil )
4335{ 4336{
4336 mFilterView->setSelectedFilter( fil ); 4337 mFilterView->setSelectedFilter( fil );
4337 updateUnmanagedViews(); 4338 updateUnmanagedViews();
4338} 4339}
4339void CalendarView::showFilter(bool visible) 4340void CalendarView::showFilter(bool visible)
4340{ 4341{
4341#if 1 4342#if 1
4342 if (visible) { 4343 if (visible) {
4343 mCalEditView->readConfig(); 4344 mCalEditView->readConfig();
4344 mCalEditView->show(); 4345 mCalEditView->show();
4345 QValueList<int> sizes; 4346 QValueList<int> sizes;
4346 sizes = mLeftFrame->sizes(); 4347 sizes = mLeftFrame->sizes();
4347 if ( sizes.count() == 4 && sizes[3] < 20 ) { 4348 if ( sizes.count() == 4 && sizes[3] < 20 ) {
4348 sizes.clear(); 4349 sizes.clear();
4349 sizes << 100; 4350 sizes << 100;
4350 sizes << 0; 4351 sizes << 0;
4351 sizes << 0; 4352 sizes << 0;
4352 sizes << 100; 4353 sizes << 100;
4353 mLeftFrame->setSizes(sizes); 4354 mLeftFrame->setSizes(sizes);
4354 } 4355 }
4355#if 0 4356#if 0
4356 sizes = mLeftFrame->sizes(); 4357 sizes = mLeftFrame->sizes();
4357 int ccc = 0; 4358 int ccc = 0;
4358 while ( ccc < sizes.count()) { 4359 while ( ccc < sizes.count()) {
4359 qDebug("size %d %d ", ccc, sizes[ccc]); 4360 qDebug("size %d %d ", ccc, sizes[ccc]);
4360 ++ccc; 4361 ++ccc;
4361 } 4362 }
4362#endif 4363#endif
4363 4364
4364 } 4365 }
4365 else { 4366 else {
4366 mCalEditView->hide(); 4367 mCalEditView->hide();
4367 } 4368 }
4368#else 4369#else
4369 if (visible) mFilterView->show(); 4370 if (visible) mFilterView->show();
4370 else mFilterView->hide(); 4371 else mFilterView->hide();
4371#endif 4372#endif
4372} 4373}
4373void CalendarView::toggleFilerEnabled( ) 4374void CalendarView::toggleFilerEnabled( )
4374{ 4375{
4375 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); 4376 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() );
4376 if ( !mFilterView->filtersEnabled() ) 4377 if ( !mFilterView->filtersEnabled() )
4377 topLevelWidget()->setCaption( i18n("Filter disabled ") ); 4378 topLevelWidget()->setCaption( i18n("Filter disabled ") );
4378 updateUnmanagedViews(); 4379 updateUnmanagedViews();
4379 4380
4380} 4381}
4381void CalendarView::updateFilter() 4382void CalendarView::updateFilter()
4382{ 4383{
4383 CalFilter *filter = mFilterView->selectedFilter(); 4384 CalFilter *filter = mFilterView->selectedFilter();
4384 if (filter) { 4385 if (filter) {
4385 QString mess; 4386 QString mess;
4386 if (mFilterView->filtersEnabled()) { 4387 if (mFilterView->filtersEnabled()) {
4387 mess = i18n("Filter selected: ")+filter->name(); 4388 mess = i18n("Filter selected: ")+filter->name();
4388 filter->setEnabled(true); 4389 filter->setEnabled(true);
4389 } 4390 }
4390 else filter->setEnabled(false); 4391 else filter->setEnabled(false);
4391 mCalendar->setFilter(filter); 4392 mCalendar->setFilter(filter);
4392 updateView(); 4393 updateView();
4393 if ( !mess.isEmpty() ) 4394 if ( !mess.isEmpty() )
4394 topLevelWidget()->setCaption( mess ); 4395 topLevelWidget()->setCaption( mess );
4395 4396
4396 } 4397 }
4397 emit filtersUpdated(); 4398 emit filtersUpdated();
4398} 4399}
4399 4400
4400void CalendarView::filterEdited() 4401void CalendarView::filterEdited()
4401{ 4402{
4402 mFilterView->updateFilters(); 4403 mFilterView->updateFilters();
4403 updateFilter(); 4404 updateFilter();
4404 writeSettings(); 4405 writeSettings();
4405} 4406}
4406 4407
4407 4408
4408void CalendarView::takeOverEvent() 4409void CalendarView::takeOverEvent()
4409{ 4410{
4410 Incidence *incidence = currentSelection(); 4411 Incidence *incidence = currentSelection();
4411 4412
4412 if (!incidence) return; 4413 if (!incidence) return;
4413 4414
4414 incidence->setOrganizer(KOPrefs::instance()->email()); 4415 incidence->setOrganizer(KOPrefs::instance()->email());
4415 incidence->recreate(); 4416 incidence->recreate();
4416 incidence->setReadOnly(false); 4417 incidence->setReadOnly(false);
4417 4418
4418 updateView(); 4419 updateView();
4419} 4420}
4420 4421
4421void CalendarView::takeOverCalendar() 4422void CalendarView::takeOverCalendar()
4422{ 4423{
4423 // TODO: Create Calendar::allIncidences() function and use it here 4424 // TODO: Create Calendar::allIncidences() function and use it here
4424 4425
4425 clearAllViews(); 4426 clearAllViews();
4426 QPtrList<Event> events = mCalendar->events(); 4427 QPtrList<Event> events = mCalendar->events();
4427 for(uint i=0; i<events.count(); ++i) { 4428 for(uint i=0; i<events.count(); ++i) {
4428 events.at(i)->setOrganizer(KOPrefs::instance()->email()); 4429 events.at(i)->setOrganizer(KOPrefs::instance()->email());
4429 events.at(i)->recreate(); 4430 events.at(i)->recreate();
4430 events.at(i)->setReadOnly(false); 4431 events.at(i)->setReadOnly(false);
4431 } 4432 }
4432 4433
4433 QPtrList<Todo> todos = mCalendar->todos(); 4434 QPtrList<Todo> todos = mCalendar->todos();
4434 for(uint i=0; i<todos.count(); ++i) { 4435 for(uint i=0; i<todos.count(); ++i) {
4435 todos.at(i)->setOrganizer(KOPrefs::instance()->email()); 4436 todos.at(i)->setOrganizer(KOPrefs::instance()->email());
4436 todos.at(i)->recreate(); 4437 todos.at(i)->recreate();
4437 todos.at(i)->setReadOnly(false); 4438 todos.at(i)->setReadOnly(false);
4438 } 4439 }
4439 4440
4440 QPtrList<Journal> journals = mCalendar->journals(); 4441 QPtrList<Journal> journals = mCalendar->journals();
4441 for(uint i=0; i<journals.count(); ++i) { 4442 for(uint i=0; i<journals.count(); ++i) {
4442 journals.at(i)->setOrganizer(KOPrefs::instance()->email()); 4443 journals.at(i)->setOrganizer(KOPrefs::instance()->email());
4443 journals.at(i)->recreate(); 4444 journals.at(i)->recreate();
4444 journals.at(i)->setReadOnly(false); 4445 journals.at(i)->setReadOnly(false);
4445 } 4446 }
4446 4447
4447 updateView(); 4448 updateView();
4448} 4449}
4449 4450
4450void CalendarView::showIntro() 4451void CalendarView::showIntro()
4451{ 4452{
4452 kdDebug() << "To be implemented." << endl; 4453 kdDebug() << "To be implemented." << endl;
4453} 4454}
4454 4455
4455QWidgetStack *CalendarView::viewStack() 4456QWidgetStack *CalendarView::viewStack()
4456{ 4457{
4457 return mRightFrame; 4458 return mRightFrame;
4458} 4459}
4459 4460
4460QWidget *CalendarView::leftFrame() 4461QWidget *CalendarView::leftFrame()
4461{ 4462{
4462 return ( QWidget *)mLeftFrame; 4463 return ( QWidget *)mLeftFrame;
4463} 4464}
4464 4465
4465DateNavigator *CalendarView::dateNavigator() 4466DateNavigator *CalendarView::dateNavigator()
4466{ 4467{
4467 return mNavigator; 4468 return mNavigator;
4468} 4469}
4469 4470
4470KDateNavigator* CalendarView::dateNavigatorWidget() 4471KDateNavigator* CalendarView::dateNavigatorWidget()
4471{ 4472{
4472 return mDateNavigator->navigatorView(); 4473 return mDateNavigator->navigatorView();
4473} 4474}
4474void CalendarView::toggleDateNavigatorWidget() 4475void CalendarView::toggleDateNavigatorWidget()
4475{ 4476{
4476 KOPrefs::instance()->mShowDateNavigator = !KOPrefs::instance()->mShowDateNavigator ; 4477 KOPrefs::instance()->mShowDateNavigator = !KOPrefs::instance()->mShowDateNavigator ;
4477 4478
4478 if (!KOPrefs::instance()->mShowDateNavigator ) 4479 if (!KOPrefs::instance()->mShowDateNavigator )
4479 mDateNavigator->hide(); 4480 mDateNavigator->hide();
4480 else 4481 else
4481 mDateNavigator->show(); 4482 mDateNavigator->show();
4482} 4483}
4483void CalendarView::addView(KOrg::BaseView *view) 4484void CalendarView::addView(KOrg::BaseView *view)
4484{ 4485{
4485 mViewManager->addView(view); 4486 mViewManager->addView(view);
4486} 4487}
4487 4488
4488void CalendarView::showView(KOrg::BaseView *view) 4489void CalendarView::showView(KOrg::BaseView *view)
4489{ 4490{
4490 mViewManager->showView(view, mLeftFrame->isVisible()); 4491 mViewManager->showView(view, mLeftFrame->isVisible());
4491} 4492}
4492 4493
4493Incidence *CalendarView::currentSelection() 4494Incidence *CalendarView::currentSelection()
4494{ 4495{
4495 return mViewManager->currentSelection(); 4496 return mViewManager->currentSelection();
4496} 4497}
4497void CalendarView::toggleAllDaySize() 4498void CalendarView::toggleAllDaySize()
4498{ 4499{
4499 /* 4500 /*
4500 if ( KOPrefs::instance()->mAllDaySize > 47 ) 4501 if ( KOPrefs::instance()->mAllDaySize > 47 )
4501 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2; 4502 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2;
4502 else 4503 else
4503 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2; 4504 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2;
4504 */ 4505 */
4505 viewManager()->agendaView()->toggleAllDay(); 4506 viewManager()->agendaView()->toggleAllDay();
4506} 4507}
4507void CalendarView::toggleExpand() 4508void CalendarView::toggleExpand()
4508{ 4509{
4509 // if ( mLeftFrame->isHidden() ) { 4510 // if ( mLeftFrame->isHidden() ) {
4510 // mLeftFrame->show(); 4511 // mLeftFrame->show();
4511 // emit calendarViewExpanded( false ); 4512 // emit calendarViewExpanded( false );
4512 // } else { 4513 // } else {
4513 // mLeftFrame->hide(); 4514 // mLeftFrame->hide();
4514 // emit calendarViewExpanded( true ); 4515 // emit calendarViewExpanded( true );
4515 // } 4516 // }
4516 //qDebug(" CalendarView::toggleExpand()"); 4517 //qDebug(" CalendarView::toggleExpand()");
4517 globalFlagBlockAgenda = 1; 4518 globalFlagBlockAgenda = 1;
4518 emit calendarViewExpanded( !mLeftFrame->isHidden() ); 4519 emit calendarViewExpanded( !mLeftFrame->isHidden() );
4519 globalFlagBlockAgenda = 5; 4520 globalFlagBlockAgenda = 5;
4520 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() ); 4521 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() );
4521 //mViewManager->showView( 0, true ); 4522 //mViewManager->showView( 0, true );
4522} 4523}
4523 4524
4524void CalendarView::calendarModified( bool modified, Calendar * ) 4525void CalendarView::calendarModified( bool modified, Calendar * )
4525{ 4526{
4526 setModified( modified ); 4527 setModified( modified );
4527} 4528}
4528 4529
4529Todo *CalendarView::selectedTodo() 4530Todo *CalendarView::selectedTodo()
4530{ 4531{
4531 Incidence *incidence = currentSelection(); 4532 Incidence *incidence = currentSelection();
4532 if ( incidence && incidence->typeID() == todoID ) { 4533 if ( incidence && incidence->typeID() == todoID ) {
4533 return static_cast<Todo *>( incidence ); 4534 return static_cast<Todo *>( incidence );
4534 } 4535 }
4535 4536
4536 incidence = mTodoList->selectedIncidences().first(); 4537 incidence = mTodoList->selectedIncidences().first();
4537 if ( incidence && incidence->typeID() == todoID ) { 4538 if ( incidence && incidence->typeID() == todoID ) {
4538 return static_cast<Todo *>( incidence ); 4539 return static_cast<Todo *>( incidence );
4539 } 4540 }
4540 4541
4541 return 0; 4542 return 0;
4542} 4543}
4543 4544
4544void CalendarView::showIncidence() 4545void CalendarView::showIncidence()
4545{ 4546{
4546 mViewerCallerIsSearchDialog = false; 4547 mViewerCallerIsSearchDialog = false;
4547 Incidence *incidence = currentSelection(); 4548 Incidence *incidence = currentSelection();
4548 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 4549 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
4549 if ( incidence ) { 4550 if ( incidence ) {
4550 ShowIncidenceVisitor v; 4551 ShowIncidenceVisitor v;
4551 v.act( incidence, this ); 4552 v.act( incidence, this );
4552 } 4553 }
4553} 4554}
4554void CalendarView::editIncidenceDescription() 4555void CalendarView::editIncidenceDescription()
4555{ 4556{
4556 mFlagEditDescription = true; 4557 mFlagEditDescription = true;
4557 editIncidence(); 4558 editIncidence();
4558 mFlagEditDescription = false; 4559 mFlagEditDescription = false;
4559} 4560}
4560void CalendarView::editIncidence() 4561void CalendarView::editIncidence()
4561{ 4562{
4562 // qDebug("editIncidence() "); 4563 // qDebug("editIncidence() ");
4563 Incidence *incidence = currentSelection(); 4564 Incidence *incidence = currentSelection();
4564 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 4565 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
4565 if ( incidence ) { 4566 if ( incidence ) {
4566 EditIncidenceVisitor v; 4567 EditIncidenceVisitor v;
4567 v.act( incidence, this ); 4568 v.act( incidence, this );
4568 } 4569 }
4569} 4570}
4570 4571
4571void CalendarView::deleteIncidence() 4572void CalendarView::deleteIncidence()
4572{ 4573{
4573 Incidence *incidence = currentSelection(); 4574 Incidence *incidence = currentSelection();
4574 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 4575 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
4575 if ( incidence ) { 4576 if ( incidence ) {
4576 deleteIncidence(incidence); 4577 deleteIncidence(incidence);
4577 } 4578 }
4578} 4579}
4579void CalendarView::showIncidence(QString uid) 4580void CalendarView::showIncidence(QString uid)
4580{ 4581{
4581 Incidence *inc = mCalendar->incidence( uid ); 4582 Incidence *inc = mCalendar->incidence( uid );
4582 if ( inc ) 4583 if ( inc )
4583 showIncidence( inc ); 4584 showIncidence( inc );
4584} 4585}
4585void CalendarView::showIncidence(Incidence *incidence) 4586void CalendarView::showIncidence(Incidence *incidence)
4586{ 4587{
4587 mViewerCallerIsSearchDialog = false; 4588 mViewerCallerIsSearchDialog = false;
4588 //qDebug("%x %x ",sender (), mDialogManager->getSearchDialog() ); 4589 //qDebug("%x %x ",sender (), mDialogManager->getSearchDialog() );
4589 if ( sender() && mDialogManager->getSearchDialog() ) { 4590 if ( sender() && mDialogManager->getSearchDialog() ) {
4590 if ( sender () == mDialogManager->getSearchDialog()->listview() ) { 4591 if ( sender () == mDialogManager->getSearchDialog()->listview() ) {
4591 mViewerCallerIsSearchDialog = true; 4592 mViewerCallerIsSearchDialog = true;
4592 } 4593 }
4593 } 4594 }
4594 if ( incidence ) { 4595 if ( incidence ) {
4595 ShowIncidenceVisitor v; 4596 ShowIncidenceVisitor v;
4596 v.act( incidence, this ); 4597 v.act( incidence, this );
4597 } 4598 }
4598} 4599}
4599 4600
4600void CalendarView::editIncidence(Incidence *incidence) 4601void CalendarView::editIncidence(Incidence *incidence)
4601{ 4602{
4602 if ( incidence ) { 4603 if ( incidence ) {
4603 4604
4604 EditIncidenceVisitor v; 4605 EditIncidenceVisitor v;
4605 v.act( incidence, this ); 4606 v.act( incidence, this );
4606 4607
4607 } 4608 }
4608} 4609}
4609 4610
4610void CalendarView::deleteIncidence(Incidence *incidence) 4611void CalendarView::deleteIncidence(Incidence *incidence)
4611{ 4612{
4612 //qDebug(" CalendarView::deleteIncidence "); 4613 //qDebug(" CalendarView::deleteIncidence ");
4613 if ( incidence == 0 ) { 4614 if ( incidence == 0 ) {
4614 updateView(); 4615 updateView();
4615 emit updateSearchDialog(); 4616 emit updateSearchDialog();
4616 return; 4617 return;
4617 } 4618 }
4618 if ( incidence ) { 4619 if ( incidence ) {
4619 DeleteIncidenceVisitor v; 4620 DeleteIncidenceVisitor v;
4620 v.act( incidence, this ); 4621 v.act( incidence, this );
4621 } 4622 }
4622} 4623}
4623 4624
4624 4625
4625void CalendarView::lookForOutgoingMessages() 4626void CalendarView::lookForOutgoingMessages()
4626{ 4627{
4627 OutgoingDialog *ogd = mDialogManager->outgoingDialog(); 4628 OutgoingDialog *ogd = mDialogManager->outgoingDialog();
4628 ogd->loadMessages(); 4629 ogd->loadMessages();
4629} 4630}
4630 4631
4631void CalendarView::lookForIncomingMessages() 4632void CalendarView::lookForIncomingMessages()
4632{ 4633{
4633 IncomingDialog *icd = mDialogManager->incomingDialog(); 4634 IncomingDialog *icd = mDialogManager->incomingDialog();
4634 icd->retrieve(); 4635 icd->retrieve();
4635} 4636}
4636 4637
4637bool CalendarView::removeCompletedSubTodos( Todo* t ) 4638bool CalendarView::removeCompletedSubTodos( Todo* t )
4638{ 4639{
4639 bool deleteTodo = true; 4640 bool deleteTodo = true;
4640 QPtrList<Incidence> subTodos; 4641 QPtrList<Incidence> subTodos;
4641 Incidence *aTodo; 4642 Incidence *aTodo;
4642 subTodos = t->relations(); 4643 subTodos = t->relations();
4643 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) { 4644 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) {
4644 if (! removeCompletedSubTodos( (Todo*) aTodo )) 4645 if (! removeCompletedSubTodos( (Todo*) aTodo ))
4645 deleteTodo = false; 4646 deleteTodo = false;
4646 } 4647 }
4647 if ( deleteTodo ) { 4648 if ( deleteTodo ) {
4648 if ( t->isCompleted() && !t->doesRecur()) { 4649 if ( t->isCompleted() && !t->doesRecur()) {
4649 checkExternalId( t ); 4650 checkExternalId( t );
4650 mCalendar->deleteTodo( t ); 4651 mCalendar->deleteTodo( t );
4651 changeTodoDisplay( t,KOGlobals::EVENTDELETED ); 4652 changeTodoDisplay( t,KOGlobals::EVENTDELETED );
4652 } 4653 }
4653 else 4654 else
4654 deleteTodo = false; 4655 deleteTodo = false;
4655 } 4656 }
4656 return deleteTodo; 4657 return deleteTodo;
4657 4658
4658} 4659}
4659void CalendarView::purgeCompleted() 4660void CalendarView::purgeCompleted()
4660{ 4661{
4661 int result = KMessageBox::warningContinueCancel(this, 4662 int result = KMessageBox::warningContinueCancel(this,
4662 i18n("Delete all completed todos?\n(Completed recurring todos\nwill not be deleted!)"),i18n("Purge Todos"),i18n("Purge")); 4663 i18n("Delete all completed todos?\n(Completed recurring todos\nwill not be deleted!)"),i18n("Purge Todos"),i18n("Purge"));
4663 4664
4664 if (result == KMessageBox::Continue) { 4665 if (result == KMessageBox::Continue) {
4665 4666
4666 QPtrList<Todo> todoCal; 4667 QPtrList<Todo> todoCal;
4667 QPtrList<Todo> rootTodos; 4668 QPtrList<Todo> rootTodos;
4668 //QPtrList<Incidence> rel; 4669 //QPtrList<Incidence> rel;
4669 Todo *aTodo; 4670 Todo *aTodo;
4670 todoCal = calendar()->todos(); 4671 todoCal = calendar()->todos();
4671 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { 4672 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) {
4672 if ( !aTodo->relatedTo() ) 4673 if ( !aTodo->relatedTo() )
4673 rootTodos.append( aTodo ); 4674 rootTodos.append( aTodo );
4674 } 4675 }
4675 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { 4676 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) {
4676 removeCompletedSubTodos( aTodo ); 4677 removeCompletedSubTodos( aTodo );
4677 } 4678 }
4678 4679
4679 updateView(); 4680 updateView();
4680 } 4681 }
4681} 4682}
4682 4683
4683void CalendarView::slotCalendarChanged() 4684void CalendarView::slotCalendarChanged()
4684{ 4685{
4685 ; 4686 ;
4686} 4687}
4687 4688
4688void CalendarView::keyPressEvent ( QKeyEvent *e) 4689void CalendarView::keyPressEvent ( QKeyEvent *e)
4689{ 4690{
4690 //qDebug("CalendarView::keyPressEvent "); 4691 //qDebug("CalendarView::keyPressEvent ");
4691 e->ignore(); 4692 e->ignore();
4692} 4693}
4693 4694
4694 4695
4695bool CalendarView::sync(KSyncManager* manager, QString filename, int mode) 4696bool CalendarView::sync(KSyncManager* manager, QString filename, int mode)
4696{ 4697{
4697 4698
4698 if ( manager != mSyncManager) 4699 if ( manager != mSyncManager)
4699 qDebug("KO: Internal error-1. SyncManager mismatch "); 4700 qDebug("KO: Internal error-1. SyncManager mismatch ");
4700 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) { 4701 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) {
4701 qDebug("KO: SyncKDE request detected!"); 4702 qDebug("KO: SyncKDE request detected!");
4702 } 4703 }
4703 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 4704 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
4704 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 4705 mCurrentSyncName = mSyncManager->getCurrentSyncName();
4705 return syncCalendar( filename, mode ); 4706 return syncCalendar( filename, mode );
4706} 4707}
4707bool CalendarView::syncExternal(KSyncManager* manager, QString resource) 4708bool CalendarView::syncExternal(KSyncManager* manager, QString resource)
4708{ 4709{
4709 //mSyncManager = manager; 4710 //mSyncManager = manager;
4710 if ( manager != mSyncManager) 4711 if ( manager != mSyncManager)
4711 qDebug("KO: Internal error-2. SyncManager mismatch "); 4712 qDebug("KO: Internal error-2. SyncManager mismatch ");
4712 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 4713 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
4713 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 4714 mCurrentSyncName = mSyncManager->getCurrentSyncName();
4714 if ( resource == "sharp" ) 4715 if ( resource == "sharp" )
4715 syncExternal( 0 ); 4716 syncExternal( 0 );
4716 if ( resource == "phone" ) 4717 if ( resource == "phone" )
4717 syncExternal( 1 ); 4718 syncExternal( 1 );
4718 // pending setmodified 4719 // pending setmodified
4719 return true; 4720 return true;
4720} 4721}
4721void CalendarView::setSyncManager(KSyncManager* manager) 4722void CalendarView::setSyncManager(KSyncManager* manager)
4722{ 4723{
4723 mSyncManager = manager; 4724 mSyncManager = manager;
4724} 4725}
4725 4726
4726void CalendarView::removeSyncInfo( QString syncProfile) 4727void CalendarView::removeSyncInfo( QString syncProfile)
4727{ 4728{
4728 qDebug("KO: removeSyncInfo for profile %s ", syncProfile.latin1()); 4729 qDebug("KO: removeSyncInfo for profile %s ", syncProfile.latin1());
4729 mCalendar->removeSyncInfo( syncProfile ); 4730 mCalendar->removeSyncInfo( syncProfile );
4730 4731
4731} 4732}
4732 4733
4733void CalendarView::undo_delete() 4734void CalendarView::undo_delete()
4734{ 4735{
4735 //qDebug("undo_delete() "); 4736 //qDebug("undo_delete() ");
4736 Incidence* undo = mCalendar->undoIncidence(); 4737 Incidence* undo = mCalendar->undoIncidence();
4737 if ( !undo ) { 4738 if ( !undo ) {
4738 KMessageBox::sorry(this,i18n("There is nothing to undo!"), 4739 KMessageBox::sorry(this,i18n("There is nothing to undo!"),
4739 i18n("KO/Pi")); 4740 i18n("KO/Pi"));
4740 return; 4741 return;
4741 } 4742 }
4742 if ( KMessageBox::Continue ==KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( undo->summary(),0 ) + 4743 if ( KMessageBox::Continue ==KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( undo->summary(),0 ) +
4743 i18n("\nAre you sure you want\nto restore this?"), 4744 i18n("\nAre you sure you want\nto restore this?"),
4744 i18n("KO/Pi Confirmation"),i18n("Restore"))) { 4745 i18n("KO/Pi Confirmation"),i18n("Restore"))) {
4745 mCalendar->undoDeleteIncidence(); 4746 mCalendar->undoDeleteIncidence();
4746 updateView(); 4747 updateView();
4747 } 4748 }
4748} 4749}
4749 4750
4750void CalendarView::slotViewerClosed() 4751void CalendarView::slotViewerClosed()
4751{ 4752{
4752 QTimer::singleShot( 50, this, SLOT ( resetFocus() ) ); 4753 QTimer::singleShot( 50, this, SLOT ( resetFocus() ) );
4753} 4754}
4754 4755
4755void CalendarView::resetFocus() 4756void CalendarView::resetFocus()
4756{ 4757{
4757 if ( mViewerCallerIsSearchDialog ) { 4758 if ( mViewerCallerIsSearchDialog ) {
4758 if ( mDialogManager->getSearchDialog()->isVisible() ){ 4759 if ( mDialogManager->getSearchDialog()->isVisible() ){
4759 mDialogManager->getSearchDialog()->raise(); 4760 mDialogManager->getSearchDialog()->raise();
4760 mDialogManager->getSearchDialog()->setActiveWindow(); 4761 mDialogManager->getSearchDialog()->setActiveWindow();
4761 mDialogManager->getSearchDialog()->listview()->resetFocus(); 4762 mDialogManager->getSearchDialog()->listview()->resetFocus();
4762 } else 4763 } else
4763 mViewerCallerIsSearchDialog = false; 4764 mViewerCallerIsSearchDialog = false;
4764 } 4765 }
4765 if ( !mViewerCallerIsSearchDialog ) { 4766 if ( !mViewerCallerIsSearchDialog ) {
4766 //mViewManager->currentView()->setFocus(); 4767 //mViewManager->currentView()->setFocus();
4767 //qDebug("sssssssssssssssset focus "); 4768 //qDebug("sssssssssssssssset focus ");
4768 topLevelWidget()->raise(); 4769 topLevelWidget()->raise();
4769 setActiveWindow(); 4770 setActiveWindow();
4770 //setFocus(); 4771 //setFocus();
4771 } 4772 }
4772 mViewerCallerIsSearchDialog = false; 4773 mViewerCallerIsSearchDialog = false;
4773} 4774}
4774 4775
4775void CalendarView::showNextAlarms() 4776void CalendarView::showNextAlarms()
4776{ 4777{
4777 QString message; 4778 QString message;
4778 QDateTime nextAl = mCalendar->nextAlarmEventDateTime(); 4779 QDateTime nextAl = mCalendar->nextAlarmEventDateTime();
4779 if ( nextAl.isValid() && mNextAlarmDateTime > QDateTime::currentDateTime() ) { 4780 if ( nextAl.isValid() && mNextAlarmDateTime > QDateTime::currentDateTime() ) {
4780 QString sum = mCalendar->nextSummary(); 4781 QString sum = mCalendar->nextSummary();
4781 QDateTime nextA = mNextAlarmDateTime; 4782 QDateTime nextA = mNextAlarmDateTime;
4782 QDateTime cur = QDateTime::currentDateTime(); 4783 QDateTime cur = QDateTime::currentDateTime();
4783 int secs = cur.secsTo( nextA ); 4784 int secs = cur.secsTo( nextA );
4784 int min = secs /60; 4785 int min = secs /60;
4785 int hours = min /60; 4786 int hours = min /60;
4786 min = min % 60; 4787 min = min % 60;
4787 int days = hours /24; 4788 int days = hours /24;
4788 hours = hours % 24; 4789 hours = hours % 24;
4789 4790
4790 //message = i18n("The next alarm is in:\n"); 4791 //message = i18n("The next alarm is in:\n");
4791 if ( days > 1 ) 4792 if ( days > 1 )
4792 message += i18n("%1 days\n").arg( days ); 4793 message += i18n("%1 days\n").arg( days );
4793 else if ( days == 1 ) 4794 else if ( days == 1 )
4794 message += i18n("1 day\n"); 4795 message += i18n("1 day\n");
4795 if ( hours > 1 ) 4796 if ( hours > 1 )
4796 message += i18n("%1 hours\n").arg( hours ); 4797 message += i18n("%1 hours\n").arg( hours );
4797 else if ( hours == 1 ) 4798 else if ( hours == 1 )
4798 message += i18n("1 hour\n"); 4799 message += i18n("1 hour\n");
4799 if ( min > 1 ) 4800 if ( min > 1 )
4800 message += i18n("%1 minutes\n").arg( min ); 4801 message += i18n("%1 minutes\n").arg( min );
4801 else if ( min == 1 ) 4802 else if ( min == 1 )
4802 message += i18n("1 minute\n"); 4803 message += i18n("1 minute\n");
4803 if ( message.isEmpty() ) 4804 if ( message.isEmpty() )
4804 message = i18n("The next alarm is in\nless than one minute!"); 4805 message = i18n("The next alarm is in\nless than one minute!");
4805 else 4806 else
4806 message = i18n("The next alarm is in:\n") + message; 4807 message = i18n("The next alarm is in:\n") + message;
4807 message += i18n("\n(%1)\n\n%2\n(%3)\n").arg( KGlobal::locale()->formatDateTime(nextA , false)).arg(sum ).arg( KGlobal::locale()->formatDateTime(nextAl , false)) ; 4808 message += i18n("\n(%1)\n\n%2\n(%3)\n").arg( KGlobal::locale()->formatDateTime(nextA , false)).arg(sum ).arg( KGlobal::locale()->formatDateTime(nextAl , false)) ;
4808 } else { 4809 } else {
4809 message = i18n("There is no next alarm."); 4810 message = i18n("There is no next alarm.");
4810 4811
4811 } 4812 }
4812#ifdef DESKTOP_VERSION 4813#ifdef DESKTOP_VERSION
4813 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 4814 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
4814 message += i18n("\nThe internal alarm notification is disabled!\n"); 4815 message += i18n("\nThe internal alarm notification is disabled!\n");
4815 message += i18n("Enable it in the settings menu, TAB alarm."); 4816 message += i18n("Enable it in the settings menu, TAB alarm.");
4816 } 4817 }
4817 4818
4818#endif 4819#endif
4819 KMessageBox::information( this, message); 4820 KMessageBox::information( this, message);
4820} 4821}
diff --git a/korganizer/kotodoview.cpp b/korganizer/kotodoview.cpp
index 94f35e6..3ae977d 100644
--- a/korganizer/kotodoview.cpp
+++ b/korganizer/kotodoview.cpp
@@ -1,1717 +1,1724 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qlayout.h> 24#include <qlayout.h>
25#include <qheader.h> 25#include <qheader.h>
26#include <qcursor.h> 26#include <qcursor.h>
27#include <qwhatsthis.h> 27#include <qwhatsthis.h>
28#include <qdialog.h> 28#include <qdialog.h>
29#include <qlabel.h> 29#include <qlabel.h>
30#include <qpushbutton.h> 30#include <qpushbutton.h>
31 31
32#include <qinputdialog.h> 32#include <qinputdialog.h>
33 33
34#include <qvbox.h> 34#include <qvbox.h>
35#include <kdebug.h> 35#include <kdebug.h>
36#include "koprefs.h" 36#include "koprefs.h"
37#include <klocale.h> 37#include <klocale.h>
38#include <kglobal.h> 38#include <kglobal.h>
39#include <kdateedit.h> 39#include <kdateedit.h>
40#include "ktimeedit.h" 40#include "ktimeedit.h"
41#include <kiconloader.h> 41#include <kiconloader.h>
42#include <kmessagebox.h> 42#include <kmessagebox.h>
43 43
44#include <libkcal/icaldrag.h> 44#include <libkcal/icaldrag.h>
45#include <libkcal/vcaldrag.h> 45#include <libkcal/vcaldrag.h>
46#include <libkcal/calfilter.h> 46#include <libkcal/calfilter.h>
47#include <libkcal/dndfactory.h> 47#include <libkcal/dndfactory.h>
48#include <libkcal/calendarresources.h> 48#include <libkcal/calendarresources.h>
49#include <libkcal/resourcecalendar.h> 49#include <libkcal/resourcecalendar.h>
50#include <kresources/resourceselectdialog.h> 50#include <kresources/resourceselectdialog.h>
51#include <libkcal/kincidenceformatter.h> 51#include <libkcal/kincidenceformatter.h>
52#ifndef DESKTOP_VERSION 52#ifndef DESKTOP_VERSION
53#include <qpe/qpeapplication.h> 53#include <qpe/qpeapplication.h>
54#else 54#else
55#include <qapplication.h> 55#include <qapplication.h>
56#endif 56#endif
57#ifndef KORG_NOPRINTER 57#ifndef KORG_NOPRINTER
58#include "calprinter.h" 58#include "calprinter.h"
59#endif 59#endif
60#include "docprefs.h" 60#include "docprefs.h"
61 61
62#include "kotodoview.h" 62#include "kotodoview.h"
63using namespace KOrg; 63using namespace KOrg;
64 64
65 65
66KOStartTodoPrefs::KOStartTodoPrefs( QString sum, QWidget *parent, const char *name ) : 66KOStartTodoPrefs::KOStartTodoPrefs( QString sum, QWidget *parent, const char *name ) :
67 QDialog( parent, name, true ) 67 QDialog( parent, name, true )
68{ 68{
69 mStopAll = true; 69 mStopAll = true;
70 setCaption( i18n("Start todo") ); 70 setCaption( i18n("Start todo") );
71 QVBoxLayout* lay = new QVBoxLayout( this ); 71 QVBoxLayout* lay = new QVBoxLayout( this );
72 lay->setSpacing( 3 ); 72 lay->setSpacing( 3 );
73 lay->setMargin( 3 ); 73 lay->setMargin( 3 );
74 QLabel * lab = new QLabel( i18n("<b>%1\n</b>").arg( sum ), this ); 74 QLabel * lab = new QLabel( i18n("<b>%1\n</b>").arg( sum ), this );
75 lay->addWidget( lab ); 75 lay->addWidget( lab );
76 lab->setAlignment( AlignCenter ); 76 lab->setAlignment( AlignCenter );
77 77
78 QPushButton * ok = new QPushButton( i18n("Start this todo\nand stop all running"), this ); 78 QPushButton * ok = new QPushButton( i18n("Start this todo\nand stop all running"), this );
79 lay->addWidget( ok ); 79 lay->addWidget( ok );
80 ok->setDefault( true ); 80 ok->setDefault( true );
81 QPushButton * start = new QPushButton( i18n("Start todo"), this ); 81 QPushButton * start = new QPushButton( i18n("Start todo"), this );
82 lay->addWidget( start ); 82 lay->addWidget( start );
83 QPushButton * cancel = new QPushButton( i18n("Cancel - do not start"), this ); 83 QPushButton * cancel = new QPushButton( i18n("Cancel - do not start"), this );
84 lay->addWidget( cancel ); 84 lay->addWidget( cancel );
85 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 85 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
86 connect ( start,SIGNAL(clicked() ),this , SLOT ( doStop() ) ); 86 connect ( start,SIGNAL(clicked() ),this , SLOT ( doStop() ) );
87 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 87 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
88 resize( sizeHint() ); 88 resize( sizeHint() );
89 89
90} 90}
91void KOStartTodoPrefs::doStop() 91void KOStartTodoPrefs::doStop()
92{ 92{
93 mStopAll = false; 93 mStopAll = false;
94 accept(); 94 accept();
95} 95}
96KOStopTodoPrefs::KOStopTodoPrefs( Todo* todo, QWidget *parent, const char *name ) : 96KOStopTodoPrefs::KOStopTodoPrefs( Todo* todo, QWidget *parent, const char *name ) :
97 QDialog( parent, name, true ) 97 QDialog( parent, name, true )
98{ 98{
99 mTodo = todo; 99 mTodo = todo;
100 setCaption( i18n("Stop todo") ); 100 setCaption( i18n("Stop todo") );
101 QVBoxLayout* lay = new QVBoxLayout( this ); 101 QVBoxLayout* lay = new QVBoxLayout( this );
102 lay->setSpacing( 3 ); 102 lay->setSpacing( 3 );
103 lay->setMargin( 3 ); 103 lay->setMargin( 3 );
104 QLabel * lab = new QLabel( i18n("<b>%1\n</b>").arg( todo->summary() ), this ); 104 QLabel * lab = new QLabel( i18n("<b>%1\n</b>").arg( todo->summary() ), this );
105 lay->addWidget( lab ); 105 lay->addWidget( lab );
106 lab->setAlignment( AlignHCenter ); 106 lab->setAlignment( AlignHCenter );
107 lab = new QLabel( i18n("Additional Comment:"), this ); 107 lab = new QLabel( i18n("Additional Comment:"), this );
108 lay->addWidget( lab ); 108 lay->addWidget( lab );
109 mComment = new QLineEdit( this ); 109 mComment = new QLineEdit( this );
110 lay->addWidget( mComment ); 110 lay->addWidget( mComment );
111 QHBox * start = new QHBox ( this ); 111 QHBox * start = new QHBox ( this );
112 lay->addWidget( start ); 112 lay->addWidget( start );
113 lab = new QLabel( i18n("Start:"), start ); 113 lab = new QLabel( i18n("Start:"), start );
114 QHBox * end = new QHBox ( this ); 114 QHBox * end = new QHBox ( this );
115 lay->addWidget( end ); 115 lay->addWidget( end );
116 lab = new QLabel( i18n("End:"), end ); 116 lab = new QLabel( i18n("End:"), end );
117 sde = new KDateEdit( start ); 117 sde = new KDateEdit( start );
118 ste = new KOTimeEdit( start ); 118 ste = new KOTimeEdit( start );
119 connect ( sde,SIGNAL(setTimeTo( QTime ) ),ste , SLOT ( setTime(QTime ) ) ); 119 connect ( sde,SIGNAL(setTimeTo( QTime ) ),ste , SLOT ( setTime(QTime ) ) );
120 ede = new KDateEdit( end ); 120 ede = new KDateEdit( end );
121 ete = new KOTimeEdit(end ); 121 ete = new KOTimeEdit(end );
122 connect ( ede,SIGNAL(setTimeTo( QTime ) ),ete , SLOT ( setTime(QTime ) ) ); 122 connect ( ede,SIGNAL(setTimeTo( QTime ) ),ete , SLOT ( setTime(QTime ) ) );
123 sde->setDate( mTodo->runStart().date() ); 123 sde->setDate( mTodo->runStart().date() );
124 ste->setTime( mTodo->runStart().time() ); 124 ste->setTime( mTodo->runStart().time() );
125 ede->setDate( QDate::currentDate()); 125 ede->setDate( QDate::currentDate());
126 ete->setTime( QTime::currentTime() ); 126 ete->setTime( QTime::currentTime() );
127 QPushButton * ok = new QPushButton( i18n("Stop and save"), this ); 127 QPushButton * ok = new QPushButton( i18n("Stop and save"), this );
128 lay->addWidget( ok ); 128 lay->addWidget( ok );
129 ok->setDefault( true ); 129 ok->setDefault( true );
130 QPushButton * cancel = new QPushButton( i18n("Continue running"), this ); 130 QPushButton * cancel = new QPushButton( i18n("Continue running"), this );
131 lay->addWidget( cancel ); 131 lay->addWidget( cancel );
132 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 132 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
133 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 133 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
134 ok = new QPushButton( i18n("Stop - do not save"), this ); 134 ok = new QPushButton( i18n("Stop - do not save"), this );
135 connect ( ok,SIGNAL(clicked() ),this , SLOT ( doNotSave() ) ); 135 connect ( ok,SIGNAL(clicked() ),this , SLOT ( doNotSave() ) );
136 lay->addWidget( ok ); 136 lay->addWidget( ok );
137 if (QApplication::desktop()->width() < 320 ) 137 if (QApplication::desktop()->width() < 320 )
138 resize( 240, sizeHint().height() ); 138 resize( 240, sizeHint().height() );
139 else 139 else
140 resize( 320, sizeHint().height() ); 140 resize( 320, sizeHint().height() );
141 141
142} 142}
143 143
144void KOStopTodoPrefs::accept() 144void KOStopTodoPrefs::accept()
145{ 145{
146 QDateTime start = QDateTime( sde->date(), ste->getTime() ); 146 QDateTime start = QDateTime( sde->date(), ste->getTime() );
147 QDateTime stop = QDateTime( ede->date(), ete->getTime() ); 147 QDateTime stop = QDateTime( ede->date(), ete->getTime() );
148 if ( start > stop ) { 148 if ( start > stop ) {
149 KMessageBox::sorry(this, 149 KMessageBox::sorry(this,
150 i18n("The start time is\nafter the end time!"), 150 i18n("The start time is\nafter the end time!"),
151 i18n("Time mismatch!")); 151 i18n("Time mismatch!"));
152 return; 152 return;
153 } 153 }
154 mTodo->saveRunningInfo( mComment->text(), start, stop ); 154 mTodo->saveRunningInfo( mComment->text(), start, stop );
155 QDialog::accept(); 155 QDialog::accept();
156} 156}
157void KOStopTodoPrefs::doNotSave() 157void KOStopTodoPrefs::doNotSave()
158{ 158{
159 int result = KMessageBox::warningContinueCancel(this, 159 int result = KMessageBox::warningContinueCancel(this,
160 i18n("Do you really want to set\nthe state to stopped\nwithout saving the data?"),mTodo->summary(),i18n("Yes, stop todo") ); 160 i18n("Do you really want to set\nthe state to stopped\nwithout saving the data?"),mTodo->summary(),i18n("Yes, stop todo") );
161 if (result != KMessageBox::Continue) return; 161 if (result != KMessageBox::Continue) return;
162 mTodo->stopRunning(); 162 mTodo->stopRunning();
163 QDialog::accept(); 163 QDialog::accept();
164} 164}
165 165
166 166
167class KOTodoViewWhatsThis :public QWhatsThis 167class KOTodoViewWhatsThis :public QWhatsThis
168{ 168{
169public: 169public:
170 KOTodoViewWhatsThis( QWidget *wid, KOTodoView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { }; 170 KOTodoViewWhatsThis( QWidget *wid, KOTodoView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { };
171 171
172protected: 172protected:
173 virtual QString text( const QPoint& p) 173 virtual QString text( const QPoint& p)
174 { 174 {
175 return _view->getWhatsThisText(p) ; 175 return _view->getWhatsThisText(p) ;
176 } 176 }
177private: 177private:
178 QWidget* _wid; 178 QWidget* _wid;
179 KOTodoView * _view; 179 KOTodoView * _view;
180}; 180};
181 181
182KOTodoListView::KOTodoListView(Calendar *calendar,QWidget *parent, 182KOTodoListView::KOTodoListView(Calendar *calendar,QWidget *parent,
183 const char *name) : 183 const char *name) :
184 KListView(parent,name) 184 KListView(parent,name)
185{ 185{
186 mName = QString ( name ); 186 mName = QString ( name );
187 mCalendar = calendar; 187 mCalendar = calendar;
188#ifndef DESKTOP_VERSION 188#ifndef DESKTOP_VERSION
189 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold ); 189 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold );
190#endif 190#endif
191 mOldCurrent = 0; 191 mOldCurrent = 0;
192 mMousePressed = false; 192 mMousePressed = false;
193 193
194 setAcceptDrops(true); 194 setAcceptDrops(true);
195 viewport()->setAcceptDrops(true); 195 viewport()->setAcceptDrops(true);
196 int size = 16; 196 int size = 16;
197 if (qApp->desktop()->width() < 300 ) 197 if (qApp->desktop()->width() < 300 )
198 size = 12; 198 size = 12;
199 setTreeStepSize( size + 6 ); 199 setTreeStepSize( size + 6 );
200 200
201} 201}
202 202
203void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e) 203void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e)
204{ 204{
205#ifndef KORG_NODND 205#ifndef KORG_NODND
206// kdDebug() << "KOTodoListView::contentsDragEnterEvent" << endl; 206// kdDebug() << "KOTodoListView::contentsDragEnterEvent" << endl;
207 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 207 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
208 !QTextDrag::canDecode( e ) ) { 208 !QTextDrag::canDecode( e ) ) {
209 e->ignore(); 209 e->ignore();
210 return; 210 return;
211 } 211 }
212 212
213 mOldCurrent = currentItem(); 213 mOldCurrent = currentItem();
214#endif 214#endif
215} 215}
216 216
217 217
218void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e) 218void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e)
219{ 219{
220#ifndef KORG_NODND 220#ifndef KORG_NODND
221// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl; 221// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl;
222 222
223 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 223 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
224 !QTextDrag::canDecode( e ) ) { 224 !QTextDrag::canDecode( e ) ) {
225 e->ignore(); 225 e->ignore();
226 return; 226 return;
227 } 227 }
228 228
229 e->accept(); 229 e->accept();
230#endif 230#endif
231} 231}
232 232
233void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *) 233void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *)
234{ 234{
235#ifndef KORG_NODND 235#ifndef KORG_NODND
236// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl; 236// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl;
237 237
238 setCurrentItem(mOldCurrent); 238 setCurrentItem(mOldCurrent);
239 setSelected(mOldCurrent,true); 239 setSelected(mOldCurrent,true);
240#endif 240#endif
241} 241}
242 242
243void KOTodoListView::contentsDropEvent(QDropEvent *e) 243void KOTodoListView::contentsDropEvent(QDropEvent *e)
244{ 244{
245#ifndef KORG_NODND 245#ifndef KORG_NODND
246// kdDebug() << "KOTodoListView::contentsDropEvent" << endl; 246// kdDebug() << "KOTodoListView::contentsDropEvent" << endl;
247 247
248 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 248 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
249 !QTextDrag::canDecode( e ) ) { 249 !QTextDrag::canDecode( e ) ) {
250 e->ignore(); 250 e->ignore();
251 return; 251 return;
252 } 252 }
253 253
254 DndFactory factory( mCalendar ); 254 DndFactory factory( mCalendar );
255 Todo *todo = factory.createDropTodo(e); 255 Todo *todo = factory.createDropTodo(e);
256 256
257 if (todo) { 257 if (todo) {
258 e->acceptAction(); 258 e->acceptAction();
259 259
260 KOTodoViewItem *destination = 260 KOTodoViewItem *destination =
261 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos())); 261 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos()));
262 Todo *destinationEvent = 0; 262 Todo *destinationEvent = 0;
263 if (destination) destinationEvent = destination->todo(); 263 if (destination) destinationEvent = destination->todo();
264 264
265 Todo *existingTodo = mCalendar->todo(todo->uid()); 265 Todo *existingTodo = mCalendar->todo(todo->uid());
266 266
267 if(existingTodo) { 267 if(existingTodo) {
268 Incidence *to = destinationEvent; 268 Incidence *to = destinationEvent;
269 while(to) { 269 while(to) {
270 if (to->uid() == todo->uid()) { 270 if (to->uid() == todo->uid()) {
271 KMessageBox::sorry(this, 271 KMessageBox::sorry(this,
272 i18n("Cannot move Todo to itself\nor a child of itself"), 272 i18n("Cannot move Todo to itself\nor a child of itself"),
273 i18n("Drop Todo")); 273 i18n("Drop Todo"));
274 delete todo; 274 delete todo;
275 return; 275 return;
276 } 276 }
277 to = to->relatedTo(); 277 to = to->relatedTo();
278 } 278 }
279 internalDrop = true; 279 internalDrop = true;
280 if ( destinationEvent ) 280 if ( destinationEvent )
281 reparentTodoSignal( destinationEvent, existingTodo ); 281 reparentTodoSignal( destinationEvent, existingTodo );
282 else 282 else
283 unparentTodoSignal(existingTodo); 283 unparentTodoSignal(existingTodo);
284 delete todo; 284 delete todo;
285 } else { 285 } else {
286 mCalendar->addTodo(todo); 286 mCalendar->addTodo(todo);
287 emit todoDropped(todo, KOGlobals::EVENTADDED); 287 emit todoDropped(todo, KOGlobals::EVENTADDED);
288 if ( destinationEvent ) 288 if ( destinationEvent )
289 reparentTodoSignal( destinationEvent, todo ); 289 reparentTodoSignal( destinationEvent, todo );
290 } 290 }
291 } 291 }
292 else { 292 else {
293 QString text; 293 QString text;
294 if (QTextDrag::decode(e,text)) { 294 if (QTextDrag::decode(e,text)) {
295 //QListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) ); 295 //QListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) );
296 KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) )); 296 KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) ));
297 qDebug("Dropped : " + text); 297 qDebug("Dropped : " + text);
298 QStringList emails = QStringList::split(",",text); 298 QStringList emails = QStringList::split(",",text);
299 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) { 299 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
300 int pos = (*it).find("<"); 300 int pos = (*it).find("<");
301 QString name = (*it).left(pos); 301 QString name = (*it).left(pos);
302 QString email = (*it).mid(pos); 302 QString email = (*it).mid(pos);
303 if (!email.isEmpty() && todoi) { 303 if (!email.isEmpty() && todoi) {
304 todoi->todo()->addAttendee(new Attendee(name,email)); 304 todoi->todo()->addAttendee(new Attendee(name,email));
305 } 305 }
306 } 306 }
307 } 307 }
308 else { 308 else {
309 qDebug("KOTodoListView::contentsDropEvent(): Todo from drop not decodable "); 309 qDebug("KOTodoListView::contentsDropEvent(): Todo from drop not decodable ");
310 e->ignore(); 310 e->ignore();
311 } 311 }
312 } 312 }
313#endif 313#endif
314} 314}
315void KOTodoListView::wheelEvent (QWheelEvent *e) 315void KOTodoListView::wheelEvent (QWheelEvent *e)
316{ 316{
317 QListView::wheelEvent (e); 317 QListView::wheelEvent (e);
318} 318}
319 319
320void KOTodoListView::contentsMousePressEvent(QMouseEvent* e) 320void KOTodoListView::contentsMousePressEvent(QMouseEvent* e)
321{ 321{
322 322
323 QPoint p(contentsToViewport(e->pos())); 323 QPoint p(contentsToViewport(e->pos()));
324 QListViewItem *i = itemAt(p); 324 QListViewItem *i = itemAt(p);
325 bool rootClicked = true; 325 bool rootClicked = true;
326 if (i) { 326 if (i) {
327 // if the user clicked into the root decoration of the item, don't 327 // if the user clicked into the root decoration of the item, don't
328 // try to start a drag! 328 // try to start a drag!
329 int X = p.x(); 329 int X = p.x();
330 //qDebug("%d %d %d", X, header()->sectionPos(0), treeStepSize() ); 330 //qDebug("%d %d %d", X, header()->sectionPos(0), treeStepSize() );
331 if (X > header()->sectionPos(0) + 331 if (X > header()->sectionPos(0) +
332 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) + 332 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) +
333 itemMargin() +i->height()|| 333 itemMargin() +i->height()||
334 X < header()->sectionPos(0)) { 334 X < header()->sectionPos(0)) {
335 rootClicked = false; 335 rootClicked = false;
336 } 336 }
337 } else { 337 } else {
338 rootClicked = false; 338 rootClicked = false;
339 } 339 }
340#ifndef KORG_NODND 340#ifndef KORG_NODND
341 mMousePressed = false; 341 mMousePressed = false;
342 if (! rootClicked && !( e->button() == RightButton) ) { 342 if (! rootClicked && !( e->button() == RightButton) ) {
343 mPressPos = e->pos(); 343 mPressPos = e->pos();
344 mMousePressed = true; 344 mMousePressed = true;
345 } else { 345 } else {
346 mMousePressed = false; 346 mMousePressed = false;
347 } 347 }
348#endif 348#endif
349 //qDebug("KOTodoListView::contentsMousePressEvent %d", rootClicked); 349 //qDebug("KOTodoListView::contentsMousePressEvent %d", rootClicked);
350#ifndef DESKTOP_VERSION 350#ifndef DESKTOP_VERSION
351 if (!( e->button() == RightButton && rootClicked) ) 351 if (!( e->button() == RightButton && rootClicked) )
352 QListView::contentsMousePressEvent(e); 352 QListView::contentsMousePressEvent(e);
353#else 353#else
354 QListView::contentsMousePressEvent(e); 354 QListView::contentsMousePressEvent(e);
355#endif 355#endif
356} 356}
357void KOTodoListView::paintEvent(QPaintEvent* e) 357void KOTodoListView::paintEvent(QPaintEvent* e)
358{ 358{
359 emit paintNeeded(); 359 emit paintNeeded();
360 QListView::paintEvent( e); 360 QListView::paintEvent( e);
361} 361}
362void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e) 362void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e)
363{ 363{
364 364
365#ifndef KORG_NODND 365#ifndef KORG_NODND
366 //QListView::contentsMouseMoveEvent(e); 366 //QListView::contentsMouseMoveEvent(e);
367 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() > 367 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() >
368 QApplication::startDragDistance()*3) { 368 QApplication::startDragDistance()*3) {
369 mMousePressed = false; 369 mMousePressed = false;
370 QListViewItem *item = itemAt(contentsToViewport(mPressPos)); 370 QListViewItem *item = itemAt(contentsToViewport(mPressPos));
371 if (item) { 371 if (item) {
372 DndFactory factory( mCalendar ); 372 DndFactory factory( mCalendar );
373 ICalDrag *vd = factory.createDrag( 373 ICalDrag *vd = factory.createDrag(
374 ((KOTodoViewItem *)item)->todo(),viewport()); 374 ((KOTodoViewItem *)item)->todo(),viewport());
375 internalDrop = false; 375 internalDrop = false;
376 // we cannot do any senseful here, because the DnD is still broken in Qt 376 // we cannot do any senseful here, because the DnD is still broken in Qt
377 if (vd->drag()) { 377 if (vd->drag()) {
378 if ( !internalDrop ) { 378 if ( !internalDrop ) {
379 //emit deleteTodo( ((KOTodoViewItem *)item)->todo() ); 379 //emit deleteTodo( ((KOTodoViewItem *)item)->todo() );
380 qDebug("Dnd: External move: Delete drag source "); 380 qDebug("Dnd: External move: Delete drag source ");
381 } else 381 } else
382 qDebug("Dnd: Internal move "); 382 qDebug("Dnd: Internal move ");
383 383
384 } else { 384 } else {
385 if ( !internalDrop ) { 385 if ( !internalDrop ) {
386 qDebug("Dnd: External Copy"); 386 qDebug("Dnd: External Copy");
387 } else 387 } else
388 qDebug("DnD: Internal copy: Copy pending"); 388 qDebug("DnD: Internal copy: Copy pending");
389 } 389 }
390 } 390 }
391 } 391 }
392#endif 392#endif
393} 393}
394void KOTodoListView::keyReleaseEvent ( QKeyEvent *e ) 394void KOTodoListView::keyReleaseEvent ( QKeyEvent *e )
395{ 395{
396 if ( !e->isAutoRepeat() ) { 396 if ( !e->isAutoRepeat() ) {
397 mFlagKeyPressed = false; 397 mFlagKeyPressed = false;
398 } 398 }
399} 399}
400 400
401 401
402void KOTodoListView::keyPressEvent ( QKeyEvent * e ) 402void KOTodoListView::keyPressEvent ( QKeyEvent * e )
403{ 403{
404 qApp->processEvents(); 404 qApp->processEvents();
405 if ( !isVisible() ) { 405 if ( !isVisible() ) {
406 e->ignore(); 406 e->ignore();
407 return; 407 return;
408 } 408 }
409 if ( e->isAutoRepeat() && !mFlagKeyPressed ) { 409 if ( e->isAutoRepeat() && !mFlagKeyPressed ) {
410 e->ignore(); 410 e->ignore();
411 // qDebug(" ignore %d",e->isAutoRepeat() ); 411 // qDebug(" ignore %d",e->isAutoRepeat() );
412 return; 412 return;
413 } 413 }
414 if (! e->isAutoRepeat() ) 414 if (! e->isAutoRepeat() )
415 mFlagKeyPressed = true; 415 mFlagKeyPressed = true;
416 QListViewItem* cn; 416 QListViewItem* cn;
417 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) { 417 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) {
418 cn = currentItem(); 418 cn = currentItem();
419 if ( cn ) { 419 if ( cn ) {
420 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 420 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
421 if ( ci ){ 421 if ( ci ){
422 if ( e->state() == ShiftButton ) 422 if ( e->state() == ShiftButton )
423 ci->setOn( false ); 423 ci->setOn( false );
424 else 424 else
425 ci->setOn( true ); 425 ci->setOn( true );
426 cn = cn->itemBelow(); 426 cn = cn->itemBelow();
427 if ( cn ) { 427 if ( cn ) {
428 setCurrentItem ( cn ); 428 setCurrentItem ( cn );
429 ensureItemVisible ( cn ); 429 ensureItemVisible ( cn );
430 } 430 }
431 431
432 } 432 }
433 } 433 }
434 434
435 e->accept(); 435 e->accept();
436 return; 436 return;
437 } 437 }
438 438
439 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) { 439 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) {
440 switch ( e->key() ) { 440 switch ( e->key() ) {
441 case Qt::Key_Down: 441 case Qt::Key_Down:
442 case Qt::Key_Up: 442 case Qt::Key_Up:
443 QListView::keyPressEvent ( e ); 443 QListView::keyPressEvent ( e );
444 e->accept(); 444 e->accept();
445 break; 445 break;
446 case Qt::Key_Left: 446 case Qt::Key_Left:
447 case Qt::Key_Right: 447 case Qt::Key_Right:
448 QListView::keyPressEvent ( e ); 448 QListView::keyPressEvent ( e );
449 e->accept(); 449 e->accept();
450 return; 450 return;
451 break; 451 break;
452 default: 452 default:
453 e->ignore(); 453 e->ignore();
454 break; 454 break;
455 } 455 }
456 return; 456 return;
457 } 457 }
458 e->ignore(); 458 e->ignore();
459} 459}
460void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e) 460void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e)
461{ 461{
462 QListView::contentsMouseReleaseEvent(e); 462 QListView::contentsMouseReleaseEvent(e);
463 mMousePressed = false; 463 mMousePressed = false;
464} 464}
465 465
466void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e) 466void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e)
467{ 467{
468 if (!e) return; 468 if (!e) return;
469 469
470 QPoint vp = contentsToViewport(e->pos()); 470 QPoint vp = contentsToViewport(e->pos());
471 471
472 QListViewItem *item = itemAt(vp); 472 QListViewItem *item = itemAt(vp);
473 473
474 emit double_Clicked(item); 474 emit double_Clicked(item);
475 if (!item) return; 475 if (!item) return;
476 476
477 emit doubleClicked(item,vp,0); 477 emit doubleClicked(item,vp,0);
478} 478}
479 479
480///////////////////////////////////////////////////////////////////////////// 480/////////////////////////////////////////////////////////////////////////////
481 481
482KOQuickTodo::KOQuickTodo(QWidget *parent) : 482KOQuickTodo::KOQuickTodo(QWidget *parent) :
483 QLineEdit(parent) 483 QLineEdit(parent)
484{ 484{
485 setText(i18n("Click to add new Todo")); 485 setText(i18n("Click to add new Todo"));
486} 486}
487 487
488void KOQuickTodo::focusInEvent(QFocusEvent *ev) 488void KOQuickTodo::focusInEvent(QFocusEvent *ev)
489{ 489{
490 if ( text()==i18n("Click to add new Todo") ) 490 if ( text()==i18n("Click to add new Todo") )
491 setText(""); 491 setText("");
492 QLineEdit::focusInEvent(ev); 492 QLineEdit::focusInEvent(ev);
493} 493}
494 494
495void KOQuickTodo::focusOutEvent(QFocusEvent *ev) 495void KOQuickTodo::focusOutEvent(QFocusEvent *ev)
496{ 496{
497 setText(i18n("Click to add new Todo")); 497 setText(i18n("Click to add new Todo"));
498 QLineEdit::focusOutEvent(ev); 498 QLineEdit::focusOutEvent(ev);
499} 499}
500 500
501///////////////////////////////////////////////////////////////////////////// 501/////////////////////////////////////////////////////////////////////////////
502 502
503KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) : 503KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) :
504 KOrg::BaseView(calendar,parent,name) 504 KOrg::BaseView(calendar,parent,name)
505{ 505{
506 mCategoryPopupMenu = 0; 506 mCategoryPopupMenu = 0;
507 mPendingUpdateBeforeRepaint = false; 507 mPendingUpdateBeforeRepaint = false;
508 isFlatDisplay = false; 508 isFlatDisplay = false;
509 mNavigator = 0; 509 mNavigator = 0;
510 QBoxLayout *topLayout = new QVBoxLayout(this); 510 QBoxLayout *topLayout = new QVBoxLayout(this);
511 mName = QString ( name ); 511 mName = QString ( name );
512 mBlockUpdate = false; 512 mBlockUpdate = false;
513 mQuickBar = new QWidget( this ); 513 mQuickBar = new QWidget( this );
514 topLayout->addWidget(mQuickBar); 514 topLayout->addWidget(mQuickBar);
515 515
516 mQuickAdd = new KOQuickTodo(mQuickBar); 516 mQuickAdd = new KOQuickTodo(mQuickBar);
517 QBoxLayout *quickLayout = new QHBoxLayout(mQuickBar); 517 QBoxLayout *quickLayout = new QHBoxLayout(mQuickBar);
518 quickLayout->addWidget( mQuickAdd ); 518 quickLayout->addWidget( mQuickAdd );
519 mNewSubBut = new QPushButton( "sub",mQuickBar ); 519 mNewSubBut = new QPushButton( "sub",mQuickBar );
520 QPushButton * s_done = new QPushButton( "D",mQuickBar ); 520 QPushButton * s_done = new QPushButton( "D",mQuickBar );
521 QPushButton * s_run = new QPushButton( "R",mQuickBar ); 521 QPushButton * s_run = new QPushButton( "R",mQuickBar );
522 QPushButton * allopen = new QPushButton( "O",mQuickBar ); 522 QPushButton * allopen = new QPushButton( "O",mQuickBar );
523 QPushButton * allclose = new QPushButton( "C",mQuickBar ); 523 QPushButton * allclose = new QPushButton( "C",mQuickBar );
524 QPushButton * flat = new QPushButton( "F",mQuickBar ); 524 QPushButton * flat = new QPushButton( "F",mQuickBar );
525 525
526 int fixwid = flat->sizeHint().height(); 526 int fixwid = mQuickAdd->sizeHint().height();
527 if ( QApplication::desktop()->width() >= 800 ) 527 if ( QApplication::desktop()->width() > 800 )
528 fixwid *= 2; 528 fixwid *= 2;
529 flat->setFixedWidth( fixwid );
530 connect ( flat, SIGNAL ( clicked()), SLOT ( setAllFlat())); 529 connect ( flat, SIGNAL ( clicked()), SLOT ( setAllFlat()));
531 allopen->setFixedWidth( fixwid );
532 connect ( allopen, SIGNAL ( clicked()), SLOT ( setAllOpen())); 530 connect ( allopen, SIGNAL ( clicked()), SLOT ( setAllOpen()));
533 allclose->setFixedWidth( fixwid );
534 connect ( allclose, SIGNAL ( clicked()), SLOT ( setAllClose())); 531 connect ( allclose, SIGNAL ( clicked()), SLOT ( setAllClose()));
535 s_done->setPixmap( SmallIcon("greenhook16")); 532 s_done->setPixmap( SmallIcon("greenhook16"));
536 s_done->setFixedWidth( fixwid );
537 s_done->setFixedHeight( flat->sizeHint().height() ); 533 s_done->setFixedHeight( flat->sizeHint().height() );
538 connect ( s_done, SIGNAL ( clicked()), SLOT ( toggleCompleted())); 534 connect ( s_done, SIGNAL ( clicked()), SLOT ( toggleCompleted()));
539 s_run->setPixmap( SmallIcon("ko16old")); 535 s_run->setPixmap( SmallIcon("ko16old"));
540 s_run->setFixedWidth( fixwid );
541 s_run->setFixedHeight( flat->sizeHint().height() );
542 connect ( s_run, SIGNAL ( clicked()), SLOT ( toggleRunning())); 536 connect ( s_run, SIGNAL ( clicked()), SLOT ( toggleRunning()));
543 537
544 mNewSubBut->setFixedWidth( fixwid*3/2 );
545 connect ( mNewSubBut, SIGNAL ( clicked()), SLOT ( newSubTodo())); 538 connect ( mNewSubBut, SIGNAL ( clicked()), SLOT ( newSubTodo()));
539
540 mNewSubBut->setFixedWidth(mNewSubBut->sizeHint().width() );
546 mNewSubBut->setEnabled( false ); 541 mNewSubBut->setEnabled( false );
542 flat->setFixedWidth( fixwid );
543 s_done->setFixedWidth( fixwid );
544 allopen->setFixedWidth( fixwid );
545 allclose->setFixedWidth( fixwid );
546 s_run->setFixedWidth( fixwid );
547 if ( QApplication::desktop()->width() < 800 ) {
548 flat->setFixedHeight( fixwid );
549 s_done->setFixedHeight( fixwid );
550 allopen->setFixedHeight( fixwid );
551 allclose->setFixedHeight( fixwid );
552 s_run->setFixedHeight( fixwid );
553 mNewSubBut->setFixedHeight( fixwid );
554 }
547 quickLayout->addWidget( mNewSubBut ); 555 quickLayout->addWidget( mNewSubBut );
548 quickLayout->addWidget( s_done ); 556 quickLayout->addWidget( s_done );
549 quickLayout->addWidget( s_run ); 557 quickLayout->addWidget( s_run );
550
551 quickLayout->addWidget( allopen ); 558 quickLayout->addWidget( allopen );
552 quickLayout->addWidget( allclose ); 559 quickLayout->addWidget( allclose );
553 quickLayout->addWidget( flat ); 560 quickLayout->addWidget( flat );
554 561
555 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickBar->hide(); 562 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickBar->hide();
556 563
557 mTodoListView = new KOTodoListView(calendar,this, name ); 564 mTodoListView = new KOTodoListView(calendar,this, name );
558 topLayout->addWidget(mTodoListView); 565 topLayout->addWidget(mTodoListView);
559 //mTodoListView->header()->setMaximumHeight(30); 566 //mTodoListView->header()->setMaximumHeight(30);
560 mTodoListView->setRootIsDecorated(true); 567 mTodoListView->setRootIsDecorated(true);
561 mTodoListView->setAllColumnsShowFocus(true); 568 mTodoListView->setAllColumnsShowFocus(true);
562 569
563 mTodoListView->setShowSortIndicator(true); 570 mTodoListView->setShowSortIndicator(true);
564 571
565 mTodoListView->addColumn(i18n("Todo")); 572 mTodoListView->addColumn(i18n("Todo"));
566 mTodoListView->addColumn(i18n("Prio")); 573 mTodoListView->addColumn(i18n("Prio"));
567 mTodoListView->setColumnAlignment(1,AlignHCenter); 574 mTodoListView->setColumnAlignment(1,AlignHCenter);
568 mTodoListView->addColumn(i18n("Complete")); 575 mTodoListView->addColumn(i18n("Complete"));
569 mTodoListView->setColumnAlignment(2,AlignCenter); 576 mTodoListView->setColumnAlignment(2,AlignCenter);
570 577
571 mTodoListView->addColumn(i18n("Due Date")); 578 mTodoListView->addColumn(i18n("Due Date"));
572 mTodoListView->setColumnAlignment(3,AlignLeft); 579 mTodoListView->setColumnAlignment(3,AlignLeft);
573 mTodoListView->addColumn(i18n("Due Time")); 580 mTodoListView->addColumn(i18n("Due Time"));
574 mTodoListView->setColumnAlignment(4,AlignHCenter); 581 mTodoListView->setColumnAlignment(4,AlignHCenter);
575 582
576 mTodoListView->addColumn(i18n("Start Date")); 583 mTodoListView->addColumn(i18n("Start Date"));
577 mTodoListView->setColumnAlignment(5,AlignLeft); 584 mTodoListView->setColumnAlignment(5,AlignLeft);
578 mTodoListView->addColumn(i18n("Start Time")); 585 mTodoListView->addColumn(i18n("Start Time"));
579 mTodoListView->setColumnAlignment(6,AlignHCenter); 586 mTodoListView->setColumnAlignment(6,AlignHCenter);
580 587
581 //mTodoListView->addColumn(i18n("Cancelled")); 588 //mTodoListView->addColumn(i18n("Cancelled"));
582 mTodoListView->addColumn(i18n("Categories")); 589 mTodoListView->addColumn(i18n("Categories"));
583 mTodoListView->addColumn(i18n("Calendar")); 590 mTodoListView->addColumn(i18n("Calendar"));
584 mTodoListView->addColumn(i18n("Last Modified")); 591 mTodoListView->addColumn(i18n("Last Modified"));
585 mTodoListView->addColumn(i18n("Created")); 592 mTodoListView->addColumn(i18n("Created"));
586 mTodoListView->addColumn(i18n("Last Modified Sub")); 593 mTodoListView->addColumn(i18n("Last Modified Sub"));
587#if 0 594#if 0
588 mTodoListView->addColumn(i18n("Sort Id")); 595 mTodoListView->addColumn(i18n("Sort Id"));
589 mTodoListView->setColumnAlignment(4,AlignHCenter); 596 mTodoListView->setColumnAlignment(4,AlignHCenter);
590#endif 597#endif
591 598
592 mTodoListView->setMinimumHeight( 60 ); 599 mTodoListView->setMinimumHeight( 60 );
593 mTodoListView->setItemsRenameable( true ); 600 mTodoListView->setItemsRenameable( true );
594 mTodoListView->setRenameable( 0 ); 601 mTodoListView->setRenameable( 0 );
595 mTodoListView->setColumnWidth( 0, 120 ); 602 mTodoListView->setColumnWidth( 0, 120 );
596 int iii = 0; 603 int iii = 0;
597 for ( iii = 0; iii< 12 ; ++iii ) 604 for ( iii = 0; iii< 12 ; ++iii )
598 mTodoListView->setColumnWidthMode( iii, QListView::Manual ); 605 mTodoListView->setColumnWidthMode( iii, QListView::Manual );
599 606
600 607
601 mKOTodoViewWhatsThis = new KOTodoViewWhatsThis(mTodoListView->viewport(),this); 608 mKOTodoViewWhatsThis = new KOTodoViewWhatsThis(mTodoListView->viewport(),this);
602 609
603 mPriorityPopupMenu = new QPopupMenu(this); 610 mPriorityPopupMenu = new QPopupMenu(this);
604 for (int i = 1; i <= 5; i++) { 611 for (int i = 1; i <= 5; i++) {
605 QString label = QString ("%1").arg (i); 612 QString label = QString ("%1").arg (i);
606 mPriority[mPriorityPopupMenu->insertItem (label)] = i; 613 mPriority[mPriorityPopupMenu->insertItem (label)] = i;
607 } 614 }
608 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int))); 615 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int)));
609 616
610 mPercentageCompletedPopupMenu = new QPopupMenu(this); 617 mPercentageCompletedPopupMenu = new QPopupMenu(this);
611 for (int i = 0; i <= 100; i+=20) { 618 for (int i = 0; i <= 100; i+=20) {
612 QString label = QString ("%1 %").arg (i); 619 QString label = QString ("%1 %").arg (i);
613 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i; 620 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i;
614 } 621 }
615 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int))); 622 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int)));
616 623
617 624
618 mCategoryPopupMenu = new QPopupMenu (this); 625 mCategoryPopupMenu = new QPopupMenu (this);
619 mCategoryPopupMenu->setCheckable (true); 626 mCategoryPopupMenu->setCheckable (true);
620 connect (mCategoryPopupMenu, SIGNAL (activated (int)), SLOT (changedCategories (int))); 627 connect (mCategoryPopupMenu, SIGNAL (activated (int)), SLOT (changedCategories (int)));
621 connect (mCategoryPopupMenu, SIGNAL (aboutToShow ()), SLOT (fillCategories ())); 628 connect (mCategoryPopupMenu, SIGNAL (aboutToShow ()), SLOT (fillCategories ()));
622 629
623 mCalPopupMenu = new QPopupMenu (this); 630 mCalPopupMenu = new QPopupMenu (this);
624 mCalPopupMenu->setCheckable (true); 631 mCalPopupMenu->setCheckable (true);
625 connect (mCalPopupMenu, SIGNAL (activated (int)), SLOT (changedCal (int))); 632 connect (mCalPopupMenu, SIGNAL (activated (int)), SLOT (changedCal (int)));
626 connect (mCalPopupMenu, SIGNAL (aboutToShow ()), SLOT (fillCal ())); 633 connect (mCalPopupMenu, SIGNAL (aboutToShow ()), SLOT (fillCal ()));
627 634
628 635
629 636
630 637
631 mItemPopupMenu = new QPopupMenu(this); 638 mItemPopupMenu = new QPopupMenu(this);
632 mItemPopupMenu->insertItem(i18n("Show"), this, 639 mItemPopupMenu->insertItem(i18n("Show"), this,
633 SLOT (showTodo())); 640 SLOT (showTodo()));
634 mItemPopupMenu->insertItem(i18n("Edit..."), this, 641 mItemPopupMenu->insertItem(i18n("Edit..."), this,
635 SLOT (editTodo())); 642 SLOT (editTodo()));
636 mItemPopupMenu->insertItem( i18n("Delete..."), this, 643 mItemPopupMenu->insertItem( i18n("Delete..."), this,
637 SLOT (deleteTodo())); 644 SLOT (deleteTodo()));
638 mItemPopupMenu->insertItem( i18n("Clone..."), this, 645 mItemPopupMenu->insertItem( i18n("Clone..."), this,
639 SLOT (cloneTodo())); 646 SLOT (cloneTodo()));
640 mItemPopupMenu->insertItem( i18n("Move..."), this, 647 mItemPopupMenu->insertItem( i18n("Move..."), this,
641 SLOT (moveTodo())); 648 SLOT (moveTodo()));
642#ifndef DESKTOP_VERSION 649#ifndef DESKTOP_VERSION
643 mItemPopupMenu->insertItem( i18n("Beam..."), this, 650 mItemPopupMenu->insertItem( i18n("Beam..."), this,
644 SLOT (beamTodo())); 651 SLOT (beamTodo()));
645#endif 652#endif
646 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this, 653 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this,
647 SLOT (cancelTodo())); 654 SLOT (cancelTodo()));
648 mItemPopupMenu->insertItem( i18n("Categories"), mCategoryPopupMenu); 655 mItemPopupMenu->insertItem( i18n("Categories"), mCategoryPopupMenu);
649 mItemPopupMenu->insertItem( i18n("Calendar"), mCalPopupMenu); 656 mItemPopupMenu->insertItem( i18n("Calendar"), mCalPopupMenu);
650 mItemPopupMenu->insertSeparator(); 657 mItemPopupMenu->insertSeparator();
651 mItemPopupMenu->insertItem( i18n("Start/Stop todo..."), this, 658 mItemPopupMenu->insertItem( i18n("Start/Stop todo..."), this,
652 SLOT (toggleRunningItem())); 659 SLOT (toggleRunningItem()));
653 mItemPopupMenu->insertSeparator(); 660 mItemPopupMenu->insertSeparator();
654 /* 661 /*
655 mItemPopupMenu->insertItem( i18n("New Todo..."), this, 662 mItemPopupMenu->insertItem( i18n("New Todo..."), this,
656 SLOT (newTodo())); 663 SLOT (newTodo()));
657 */ 664 */
658 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this, 665 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this,
659 SLOT (newSubTodo())); 666 SLOT (newSubTodo()));
660 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this, 667 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this,
661 SLOT (unparentTodo()),0,21); 668 SLOT (unparentTodo()),0,21);
662 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this, 669 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this,
663 SLOT (reparentTodo()),0,22); 670 SLOT (reparentTodo()),0,22);
664 mItemPopupMenu->insertSeparator(); 671 mItemPopupMenu->insertSeparator();
665#if 0 672#if 0
666 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed..."), 673 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed..."),
667 this, SLOT( purgeCompleted() ) ); 674 this, SLOT( purgeCompleted() ) );
668 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"), 675 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"),
669 this, SLOT( toggleCompleted() ),0, 33 ); 676 this, SLOT( toggleCompleted() ),0, 33 );
670 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 677 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
671 this, SLOT( toggleQuickTodo() ),0, 34 ); 678 this, SLOT( toggleQuickTodo() ),0, 34 );
672 mItemPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"), 679 mItemPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"),
673 this, SLOT( toggleRunning() ),0, 35 ); 680 this, SLOT( toggleRunning() ),0, 35 );
674 681
675#endif 682#endif
676 mPopupMenu = new QPopupMenu(this); 683 mPopupMenu = new QPopupMenu(this);
677 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this, 684 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this,
678 SLOT (newTodo()),0,1); 685 SLOT (newTodo()),0,1);
679 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed..."), 686 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed..."),
680 this, SLOT(purgeCompleted()),0,2); 687 this, SLOT(purgeCompleted()),0,2);
681 mPopupMenu->insertItem(i18n("Show Completed"), 688 mPopupMenu->insertItem(i18n("Show Completed"),
682 this, SLOT( toggleCompleted() ),0,3 ); 689 this, SLOT( toggleCompleted() ),0,3 );
683 mPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"), 690 mPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"),
684 this, SLOT( toggleRunning() ),0,5 ); 691 this, SLOT( toggleRunning() ),0,5 );
685 mPopupMenu->insertItem(i18n(" set all open","Display all opened"), 692 mPopupMenu->insertItem(i18n(" set all open","Display all opened"),
686 this, SLOT( setAllOpen() ),0,6 ); 693 this, SLOT( setAllOpen() ),0,6 );
687 mPopupMenu->insertItem(i18n(" set all close","Display all closed"), 694 mPopupMenu->insertItem(i18n(" set all close","Display all closed"),
688 this, SLOT( setAllClose() ),0,7 ); 695 this, SLOT( setAllClose() ),0,7 );
689 mPopupMenu->insertItem(i18n(" set all flat","Display all flat"), 696 mPopupMenu->insertItem(i18n(" set all flat","Display all flat"),
690 this, SLOT( setAllFlat() ),0,8 ); 697 this, SLOT( setAllFlat() ),0,8 );
691 mPopupMenu->insertSeparator(); 698 mPopupMenu->insertSeparator();
692 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 699 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
693 this, SLOT( toggleQuickTodo() ),0,4 ); 700 this, SLOT( toggleQuickTodo() ),0,4 );
694 mDocPrefs = new DocPrefs( name ); 701 mDocPrefs = new DocPrefs( name );
695 702
696 mItemPopupMenu->insertItem(i18n("Todo View"),mPopupMenu ); 703 mItemPopupMenu->insertItem(i18n("Todo View"),mPopupMenu );
697 mPopupMenu->setCheckable( true ); 704 mPopupMenu->setCheckable( true );
698 mItemPopupMenu->setCheckable( true ); 705 mItemPopupMenu->setCheckable( true );
699 706
700 707
701 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); 708 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo );
702 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); 709 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo );
703 710
704 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); 711 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo);
705 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); 712 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo );
706 713
707 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); 714 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos);
708 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); 715 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos );
709 716
710 717
711 // Double clicking conflicts with opening/closing the subtree 718 // Double clicking conflicts with opening/closing the subtree
712 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ), 719 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ),
713 SLOT( editItem( QListViewItem *) ) ); 720 SLOT( editItem( QListViewItem *) ) );
714 /* 721 /*
715 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *, 722 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *,
716 const QPoint &,int ) ), 723 const QPoint &,int ) ),
717 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 724 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
718 */ 725 */
719 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *, 726 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *,
720 const QPoint &,int ) ), 727 const QPoint &,int ) ),
721 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 728 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
722 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ), 729 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ),
723 SLOT( itemClicked( QListViewItem * ) ) ); 730 SLOT( itemClicked( QListViewItem * ) ) );
724 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ), 731 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ),
725 SLOT( itemDoubleClicked( QListViewItem * ) ) ); 732 SLOT( itemDoubleClicked( QListViewItem * ) ) );
726 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ), 733 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ),
727 SLOT( updateView() ) ); 734 SLOT( updateView() ) );
728 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ), 735 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ),
729 SLOT( todoModified(Todo *, int) ) ); 736 SLOT( todoModified(Todo *, int) ) );
730 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ), 737 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ),
731 SLOT( itemStateChanged( QListViewItem * ) ) ); 738 SLOT( itemStateChanged( QListViewItem * ) ) );
732 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ), 739 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ),
733 SLOT( itemStateChanged( QListViewItem * ) ) ); 740 SLOT( itemStateChanged( QListViewItem * ) ) );
734 connect( mTodoListView, SIGNAL( paintNeeded() ), 741 connect( mTodoListView, SIGNAL( paintNeeded() ),
735 SLOT( paintNeeded()) ); 742 SLOT( paintNeeded()) );
736 743
737#if 0 744#if 0
738 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)), 745 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)),
739 SLOT(selectionChanged(QListViewItem *))); 746 SLOT(selectionChanged(QListViewItem *)));
740 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)), 747 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)),
741 SLOT(selectionChanged(QListViewItem *))); 748 SLOT(selectionChanged(QListViewItem *)));
742 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)), 749 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)),
743 SLOT(selectionChanged(QListViewItem *))); 750 SLOT(selectionChanged(QListViewItem *)));
744#endif 751#endif
745 752
746 connect( mTodoListView, SIGNAL(reparentTodoSignal( Todo *,Todo * ) ), SIGNAL(reparentTodoSignal( Todo *,Todo * ) )); 753 connect( mTodoListView, SIGNAL(reparentTodoSignal( Todo *,Todo * ) ), SIGNAL(reparentTodoSignal( Todo *,Todo * ) ));
747 connect( mTodoListView, SIGNAL(unparentTodoSignal(Todo *) ), SIGNAL(unparentTodoSignal(Todo *) )); 754 connect( mTodoListView, SIGNAL(unparentTodoSignal(Todo *) ), SIGNAL(unparentTodoSignal(Todo *) ));
748 connect( mTodoListView, SIGNAL( deleteTodo(Todo *) ), SIGNAL(deleteTodoSignal(Todo *) )); 755 connect( mTodoListView, SIGNAL( deleteTodo(Todo *) ), SIGNAL(deleteTodoSignal(Todo *) ));
749 756
750 connect( mTodoListView, SIGNAL(selectionChanged() ), 757 connect( mTodoListView, SIGNAL(selectionChanged() ),
751 SLOT( processSelectionChange() ) ); 758 SLOT( processSelectionChange() ) );
752 connect( mQuickAdd, SIGNAL( returnPressed () ), 759 connect( mQuickAdd, SIGNAL( returnPressed () ),
753 SLOT( addQuickTodo() ) ); 760 SLOT( addQuickTodo() ) );
754 761
755} 762}
756 763
757KOTodoView::~KOTodoView() 764KOTodoView::~KOTodoView()
758{ 765{
759 766
760#if QT_VERSION >= 0x030000 767#if QT_VERSION >= 0x030000
761 768
762#else 769#else
763 delete mKOTodoViewWhatsThis; 770 delete mKOTodoViewWhatsThis;
764#endif 771#endif
765 772
766 delete mDocPrefs; 773 delete mDocPrefs;
767} 774}
768QString KOTodoView::getWhatsThisText(QPoint p) 775QString KOTodoView::getWhatsThisText(QPoint p)
769{ 776{
770 KOTodoViewItem* item = ( KOTodoViewItem* ) mTodoListView->itemAt( p ); 777 KOTodoViewItem* item = ( KOTodoViewItem* ) mTodoListView->itemAt( p );
771 if ( item ) 778 if ( item )
772 return KIncidenceFormatter::instance()->getFormattedText( item->todo(), 779 return KIncidenceFormatter::instance()->getFormattedText( item->todo(),
773 KOPrefs::instance()->mWTshowDetails, 780 KOPrefs::instance()->mWTshowDetails,
774 KOPrefs::instance()->mWTshowCreated, 781 KOPrefs::instance()->mWTshowCreated,
775 KOPrefs::instance()->mWTshowChanged); 782 KOPrefs::instance()->mWTshowChanged);
776 return i18n("That is the todo view" ); 783 return i18n("That is the todo view" );
777 784
778} 785}
779 786
780void KOTodoView::jumpToDate () 787void KOTodoView::jumpToDate ()
781{ 788{
782 // if (mActiveItem) { 789 // if (mActiveItem) {
783// mActiveItem->todo()); 790// mActiveItem->todo());
784// if ( mActiveItem->todo()->hasDueDate() ) 791// if ( mActiveItem->todo()->hasDueDate() )
785// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() ); 792// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() );
786} 793}
787void KOTodoView::paintNeeded() 794void KOTodoView::paintNeeded()
788{ 795{
789 if ( mPendingUpdateBeforeRepaint ) { 796 if ( mPendingUpdateBeforeRepaint ) {
790 updateView(); 797 updateView();
791 mPendingUpdateBeforeRepaint = false; 798 mPendingUpdateBeforeRepaint = false;
792 } 799 }
793} 800}
794void KOTodoView::paintEvent(QPaintEvent * pevent) 801void KOTodoView::paintEvent(QPaintEvent * pevent)
795{ 802{
796 if ( mPendingUpdateBeforeRepaint ) { 803 if ( mPendingUpdateBeforeRepaint ) {
797 updateView(); 804 updateView();
798 mPendingUpdateBeforeRepaint = false; 805 mPendingUpdateBeforeRepaint = false;
799 } 806 }
800 KOrg::BaseView::paintEvent( pevent); 807 KOrg::BaseView::paintEvent( pevent);
801} 808}
802 809
803void KOTodoView::updateView() 810void KOTodoView::updateView()
804{ 811{
805 pendingSubtodo = 0; 812 pendingSubtodo = 0;
806 if ( mBlockUpdate ) { 813 if ( mBlockUpdate ) {
807 return; 814 return;
808 } 815 }
809 if ( !isVisible() ) { 816 if ( !isVisible() ) {
810 mPendingUpdateBeforeRepaint = true; 817 mPendingUpdateBeforeRepaint = true;
811 return; 818 return;
812 } 819 }
813 //qDebug("KOTodoView::updateView() %x", this); 820 //qDebug("KOTodoView::updateView() %x", this);
814 if ( isFlatDisplay ) { 821 if ( isFlatDisplay ) {
815 displayAllFlat(); 822 displayAllFlat();
816 return; 823 return;
817 } 824 }
818 storeCurrentItem(); 825 storeCurrentItem();
819 //qDebug("update "); 826 //qDebug("update ");
820// kdDebug() << "KOTodoView::updateView()" << endl; 827// kdDebug() << "KOTodoView::updateView()" << endl;
821 QFont fo = KOPrefs::instance()->mTodoViewFont; 828 QFont fo = KOPrefs::instance()->mTodoViewFont;
822 829
823 830
824 mTodoListView->clear(); 831 mTodoListView->clear();
825 if ( mName == "todolistsmall" ) { 832 if ( mName == "todolistsmall" ) {
826 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) { 833 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) {
827 int ps = fo.pointSize() -2; 834 int ps = fo.pointSize() -2;
828 if ( ps > 12 ) 835 if ( ps > 12 )
829 ps -= 2; 836 ps -= 2;
830 fo.setPointSize( ps ); 837 fo.setPointSize( ps );
831 } 838 }
832 } 839 }
833 840
834 mTodoListView->setFont( fo ); 841 mTodoListView->setFont( fo );
835 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont ); 842 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont );
836 //mTodoListView->header()->setMaximumHeight(fm.height()); 843 //mTodoListView->header()->setMaximumHeight(fm.height());
837 QPtrList<Todo> todoList = calendar()->todos(); 844 QPtrList<Todo> todoList = calendar()->todos();
838 845
839/* 846/*
840 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl; 847 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl;
841 Event *t; 848 Event *t;
842 for(t = todoList.first(); t; t = todoList.next()) { 849 for(t = todoList.first(); t; t = todoList.next()) {
843 kdDebug() << " " << t->getSummary() << endl; 850 kdDebug() << " " << t->getSummary() << endl;
844 851
845 if (t->getRelatedTo()) { 852 if (t->getRelatedTo()) {
846 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl; 853 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl;
847 } 854 }
848 855
849 QPtrList<Event> l = t->getRelations(); 856 QPtrList<Event> l = t->getRelations();
850 Event *c; 857 Event *c;
851 for(c=l.first();c;c=l.next()) { 858 for(c=l.first();c;c=l.next()) {
852 kdDebug() << " - relation: " << c->getSummary() << endl; 859 kdDebug() << " - relation: " << c->getSummary() << endl;
853 } 860 }
854 } 861 }
855*/ 862*/
856 863
857 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a 864 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a
858 // specific order of events. That means that we have to generate parent items 865 // specific order of events. That means that we have to generate parent items
859 // recursively for proper hierarchical display of Todos. 866 // recursively for proper hierarchical display of Todos.
860 mTodoMap.clear(); 867 mTodoMap.clear();
861 Todo *todo; 868 Todo *todo;
862 todo = todoList.first();// todo; todo = todoList.next()) { 869 todo = todoList.first();// todo; todo = todoList.next()) {
863 while ( todo ) { 870 while ( todo ) {
864 bool next = true; 871 bool next = true;
865 // qDebug("todo %s ", todo->summary().latin1()); 872 // qDebug("todo %s ", todo->summary().latin1());
866 Incidence *incidence = todo->relatedTo(); 873 Incidence *incidence = todo->relatedTo();
867 while ( incidence ) { 874 while ( incidence ) {
868 if ( incidence->typeID() == todoID ) { 875 if ( incidence->typeID() == todoID ) {
869 //qDebug("related %s ",incidence->summary().latin1() ); 876 //qDebug("related %s ",incidence->summary().latin1() );
870 if ( !(todoList.contains ( ((Todo* )incidence ) ) ) && incidence->calEnabled() ) { 877 if ( !(todoList.contains ( ((Todo* )incidence ) ) ) && incidence->calEnabled() ) {
871 //qDebug("related not found "); 878 //qDebug("related not found ");
872 todoList.remove( ); 879 todoList.remove( );
873 todo = todoList.current(); 880 todo = todoList.current();
874 next = false; 881 next = false;
875 incidence = 0; 882 incidence = 0;
876 883
877 } else { 884 } else {
878 //qDebug("related found "); 885 //qDebug("related found ");
879 incidence = incidence->relatedTo(); 886 incidence = incidence->relatedTo();
880 } 887 }
881 } else 888 } else
882 incidence = 0; 889 incidence = 0;
883 } 890 }
884 if ( next ) 891 if ( next )
885 todo = todoList.next(); 892 todo = todoList.next();
886 } 893 }
887 894
888 for(todo = todoList.first(); todo; todo = todoList.next()) { 895 for(todo = todoList.first(); todo; todo = todoList.next()) {
889 if (!mTodoMap.contains(todo) && checkTodo( todo ) ) 896 if (!mTodoMap.contains(todo) && checkTodo( todo ) )
890 { 897 {
891 insertTodoItem(todo); 898 insertTodoItem(todo);
892 } 899 }
893 } 900 }
894 // Restore opened/closed state 901 // Restore opened/closed state
895 mTodoListView->blockSignals( true ); 902 mTodoListView->blockSignals( true );
896 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() ); 903 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() );
897 mTodoListView->blockSignals( false ); 904 mTodoListView->blockSignals( false );
898 resetCurrentItem(); 905 resetCurrentItem();
899} 906}
900 907
901void KOTodoView::storeCurrentItem() 908void KOTodoView::storeCurrentItem()
902{ 909{
903 mCurItem = 0; 910 mCurItem = 0;
904 mCurItemRootParent = 0; 911 mCurItemRootParent = 0;
905 mCurItemParent = 0; 912 mCurItemParent = 0;
906 mCurItemAbove = 0; 913 mCurItemAbove = 0;
907 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 914 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
908 if (mActiveItem) { 915 if (mActiveItem) {
909 mCurItem = mActiveItem->todo(); 916 mCurItem = mActiveItem->todo();
910 KOTodoViewItem* activeItemAbove = (KOTodoViewItem*)mActiveItem->itemAbove (); 917 KOTodoViewItem* activeItemAbove = (KOTodoViewItem*)mActiveItem->itemAbove ();
911 if ( activeItemAbove ) 918 if ( activeItemAbove )
912 mCurItemAbove = activeItemAbove->todo(); 919 mCurItemAbove = activeItemAbove->todo();
913 mCurItemRootParent = mCurItem; 920 mCurItemRootParent = mCurItem;
914 mCurItemParent = mCurItemRootParent->relatedTo(); 921 mCurItemParent = mCurItemRootParent->relatedTo();
915 while ( mCurItemRootParent->relatedTo() != 0 ) 922 while ( mCurItemRootParent->relatedTo() != 0 )
916 mCurItemRootParent = mCurItemRootParent->relatedTo(); 923 mCurItemRootParent = mCurItemRootParent->relatedTo();
917 } 924 }
918 mActiveItem = 0; 925 mActiveItem = 0;
919} 926}
920 927
921void KOTodoView::resetCurrentItem() 928void KOTodoView::resetCurrentItem()
922{ 929{
923 //mTodoListView->setFocus(); 930 //mTodoListView->setFocus();
924 KOTodoViewItem* foundItem = 0; 931 KOTodoViewItem* foundItem = 0;
925 KOTodoViewItem* foundItemRoot = 0; 932 KOTodoViewItem* foundItemRoot = 0;
926 KOTodoViewItem* foundItemParent = 0; 933 KOTodoViewItem* foundItemParent = 0;
927 KOTodoViewItem* foundItemAbove = 0; 934 KOTodoViewItem* foundItemAbove = 0;
928 if ( mTodoListView->firstChild () ) { 935 if ( mTodoListView->firstChild () ) {
929 if ( mCurItem ) { 936 if ( mCurItem ) {
930 KOTodoViewItem* item = (KOTodoViewItem*)mTodoListView->firstChild (); 937 KOTodoViewItem* item = (KOTodoViewItem*)mTodoListView->firstChild ();
931 while ( item ) { 938 while ( item ) {
932 if ( item->todo() == mCurItem ) { 939 if ( item->todo() == mCurItem ) {
933 foundItem = item; 940 foundItem = item;
934 break; 941 break;
935 } else if ( item->todo() == mCurItemAbove ) { 942 } else if ( item->todo() == mCurItemAbove ) {
936 foundItemAbove = item; 943 foundItemAbove = item;
937 944
938 } 945 }
939 if ( item->todo() == mCurItemRootParent ) { 946 if ( item->todo() == mCurItemRootParent ) {
940 foundItemRoot = item; 947 foundItemRoot = item;
941 } 948 }
942 if ( item->todo() == mCurItemParent ) { 949 if ( item->todo() == mCurItemParent ) {
943 foundItemParent = item; 950 foundItemParent = item;
944 } 951 }
945 item = (KOTodoViewItem*)item->itemBelow(); 952 item = (KOTodoViewItem*)item->itemBelow();
946 } 953 }
947 if ( ! foundItem ) { 954 if ( ! foundItem ) {
948 if ( foundItemParent ) { 955 if ( foundItemParent ) {
949 foundItem = foundItemParent; 956 foundItem = foundItemParent;
950 } else { 957 } else {
951 if ( foundItemRoot ) 958 if ( foundItemRoot )
952 foundItem = foundItemRoot; 959 foundItem = foundItemRoot;
953 else 960 else
954 foundItem = foundItemAbove; 961 foundItem = foundItemAbove;
955 } 962 }
956 } 963 }
957 } 964 }
958 if ( foundItem ) { 965 if ( foundItem ) {
959 mTodoListView->setSelected ( foundItem, true ); 966 mTodoListView->setSelected ( foundItem, true );
960 mTodoListView->setCurrentItem( foundItem ); 967 mTodoListView->setCurrentItem( foundItem );
961 mTodoListView->ensureItemVisible( foundItem ); 968 mTodoListView->ensureItemVisible( foundItem );
962 } else { 969 } else {
963 if ( mTodoListView->firstChild () ) { 970 if ( mTodoListView->firstChild () ) {
964 mTodoListView->setSelected ( mTodoListView->firstChild (), true ); 971 mTodoListView->setSelected ( mTodoListView->firstChild (), true );
965 mTodoListView->setCurrentItem( mTodoListView->firstChild () ); 972 mTodoListView->setCurrentItem( mTodoListView->firstChild () );
966 } 973 }
967 } 974 }
968 } 975 }
969 processSelectionChange(); 976 processSelectionChange();
970 QTimer::singleShot( 100, this, SLOT ( resetFocusToList() )); 977 QTimer::singleShot( 100, this, SLOT ( resetFocusToList() ));
971} 978}
972void KOTodoView::resetFocusToList() 979void KOTodoView::resetFocusToList()
973{ 980{
974 topLevelWidget()->setActiveWindow(); 981 topLevelWidget()->setActiveWindow();
975 mTodoListView->setFocus(); 982 mTodoListView->setFocus();
976} 983}
977//Incidence * mCurItem, *mCurItemRootParent,*mCurItemAbove; 984//Incidence * mCurItem, *mCurItemRootParent,*mCurItemAbove;
978bool KOTodoView::checkTodo( Todo * todo ) 985bool KOTodoView::checkTodo( Todo * todo )
979{ 986{
980 987
981 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() ) 988 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() )
982 return false; 989 return false;
983 if ( !todo->isCompleted() ) { 990 if ( !todo->isCompleted() ) {
984 if ( todo->hasDueDate() && todo->dtDue().date() <= QDate::currentDate() ) 991 if ( todo->hasDueDate() && todo->dtDue().date() <= QDate::currentDate() )
985 return true; 992 return true;
986 } 993 }
987 if ( KOPrefs::instance()->mHideNonStartedTodos && mNavigator ) { 994 if ( KOPrefs::instance()->mHideNonStartedTodos && mNavigator ) {
988 if ( todo->hasStartDate() ) 995 if ( todo->hasStartDate() )
989 if ( mNavigator->selectedDates().last() < todo->dtStart().date() ) 996 if ( mNavigator->selectedDates().last() < todo->dtStart().date() )
990 return false; 997 return false;
991 if ( todo->hasDueDate() ) 998 if ( todo->hasDueDate() )
992 if ( mNavigator->selectedDates().first() > todo->dtDue().date() ) 999 if ( mNavigator->selectedDates().first() > todo->dtDue().date() )
993 return false; 1000 return false;
994 } 1001 }
995 return true; 1002 return true;
996} 1003}
997 1004
998void KOTodoView::restoreItemState( QListViewItem *item ) 1005void KOTodoView::restoreItemState( QListViewItem *item )
999{ 1006{
1000 pendingSubtodo = 0; 1007 pendingSubtodo = 0;
1001 while( item ) { 1008 while( item ) {
1002 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 1009 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
1003 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) ); 1010 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) );
1004 if( item->childCount() > 0 ) restoreItemState( item->firstChild() ); 1011 if( item->childCount() > 0 ) restoreItemState( item->firstChild() );
1005 item = item->nextSibling(); 1012 item = item->nextSibling();
1006 } 1013 }
1007} 1014}
1008 1015
1009 1016
1010QMap<Todo *,KOTodoViewItem *>::ConstIterator 1017QMap<Todo *,KOTodoViewItem *>::ConstIterator
1011KOTodoView::insertTodoItem(Todo *todo) 1018KOTodoView::insertTodoItem(Todo *todo)
1012{ 1019{
1013 1020
1014 // kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl; 1021 // kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl;
1015 // TODO: Check, if dynmaic cast is necessary 1022 // TODO: Check, if dynmaic cast is necessary
1016 1023
1017 pendingSubtodo = 0; 1024 pendingSubtodo = 0;
1018 Incidence *incidence = todo->relatedTo(); 1025 Incidence *incidence = todo->relatedTo();
1019 while ( incidence && !incidence->calEnabled() ) 1026 while ( incidence && !incidence->calEnabled() )
1020 incidence = incidence->relatedTo(); 1027 incidence = incidence->relatedTo();
1021 if (incidence && incidence->typeID() == todoID ) { 1028 if (incidence && incidence->typeID() == todoID ) {
1022 Todo *relatedTodo = static_cast<Todo *>(incidence); 1029 Todo *relatedTodo = static_cast<Todo *>(incidence);
1023 1030
1024 // kdDebug() << " has Related" << endl; 1031 // kdDebug() << " has Related" << endl;
1025 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 1032 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
1026 itemIterator = mTodoMap.find(relatedTodo); 1033 itemIterator = mTodoMap.find(relatedTodo);
1027 if (itemIterator == mTodoMap.end()) { 1034 if (itemIterator == mTodoMap.end()) {
1028 // kdDebug() << " related not yet in list" << endl; 1035 // kdDebug() << " related not yet in list" << endl;
1029 itemIterator = insertTodoItem (relatedTodo); 1036 itemIterator = insertTodoItem (relatedTodo);
1030 } 1037 }
1031 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem 1038 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem
1032 // and one into the map. Sure finding is more easy but why? -zecke 1039 // and one into the map. Sure finding is more easy but why? -zecke
1033 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this); 1040 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this);
1034 return mTodoMap.insert(todo,todoItem); 1041 return mTodoMap.insert(todo,todoItem);
1035 } else { 1042 } else {
1036 // kdDebug() << " no Related" << endl; 1043 // kdDebug() << " no Related" << endl;
1037 // see above -zecke 1044 // see above -zecke
1038 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 1045 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
1039 return mTodoMap.insert(todo,todoItem); 1046 return mTodoMap.insert(todo,todoItem);
1040 } 1047 }
1041} 1048}
1042 1049
1043 1050
1044void KOTodoView::updateConfig() 1051void KOTodoView::updateConfig()
1045{ 1052{
1046 updateView(); 1053 updateView();
1047 mTodoListView->repaintContents(); 1054 mTodoListView->repaintContents();
1048} 1055}
1049 1056
1050QPtrList<Incidence> KOTodoView::selectedIncidences() 1057QPtrList<Incidence> KOTodoView::selectedIncidences()
1051{ 1058{
1052 QPtrList<Incidence> selected; 1059 QPtrList<Incidence> selected;
1053 1060
1054 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 1061 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
1055// if (!item) item = mActiveItem; 1062// if (!item) item = mActiveItem;
1056 if (item) selected.append(item->todo()); 1063 if (item) selected.append(item->todo());
1057 1064
1058 return selected; 1065 return selected;
1059} 1066}
1060 1067
1061QPtrList<Todo> KOTodoView::selectedTodos() 1068QPtrList<Todo> KOTodoView::selectedTodos()
1062{ 1069{
1063 QPtrList<Todo> selected; 1070 QPtrList<Todo> selected;
1064 1071
1065 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 1072 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
1066// if (!item) item = mActiveItem; 1073// if (!item) item = mActiveItem;
1067 if (item) selected.append(item->todo()); 1074 if (item) selected.append(item->todo());
1068 1075
1069 return selected; 1076 return selected;
1070} 1077}
1071 1078
1072void KOTodoView::changeEventDisplay(Event *, int) 1079void KOTodoView::changeEventDisplay(Event *, int)
1073{ 1080{
1074 updateView(); 1081 updateView();
1075} 1082}
1076 1083
1077void KOTodoView::showDates(const QDate &, const QDate &) 1084void KOTodoView::showDates(const QDate &, const QDate &)
1078{ 1085{
1079} 1086}
1080 1087
1081void KOTodoView::showEvents(QPtrList<Event>) 1088void KOTodoView::showEvents(QPtrList<Event>)
1082{ 1089{
1083 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl; 1090 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl;
1084} 1091}
1085 1092
1086void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd, 1093void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd,
1087 const QDate &td) 1094 const QDate &td)
1088{ 1095{
1089#ifndef KORG_NOPRINTER 1096#ifndef KORG_NOPRINTER
1090 calPrinter->preview(CalPrinter::Todolist, fd, td); 1097 calPrinter->preview(CalPrinter::Todolist, fd, td);
1091#endif 1098#endif
1092} 1099}
1093 1100
1094void KOTodoView::editItem(QListViewItem *item ) 1101void KOTodoView::editItem(QListViewItem *item )
1095{ 1102{
1096 emit editTodoSignal(((KOTodoViewItem *)item)->todo()); 1103 emit editTodoSignal(((KOTodoViewItem *)item)->todo());
1097} 1104}
1098 1105
1099void KOTodoView::showItem(QListViewItem *item,const QPoint &,int) 1106void KOTodoView::showItem(QListViewItem *item,const QPoint &,int)
1100{ 1107{
1101 emit showTodoSignal(((KOTodoViewItem *)item)->todo()); 1108 emit showTodoSignal(((KOTodoViewItem *)item)->todo());
1102} 1109}
1103 1110
1104void KOTodoView::popupMenu(QListViewItem *item,const QPoint &p,int column) 1111void KOTodoView::popupMenu(QListViewItem *item,const QPoint &p,int column)
1105{ 1112{
1106 pendingSubtodo = 0; 1113 pendingSubtodo = 0;
1107 mActiveItem = (KOTodoViewItem *)item; 1114 mActiveItem = (KOTodoViewItem *)item;
1108 if (item) { 1115 if (item) {
1109 switch (column){ 1116 switch (column){
1110 case 1: 1117 case 1:
1111 mPriorityPopupMenu->popup(QCursor::pos ()); break; 1118 mPriorityPopupMenu->popup(QCursor::pos ()); break;
1112 case 2: 1119 case 2:
1113 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break; 1120 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break;
1114 case 3: 1121 case 3:
1115 moveTodo(); 1122 moveTodo();
1116 break; 1123 break;
1117 case 8: 1124 case 7:
1118 mCategoryPopupMenu->popup(QCursor::pos ()); break; 1125 mCategoryPopupMenu->popup(QCursor::pos ()); break;
1119 case 9: 1126 case 8:
1120 mCalPopupMenu->popup(QCursor::pos ()); break; 1127 mCalPopupMenu->popup(QCursor::pos ()); break;
1121 default: 1128 default:
1122 mItemPopupMenu->popup(QCursor::pos()); 1129 mItemPopupMenu->popup(QCursor::pos());
1123 } 1130 }
1124 } else mPopupMenu->popup(QCursor::pos()); 1131 } else mPopupMenu->popup(QCursor::pos());
1125} 1132}
1126void KOTodoView::newTodo() 1133void KOTodoView::newTodo()
1127{ 1134{
1128 emit newTodoSignal(); 1135 emit newTodoSignal();
1129} 1136}
1130 1137
1131void KOTodoView::newSubTodo() 1138void KOTodoView::newSubTodo()
1132{ 1139{
1133 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1140 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1134 if (mActiveItem) { 1141 if (mActiveItem) {
1135 if ( mQuickAdd->isVisible() && !mQuickAdd->text().isEmpty() && mQuickAdd->text() != i18n("Click to add new Todo") ) { 1142 if ( mQuickAdd->isVisible() && !mQuickAdd->text().isEmpty() && mQuickAdd->text() != i18n("Click to add new Todo") ) {
1136 addQuickTodoPar( mActiveItem->todo()); 1143 addQuickTodoPar( mActiveItem->todo());
1137 } else 1144 } else
1138 emit newSubTodoSignal(mActiveItem->todo()); 1145 emit newSubTodoSignal(mActiveItem->todo());
1139 } 1146 }
1140} 1147}
1141void KOTodoView::unparentTodo() 1148void KOTodoView::unparentTodo()
1142{ 1149{
1143 if (mActiveItem) { 1150 if (mActiveItem) {
1144 emit unparentTodoSignal(mActiveItem->todo()); 1151 emit unparentTodoSignal(mActiveItem->todo());
1145 } 1152 }
1146} 1153}
1147 1154
1148void KOTodoView::reparentTodo() 1155void KOTodoView::reparentTodo()
1149{ 1156{
1150 if (mActiveItem) { 1157 if (mActiveItem) {
1151 topLevelWidget()->setCaption(i18n("Click on new parent item")); 1158 topLevelWidget()->setCaption(i18n("Click on new parent item"));
1152 pendingSubtodo = mActiveItem; 1159 pendingSubtodo = mActiveItem;
1153 } 1160 }
1154} 1161}
1155void KOTodoView::editTodo() 1162void KOTodoView::editTodo()
1156{ 1163{
1157 if (mActiveItem) { 1164 if (mActiveItem) {
1158 emit editTodoSignal(mActiveItem->todo()); 1165 emit editTodoSignal(mActiveItem->todo());
1159 } 1166 }
1160} 1167}
1161void KOTodoView::cloneTodo() 1168void KOTodoView::cloneTodo()
1162{ 1169{
1163 if (mActiveItem) { 1170 if (mActiveItem) {
1164 emit cloneTodoSignal((Incidence*)mActiveItem->todo()); 1171 emit cloneTodoSignal((Incidence*)mActiveItem->todo());
1165 } 1172 }
1166} 1173}
1167void KOTodoView::cancelTodo() 1174void KOTodoView::cancelTodo()
1168{ 1175{
1169 if (mActiveItem) { 1176 if (mActiveItem) {
1170 emit cancelTodoSignal((Incidence*)mActiveItem->todo()); 1177 emit cancelTodoSignal((Incidence*)mActiveItem->todo());
1171 } 1178 }
1172} 1179}
1173void KOTodoView::moveTodo() 1180void KOTodoView::moveTodo()
1174{ 1181{
1175 if (mActiveItem) { 1182 if (mActiveItem) {
1176 emit moveTodoSignal((Incidence*)mActiveItem->todo()); 1183 emit moveTodoSignal((Incidence*)mActiveItem->todo());
1177 } 1184 }
1178} 1185}
1179void KOTodoView::beamTodo() 1186void KOTodoView::beamTodo()
1180{ 1187{
1181 if (mActiveItem) { 1188 if (mActiveItem) {
1182 emit beamTodoSignal((Incidence*)mActiveItem->todo()); 1189 emit beamTodoSignal((Incidence*)mActiveItem->todo());
1183 } 1190 }
1184} 1191}
1185 1192
1186 1193
1187void KOTodoView::showTodo() 1194void KOTodoView::showTodo()
1188{ 1195{
1189 if (mActiveItem) { 1196 if (mActiveItem) {
1190 emit showTodoSignal(mActiveItem->todo()); 1197 emit showTodoSignal(mActiveItem->todo());
1191 } 1198 }
1192} 1199}
1193 1200
1194void KOTodoView::deleteTodo() 1201void KOTodoView::deleteTodo()
1195{ 1202{
1196 if (mActiveItem) { 1203 if (mActiveItem) {
1197 emit deleteTodoSignal(mActiveItem->todo()); 1204 emit deleteTodoSignal(mActiveItem->todo());
1198 } 1205 }
1199} 1206}
1200 1207
1201void KOTodoView::setNewPriority(int index) 1208void KOTodoView::setNewPriority(int index)
1202{ 1209{
1203 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 1210 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
1204 mActiveItem->todo()->setPriority(mPriority[index]); 1211 mActiveItem->todo()->setPriority(mPriority[index]);
1205 mActiveItem->construct(); 1212 mActiveItem->construct();
1206 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED); 1213 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED);
1207 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 1214 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
1208 } 1215 }
1209 processSelectionChange(); 1216 processSelectionChange();
1210} 1217}
1211 1218
1212void KOTodoView::setNewPercentage(int index) 1219void KOTodoView::setNewPercentage(int index)
1213{ 1220{
1214 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 1221 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
1215 1222
1216 if ( mPercentage[index] == 100 && !mActiveItem->isOn() ) { 1223 if ( mPercentage[index] == 100 && !mActiveItem->isOn() ) {
1217 mActiveItem->setOn( true ); 1224 mActiveItem->setOn( true );
1218 processSelectionChange(); 1225 processSelectionChange();
1219 return; 1226 return;
1220 } else if ( mPercentage[index] != 100 && mActiveItem->isOn() ) { 1227 } else if ( mPercentage[index] != 100 && mActiveItem->isOn() ) {
1221 KOTodoViewItem* par = (static_cast<KOTodoViewItem*>(mActiveItem->parent())); 1228 KOTodoViewItem* par = (static_cast<KOTodoViewItem*>(mActiveItem->parent()));
1222 if ( par && par->isOn() ) 1229 if ( par && par->isOn() )
1223 par->setOn( false ); 1230 par->setOn( false );
1224 } 1231 }
1225 if (mPercentage[index] == 100) { 1232 if (mPercentage[index] == 100) {
1226 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime()); 1233 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime());
1227 } else { 1234 } else {
1228 mActiveItem->todo()->setCompleted(false); 1235 mActiveItem->todo()->setCompleted(false);
1229 } 1236 }
1230 mActiveItem->todo()->setPercentComplete(mPercentage[index]); 1237 mActiveItem->todo()->setPercentComplete(mPercentage[index]);
1231 mActiveItem->construct(); 1238 mActiveItem->construct();
1232 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED); 1239 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED);
1233 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 1240 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
1234 } 1241 }
1235 processSelectionChange(); 1242 processSelectionChange();
1236} 1243}
1237 1244
1238void KOTodoView::fillCategories () 1245void KOTodoView::fillCategories ()
1239{ 1246{
1240 mCategoryPopupMenu->clear(); 1247 mCategoryPopupMenu->clear();
1241 if ( ! mActiveItem ) return; 1248 if ( ! mActiveItem ) return;
1242 QStringList checkedCategories = mActiveItem->todo()->categories (); 1249 QStringList checkedCategories = mActiveItem->todo()->categories ();
1243 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin (); 1250 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin ();
1244 it != KOPrefs::instance()->mCustomCategories.end (); 1251 it != KOPrefs::instance()->mCustomCategories.end ();
1245 ++it) { 1252 ++it) {
1246 int index = mCategoryPopupMenu->insertItem (*it); 1253 int index = mCategoryPopupMenu->insertItem (*it);
1247 mCategory[index] = *it; 1254 mCategory[index] = *it;
1248 if (checkedCategories.find (*it) != checkedCategories.end ()) mCategoryPopupMenu->setItemChecked (index, true); 1255 if (checkedCategories.find (*it) != checkedCategories.end ()) mCategoryPopupMenu->setItemChecked (index, true);
1249 } 1256 }
1250} 1257}
1251void KOTodoView::fillCal () 1258void KOTodoView::fillCal ()
1252{ 1259{
1253 mCalPopupMenu->clear(); 1260 mCalPopupMenu->clear();
1254 if (!mActiveItem) return; 1261 if (!mActiveItem) return;
1255 bool readO = mActiveItem->todo()->isReadOnly(); 1262 bool readO = mActiveItem->todo()->isReadOnly();
1256 KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first(); 1263 KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first();
1257 while ( kkf ) { 1264 while ( kkf ) {
1258 int index = mCalPopupMenu->insertItem( kkf->mName, kkf->mCalNumber); 1265 int index = mCalPopupMenu->insertItem( kkf->mName, kkf->mCalNumber);
1259 if ( kkf->mErrorOnLoad || kkf->isReadOnly || readO ) 1266 if ( kkf->mErrorOnLoad || kkf->isReadOnly || readO )
1260 mCalPopupMenu->setItemEnabled( index, false ); 1267 mCalPopupMenu->setItemEnabled( index, false );
1261 mCalPopupMenu->setItemChecked (index, kkf->mCalNumber == mActiveItem->todo()->calID()); 1268 mCalPopupMenu->setItemChecked (index, kkf->mCalNumber == mActiveItem->todo()->calID());
1262 kkf = KOPrefs::instance()->mCalendars.next(); 1269 kkf = KOPrefs::instance()->mCalendars.next();
1263 } 1270 }
1264} 1271}
1265void KOTodoView::changedCal (int index ) 1272void KOTodoView::changedCal (int index )
1266{ 1273{
1267 if (!mActiveItem) return; 1274 if (!mActiveItem) return;
1268 mActiveItem->todo()->setCalID( index ); 1275 mActiveItem->todo()->setCalID( index );
1269 mActiveItem->construct(); 1276 mActiveItem->construct();
1270} 1277}
1271void KOTodoView::changedCategories(int index) 1278void KOTodoView::changedCategories(int index)
1272{ 1279{
1273 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 1280 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
1274 QStringList categories = mActiveItem->todo()->categories (); 1281 QStringList categories = mActiveItem->todo()->categories ();
1275 QString colcat = categories.first(); 1282 QString colcat = categories.first();
1276 if (categories.find (mCategory[index]) != categories.end ()) 1283 if (categories.find (mCategory[index]) != categories.end ())
1277 categories.remove (mCategory[index]); 1284 categories.remove (mCategory[index]);
1278 else 1285 else
1279 categories.insert (categories.end(), mCategory[index]); 1286 categories.insert (categories.end(), mCategory[index]);
1280 categories.sort (); 1287 categories.sort ();
1281 if ( !colcat.isEmpty() ) { 1288 if ( !colcat.isEmpty() ) {
1282 if ( categories.find ( colcat ) != categories.end () ) { 1289 if ( categories.find ( colcat ) != categories.end () ) {
1283 categories.remove( colcat ); 1290 categories.remove( colcat );
1284 categories.prepend( colcat ); 1291 categories.prepend( colcat );
1285 } 1292 }
1286 } 1293 }
1287 mActiveItem->todo()->setCategories (categories); 1294 mActiveItem->todo()->setCategories (categories);
1288 mActiveItem->construct(); 1295 mActiveItem->construct();
1289 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 1296 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
1290 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED); 1297 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED);
1291 } 1298 }
1292} 1299}
1293void KOTodoView::itemDoubleClicked(QListViewItem *item) 1300void KOTodoView::itemDoubleClicked(QListViewItem *item)
1294{ 1301{
1295 if ( pendingSubtodo != 0 ) { 1302 if ( pendingSubtodo != 0 ) {
1296 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 1303 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
1297 } 1304 }
1298 pendingSubtodo = 0; 1305 pendingSubtodo = 0;
1299 //int row = mTodoListView->header()->sectionAt ( mTodoListView->header()->mapFromGlobal( QCursor::pos()).x() ); 1306 //int row = mTodoListView->header()->sectionAt ( mTodoListView->header()->mapFromGlobal( QCursor::pos()).x() );
1300 int row = mTodoListView->header()->sectionAt ( mTodoListView->viewportToContents(mTodoListView->viewport()->mapFromGlobal( QCursor::pos())) .x() ); 1307 int row = mTodoListView->header()->sectionAt ( mTodoListView->viewportToContents(mTodoListView->viewport()->mapFromGlobal( QCursor::pos())) .x() );
1301 //qDebug("ROW %d ", row); 1308 //qDebug("ROW %d ", row);
1302 if (!item) { 1309 if (!item) {
1303 newTodo(); 1310 newTodo();
1304 return; 1311 return;
1305 } else { 1312 } else {
1306 if ( row == 1 ) { 1313 if ( row == 1 ) {
1307 mActiveItem = (KOTodoViewItem *) item; 1314 mActiveItem = (KOTodoViewItem *) item;
1308 newSubTodo(); 1315 newSubTodo();
1309 return; 1316 return;
1310 } 1317 }
1311 if ( row == 5 || row == 6 || row == 2) { 1318 if ( row == 5 || row == 6 || row == 2) {
1312 mActiveItem = (KOTodoViewItem *) item; 1319 mActiveItem = (KOTodoViewItem *) item;
1313 Todo * t = mActiveItem->todo(); 1320 Todo * t = mActiveItem->todo();
1314 if ( t->isRunning() ) { 1321 if ( t->isRunning() ) {
1315 if ( t->runTime() < 15) { 1322 if ( t->runTime() < 15) {
1316 t->stopRunning(); 1323 t->stopRunning();
1317 mActiveItem->construct(); 1324 mActiveItem->construct();
1318 topLevelWidget()->setCaption(i18n("Todo stopped - no data saved because runtime was < 15 sec!")); 1325 topLevelWidget()->setCaption(i18n("Todo stopped - no data saved because runtime was < 15 sec!"));
1319 return; 1326 return;
1320 } 1327 }
1321 else 1328 else
1322 toggleRunningItem(); 1329 toggleRunningItem();
1323 return; 1330 return;
1324 } else { 1331 } else {
1325 t->setRunning( true ); 1332 t->setRunning( true );
1326 mActiveItem->construct(); 1333 mActiveItem->construct();
1327 topLevelWidget()->setCaption(i18n("Todo started! Double click again to stop!")); 1334 topLevelWidget()->setCaption(i18n("Todo started! Double click again to stop!"));
1328 return; 1335 return;
1329 } 1336 }
1330 } 1337 }
1331 } 1338 }
1332 if ( KOPrefs::instance()->mEditOnDoubleClick ) 1339 if ( KOPrefs::instance()->mEditOnDoubleClick )
1333 editItem( item ); 1340 editItem( item );
1334 else 1341 else
1335 showItem( item , QPoint(), 0 ); 1342 showItem( item , QPoint(), 0 );
1336} 1343}
1337void KOTodoView::toggleRunningItem() 1344void KOTodoView::toggleRunningItem()
1338{ 1345{
1339 // qDebug("KOTodoView::toggleRunning() "); 1346 // qDebug("KOTodoView::toggleRunning() ");
1340 if ( ! mActiveItem ) 1347 if ( ! mActiveItem )
1341 return; 1348 return;
1342 Todo * t = mActiveItem->todo(); 1349 Todo * t = mActiveItem->todo();
1343 if ( t->isRunning() ) { 1350 if ( t->isRunning() ) {
1344 KOStopTodoPrefs tp ( t, this ); 1351 KOStopTodoPrefs tp ( t, this );
1345 if (QApplication::desktop()->width() <= 800 ){ 1352 if (QApplication::desktop()->width() <= 800 ){
1346 int wid = tp.width(); 1353 int wid = tp.width();
1347 int hei = tp.height(); 1354 int hei = tp.height();
1348 int xx = (QApplication::desktop()->width()-wid)/2; 1355 int xx = (QApplication::desktop()->width()-wid)/2;
1349 int yy = (QApplication::desktop()->height()-hei)/2; 1356 int yy = (QApplication::desktop()->height()-hei)/2;
1350 tp.setGeometry( xx,yy,wid,hei ); 1357 tp.setGeometry( xx,yy,wid,hei );
1351 } 1358 }
1352 tp.exec(); 1359 tp.exec();
1353 mActiveItem->construct(); 1360 mActiveItem->construct();
1354 } else { 1361 } else {
1355 KOStartTodoPrefs tp ( t->summary(), this ); 1362 KOStartTodoPrefs tp ( t->summary(), this );
1356 if (QApplication::desktop()->width() <= 800 ){ 1363 if (QApplication::desktop()->width() <= 800 ){
1357 int wid = tp.width(); 1364 int wid = tp.width();
1358 int hei = tp.height(); 1365 int hei = tp.height();
1359 int xx = (QApplication::desktop()->width()-wid)/2; 1366 int xx = (QApplication::desktop()->width()-wid)/2;
1360 int yy = (QApplication::desktop()->height()-hei)/2; 1367 int yy = (QApplication::desktop()->height()-hei)/2;
1361 tp.setGeometry( xx,yy,wid,hei ); 1368 tp.setGeometry( xx,yy,wid,hei );
1362 } 1369 }
1363 if ( !tp.exec() ) return; 1370 if ( !tp.exec() ) return;
1364 if ( tp.stopAll() ) { 1371 if ( tp.stopAll() ) {
1365 mCalendar->stopAllTodos(); 1372 mCalendar->stopAllTodos();
1366 t->setRunning( true ); 1373 t->setRunning( true );
1367 updateView(); 1374 updateView();
1368 } else { 1375 } else {
1369 t->setRunning( true ); 1376 t->setRunning( true );
1370 mActiveItem->construct(); 1377 mActiveItem->construct();
1371 } 1378 }
1372 } 1379 }
1373} 1380}
1374 1381
1375void KOTodoView::itemClicked(QListViewItem *item) 1382void KOTodoView::itemClicked(QListViewItem *item)
1376{ 1383{
1377 //qDebug("KOTodoView::itemClicked %d", item); 1384 //qDebug("KOTodoView::itemClicked %d", item);
1378 if (!item) { 1385 if (!item) {
1379 if ( pendingSubtodo != 0 ) { 1386 if ( pendingSubtodo != 0 ) {
1380 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 1387 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
1381 } 1388 }
1382 pendingSubtodo = 0; 1389 pendingSubtodo = 0;
1383 return; 1390 return;
1384 } 1391 }
1385 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 1392 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
1386 if ( pendingSubtodo != 0 ) { 1393 if ( pendingSubtodo != 0 ) {
1387 bool allowReparent = true; 1394 bool allowReparent = true;
1388 QListViewItem *par = item; 1395 QListViewItem *par = item;
1389 while ( par ) { 1396 while ( par ) {
1390 if ( par == pendingSubtodo ) { 1397 if ( par == pendingSubtodo ) {
1391 allowReparent = false; 1398 allowReparent = false;
1392 break; 1399 break;
1393 } 1400 }
1394 par = par->parent(); 1401 par = par->parent();
1395 } 1402 }
1396 if ( !allowReparent ) { 1403 if ( !allowReparent ) {
1397 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!")); 1404 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!"));
1398 pendingSubtodo = 0; 1405 pendingSubtodo = 0;
1399 } else { 1406 } else {
1400 Todo* newParent = todoItem->todo(); 1407 Todo* newParent = todoItem->todo();
1401 Todo* newSub = pendingSubtodo->todo(); 1408 Todo* newSub = pendingSubtodo->todo();
1402 pendingSubtodo = 0; 1409 pendingSubtodo = 0;
1403 emit reparentTodoSignal( newParent,newSub ); 1410 emit reparentTodoSignal( newParent,newSub );
1404 return; 1411 return;
1405 } 1412 }
1406 } 1413 }
1407 1414
1408} 1415}
1409 1416
1410void KOTodoView::setDocumentId( const QString &id ) 1417void KOTodoView::setDocumentId( const QString &id )
1411{ 1418{
1412 1419
1413 mDocPrefs->setDoc( id ); 1420 mDocPrefs->setDoc( id );
1414} 1421}
1415 1422
1416void KOTodoView::itemStateChanged( QListViewItem *item ) 1423void KOTodoView::itemStateChanged( QListViewItem *item )
1417{ 1424{
1418 if (!item) return; 1425 if (!item) return;
1419 1426
1420 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 1427 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
1421 1428
1422// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl; 1429// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl;
1423 1430
1424 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() ); 1431 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() );
1425} 1432}
1426 1433
1427void KOTodoView::saveLayout(KConfig *config, const QString &group) const 1434void KOTodoView::saveLayout(KConfig *config, const QString &group) const
1428{ 1435{
1429 mTodoListView->saveLayout(config,group); 1436 mTodoListView->saveLayout(config,group);
1430} 1437}
1431 1438
1432void KOTodoView::restoreLayout(KConfig *config, const QString &group) 1439void KOTodoView::restoreLayout(KConfig *config, const QString &group)
1433{ 1440{
1434 mTodoListView->restoreLayout(config,group); 1441 mTodoListView->restoreLayout(config,group);
1435} 1442}
1436 1443
1437void KOTodoView::processSelectionChange() 1444void KOTodoView::processSelectionChange()
1438{ 1445{
1439// kdDebug() << "KOTodoView::processSelectionChange()" << endl; 1446// kdDebug() << "KOTodoView::processSelectionChange()" << endl;
1440 1447
1441 KOTodoViewItem *item = 1448 KOTodoViewItem *item =
1442 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() ); 1449 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() );
1443 1450
1444 if ( !item ) { 1451 if ( !item ) {
1445 emit incidenceSelected( 0 ); 1452 emit incidenceSelected( 0 );
1446 mNewSubBut->setEnabled( false ); 1453 mNewSubBut->setEnabled( false );
1447 } else { 1454 } else {
1448 emit incidenceSelected( item->todo() ); 1455 emit incidenceSelected( item->todo() );
1449 mNewSubBut->setEnabled( true ); 1456 mNewSubBut->setEnabled( true );
1450 } 1457 }
1451} 1458}
1452 1459
1453void KOTodoView::modified(bool b) 1460void KOTodoView::modified(bool b)
1454{ 1461{
1455 emit isModified(b); 1462 emit isModified(b);
1456} 1463}
1457void KOTodoView::setTodoModified( Todo* todo ) 1464void KOTodoView::setTodoModified( Todo* todo )
1458{ 1465{
1459 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED ); 1466 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED );
1460} 1467}
1461void KOTodoView::clearSelection() 1468void KOTodoView::clearSelection()
1462{ 1469{
1463 mTodoListView->selectAll( false ); 1470 mTodoListView->selectAll( false );
1464} 1471}
1465void KOTodoView::setAllOpen() 1472void KOTodoView::setAllOpen()
1466{ 1473{
1467 if ( isFlatDisplay ) { 1474 if ( isFlatDisplay ) {
1468 isFlatDisplay = false; 1475 isFlatDisplay = false;
1469 mPopupMenu->setItemChecked( 8,false ); 1476 mPopupMenu->setItemChecked( 8,false );
1470 updateView(); 1477 updateView();
1471 } else { 1478 } else {
1472 storeCurrentItem(); 1479 storeCurrentItem();
1473 } 1480 }
1474 setOpen(mTodoListView->firstChild(), true); 1481 setOpen(mTodoListView->firstChild(), true);
1475 resetCurrentItem(); 1482 resetCurrentItem();
1476} 1483}
1477void KOTodoView::setAllClose() 1484void KOTodoView::setAllClose()
1478{ 1485{
1479 if ( isFlatDisplay ) { 1486 if ( isFlatDisplay ) {
1480 isFlatDisplay = false; 1487 isFlatDisplay = false;
1481 mPopupMenu->setItemChecked( 8,false ); 1488 mPopupMenu->setItemChecked( 8,false );
1482 updateView(); 1489 updateView();
1483 } else { 1490 } else {
1484 storeCurrentItem(); 1491 storeCurrentItem();
1485 } 1492 }
1486 setOpen(mTodoListView->firstChild(), false); 1493 setOpen(mTodoListView->firstChild(), false);
1487 resetCurrentItem(); 1494 resetCurrentItem();
1488} 1495}
1489void KOTodoView::setOpen( QListViewItem* item, bool setOpenI) 1496void KOTodoView::setOpen( QListViewItem* item, bool setOpenI)
1490{ 1497{
1491 1498
1492 while ( item ) { 1499 while ( item ) {
1493 setOpen( item->firstChild(), setOpenI ); 1500 setOpen( item->firstChild(), setOpenI );
1494 item->setOpen( setOpenI ); 1501 item->setOpen( setOpenI );
1495 item = item->nextSibling(); 1502 item = item->nextSibling();
1496 } 1503 }
1497} 1504}
1498 1505
1499void KOTodoView::displayAllFlat() 1506void KOTodoView::displayAllFlat()
1500{ 1507{
1501 storeCurrentItem(); 1508 storeCurrentItem();
1502 pendingSubtodo = 0; 1509 pendingSubtodo = 0;
1503 if ( mBlockUpdate ) { 1510 if ( mBlockUpdate ) {
1504 return; 1511 return;
1505 } 1512 }
1506 mPopupMenu->setItemChecked( 8,true ); 1513 mPopupMenu->setItemChecked( 8,true );
1507 isFlatDisplay = true; 1514 isFlatDisplay = true;
1508 QPtrList<Todo> todoList = calendar()->todos(); 1515 QPtrList<Todo> todoList = calendar()->todos();
1509 mTodoMap.clear(); 1516 mTodoMap.clear();
1510 mTodoListView->clear(); 1517 mTodoListView->clear();
1511 Todo *todo; 1518 Todo *todo;
1512 for(todo = todoList.first(); todo; todo = todoList.next()) { 1519 for(todo = todoList.first(); todo; todo = todoList.next()) {
1513 if ( checkTodo( todo ) ) { 1520 if ( checkTodo( todo ) ) {
1514 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 1521 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
1515 mTodoMap.insert(todo,todoItem); 1522 mTodoMap.insert(todo,todoItem);
1516 } 1523 }
1517 } 1524 }
1518 resetCurrentItem(); 1525 resetCurrentItem();
1519} 1526}
1520 1527
1521void KOTodoView::setAllFlat() 1528void KOTodoView::setAllFlat()
1522{ 1529{
1523 if ( isFlatDisplay ) { 1530 if ( isFlatDisplay ) {
1524 isFlatDisplay = false; 1531 isFlatDisplay = false;
1525 mPopupMenu->setItemChecked( 8,false ); 1532 mPopupMenu->setItemChecked( 8,false );
1526 updateView(); 1533 updateView();
1527 return; 1534 return;
1528 } 1535 }
1529 displayAllFlat(); 1536 displayAllFlat();
1530} 1537}
1531 1538
1532void KOTodoView::purgeCompleted() 1539void KOTodoView::purgeCompleted()
1533{ 1540{
1534 emit purgeCompletedSignal(); 1541 emit purgeCompletedSignal();
1535 1542
1536} 1543}
1537void KOTodoView::toggleQuickTodo() 1544void KOTodoView::toggleQuickTodo()
1538{ 1545{
1539 if ( mQuickBar->isVisible() ) { 1546 if ( mQuickBar->isVisible() ) {
1540 mQuickBar->hide(); 1547 mQuickBar->hide();
1541 KOPrefs::instance()->mEnableQuickTodo = false; 1548 KOPrefs::instance()->mEnableQuickTodo = false;
1542 } 1549 }
1543 else { 1550 else {
1544 mQuickBar->show(); 1551 mQuickBar->show();
1545 KOPrefs::instance()->mEnableQuickTodo = true; 1552 KOPrefs::instance()->mEnableQuickTodo = true;
1546 } 1553 }
1547 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); 1554 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo);
1548 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); 1555 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo );
1549} 1556}
1550 1557
1551void KOTodoView::toggleRunning() 1558void KOTodoView::toggleRunning()
1552{ 1559{
1553 KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos; 1560 KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos;
1554 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); 1561 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos);
1555 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); 1562 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos );
1556 updateView(); 1563 updateView();
1557 if ( KOPrefs::instance()->mHideNonStartedTodos ) 1564 if ( KOPrefs::instance()->mHideNonStartedTodos )
1558 topLevelWidget()->setCaption(i18n("Hide not Running")); 1565 topLevelWidget()->setCaption(i18n("Hide not Running"));
1559 else 1566 else
1560 topLevelWidget()->setCaption(i18n("Show not Running")); 1567 topLevelWidget()->setCaption(i18n("Show not Running"));
1561} 1568}
1562 1569
1563void KOTodoView::toggleCompleted() 1570void KOTodoView::toggleCompleted()
1564{ 1571{
1565 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo; 1572 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo;
1566 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); 1573 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo );
1567 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); 1574 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo );
1568 updateView(); 1575 updateView();
1569 if ( KOPrefs::instance()->mShowCompletedTodo ) 1576 if ( KOPrefs::instance()->mShowCompletedTodo )
1570 topLevelWidget()->setCaption(i18n("Show Completed")); 1577 topLevelWidget()->setCaption(i18n("Show Completed"));
1571 else 1578 else
1572 topLevelWidget()->setCaption(i18n("Hide Completed")); 1579 topLevelWidget()->setCaption(i18n("Hide Completed"));
1573} 1580}
1574 1581
1575void KOTodoView::addQuickTodo() 1582void KOTodoView::addQuickTodo()
1576{ 1583{
1577 addQuickTodoPar( 0 ); 1584 addQuickTodoPar( 0 );
1578} 1585}
1579void KOTodoView::addQuickTodoPar( Todo * parentTodo) 1586void KOTodoView::addQuickTodoPar( Todo * parentTodo)
1580{ 1587{
1581 Todo *todo = new Todo(); 1588 Todo *todo = new Todo();
1582 todo->setSummary(mQuickAdd->text()); 1589 todo->setSummary(mQuickAdd->text());
1583 todo->setOrganizer(KOPrefs::instance()->email()); 1590 todo->setOrganizer(KOPrefs::instance()->email());
1584 if ( parentTodo ) { 1591 if ( parentTodo ) {
1585 todo->setRelatedTo(parentTodo); 1592 todo->setRelatedTo(parentTodo);
1586 1593
1587 todo->setCategories (parentTodo->categoriesStr ()); 1594 todo->setCategories (parentTodo->categoriesStr ());
1588 todo->setSecrecy (parentTodo->secrecy ()); 1595 todo->setSecrecy (parentTodo->secrecy ());
1589 if ( parentTodo->priority() < 3 ) 1596 if ( parentTodo->priority() < 3 )
1590 todo->setPriority( parentTodo->priority() ); 1597 todo->setPriority( parentTodo->priority() );
1591 todo->setCalID( parentTodo->calID() ); 1598 todo->setCalID( parentTodo->calID() );
1592 } else { 1599 } else {
1593 CalFilter * cf = mCalendar->filter(); 1600 CalFilter * cf = mCalendar->filter();
1594 if ( cf ) { 1601 if ( cf ) {
1595 if ( cf->isEnabled()&& cf->showCategories()) { 1602 if ( cf->isEnabled()&& cf->showCategories()) {
1596 todo->setCategories(cf->categoryList()); 1603 todo->setCategories(cf->categoryList());
1597 } 1604 }
1598 if ( cf->isEnabled() ) 1605 if ( cf->isEnabled() )
1599 todo->setSecrecy( cf->getSecrecy()); 1606 todo->setSecrecy( cf->getSecrecy());
1600 } 1607 }
1601 } 1608 }
1602 mCalendar->addTodo(todo); 1609 mCalendar->addTodo(todo);
1603 mQuickAdd->setText(""); 1610 mQuickAdd->setText("");
1604 todoModified (todo, KOGlobals::EVENTADDED ); 1611 todoModified (todo, KOGlobals::EVENTADDED );
1605 updateView(); 1612 updateView();
1606 1613
1607} 1614}
1608void KOTodoView::keyPressEvent ( QKeyEvent * e ) 1615void KOTodoView::keyPressEvent ( QKeyEvent * e )
1609{ 1616{
1610 // e->ignore(); 1617 // e->ignore();
1611 //return; 1618 //return;
1612 if ( !isVisible() ) { 1619 if ( !isVisible() ) {
1613 e->ignore(); 1620 e->ignore();
1614 return; 1621 return;
1615 } 1622 }
1616 switch ( e->key() ) { 1623 switch ( e->key() ) {
1617 case Qt::Key_Down: 1624 case Qt::Key_Down:
1618 case Qt::Key_Up: 1625 case Qt::Key_Up:
1619 // KOrg::BaseView::keyPressEvent ( e ); 1626 // KOrg::BaseView::keyPressEvent ( e );
1620 e->ignore(); 1627 e->ignore();
1621 break; 1628 break;
1622 1629
1623 case Qt::Key_Q: 1630 case Qt::Key_Q:
1624 1631
1625 1632
1626 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton ) { 1633 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton ) {
1627 e->ignore(); 1634 e->ignore();
1628 break; 1635 break;
1629 } 1636 }
1630 toggleQuickTodo(); 1637 toggleQuickTodo();
1631 break; 1638 break;
1632 case Qt::Key_U: 1639 case Qt::Key_U:
1633 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1640 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1634 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1641 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1635 unparentTodo(); 1642 unparentTodo();
1636 e->accept(); 1643 e->accept();
1637 } else 1644 } else
1638 e->ignore(); 1645 e->ignore();
1639 break; 1646 break;
1640 case Qt::Key_S: 1647 case Qt::Key_S:
1641 if ( e->state() == Qt::ControlButton ) { 1648 if ( e->state() == Qt::ControlButton ) {
1642 e->ignore(); 1649 e->ignore();
1643 break; 1650 break;
1644 } 1651 }
1645 if ( e->state() == Qt::ShiftButton ) { 1652 if ( e->state() == Qt::ShiftButton ) {
1646 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1653 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1647 reparentTodo(); 1654 reparentTodo();
1648 e->accept(); 1655 e->accept();
1649 } else 1656 } else
1650 e->ignore(); 1657 e->ignore();
1651 break; 1658 break;
1652 case Qt::Key_P: 1659 case Qt::Key_P:
1653 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1660 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1654 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1661 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1655 if ( pendingSubtodo ) 1662 if ( pendingSubtodo )
1656 itemClicked(mActiveItem); 1663 itemClicked(mActiveItem);
1657 e->accept(); 1664 e->accept();
1658 } else 1665 } else
1659 e->ignore(); 1666 e->ignore();
1660 break; 1667 break;
1661 case Qt::Key_Escape: 1668 case Qt::Key_Escape:
1662 if ( pendingSubtodo ) { 1669 if ( pendingSubtodo ) {
1663 itemClicked(0); 1670 itemClicked(0);
1664 e->accept(); 1671 e->accept();
1665 } else 1672 } else
1666 e->ignore(); 1673 e->ignore();
1667 break; 1674 break;
1668 default: 1675 default:
1669 e->ignore(); 1676 e->ignore();
1670 } 1677 }
1671 1678
1672 if ( true ) { 1679 if ( true ) {
1673 if ( e->key() == Qt::Key_I ) { 1680 if ( e->key() == Qt::Key_I ) {
1674 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem(); 1681 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem();
1675 if ( cn ) { 1682 if ( cn ) {
1676 mActiveItem = cn; 1683 mActiveItem = cn;
1677 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 1684 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
1678 if ( ci ){ 1685 if ( ci ){
1679 showTodo(); 1686 showTodo();
1680 cn = (KOTodoViewItem*)cn->itemBelow(); 1687 cn = (KOTodoViewItem*)cn->itemBelow();
1681 if ( cn ) { 1688 if ( cn ) {
1682 mTodoListView->setCurrentItem ( cn ); 1689 mTodoListView->setCurrentItem ( cn );
1683 mTodoListView->ensureItemVisible ( cn ); 1690 mTodoListView->ensureItemVisible ( cn );
1684 } 1691 }
1685 1692
1686 } 1693 }
1687 } 1694 }
1688 e->accept(); 1695 e->accept();
1689 1696
1690 } 1697 }
1691 1698
1692 } 1699 }
1693 1700
1694} 1701}
1695void KOTodoView::updateTodo( Todo * t, int type ) 1702void KOTodoView::updateTodo( Todo * t, int type )
1696{ 1703{
1697 if ( mBlockUpdate) 1704 if ( mBlockUpdate)
1698 return; 1705 return;
1699 1706
1700 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 1707 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
1701 itemIterator = mTodoMap.find(t); 1708 itemIterator = mTodoMap.find(t);
1702 if (itemIterator != mTodoMap.end()) { 1709 if (itemIterator != mTodoMap.end()) {
1703 (*itemIterator)->construct(); 1710 (*itemIterator)->construct();
1704 } else { 1711 } else {
1705 if ( type == KOGlobals::EVENTADDED ) { 1712 if ( type == KOGlobals::EVENTADDED ) {
1706 insertTodoItem( t ); 1713 insertTodoItem( t );
1707 } 1714 }
1708 } 1715 }
1709 1716
1710} 1717}
1711 1718
1712void KOTodoView::todoModified(Todo * t , int p ) 1719void KOTodoView::todoModified(Todo * t , int p )
1713{ 1720{
1714 mBlockUpdate = true; 1721 mBlockUpdate = true;
1715 emit todoModifiedSignal ( t, p ); 1722 emit todoModifiedSignal ( t, p );
1716 mBlockUpdate = false; 1723 mBlockUpdate = false;
1717} 1724}