summaryrefslogtreecommitdiffabout
path: root/korganizer
Unidiff
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp2
-rw-r--r--korganizer/koagenda.cpp4
-rw-r--r--korganizer/koagendaitem.cpp2
-rw-r--r--korganizer/koagendaview.cpp2
-rw-r--r--korganizer/kodaymatrix.cpp2
-rw-r--r--korganizer/koeditorrecurrence.cpp172
-rw-r--r--korganizer/koeventviewer.cpp6
-rw-r--r--korganizer/kolistview.cpp4
-rw-r--r--korganizer/komonthview.cpp6
-rw-r--r--korganizer/kotodoeditor.cpp3
-rw-r--r--korganizer/kowhatsnextview.cpp4
11 files changed, 108 insertions, 99 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index a76f2ed..a9d42f0 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,4855 +1,4855 @@
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 mConflictingEvent = 0; 373 mConflictingEvent = 0;
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}
658 658
659 659
660void CalendarView::nextConflict( bool all, bool allday ) 660void CalendarView::nextConflict( bool all, bool allday )
661{ 661{
662 static bool block = false; 662 static bool block = false;
663 if ( block ) return; 663 if ( block ) return;
664 block = true; 664 block = true;
665 QPtrList<Event> testlist = mCalendar->events(); 665 QPtrList<Event> testlist = mCalendar->events();
666 Event * test = testlist.first(); 666 Event * test = testlist.first();
667 while ( test ) { 667 while ( test ) {
668 test->setTagged( false ); 668 test->setTagged( false );
669 test = testlist.next(); 669 test = testlist.next();
670 } 670 }
671 QTime st ( 0,0,0); 671 QTime st ( 0,0,0);
672 if ( mViewManager->currentView() == mViewManager->agendaView() ) 672 if ( mViewManager->currentView() == mViewManager->agendaView() )
673 st = mViewManager->agendaView()->agenda()->getEndTime(); 673 st = mViewManager->agendaView()->agenda()->getEndTime();
674 //qDebug("time %s ", st.toString().latin1()); 674 //qDebug("time %s ", st.toString().latin1());
675 QDateTime startDT = QDateTime (mNavigator->selectedDates().first(),st); 675 QDateTime startDT = QDateTime (mNavigator->selectedDates().first(),st);
676 QDateTime conflict; 676 QDateTime conflict;
677 QDateTime retVal; 677 QDateTime retVal;
678 bool found = false; 678 bool found = false;
679 Event * cE = 0; 679 Event * cE = 0;
680 Event * cE2 = 0; 680 Event * cE2 = 0;
681 QPtrList<Event> testlist2 = testlist; 681 QPtrList<Event> testlist2 = testlist;
682 test = testlist.first(); 682 test = testlist.first();
683 bool skip = false; 683 bool skip = false;
684 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); 684 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") );
685 //QTime tm; 685 //QTime tm;
686 //tm.start(); 686 //tm.start();
687 while ( test ) { 687 while ( test ) {
688 qApp->processEvents(); 688 qApp->processEvents();
689 skip = false; 689 skip = false;
690 if ( !all ) skip = ( allday != test->doesFloat() ); 690 if ( !all ) skip = ( allday != test->doesFloat() );
691 if ( !skip ) { 691 if ( !skip ) {
692 if ( found ) 692 if ( found )
693 skip = !test->matchTime( &startDT, &conflict ); 693 skip = !test->matchTime( &startDT, &conflict );
694 else 694 else
695 skip = !test->matchTime( &startDT, 0 ); 695 skip = !test->matchTime( &startDT, 0 );
696 } 696 }
697 if ( !skip ) { 697 if ( !skip ) {
698 Event * test2 = testlist2.first(); 698 Event * test2 = testlist2.first();
699 while ( test2 ) { 699 while ( test2 ) {
700 skip = test2->isTagged(); 700 skip = test2->isTagged();
701 if ( !skip && !all ) skip = ( allday != test2->doesFloat() ); 701 if ( !skip && !all ) skip = ( allday != test2->doesFloat() );
702 if ( !skip ) { 702 if ( !skip ) {
703 if ( found ) 703 if ( found )
704 skip = !test2->matchTime( &startDT, &conflict ); 704 skip = !test2->matchTime( &startDT, &conflict );
705 else 705 else
706 skip = !test2->matchTime( &startDT, 0 ); 706 skip = !test2->matchTime( &startDT, 0 );
707 } 707 }
708 if ( !skip ) { 708 if ( !skip ) {
709 if ( test->isOverlapping ( test2, &retVal, &startDT ) ) { 709 if ( test->isOverlapping ( test2, &retVal, &startDT ) ) {
710 //qDebug("overlap "); 710 //qDebug("overlap ");
711 if ( ! found ) { 711 if ( ! found ) {
712 if ( retVal >= startDT ) { 712 if ( retVal >= startDT ) {
713 conflict = retVal; 713 conflict = retVal;
714 cE = test; 714 cE = test;
715 cE2 = test2; 715 cE2 = test2;
716 found = true; 716 found = true;
717 } 717 }
718 } else { 718 } else {
719 if ( retVal >= startDT && retVal < conflict ) { 719 if ( retVal >= startDT && retVal < conflict ) {
720 conflict = retVal; 720 conflict = retVal;
721 cE = test; 721 cE = test;
722 cE2 = test2; 722 cE2 = test2;
723 } 723 }
724 } 724 }
725 } 725 }
726 } 726 }
727 test2 = testlist2.next(); 727 test2 = testlist2.next();
728 } 728 }
729 } 729 }
730 test->setTagged( true ); 730 test->setTagged( true );
731 test = testlist.next(); 731 test = testlist.next();
732 } 732 }
733 //qDebug("Search time : %d", tm.elapsed()); 733 //qDebug("Search time : %d", tm.elapsed());
734 if ( found ) { 734 if ( found ) {
735 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) 735 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 )
736 mViewManager->showDayView(); 736 mViewManager->showDayView();
737 mNavigator->slotDaySelect( conflict.date() ); 737 mNavigator->slotDaySelect( conflict.date() );
738 int hour = conflict.time().hour(); 738 int hour = conflict.time().hour();
739 mViewManager->agendaView()->setStartHour( hour ); 739 mViewManager->agendaView()->setStartHour( hour );
740 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( cE->summary().left( 20 ) ).arg( cE2->summary().left( 20 ) ) ); 740 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( cE->summary().left( 20 ) ).arg( cE2->summary().left( 20 ) ) );
741 block = false; 741 block = false;
742 return; 742 return;
743 } 743 }
744 744
745 topLevelWidget()->setCaption( i18n("No conflict found") ); 745 topLevelWidget()->setCaption( i18n("No conflict found") );
746 //qDebug("No conflict found "); 746 //qDebug("No conflict found ");
747 block = false; 747 block = false;
748 return; 748 return;
749} 749}
750 750
751void CalendarView::conflictAll() 751void CalendarView::conflictAll()
752{ 752{
753 nextConflict ( true, true ); 753 nextConflict ( true, true );
754} 754}
755void CalendarView::conflictAllday() 755void CalendarView::conflictAllday()
756{ 756{
757 nextConflict ( false, true ); 757 nextConflict ( false, true );
758} 758}
759void CalendarView::conflictNotAll() 759void CalendarView::conflictNotAll()
760{ 760{
761 nextConflict ( false, false ); 761 nextConflict ( false, false );
762} 762}
763 763
764void CalendarView::setCalReadOnly( int id, bool readO ) 764void CalendarView::setCalReadOnly( int id, bool readO )
765{ 765{
766 if ( readO ) { 766 if ( readO ) {
767 emit save(); 767 emit save();
768 } 768 }
769 mCalendar->setReadOnly( id, readO ); 769 mCalendar->setReadOnly( id, readO );
770} 770}
771void CalendarView::setScrollBarStep(int val ) 771void CalendarView::setScrollBarStep(int val )
772{ 772{
773#ifdef DESKTOP_VERSION 773#ifdef DESKTOP_VERSION
774 mDateScrollBar->setLineStep ( val ); 774 mDateScrollBar->setLineStep ( val );
775#endif 775#endif
776} 776}
777void CalendarView::scrollBarValue(int val ) 777void CalendarView::scrollBarValue(int val )
778{ 778{
779#ifdef DESKTOP_VERSION 779#ifdef DESKTOP_VERSION
780 if ( QApplication::desktop()->width() < 800 ) return; 780 if ( QApplication::desktop()->width() < 800 ) return;
781 static bool block = false; 781 static bool block = false;
782 if ( block ) return; 782 if ( block ) return;
783 block = true; 783 block = true;
784 int count = mNavigator->selectedDates().count(); 784 int count = mNavigator->selectedDates().count();
785 int day = mNavigator->selectedDates().first().dayOfYear(); 785 int day = mNavigator->selectedDates().first().dayOfYear();
786 int stepdays = val; 786 int stepdays = val;
787 if ( mDateScrollBar->lineStep () <= count ) { 787 if ( mDateScrollBar->lineStep () <= count ) {
788 //val = val/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); 788 //val = val/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep();
789 //qDebug("VAL %d ",val ); 789 //qDebug("VAL %d ",val );
790 stepdays = (val-day)/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); 790 stepdays = (val-day)/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep();
791 stepdays = day+stepdays; 791 stepdays = day+stepdays;
792 if ( stepdays < 0 ) stepdays = 0; 792 if ( stepdays < 0 ) stepdays = 0;
793 } 793 }
794 if ( stepdays == day ) { 794 if ( stepdays == day ) {
795 block = false; 795 block = false;
796 return; 796 return;
797 } 797 }
798 int year = mNavigator->selectedDates().first().year(); 798 int year = mNavigator->selectedDates().first().year();
799 QDate d ( year,1,1 ); 799 QDate d ( year,1,1 );
800 mNavigator->selectDates( d.addDays( stepdays-1) , count ); 800 mNavigator->selectDates( d.addDays( stepdays-1) , count );
801 block = false; 801 block = false;
802#endif 802#endif
803 803
804} 804}
805void CalendarView::updateView(const QDate &start, const QDate &end) 805void CalendarView::updateView(const QDate &start, const QDate &end)
806{ 806{
807#ifdef DESKTOP_VERSION 807#ifdef DESKTOP_VERSION
808 if ( ! mDateScrollBar->draggingSlider () ) { 808 if ( ! mDateScrollBar->draggingSlider () ) {
809 int dof = start.dayOfYear(); 809 int dof = start.dayOfYear();
810 //qDebug("dof %d day %d val %d ", dof, start.dayOfYear(),mDateScrollBar->value() ); 810 //qDebug("dof %d day %d val %d ", dof, start.dayOfYear(),mDateScrollBar->value() );
811 if ( dof != mDateScrollBar->value() ) { 811 if ( dof != mDateScrollBar->value() ) {
812 mDateScrollBar->blockSignals( true ); 812 mDateScrollBar->blockSignals( true );
813 mDateScrollBar->setValue( start.dayOfYear()); 813 mDateScrollBar->setValue( start.dayOfYear());
814 mDateScrollBar->blockSignals( false ); 814 mDateScrollBar->blockSignals( false );
815 } 815 }
816 } 816 }
817#endif 817#endif
818 mTodoList->updateView(); 818 mTodoList->updateView();
819 mViewManager->updateView(start, end); 819 mViewManager->updateView(start, end);
820 //mDateNavigator->updateView(); 820 //mDateNavigator->updateView();
821} 821}
822 822
823 823
824 824
825void CalendarView::checkFiles() 825void CalendarView::checkFiles()
826{ 826{
827 QString message; 827 QString message;
828 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 828 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
829 KopiCalendarFile * cal = calendars.first(); 829 KopiCalendarFile * cal = calendars.first();
830 while ( cal ) { 830 while ( cal ) {
831 if ( cal->mErrorOnLoad ) { 831 if ( cal->mErrorOnLoad ) {
832 message += cal->mName +"\n"+KGlobal::formatMessage ( "(" +i18n( "Filepath: ")+ cal->mFileName+")" ,0 )+"\n"; 832 message += cal->mName +"\n"+KGlobal::formatMessage ( "(" +i18n( "Filepath: ")+ cal->mFileName+")" ,0 )+"\n";
833 } 833 }
834 cal = calendars.next(); 834 cal = calendars.next();
835 } 835 }
836 if ( !message.isEmpty() ) { 836 if ( !message.isEmpty() ) {
837 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); 837 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);
838 KMessageBox::error(this,message, i18n("Loding of calendar(s) failed")); 838 KMessageBox::error(this,message, i18n("Loding of calendar(s) failed"));
839 } 839 }
840 QTimer::singleShot( 2000, this, SLOT ( checkAlarms() )); 840 QTimer::singleShot( 2000, this, SLOT ( checkAlarms() ));
841} 841}
842void CalendarView::checkAlarms() 842void CalendarView::checkAlarms()
843{ 843{
844 844
845 845
846 KConfig *config = KOGlobals::config(); 846 KConfig *config = KOGlobals::config();
847 config->setGroup( "AppRun" ); 847 config->setGroup( "AppRun" );
848 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 848 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
849 int daysto = dt.daysTo( QDate::currentDate() ); 849 int daysto = dt.daysTo( QDate::currentDate() );
850 int days = config->readNumEntry( "LatestProgramStopDays" , daysto); 850 int days = config->readNumEntry( "LatestProgramStopDays" , daysto);
851 dt = dt.addDays( days ); 851 dt = dt.addDays( days );
852 int secto = dt.secsTo( QDateTime::currentDateTime() ); 852 int secto = dt.secsTo( QDateTime::currentDateTime() );
853 int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30; 853 int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30;
854 //qDebug("KO: Reading program stop %d ", secs); 854 //qDebug("KO: Reading program stop %d ", secs);
855 //secs -= ( 3600 * 24*3 ); // debug only 855 //secs -= ( 3600 * 24*3 ); // debug only
856 QDateTime latest = dt.addSecs ( secs ); 856 QDateTime latest = dt.addSecs ( secs );
857 qDebug("KO: Last termination on %s ", latest.toString().latin1()); 857 qDebug("KO: Last termination on %s ", latest.toString().latin1());
858 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 858 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
859 QPtrList<Incidence> el = mCalendar->rawIncidences(); 859 QPtrList<Incidence> el = mCalendar->rawIncidences();
860 QPtrList<Incidence> al; 860 QPtrList<Incidence> al;
861 Incidence* inL = el.first(); 861 Incidence* inL = el.first();
862 QDateTime cur = QDateTime::currentDateTime().addSecs(-59); 862 QDateTime cur = QDateTime::currentDateTime().addSecs(-59);
863 qDebug("KO: Checking alarm until %s ", cur.toString().latin1()); 863 qDebug("KO: Checking alarm until %s ", cur.toString().latin1());
864 while ( inL ) { 864 while ( inL ) {
865 bool ok = false; 865 bool ok = false;
866 int offset = 0; 866 int offset = 0;
867 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ; 867 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ;
868 if ( ok ) { 868 if ( ok ) {
869 //qDebug("OK %s",next.toString().latin1()); 869 //qDebug("OK %s",next.toString().latin1());
870 if ( next < cur ) { 870 if ( next < cur ) {
871 al.append( inL ); 871 al.append( inL );
872 //qDebug("found missed alarm: %s ", inL->summary().latin1() ); 872 //qDebug("found missed alarm: %s ", inL->summary().latin1() );
873 } 873 }
874 } 874 }
875 inL = el.next(); 875 inL = el.next();
876 } 876 }
877 if ( al.count() ) { 877 if ( al.count() ) {
878 QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop ); 878 QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop );
879 dia->setCaption( i18n("KO/Pi: Missing alarms!") ); 879 dia->setCaption( i18n("KO/Pi: Missing alarms!") );
880 QVBoxLayout* lay = new QVBoxLayout( dia ); 880 QVBoxLayout* lay = new QVBoxLayout( dia );
881 lay->setSpacing( 0 ); 881 lay->setSpacing( 0 );
882 lay->setMargin( 0 ); 882 lay->setMargin( 0 );
883 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest ); 883 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest );
884 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); 884 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) ));
885 lay->addWidget( matb ); 885 lay->addWidget( matb );
886 if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) { 886 if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) {
887 int wid = 210; 887 int wid = 210;
888 int x = QApplication::desktop()->width() - wid - 7; 888 int x = QApplication::desktop()->width() - wid - 7;
889 int y = QApplication::desktop()->height() - wid - 70; 889 int y = QApplication::desktop()->height() - wid - 70;
890 dia->setGeometry ( x,y,wid,wid); 890 dia->setGeometry ( x,y,wid,wid);
891 } else { 891 } else {
892 int si = 220; 892 int si = 220;
893 if ( QApplication::desktop()->width() > 470 ) 893 if ( QApplication::desktop()->width() > 470 )
894 si = 400; 894 si = 400;
895 dia->resize(si,si/2); 895 dia->resize(si,si/2);
896 } 896 }
897 dia->setBackgroundColor( QColor( 255, 255, 255 ) ); 897 dia->setBackgroundColor( QColor( 255, 255, 255 ) );
898 dia->show(); 898 dia->show();
899 899
900 } 900 }
901} 901}
902void CalendarView::showDay( QDate d ) 902void CalendarView::showDay( QDate d )
903{ 903{
904 dateNavigator()->blockSignals( true ); 904 dateNavigator()->blockSignals( true );
905 dateNavigator()->selectDate( d ); 905 dateNavigator()->selectDate( d );
906 dateNavigator()->blockSignals( false ); 906 dateNavigator()->blockSignals( false );
907 mViewManager->showDayView(); 907 mViewManager->showDayView();
908 //dateNavigator()->selectDate( d ); 908 //dateNavigator()->selectDate( d );
909} 909}
910void CalendarView::timerAlarm() 910void CalendarView::timerAlarm()
911{ 911{
912 //qDebug("CalendarView::timerAlarm() "); 912 //qDebug("CalendarView::timerAlarm() ");
913 computeAlarm(mAlarmNotification ); 913 computeAlarm(mAlarmNotification );
914} 914}
915 915
916void CalendarView::suspendAlarm() 916void CalendarView::suspendAlarm()
917{ 917{
918 //qDebug(" CalendarView::suspendAlarm() "); 918 //qDebug(" CalendarView::suspendAlarm() ");
919 computeAlarm(mSuspendAlarmNotification ); 919 computeAlarm(mSuspendAlarmNotification );
920 920
921} 921}
922 922
923void CalendarView::startAlarm( QString mess , QString filename) 923void CalendarView::startAlarm( QString mess , QString filename)
924{ 924{
925 925
926 topLevelWidget()->showNormal(); 926 topLevelWidget()->showNormal();
927 topLevelWidget()->setActiveWindow(); 927 topLevelWidget()->setActiveWindow();
928 topLevelWidget()->raise(); 928 topLevelWidget()->raise();
929 929
930 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 930 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
931 QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) ); 931 QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) );
932 932
933} 933}
934 934
935void CalendarView::checkNextTimerAlarm() 935void CalendarView::checkNextTimerAlarm()
936{ 936{
937 mCalendar->checkAlarmForIncidence( 0, true ); 937 mCalendar->checkAlarmForIncidence( 0, true );
938} 938}
939 939
940void CalendarView::computeAlarm( QString msg ) 940void CalendarView::computeAlarm( QString msg )
941{ 941{
942 942
943 QString mess = msg; 943 QString mess = msg;
944 QString mAlarmMessage = mess.mid( 9 ); 944 QString mAlarmMessage = mess.mid( 9 );
945 QString filename = MainWindow::resourcePath(); 945 QString filename = MainWindow::resourcePath();
946 filename += "koalarm.wav"; 946 filename += "koalarm.wav";
947 QString tempfilename; 947 QString tempfilename;
948 if ( mess.left( 13 ) == "suspend_alarm") { 948 if ( mess.left( 13 ) == "suspend_alarm") {
949 bool error = false; 949 bool error = false;
950 int len = mess.mid( 13 ).find("+++"); 950 int len = mess.mid( 13 ).find("+++");
951 if ( len < 2 ) 951 if ( len < 2 )
952 error = true; 952 error = true;
953 else { 953 else {
954 tempfilename = mess.mid( 13, len ); 954 tempfilename = mess.mid( 13, len );
955 if ( !QFile::exists( tempfilename ) ) 955 if ( !QFile::exists( tempfilename ) )
956 error = true; 956 error = true;
957 } 957 }
958 if ( ! error ) { 958 if ( ! error ) {
959 filename = tempfilename; 959 filename = tempfilename;
960 } 960 }
961 mAlarmMessage = mess.mid( 13+len+3 ); 961 mAlarmMessage = mess.mid( 13+len+3 );
962 //qDebug("suspend file %s ",tempfilename.latin1() ); 962 //qDebug("suspend file %s ",tempfilename.latin1() );
963 startAlarm( mAlarmMessage, filename); 963 startAlarm( mAlarmMessage, filename);
964 return; 964 return;
965 } 965 }
966 if ( mess.left( 11 ) == "timer_alarm") { 966 if ( mess.left( 11 ) == "timer_alarm") {
967 //mTimerTime = 0; 967 //mTimerTime = 0;
968 startAlarm( mess.mid( 11 ), filename ); 968 startAlarm( mess.mid( 11 ), filename );
969 return; 969 return;
970 } 970 }
971 if ( mess.left( 10 ) == "proc_alarm") { 971 if ( mess.left( 10 ) == "proc_alarm") {
972 bool error = false; 972 bool error = false;
973 int len = mess.mid( 10 ).find("+++"); 973 int len = mess.mid( 10 ).find("+++");
974 if ( len < 2 ) 974 if ( len < 2 )
975 error = true; 975 error = true;
976 else { 976 else {
977 tempfilename = mess.mid( 10, len ); 977 tempfilename = mess.mid( 10, len );
978 if ( !QFile::exists( tempfilename ) ) 978 if ( !QFile::exists( tempfilename ) )
979 error = true; 979 error = true;
980 } 980 }
981 if ( error ) { 981 if ( error ) {
982 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 982 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
983 mAlarmMessage += mess.mid( 10+len+3+9 ); 983 mAlarmMessage += mess.mid( 10+len+3+9 );
984 } else { 984 } else {
985 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 985 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
986 //qDebug("-----system command %s ",tempfilename.latin1() ); 986 //qDebug("-----system command %s ",tempfilename.latin1() );
987#ifndef _WIN32_ 987#ifndef _WIN32_
988 if ( vfork () == 0 ) { 988 if ( vfork () == 0 ) {
989 execl ( tempfilename.latin1(), 0 ); 989 execl ( tempfilename.latin1(), 0 );
990 return; 990 return;
991 } 991 }
992#else 992#else
993 QProcess* p = new QProcess(); 993 QProcess* p = new QProcess();
994 p->addArgument( tempfilename.latin1() ); 994 p->addArgument( tempfilename.latin1() );
995 p->start(); 995 p->start();
996 return; 996 return;
997#endif 997#endif
998 998
999 return; 999 return;
1000 } 1000 }
1001 1001
1002 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 1002 //qDebug("+++++++system command %s ",tempfilename.latin1() );
1003 } 1003 }
1004 if ( mess.left( 11 ) == "audio_alarm") { 1004 if ( mess.left( 11 ) == "audio_alarm") {
1005 bool error = false; 1005 bool error = false;
1006 int len = mess.mid( 11 ).find("+++"); 1006 int len = mess.mid( 11 ).find("+++");
1007 if ( len < 2 ) 1007 if ( len < 2 )
1008 error = true; 1008 error = true;
1009 else { 1009 else {
1010 tempfilename = mess.mid( 11, len ); 1010 tempfilename = mess.mid( 11, len );
1011 if ( !QFile::exists( tempfilename ) ) 1011 if ( !QFile::exists( tempfilename ) )
1012 error = true; 1012 error = true;
1013 } 1013 }
1014 if ( ! error ) { 1014 if ( ! error ) {
1015 filename = tempfilename; 1015 filename = tempfilename;
1016 } 1016 }
1017 mAlarmMessage = mess.mid( 11+len+3+9 ); 1017 mAlarmMessage = mess.mid( 11+len+3+9 );
1018 //qDebug("audio file command %s ",tempfilename.latin1() ); 1018 //qDebug("audio file command %s ",tempfilename.latin1() );
1019 } 1019 }
1020 if ( mess.left( 9 ) == "cal_alarm") { 1020 if ( mess.left( 9 ) == "cal_alarm") {
1021 mAlarmMessage = mess.mid( 9 ) ; 1021 mAlarmMessage = mess.mid( 9 ) ;
1022 } 1022 }
1023 1023
1024 startAlarm( mAlarmMessage, filename ); 1024 startAlarm( mAlarmMessage, filename );
1025 1025
1026 1026
1027} 1027}
1028 1028
1029void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 1029void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
1030{ 1030{
1031 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1031 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1032 1032
1033 mSuspendAlarmNotification = noti; 1033 mSuspendAlarmNotification = noti;
1034 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 1034 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
1035 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 1035 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
1036 mSuspendTimer->start( ms , true ); 1036 mSuspendTimer->start( ms , true );
1037 1037
1038} 1038}
1039 1039
1040void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 1040void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
1041{ 1041{
1042 mNextAlarmDateTime = qdt; 1042 mNextAlarmDateTime = qdt;
1043 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1043 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1044 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 1044 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
1045#ifndef DESKTOP_VERSION 1045#ifndef DESKTOP_VERSION
1046 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() ); 1046 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() );
1047#endif 1047#endif
1048 return; 1048 return;
1049 } 1049 }
1050 int maxSec; 1050 int maxSec;
1051 //maxSec = 5; //testing only 1051 //maxSec = 5; //testing only
1052 maxSec = 86400+3600; // one day+1hour 1052 maxSec = 86400+3600; // one day+1hour
1053 mAlarmNotification = noti; 1053 mAlarmNotification = noti;
1054 int sec = QDateTime::currentDateTime().secsTo( qdt ); 1054 int sec = QDateTime::currentDateTime().secsTo( qdt );
1055 if ( sec > maxSec ) { 1055 if ( sec > maxSec ) {
1056 mRecheckAlarmTimer->start( maxSec * 1000 ); 1056 mRecheckAlarmTimer->start( maxSec * 1000 );
1057 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 1057 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
1058 return; 1058 return;
1059 } else { 1059 } else {
1060 mRecheckAlarmTimer->stop(); 1060 mRecheckAlarmTimer->stop();
1061 } 1061 }
1062 //qDebug("Alarm timer started with secs: %d ", sec); 1062 //qDebug("Alarm timer started with secs: %d ", sec);
1063 mAlarmTimer->start( sec *1000 , true ); 1063 mAlarmTimer->start( sec *1000 , true );
1064 1064
1065} 1065}
1066// called by mRecheckAlarmTimer to get next alarm 1066// called by mRecheckAlarmTimer to get next alarm
1067// we need this, because a QTimer has only a max range of 25 days 1067// we need this, because a QTimer has only a max range of 25 days
1068void CalendarView::recheckTimerAlarm() 1068void CalendarView::recheckTimerAlarm()
1069{ 1069{
1070 mAlarmTimer->stop(); 1070 mAlarmTimer->stop();
1071 mRecheckAlarmTimer->stop(); 1071 mRecheckAlarmTimer->stop();
1072 mCalendar->checkAlarmForIncidence( 0, true ); 1072 mCalendar->checkAlarmForIncidence( 0, true );
1073} 1073}
1074#ifndef DESKTOP_VERSION 1074#ifndef DESKTOP_VERSION
1075void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 1075void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
1076#else 1076#else
1077void CalendarView::removeAlarm(const QDateTime &, const QString & ) 1077void CalendarView::removeAlarm(const QDateTime &, const QString & )
1078#endif 1078#endif
1079{ 1079{
1080 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1080 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1081 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 1081 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
1082#ifndef DESKTOP_VERSION 1082#ifndef DESKTOP_VERSION
1083 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() ); 1083 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() );
1084#endif 1084#endif
1085 return; 1085 return;
1086 } 1086 }
1087 mAlarmTimer->stop(); 1087 mAlarmTimer->stop();
1088} 1088}
1089void CalendarView::selectWeekNum ( int num ) 1089void CalendarView::selectWeekNum ( int num )
1090{ 1090{
1091 dateNavigator()->blockSignals( true ); 1091 dateNavigator()->blockSignals( true );
1092 dateNavigator()->selectWeek( num ); 1092 dateNavigator()->selectWeek( num );
1093 dateNavigator()->blockSignals( false ); 1093 dateNavigator()->blockSignals( false );
1094 mViewManager->showWeekView(); 1094 mViewManager->showWeekView();
1095} 1095}
1096KOViewManager *CalendarView::viewManager() 1096KOViewManager *CalendarView::viewManager()
1097{ 1097{
1098 return mViewManager; 1098 return mViewManager;
1099} 1099}
1100 1100
1101KODialogManager *CalendarView::dialogManager() 1101KODialogManager *CalendarView::dialogManager()
1102{ 1102{
1103 return mDialogManager; 1103 return mDialogManager;
1104} 1104}
1105 1105
1106QDate CalendarView::startDate() 1106QDate CalendarView::startDate()
1107{ 1107{
1108 DateList dates = mNavigator->selectedDates(); 1108 DateList dates = mNavigator->selectedDates();
1109 1109
1110 return dates.first(); 1110 return dates.first();
1111} 1111}
1112 1112
1113QDate CalendarView::endDate() 1113QDate CalendarView::endDate()
1114{ 1114{
1115 DateList dates = mNavigator->selectedDates(); 1115 DateList dates = mNavigator->selectedDates();
1116 1116
1117 return dates.last(); 1117 return dates.last();
1118} 1118}
1119 1119
1120 1120
1121void CalendarView::createPrinter() 1121void CalendarView::createPrinter()
1122{ 1122{
1123#ifndef KORG_NOPRINTER 1123#ifndef KORG_NOPRINTER
1124 if (!mCalPrinter) { 1124 if (!mCalPrinter) {
1125 mCalPrinter = new CalPrinter(this, mCalendar); 1125 mCalPrinter = new CalPrinter(this, mCalendar);
1126 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 1126 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
1127 } 1127 }
1128#endif 1128#endif
1129} 1129}
1130 1130
1131 1131
1132//KOPrefs::instance()->mWriteBackFile 1132//KOPrefs::instance()->mWriteBackFile
1133//KOPrefs::instance()->mWriteBackExistingOnly 1133//KOPrefs::instance()->mWriteBackExistingOnly
1134 1134
1135// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 1135// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
1136// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 1136// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
1137// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 1137// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
1138// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 1138// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
1139// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 1139// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
1140// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 1140// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
1141 1141
1142int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 1142int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
1143{ 1143{
1144 1144
1145 // 0 equal 1145 // 0 equal
1146 // 1 take local 1146 // 1 take local
1147 // 2 take remote 1147 // 2 take remote
1148 // 3 cancel 1148 // 3 cancel
1149 QDateTime lastSync = mLastCalendarSync; 1149 QDateTime lastSync = mLastCalendarSync;
1150 QDateTime localMod = local->lastModified(); 1150 QDateTime localMod = local->lastModified();
1151 QDateTime remoteMod = remote->lastModified(); 1151 QDateTime remoteMod = remote->lastModified();
1152 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1152 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1153 bool remCh, locCh; 1153 bool remCh, locCh;
1154 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 1154 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
1155 //if ( remCh ) 1155 //if ( remCh )
1156 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 1156 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
1157 locCh = ( localMod > mLastCalendarSync ); 1157 locCh = ( localMod > mLastCalendarSync );
1158 if ( !remCh && ! locCh ) { 1158 if ( !remCh && ! locCh ) {
1159 //qDebug("both not changed "); 1159 //qDebug("both not changed ");
1160 lastSync = localMod.addDays(1); 1160 lastSync = localMod.addDays(1);
1161 if ( mode <= SYNC_PREF_ASK ) 1161 if ( mode <= SYNC_PREF_ASK )
1162 return 0; 1162 return 0;
1163 } else { 1163 } else {
1164 if ( locCh ) { 1164 if ( locCh ) {
1165 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 1165 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
1166 lastSync = localMod.addDays( -1 ); 1166 lastSync = localMod.addDays( -1 );
1167 if ( !remCh ) 1167 if ( !remCh )
1168 remoteMod = ( lastSync.addDays( -1 ) ); 1168 remoteMod = ( lastSync.addDays( -1 ) );
1169 } else { 1169 } else {
1170 //qDebug(" not loc changed "); 1170 //qDebug(" not loc changed ");
1171 lastSync = localMod.addDays( 1 ); 1171 lastSync = localMod.addDays( 1 );
1172 if ( remCh ) 1172 if ( remCh )
1173 remoteMod =( lastSync.addDays( 1 ) ); 1173 remoteMod =( lastSync.addDays( 1 ) );
1174 1174
1175 } 1175 }
1176 } 1176 }
1177 full = true; 1177 full = true;
1178 if ( mode < SYNC_PREF_ASK ) 1178 if ( mode < SYNC_PREF_ASK )
1179 mode = SYNC_PREF_ASK; 1179 mode = SYNC_PREF_ASK;
1180 } else { 1180 } else {
1181 if ( localMod == remoteMod ) 1181 if ( localMod == remoteMod )
1182 // if ( local->revision() == remote->revision() ) 1182 // if ( local->revision() == remote->revision() )
1183 return 0; 1183 return 0;
1184 1184
1185 } 1185 }
1186 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 1186 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
1187 1187
1188 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 1188 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
1189 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 1189 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
1190 //full = true; //debug only 1190 //full = true; //debug only
1191 if ( full ) { 1191 if ( full ) {
1192 bool equ = false; 1192 bool equ = false;
1193 if ( local->typeID() == eventID ) { 1193 if ( local->typeID() == eventID ) {
1194 equ = (*((Event*) local) == *((Event*) remote)); 1194 equ = (*((Event*) local) == *((Event*) remote));
1195 } 1195 }
1196 else if ( local->typeID() == todoID ) 1196 else if ( local->typeID() == todoID )
1197 equ = (*((Todo*) local) == (*(Todo*) remote)); 1197 equ = (*((Todo*) local) == (*(Todo*) remote));
1198 else if ( local->typeID() == journalID ) 1198 else if ( local->typeID() == journalID )
1199 equ = (*((Journal*) local) == *((Journal*) remote)); 1199 equ = (*((Journal*) local) == *((Journal*) remote));
1200 if ( equ ) { 1200 if ( equ ) {
1201 //qDebug("equal "); 1201 //qDebug("equal ");
1202 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1202 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1203 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 1203 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
1204 } 1204 }
1205 if ( mode < SYNC_PREF_FORCE_LOCAL ) 1205 if ( mode < SYNC_PREF_FORCE_LOCAL )
1206 return 0; 1206 return 0;
1207 1207
1208 }//else //debug only 1208 }//else //debug only
1209 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 1209 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
1210 } 1210 }
1211 int result; 1211 int result;
1212 bool localIsNew; 1212 bool localIsNew;
1213 //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() ); 1213 //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() );
1214 1214
1215 1215
1216 // ************************************************ 1216 // ************************************************
1217 // ************************************************ 1217 // ************************************************
1218 // ************************************************ 1218 // ************************************************
1219 // We may have that lastSync > remoteMod AND lastSync > localMod 1219 // We may have that lastSync > remoteMod AND lastSync > localMod
1220 // BUT remoteMod != localMod 1220 // BUT remoteMod != localMod
1221 1221
1222 1222
1223 if ( full && mode < SYNC_PREF_NEWEST ) 1223 if ( full && mode < SYNC_PREF_NEWEST )
1224 mode = SYNC_PREF_ASK; 1224 mode = SYNC_PREF_ASK;
1225 1225
1226 switch( mode ) { 1226 switch( mode ) {
1227 case SYNC_PREF_LOCAL: 1227 case SYNC_PREF_LOCAL:
1228 if ( lastSync > remoteMod ) 1228 if ( lastSync > remoteMod )
1229 return 1; 1229 return 1;
1230 if ( lastSync > localMod ) 1230 if ( lastSync > localMod )
1231 return 2; 1231 return 2;
1232 return 1; 1232 return 1;
1233 break; 1233 break;
1234 case SYNC_PREF_REMOTE: 1234 case SYNC_PREF_REMOTE:
1235 if ( lastSync > localMod ) 1235 if ( lastSync > localMod )
1236 return 2; 1236 return 2;
1237 if ( lastSync > remoteMod ) 1237 if ( lastSync > remoteMod )
1238 return 1; 1238 return 1;
1239 return 2; 1239 return 2;
1240 break; 1240 break;
1241 case SYNC_PREF_NEWEST: 1241 case SYNC_PREF_NEWEST:
1242 if ( localMod >= remoteMod ) 1242 if ( localMod >= remoteMod )
1243 return 1; 1243 return 1;
1244 else 1244 else
1245 return 2; 1245 return 2;
1246 break; 1246 break;
1247 case SYNC_PREF_ASK: 1247 case SYNC_PREF_ASK:
1248 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1248 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1249 if ( lastSync > remoteMod && lastSync > localMod) 1249 if ( lastSync > remoteMod && lastSync > localMod)
1250 return 0; 1250 return 0;
1251 if ( lastSync > remoteMod ) 1251 if ( lastSync > remoteMod )
1252 return 1; 1252 return 1;
1253 if ( lastSync > localMod ) 1253 if ( lastSync > localMod )
1254 return 2; 1254 return 2;
1255 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1255 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1256 localIsNew = localMod >= remoteMod; 1256 localIsNew = localMod >= remoteMod;
1257 if ( localIsNew ) 1257 if ( localIsNew )
1258 getEventViewerDialog()->setColorMode( 1 ); 1258 getEventViewerDialog()->setColorMode( 1 );
1259 else 1259 else
1260 getEventViewerDialog()->setColorMode( 2 ); 1260 getEventViewerDialog()->setColorMode( 2 );
1261 getEventViewerDialog()->setIncidence(local); 1261 getEventViewerDialog()->setIncidence(local);
1262 if ( localIsNew ) 1262 if ( localIsNew )
1263 getEventViewerDialog()->setColorMode( 2 ); 1263 getEventViewerDialog()->setColorMode( 2 );
1264 else 1264 else
1265 getEventViewerDialog()->setColorMode( 1 ); 1265 getEventViewerDialog()->setColorMode( 1 );
1266 getEventViewerDialog()->addIncidence(remote); 1266 getEventViewerDialog()->addIncidence(remote);
1267 getEventViewerDialog()->setColorMode( 0 ); 1267 getEventViewerDialog()->setColorMode( 0 );
1268 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 1268 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
1269 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 1269 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
1270 getEventViewerDialog()->showMe(); 1270 getEventViewerDialog()->showMe();
1271 result = getEventViewerDialog()->executeS( localIsNew ); 1271 result = getEventViewerDialog()->executeS( localIsNew );
1272 return result; 1272 return result;
1273 1273
1274 break; 1274 break;
1275 case SYNC_PREF_FORCE_LOCAL: 1275 case SYNC_PREF_FORCE_LOCAL:
1276 return 1; 1276 return 1;
1277 break; 1277 break;
1278 case SYNC_PREF_FORCE_REMOTE: 1278 case SYNC_PREF_FORCE_REMOTE:
1279 return 2; 1279 return 2;
1280 break; 1280 break;
1281 1281
1282 default: 1282 default:
1283 // SYNC_PREF_TAKE_BOTH not implemented 1283 // SYNC_PREF_TAKE_BOTH not implemented
1284 break; 1284 break;
1285 } 1285 }
1286 return 0; 1286 return 0;
1287} 1287}
1288Event* CalendarView::getLastSyncEvent() 1288Event* CalendarView::getLastSyncEvent()
1289{ 1289{
1290 Event* lse; 1290 Event* lse;
1291 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 1291 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
1292 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 1292 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
1293 if (!lse) { 1293 if (!lse) {
1294 lse = new Event(); 1294 lse = new Event();
1295 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 1295 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
1296 QString sum = ""; 1296 QString sum = "";
1297 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 1297 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
1298 sum = "E: "; 1298 sum = "E: ";
1299 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 1299 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
1300 lse->setDtStart( mLastCalendarSync ); 1300 lse->setDtStart( mLastCalendarSync );
1301 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1301 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1302 lse->setCategories( i18n("SyncEvent") ); 1302 lse->setCategories( i18n("SyncEvent") );
1303 lse->setReadOnly( true ); 1303 lse->setReadOnly( true );
1304 mCalendar->addEvent( lse ); 1304 mCalendar->addEvent( lse );
1305 } 1305 }
1306 1306
1307 return lse; 1307 return lse;
1308 1308
1309} 1309}
1310 1310
1311// we check, if the to delete event has a id for a profile 1311// we check, if the to delete event has a id for a profile
1312// if yes, we set this id in the profile to delete 1312// if yes, we set this id in the profile to delete
1313void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 1313void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
1314{ 1314{
1315 if ( lastSync.count() == 0 ) { 1315 if ( lastSync.count() == 0 ) {
1316 //qDebug(" lastSync.count() == 0"); 1316 //qDebug(" lastSync.count() == 0");
1317 return; 1317 return;
1318 } 1318 }
1319 if ( toDelete->typeID() == journalID ) 1319 if ( toDelete->typeID() == journalID )
1320 return; 1320 return;
1321 1321
1322 Event* eve = lastSync.first(); 1322 Event* eve = lastSync.first();
1323 1323
1324 while ( eve ) { 1324 while ( eve ) {
1325 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 1325 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
1326 if ( !id.isEmpty() ) { 1326 if ( !id.isEmpty() ) {
1327 QString des = eve->description(); 1327 QString des = eve->description();
1328 QString pref = "e"; 1328 QString pref = "e";
1329 if ( toDelete->typeID() == todoID ) 1329 if ( toDelete->typeID() == todoID )
1330 pref = "t"; 1330 pref = "t";
1331 des += pref+ id + ","; 1331 des += pref+ id + ",";
1332 eve->setReadOnly( false ); 1332 eve->setReadOnly( false );
1333 eve->setDescription( des ); 1333 eve->setDescription( des );
1334 //qDebug("setdes %s ", des.latin1()); 1334 //qDebug("setdes %s ", des.latin1());
1335 eve->setReadOnly( true ); 1335 eve->setReadOnly( true );
1336 } 1336 }
1337 eve = lastSync.next(); 1337 eve = lastSync.next();
1338 } 1338 }
1339 1339
1340} 1340}
1341void CalendarView::checkExternalId( Incidence * inc ) 1341void CalendarView::checkExternalId( Incidence * inc )
1342{ 1342{
1343 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 1343 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
1344 checkExternSyncEvent( lastSync, inc ); 1344 checkExternSyncEvent( lastSync, inc );
1345 1345
1346} 1346}
1347bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 1347bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
1348{ 1348{
1349 bool syncOK = true; 1349 bool syncOK = true;
1350 int addedEvent = 0; 1350 int addedEvent = 0;
1351 int addedEventR = 0; 1351 int addedEventR = 0;
1352 int deletedEventR = 0; 1352 int deletedEventR = 0;
1353 int deletedEventL = 0; 1353 int deletedEventL = 0;
1354 int changedLocal = 0; 1354 int changedLocal = 0;
1355 int changedRemote = 0; 1355 int changedRemote = 0;
1356 int filteredIN = 0; 1356 int filteredIN = 0;
1357 int filteredOUT = 0; 1357 int filteredOUT = 0;
1358 //QPtrList<Event> el = local->rawEvents(); 1358 //QPtrList<Event> el = local->rawEvents();
1359 Event* eventR; 1359 Event* eventR;
1360 QString uid; 1360 QString uid;
1361 int take; 1361 int take;
1362 Event* eventRSync; 1362 Event* eventRSync;
1363 Event* eventLSync; 1363 Event* eventLSync;
1364 clearAllViews(); 1364 clearAllViews();
1365 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 1365 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
1366 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 1366 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
1367 bool fullDateRange = false; 1367 bool fullDateRange = false;
1368 local->resetTempSyncStat(); 1368 local->resetTempSyncStat();
1369 mLastCalendarSync = QDateTime::currentDateTime(); 1369 mLastCalendarSync = QDateTime::currentDateTime();
1370 if ( mSyncManager->syncWithDesktop() ) { 1370 if ( mSyncManager->syncWithDesktop() ) {
1371 remote->resetPilotStat(1); 1371 remote->resetPilotStat(1);
1372 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1372 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1373 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 1373 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
1374 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 1374 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
1375 } else { 1375 } else {
1376 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 1376 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
1377 } 1377 }
1378 } 1378 }
1379 QDateTime modifiedCalendar = mLastCalendarSync; 1379 QDateTime modifiedCalendar = mLastCalendarSync;
1380 eventLSync = getLastSyncEvent(); 1380 eventLSync = getLastSyncEvent();
1381 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 1381 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
1382 if ( eventR ) { 1382 if ( eventR ) {
1383 qDebug("last-syncEvent on remote found "); 1383 qDebug("last-syncEvent on remote found ");
1384 eventRSync = (Event*) eventR->clone(); 1384 eventRSync = (Event*) eventR->clone();
1385 remote->deleteEvent(eventR ); 1385 remote->deleteEvent(eventR );
1386 1386
1387 } else { 1387 } else {
1388 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 1388 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
1389 eventRSync = (Event*)eventLSync->clone(); 1389 eventRSync = (Event*)eventLSync->clone();
1390 } else { 1390 } else {
1391 fullDateRange = true; 1391 fullDateRange = true;
1392 eventRSync = new Event(); 1392 eventRSync = new Event();
1393 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 1393 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
1394 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 1394 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
1395 eventRSync->setDtStart( mLastCalendarSync ); 1395 eventRSync->setDtStart( mLastCalendarSync );
1396 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1396 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1397 eventRSync->setCategories( i18n("SyncEvent") ); 1397 eventRSync->setCategories( i18n("SyncEvent") );
1398 } 1398 }
1399 } 1399 }
1400 if ( eventLSync->dtStart() == mLastCalendarSync ) 1400 if ( eventLSync->dtStart() == mLastCalendarSync )
1401 fullDateRange = true; 1401 fullDateRange = true;
1402 1402
1403 if ( ! fullDateRange ) { 1403 if ( ! fullDateRange ) {
1404 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 1404 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
1405 1405
1406 qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 1406 qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
1407 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 1407 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
1408 fullDateRange = true; 1408 fullDateRange = true;
1409 } 1409 }
1410 } 1410 }
1411 if ( mSyncManager->syncWithDesktop() ) { 1411 if ( mSyncManager->syncWithDesktop() ) {
1412 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 1412 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
1413 } 1413 }
1414 if ( fullDateRange ) 1414 if ( fullDateRange )
1415 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 1415 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
1416 else 1416 else
1417 mLastCalendarSync = eventLSync->dtStart(); 1417 mLastCalendarSync = eventLSync->dtStart();
1418 // for resyncing if own file has changed 1418 // for resyncing if own file has changed
1419 if ( mCurrentSyncDevice == "deleteaftersync" ) { 1419 if ( mCurrentSyncDevice == "deleteaftersync" ) {
1420 mLastCalendarSync = loadedFileVersion; 1420 mLastCalendarSync = loadedFileVersion;
1421 //qDebug("setting mLastCalendarSync "); 1421 //qDebug("setting mLastCalendarSync ");
1422 } 1422 }
1423 //qDebug("*************************** "); 1423 //qDebug("*************************** ");
1424 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1424 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1425 QPtrList<Incidence> er = remote->rawIncidences(); 1425 QPtrList<Incidence> er = remote->rawIncidences();
1426 Incidence* inR = er.first(); 1426 Incidence* inR = er.first();
1427 Incidence* inL; 1427 Incidence* inL;
1428 QProgressBar bar( er.count(),0 ); 1428 QProgressBar bar( er.count(),0 );
1429 bar.setCaption (i18n("Syncing - close to abort!") ); 1429 bar.setCaption (i18n("Syncing - close to abort!") );
1430 1430
1431 // ************** setting up filter ************* 1431 // ************** setting up filter *************
1432 CalFilter *filterIN = 0; 1432 CalFilter *filterIN = 0;
1433 CalFilter *filterOUT = 0; 1433 CalFilter *filterOUT = 0;
1434 CalFilter *filter = mFilters.first(); 1434 CalFilter *filter = mFilters.first();
1435 while(filter) { 1435 while(filter) {
1436 if ( filter->name() == mSyncManager->mFilterInCal ) 1436 if ( filter->name() == mSyncManager->mFilterInCal )
1437 filterIN = filter; 1437 filterIN = filter;
1438 if ( filter->name() == mSyncManager->mFilterOutCal ) 1438 if ( filter->name() == mSyncManager->mFilterOutCal )
1439 filterOUT = filter; 1439 filterOUT = filter;
1440 filter = mFilters.next(); 1440 filter = mFilters.next();
1441 } 1441 }
1442 int w = 300; 1442 int w = 300;
1443 if ( QApplication::desktop()->width() < 320 ) 1443 if ( QApplication::desktop()->width() < 320 )
1444 w = 220; 1444 w = 220;
1445 int h = bar.sizeHint().height() ; 1445 int h = bar.sizeHint().height() ;
1446 int dw = QApplication::desktop()->width(); 1446 int dw = QApplication::desktop()->width();
1447 int dh = QApplication::desktop()->height(); 1447 int dh = QApplication::desktop()->height();
1448 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1448 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1449 bar.show(); 1449 bar.show();
1450 int modulo = (er.count()/10)+1; 1450 int modulo = (er.count()/10)+1;
1451 int incCounter = 0; 1451 int incCounter = 0;
1452 while ( inR ) { 1452 while ( inR ) {
1453 if ( ! bar.isVisible() ) 1453 if ( ! bar.isVisible() )
1454 return false; 1454 return false;
1455 if ( incCounter % modulo == 0 ) 1455 if ( incCounter % modulo == 0 )
1456 bar.setProgress( incCounter ); 1456 bar.setProgress( incCounter );
1457 ++incCounter; 1457 ++incCounter;
1458 uid = inR->uid(); 1458 uid = inR->uid();
1459 bool skipIncidence = false; 1459 bool skipIncidence = false;
1460 if ( uid.left(15) == QString("last-syncEvent-") ) 1460 if ( uid.left(15) == QString("last-syncEvent-") )
1461 skipIncidence = true; 1461 skipIncidence = true;
1462 QString idS; 1462 QString idS;
1463 qApp->processEvents(); 1463 qApp->processEvents();
1464 if ( !skipIncidence ) { 1464 if ( !skipIncidence ) {
1465 inL = local->incidenceForUid( uid , false ); 1465 inL = local->incidenceForUid( uid , false );
1466 if ( inL ) { // maybe conflict - same uid in both calendars 1466 if ( inL ) { // maybe conflict - same uid in both calendars
1467 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1467 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1468 //qDebug("take %d %s ", take, inL->summary().latin1()); 1468 //qDebug("take %d %s ", take, inL->summary().latin1());
1469 if ( take == 3 ) 1469 if ( take == 3 )
1470 return false; 1470 return false;
1471 if ( take == 1 ) {// take local ********************** 1471 if ( take == 1 ) {// take local **********************
1472 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1472 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1473 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1473 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1474 else 1474 else
1475 idS = inR->IDStr(); 1475 idS = inR->IDStr();
1476 int calID = inR->calID(); 1476 int calID = inR->calID();
1477 remote->deleteIncidence( inR ); 1477 remote->deleteIncidence( inR );
1478 inR = inL->clone(); 1478 inR = inL->clone();
1479 inR->setCalID( calID ); 1479 inR->setCalID( calID );
1480 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1480 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1481 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1481 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1482 inR->setIDStr( idS ); 1482 inR->setIDStr( idS );
1483 remote->addIncidence( inR ); 1483 remote->addIncidence( inR );
1484 if ( mSyncManager->syncWithDesktop() ) 1484 if ( mSyncManager->syncWithDesktop() )
1485 inR->setPilotId( 2 ); 1485 inR->setPilotId( 2 );
1486 ++changedRemote; 1486 ++changedRemote;
1487 } else {// take remote ********************** 1487 } else {// take remote **********************
1488 if ( !inL->isReadOnly() ) { 1488 if ( !inL->isReadOnly() ) {
1489 idS = inL->IDStr(); 1489 idS = inL->IDStr();
1490 int pid = inL->pilotId(); 1490 int pid = inL->pilotId();
1491 int calID = inL->calID(); 1491 int calID = inL->calID();
1492 local->deleteIncidence( inL ); 1492 local->deleteIncidence( inL );
1493 inL = inR->clone(); 1493 inL = inR->clone();
1494 inL->setCalID( calID ); 1494 inL->setCalID( calID );
1495 if ( mSyncManager->syncWithDesktop() ) 1495 if ( mSyncManager->syncWithDesktop() )
1496 inL->setPilotId( pid ); 1496 inL->setPilotId( pid );
1497 inL->setIDStr( idS ); 1497 inL->setIDStr( idS );
1498 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1498 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1499 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1499 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1500 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1500 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1501 } 1501 }
1502 local->addIncidence( inL ); 1502 local->addIncidence( inL );
1503 ++changedLocal; 1503 ++changedLocal;
1504 } 1504 }
1505 } 1505 }
1506 } 1506 }
1507 } else { // no conflict ********** add or delete remote 1507 } else { // no conflict ********** add or delete remote
1508 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1508 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1509 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1509 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1510 QString des = eventLSync->description(); 1510 QString des = eventLSync->description();
1511 QString pref = "e"; 1511 QString pref = "e";
1512 if ( inR->typeID() == todoID ) 1512 if ( inR->typeID() == todoID )
1513 pref = "t"; 1513 pref = "t";
1514 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1514 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1515 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1515 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1516 //remote->deleteIncidence( inR ); 1516 //remote->deleteIncidence( inR );
1517 ++deletedEventR; 1517 ++deletedEventR;
1518 } else { 1518 } else {
1519 inR->setLastModified( modifiedCalendar ); 1519 inR->setLastModified( modifiedCalendar );
1520 inL = inR->clone(); 1520 inL = inR->clone();
1521 inL->setIDStr( ":" ); 1521 inL->setIDStr( ":" );
1522 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1522 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1523 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1523 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1524 1524
1525 inL->setCalID( 0 );// add to default cal 1525 inL->setCalID( 0 );// add to default cal
1526 local->addIncidence( inL ); 1526 local->addIncidence( inL );
1527 ++addedEvent; 1527 ++addedEvent;
1528 1528
1529 } 1529 }
1530 } else { 1530 } else {
1531 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1531 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1532 inR->setLastModified( modifiedCalendar ); 1532 inR->setLastModified( modifiedCalendar );
1533 inL = inR->clone(); 1533 inL = inR->clone();
1534 inL->setIDStr( ":" ); 1534 inL->setIDStr( ":" );
1535 inL->setCalID( 0 );// add to default cal 1535 inL->setCalID( 0 );// add to default cal
1536 local->addIncidence( inL ); 1536 local->addIncidence( inL );
1537 ++addedEvent; 1537 ++addedEvent;
1538 1538
1539 } else { 1539 } else {
1540 checkExternSyncEvent(eventRSyncSharp, inR); 1540 checkExternSyncEvent(eventRSyncSharp, inR);
1541 remote->deleteIncidence( inR ); 1541 remote->deleteIncidence( inR );
1542 ++deletedEventR; 1542 ++deletedEventR;
1543 } 1543 }
1544 } 1544 }
1545 } else { 1545 } else {
1546 ++filteredIN; 1546 ++filteredIN;
1547 } 1547 }
1548 } 1548 }
1549 } 1549 }
1550 inR = er.next(); 1550 inR = er.next();
1551 } 1551 }
1552 QPtrList<Incidence> el = local->rawIncidences(); 1552 QPtrList<Incidence> el = local->rawIncidences();
1553 inL = el.first(); 1553 inL = el.first();
1554 modulo = (el.count()/10)+1; 1554 modulo = (el.count()/10)+1;
1555 bar.setCaption (i18n("Add / remove events") ); 1555 bar.setCaption (i18n("Add / remove events") );
1556 bar.setTotalSteps ( el.count() ) ; 1556 bar.setTotalSteps ( el.count() ) ;
1557 bar.show(); 1557 bar.show();
1558 incCounter = 0; 1558 incCounter = 0;
1559 1559
1560 while ( inL ) { 1560 while ( inL ) {
1561 1561
1562 qApp->processEvents(); 1562 qApp->processEvents();
1563 if ( ! bar.isVisible() ) 1563 if ( ! bar.isVisible() )
1564 return false; 1564 return false;
1565 if ( incCounter % modulo == 0 ) 1565 if ( incCounter % modulo == 0 )
1566 bar.setProgress( incCounter ); 1566 bar.setProgress( incCounter );
1567 ++incCounter; 1567 ++incCounter;
1568 uid = inL->uid(); 1568 uid = inL->uid();
1569 bool skipIncidence = false; 1569 bool skipIncidence = false;
1570 if ( uid.left(15) == QString("last-syncEvent-") ) 1570 if ( uid.left(15) == QString("last-syncEvent-") )
1571 skipIncidence = true; 1571 skipIncidence = true;
1572 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) 1572 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID )
1573 skipIncidence = true; 1573 skipIncidence = true;
1574 if ( !skipIncidence ) { 1574 if ( !skipIncidence ) {
1575 inR = remote->incidenceForUid( uid , true ); 1575 inR = remote->incidenceForUid( uid , true );
1576 if ( ! inR ) { 1576 if ( ! inR ) {
1577 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1577 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1578 // no conflict ********** add or delete local 1578 // no conflict ********** add or delete local
1579 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1579 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1580 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1580 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1581 checkExternSyncEvent(eventLSyncSharp, inL); 1581 checkExternSyncEvent(eventLSyncSharp, inL);
1582 local->deleteIncidence( inL ); 1582 local->deleteIncidence( inL );
1583 ++deletedEventL; 1583 ++deletedEventL;
1584 } else { 1584 } else {
1585 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1585 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1586 inL->removeID(mCurrentSyncDevice ); 1586 inL->removeID(mCurrentSyncDevice );
1587 ++addedEventR; 1587 ++addedEventR;
1588 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1588 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1589 inL->setLastModified( modifiedCalendar ); 1589 inL->setLastModified( modifiedCalendar );
1590 inR = inL->clone(); 1590 inR = inL->clone();
1591 inR->setIDStr( ":" ); 1591 inR->setIDStr( ":" );
1592 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1592 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1593 inR->setCalID( 0 );// add to default cal 1593 inR->setCalID( 0 );// add to default cal
1594 remote->addIncidence( inR ); 1594 remote->addIncidence( inR );
1595 } 1595 }
1596 } 1596 }
1597 } else { 1597 } else {
1598 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1598 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1599 checkExternSyncEvent(eventLSyncSharp, inL); 1599 checkExternSyncEvent(eventLSyncSharp, inL);
1600 local->deleteIncidence( inL ); 1600 local->deleteIncidence( inL );
1601 ++deletedEventL; 1601 ++deletedEventL;
1602 } else { 1602 } else {
1603 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1603 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1604 ++addedEventR; 1604 ++addedEventR;
1605 inL->setLastModified( modifiedCalendar ); 1605 inL->setLastModified( modifiedCalendar );
1606 inR = inL->clone(); 1606 inR = inL->clone();
1607 inR->setIDStr( ":" ); 1607 inR->setIDStr( ":" );
1608 inR->setCalID( 0 );// add to default cal 1608 inR->setCalID( 0 );// add to default cal
1609 remote->addIncidence( inR ); 1609 remote->addIncidence( inR );
1610 } 1610 }
1611 } 1611 }
1612 } 1612 }
1613 } else { 1613 } else {
1614 ++filteredOUT; 1614 ++filteredOUT;
1615 } 1615 }
1616 } 1616 }
1617 } 1617 }
1618 inL = el.next(); 1618 inL = el.next();
1619 } 1619 }
1620 int delFut = 0; 1620 int delFut = 0;
1621 int remRem = 0; 1621 int remRem = 0;
1622 if ( mSyncManager->mWriteBackInFuture ) { 1622 if ( mSyncManager->mWriteBackInFuture ) {
1623 er = remote->rawIncidences(); 1623 er = remote->rawIncidences();
1624 remRem = er.count(); 1624 remRem = er.count();
1625 inR = er.first(); 1625 inR = er.first();
1626 QDateTime dt; 1626 QDateTime dt;
1627 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1627 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1628 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1628 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1629 while ( inR ) { 1629 while ( inR ) {
1630 if ( inR->typeID() == todoID ) { 1630 if ( inR->typeID() == todoID ) {
1631 Todo * t = (Todo*)inR; 1631 Todo * t = (Todo*)inR;
1632 if ( t->hasDueDate() ) 1632 if ( t->hasDueDate() )
1633 dt = t->dtDue(); 1633 dt = t->dtDue();
1634 else 1634 else
1635 dt = cur.addSecs( 62 ); 1635 dt = cur.addSecs( 62 );
1636 } 1636 }
1637 else if (inR->typeID() == eventID ) { 1637 else if (inR->typeID() == eventID ) {
1638 bool ok; 1638 bool ok;
1639 dt = inR->getNextOccurence( cur, &ok ); 1639 dt = inR->getNextOccurence( cur, &ok );
1640 if ( !ok ) 1640 if ( !ok )
1641 dt = cur.addSecs( -62 ); 1641 dt = cur.addSecs( -62 );
1642 } 1642 }
1643 else 1643 else
1644 dt = inR->dtStart(); 1644 dt = inR->dtStart();
1645 if ( dt < cur || dt > end ) { 1645 if ( dt < cur || dt > end ) {
1646 remote->deleteIncidence( inR ); 1646 remote->deleteIncidence( inR );
1647 ++delFut; 1647 ++delFut;
1648 } 1648 }
1649 inR = er.next(); 1649 inR = er.next();
1650 } 1650 }
1651 } 1651 }
1652 bar.hide(); 1652 bar.hide();
1653 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1653 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1654 eventLSync->setReadOnly( false ); 1654 eventLSync->setReadOnly( false );
1655 eventLSync->setDtStart( mLastCalendarSync ); 1655 eventLSync->setDtStart( mLastCalendarSync );
1656 eventRSync->setDtStart( mLastCalendarSync ); 1656 eventRSync->setDtStart( mLastCalendarSync );
1657 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1657 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1658 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1658 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1659 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1659 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1660 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1660 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1661 eventLSync->setReadOnly( true ); 1661 eventLSync->setReadOnly( true );
1662 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1662 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1663 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1663 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1664 remote->addEvent( eventRSync ); 1664 remote->addEvent( eventRSync );
1665 else 1665 else
1666 delete eventRSync; 1666 delete eventRSync;
1667 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1667 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1668 QString mes; 1668 QString mes;
1669 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 ); 1669 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 );
1670 QString delmess; 1670 QString delmess;
1671 if ( delFut ) { 1671 if ( delFut ) {
1672 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); 1672 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);
1673 mes += delmess; 1673 mes += delmess;
1674 } 1674 }
1675 mes = i18n("Local calendar changed!\n") +mes; 1675 mes = i18n("Local calendar changed!\n") +mes;
1676 mCalendar->checkAlarmForIncidence( 0, true ); 1676 mCalendar->checkAlarmForIncidence( 0, true );
1677 qDebug( mes ); 1677 qDebug( mes );
1678 if ( mSyncManager->mShowSyncSummary ) { 1678 if ( mSyncManager->mShowSyncSummary ) {
1679 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1679 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1680 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1680 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1681 qDebug("KO: WB cancelled "); 1681 qDebug("KO: WB cancelled ");
1682 mSyncManager->mWriteBackFile = false; 1682 mSyncManager->mWriteBackFile = false;
1683 return syncOK; 1683 return syncOK;
1684 } 1684 }
1685 } 1685 }
1686 return syncOK; 1686 return syncOK;
1687} 1687}
1688 1688
1689void CalendarView::setSyncDevice( QString s ) 1689void CalendarView::setSyncDevice( QString s )
1690{ 1690{
1691 mCurrentSyncDevice= s; 1691 mCurrentSyncDevice= s;
1692} 1692}
1693void CalendarView::setSyncName( QString s ) 1693void CalendarView::setSyncName( QString s )
1694{ 1694{
1695 mCurrentSyncName= s; 1695 mCurrentSyncName= s;
1696} 1696}
1697bool CalendarView::syncCalendar(QString filename, int mode) 1697bool CalendarView::syncCalendar(QString filename, int mode)
1698{ 1698{
1699 //qDebug("syncCalendar %s ", filename.latin1()); 1699 //qDebug("syncCalendar %s ", filename.latin1());
1700 mGlobalSyncMode = SYNC_MODE_NORMAL; 1700 mGlobalSyncMode = SYNC_MODE_NORMAL;
1701 CalendarLocal* calendar = new CalendarLocal(); 1701 CalendarLocal* calendar = new CalendarLocal();
1702 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1702 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1703 FileStorage* storage = new FileStorage( calendar ); 1703 FileStorage* storage = new FileStorage( calendar );
1704 bool syncOK = false; 1704 bool syncOK = false;
1705 storage->setFileName( filename ); 1705 storage->setFileName( filename );
1706 // qDebug("loading ... "); 1706 // qDebug("loading ... ");
1707 if ( storage->load() ) { 1707 if ( storage->load() ) {
1708 getEventViewerDialog()->setSyncMode( true ); 1708 getEventViewerDialog()->setSyncMode( true );
1709 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1709 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1710 getEventViewerDialog()->setSyncMode( false ); 1710 getEventViewerDialog()->setSyncMode( false );
1711 if ( syncOK ) { 1711 if ( syncOK ) {
1712 if ( mSyncManager->mWriteBackFile ) 1712 if ( mSyncManager->mWriteBackFile )
1713 { 1713 {
1714 storage->setSaveFormat( new ICalFormat() ); 1714 storage->setSaveFormat( new ICalFormat() );
1715 storage->save(); 1715 storage->save();
1716 } 1716 }
1717 } 1717 }
1718 setModified( true ); 1718 setModified( true );
1719 } 1719 }
1720 delete storage; 1720 delete storage;
1721 delete calendar; 1721 delete calendar;
1722 if ( syncOK ) 1722 if ( syncOK )
1723 updateView(); 1723 updateView();
1724 return syncOK; 1724 return syncOK;
1725} 1725}
1726 1726
1727void CalendarView::syncExternal( int mode ) 1727void CalendarView::syncExternal( int mode )
1728{ 1728{
1729 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1729 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1730 1730
1731 qApp->processEvents(); 1731 qApp->processEvents();
1732 CalendarLocal* calendar = new CalendarLocal(); 1732 CalendarLocal* calendar = new CalendarLocal();
1733 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1733 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1734 bool syncOK = false; 1734 bool syncOK = false;
1735 bool loadSuccess = false; 1735 bool loadSuccess = false;
1736 PhoneFormat* phoneFormat = 0; 1736 PhoneFormat* phoneFormat = 0;
1737 emit tempDisableBR(true); 1737 emit tempDisableBR(true);
1738#ifndef DESKTOP_VERSION 1738#ifndef DESKTOP_VERSION
1739 SharpFormat* sharpFormat = 0; 1739 SharpFormat* sharpFormat = 0;
1740 if ( mode == 0 ) { // sharp 1740 if ( mode == 0 ) { // sharp
1741 sharpFormat = new SharpFormat () ; 1741 sharpFormat = new SharpFormat () ;
1742 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1742 loadSuccess = sharpFormat->load( calendar, mCalendar );
1743 1743
1744 } else 1744 } else
1745#endif 1745#endif
1746 if ( mode == 1 ) { // phone 1746 if ( mode == 1 ) { // phone
1747 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1747 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1748 mSyncManager->mPhoneDevice, 1748 mSyncManager->mPhoneDevice,
1749 mSyncManager->mPhoneConnection, 1749 mSyncManager->mPhoneConnection,
1750 mSyncManager->mPhoneModel); 1750 mSyncManager->mPhoneModel);
1751 loadSuccess = phoneFormat->load( calendar,mCalendar); 1751 loadSuccess = phoneFormat->load( calendar,mCalendar);
1752 1752
1753 } else { 1753 } else {
1754 emit tempDisableBR(false); 1754 emit tempDisableBR(false);
1755 return; 1755 return;
1756 } 1756 }
1757 if ( loadSuccess ) { 1757 if ( loadSuccess ) {
1758 getEventViewerDialog()->setSyncMode( true ); 1758 getEventViewerDialog()->setSyncMode( true );
1759 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1759 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1760 getEventViewerDialog()->setSyncMode( false ); 1760 getEventViewerDialog()->setSyncMode( false );
1761 qApp->processEvents(); 1761 qApp->processEvents();
1762 if ( syncOK ) { 1762 if ( syncOK ) {
1763 if ( mSyncManager->mWriteBackFile ) 1763 if ( mSyncManager->mWriteBackFile )
1764 { 1764 {
1765 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1765 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1766 Incidence* inc = iL.first(); 1766 Incidence* inc = iL.first();
1767 if ( phoneFormat ) { 1767 if ( phoneFormat ) {
1768 while ( inc ) { 1768 while ( inc ) {
1769 inc->removeID(mCurrentSyncDevice); 1769 inc->removeID(mCurrentSyncDevice);
1770 inc = iL.next(); 1770 inc = iL.next();
1771 } 1771 }
1772 } 1772 }
1773#ifndef DESKTOP_VERSION 1773#ifndef DESKTOP_VERSION
1774 if ( sharpFormat ) 1774 if ( sharpFormat )
1775 sharpFormat->save(calendar); 1775 sharpFormat->save(calendar);
1776#endif 1776#endif
1777 if ( phoneFormat ) 1777 if ( phoneFormat )
1778 phoneFormat->save(calendar); 1778 phoneFormat->save(calendar);
1779 iL = calendar->rawIncidences(); 1779 iL = calendar->rawIncidences();
1780 inc = iL.first(); 1780 inc = iL.first();
1781 Incidence* loc; 1781 Incidence* loc;
1782 while ( inc ) { 1782 while ( inc ) {
1783 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1783 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1784 loc = mCalendar->incidence(inc->uid() ); 1784 loc = mCalendar->incidence(inc->uid() );
1785 if ( loc ) { 1785 if ( loc ) {
1786 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1786 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1787 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1787 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1788 } 1788 }
1789 } 1789 }
1790 inc = iL.next(); 1790 inc = iL.next();
1791 } 1791 }
1792 Incidence* lse = getLastSyncEvent(); 1792 Incidence* lse = getLastSyncEvent();
1793 if ( lse ) { 1793 if ( lse ) {
1794 lse->setReadOnly( false ); 1794 lse->setReadOnly( false );
1795 lse->setDescription( "" ); 1795 lse->setDescription( "" );
1796 lse->setReadOnly( true ); 1796 lse->setReadOnly( true );
1797 } 1797 }
1798 } 1798 }
1799 } else { 1799 } else {
1800 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1800 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1801 } 1801 }
1802 setModified( true ); 1802 setModified( true );
1803 } else { 1803 } else {
1804 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1804 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1805 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1805 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1806 question, i18n("Ok")) ; 1806 question, i18n("Ok")) ;
1807 1807
1808 } 1808 }
1809 delete calendar; 1809 delete calendar;
1810 updateView(); 1810 updateView();
1811 emit tempDisableBR(false); 1811 emit tempDisableBR(false);
1812 return ;//syncOK; 1812 return ;//syncOK;
1813 1813
1814} 1814}
1815 1815
1816bool CalendarView::importBday() 1816bool CalendarView::importBday()
1817{ 1817{
1818#ifndef KORG_NOKABC 1818#ifndef KORG_NOKABC
1819 1819
1820#ifdef DESKTOP_VERSION 1820#ifdef DESKTOP_VERSION
1821 int curCal = mCalendar->defaultCalendar(); 1821 int curCal = mCalendar->defaultCalendar();
1822 int bd = mCalEditView->getBirtdayID(); 1822 int bd = mCalEditView->getBirtdayID();
1823 if ( bd == 0 ) 1823 if ( bd == 0 )
1824 return false; 1824 return false;
1825 mCalendar->setDefaultCalendar( bd ); 1825 mCalendar->setDefaultCalendar( bd );
1826 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1826 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1827 KABC::AddressBook::Iterator it; 1827 KABC::AddressBook::Iterator it;
1828 int count = 0; 1828 int count = 0;
1829 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1829 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1830 ++count; 1830 ++count;
1831 } 1831 }
1832 QProgressBar bar(count,0 ); 1832 QProgressBar bar(count,0 );
1833 int w = 300; 1833 int w = 300;
1834 if ( QApplication::desktop()->width() < 320 ) 1834 if ( QApplication::desktop()->width() < 320 )
1835 w = 220; 1835 w = 220;
1836 int h = bar.sizeHint().height() ; 1836 int h = bar.sizeHint().height() ;
1837 int dw = QApplication::desktop()->width(); 1837 int dw = QApplication::desktop()->width();
1838 int dh = QApplication::desktop()->height(); 1838 int dh = QApplication::desktop()->height();
1839 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1839 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1840 bar.show(); 1840 bar.show();
1841 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1841 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1842 qApp->processEvents(); 1842 qApp->processEvents();
1843 count = 0; 1843 count = 0;
1844 int addCount = 0; 1844 int addCount = 0;
1845 KCal::Attendee* a = 0; 1845 KCal::Attendee* a = 0;
1846 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1846 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1847 if ( ! bar.isVisible() ) 1847 if ( ! bar.isVisible() )
1848 return false; 1848 return false;
1849 bar.setProgress( count++ ); 1849 bar.setProgress( count++ );
1850 qApp->processEvents(); 1850 qApp->processEvents();
1851 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1851 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1852 if ( (*it).birthday().date().isValid() ){ 1852 if ( (*it).birthday().date().isValid() ){
1853 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1853 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1854 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1854 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1855 ++addCount; 1855 ++addCount;
1856 } 1856 }
1857 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1857 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1858 if ( anni.isValid() ){ 1858 if ( anni.isValid() ){
1859 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1859 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1860 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1860 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1861 ++addCount; 1861 ++addCount;
1862 } 1862 }
1863 } 1863 }
1864 mCalendar->setDefaultCalendar( curCal ); 1864 mCalendar->setDefaultCalendar( curCal );
1865 updateView(); 1865 updateView();
1866 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1866 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1867#else //DESKTOP_VERSION 1867#else //DESKTOP_VERSION
1868 1868
1869 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1869 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1870 // the result should now arrive through method insertBirthdays 1870 // the result should now arrive through method insertBirthdays
1871 1871
1872#endif //DESKTOP_VERSION 1872#endif //DESKTOP_VERSION
1873 1873
1874#endif //KORG_NOKABC 1874#endif //KORG_NOKABC
1875 1875
1876 1876
1877 return true; 1877 return true;
1878} 1878}
1879 1879
1880// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1880// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1881void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1881void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1882 const QStringList& anniversaryList, const QStringList& realNameList, 1882 const QStringList& anniversaryList, const QStringList& realNameList,
1883 const QStringList& emailList, const QStringList& assembledNameList, 1883 const QStringList& emailList, const QStringList& assembledNameList,
1884 const QStringList& uidList) 1884 const QStringList& uidList)
1885{ 1885{
1886 1886
1887 //qDebug("KO::CalendarView::insertBirthdays"); 1887 //qDebug("KO::CalendarView::insertBirthdays");
1888 if (uid == this->name()) 1888 if (uid == this->name())
1889 { 1889 {
1890 int curCal = mCalendar->defaultCalendar(); 1890 int curCal = mCalendar->defaultCalendar();
1891 int bd = mCalEditView->getBirtdayID(); 1891 int bd = mCalEditView->getBirtdayID();
1892 if ( bd == 0 ) 1892 if ( bd == 0 )
1893 return; 1893 return;
1894 mCalendar->setDefaultCalendar( bd ); 1894 mCalendar->setDefaultCalendar( bd );
1895 1895
1896 1896
1897 int count = birthdayList.count(); 1897 int count = birthdayList.count();
1898 int addCount = 0; 1898 int addCount = 0;
1899 KCal::Attendee* a = 0; 1899 KCal::Attendee* a = 0;
1900 1900
1901 //qDebug("CalView 1 %i", count); 1901 //qDebug("CalView 1 %i", count);
1902 1902
1903 QProgressBar bar(count,0 ); 1903 QProgressBar bar(count,0 );
1904 int w = 300; 1904 int w = 300;
1905 if ( QApplication::desktop()->width() < 320 ) 1905 if ( QApplication::desktop()->width() < 320 )
1906 w = 220; 1906 w = 220;
1907 int h = bar.sizeHint().height() ; 1907 int h = bar.sizeHint().height() ;
1908 int dw = QApplication::desktop()->width(); 1908 int dw = QApplication::desktop()->width();
1909 int dh = QApplication::desktop()->height(); 1909 int dh = QApplication::desktop()->height();
1910 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1910 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1911 bar.show(); 1911 bar.show();
1912 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1912 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1913 qApp->processEvents(); 1913 qApp->processEvents();
1914 1914
1915 QDate birthday; 1915 QDate birthday;
1916 QDate anniversary; 1916 QDate anniversary;
1917 QString realName; 1917 QString realName;
1918 QString email; 1918 QString email;
1919 QString assembledName; 1919 QString assembledName;
1920 QString uid; 1920 QString uid;
1921 bool ok = true; 1921 bool ok = true;
1922 for ( int i = 0; i < count; i++) 1922 for ( int i = 0; i < count; i++)
1923 { 1923 {
1924 if ( ! bar.isVisible() ) 1924 if ( ! bar.isVisible() )
1925 return; 1925 return;
1926 bar.setProgress( i ); 1926 bar.setProgress( i );
1927 qApp->processEvents(); 1927 qApp->processEvents();
1928 1928
1929 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1929 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1930 if (!ok) { 1930 if (!ok) {
1931 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1931 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1932 } 1932 }
1933 1933
1934 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1934 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1935 if (!ok) { 1935 if (!ok) {
1936 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1936 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1937 } 1937 }
1938 realName = realNameList[i]; 1938 realName = realNameList[i];
1939 email = emailList[i]; 1939 email = emailList[i];
1940 assembledName = assembledNameList[i]; 1940 assembledName = assembledNameList[i];
1941 uid = uidList[i]; 1941 uid = uidList[i];
1942 //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() ); 1942 //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() );
1943 1943
1944 if ( birthday.isValid() ){ 1944 if ( birthday.isValid() ){
1945 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1945 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1946 KCal::Attendee::ReqParticipant,uid) ; 1946 KCal::Attendee::ReqParticipant,uid) ;
1947 if ( addAnniversary( birthday, assembledName, a, true ) ) 1947 if ( addAnniversary( birthday, assembledName, a, true ) )
1948 ++addCount; 1948 ++addCount;
1949 } 1949 }
1950 1950
1951 if ( anniversary.isValid() ){ 1951 if ( anniversary.isValid() ){
1952 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1952 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1953 KCal::Attendee::ReqParticipant,uid) ; 1953 KCal::Attendee::ReqParticipant,uid) ;
1954 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1954 if ( addAnniversary( anniversary, assembledName, a, false ) )
1955 ++addCount; 1955 ++addCount;
1956 } 1956 }
1957 } 1957 }
1958 1958
1959 mCalendar->setDefaultCalendar( curCal ); 1959 mCalendar->setDefaultCalendar( curCal );
1960 updateView(); 1960 updateView();
1961 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1961 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1962 1962
1963 } 1963 }
1964 1964
1965} 1965}
1966 1966
1967 1967
1968 1968
1969bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1969bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1970{ 1970{
1971 //qDebug("addAnni "); 1971 //qDebug("addAnni ");
1972 Event * ev = new Event(); 1972 Event * ev = new Event();
1973 ev->setOrganizer(KOPrefs::instance()->email()); 1973 ev->setOrganizer(KOPrefs::instance()->email());
1974 if ( a ) { 1974 if ( a ) {
1975 ev->addAttendee( a ); 1975 ev->addAttendee( a );
1976 } 1976 }
1977 QString kind; 1977 QString kind;
1978 if ( birthday ) { 1978 if ( birthday ) {
1979 kind = i18n( "Birthday" ); 1979 kind = i18n( "Birthday" );
1980 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 1980 ev->setSummary( name + " (" + QString::number(date.year()) +")");
1981 } 1981 }
1982 else { 1982 else {
1983 kind = i18n( "Anniversary" ); 1983 kind = i18n( "Anniversary" );
1984 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 1984 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
1985 } 1985 }
1986 ev->setCategories( kind ); 1986 ev->setCategories( kind );
1987 ev->setDtStart( QDateTime(date) ); 1987 ev->setDtStart( QDateTime(date) );
1988 ev->setDtEnd( QDateTime(date) ); 1988 ev->setDtEnd( QDateTime(date) );
1989 ev->setFloats( true ); 1989 ev->setFloats( true );
1990 Recurrence * rec = ev->recurrence(); 1990 Recurrence * rec = ev->recurrence();
1991 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1991 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1992 rec->addYearlyNum( date.month() ); 1992 rec->addYearlyNum( date.month() );
1993 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1993 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1994 delete ev; 1994 delete ev;
1995 return false; 1995 return false;
1996 } 1996 }
1997 return true; 1997 return true;
1998 1998
1999} 1999}
2000bool CalendarView::importQtopia( const QString &categories, 2000bool CalendarView::importQtopia( const QString &categories,
2001 const QString &datebook, 2001 const QString &datebook,
2002 const QString &todolist ) 2002 const QString &todolist )
2003{ 2003{
2004 2004
2005 QtopiaFormat qtopiaFormat; 2005 QtopiaFormat qtopiaFormat;
2006 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 2006 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
2007 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 2007 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
2008 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 2008 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
2009 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 2009 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
2010 2010
2011 updateView(); 2011 updateView();
2012 return true; 2012 return true;
2013 2013
2014#if 0 2014#if 0
2015 mGlobalSyncMode = SYNC_MODE_QTOPIA; 2015 mGlobalSyncMode = SYNC_MODE_QTOPIA;
2016 mCurrentSyncDevice = "qtopia-XML"; 2016 mCurrentSyncDevice = "qtopia-XML";
2017 if ( mSyncManager->mAskForPreferences ) 2017 if ( mSyncManager->mAskForPreferences )
2018 edit_sync_options(); 2018 edit_sync_options();
2019 qApp->processEvents(); 2019 qApp->processEvents();
2020 CalendarLocal* calendar = new CalendarLocal(); 2020 CalendarLocal* calendar = new CalendarLocal();
2021 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2021 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2022 bool syncOK = false; 2022 bool syncOK = false;
2023 QtopiaFormat qtopiaFormat; 2023 QtopiaFormat qtopiaFormat;
2024 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 2024 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
2025 bool loadOk = true; 2025 bool loadOk = true;
2026 if ( !categories.isEmpty() ) 2026 if ( !categories.isEmpty() )
2027 loadOk = qtopiaFormat.load( calendar, categories ); 2027 loadOk = qtopiaFormat.load( calendar, categories );
2028 if ( loadOk && !datebook.isEmpty() ) 2028 if ( loadOk && !datebook.isEmpty() )
2029 loadOk = qtopiaFormat.load( calendar, datebook ); 2029 loadOk = qtopiaFormat.load( calendar, datebook );
2030 if ( loadOk && !todolist.isEmpty() ) 2030 if ( loadOk && !todolist.isEmpty() )
2031 loadOk = qtopiaFormat.load( calendar, todolist ); 2031 loadOk = qtopiaFormat.load( calendar, todolist );
2032 2032
2033 if ( loadOk ) { 2033 if ( loadOk ) {
2034 getEventViewerDialog()->setSyncMode( true ); 2034 getEventViewerDialog()->setSyncMode( true );
2035 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 2035 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
2036 getEventViewerDialog()->setSyncMode( false ); 2036 getEventViewerDialog()->setSyncMode( false );
2037 qApp->processEvents(); 2037 qApp->processEvents();
2038 if ( syncOK ) { 2038 if ( syncOK ) {
2039 if ( mSyncManager->mWriteBackFile ) 2039 if ( mSyncManager->mWriteBackFile )
2040 { 2040 {
2041 // write back XML file 2041 // write back XML file
2042 2042
2043 } 2043 }
2044 setModified( true ); 2044 setModified( true );
2045 } 2045 }
2046 } else { 2046 } else {
2047 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 2047 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
2048 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 2048 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
2049 question, i18n("Ok")) ; 2049 question, i18n("Ok")) ;
2050 } 2050 }
2051 delete calendar; 2051 delete calendar;
2052 updateView(); 2052 updateView();
2053 return syncOK; 2053 return syncOK;
2054 2054
2055 2055
2056#endif 2056#endif
2057 2057
2058} 2058}
2059 2059
2060void CalendarView::setSyncEventsReadOnly() 2060void CalendarView::setSyncEventsReadOnly()
2061{ 2061{
2062 mCalendar->setSyncEventsReadOnly(); 2062 mCalendar->setSyncEventsReadOnly();
2063} 2063}
2064 2064
2065bool CalendarView::loadCalendars() 2065bool CalendarView::loadCalendars()
2066{ 2066{
2067 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2067 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2068 KopiCalendarFile * cal = calendars.first(); 2068 KopiCalendarFile * cal = calendars.first();
2069 mCalendar->setDefaultCalendar( 1 ); 2069 mCalendar->setDefaultCalendar( 1 );
2070 openCalendar( MainWindow::defaultFileName(), false ); 2070 openCalendar( MainWindow::defaultFileName(), false );
2071 cal = calendars.next(); 2071 cal = calendars.next();
2072 while ( cal ) { 2072 while ( cal ) {
2073 addCalendar( cal ); 2073 addCalendar( cal );
2074 cal = calendars.next(); 2074 cal = calendars.next();
2075 } 2075 }
2076 restoreCalendarSettings(); 2076 restoreCalendarSettings();
2077 return true; 2077 return true;
2078} 2078}
2079bool CalendarView::restoreCalendarSettings() 2079bool CalendarView::restoreCalendarSettings()
2080{ 2080{
2081 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2081 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2082 KopiCalendarFile * cal = calendars.first(); 2082 KopiCalendarFile * cal = calendars.first();
2083 while ( cal ) { 2083 while ( cal ) {
2084 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); 2084 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled );
2085 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); 2085 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled );
2086 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); 2086 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly );
2087 if ( cal->isStandard ) 2087 if ( cal->isStandard )
2088 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2088 mCalendar->setDefaultCalendar( cal->mCalNumber );
2089 cal = calendars.next(); 2089 cal = calendars.next();
2090 } 2090 }
2091 setSyncEventsReadOnly(); 2091 setSyncEventsReadOnly();
2092 mCalendar->reInitAlarmSettings(); 2092 mCalendar->reInitAlarmSettings();
2093 updateUnmanagedViews(); 2093 updateUnmanagedViews();
2094 updateView(); 2094 updateView();
2095 return true; 2095 return true;
2096} 2096}
2097void CalendarView::addCalendarId( int id ) 2097void CalendarView::addCalendarId( int id )
2098{ 2098{
2099 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); 2099 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id );
2100 if ( cal ) 2100 if ( cal )
2101 addCalendar( cal ); 2101 addCalendar( cal );
2102} 2102}
2103bool CalendarView::addCalendar( KopiCalendarFile * cal ) 2103bool CalendarView::addCalendar( KopiCalendarFile * cal )
2104{ 2104{
2105 cal->mErrorOnLoad = false; 2105 cal->mErrorOnLoad = false;
2106 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { 2106 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) {
2107 cal->mLoadDt = QDateTime::currentDateTime(); 2107 cal->mLoadDt = QDateTime::currentDateTime();
2108 return true; 2108 return true;
2109 } 2109 }
2110 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() ); 2110 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() );
2111 cal->mErrorOnLoad = true; 2111 cal->mErrorOnLoad = true;
2112 return false; 2112 return false;
2113} 2113}
2114bool CalendarView::openCalendar(QString filename, bool merge) 2114bool CalendarView::openCalendar(QString filename, bool merge)
2115{ 2115{
2116 2116
2117 if (filename.isEmpty()) { 2117 if (filename.isEmpty()) {
2118 return false; 2118 return false;
2119 } 2119 }
2120 2120
2121 if (!QFile::exists(filename)) { 2121 if (!QFile::exists(filename)) {
2122 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 2122 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
2123 return false; 2123 return false;
2124 } 2124 }
2125 2125
2126 globalFlagBlockAgenda = 1; 2126 globalFlagBlockAgenda = 1;
2127 clearAllViews(); 2127 clearAllViews();
2128 if (!merge) { 2128 if (!merge) {
2129 mViewManager->setDocumentId( filename ); 2129 mViewManager->setDocumentId( filename );
2130 mCalendar->close(); 2130 mCalendar->close();
2131 } 2131 }
2132 mStorage->setFileName( filename ); 2132 mStorage->setFileName( filename );
2133 2133
2134 if ( mStorage->load() ) { 2134 if ( mStorage->load() ) {
2135 if ( merge ) ;//setModified( true ); 2135 if ( merge ) ;//setModified( true );
2136 else { 2136 else {
2137 //setModified( true ); 2137 //setModified( true );
2138 mViewManager->setDocumentId( filename ); 2138 mViewManager->setDocumentId( filename );
2139 mDialogManager->setDocumentId( filename ); 2139 mDialogManager->setDocumentId( filename );
2140 mTodoList->setDocumentId( filename ); 2140 mTodoList->setDocumentId( filename );
2141 } 2141 }
2142 globalFlagBlockAgenda = 2; 2142 globalFlagBlockAgenda = 2;
2143 // if ( getLastSyncEvent() ) 2143 // if ( getLastSyncEvent() )
2144 // getLastSyncEvent()->setReadOnly( true ); 2144 // getLastSyncEvent()->setReadOnly( true );
2145 mCalendar->reInitAlarmSettings(); 2145 mCalendar->reInitAlarmSettings();
2146 setSyncEventsReadOnly(); 2146 setSyncEventsReadOnly();
2147 updateUnmanagedViews(); 2147 updateUnmanagedViews();
2148 updateView(); 2148 updateView();
2149 if ( filename != MainWindow::defaultFileName() ) { 2149 if ( filename != MainWindow::defaultFileName() ) {
2150 saveCalendar( MainWindow::defaultFileName() ); 2150 saveCalendar( MainWindow::defaultFileName() );
2151 } else { 2151 } else {
2152 QFileInfo finf ( MainWindow::defaultFileName()); 2152 QFileInfo finf ( MainWindow::defaultFileName());
2153 if ( finf.exists() ) { 2153 if ( finf.exists() ) {
2154 setLoadedFileVersion( finf.lastModified () ); 2154 setLoadedFileVersion( finf.lastModified () );
2155 } 2155 }
2156 } 2156 }
2157 return true; 2157 return true;
2158 } else { 2158 } else {
2159 // while failing to load, the calendar object could 2159 // while failing to load, the calendar object could
2160 // have become partially populated. Clear it out. 2160 // have become partially populated. Clear it out.
2161 if ( !merge ) { 2161 if ( !merge ) {
2162 mCalendar->close(); 2162 mCalendar->close();
2163 mViewManager->setDocumentId( filename ); 2163 mViewManager->setDocumentId( filename );
2164 mDialogManager->setDocumentId( filename ); 2164 mDialogManager->setDocumentId( filename );
2165 mTodoList->setDocumentId( filename ); 2165 mTodoList->setDocumentId( filename );
2166 } 2166 }
2167 2167
2168 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 2168 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
2169 2169
2170 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 2170 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
2171 globalFlagBlockAgenda = 2; 2171 globalFlagBlockAgenda = 2;
2172 mCalendar->reInitAlarmSettings(); 2172 mCalendar->reInitAlarmSettings();
2173 setSyncEventsReadOnly(); 2173 setSyncEventsReadOnly();
2174 updateUnmanagedViews(); 2174 updateUnmanagedViews();
2175 updateView(); 2175 updateView();
2176 } 2176 }
2177 return false; 2177 return false;
2178} 2178}
2179void CalendarView::mergeFile( QString fn ) 2179void CalendarView::mergeFile( QString fn )
2180{ 2180{
2181 clearAllViews(); 2181 clearAllViews();
2182 mCalendar->mergeCalendarFile( fn ); 2182 mCalendar->mergeCalendarFile( fn );
2183 mCalendar->reInitAlarmSettings(); 2183 mCalendar->reInitAlarmSettings();
2184 setSyncEventsReadOnly(); 2184 setSyncEventsReadOnly();
2185 updateUnmanagedViews(); 2185 updateUnmanagedViews();
2186 updateView(); 2186 updateView();
2187} 2187}
2188void CalendarView::showOpenError() 2188void CalendarView::showOpenError()
2189{ 2189{
2190 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 2190 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
2191} 2191}
2192void CalendarView::setLoadedFileVersion(QDateTime dt) 2192void CalendarView::setLoadedFileVersion(QDateTime dt)
2193{ 2193{
2194 loadedFileVersion = dt; 2194 loadedFileVersion = dt;
2195} 2195}
2196bool CalendarView::checkFileChanged(QString fn) 2196bool CalendarView::checkFileChanged(QString fn)
2197{ 2197{
2198 QFileInfo finf ( fn ); 2198 QFileInfo finf ( fn );
2199 if ( !finf.exists() ) 2199 if ( !finf.exists() )
2200 return true; 2200 return true;
2201 QDateTime dt = finf.lastModified (); 2201 QDateTime dt = finf.lastModified ();
2202 if ( dt <= loadedFileVersion ) 2202 if ( dt <= loadedFileVersion )
2203 return false; 2203 return false;
2204 return true; 2204 return true;
2205 2205
2206} 2206}
2207void CalendarView::watchSavedFile() 2207void CalendarView::watchSavedFile()
2208{ 2208{
2209 QFileInfo finf ( MainWindow::defaultFileName()); 2209 QFileInfo finf ( MainWindow::defaultFileName());
2210 if ( !finf.exists() ) 2210 if ( !finf.exists() )
2211 return; 2211 return;
2212 QDateTime dt = finf.lastModified (); 2212 QDateTime dt = finf.lastModified ();
2213 if ( dt < loadedFileVersion ) { 2213 if ( dt < loadedFileVersion ) {
2214 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 2214 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
2215 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 2215 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
2216 return; 2216 return;
2217 } 2217 }
2218 loadedFileVersion = dt; 2218 loadedFileVersion = dt;
2219} 2219}
2220bool CalendarView::checkAllFileVersions() 2220bool CalendarView::checkAllFileVersions()
2221{ 2221{
2222 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2222 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2223 KopiCalendarFile * cal = calendars.first(); 2223 KopiCalendarFile * cal = calendars.first();
2224 mCalendar->setDefaultCalendar( 1 ); 2224 mCalendar->setDefaultCalendar( 1 );
2225 mCalendar->setDefaultCalendarEnabledOnly(); 2225 mCalendar->setDefaultCalendarEnabledOnly();
2226 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2226 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2227 if ( !checkFileVersion(MainWindow::defaultFileName())) { 2227 if ( !checkFileVersion(MainWindow::defaultFileName())) {
2228 restoreCalendarSettings(); 2228 restoreCalendarSettings();
2229 return false; 2229 return false;
2230 } 2230 }
2231 } 2231 }
2232 cal = calendars.next(); 2232 cal = calendars.next();
2233 QDateTime storeTemp = loadedFileVersion; 2233 QDateTime storeTemp = loadedFileVersion;
2234 while ( cal ) { 2234 while ( cal ) {
2235 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2235 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2236 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2236 mCalendar->setDefaultCalendar( cal->mCalNumber );
2237 mCalendar->setDefaultCalendarEnabledOnly(); 2237 mCalendar->setDefaultCalendarEnabledOnly();
2238 loadedFileVersion = cal->mLoadDt.addSecs( 15 ); 2238 loadedFileVersion = cal->mLoadDt.addSecs( 15 );
2239 if ( !checkFileVersion(cal->mFileName )) { 2239 if ( !checkFileVersion(cal->mFileName )) {
2240 loadedFileVersion = storeTemp; 2240 loadedFileVersion = storeTemp;
2241 restoreCalendarSettings(); 2241 restoreCalendarSettings();
2242 return false; 2242 return false;
2243 } 2243 }
2244 } 2244 }
2245 cal = calendars.next(); 2245 cal = calendars.next();
2246 } 2246 }
2247 loadedFileVersion = storeTemp; 2247 loadedFileVersion = storeTemp;
2248 return true; 2248 return true;
2249} 2249}
2250bool CalendarView::checkFileVersion(QString fn) 2250bool CalendarView::checkFileVersion(QString fn)
2251{ 2251{
2252 QFileInfo finf ( fn ); 2252 QFileInfo finf ( fn );
2253 if ( !finf.exists() ) 2253 if ( !finf.exists() )
2254 return true; 2254 return true;
2255 QDateTime dt = finf.lastModified (); 2255 QDateTime dt = finf.lastModified ();
2256 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); 2256 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1());
2257 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); 2257 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1());
2258 if ( dt <= loadedFileVersion ) 2258 if ( dt <= loadedFileVersion )
2259 return true; 2259 return true;
2260 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)) , 2260 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)) ,
2261 i18n("KO/Pi Warning"),i18n("Overwrite"), 2261 i18n("KO/Pi Warning"),i18n("Overwrite"),
2262 i18n("Sync+save")); 2262 i18n("Sync+save"));
2263 2263
2264 if ( km == KMessageBox::Cancel ) 2264 if ( km == KMessageBox::Cancel )
2265 return false; 2265 return false;
2266 if ( km == KMessageBox::Yes ) 2266 if ( km == KMessageBox::Yes )
2267 return true; 2267 return true;
2268 2268
2269 setSyncDevice("deleteaftersync" ); 2269 setSyncDevice("deleteaftersync" );
2270 mSyncManager->mAskForPreferences = true; 2270 mSyncManager->mAskForPreferences = true;
2271 mSyncManager->mSyncAlgoPrefs = 3; 2271 mSyncManager->mSyncAlgoPrefs = 3;
2272 mSyncManager->mWriteBackFile = false; 2272 mSyncManager->mWriteBackFile = false;
2273 mSyncManager->mWriteBackExistingOnly = false; 2273 mSyncManager->mWriteBackExistingOnly = false;
2274 mSyncManager->mShowSyncSummary = false; 2274 mSyncManager->mShowSyncSummary = false;
2275 syncCalendar( fn, 3 ); 2275 syncCalendar( fn, 3 );
2276 Event * e = getLastSyncEvent(); 2276 Event * e = getLastSyncEvent();
2277 if ( e ) 2277 if ( e )
2278 mCalendar->deleteEvent( e ); 2278 mCalendar->deleteEvent( e );
2279 return true; 2279 return true;
2280} 2280}
2281bool CalendarView::saveCalendars() 2281bool CalendarView::saveCalendars()
2282{ 2282{
2283 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2283 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2284 KopiCalendarFile * cal = calendars.first(); 2284 KopiCalendarFile * cal = calendars.first();
2285 mCalendar->setDefaultCalendar( 1 ); 2285 mCalendar->setDefaultCalendar( 1 );
2286 mCalendar->setDefaultCalendarEnabledOnly(); 2286 mCalendar->setDefaultCalendarEnabledOnly();
2287 saveCalendar( MainWindow::defaultFileName() ); 2287 saveCalendar( MainWindow::defaultFileName() );
2288 cal = calendars.next(); 2288 cal = calendars.next();
2289 while ( cal ) { 2289 while ( cal ) {
2290 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2290 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2291 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2291 mCalendar->setDefaultCalendar( cal->mCalNumber );
2292 mCalendar->setDefaultCalendarEnabledOnly(); 2292 mCalendar->setDefaultCalendarEnabledOnly();
2293 if ( saveCalendar( cal->mFileName ) ) 2293 if ( saveCalendar( cal->mFileName ) )
2294 cal->mLoadDt = QDateTime::currentDateTime(); 2294 cal->mLoadDt = QDateTime::currentDateTime();
2295 } 2295 }
2296 cal = calendars.next(); 2296 cal = calendars.next();
2297 } 2297 }
2298 restoreCalendarSettings(); 2298 restoreCalendarSettings();
2299 return true; 2299 return true;
2300} 2300}
2301bool CalendarView::saveCalendar( QString filename ) 2301bool CalendarView::saveCalendar( QString filename )
2302{ 2302{
2303 2303
2304 // Store back all unsaved data into calendar object 2304 // Store back all unsaved data into calendar object
2305 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 2305 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
2306 if ( mViewManager->currentView() ) 2306 if ( mViewManager->currentView() )
2307 mViewManager->currentView()->flushView(); 2307 mViewManager->currentView()->flushView();
2308 2308
2309 2309
2310 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 2310 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
2311 mStorage->setSaveFormat( new ICalFormat() ); 2311 mStorage->setSaveFormat( new ICalFormat() );
2312 mStorage->setFileName( filename ); 2312 mStorage->setFileName( filename );
2313 bool success; 2313 bool success;
2314 success = mStorage->save(); 2314 success = mStorage->save();
2315 if ( !success ) { 2315 if ( !success ) {
2316 return false; 2316 return false;
2317 } 2317 }
2318 if ( filename == MainWindow::defaultFileName() ) { 2318 if ( filename == MainWindow::defaultFileName() ) {
2319 setLoadedFileVersion( lfv ); 2319 setLoadedFileVersion( lfv );
2320 watchSavedFile(); 2320 watchSavedFile();
2321 } 2321 }
2322 return true; 2322 return true;
2323} 2323}
2324 2324
2325void CalendarView::closeCalendar() 2325void CalendarView::closeCalendar()
2326{ 2326{
2327 2327
2328 // child windows no longer valid 2328 // child windows no longer valid
2329 clearAllViews(); 2329 clearAllViews();
2330 emit closingDown(); 2330 emit closingDown();
2331 2331
2332 mCalendar->close(); 2332 mCalendar->close();
2333 setModified(false); 2333 setModified(false);
2334 updateView(); 2334 updateView();
2335} 2335}
2336 2336
2337void CalendarView::archiveCalendar() 2337void CalendarView::archiveCalendar()
2338{ 2338{
2339 mDialogManager->showArchiveDialog(); 2339 mDialogManager->showArchiveDialog();
2340} 2340}
2341 2341
2342 2342
2343void CalendarView::readSettings() 2343void CalendarView::readSettings()
2344{ 2344{
2345 2345
2346 2346
2347 // mViewManager->showAgendaView(); 2347 // mViewManager->showAgendaView();
2348 QString str; 2348 QString str;
2349 //qDebug("CalendarView::readSettings() "); 2349 //qDebug("CalendarView::readSettings() ");
2350 // read settings from the KConfig, supplying reasonable 2350 // read settings from the KConfig, supplying reasonable
2351 // defaults where none are to be found 2351 // defaults where none are to be found
2352 KConfig *config = KOGlobals::config(); 2352 KConfig *config = KOGlobals::config();
2353#ifndef KORG_NOSPLITTER 2353#ifndef KORG_NOSPLITTER
2354 config->setGroup("KOrganizer Geometry"); 2354 config->setGroup("KOrganizer Geometry");
2355 2355
2356 QValueList<int> sizes = config->readIntListEntry("Separator1"); 2356 QValueList<int> sizes = config->readIntListEntry("Separator1");
2357 if (sizes.count() != 2) { 2357 if (sizes.count() != 2) {
2358 sizes << mDateNavigator->minimumSizeHint().width(); 2358 sizes << mDateNavigator->minimumSizeHint().width();
2359 sizes << 300; 2359 sizes << 300;
2360 } 2360 }
2361 mPanner->setSizes(sizes); 2361 mPanner->setSizes(sizes);
2362 2362
2363 sizes = config->readIntListEntry("Separator2"); 2363 sizes = config->readIntListEntry("Separator2");
2364 if ( ( mResourceView && sizes.count() == 4 ) || 2364 if ( ( mResourceView && sizes.count() == 4 ) ||
2365 ( !mResourceView && sizes.count() == 3 ) ) { 2365 ( !mResourceView && sizes.count() == 3 ) ) {
2366 mLeftSplitter->setSizes(sizes); 2366 mLeftSplitter->setSizes(sizes);
2367 } 2367 }
2368#endif 2368#endif
2369 globalFlagBlockAgenda = 1; 2369 globalFlagBlockAgenda = 1;
2370 mViewManager->showAgendaView(); 2370 mViewManager->showAgendaView();
2371 //mViewManager->readSettings( config ); 2371 //mViewManager->readSettings( config );
2372 mTodoList->restoreLayout(config,QString("Todo Layout")); 2372 mTodoList->restoreLayout(config,QString("Todo Layout"));
2373 readFilterSettings(config); 2373 readFilterSettings(config);
2374 2374
2375#ifdef DESKTOP_VERSION 2375#ifdef DESKTOP_VERSION
2376 config->setGroup("WidgetLayout"); 2376 config->setGroup("WidgetLayout");
2377 QStringList list; 2377 QStringList list;
2378 list = config->readListEntry("MainLayout"); 2378 list = config->readListEntry("MainLayout");
2379 int x,y,w,h; 2379 int x,y,w,h;
2380 if ( ! list.isEmpty() ) { 2380 if ( ! list.isEmpty() ) {
2381 x = list[0].toInt(); 2381 x = list[0].toInt();
2382 y = list[1].toInt(); 2382 y = list[1].toInt();
2383 w = list[2].toInt(); 2383 w = list[2].toInt();
2384 h = list[3].toInt(); 2384 h = list[3].toInt();
2385 KApplication::testCoords( &x,&y,&w,&h ); 2385 KApplication::testCoords( &x,&y,&w,&h );
2386 topLevelWidget()->setGeometry(x,y,w,h); 2386 topLevelWidget()->setGeometry(x,y,w,h);
2387 2387
2388 } else { 2388 } else {
2389 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 2389 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
2390 } 2390 }
2391 list = config->readListEntry("EditEventLayout"); 2391 list = config->readListEntry("EditEventLayout");
2392 if ( ! list.isEmpty() ) { 2392 if ( ! list.isEmpty() ) {
2393 x = list[0].toInt(); 2393 x = list[0].toInt();
2394 y = list[1].toInt(); 2394 y = list[1].toInt();
2395 w = list[2].toInt(); 2395 w = list[2].toInt();
2396 h = list[3].toInt(); 2396 h = list[3].toInt();
2397 KApplication::testCoords( &x,&y,&w,&h ); 2397 KApplication::testCoords( &x,&y,&w,&h );
2398 mEventEditor->setGeometry(x,y,w,h); 2398 mEventEditor->setGeometry(x,y,w,h);
2399 2399
2400 } 2400 }
2401 list = config->readListEntry("EditTodoLayout"); 2401 list = config->readListEntry("EditTodoLayout");
2402 if ( ! list.isEmpty() ) { 2402 if ( ! list.isEmpty() ) {
2403 x = list[0].toInt(); 2403 x = list[0].toInt();
2404 y = list[1].toInt(); 2404 y = list[1].toInt();
2405 w = list[2].toInt(); 2405 w = list[2].toInt();
2406 h = list[3].toInt(); 2406 h = list[3].toInt();
2407 KApplication::testCoords( &x,&y,&w,&h ); 2407 KApplication::testCoords( &x,&y,&w,&h );
2408 mTodoEditor->setGeometry(x,y,w,h); 2408 mTodoEditor->setGeometry(x,y,w,h);
2409 2409
2410 } 2410 }
2411 list = config->readListEntry("ViewerLayout"); 2411 list = config->readListEntry("ViewerLayout");
2412 if ( ! list.isEmpty() ) { 2412 if ( ! list.isEmpty() ) {
2413 x = list[0].toInt(); 2413 x = list[0].toInt();
2414 y = list[1].toInt(); 2414 y = list[1].toInt();
2415 w = list[2].toInt(); 2415 w = list[2].toInt();
2416 h = list[3].toInt(); 2416 h = list[3].toInt();
2417 KApplication::testCoords( &x,&y,&w,&h ); 2417 KApplication::testCoords( &x,&y,&w,&h );
2418 getEventViewerDialog()->setGeometry(x,y,w,h); 2418 getEventViewerDialog()->setGeometry(x,y,w,h);
2419 } 2419 }
2420#endif 2420#endif
2421 config->setGroup( "Views" ); 2421 config->setGroup( "Views" );
2422 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 2422 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
2423 2423
2424 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame"); 2424 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame");
2425 2425
2426 int resetval = 0; 2426 int resetval = 0;
2427 int maxVal = 0; 2427 int maxVal = 0;
2428 if (sizes.count() != 3) { 2428 if (sizes.count() != 3) {
2429 if ( KOPrefs::instance()->mVerticalScreen ) { 2429 if ( KOPrefs::instance()->mVerticalScreen ) {
2430 resetval = mDateNavigator->sizeHint().width()+2; 2430 resetval = mDateNavigator->sizeHint().width()+2;
2431 } else { 2431 } else {
2432 resetval = mDateNavigator->sizeHint().height()+2; 2432 resetval = mDateNavigator->sizeHint().height()+2;
2433 } 2433 }
2434 } 2434 }
2435 if ( resetval ) { 2435 if ( resetval ) {
2436 sizes.clear(); 2436 sizes.clear();
2437 if ( KOPrefs::instance()->mVerticalScreen ) { 2437 if ( KOPrefs::instance()->mVerticalScreen ) {
2438 maxVal = QApplication::desktop()->width() -10; 2438 maxVal = QApplication::desktop()->width() -10;
2439 } else { 2439 } else {
2440 maxVal = QApplication::desktop()->height()-10; 2440 maxVal = QApplication::desktop()->height()-10;
2441 } 2441 }
2442 sizes << resetval; 2442 sizes << resetval;
2443 if ( maxVal < resetval + resetval) 2443 if ( maxVal < resetval + resetval)
2444 resetval = maxVal - resetval; 2444 resetval = maxVal - resetval;
2445 sizes << resetval; 2445 sizes << resetval;
2446 sizes << 100; 2446 sizes << 100;
2447 } 2447 }
2448 mLeftFrame->setSizes(sizes); 2448 mLeftFrame->setSizes(sizes);
2449 sizes = config->readIntListEntry("Main Splitter Frame"); 2449 sizes = config->readIntListEntry("Main Splitter Frame");
2450 resetval = 0; 2450 resetval = 0;
2451 maxVal = 0; 2451 maxVal = 0;
2452 if (sizes.count() != 2) { 2452 if (sizes.count() != 2) {
2453 if ( !KOPrefs::instance()->mVerticalScreen ) { 2453 if ( !KOPrefs::instance()->mVerticalScreen ) {
2454 resetval = mDateNavigator->sizeHint().width()+2; 2454 resetval = mDateNavigator->sizeHint().width()+2;
2455 } else { 2455 } else {
2456 resetval = mDateNavigator->sizeHint().height()+2; 2456 resetval = mDateNavigator->sizeHint().height()+2;
2457 } 2457 }
2458 } 2458 }
2459 if ( resetval ) { 2459 if ( resetval ) {
2460 sizes.clear(); 2460 sizes.clear();
2461 if ( !KOPrefs::instance()->mVerticalScreen ) { 2461 if ( !KOPrefs::instance()->mVerticalScreen ) {
2462 maxVal = QApplication::desktop()->width() -10; 2462 maxVal = QApplication::desktop()->width() -10;
2463 } else { 2463 } else {
2464 maxVal = QApplication::desktop()->height()-10; 2464 maxVal = QApplication::desktop()->height()-10;
2465 } 2465 }
2466 sizes << resetval; 2466 sizes << resetval;
2467 if ( maxVal < resetval + resetval) 2467 if ( maxVal < resetval + resetval)
2468 resetval = maxVal - resetval; 2468 resetval = maxVal - resetval;
2469 sizes << resetval; 2469 sizes << resetval;
2470 } 2470 }
2471 mMainFrame->setSizes(sizes); 2471 mMainFrame->setSizes(sizes);
2472 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 2472 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
2473 else if ( dateCount == 7 ) mNavigator->selectWeek(); 2473 else if ( dateCount == 7 ) mNavigator->selectWeek();
2474 else mNavigator->selectDates( dateCount ); 2474 else mNavigator->selectDates( dateCount );
2475 // mViewManager->readSettings( config ); 2475 // mViewManager->readSettings( config );
2476 updateConfig(); 2476 updateConfig();
2477 globalFlagBlockAgenda = 2; 2477 globalFlagBlockAgenda = 2;
2478 mViewManager->readSettings( config ); 2478 mViewManager->readSettings( config );
2479 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) ); 2479 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) );
2480} 2480}
2481 2481
2482void CalendarView::checkSuspendAlarm() 2482void CalendarView::checkSuspendAlarm()
2483{ 2483{
2484 if ( mSuspendTimer->isActive() ) { 2484 if ( mSuspendTimer->isActive() ) {
2485 KMessageBox::information( this, i18n("<b>WARNING:</b> There is a pending suspended alarm!"), i18n("Pending Suspend Alarm")); 2485 KMessageBox::information( this, i18n("<b>WARNING:</b> There is a pending suspended alarm!"), i18n("Pending Suspend Alarm"));
2486 } 2486 }
2487} 2487}
2488void CalendarView::writeSettings() 2488void CalendarView::writeSettings()
2489{ 2489{
2490 // kdDebug() << "CalendarView::writeSettings" << endl; 2490 // kdDebug() << "CalendarView::writeSettings" << endl;
2491 2491
2492 KConfig *config = KOGlobals::config(); 2492 KConfig *config = KOGlobals::config();
2493 2493
2494 mViewManager->writeSettings( config ); 2494 mViewManager->writeSettings( config );
2495 mTodoList->saveLayout(config,QString("Todo Layout")); 2495 mTodoList->saveLayout(config,QString("Todo Layout"));
2496 mDialogManager->writeSettings( config ); 2496 mDialogManager->writeSettings( config );
2497 //KOPrefs::instance()->usrWriteConfig(); 2497 //KOPrefs::instance()->usrWriteConfig();
2498 KOPrefs::instance()->writeConfig(); 2498 KOPrefs::instance()->writeConfig();
2499 2499
2500 writeFilterSettings(config); 2500 writeFilterSettings(config);
2501 config->setGroup( "AppRun" ); 2501 config->setGroup( "AppRun" );
2502 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 2502 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
2503 int days = dt.daysTo( QDate::currentDate() ); 2503 int days = dt.daysTo( QDate::currentDate() );
2504 dt = dt.addDays( days ); 2504 dt = dt.addDays( days );
2505 int secs = dt.secsTo( QDateTime::currentDateTime() ); 2505 int secs = dt.secsTo( QDateTime::currentDateTime() );
2506 config->writeEntry( "LatestProgramStopDays", days ); 2506 config->writeEntry( "LatestProgramStopDays", days );
2507 config->writeEntry( "LatestProgramStopSecs", secs ); 2507 config->writeEntry( "LatestProgramStopSecs", secs );
2508 //qDebug("KO: Writing stop time: %d ", secs); 2508 //qDebug("KO: Writing stop time: %d ", secs);
2509 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 2509 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
2510 //QDateTime latest = dt.addSecs ( secs ); 2510 //QDateTime latest = dt.addSecs ( secs );
2511 //qDebug("KO: Termination on %s ", latest.toString().latin1()); 2511 //qDebug("KO: Termination on %s ", latest.toString().latin1());
2512 config->setGroup( "Views" ); 2512 config->setGroup( "Views" );
2513 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 2513 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
2514 2514
2515#if 0 2515#if 0
2516 qDebug("********************* "); 2516 qDebug("********************* ");
2517 qDebug("Testcode secsto "); 2517 qDebug("Testcode secsto ");
2518 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) ); 2518 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) );
2519 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) ); 2519 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) );
2520 int secsto = dt_nodaylight.secsTo( dt_daylight ); 2520 int secsto = dt_nodaylight.secsTo( dt_daylight );
2521 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto ); 2521 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto );
2522 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() ); 2522 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() );
2523 qDebug("dt daylight %s ",dt_daylight.toString().latin1() ); 2523 qDebug("dt daylight %s ",dt_daylight.toString().latin1() );
2524 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() ); 2524 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() );
2525 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600); 2525 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600);
2526 qDebug("********************* testcode end"); 2526 qDebug("********************* testcode end");
2527 2527
2528#endif 2528#endif
2529 2529
2530 QValueList<int> listINT = mLeftFrame->sizes(); 2530 QValueList<int> listINT = mLeftFrame->sizes();
2531 config->writeEntry("Left Splitter Frame",listINT); 2531 config->writeEntry("Left Splitter Frame",listINT);
2532 QValueList<int> listINT2 = mMainFrame->sizes(); 2532 QValueList<int> listINT2 = mMainFrame->sizes();
2533 config->writeEntry("Main Splitter Frame",listINT2); 2533 config->writeEntry("Main Splitter Frame",listINT2);
2534#ifdef DESKTOP_VERSION 2534#ifdef DESKTOP_VERSION
2535 config->setGroup("WidgetLayout"); 2535 config->setGroup("WidgetLayout");
2536 QStringList list ;//= config->readListEntry("MainLayout"); 2536 QStringList list ;//= config->readListEntry("MainLayout");
2537 int x,y,w,h; 2537 int x,y,w,h;
2538 QWidget* wid; 2538 QWidget* wid;
2539 wid = topLevelWidget(); 2539 wid = topLevelWidget();
2540 x = wid->geometry().x(); 2540 x = wid->geometry().x();
2541 y = wid->geometry().y(); 2541 y = wid->geometry().y();
2542 w = wid->width(); 2542 w = wid->width();
2543 h = wid->height(); 2543 h = wid->height();
2544 list.clear(); 2544 list.clear();
2545 list << QString::number( x ); 2545 list << QString::number( x );
2546 list << QString::number( y ); 2546 list << QString::number( y );
2547 list << QString::number( w ); 2547 list << QString::number( w );
2548 list << QString::number( h ); 2548 list << QString::number( h );
2549 config->writeEntry("MainLayout",list ); 2549 config->writeEntry("MainLayout",list );
2550 2550
2551 wid = mEventEditor; 2551 wid = mEventEditor;
2552 x = wid->geometry().x(); 2552 x = wid->geometry().x();
2553 y = wid->geometry().y(); 2553 y = wid->geometry().y();
2554 w = wid->width(); 2554 w = wid->width();
2555 h = wid->height(); 2555 h = wid->height();
2556 list.clear(); 2556 list.clear();
2557 list << QString::number( x ); 2557 list << QString::number( x );
2558 list << QString::number( y ); 2558 list << QString::number( y );
2559 list << QString::number( w ); 2559 list << QString::number( w );
2560 list << QString::number( h ); 2560 list << QString::number( h );
2561 config->writeEntry("EditEventLayout",list ); 2561 config->writeEntry("EditEventLayout",list );
2562 2562
2563 wid = mTodoEditor; 2563 wid = mTodoEditor;
2564 x = wid->geometry().x(); 2564 x = wid->geometry().x();
2565 y = wid->geometry().y(); 2565 y = wid->geometry().y();
2566 w = wid->width(); 2566 w = wid->width();
2567 h = wid->height(); 2567 h = wid->height();
2568 list.clear(); 2568 list.clear();
2569 list << QString::number( x ); 2569 list << QString::number( x );
2570 list << QString::number( y ); 2570 list << QString::number( y );
2571 list << QString::number( w ); 2571 list << QString::number( w );
2572 list << QString::number( h ); 2572 list << QString::number( h );
2573 config->writeEntry("EditTodoLayout",list ); 2573 config->writeEntry("EditTodoLayout",list );
2574 wid = getEventViewerDialog(); 2574 wid = getEventViewerDialog();
2575 x = wid->geometry().x(); 2575 x = wid->geometry().x();
2576 y = wid->geometry().y(); 2576 y = wid->geometry().y();
2577 w = wid->width(); 2577 w = wid->width();
2578 h = wid->height(); 2578 h = wid->height();
2579 list.clear(); 2579 list.clear();
2580 list << QString::number( x ); 2580 list << QString::number( x );
2581 list << QString::number( y ); 2581 list << QString::number( y );
2582 list << QString::number( w ); 2582 list << QString::number( w );
2583 list << QString::number( h ); 2583 list << QString::number( h );
2584 config->writeEntry("ViewerLayout",list ); 2584 config->writeEntry("ViewerLayout",list );
2585 wid = mDialogManager->getSearchDialog(); 2585 wid = mDialogManager->getSearchDialog();
2586 if ( wid ) { 2586 if ( wid ) {
2587 x = wid->geometry().x(); 2587 x = wid->geometry().x();
2588 y = wid->geometry().y(); 2588 y = wid->geometry().y();
2589 w = wid->width(); 2589 w = wid->width();
2590 h = wid->height(); 2590 h = wid->height();
2591 list.clear(); 2591 list.clear();
2592 list << QString::number( x ); 2592 list << QString::number( x );
2593 list << QString::number( y ); 2593 list << QString::number( y );
2594 list << QString::number( w ); 2594 list << QString::number( w );
2595 list << QString::number( h ); 2595 list << QString::number( h );
2596 config->writeEntry("SearchLayout",list ); 2596 config->writeEntry("SearchLayout",list );
2597 } 2597 }
2598#endif 2598#endif
2599 2599
2600 2600
2601 config->sync(); 2601 config->sync();
2602} 2602}
2603 2603
2604void CalendarView::readFilterSettings(KConfig *config) 2604void CalendarView::readFilterSettings(KConfig *config)
2605{ 2605{
2606 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 2606 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
2607 2607
2608 mFilters.clear(); 2608 mFilters.clear();
2609 2609
2610 config->setGroup("General"); 2610 config->setGroup("General");
2611 QStringList filterList = config->readListEntry("CalendarFilters"); 2611 QStringList filterList = config->readListEntry("CalendarFilters");
2612 2612
2613 QStringList::ConstIterator it = filterList.begin(); 2613 QStringList::ConstIterator it = filterList.begin();
2614 QStringList::ConstIterator end = filterList.end(); 2614 QStringList::ConstIterator end = filterList.end();
2615 while(it != end) { 2615 while(it != end) {
2616 // kdDebug() << " filter: " << (*it) << endl; 2616 // kdDebug() << " filter: " << (*it) << endl;
2617 2617
2618 CalFilter *filter; 2618 CalFilter *filter;
2619 filter = new CalFilter(*it); 2619 filter = new CalFilter(*it);
2620 config->setGroup("Filter_" + (*it).utf8()); 2620 config->setGroup("Filter_" + (*it).utf8());
2621 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 2621 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
2622 filter->setCriteria(config->readNumEntry("Criteria",0)); 2622 filter->setCriteria(config->readNumEntry("Criteria",0));
2623 filter->setCategoryList(config->readListEntry("CategoryList")); 2623 filter->setCategoryList(config->readListEntry("CategoryList"));
2624 mFilters.append(filter); 2624 mFilters.append(filter);
2625 2625
2626 ++it; 2626 ++it;
2627 } 2627 }
2628 2628
2629 if (mFilters.count() == 0) { 2629 if (mFilters.count() == 0) {
2630 CalFilter *filter = new CalFilter(i18n("Default")); 2630 CalFilter *filter = new CalFilter(i18n("Default"));
2631 mFilters.append(filter); 2631 mFilters.append(filter);
2632 } 2632 }
2633 mFilterView->updateFilters(); 2633 mFilterView->updateFilters();
2634 config->setGroup("FilterView"); 2634 config->setGroup("FilterView");
2635 2635
2636 mFilterView->blockSignals(true); 2636 mFilterView->blockSignals(true);
2637 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 2637 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
2638 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 2638 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
2639 mFilterView->blockSignals(false); 2639 mFilterView->blockSignals(false);
2640 // We do it manually to avoid it being done twice by the above calls 2640 // We do it manually to avoid it being done twice by the above calls
2641 updateFilter(); 2641 updateFilter();
2642} 2642}
2643 2643
2644void CalendarView::writeFilterSettings(KConfig *config) 2644void CalendarView::writeFilterSettings(KConfig *config)
2645{ 2645{
2646 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 2646 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
2647 2647
2648 QStringList filterList; 2648 QStringList filterList;
2649 2649
2650 CalFilter *filter = mFilters.first(); 2650 CalFilter *filter = mFilters.first();
2651 while(filter) { 2651 while(filter) {
2652 // kdDebug() << " fn: " << filter->name() << endl; 2652 // kdDebug() << " fn: " << filter->name() << endl;
2653 filterList << filter->name(); 2653 filterList << filter->name();
2654 config->setGroup("Filter_" + filter->name().utf8()); 2654 config->setGroup("Filter_" + filter->name().utf8());
2655 config->writeEntry("Criteria",filter->criteria()); 2655 config->writeEntry("Criteria",filter->criteria());
2656 config->writeEntry("CategoryList",filter->categoryList()); 2656 config->writeEntry("CategoryList",filter->categoryList());
2657 filter = mFilters.next(); 2657 filter = mFilters.next();
2658 } 2658 }
2659 config->setGroup("General"); 2659 config->setGroup("General");
2660 config->writeEntry("CalendarFilters",filterList); 2660 config->writeEntry("CalendarFilters",filterList);
2661 2661
2662 config->setGroup("FilterView"); 2662 config->setGroup("FilterView");
2663 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 2663 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
2664 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 2664 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
2665} 2665}
2666 2666
2667 2667
2668void CalendarView::goToday() 2668void CalendarView::goToday()
2669{ 2669{
2670 if ( mViewManager->currentView()->isMonthView() ) 2670 if ( mViewManager->currentView()->isMonthView() )
2671 mNavigator->selectTodayMonth(); 2671 mNavigator->selectTodayMonth();
2672 else 2672 else
2673 mNavigator->selectToday(); 2673 mNavigator->selectToday();
2674} 2674}
2675 2675
2676void CalendarView::goNext() 2676void CalendarView::goNext()
2677{ 2677{
2678 mNavigator->selectNext(); 2678 mNavigator->selectNext();
2679} 2679}
2680 2680
2681void CalendarView::goPrevious() 2681void CalendarView::goPrevious()
2682{ 2682{
2683 mNavigator->selectPrevious(); 2683 mNavigator->selectPrevious();
2684} 2684}
2685void CalendarView::goNextMonth() 2685void CalendarView::goNextMonth()
2686{ 2686{
2687 mNavigator->selectNextMonth(); 2687 mNavigator->selectNextMonth();
2688} 2688}
2689 2689
2690void CalendarView::goPreviousMonth() 2690void CalendarView::goPreviousMonth()
2691{ 2691{
2692 mNavigator->selectPreviousMonth(); 2692 mNavigator->selectPreviousMonth();
2693} 2693}
2694 2694
2695void CalendarView::updateConfig() 2695void CalendarView::updateConfig()
2696{ 2696{
2697 if ( KOPrefs::instance()->mUseAppColors ) 2697 if ( KOPrefs::instance()->mUseAppColors )
2698 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 2698 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
2699 emit configChanged(); 2699 emit configChanged();
2700 mTodoList->updateConfig(); 2700 mTodoList->updateConfig();
2701 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 2701 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
2702 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2702 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2703 // To make the "fill window" configurations work 2703 // To make the "fill window" configurations work
2704 //mViewManager->raiseCurrentView(); 2704 //mViewManager->raiseCurrentView();
2705} 2705}
2706 2706
2707 2707
2708void CalendarView::eventChanged(Event *event) 2708void CalendarView::eventChanged(Event *event)
2709{ 2709{
2710 changeEventDisplay(event,KOGlobals::EVENTEDITED); 2710 changeEventDisplay(event,KOGlobals::EVENTEDITED);
2711 //updateUnmanagedViews(); 2711 //updateUnmanagedViews();
2712} 2712}
2713 2713
2714void CalendarView::eventAdded(Event *event) 2714void CalendarView::eventAdded(Event *event)
2715{ 2715{
2716 changeEventDisplay(event,KOGlobals::EVENTADDED); 2716 changeEventDisplay(event,KOGlobals::EVENTADDED);
2717} 2717}
2718 2718
2719void CalendarView::eventToBeDeleted(Event *) 2719void CalendarView::eventToBeDeleted(Event *)
2720{ 2720{
2721 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 2721 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
2722} 2722}
2723 2723
2724void CalendarView::eventDeleted() 2724void CalendarView::eventDeleted()
2725{ 2725{
2726 changeEventDisplay(0,KOGlobals::EVENTDELETED); 2726 changeEventDisplay(0,KOGlobals::EVENTDELETED);
2727} 2727}
2728void CalendarView::changeTodoDisplay(Todo *which, int action) 2728void CalendarView::changeTodoDisplay(Todo *which, int action)
2729{ 2729{
2730 changeIncidenceDisplay((Incidence *)which, action); 2730 changeIncidenceDisplay((Incidence *)which, action);
2731 mDateNavigator->updateView(); //LR 2731 mDateNavigator->updateView(); //LR
2732 //mDialogManager->updateSearchDialog(); 2732 //mDialogManager->updateSearchDialog();
2733 2733
2734 if (which) { 2734 if (which) {
2735 mViewManager->updateWNview(); 2735 mViewManager->updateWNview();
2736 //mTodoList->updateView(); 2736 //mTodoList->updateView();
2737 } 2737 }
2738 2738
2739} 2739}
2740 2740
2741void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 2741void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
2742{ 2742{
2743 updateUnmanagedViews(); 2743 updateUnmanagedViews();
2744 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 2744 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
2745 if ( action == KOGlobals::EVENTDELETED ) { //delete 2745 if ( action == KOGlobals::EVENTDELETED ) { //delete
2746 mCalendar->checkAlarmForIncidence( 0, true ); 2746 mCalendar->checkAlarmForIncidence( 0, true );
2747 if ( mEventViewerDialog ) 2747 if ( mEventViewerDialog )
2748 mEventViewerDialog->hide(); 2748 mEventViewerDialog->hide();
2749 } 2749 }
2750 else 2750 else
2751 mCalendar->checkAlarmForIncidence( which , false ); 2751 mCalendar->checkAlarmForIncidence( which , false );
2752} 2752}
2753 2753
2754// most of the changeEventDisplays() right now just call the view's 2754// most of the changeEventDisplays() right now just call the view's
2755// total update mode, but they SHOULD be recoded to be more refresh-efficient. 2755// total update mode, but they SHOULD be recoded to be more refresh-efficient.
2756void CalendarView::changeEventDisplay(Event *which, int action) 2756void CalendarView::changeEventDisplay(Event *which, int action)
2757{ 2757{
2758 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 2758 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
2759 changeIncidenceDisplay((Incidence *)which, action); 2759 changeIncidenceDisplay((Incidence *)which, action);
2760 static bool clearallviews = false; 2760 static bool clearallviews = false;
2761 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) { 2761 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) {
2762 if ( clearallviews ) { 2762 if ( clearallviews ) {
2763 clearAllViews(); 2763 clearAllViews();
2764 clearallviews = false; 2764 clearallviews = false;
2765 } 2765 }
2766 return; 2766 return;
2767 } 2767 }
2768 clearallviews = true; 2768 clearallviews = true;
2769 mDateNavigator->updateView(); 2769 mDateNavigator->updateView();
2770 //mDialogManager->updateSearchDialog(); 2770 //mDialogManager->updateSearchDialog();
2771 if (which) { 2771 if (which) {
2772 // If there is an event view visible update the display 2772 // If there is an event view visible update the display
2773 mViewManager->currentView()->changeEventDisplay(which,action); 2773 mViewManager->currentView()->changeEventDisplay(which,action);
2774 // TODO: check, if update needed 2774 // TODO: check, if update needed
2775 // if (which->getTodoStatus()) { 2775 // if (which->getTodoStatus()) {
2776 mTodoList->updateView(); 2776 mTodoList->updateView();
2777 if ( action != KOGlobals::EVENTDELETED ) { 2777 if ( action != KOGlobals::EVENTDELETED ) {
2778 mConflictingEvent = which ; 2778 mConflictingEvent = which ;
2779 int time = 1000; 2779 int time = 1000;
2780#ifdef DESKTOP_VERSION 2780#ifdef DESKTOP_VERSION
2781 time = 500; 2781 time = 500;
2782#endif 2782#endif
2783 QTimer::singleShot( time, this, SLOT ( checkConflictForEvent() ) ); 2783 QTimer::singleShot( time, this, SLOT ( checkConflictForEvent() ) );
2784 } 2784 }
2785 // } 2785 // }
2786 } else { 2786 } else {
2787 mViewManager->currentView()->updateView(); 2787 mViewManager->currentView()->updateView();
2788 } 2788 }
2789} 2789}
2790void CalendarView::checkConflictForEvent() 2790void CalendarView::checkConflictForEvent()
2791{ 2791{
2792 2792
2793 if (!KOPrefs::instance()->mConfirm) 2793 if (!KOPrefs::instance()->mConfirm)
2794 return; 2794 return;
2795 if ( ! mConflictingEvent ) return; 2795 if ( ! mConflictingEvent ) return;
2796 Event * conflictingEvent = mConflictingEvent; 2796 Event * conflictingEvent = mConflictingEvent;
2797 mConflictingEvent = 0; 2797 mConflictingEvent = 0;
2798 QDateTime current = QDateTime::currentDateTime(); 2798 QDateTime current = QDateTime::currentDateTime();
2799 if ( ! conflictingEvent->matchTime( &current, 0 ) ) { 2799 if ( ! conflictingEvent->matchTime( &current, 0 ) ) {
2800 return; 2800 return;
2801 } 2801 }
2802 QPtrList<Event> testlist = mCalendar->events(); 2802 QPtrList<Event> testlist = mCalendar->events();
2803 Event * test = testlist.first(); 2803 Event * test = testlist.first();
2804 QDateTime conflict; 2804 QDateTime conflict;
2805 QDateTime retVal; 2805 QDateTime retVal;
2806 bool found = false; 2806 bool found = false;
2807 Event * cE = 0; 2807 Event * cE = 0;
2808 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); 2808 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") );
2809 while ( test ) { 2809 while ( test ) {
2810 qApp->processEvents(); 2810 qApp->processEvents();
2811 bool skip = false; 2811 bool skip = false;
2812 if ( found ) 2812 if ( found )
2813 skip = !test->matchTime( &current, &conflict ); 2813 skip = !test->matchTime( &current, &conflict );
2814 else 2814 else
2815 skip = !test->matchTime( &current, 0 ); 2815 skip = !test->matchTime( &current, 0 );
2816 if ( !skip && !test->doesFloat() ) { 2816 if ( !skip && !test->doesFloat() ) {
2817 if ( conflictingEvent->isOverlapping ( test, &retVal, &current ) ) { 2817 if ( conflictingEvent->isOverlapping ( test, &retVal, &current ) ) {
2818 if ( ! found ) { 2818 if ( ! found ) {
2819 conflict = retVal; 2819 conflict = retVal;
2820 cE = test; 2820 cE = test;
2821 } else { 2821 } else {
2822 if ( retVal < conflict ) { 2822 if ( retVal < conflict ) {
2823 conflict = retVal; 2823 conflict = retVal;
2824 cE = test; 2824 cE = test;
2825 } 2825 }
2826 } 2826 }
2827 found = true; 2827 found = true;
2828 } 2828 }
2829 } 2829 }
2830 test = testlist.next(); 2830 test = testlist.next();
2831 } 2831 }
2832 topLevelWidget()->setCaption( i18n("KO/Pi") ); 2832 topLevelWidget()->setCaption( i18n("KO/Pi") );
2833 if ( found ) { 2833 if ( found ) {
2834 QString mess = i18n("The event\n%1\nconflicts with event\n%2\nat date\n%3.\n").arg(KGlobal::formatMessage ( conflictingEvent->summary(),0 ) ).arg( KGlobal::formatMessage ( cE->summary(),0 )).arg(KGlobal::locale()->formatDate(conflict.date()) ) ; 2834 QString mess = i18n("The event\n%1\nconflicts with event\n%2\nat date\n%3.\n").arg(KGlobal::formatMessage ( conflictingEvent->summary(),0 ) ).arg( KGlobal::formatMessage ( cE->summary(),0 )).arg(KGlobal::locale()->formatDate(conflict.date()) ) ;
2835 qApp->processEvents(); 2835 qApp->processEvents();
2836 int km = KMessageBox::warningContinueCancel(this,mess, 2836 int km = KMessageBox::warningContinueCancel(this,mess,
2837 i18n("KO/Pi Conflict delected"),i18n("Show date"),i18n("No problem!")); 2837 i18n("KO/Pi Conflict delected"),i18n("Show date"),i18n("No problem!"));
2838 if ( km != KMessageBox::Continue ) { 2838 if ( km != KMessageBox::Continue ) {
2839 return; 2839 return;
2840 } 2840 }
2841 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) 2841 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 )
2842 mViewManager->showDayView(); 2842 mViewManager->showDayView();
2843 mNavigator->slotDaySelect( conflict.date() ); 2843 mNavigator->slotDaySelect( conflict.date() );
2844 int hour = conflict.time().hour(); 2844 int hour = conflict.time().hour();
2845 mViewManager->agendaView()->setStartHour( hour ); 2845 mViewManager->agendaView()->setStartHour( hour );
2846 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( conflictingEvent->summary().left( 20 ) ).arg( cE->summary().left( 20 ) ) ); 2846 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( conflictingEvent->summary().left( 20 ) ).arg( cE->summary().left( 20 ) ) );
2847 } else 2847 } else
2848 topLevelWidget()->setCaption( i18n("No conflict found") ); 2848 topLevelWidget()->setCaption( i18n("No conflict found") );
2849 return; 2849 return;
2850 2850
2851} 2851}
2852 2852
2853void CalendarView::updateTodoViews() 2853void CalendarView::updateTodoViews()
2854{ 2854{
2855 mTodoList->updateView(); 2855 mTodoList->updateView();
2856 mViewManager->currentView()->updateView(); 2856 mViewManager->currentView()->updateView();
2857 2857
2858} 2858}
2859 2859
2860 2860
2861 2861
2862void CalendarView::clearAllViews() 2862void CalendarView::clearAllViews()
2863{ 2863{
2864 mTodoList->clearList(); 2864 mTodoList->clearList();
2865 mViewManager->clearAllViews(); 2865 mViewManager->clearAllViews();
2866 SearchDialog * sd = mDialogManager->getSearchDialog(); 2866 SearchDialog * sd = mDialogManager->getSearchDialog();
2867 if ( sd ) { 2867 if ( sd ) {
2868 KOListView* kol = sd->listview(); 2868 KOListView* kol = sd->listview();
2869 if ( kol ) 2869 if ( kol )
2870 kol->clearList(); 2870 kol->clearList();
2871 } 2871 }
2872} 2872}
2873void CalendarView::updateView() 2873void CalendarView::updateView()
2874{ 2874{
2875 static bool clearallviews = false; 2875 static bool clearallviews = false;
2876 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) { 2876 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) {
2877 if ( clearallviews ) { 2877 if ( clearallviews ) {
2878 clearAllViews(); 2878 clearAllViews();
2879 clearallviews = false; 2879 clearallviews = false;
2880 } 2880 }
2881 return; 2881 return;
2882 } 2882 }
2883 clearallviews = true; 2883 clearallviews = true;
2884 DateList tmpList = mNavigator->selectedDates(); 2884 DateList tmpList = mNavigator->selectedDates();
2885 2885
2886 if ( KOPrefs::instance()->mHideNonStartedTodos ) 2886 if ( KOPrefs::instance()->mHideNonStartedTodos )
2887 mTodoList->updateView(); 2887 mTodoList->updateView();
2888 // We assume that the navigator only selects consecutive days. 2888 // We assume that the navigator only selects consecutive days.
2889 updateView( tmpList.first(), tmpList.last() ); 2889 updateView( tmpList.first(), tmpList.last() );
2890} 2890}
2891 2891
2892void CalendarView::updateUnmanagedViews() 2892void CalendarView::updateUnmanagedViews()
2893{ 2893{
2894 mDateNavigator->updateDayMatrix(); 2894 mDateNavigator->updateDayMatrix();
2895} 2895}
2896 2896
2897int CalendarView::msgItemDelete(const QString name) 2897int CalendarView::msgItemDelete(const QString name)
2898{ 2898{
2899 return KMessageBox::warningContinueCancel(this,name +"\n\n"+ 2899 return KMessageBox::warningContinueCancel(this,name +"\n\n"+
2900 i18n("This item will be\npermanently deleted."), 2900 i18n("This item will be\npermanently deleted."),
2901 i18n("KO/Pi Confirmation"),i18n("Delete")); 2901 i18n("KO/Pi Confirmation"),i18n("Delete"));
2902} 2902}
2903 2903
2904 2904
2905void CalendarView::edit_cut() 2905void CalendarView::edit_cut()
2906{ 2906{
2907 Event *anEvent=0; 2907 Event *anEvent=0;
2908 2908
2909 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2909 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2910 2910
2911 if (mViewManager->currentView()->isEventView()) { 2911 if (mViewManager->currentView()->isEventView()) {
2912 if ( incidence && incidence->typeID() == eventID ) { 2912 if ( incidence && incidence->typeID() == eventID ) {
2913 anEvent = static_cast<Event *>(incidence); 2913 anEvent = static_cast<Event *>(incidence);
2914 } 2914 }
2915 } 2915 }
2916 2916
2917 if (!anEvent) { 2917 if (!anEvent) {
2918 KNotifyClient::beep(); 2918 KNotifyClient::beep();
2919 return; 2919 return;
2920 } 2920 }
2921 DndFactory factory( mCalendar ); 2921 DndFactory factory( mCalendar );
2922 factory.cutIncidence(anEvent); 2922 factory.cutIncidence(anEvent);
2923 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2923 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2924} 2924}
2925 2925
2926void CalendarView::edit_copy() 2926void CalendarView::edit_copy()
2927{ 2927{
2928 Event *anEvent=0; 2928 Event *anEvent=0;
2929 2929
2930 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2930 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2931 2931
2932 if (mViewManager->currentView()->isEventView()) { 2932 if (mViewManager->currentView()->isEventView()) {
2933 if ( incidence && incidence->typeID() == eventID ) { 2933 if ( incidence && incidence->typeID() == eventID ) {
2934 anEvent = static_cast<Event *>(incidence); 2934 anEvent = static_cast<Event *>(incidence);
2935 } 2935 }
2936 } 2936 }
2937 2937
2938 if (!anEvent) { 2938 if (!anEvent) {
2939 KNotifyClient::beep(); 2939 KNotifyClient::beep();
2940 return; 2940 return;
2941 } 2941 }
2942 DndFactory factory( mCalendar ); 2942 DndFactory factory( mCalendar );
2943 factory.copyIncidence(anEvent); 2943 factory.copyIncidence(anEvent);
2944} 2944}
2945 2945
2946void CalendarView::edit_paste() 2946void CalendarView::edit_paste()
2947{ 2947{
2948 QDate date = mNavigator->selectedDates().first(); 2948 QDate date = mNavigator->selectedDates().first();
2949 2949
2950 DndFactory factory( mCalendar ); 2950 DndFactory factory( mCalendar );
2951 Event *pastedEvent = (Event *)factory.pasteIncidence( date ); 2951 Event *pastedEvent = (Event *)factory.pasteIncidence( date );
2952 2952
2953 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2953 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2954} 2954}
2955void CalendarView::edit_global_options() 2955void CalendarView::edit_global_options()
2956{ 2956{
2957 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId; 2957 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId;
2958 emit save(); 2958 emit save();
2959 emit saveStopTimer(); 2959 emit saveStopTimer();
2960 mDialogManager->showGlobalOptionsDialog(); 2960 mDialogManager->showGlobalOptionsDialog();
2961 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) { 2961 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) {
2962 emit saveStopTimer(); 2962 emit saveStopTimer();
2963 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!"), 2963 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!"),
2964 i18n("Timezone settings"),i18n("Reload"))) { 2964 i18n("Timezone settings"),i18n("Reload"))) {
2965 qDebug("KO: TZ reload cancelled "); 2965 qDebug("KO: TZ reload cancelled ");
2966 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2966 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2967 return; 2967 return;
2968 } 2968 }
2969 qDebug("KO: Timezone change "); 2969 qDebug("KO: Timezone change ");
2970 loadCalendars(); 2970 loadCalendars();
2971 setModified(true); 2971 setModified(true);
2972 } 2972 }
2973 else 2973 else
2974 qDebug("KO: No tz change "); 2974 qDebug("KO: No tz change ");
2975} 2975}
2976void CalendarView::edit_options() 2976void CalendarView::edit_options()
2977{ 2977{
2978 mDialogManager->showOptionsDialog(); 2978 mDialogManager->showOptionsDialog();
2979} 2979}
2980 2980
2981 2981
2982void CalendarView::slotSelectPickerDate( QDate d) 2982void CalendarView::slotSelectPickerDate( QDate d)
2983{ 2983{
2984 mDateFrame->hide(); 2984 mDateFrame->hide();
2985 if ( mDatePickerMode == 1 ) { 2985 if ( mDatePickerMode == 1 ) {
2986 mNavigator->slotDaySelect( d ); 2986 mNavigator->slotDaySelect( d );
2987 } else if ( mDatePickerMode == 2 ) { 2987 } else if ( mDatePickerMode == 2 ) {
2988 if ( mMoveIncidence->typeID() == todoID ) { 2988 if ( mMoveIncidence->typeID() == todoID ) {
2989 Todo * to = (Todo *) mMoveIncidence; 2989 Todo * to = (Todo *) mMoveIncidence;
2990 QTime tim; 2990 QTime tim;
2991 int len = 0; 2991 int len = 0;
2992 if ( to->hasStartDate() && to->hasDueDate() ) 2992 if ( to->hasStartDate() && to->hasDueDate() )
2993 len = to->dtStart().secsTo( to->dtDue()); 2993 len = to->dtStart().secsTo( to->dtDue());
2994 if ( to->hasDueDate() ) 2994 if ( to->hasDueDate() )
2995 tim = to->dtDue().time(); 2995 tim = to->dtDue().time();
2996 else { 2996 else {
2997 tim = QTime ( 0,0,0 ); 2997 tim = QTime ( 0,0,0 );
2998 to->setFloats( true ); 2998 to->setFloats( true );
2999 to->setHasDueDate( true ); 2999 to->setHasDueDate( true );
3000 } 3000 }
3001 QDateTime dt ( d,tim ); 3001 QDateTime dt ( d,tim );
3002 to->setDtDue( dt ); 3002 to->setDtDue( dt );
3003 3003
3004 if ( to->hasStartDate() ) { 3004 if ( to->hasStartDate() ) {
3005 if ( len>0 ) 3005 if ( len>0 )
3006 to->setDtStart(to->dtDue().addSecs( -len )); 3006 to->setDtStart(to->dtDue().addSecs( -len ));
3007 else 3007 else
3008 if (to->dtStart() > to->dtDue() ) 3008 if (to->dtStart() > to->dtDue() )
3009 to->setDtStart(to->dtDue().addDays( -3 )); 3009 to->setDtStart(to->dtDue().addDays( -3 ));
3010 } 3010 }
3011 3011
3012 todoChanged( to ); 3012 todoChanged( to );
3013 } else if ( mMoveIncidence->typeID() == eventID ) { 3013 } else if ( mMoveIncidence->typeID() == eventID ) {
3014 if ( mMoveIncidence->doesRecur() ) { 3014 if ( mMoveIncidence->doesRecur() ) {
3015#if 0 3015#if 0
3016 // PENDING implement this 3016 // PENDING implement this
3017 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate ); 3017 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate );
3018 mCalendar()->addIncidence( newInc ); 3018 mCalendar()->addIncidence( newInc );
3019 if ( mMoveIncidence->typeID() == todoID ) 3019 if ( mMoveIncidence->typeID() == todoID )
3020 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED ); 3020 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED );
3021 else 3021 else
3022 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED); 3022 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED);
3023 mMoveIncidence = newInc; 3023 mMoveIncidence = newInc;
3024 3024
3025#endif 3025#endif
3026 } 3026 }
3027 QTime tim = mMoveIncidence->dtStart().time(); 3027 QTime tim = mMoveIncidence->dtStart().time();
3028 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 3028 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
3029 QDateTime dt ( d,tim ); 3029 QDateTime dt ( d,tim );
3030 mMoveIncidence->setDtStart( dt ); 3030 mMoveIncidence->setDtStart( dt );
3031 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 3031 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
3032 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 3032 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
3033 } else if ( mMoveIncidence->typeID() == journalID ) { 3033 } else if ( mMoveIncidence->typeID() == journalID ) {
3034 QTime tim = mMoveIncidence->dtStart().time(); 3034 QTime tim = mMoveIncidence->dtStart().time();
3035 QDateTime dt ( d,tim ); 3035 QDateTime dt ( d,tim );
3036 mMoveIncidence->setDtStart( dt ); 3036 mMoveIncidence->setDtStart( dt );
3037 updateView(); 3037 updateView();
3038 } 3038 }
3039 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 3039 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
3040 } 3040 }
3041} 3041}
3042 3042
3043void CalendarView::removeCategories() 3043void CalendarView::removeCategories()
3044{ 3044{
3045 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 3045 QPtrList<Incidence> incList = mCalendar->rawIncidences();
3046 QStringList catList = KOPrefs::instance()->mCustomCategories; 3046 QStringList catList = KOPrefs::instance()->mCustomCategories;
3047 QStringList catIncList; 3047 QStringList catIncList;
3048 QStringList newCatList; 3048 QStringList newCatList;
3049 Incidence* inc = incList.first(); 3049 Incidence* inc = incList.first();
3050 uint i; 3050 uint i;
3051 while ( inc ) { 3051 while ( inc ) {
3052 newCatList.clear(); 3052 newCatList.clear();
3053 catIncList = inc->categories() ; 3053 catIncList = inc->categories() ;
3054 for( i = 0; i< catIncList.count(); ++i ) { 3054 for( i = 0; i< catIncList.count(); ++i ) {
3055 if ( catList.contains (catIncList[i])) 3055 if ( catList.contains (catIncList[i]))
3056 newCatList.append( catIncList[i] ); 3056 newCatList.append( catIncList[i] );
3057 } 3057 }
3058 newCatList.sort(); 3058 newCatList.sort();
3059 inc->setCategories( newCatList.join(",") ); 3059 inc->setCategories( newCatList.join(",") );
3060 inc = incList.next(); 3060 inc = incList.next();
3061 } 3061 }
3062} 3062}
3063 3063
3064int CalendarView::addCategories() 3064int CalendarView::addCategories()
3065{ 3065{
3066 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 3066 QPtrList<Incidence> incList = mCalendar->rawIncidences();
3067 QStringList catList = KOPrefs::instance()->mCustomCategories; 3067 QStringList catList = KOPrefs::instance()->mCustomCategories;
3068 QStringList catIncList; 3068 QStringList catIncList;
3069 Incidence* inc = incList.first(); 3069 Incidence* inc = incList.first();
3070 uint i; 3070 uint i;
3071 int count = 0; 3071 int count = 0;
3072 while ( inc ) { 3072 while ( inc ) {
3073 catIncList = inc->categories() ; 3073 catIncList = inc->categories() ;
3074 for( i = 0; i< catIncList.count(); ++i ) { 3074 for( i = 0; i< catIncList.count(); ++i ) {
3075 if ( !catList.contains (catIncList[i])) { 3075 if ( !catList.contains (catIncList[i])) {
3076 catList.append( catIncList[i] ); 3076 catList.append( catIncList[i] );
3077 //qDebug("add cat %s ", catIncList[i].latin1()); 3077 //qDebug("add cat %s ", catIncList[i].latin1());
3078 ++count; 3078 ++count;
3079 } 3079 }
3080 } 3080 }
3081 inc = incList.next(); 3081 inc = incList.next();
3082 } 3082 }
3083 catList.sort(); 3083 catList.sort();
3084 KOPrefs::instance()->mCustomCategories = catList; 3084 KOPrefs::instance()->mCustomCategories = catList;
3085 return count; 3085 return count;
3086} 3086}
3087 3087
3088void CalendarView::editCategories() 3088void CalendarView::editCategories()
3089{ 3089{
3090 qDebug("CalendarView::editCategories() "); 3090 qDebug("CalendarView::editCategories() ");
3091 KPIM::CategoryEditDialog ced (KOPrefs::instance(),this ); 3091 KPIM::CategoryEditDialog ced (KOPrefs::instance(),this );
3092 ced.exec(); 3092 ced.exec();
3093} 3093}
3094void CalendarView::manageCategories() 3094void CalendarView::manageCategories()
3095{ 3095{
3096 KOCatPrefs* cp = new KOCatPrefs(); 3096 KOCatPrefs* cp = new KOCatPrefs();
3097 cp->show(); 3097 cp->show();
3098 int w =cp->sizeHint().width() ; 3098 int w =cp->sizeHint().width() ;
3099 int h = cp->sizeHint().height() ; 3099 int h = cp->sizeHint().height() ;
3100 int dw = QApplication::desktop()->width(); 3100 int dw = QApplication::desktop()->width();
3101 int dh = QApplication::desktop()->height(); 3101 int dh = QApplication::desktop()->height();
3102 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 3102 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
3103 if ( !cp->exec() ) { 3103 if ( !cp->exec() ) {
3104 delete cp; 3104 delete cp;
3105 return; 3105 return;
3106 } 3106 }
3107 int count = 0; 3107 int count = 0;
3108 if ( cp->addCat() ) { 3108 if ( cp->addCat() ) {
3109 count = addCategories(); 3109 count = addCategories();
3110 if ( count ) { 3110 if ( count ) {
3111 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 3111 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
3112 writeSettings(); 3112 writeSettings();
3113 } else 3113 } else
3114 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! ")); 3114 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! "));
3115 } else { 3115 } else {
3116 removeCategories(); 3116 removeCategories();
3117 updateView(); 3117 updateView();
3118 } 3118 }
3119 delete cp; 3119 delete cp;
3120} 3120}
3121 3121
3122void CalendarView::beamIncidence(Incidence * Inc) 3122void CalendarView::beamIncidence(Incidence * Inc)
3123{ 3123{
3124 QPtrList<Incidence> delSel ; 3124 QPtrList<Incidence> delSel ;
3125 delSel.append(Inc); 3125 delSel.append(Inc);
3126 beamIncidenceList( delSel ); 3126 beamIncidenceList( delSel );
3127} 3127}
3128void CalendarView::beamCalendar() 3128void CalendarView::beamCalendar()
3129{ 3129{
3130 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 3130 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
3131 //qDebug("beamCalendar() "); 3131 //qDebug("beamCalendar() ");
3132 beamIncidenceList( delSel ); 3132 beamIncidenceList( delSel );
3133} 3133}
3134void CalendarView::beamFilteredCalendar() 3134void CalendarView::beamFilteredCalendar()
3135{ 3135{
3136 QPtrList<Incidence> delSel = mCalendar->incidences(); 3136 QPtrList<Incidence> delSel = mCalendar->incidences();
3137 //qDebug("beamFilteredCalendar() "); 3137 //qDebug("beamFilteredCalendar() ");
3138 beamIncidenceList( delSel ); 3138 beamIncidenceList( delSel );
3139} 3139}
3140void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 3140void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
3141{ 3141{
3142 3142
3143 KOBeamPrefs beamDialog; 3143 KOBeamPrefs beamDialog;
3144 if ( beamDialog.exec () == QDialog::Rejected ) 3144 if ( beamDialog.exec () == QDialog::Rejected )
3145 return; 3145 return;
3146#ifdef DESKTOP_VERSION 3146#ifdef DESKTOP_VERSION
3147 QString fn = locateLocal( "tmp", "kopibeamfile" ); 3147 QString fn = locateLocal( "tmp", "kopibeamfile" );
3148#else 3148#else
3149 QString fn = "/tmp/kopibeamfile"; 3149 QString fn = "/tmp/kopibeamfile";
3150#endif 3150#endif
3151 QString mes; 3151 QString mes;
3152 bool createbup = true; 3152 bool createbup = true;
3153 if ( createbup ) { 3153 if ( createbup ) {
3154 QString description = "\n"; 3154 QString description = "\n";
3155 CalendarLocal* cal = new CalendarLocal(); 3155 CalendarLocal* cal = new CalendarLocal();
3156 if ( beamDialog.beamLocal() ) 3156 if ( beamDialog.beamLocal() )
3157 cal->setLocalTime(); 3157 cal->setLocalTime();
3158 else 3158 else
3159 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 3159 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
3160 Incidence *incidence = delSel.first(); 3160 Incidence *incidence = delSel.first();
3161 bool addText = false; 3161 bool addText = false;
3162 if ( delSel.count() < 10 ) 3162 if ( delSel.count() < 10 )
3163 addText = true; 3163 addText = true;
3164 else { 3164 else {
3165 description.sprintf(i18n(" %d items?"),delSel.count() ); 3165 description.sprintf(i18n(" %d items?"),delSel.count() );
3166 } 3166 }
3167 while ( incidence ) { 3167 while ( incidence ) {
3168 Incidence *in = incidence->clone(); 3168 Incidence *in = incidence->clone();
3169 if ( ! in->summary().isEmpty() ) { 3169 if ( ! in->summary().isEmpty() ) {
3170 in->setDescription(""); 3170 in->setDescription("");
3171 } else { 3171 } else {
3172 in->setSummary( in->description().left(20)); 3172 in->setSummary( in->description().left(20));
3173 in->setDescription(""); 3173 in->setDescription("");
3174 } 3174 }
3175 if ( addText ) 3175 if ( addText )
3176 description += in->summary() + "\n"; 3176 description += in->summary() + "\n";
3177 cal->addIncidence( in ); 3177 cal->addIncidence( in );
3178 incidence = delSel.next(); 3178 incidence = delSel.next();
3179 } 3179 }
3180 if ( beamDialog.beamVcal() ) { 3180 if ( beamDialog.beamVcal() ) {
3181 fn += ".vcs"; 3181 fn += ".vcs";
3182 FileStorage storage( cal, fn, new VCalFormat ); 3182 FileStorage storage( cal, fn, new VCalFormat );
3183 storage.save(); 3183 storage.save();
3184 } else { 3184 } else {
3185 fn += ".ics"; 3185 fn += ".ics";
3186 FileStorage storage( cal, fn, new ICalFormat( ) ); 3186 FileStorage storage( cal, fn, new ICalFormat( ) );
3187 storage.save(); 3187 storage.save();
3188 } 3188 }
3189 delete cal; 3189 delete cal;
3190 mes = i18n("KO/Pi: Ready for beaming"); 3190 mes = i18n("KO/Pi: Ready for beaming");
3191 topLevelWidget()->setCaption(mes); 3191 topLevelWidget()->setCaption(mes);
3192 KApplication::convert2latin1( fn ); 3192 KApplication::convert2latin1( fn );
3193#ifndef DESKTOP_VERSION 3193#ifndef DESKTOP_VERSION
3194 Ir *ir = new Ir( this ); 3194 Ir *ir = new Ir( this );
3195 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 3195 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
3196 ir->send( fn, description, "text/x-vCalendar" ); 3196 ir->send( fn, description, "text/x-vCalendar" );
3197#endif 3197#endif
3198 } 3198 }
3199} 3199}
3200 3200
3201#ifndef DESKTOP_VERSION 3201#ifndef DESKTOP_VERSION
3202void CalendarView::beamDone( Ir *ir ) 3202void CalendarView::beamDone( Ir *ir )
3203{ 3203{
3204 delete ir; 3204 delete ir;
3205 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); 3205 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") );
3206 topLevelWidget()->raise(); 3206 topLevelWidget()->raise();
3207} 3207}
3208#else 3208#else
3209void CalendarView::beamDone( Ir *){;} 3209void CalendarView::beamDone( Ir *){;}
3210#endif 3210#endif
3211void CalendarView::moveIncidence(Incidence * inc ) 3211void CalendarView::moveIncidence(Incidence * inc )
3212{ 3212{
3213 if ( !inc ) return; 3213 if ( !inc ) return;
3214 showDatePickerPopup(); 3214 showDatePickerPopup();
3215 mDatePickerMode = 2; 3215 mDatePickerMode = 2;
3216 mMoveIncidence = inc ; 3216 mMoveIncidence = inc ;
3217 QDate da; 3217 QDate da;
3218 if ( mMoveIncidence->typeID() == todoID ) { 3218 if ( mMoveIncidence->typeID() == todoID ) {
3219 Todo * to = (Todo *) mMoveIncidence; 3219 Todo * to = (Todo *) mMoveIncidence;
3220 if ( to->hasDueDate() ) 3220 if ( to->hasDueDate() )
3221 da = to->dtDue().date(); 3221 da = to->dtDue().date();
3222 else 3222 else
3223 da = QDate::currentDate(); 3223 da = QDate::currentDate();
3224 } else { 3224 } else {
3225 da = mMoveIncidence->dtStart().date(); 3225 da = mMoveIncidence->dtStart().date();
3226 } 3226 }
3227 //PENDING set date for recurring incidence to date of recurrence 3227 //PENDING set date for recurring incidence to date of recurrence
3228 //mMoveIncidenceOldDate; 3228 //mMoveIncidenceOldDate;
3229 mDatePicker->setDate( da ); 3229 mDatePicker->setDate( da );
3230} 3230}
3231void CalendarView::showDatePickerPopup() 3231void CalendarView::showDatePickerPopup()
3232{ 3232{
3233 if ( mDateFrame->isVisible() ) 3233 if ( mDateFrame->isVisible() )
3234 mDateFrame->hide(); 3234 mDateFrame->hide();
3235 else { 3235 else {
3236 int offX = 0, offY = 0; 3236 int offX = 0, offY = 0;
3237#ifdef DESKTOP_VERSION 3237#ifdef DESKTOP_VERSION
3238 int w =mDatePicker->sizeHint().width() ; 3238 int w =mDatePicker->sizeHint().width() ;
3239 int h = mDatePicker->sizeHint().height() ; 3239 int h = mDatePicker->sizeHint().height() ;
3240 int dw = topLevelWidget()->width(); 3240 int dw = topLevelWidget()->width();
3241 int dh = topLevelWidget()->height(); 3241 int dh = topLevelWidget()->height();
3242 offX = topLevelWidget()->x(); 3242 offX = topLevelWidget()->x();
3243 offY = topLevelWidget()->y(); 3243 offY = topLevelWidget()->y();
3244#else 3244#else
3245 int w =mDatePicker->sizeHint().width() ; 3245 int w =mDatePicker->sizeHint().width() ;
3246 int h = mDatePicker->sizeHint().height() ; 3246 int h = mDatePicker->sizeHint().height() ;
3247 int dw = QApplication::desktop()->width(); 3247 int dw = QApplication::desktop()->width();
3248 int dh = QApplication::desktop()->height(); 3248 int dh = QApplication::desktop()->height();
3249#endif 3249#endif
3250 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h ); 3250 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h );
3251 mDateFrame->show(); 3251 mDateFrame->show();
3252 } 3252 }
3253} 3253}
3254void CalendarView::showDatePicker( ) 3254void CalendarView::showDatePicker( )
3255{ 3255{
3256 showDatePickerPopup(); 3256 showDatePickerPopup();
3257 mDatePickerMode = 1; 3257 mDatePickerMode = 1;
3258 mDatePicker->setDate( mNavigator->selectedDates().first() ); 3258 mDatePicker->setDate( mNavigator->selectedDates().first() );
3259} 3259}
3260 3260
3261void CalendarView::showEventEditor() 3261void CalendarView::showEventEditor()
3262{ 3262{
3263#ifdef DESKTOP_VERSION 3263#ifdef DESKTOP_VERSION
3264 int x,y,w,h; 3264 int x,y,w,h;
3265 x = mEventEditor->geometry().x(); 3265 x = mEventEditor->geometry().x();
3266 y = mEventEditor->geometry().y(); 3266 y = mEventEditor->geometry().y();
3267 w = mEventEditor->width(); 3267 w = mEventEditor->width();
3268 h = mEventEditor->height(); 3268 h = mEventEditor->height();
3269 mEventEditor->show(); 3269 mEventEditor->show();
3270 mEventEditor->setGeometry(x,y,w,h); 3270 mEventEditor->setGeometry(x,y,w,h);
3271#else 3271#else
3272 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) { 3272 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) {
3273 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 3273 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
3274 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() ); 3274 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() );
3275 qApp->processEvents(); 3275 qApp->processEvents();
3276 delete mEventEditor; 3276 delete mEventEditor;
3277 mEventEditor = mDialogManager->getEventEditor(); 3277 mEventEditor = mDialogManager->getEventEditor();
3278 topLevelWidget()->setCaption( i18n("") ); 3278 topLevelWidget()->setCaption( i18n("") );
3279 } 3279 }
3280 mEventEditor->showMaximized(); 3280 mEventEditor->showMaximized();
3281#endif 3281#endif
3282} 3282}
3283void CalendarView::showTodoEditor() 3283void CalendarView::showTodoEditor()
3284{ 3284{
3285#ifdef DESKTOP_VERSION 3285#ifdef DESKTOP_VERSION
3286 int x,y,w,h; 3286 int x,y,w,h;
3287 x = mTodoEditor->geometry().x(); 3287 x = mTodoEditor->geometry().x();
3288 y = mTodoEditor->geometry().y(); 3288 y = mTodoEditor->geometry().y();
3289 w = mTodoEditor->width(); 3289 w = mTodoEditor->width();
3290 h = mTodoEditor->height(); 3290 h = mTodoEditor->height();
3291 mTodoEditor->show(); 3291 mTodoEditor->show();
3292 mTodoEditor->setGeometry(x,y,w,h); 3292 mTodoEditor->setGeometry(x,y,w,h);
3293#else 3293#else
3294 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) { 3294 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) {
3295 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 3295 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
3296 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() ); 3296 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() );
3297 qApp->processEvents(); 3297 qApp->processEvents();
3298 delete mTodoEditor; 3298 delete mTodoEditor;
3299 mTodoEditor = mDialogManager->getTodoEditor(); 3299 mTodoEditor = mDialogManager->getTodoEditor();
3300 topLevelWidget()->setCaption( i18n("") ); 3300 topLevelWidget()->setCaption( i18n("") );
3301 } 3301 }
3302 mTodoEditor->showMaximized(); 3302 mTodoEditor->showMaximized();
3303#endif 3303#endif
3304} 3304}
3305 3305
3306void CalendarView::cloneIncidence() 3306void CalendarView::cloneIncidence()
3307{ 3307{
3308 Incidence *incidence = currentSelection(); 3308 Incidence *incidence = currentSelection();
3309 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3309 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3310 if ( incidence ) { 3310 if ( incidence ) {
3311 cloneIncidence(incidence); 3311 cloneIncidence(incidence);
3312 } 3312 }
3313} 3313}
3314void CalendarView::moveIncidence() 3314void CalendarView::moveIncidence()
3315{ 3315{
3316 Incidence *incidence = currentSelection(); 3316 Incidence *incidence = currentSelection();
3317 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3317 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3318 if ( incidence ) { 3318 if ( incidence ) {
3319 moveIncidence(incidence); 3319 moveIncidence(incidence);
3320 } 3320 }
3321} 3321}
3322void CalendarView::beamIncidence() 3322void CalendarView::beamIncidence()
3323{ 3323{
3324 Incidence *incidence = currentSelection(); 3324 Incidence *incidence = currentSelection();
3325 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3325 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3326 if ( incidence ) { 3326 if ( incidence ) {
3327 beamIncidence(incidence); 3327 beamIncidence(incidence);
3328 } 3328 }
3329} 3329}
3330void CalendarView::toggleCancelIncidence() 3330void CalendarView::toggleCancelIncidence()
3331{ 3331{
3332 Incidence *incidence = currentSelection(); 3332 Incidence *incidence = currentSelection();
3333 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3333 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3334 if ( incidence ) { 3334 if ( incidence ) {
3335 cancelIncidence(incidence); 3335 cancelIncidence(incidence);
3336 } 3336 }
3337} 3337}
3338 3338
3339 3339
3340void CalendarView::cancelIncidence(Incidence * inc ) 3340void CalendarView::cancelIncidence(Incidence * inc )
3341{ 3341{
3342 inc->setCancelled( ! inc->cancelled() ); 3342 inc->setCancelled( ! inc->cancelled() );
3343 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 3343 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
3344 updateView(); 3344 updateView();
3345} 3345}
3346void CalendarView::cloneIncidence(Incidence * orgInc ) 3346void CalendarView::cloneIncidence(Incidence * orgInc )
3347{ 3347{
3348 Incidence * newInc = orgInc->clone(); 3348 Incidence * newInc = orgInc->clone();
3349 newInc->recreate(); 3349 newInc->recreate();
3350 3350
3351 if ( newInc->typeID() == todoID ) { 3351 if ( newInc->typeID() == todoID ) {
3352 Todo* t = (Todo*) newInc; 3352 Todo* t = (Todo*) newInc;
3353 bool cloneSub = false; 3353 bool cloneSub = false;
3354 if ( orgInc->relations().count() ) { 3354 if ( orgInc->relations().count() ) {
3355 int result = KMessageBox::warningYesNoCancel(this, 3355 int result = KMessageBox::warningYesNoCancel(this,
3356 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 ) ), 3356 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 ) ),
3357 i18n("Todo has subtodos"), 3357 i18n("Todo has subtodos"),
3358 i18n("Yes"), 3358 i18n("Yes"),
3359 i18n("No")); 3359 i18n("No"));
3360 3360
3361 if ( result == KMessageBox::Cancel ) { 3361 if ( result == KMessageBox::Cancel ) {
3362 delete t; 3362 delete t;
3363 return; 3363 return;
3364 } 3364 }
3365 if (result == KMessageBox::Yes) cloneSub = true; 3365 if (result == KMessageBox::Yes) cloneSub = true;
3366 } 3366 }
3367 showTodoEditor(); 3367 showTodoEditor();
3368 mTodoEditor->editTodo( t ); 3368 mTodoEditor->editTodo( t );
3369 if ( mTodoEditor->exec() ) { 3369 if ( mTodoEditor->exec() ) {
3370 if ( cloneSub ) { 3370 if ( cloneSub ) {
3371 orgInc->cloneRelations( t ); 3371 orgInc->cloneRelations( t );
3372 mCalendar->addIncidenceBranch( t ); 3372 mCalendar->addIncidenceBranch( t );
3373 updateView(); 3373 updateView();
3374 3374
3375 } else { 3375 } else {
3376 mCalendar->addTodo( t ); 3376 mCalendar->addTodo( t );
3377 updateView(); 3377 updateView();
3378 } 3378 }
3379 } else { 3379 } else {
3380 delete t; 3380 delete t;
3381 } 3381 }
3382 } 3382 }
3383 else if ( newInc->typeID() == eventID ) { 3383 else if ( newInc->typeID() == eventID ) {
3384 Event* e = (Event*) newInc; 3384 Event* e = (Event*) newInc;
3385 showEventEditor(); 3385 showEventEditor();
3386 mEventEditor->editEvent( e ); 3386 mEventEditor->editEvent( e );
3387 if ( mEventEditor->exec() ) { 3387 if ( mEventEditor->exec() ) {
3388 mCalendar->addEvent( e ); 3388 mCalendar->addEvent( e );
3389 updateView(); 3389 updateView();
3390 } else { 3390 } else {
3391 delete e; 3391 delete e;
3392 } 3392 }
3393 } if ( newInc->typeID() == journalID ) { 3393 } if ( newInc->typeID() == journalID ) {
3394 mCalendar->addJournal( (Journal*) newInc ); 3394 mCalendar->addJournal( (Journal*) newInc );
3395 editJournal( (Journal*) newInc ); 3395 editJournal( (Journal*) newInc );
3396 } 3396 }
3397 setActiveWindow(); 3397 setActiveWindow();
3398} 3398}
3399 3399
3400void CalendarView::newEvent() 3400void CalendarView::newEvent()
3401{ 3401{
3402 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 3402 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
3403 KOAgendaView *aView = mViewManager->agendaView(); 3403 KOAgendaView *aView = mViewManager->agendaView();
3404 if (aView) { 3404 if (aView) {
3405 if (aView->selectionStart().isValid()) { 3405 if (aView->selectionStart().isValid()) {
3406 if (aView->selectedIsAllDay()) { 3406 if (aView->selectedIsAllDay()) {
3407 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 3407 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
3408 } else { 3408 } else {
3409 newEvent(aView->selectionStart(),aView->selectionEnd()); 3409 newEvent(aView->selectionStart(),aView->selectionEnd());
3410 } 3410 }
3411 return; 3411 return;
3412 } 3412 }
3413 } 3413 }
3414 3414
3415 QDate date = mNavigator->selectedDates().first(); 3415 QDate date = mNavigator->selectedDates().first();
3416#if 0 3416#if 0
3417 QDateTime current = QDateTime::currentDateTime(); 3417 QDateTime current = QDateTime::currentDateTime();
3418 if ( date <= current.date() ) { 3418 if ( date <= current.date() ) {
3419 int hour = current.time().hour() +1; 3419 int hour = current.time().hour() +1;
3420 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 3420 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
3421 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 3421 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
3422 } else 3422 } else
3423#endif 3423#endif
3424 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 3424 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
3425 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 3425 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
3426 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 3426 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
3427} 3427}
3428 3428
3429void CalendarView::newEvent(QDateTime fh) 3429void CalendarView::newEvent(QDateTime fh)
3430{ 3430{
3431 newEvent(fh, 3431 newEvent(fh,
3432 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 3432 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
3433} 3433}
3434 3434
3435void CalendarView::newEvent(QDate dt) 3435void CalendarView::newEvent(QDate dt)
3436{ 3436{
3437 newEvent(QDateTime(dt, QTime(0,0,0)), 3437 newEvent(QDateTime(dt, QTime(0,0,0)),
3438 QDateTime(dt, QTime(0,0,0)), true); 3438 QDateTime(dt, QTime(0,0,0)), true);
3439} 3439}
3440void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint) 3440void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint)
3441{ 3441{
3442 newEvent(fromHint, toHint, false); 3442 newEvent(fromHint, toHint, false);
3443} 3443}
3444void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 3444void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
3445{ 3445{
3446 3446
3447 showEventEditor(); 3447 showEventEditor();
3448 mEventEditor->newEvent(fromHint,toHint,allDay); 3448 mEventEditor->newEvent(fromHint,toHint,allDay);
3449 if ( mFilterView->filtersEnabled() ) { 3449 if ( mFilterView->filtersEnabled() ) {
3450 CalFilter *filter = mFilterView->selectedFilter(); 3450 CalFilter *filter = mFilterView->selectedFilter();
3451 if (filter && filter->showCategories()) { 3451 if (filter && filter->showCategories()) {
3452 mEventEditor->setCategories(filter->categoryList().join(",") ); 3452 mEventEditor->setCategories(filter->categoryList().join(",") );
3453 } 3453 }
3454 if ( filter ) 3454 if ( filter )
3455 mEventEditor->setSecrecy( filter->getSecrecy() ); 3455 mEventEditor->setSecrecy( filter->getSecrecy() );
3456 } 3456 }
3457 mEventEditor->exec(); 3457 mEventEditor->exec();
3458 setActiveWindow(); 3458 setActiveWindow();
3459} 3459}
3460void CalendarView::todoAdded(Todo * t) 3460void CalendarView::todoAdded(Todo * t)
3461{ 3461{
3462 3462
3463 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 3463 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
3464 updateTodoViews(); 3464 updateTodoViews();
3465} 3465}
3466void CalendarView::todoChanged(Todo * t) 3466void CalendarView::todoChanged(Todo * t)
3467{ 3467{
3468 emit todoModified( t, 4 ); 3468 emit todoModified( t, 4 );
3469 // updateTodoViews(); 3469 // updateTodoViews();
3470} 3470}
3471void CalendarView::todoToBeDeleted(Todo *) 3471void CalendarView::todoToBeDeleted(Todo *)
3472{ 3472{
3473 //qDebug("todoToBeDeleted(Todo *) "); 3473 //qDebug("todoToBeDeleted(Todo *) ");
3474 updateTodoViews(); 3474 updateTodoViews();
3475} 3475}
3476void CalendarView::todoDeleted() 3476void CalendarView::todoDeleted()
3477{ 3477{
3478 //qDebug(" todoDeleted()"); 3478 //qDebug(" todoDeleted()");
3479 updateTodoViews(); 3479 updateTodoViews();
3480} 3480}
3481 3481
3482 3482
3483void CalendarView::newTodoDateTime( QDateTime dt, bool allday ) 3483void CalendarView::newTodoDateTime( QDateTime dt, bool allday )
3484{ 3484{
3485 showTodoEditor(); 3485 showTodoEditor();
3486 mTodoEditor->newTodo(dt,0,allday); 3486 mTodoEditor->newTodo(dt,0,allday);
3487 if ( mFilterView->filtersEnabled() ) { 3487 if ( mFilterView->filtersEnabled() ) {
3488 CalFilter *filter = mFilterView->selectedFilter(); 3488 CalFilter *filter = mFilterView->selectedFilter();
3489 if (filter && filter->showCategories()) { 3489 if (filter && filter->showCategories()) {
3490 mTodoEditor->setCategories(filter->categoryList().join(",") ); 3490 mTodoEditor->setCategories(filter->categoryList().join(",") );
3491 } 3491 }
3492 if ( filter ) 3492 if ( filter )
3493 mTodoEditor->setSecrecy( filter->getSecrecy() ); 3493 mTodoEditor->setSecrecy( filter->getSecrecy() );
3494 } 3494 }
3495 mTodoEditor->exec(); 3495 mTodoEditor->exec();
3496 setActiveWindow(); 3496 setActiveWindow();
3497} 3497}
3498 3498
3499void CalendarView::newTodo() 3499void CalendarView::newTodo()
3500{ 3500{
3501 newTodoDateTime( QDateTime(),true ); 3501 newTodoDateTime( QDateTime(),true );
3502} 3502}
3503 3503
3504void CalendarView::newSubTodo() 3504void CalendarView::newSubTodo()
3505{ 3505{
3506 Todo *todo = selectedTodo(); 3506 Todo *todo = selectedTodo();
3507 if ( todo ) newSubTodo( todo ); 3507 if ( todo ) newSubTodo( todo );
3508} 3508}
3509 3509
3510void CalendarView::newSubTodo(Todo *parentEvent) 3510void CalendarView::newSubTodo(Todo *parentEvent)
3511{ 3511{
3512 3512
3513 showTodoEditor(); 3513 showTodoEditor();
3514 mTodoEditor->newTodo(QDateTime(),parentEvent,true); 3514 mTodoEditor->newTodo(QDateTime(),parentEvent,true);
3515 mTodoEditor->exec(); 3515 mTodoEditor->exec();
3516 setActiveWindow(); 3516 setActiveWindow();
3517} 3517}
3518 3518
3519void CalendarView::newFloatingEvent() 3519void CalendarView::newFloatingEvent()
3520{ 3520{
3521 DateList tmpList = mNavigator->selectedDates(); 3521 DateList tmpList = mNavigator->selectedDates();
3522 QDate date = tmpList.first(); 3522 QDate date = tmpList.first();
3523 3523
3524 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 3524 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
3525 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 3525 QDateTime( date, QTime( 12, 0, 0 ) ), true );
3526} 3526}
3527 3527
3528 3528
3529void CalendarView::editEvent( Event *event ) 3529void CalendarView::editEvent( Event *event )
3530{ 3530{
3531 3531
3532 if ( !event ) return; 3532 if ( !event ) return;
3533 if ( event->isReadOnly() ) { 3533 if ( event->isReadOnly() ) {
3534 showEvent( event ); 3534 showEvent( event );
3535 return; 3535 return;
3536 } 3536 }
3537 showEventEditor(); 3537 showEventEditor();
3538 mEventEditor->editEvent( event , mFlagEditDescription); 3538 mEventEditor->editEvent( event , mFlagEditDescription);
3539 mEventEditor->exec(); 3539 mEventEditor->exec();
3540 setActiveWindow(); 3540 setActiveWindow();
3541 3541
3542} 3542}
3543void CalendarView::editJournal( Journal *jour ) 3543void CalendarView::editJournal( Journal *jour )
3544{ 3544{
3545 if ( !jour ) return; 3545 if ( !jour ) return;
3546 mDialogManager->hideSearchDialog(); 3546 mDialogManager->hideSearchDialog();
3547 mViewManager->showJournalView(); 3547 mViewManager->showJournalView();
3548 mNavigator->slotDaySelect( jour->dtStart().date() ); 3548 mNavigator->slotDaySelect( jour->dtStart().date() );
3549} 3549}
3550void CalendarView::editTodo( Todo *todo ) 3550void CalendarView::editTodo( Todo *todo )
3551{ 3551{
3552 if ( !todo ) return; 3552 if ( !todo ) return;
3553 3553
3554 if ( todo->isReadOnly() ) { 3554 if ( todo->isReadOnly() ) {
3555 showTodo( todo ); 3555 showTodo( todo );
3556 return; 3556 return;
3557 } 3557 }
3558 showTodoEditor(); 3558 showTodoEditor();
3559 mTodoEditor->editTodo( todo ,mFlagEditDescription); 3559 mTodoEditor->editTodo( todo ,mFlagEditDescription);
3560 mTodoEditor->exec(); 3560 mTodoEditor->exec();
3561 setActiveWindow(); 3561 setActiveWindow();
3562 3562
3563} 3563}
3564 3564
3565KOEventViewerDialog* CalendarView::getEventViewerDialog() 3565KOEventViewerDialog* CalendarView::getEventViewerDialog()
3566{ 3566{
3567 if ( !mEventViewerDialog ) { 3567 if ( !mEventViewerDialog ) {
3568 mEventViewerDialog = new KOEventViewerDialog(0); 3568 mEventViewerDialog = new KOEventViewerDialog(0);
3569 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 3569 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
3570 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 3570 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
3571 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 3571 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
3572 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 3572 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
3573 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 3573 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
3574 viewManager(), SLOT( showAgendaView( bool ) ) ); 3574 viewManager(), SLOT( showAgendaView( bool ) ) );
3575 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()), 3575 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()),
3576 this, SLOT( slotViewerClosed() ) ); 3576 this, SLOT( slotViewerClosed() ) );
3577 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ), 3577 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ),
3578 this, SLOT( todoChanged(Todo *) ) ); 3578 this, SLOT( todoChanged(Todo *) ) );
3579 connect( mEventViewerDialog, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); 3579 connect( mEventViewerDialog, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) ));
3580 mEventViewerDialog->resize( 640, 480 ); 3580 mEventViewerDialog->resize( 640, 480 );
3581 3581
3582 } 3582 }
3583 return mEventViewerDialog; 3583 return mEventViewerDialog;
3584} 3584}
3585void CalendarView::showEvent(Event *event) 3585void CalendarView::showEvent(Event *event)
3586{ 3586{
3587 getEventViewerDialog()->setEvent(event); 3587 getEventViewerDialog()->setEvent(event);
3588 getEventViewerDialog()->showMe(); 3588 getEventViewerDialog()->showMe();
3589} 3589}
3590 3590
3591void CalendarView::showTodo(Todo *event) 3591void CalendarView::showTodo(Todo *event)
3592{ 3592{
3593 getEventViewerDialog()->setTodo(event); 3593 getEventViewerDialog()->setTodo(event);
3594 getEventViewerDialog()->showMe(); 3594 getEventViewerDialog()->showMe();
3595} 3595}
3596void CalendarView::showJournal( Journal *jour ) 3596void CalendarView::showJournal( Journal *jour )
3597{ 3597{
3598 getEventViewerDialog()->setJournal(jour); 3598 getEventViewerDialog()->setJournal(jour);
3599 getEventViewerDialog()->showMe(); 3599 getEventViewerDialog()->showMe();
3600 3600
3601} 3601}
3602// void CalendarView::todoModified (Todo *event, int changed) 3602// void CalendarView::todoModified (Todo *event, int changed)
3603// { 3603// {
3604// // if (mDialogList.find (event) != mDialogList.end ()) { 3604// // if (mDialogList.find (event) != mDialogList.end ()) {
3605// // kdDebug() << "Todo modified and open" << endl; 3605// // kdDebug() << "Todo modified and open" << endl;
3606// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 3606// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
3607// // temp->modified (changed); 3607// // temp->modified (changed);
3608 3608
3609// // } 3609// // }
3610 3610
3611// mViewManager->updateView(); 3611// mViewManager->updateView();
3612// } 3612// }
3613 3613
3614void CalendarView::appointment_show() 3614void CalendarView::appointment_show()
3615{ 3615{
3616 Event *anEvent = 0; 3616 Event *anEvent = 0;
3617 3617
3618 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3618 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3619 3619
3620 if (mViewManager->currentView()->isEventView()) { 3620 if (mViewManager->currentView()->isEventView()) {
3621 if ( incidence && incidence->typeID() == eventID ) { 3621 if ( incidence && incidence->typeID() == eventID ) {
3622 anEvent = static_cast<Event *>(incidence); 3622 anEvent = static_cast<Event *>(incidence);
3623 } 3623 }
3624 } 3624 }
3625 3625
3626 if (!anEvent) { 3626 if (!anEvent) {
3627 KNotifyClient::beep(); 3627 KNotifyClient::beep();
3628 return; 3628 return;
3629 } 3629 }
3630 3630
3631 showEvent(anEvent); 3631 showEvent(anEvent);
3632} 3632}
3633 3633
3634void CalendarView::appointment_edit() 3634void CalendarView::appointment_edit()
3635{ 3635{
3636 Event *anEvent = 0; 3636 Event *anEvent = 0;
3637 3637
3638 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3638 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3639 3639
3640 if (mViewManager->currentView()->isEventView()) { 3640 if (mViewManager->currentView()->isEventView()) {
3641 if ( incidence && incidence->typeID() == eventID ) { 3641 if ( incidence && incidence->typeID() == eventID ) {
3642 anEvent = static_cast<Event *>(incidence); 3642 anEvent = static_cast<Event *>(incidence);
3643 } 3643 }
3644 } 3644 }
3645 3645
3646 if (!anEvent) { 3646 if (!anEvent) {
3647 KNotifyClient::beep(); 3647 KNotifyClient::beep();
3648 return; 3648 return;
3649 } 3649 }
3650 3650
3651 editEvent(anEvent); 3651 editEvent(anEvent);
3652} 3652}
3653 3653
3654void CalendarView::appointment_delete() 3654void CalendarView::appointment_delete()
3655{ 3655{
3656 Event *anEvent = 0; 3656 Event *anEvent = 0;
3657 3657
3658 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3658 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3659 3659
3660 if (mViewManager->currentView()->isEventView()) { 3660 if (mViewManager->currentView()->isEventView()) {
3661 if ( incidence && incidence->typeID() == eventID ) { 3661 if ( incidence && incidence->typeID() == eventID ) {
3662 anEvent = static_cast<Event *>(incidence); 3662 anEvent = static_cast<Event *>(incidence);
3663 } 3663 }
3664 } 3664 }
3665 3665
3666 if (!anEvent) { 3666 if (!anEvent) {
3667 KNotifyClient::beep(); 3667 KNotifyClient::beep();
3668 return; 3668 return;
3669 } 3669 }
3670 3670
3671 deleteEvent(anEvent); 3671 deleteEvent(anEvent);
3672} 3672}
3673 3673
3674void CalendarView::todo_resub( Todo * parent, Todo * sub ) 3674void CalendarView::todo_resub( Todo * parent, Todo * sub )
3675{ 3675{
3676 if (!sub) return; 3676 if (!sub) return;
3677 if ( sub->relatedTo() == parent ) 3677 if ( sub->relatedTo() == parent )
3678 return; 3678 return;
3679 sub->setRelatedTo(parent); 3679 sub->setRelatedTo(parent);
3680 sub->updated(); 3680 sub->updated();
3681 setModified(true); 3681 setModified(true);
3682 updateView(); 3682 updateView();
3683} 3683}
3684void CalendarView::todo_unsub(Todo *anTodo ) 3684void CalendarView::todo_unsub(Todo *anTodo )
3685{ 3685{
3686 todo_resub( 0, anTodo ); 3686 todo_resub( 0, anTodo );
3687} 3687}
3688 3688
3689void CalendarView::deleteTodo(Todo *todo) 3689void CalendarView::deleteTodo(Todo *todo)
3690{ 3690{
3691 if (!todo) { 3691 if (!todo) {
3692 KNotifyClient::beep(); 3692 KNotifyClient::beep();
3693 return; 3693 return;
3694 } 3694 }
3695 if (KOPrefs::instance()->mConfirm) { 3695 if (KOPrefs::instance()->mConfirm) {
3696 QString text = KGlobal::formatMessage ( todo->summary(),0 ); 3696 QString text = KGlobal::formatMessage ( todo->summary(),0 );
3697 if (!todo->relations().isEmpty()) { 3697 if (!todo->relations().isEmpty()) {
3698 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!"); 3698 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!");
3699 3699
3700 } 3700 }
3701 switch (msgItemDelete(i18n("Todo:") +"\n"+text)) { 3701 switch (msgItemDelete(i18n("Todo:") +"\n"+text)) {
3702 case KMessageBox::Continue: // OK 3702 case KMessageBox::Continue: // OK
3703 bool deleteT = false; 3703 bool deleteT = false;
3704 if (!todo->relations().isEmpty()) { 3704 if (!todo->relations().isEmpty()) {
3705 deleteT = removeCompletedSubTodos( todo ); 3705 deleteT = removeCompletedSubTodos( todo );
3706 } 3706 }
3707 // deleteT == true: todo already deleted in removeCompletedSubTodos 3707 // deleteT == true: todo already deleted in removeCompletedSubTodos
3708 if ( !deleteT ) { 3708 if ( !deleteT ) {
3709 checkExternalId( todo ); 3709 checkExternalId( todo );
3710 calendar()->deleteTodo(todo); 3710 calendar()->deleteTodo(todo);
3711 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3711 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3712 updateView(); 3712 updateView();
3713 } 3713 }
3714 break; 3714 break;
3715 } // switch 3715 } // switch
3716 } else { 3716 } else {
3717 checkExternalId( todo ); 3717 checkExternalId( todo );
3718 mCalendar->deleteTodo(todo); 3718 mCalendar->deleteTodo(todo);
3719 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3719 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3720 updateView(); 3720 updateView();
3721 } 3721 }
3722 3722
3723 emit updateSearchDialog(); 3723 emit updateSearchDialog();
3724} 3724}
3725void CalendarView::deleteJournal(Journal *jour) 3725void CalendarView::deleteJournal(Journal *jour)
3726{ 3726{
3727 if (!jour) { 3727 if (!jour) {
3728 KNotifyClient::beep(); 3728 KNotifyClient::beep();
3729 return; 3729 return;
3730 } 3730 }
3731 if (KOPrefs::instance()->mConfirm) { 3731 if (KOPrefs::instance()->mConfirm) {
3732 3732
3733 QString des; 3733 QString des;
3734 if ( !jour->summary().isEmpty() ) { 3734 if ( !jour->summary().isEmpty() ) {
3735 des = jour->summary(); 3735 des = jour->summary();
3736 } else { 3736 } else {
3737 des = jour->description().left(30); 3737 des = jour->description().left(30);
3738 des = des.simplifyWhiteSpace (); 3738 des = des.simplifyWhiteSpace ();
3739 des.replace (QRegExp ("\\n"),"" ); 3739 des.replace (QRegExp ("\\n"),"" );
3740 des.replace (QRegExp ("\\r"),"" ); 3740 des.replace (QRegExp ("\\r"),"" );
3741 } 3741 }
3742 switch (msgItemDelete( i18n("Journal:") +"\n"+KGlobal::formatMessage ( des,0 ))) { 3742 switch (msgItemDelete( i18n("Journal:") +"\n"+KGlobal::formatMessage ( des,0 ))) {
3743 case KMessageBox::Continue: // OK 3743 case KMessageBox::Continue: // OK
3744 calendar()->deleteJournal(jour); 3744 calendar()->deleteJournal(jour);
3745 updateView(); 3745 updateView();
3746 break; 3746 break;
3747 } // switch 3747 } // switch
3748 } else { 3748 } else {
3749 calendar()->deleteJournal(jour);; 3749 calendar()->deleteJournal(jour);;
3750 updateView(); 3750 updateView();
3751 } 3751 }
3752 emit updateSearchDialog(); 3752 emit updateSearchDialog();
3753} 3753}
3754 3754
3755void CalendarView::deleteEvent(Event *anEvent) 3755void CalendarView::deleteEvent(Event *anEvent)
3756{ 3756{
3757 if (!anEvent) { 3757 if (!anEvent) {
3758 KNotifyClient::beep(); 3758 KNotifyClient::beep();
3759 return; 3759 return;
3760 } 3760 }
3761 3761
3762 if (anEvent->recurrence()->doesRecur()) { 3762 if (anEvent->doesRecur()) {
3763 QDate itemDate = mViewManager->currentSelectionDate(); 3763 QDate itemDate = mViewManager->currentSelectionDate();
3764 int km; 3764 int km;
3765 if (!itemDate.isValid()) { 3765 if (!itemDate.isValid()) {
3766 //kdDebug() << "Date Not Valid" << endl; 3766 //kdDebug() << "Date Not Valid" << endl;
3767 if (KOPrefs::instance()->mConfirm) { 3767 if (KOPrefs::instance()->mConfirm) {
3768 km = KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 3768 km = KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
3769 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 3769 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
3770 i18n("KO/Pi Confirmation"),i18n("Delete All")); 3770 i18n("KO/Pi Confirmation"),i18n("Delete All"));
3771 if ( km == KMessageBox::Continue ) 3771 if ( km == KMessageBox::Continue )
3772 km = KMessageBox::No; // No = all below 3772 km = KMessageBox::No; // No = all below
3773 } else 3773 } else
3774 km = KMessageBox::No; 3774 km = KMessageBox::No;
3775 } else { 3775 } else {
3776 km = KMessageBox::warningYesNoCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 3776 km = KMessageBox::warningYesNoCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
3777 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 3777 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
3778 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 3778 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
3779 i18n("KO/Pi Confirmation"),i18n("Current"), 3779 i18n("KO/Pi Confirmation"),i18n("Current"),
3780 i18n("All")); 3780 i18n("All"));
3781 } 3781 }
3782 switch(km) { 3782 switch(km) {
3783 3783
3784 case KMessageBox::No: // Continue // all 3784 case KMessageBox::No: // Continue // all
3785 //qDebug("KMessageBox::No "); 3785 //qDebug("KMessageBox::No ");
3786 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3786 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3787 schedule(Scheduler::Cancel,anEvent); 3787 schedule(Scheduler::Cancel,anEvent);
3788 3788
3789 checkExternalId( anEvent); 3789 checkExternalId( anEvent);
3790 mCalendar->deleteEvent(anEvent); 3790 mCalendar->deleteEvent(anEvent);
3791 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 3791 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
3792 break; 3792 break;
3793 3793
3794 // Disabled because it does not work 3794 // Disabled because it does not work
3795 //#if 0 3795 //#if 0
3796 case KMessageBox::Yes: // just this one 3796 case KMessageBox::Yes: // just this one
3797 //QDate qd = mNavigator->selectedDates().first(); 3797 //QDate qd = mNavigator->selectedDates().first();
3798 //if (!qd.isValid()) { 3798 //if (!qd.isValid()) {
3799 // kdDebug() << "no date selected, or invalid date" << endl; 3799 // kdDebug() << "no date selected, or invalid date" << endl;
3800 // KNotifyClient::beep(); 3800 // KNotifyClient::beep();
3801 // return; 3801 // return;
3802 //} 3802 //}
3803 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 3803 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
3804 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 3804 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
3805 anEvent->addExDate(itemDate); 3805 anEvent->addExDate(itemDate);
3806 int duration = anEvent->recurrence()->duration(); 3806 int duration = anEvent->recurrence()->duration();
3807 if ( duration > 0 ) { 3807 if ( duration > 0 ) {
3808 anEvent->recurrence()->setDuration( duration - 1 ); 3808 anEvent->recurrence()->setDuration( duration - 1 );
3809 } 3809 }
3810 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 3810 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
3811 } 3811 }
3812 break; 3812 break;
3813 //#endif 3813 //#endif
3814 } // switch 3814 } // switch
3815 } else { 3815 } else {
3816 if (KOPrefs::instance()->mConfirm) { 3816 if (KOPrefs::instance()->mConfirm) {
3817 switch (KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 3817 switch (KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
3818 i18n("\nAre you sure you want\nto delete this event?"), 3818 i18n("\nAre you sure you want\nto delete this event?"),
3819 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 3819 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
3820 case KMessageBox::Continue: // OK 3820 case KMessageBox::Continue: // OK
3821 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3821 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3822 schedule(Scheduler::Cancel,anEvent); 3822 schedule(Scheduler::Cancel,anEvent);
3823 checkExternalId( anEvent); 3823 checkExternalId( anEvent);
3824 mCalendar->deleteEvent(anEvent); 3824 mCalendar->deleteEvent(anEvent);
3825 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3825 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3826 break; 3826 break;
3827 } // switch 3827 } // switch
3828 } else { 3828 } else {
3829 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3829 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3830 schedule(Scheduler::Cancel,anEvent); 3830 schedule(Scheduler::Cancel,anEvent);
3831 checkExternalId( anEvent); 3831 checkExternalId( anEvent);
3832 mCalendar->deleteEvent(anEvent); 3832 mCalendar->deleteEvent(anEvent);
3833 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3833 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3834 } 3834 }
3835 } // if-else 3835 } // if-else
3836 emit updateSearchDialog(); 3836 emit updateSearchDialog();
3837} 3837}
3838 3838
3839bool CalendarView::deleteEvent(const QString &uid) 3839bool CalendarView::deleteEvent(const QString &uid)
3840{ 3840{
3841 Event *ev = mCalendar->event(uid); 3841 Event *ev = mCalendar->event(uid);
3842 if (ev) { 3842 if (ev) {
3843 deleteEvent(ev); 3843 deleteEvent(ev);
3844 return true; 3844 return true;
3845 } else { 3845 } else {
3846 return false; 3846 return false;
3847 } 3847 }
3848} 3848}
3849 3849
3850/*****************************************************************************/ 3850/*****************************************************************************/
3851 3851
3852void CalendarView::action_mail() 3852void CalendarView::action_mail()
3853{ 3853{
3854#ifndef KORG_NOMAIL 3854#ifndef KORG_NOMAIL
3855 KOMailClient mailClient; 3855 KOMailClient mailClient;
3856 3856
3857 Incidence *incidence = currentSelection(); 3857 Incidence *incidence = currentSelection();
3858 3858
3859 if (!incidence) { 3859 if (!incidence) {
3860 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3860 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3861 return; 3861 return;
3862 } 3862 }
3863 if(incidence->attendeeCount() == 0 ) { 3863 if(incidence->attendeeCount() == 0 ) {
3864 KMessageBox::sorry(this, 3864 KMessageBox::sorry(this,
3865 i18n("Can't generate mail:\nNo attendees defined.\n")); 3865 i18n("Can't generate mail:\nNo attendees defined.\n"));
3866 return; 3866 return;
3867 } 3867 }
3868 3868
3869 CalendarLocal cal_tmp; 3869 CalendarLocal cal_tmp;
3870 Event *event = 0; 3870 Event *event = 0;
3871 Event *ev = 0; 3871 Event *ev = 0;
3872 if ( incidence && incidence->typeID() == eventID ) { 3872 if ( incidence && incidence->typeID() == eventID ) {
3873 event = static_cast<Event *>(incidence); 3873 event = static_cast<Event *>(incidence);
3874 ev = new Event(*event); 3874 ev = new Event(*event);
3875 cal_tmp.addEvent(ev); 3875 cal_tmp.addEvent(ev);
3876 } 3876 }
3877 ICalFormat mForm(); 3877 ICalFormat mForm();
3878 QString attachment = mForm.toString( &cal_tmp ); 3878 QString attachment = mForm.toString( &cal_tmp );
3879 if (ev) delete(ev); 3879 if (ev) delete(ev);
3880 3880
3881 mailClient.mailAttendees(currentSelection(), attachment); 3881 mailClient.mailAttendees(currentSelection(), attachment);
3882 3882
3883#endif 3883#endif
3884 3884
3885#if 0 3885#if 0
3886 Event *anEvent = 0; 3886 Event *anEvent = 0;
3887 if (mViewManager->currentView()->isEventView()) { 3887 if (mViewManager->currentView()->isEventView()) {
3888 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); 3888 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
3889 } 3889 }
3890 3890
3891 if (!anEvent) { 3891 if (!anEvent) {
3892 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3892 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3893 return; 3893 return;
3894 } 3894 }
3895 if(anEvent->attendeeCount() == 0 ) { 3895 if(anEvent->attendeeCount() == 0 ) {
3896 KMessageBox::sorry(this, 3896 KMessageBox::sorry(this,
3897 i18n("Can't generate mail:\nNo attendees defined.\n")); 3897 i18n("Can't generate mail:\nNo attendees defined.\n"));
3898 return; 3898 return;
3899 } 3899 }
3900 3900
3901 mailobject.emailEvent(anEvent); 3901 mailobject.emailEvent(anEvent);
3902#endif 3902#endif
3903} 3903}
3904 3904
3905 3905
3906void CalendarView::schedule_publish(Incidence *incidence) 3906void CalendarView::schedule_publish(Incidence *incidence)
3907{ 3907{
3908 Event *event = 0; 3908 Event *event = 0;
3909 Todo *todo = 0; 3909 Todo *todo = 0;
3910 3910
3911 if (incidence == 0) { 3911 if (incidence == 0) {
3912 incidence = mViewManager->currentView()->selectedIncidences().first(); 3912 incidence = mViewManager->currentView()->selectedIncidences().first();
3913 if (incidence == 0) { 3913 if (incidence == 0) {
3914 incidence = mTodoList->selectedIncidences().first(); 3914 incidence = mTodoList->selectedIncidences().first();
3915 } 3915 }
3916 } 3916 }
3917 if ( incidence && incidence->typeID() == eventID ) { 3917 if ( incidence && incidence->typeID() == eventID ) {
3918 event = static_cast<Event *>(incidence); 3918 event = static_cast<Event *>(incidence);
3919 } else { 3919 } else {
3920 if ( incidence && incidence->typeID() == todoID ) { 3920 if ( incidence && incidence->typeID() == todoID ) {
3921 todo = static_cast<Todo *>(incidence); 3921 todo = static_cast<Todo *>(incidence);
3922 } 3922 }
3923 } 3923 }
3924 3924
3925 if (!event && !todo) { 3925 if (!event && !todo) {
3926 KMessageBox::sorry(this,i18n("No event selected.")); 3926 KMessageBox::sorry(this,i18n("No event selected."));
3927 return; 3927 return;
3928 } 3928 }
3929 3929
3930 PublishDialog *publishdlg = new PublishDialog(); 3930 PublishDialog *publishdlg = new PublishDialog();
3931 if (incidence->attendeeCount()>0) { 3931 if (incidence->attendeeCount()>0) {
3932 QPtrList<Attendee> attendees = incidence->attendees(); 3932 QPtrList<Attendee> attendees = incidence->attendees();
3933 attendees.first(); 3933 attendees.first();
3934 while ( attendees.current()!=0 ) { 3934 while ( attendees.current()!=0 ) {
3935 publishdlg->addAttendee(attendees.current()); 3935 publishdlg->addAttendee(attendees.current());
3936 attendees.next(); 3936 attendees.next();
3937 } 3937 }
3938 } 3938 }
3939 bool send = true; 3939 bool send = true;
3940 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 3940 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
3941 if ( publishdlg->exec() != QDialog::Accepted ) 3941 if ( publishdlg->exec() != QDialog::Accepted )
3942 send = false; 3942 send = false;
3943 } 3943 }
3944 if ( send ) { 3944 if ( send ) {
3945 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3945 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3946 if ( event ) { 3946 if ( event ) {
3947 Event *ev = new Event(*event); 3947 Event *ev = new Event(*event);
3948 ev->registerObserver(0); 3948 ev->registerObserver(0);
3949 ev->clearAttendees(); 3949 ev->clearAttendees();
3950 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3950 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3951 delete(ev); 3951 delete(ev);
3952 } 3952 }
3953 } else { 3953 } else {
3954 if ( todo ) { 3954 if ( todo ) {
3955 Todo *ev = new Todo(*todo); 3955 Todo *ev = new Todo(*todo);
3956 ev->registerObserver(0); 3956 ev->registerObserver(0);
3957 ev->clearAttendees(); 3957 ev->clearAttendees();
3958 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3958 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3959 delete(ev); 3959 delete(ev);
3960 } 3960 }
3961 } 3961 }
3962 } 3962 }
3963 } 3963 }
3964 delete publishdlg; 3964 delete publishdlg;
3965} 3965}
3966 3966
3967void CalendarView::schedule_request(Incidence *incidence) 3967void CalendarView::schedule_request(Incidence *incidence)
3968{ 3968{
3969 schedule(Scheduler::Request,incidence); 3969 schedule(Scheduler::Request,incidence);
3970} 3970}
3971 3971
3972void CalendarView::schedule_refresh(Incidence *incidence) 3972void CalendarView::schedule_refresh(Incidence *incidence)
3973{ 3973{
3974 schedule(Scheduler::Refresh,incidence); 3974 schedule(Scheduler::Refresh,incidence);
3975} 3975}
3976 3976
3977void CalendarView::schedule_cancel(Incidence *incidence) 3977void CalendarView::schedule_cancel(Incidence *incidence)
3978{ 3978{
3979 schedule(Scheduler::Cancel,incidence); 3979 schedule(Scheduler::Cancel,incidence);
3980} 3980}
3981 3981
3982void CalendarView::schedule_add(Incidence *incidence) 3982void CalendarView::schedule_add(Incidence *incidence)
3983{ 3983{
3984 schedule(Scheduler::Add,incidence); 3984 schedule(Scheduler::Add,incidence);
3985} 3985}
3986 3986
3987void CalendarView::schedule_reply(Incidence *incidence) 3987void CalendarView::schedule_reply(Incidence *incidence)
3988{ 3988{
3989 schedule(Scheduler::Reply,incidence); 3989 schedule(Scheduler::Reply,incidence);
3990} 3990}
3991 3991
3992void CalendarView::schedule_counter(Incidence *incidence) 3992void CalendarView::schedule_counter(Incidence *incidence)
3993{ 3993{
3994 schedule(Scheduler::Counter,incidence); 3994 schedule(Scheduler::Counter,incidence);
3995} 3995}
3996 3996
3997void CalendarView::schedule_declinecounter(Incidence *incidence) 3997void CalendarView::schedule_declinecounter(Incidence *incidence)
3998{ 3998{
3999 schedule(Scheduler::Declinecounter,incidence); 3999 schedule(Scheduler::Declinecounter,incidence);
4000} 4000}
4001 4001
4002void CalendarView::schedule_publish_freebusy(int daysToPublish) 4002void CalendarView::schedule_publish_freebusy(int daysToPublish)
4003{ 4003{
4004 QDateTime start = QDateTime::currentDateTime(); 4004 QDateTime start = QDateTime::currentDateTime();
4005 QDateTime end = start.addDays(daysToPublish); 4005 QDateTime end = start.addDays(daysToPublish);
4006 4006
4007 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); 4007 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
4008 freebusy->setOrganizer(KOPrefs::instance()->email()); 4008 freebusy->setOrganizer(KOPrefs::instance()->email());
4009 4009
4010 4010
4011 PublishDialog *publishdlg = new PublishDialog(); 4011 PublishDialog *publishdlg = new PublishDialog();
4012 if ( publishdlg->exec() == QDialog::Accepted ) { 4012 if ( publishdlg->exec() == QDialog::Accepted ) {
4013 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 4013 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
4014 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { 4014 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
4015 delete(freebusy); 4015 delete(freebusy);
4016 } 4016 }
4017 } 4017 }
4018 delete publishdlg; 4018 delete publishdlg;
4019} 4019}
4020 4020
4021void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) 4021void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
4022{ 4022{
4023 Event *event = 0; 4023 Event *event = 0;
4024 Todo *todo = 0; 4024 Todo *todo = 0;
4025 4025
4026 if (incidence == 0) { 4026 if (incidence == 0) {
4027 incidence = mViewManager->currentView()->selectedIncidences().first(); 4027 incidence = mViewManager->currentView()->selectedIncidences().first();
4028 if (incidence == 0) { 4028 if (incidence == 0) {
4029 incidence = mTodoList->selectedIncidences().first(); 4029 incidence = mTodoList->selectedIncidences().first();
4030 } 4030 }
4031 } 4031 }
4032 if ( incidence && incidence->typeID() == eventID ) { 4032 if ( incidence && incidence->typeID() == eventID ) {
4033 event = static_cast<Event *>(incidence); 4033 event = static_cast<Event *>(incidence);
4034 } 4034 }
4035 if ( incidence && incidence->typeID() == todoID ) { 4035 if ( incidence && incidence->typeID() == todoID ) {
4036 todo = static_cast<Todo *>(incidence); 4036 todo = static_cast<Todo *>(incidence);
4037 } 4037 }
4038 4038
4039 if (!event && !todo) { 4039 if (!event && !todo) {
4040 KMessageBox::sorry(this,i18n("No event selected.")); 4040 KMessageBox::sorry(this,i18n("No event selected."));
4041 return; 4041 return;
4042 } 4042 }
4043 4043
4044 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { 4044 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
4045 KMessageBox::sorry(this,i18n("The event has no attendees.")); 4045 KMessageBox::sorry(this,i18n("The event has no attendees."));
4046 return; 4046 return;
4047 } 4047 }
4048 4048
4049 Event *ev = 0; 4049 Event *ev = 0;
4050 if (event) ev = new Event(*event); 4050 if (event) ev = new Event(*event);
4051 Todo *to = 0; 4051 Todo *to = 0;
4052 if (todo) to = new Todo(*todo); 4052 if (todo) to = new Todo(*todo);
4053 4053
4054 if (method == Scheduler::Reply || method == Scheduler::Refresh) { 4054 if (method == Scheduler::Reply || method == Scheduler::Refresh) {
4055 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 4055 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
4056 if (!me) { 4056 if (!me) {
4057 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); 4057 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails."));
4058 return; 4058 return;
4059 } 4059 }
4060 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { 4060 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
4061 StatusDialog *statdlg = new StatusDialog(this); 4061 StatusDialog *statdlg = new StatusDialog(this);
4062 if (!statdlg->exec()==QDialog::Accepted) return; 4062 if (!statdlg->exec()==QDialog::Accepted) return;
4063 me->setStatus( statdlg->status() ); 4063 me->setStatus( statdlg->status() );
4064 delete(statdlg); 4064 delete(statdlg);
4065 } 4065 }
4066 Attendee *menew = new Attendee(*me); 4066 Attendee *menew = new Attendee(*me);
4067 if (ev) { 4067 if (ev) {
4068 ev->clearAttendees(); 4068 ev->clearAttendees();
4069 ev->addAttendee(menew,false); 4069 ev->addAttendee(menew,false);
4070 } else { 4070 } else {
4071 if (to) { 4071 if (to) {
4072 todo->clearAttendees(); 4072 todo->clearAttendees();
4073 todo->addAttendee(menew,false); 4073 todo->addAttendee(menew,false);
4074 } 4074 }
4075 } 4075 }
4076 } 4076 }
4077 4077
4078 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 4078 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
4079 if (ev) { 4079 if (ev) {
4080 if ( !dlg->addMessage(ev,method) ) delete(ev); 4080 if ( !dlg->addMessage(ev,method) ) delete(ev);
4081 } else { 4081 } else {
4082 if (to) { 4082 if (to) {
4083 if ( !dlg->addMessage(to,method) ) delete(to); 4083 if ( !dlg->addMessage(to,method) ) delete(to);
4084 } 4084 }
4085 } 4085 }
4086} 4086}
4087 4087
4088void CalendarView::openAddressbook() 4088void CalendarView::openAddressbook()
4089{ 4089{
4090 KRun::runCommand("kaddressbook"); 4090 KRun::runCommand("kaddressbook");
4091} 4091}
4092 4092
4093void CalendarView::setModified(bool modified) 4093void CalendarView::setModified(bool modified)
4094{ 4094{
4095 //qDebug("CalendarView::setModified %d ", modified); 4095 //qDebug("CalendarView::setModified %d ", modified);
4096 if ( modified ) 4096 if ( modified )
4097 emit signalmodified(); 4097 emit signalmodified();
4098 mModified = modified; 4098 mModified = modified;
4099 if ( mModified ) 4099 if ( mModified )
4100 emit modifiedChanged(mModified); 4100 emit modifiedChanged(mModified);
4101 4101
4102} 4102}
4103 4103
4104bool CalendarView::isReadOnly() 4104bool CalendarView::isReadOnly()
4105{ 4105{
4106 return mReadOnly; 4106 return mReadOnly;
4107} 4107}
4108 4108
4109void CalendarView::setReadOnly(bool readOnly) 4109void CalendarView::setReadOnly(bool readOnly)
4110{ 4110{
4111 if (mReadOnly != readOnly) { 4111 if (mReadOnly != readOnly) {
4112 mReadOnly = readOnly; 4112 mReadOnly = readOnly;
4113 emit readOnlyChanged(mReadOnly); 4113 emit readOnlyChanged(mReadOnly);
4114 } 4114 }
4115} 4115}
4116 4116
4117bool CalendarView::isModified() 4117bool CalendarView::isModified()
4118{ 4118{
4119 return mModified; 4119 return mModified;
4120} 4120}
4121void CalendarView::slotprintSelInc() 4121void CalendarView::slotprintSelInc()
4122{ 4122{
4123 if ( currentSelection() == 0 ) { 4123 if ( currentSelection() == 0 ) {
4124 KMessageBox::sorry(this,i18n("There is nothing selected!")); 4124 KMessageBox::sorry(this,i18n("There is nothing selected!"));
4125 return; 4125 return;
4126 } 4126 }
4127 showIncidence(); 4127 showIncidence();
4128 getEventViewerDialog()->print(); 4128 getEventViewerDialog()->print();
4129 4129
4130} 4130}
4131void CalendarView::printSetup() 4131void CalendarView::printSetup()
4132{ 4132{
4133#ifndef KORG_NOPRINTER 4133#ifndef KORG_NOPRINTER
4134 createPrinter(); 4134 createPrinter();
4135 4135
4136 mCalPrinter->setupPrinter(); 4136 mCalPrinter->setupPrinter();
4137#endif 4137#endif
4138} 4138}
4139 4139
4140void CalendarView::print() 4140void CalendarView::print()
4141{ 4141{
4142#ifndef KORG_NOPRINTER 4142#ifndef KORG_NOPRINTER
4143 createPrinter(); 4143 createPrinter();
4144 4144
4145 DateList tmpDateList = mNavigator->selectedDates(); 4145 DateList tmpDateList = mNavigator->selectedDates();
4146 mCalPrinter->print(CalPrinter::Month, 4146 mCalPrinter->print(CalPrinter::Month,
4147 tmpDateList.first(), tmpDateList.last()); 4147 tmpDateList.first(), tmpDateList.last());
4148#endif 4148#endif
4149} 4149}
4150 4150
4151void CalendarView::printPreview() 4151void CalendarView::printPreview()
4152{ 4152{
4153#ifndef KORG_NOPRINTER 4153#ifndef KORG_NOPRINTER
4154 kdDebug() << "CalendarView::printPreview()" << endl; 4154 kdDebug() << "CalendarView::printPreview()" << endl;
4155 4155
4156 createPrinter(); 4156 createPrinter();
4157 4157
4158 DateList tmpDateList = mNavigator->selectedDates(); 4158 DateList tmpDateList = mNavigator->selectedDates();
4159 4159
4160 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), 4160 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(),
4161 tmpDateList.last()); 4161 tmpDateList.last());
4162#endif 4162#endif
4163} 4163}
4164 4164
4165void CalendarView::exportICalendar() 4165void CalendarView::exportICalendar()
4166{ 4166{
4167 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); 4167 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this);
4168 4168
4169 // Force correct extension 4169 // Force correct extension
4170 if (filename.right(4) != ".ics") filename += ".ics"; 4170 if (filename.right(4) != ".ics") filename += ".ics";
4171 4171
4172 FileStorage storage( mCalendar, filename, new ICalFormat() ); 4172 FileStorage storage( mCalendar, filename, new ICalFormat() );
4173 storage.save(); 4173 storage.save();
4174} 4174}
4175 4175
4176bool CalendarView::exportVCalendar( QString filename ) 4176bool CalendarView::exportVCalendar( QString filename )
4177{ 4177{
4178 if (mCalendar->journals().count() > 0) { 4178 if (mCalendar->journals().count() > 0) {
4179 int result = KMessageBox::warningContinueCancel(this, 4179 int result = KMessageBox::warningContinueCancel(this,
4180 i18n("The journal entries can not be\nexported to a vCalendar file."), 4180 i18n("The journal entries can not be\nexported to a vCalendar file."),
4181 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 4181 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
4182 true); 4182 true);
4183 if (result != KMessageBox::Continue) return false; 4183 if (result != KMessageBox::Continue) return false;
4184 } 4184 }
4185 4185
4186 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); 4186 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this);
4187 4187
4188 // Force correct extension 4188 // Force correct extension
4189 if (filename.right(4) != ".vcs") filename += ".vcs"; 4189 if (filename.right(4) != ".vcs") filename += ".vcs";
4190 4190
4191 FileStorage storage( mCalendar, filename, new VCalFormat ); 4191 FileStorage storage( mCalendar, filename, new VCalFormat );
4192 return storage.save(); 4192 return storage.save();
4193 4193
4194} 4194}
4195 4195
4196void CalendarView::eventUpdated(Incidence *) 4196void CalendarView::eventUpdated(Incidence *)
4197{ 4197{
4198 setModified(); 4198 setModified();
4199 // Don't call updateView here. The code, which has caused the update of the 4199 // Don't call updateView here. The code, which has caused the update of the
4200 // event is responsible for updating the view. 4200 // event is responsible for updating the view.
4201 // updateView(); 4201 // updateView();
4202} 4202}
4203 4203
4204void CalendarView::adaptNavigationUnits() 4204void CalendarView::adaptNavigationUnits()
4205{ 4205{
4206 if (mViewManager->currentView()->isEventView()) { 4206 if (mViewManager->currentView()->isEventView()) {
4207 int days = mViewManager->currentView()->currentDateCount(); 4207 int days = mViewManager->currentView()->currentDateCount();
4208 if (days == 1) { 4208 if (days == 1) {
4209 emit changeNavStringPrev(i18n("&Previous Day")); 4209 emit changeNavStringPrev(i18n("&Previous Day"));
4210 emit changeNavStringNext(i18n("&Next Day")); 4210 emit changeNavStringNext(i18n("&Next Day"));
4211 } else { 4211 } else {
4212 emit changeNavStringPrev(i18n("&Previous Week")); 4212 emit changeNavStringPrev(i18n("&Previous Week"));
4213 emit changeNavStringNext(i18n("&Next Week")); 4213 emit changeNavStringNext(i18n("&Next Week"));
4214 } 4214 }
4215 } 4215 }
4216} 4216}
4217 4217
4218void CalendarView::processMainViewSelection( Incidence *incidence ) 4218void CalendarView::processMainViewSelection( Incidence *incidence )
4219{ 4219{
4220 if ( incidence ) mTodoList->clearSelection(); 4220 if ( incidence ) mTodoList->clearSelection();
4221 processIncidenceSelection( incidence ); 4221 processIncidenceSelection( incidence );
4222} 4222}
4223 4223
4224void CalendarView::processTodoListSelection( Incidence *incidence ) 4224void CalendarView::processTodoListSelection( Incidence *incidence )
4225{ 4225{
4226 if ( incidence && mViewManager->currentView() ) { 4226 if ( incidence && mViewManager->currentView() ) {
4227 mViewManager->currentView()->clearSelection(); 4227 mViewManager->currentView()->clearSelection();
4228 } 4228 }
4229 processIncidenceSelection( incidence ); 4229 processIncidenceSelection( incidence );
4230} 4230}
4231 4231
4232void CalendarView::processIncidenceSelection( Incidence *incidence ) 4232void CalendarView::processIncidenceSelection( Incidence *incidence )
4233{ 4233{
4234 emit incidenceSelected( incidence ); 4234 emit incidenceSelected( incidence );
4235 if ( incidence == mSelectedIncidence ) return; 4235 if ( incidence == mSelectedIncidence ) return;
4236 mSelectedIncidence = incidence; 4236 mSelectedIncidence = incidence;
4237 4237
4238 if ( incidence && incidence->typeID() == eventID ) { 4238 if ( incidence && incidence->typeID() == eventID ) {
4239 Event *event = static_cast<Event *>( incidence ); 4239 Event *event = static_cast<Event *>( incidence );
4240 if ( event->organizer() == KOPrefs::instance()->email() ) { 4240 if ( event->organizer() == KOPrefs::instance()->email() ) {
4241 emit organizerEventsSelected( true ); 4241 emit organizerEventsSelected( true );
4242 } else { 4242 } else {
4243 emit organizerEventsSelected(false); 4243 emit organizerEventsSelected(false);
4244 } 4244 }
4245 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 4245 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
4246 KOPrefs::instance()->email() ) ) { 4246 KOPrefs::instance()->email() ) ) {
4247 emit groupEventsSelected( true ); 4247 emit groupEventsSelected( true );
4248 } else { 4248 } else {
4249 emit groupEventsSelected(false); 4249 emit groupEventsSelected(false);
4250 } 4250 }
4251 return; 4251 return;
4252 } else { 4252 } else {
4253 if ( incidence && incidence->typeID() == todoID ) { 4253 if ( incidence && incidence->typeID() == todoID ) {
4254 emit todoSelected( true ); 4254 emit todoSelected( true );
4255 Todo *event = static_cast<Todo *>( incidence ); 4255 Todo *event = static_cast<Todo *>( incidence );
4256 if ( event->organizer() == KOPrefs::instance()->email() ) { 4256 if ( event->organizer() == KOPrefs::instance()->email() ) {
4257 emit organizerEventsSelected( true ); 4257 emit organizerEventsSelected( true );
4258 } else { 4258 } else {
4259 emit organizerEventsSelected(false); 4259 emit organizerEventsSelected(false);
4260 } 4260 }
4261 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 4261 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
4262 KOPrefs::instance()->email() ) ) { 4262 KOPrefs::instance()->email() ) ) {
4263 emit groupEventsSelected( true ); 4263 emit groupEventsSelected( true );
4264 } else { 4264 } else {
4265 emit groupEventsSelected(false); 4265 emit groupEventsSelected(false);
4266 } 4266 }
4267 return; 4267 return;
4268 } else { 4268 } else {
4269 emit todoSelected( false ); 4269 emit todoSelected( false );
4270 emit organizerEventsSelected(false); 4270 emit organizerEventsSelected(false);
4271 emit groupEventsSelected(false); 4271 emit groupEventsSelected(false);
4272 } 4272 }
4273 return; 4273 return;
4274 } 4274 }
4275 4275
4276 /* if ( incidence && incidence->typeID() == todoID ) { 4276 /* if ( incidence && incidence->typeID() == todoID ) {
4277 emit todoSelected( true ); 4277 emit todoSelected( true );
4278 } else { 4278 } else {
4279 emit todoSelected( false ); 4279 emit todoSelected( false );
4280 }*/ 4280 }*/
4281} 4281}
4282 4282
4283 4283
4284void CalendarView::checkClipboard() 4284void CalendarView::checkClipboard()
4285{ 4285{
4286#ifndef KORG_NODND 4286#ifndef KORG_NODND
4287 if (ICalDrag::canDecode(QApplication::clipboard()->data())) { 4287 if (ICalDrag::canDecode(QApplication::clipboard()->data())) {
4288 emit pasteEnabled(true); 4288 emit pasteEnabled(true);
4289 } else { 4289 } else {
4290 emit pasteEnabled(false); 4290 emit pasteEnabled(false);
4291 } 4291 }
4292#endif 4292#endif
4293} 4293}
4294 4294
4295void CalendarView::showDates(const DateList &selectedDates) 4295void CalendarView::showDates(const DateList &selectedDates)
4296{ 4296{
4297 // kdDebug() << "CalendarView::selectDates()" << endl; 4297 // kdDebug() << "CalendarView::selectDates()" << endl;
4298 4298
4299 4299
4300 if ( !mBlockShowDates ) { 4300 if ( !mBlockShowDates ) {
4301 if ( mViewManager->currentView() ) { 4301 if ( mViewManager->currentView() ) {
4302 updateView( selectedDates.first(), selectedDates.last() ); 4302 updateView( selectedDates.first(), selectedDates.last() );
4303 } else { 4303 } else {
4304 mViewManager->showAgendaView(); 4304 mViewManager->showAgendaView();
4305 } 4305 }
4306 } 4306 }
4307 4307
4308 QDate date = selectedDates.first(); 4308 QDate date = selectedDates.first();
4309 if ( ! date.isValid() ) { 4309 if ( ! date.isValid() ) {
4310 topLevelWidget()->setCaption(""); 4310 topLevelWidget()->setCaption("");
4311 return; 4311 return;
4312 } 4312 }
4313 4313
4314 QString selDates; 4314 QString selDates;
4315 selDates = KGlobal::locale()->formatDate( date, true); 4315 selDates = KGlobal::locale()->formatDate( date, true);
4316 if (selectedDates.first() < selectedDates.last() ) 4316 if (selectedDates.first() < selectedDates.last() )
4317 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); 4317 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true);
4318 else { 4318 else {
4319 QString addString; 4319 QString addString;
4320 if ( date == QDateTime::currentDateTime().date() ) 4320 if ( date == QDateTime::currentDateTime().date() )
4321 addString = i18n("Today"); 4321 addString = i18n("Today");
4322 else if ( date == QDateTime::currentDateTime().date().addDays(1) ) 4322 else if ( date == QDateTime::currentDateTime().date().addDays(1) )
4323 addString = i18n("Tomorrow"); 4323 addString = i18n("Tomorrow");
4324 else if ( date == QDateTime::currentDateTime().date().addDays(-1) ) 4324 else if ( date == QDateTime::currentDateTime().date().addDays(-1) )
4325 addString = i18n("Yesterday"); 4325 addString = i18n("Yesterday");
4326 else if ( date == QDateTime::currentDateTime().date().addDays(-2) ) 4326 else if ( date == QDateTime::currentDateTime().date().addDays(-2) )
4327 addString = i18n("Day before yesterday"); 4327 addString = i18n("Day before yesterday");
4328 else if ( date == QDateTime::currentDateTime().date().addDays(2) ) 4328 else if ( date == QDateTime::currentDateTime().date().addDays(2) )
4329 addString = i18n("Day after tomorrow"); 4329 addString = i18n("Day after tomorrow");
4330 if ( !addString.isEmpty() ) { 4330 if ( !addString.isEmpty() ) {
4331 topLevelWidget()->setCaption( addString+", " + selDates ); 4331 topLevelWidget()->setCaption( addString+", " + selDates );
4332 return; 4332 return;
4333 } 4333 }
4334 } 4334 }
4335 topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); 4335 topLevelWidget()->setCaption( i18n("Dates: ") + selDates );
4336 4336
4337} 4337}
4338 4338
4339QPtrList<CalFilter> CalendarView::filters() 4339QPtrList<CalFilter> CalendarView::filters()
4340{ 4340{
4341 return mFilters; 4341 return mFilters;
4342 4342
4343} 4343}
4344void CalendarView::editFilters() 4344void CalendarView::editFilters()
4345{ 4345{
4346 // kdDebug() << "CalendarView::editFilters()" << endl; 4346 // kdDebug() << "CalendarView::editFilters()" << endl;
4347 4347
4348 CalFilter *filter = mFilters.first(); 4348 CalFilter *filter = mFilters.first();
4349 while(filter) { 4349 while(filter) {
4350 filter = mFilters.next(); 4350 filter = mFilters.next();
4351 } 4351 }
4352 4352
4353 mDialogManager->showFilterEditDialog(&mFilters); 4353 mDialogManager->showFilterEditDialog(&mFilters);
4354 updateFilter(); 4354 updateFilter();
4355} 4355}
4356void CalendarView::toggleFilter() 4356void CalendarView::toggleFilter()
4357{ 4357{
4358 if ( mLeftFrame->isHidden() ) { 4358 if ( mLeftFrame->isHidden() ) {
4359 toggleExpand(); 4359 toggleExpand();
4360 showFilter( true ); 4360 showFilter( true );
4361 } else 4361 } else
4362 showFilter(! mCalEditView->isVisible()); 4362 showFilter(! mCalEditView->isVisible());
4363} 4363}
4364 4364
4365KOFilterView *CalendarView::filterView() 4365KOFilterView *CalendarView::filterView()
4366{ 4366{
4367 return mFilterView; 4367 return mFilterView;
4368} 4368}
4369void CalendarView::selectFilter( int fil ) 4369void CalendarView::selectFilter( int fil )
4370{ 4370{
4371 mFilterView->setSelectedFilter( fil ); 4371 mFilterView->setSelectedFilter( fil );
4372 updateUnmanagedViews(); 4372 updateUnmanagedViews();
4373} 4373}
4374void CalendarView::showFilter(bool visible) 4374void CalendarView::showFilter(bool visible)
4375{ 4375{
4376#if 1 4376#if 1
4377 if (visible) { 4377 if (visible) {
4378 mCalEditView->readConfig(); 4378 mCalEditView->readConfig();
4379 mCalEditView->show(); 4379 mCalEditView->show();
4380 QValueList<int> sizes; 4380 QValueList<int> sizes;
4381 sizes = mLeftFrame->sizes(); 4381 sizes = mLeftFrame->sizes();
4382 if ( sizes.count() == 4 && sizes[3] < 20 ) { 4382 if ( sizes.count() == 4 && sizes[3] < 20 ) {
4383 sizes.clear(); 4383 sizes.clear();
4384 sizes << 100; 4384 sizes << 100;
4385 sizes << 0; 4385 sizes << 0;
4386 sizes << 0; 4386 sizes << 0;
4387 sizes << 100; 4387 sizes << 100;
4388 mLeftFrame->setSizes(sizes); 4388 mLeftFrame->setSizes(sizes);
4389 } 4389 }
4390#if 0 4390#if 0
4391 sizes = mLeftFrame->sizes(); 4391 sizes = mLeftFrame->sizes();
4392 int ccc = 0; 4392 int ccc = 0;
4393 while ( ccc < sizes.count()) { 4393 while ( ccc < sizes.count()) {
4394 qDebug("size %d %d ", ccc, sizes[ccc]); 4394 qDebug("size %d %d ", ccc, sizes[ccc]);
4395 ++ccc; 4395 ++ccc;
4396 } 4396 }
4397#endif 4397#endif
4398 4398
4399 } 4399 }
4400 else { 4400 else {
4401 mCalEditView->hide(); 4401 mCalEditView->hide();
4402 } 4402 }
4403#else 4403#else
4404 if (visible) mFilterView->show(); 4404 if (visible) mFilterView->show();
4405 else mFilterView->hide(); 4405 else mFilterView->hide();
4406#endif 4406#endif
4407} 4407}
4408void CalendarView::toggleFilerEnabled( ) 4408void CalendarView::toggleFilerEnabled( )
4409{ 4409{
4410 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); 4410 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() );
4411 if ( !mFilterView->filtersEnabled() ) 4411 if ( !mFilterView->filtersEnabled() )
4412 topLevelWidget()->setCaption( i18n("Filter disabled ") ); 4412 topLevelWidget()->setCaption( i18n("Filter disabled ") );
4413 updateUnmanagedViews(); 4413 updateUnmanagedViews();
4414 4414
4415} 4415}
4416void CalendarView::updateFilter() 4416void CalendarView::updateFilter()
4417{ 4417{
4418 CalFilter *filter = mFilterView->selectedFilter(); 4418 CalFilter *filter = mFilterView->selectedFilter();
4419 if (filter) { 4419 if (filter) {
4420 QString mess; 4420 QString mess;
4421 if (mFilterView->filtersEnabled()) { 4421 if (mFilterView->filtersEnabled()) {
4422 mess = i18n("Filter selected: ")+filter->name(); 4422 mess = i18n("Filter selected: ")+filter->name();
4423 filter->setEnabled(true); 4423 filter->setEnabled(true);
4424 } 4424 }
4425 else filter->setEnabled(false); 4425 else filter->setEnabled(false);
4426 mCalendar->setFilter(filter); 4426 mCalendar->setFilter(filter);
4427 updateView(); 4427 updateView();
4428 if ( !mess.isEmpty() ) 4428 if ( !mess.isEmpty() )
4429 topLevelWidget()->setCaption( mess ); 4429 topLevelWidget()->setCaption( mess );
4430 4430
4431 } 4431 }
4432 emit filtersUpdated(); 4432 emit filtersUpdated();
4433} 4433}
4434 4434
4435void CalendarView::filterEdited() 4435void CalendarView::filterEdited()
4436{ 4436{
4437 mFilterView->updateFilters(); 4437 mFilterView->updateFilters();
4438 updateFilter(); 4438 updateFilter();
4439 writeSettings(); 4439 writeSettings();
4440} 4440}
4441 4441
4442 4442
4443void CalendarView::takeOverEvent() 4443void CalendarView::takeOverEvent()
4444{ 4444{
4445 Incidence *incidence = currentSelection(); 4445 Incidence *incidence = currentSelection();
4446 4446
4447 if (!incidence) return; 4447 if (!incidence) return;
4448 4448
4449 incidence->setOrganizer(KOPrefs::instance()->email()); 4449 incidence->setOrganizer(KOPrefs::instance()->email());
4450 incidence->recreate(); 4450 incidence->recreate();
4451 incidence->setReadOnly(false); 4451 incidence->setReadOnly(false);
4452 4452
4453 updateView(); 4453 updateView();
4454} 4454}
4455 4455
4456void CalendarView::takeOverCalendar() 4456void CalendarView::takeOverCalendar()
4457{ 4457{
4458 // TODO: Create Calendar::allIncidences() function and use it here 4458 // TODO: Create Calendar::allIncidences() function and use it here
4459 4459
4460 clearAllViews(); 4460 clearAllViews();
4461 QPtrList<Event> events = mCalendar->events(); 4461 QPtrList<Event> events = mCalendar->events();
4462 for(uint i=0; i<events.count(); ++i) { 4462 for(uint i=0; i<events.count(); ++i) {
4463 events.at(i)->setOrganizer(KOPrefs::instance()->email()); 4463 events.at(i)->setOrganizer(KOPrefs::instance()->email());
4464 events.at(i)->recreate(); 4464 events.at(i)->recreate();
4465 events.at(i)->setReadOnly(false); 4465 events.at(i)->setReadOnly(false);
4466 } 4466 }
4467 4467
4468 QPtrList<Todo> todos = mCalendar->todos(); 4468 QPtrList<Todo> todos = mCalendar->todos();
4469 for(uint i=0; i<todos.count(); ++i) { 4469 for(uint i=0; i<todos.count(); ++i) {
4470 todos.at(i)->setOrganizer(KOPrefs::instance()->email()); 4470 todos.at(i)->setOrganizer(KOPrefs::instance()->email());
4471 todos.at(i)->recreate(); 4471 todos.at(i)->recreate();
4472 todos.at(i)->setReadOnly(false); 4472 todos.at(i)->setReadOnly(false);
4473 } 4473 }
4474 4474
4475 QPtrList<Journal> journals = mCalendar->journals(); 4475 QPtrList<Journal> journals = mCalendar->journals();
4476 for(uint i=0; i<journals.count(); ++i) { 4476 for(uint i=0; i<journals.count(); ++i) {
4477 journals.at(i)->setOrganizer(KOPrefs::instance()->email()); 4477 journals.at(i)->setOrganizer(KOPrefs::instance()->email());
4478 journals.at(i)->recreate(); 4478 journals.at(i)->recreate();
4479 journals.at(i)->setReadOnly(false); 4479 journals.at(i)->setReadOnly(false);
4480 } 4480 }
4481 4481
4482 updateView(); 4482 updateView();
4483} 4483}
4484 4484
4485void CalendarView::showIntro() 4485void CalendarView::showIntro()
4486{ 4486{
4487 kdDebug() << "To be implemented." << endl; 4487 kdDebug() << "To be implemented." << endl;
4488} 4488}
4489 4489
4490QWidgetStack *CalendarView::viewStack() 4490QWidgetStack *CalendarView::viewStack()
4491{ 4491{
4492 return mRightFrame; 4492 return mRightFrame;
4493} 4493}
4494 4494
4495QWidget *CalendarView::leftFrame() 4495QWidget *CalendarView::leftFrame()
4496{ 4496{
4497 return ( QWidget *)mLeftFrame; 4497 return ( QWidget *)mLeftFrame;
4498} 4498}
4499 4499
4500DateNavigator *CalendarView::dateNavigator() 4500DateNavigator *CalendarView::dateNavigator()
4501{ 4501{
4502 return mNavigator; 4502 return mNavigator;
4503} 4503}
4504 4504
4505KDateNavigator* CalendarView::dateNavigatorWidget() 4505KDateNavigator* CalendarView::dateNavigatorWidget()
4506{ 4506{
4507 return mDateNavigator->navigatorView(); 4507 return mDateNavigator->navigatorView();
4508} 4508}
4509void CalendarView::toggleDateNavigatorWidget() 4509void CalendarView::toggleDateNavigatorWidget()
4510{ 4510{
4511 KOPrefs::instance()->mShowDateNavigator = !KOPrefs::instance()->mShowDateNavigator ; 4511 KOPrefs::instance()->mShowDateNavigator = !KOPrefs::instance()->mShowDateNavigator ;
4512 4512
4513 if (!KOPrefs::instance()->mShowDateNavigator ) 4513 if (!KOPrefs::instance()->mShowDateNavigator )
4514 mDateNavigator->hide(); 4514 mDateNavigator->hide();
4515 else 4515 else
4516 mDateNavigator->show(); 4516 mDateNavigator->show();
4517} 4517}
4518void CalendarView::addView(KOrg::BaseView *view) 4518void CalendarView::addView(KOrg::BaseView *view)
4519{ 4519{
4520 mViewManager->addView(view); 4520 mViewManager->addView(view);
4521} 4521}
4522 4522
4523void CalendarView::showView(KOrg::BaseView *view) 4523void CalendarView::showView(KOrg::BaseView *view)
4524{ 4524{
4525 mViewManager->showView(view, mLeftFrame->isVisible()); 4525 mViewManager->showView(view, mLeftFrame->isVisible());
4526} 4526}
4527 4527
4528Incidence *CalendarView::currentSelection() 4528Incidence *CalendarView::currentSelection()
4529{ 4529{
4530 return mViewManager->currentSelection(); 4530 return mViewManager->currentSelection();
4531} 4531}
4532void CalendarView::toggleAllDaySize() 4532void CalendarView::toggleAllDaySize()
4533{ 4533{
4534 /* 4534 /*
4535 if ( KOPrefs::instance()->mAllDaySize > 47 ) 4535 if ( KOPrefs::instance()->mAllDaySize > 47 )
4536 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2; 4536 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2;
4537 else 4537 else
4538 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2; 4538 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2;
4539 */ 4539 */
4540 viewManager()->agendaView()->toggleAllDay(); 4540 viewManager()->agendaView()->toggleAllDay();
4541} 4541}
4542void CalendarView::toggleExpand() 4542void CalendarView::toggleExpand()
4543{ 4543{
4544 // if ( mLeftFrame->isHidden() ) { 4544 // if ( mLeftFrame->isHidden() ) {
4545 // mLeftFrame->show(); 4545 // mLeftFrame->show();
4546 // emit calendarViewExpanded( false ); 4546 // emit calendarViewExpanded( false );
4547 // } else { 4547 // } else {
4548 // mLeftFrame->hide(); 4548 // mLeftFrame->hide();
4549 // emit calendarViewExpanded( true ); 4549 // emit calendarViewExpanded( true );
4550 // } 4550 // }
4551 //qDebug(" CalendarView::toggleExpand()"); 4551 //qDebug(" CalendarView::toggleExpand()");
4552 globalFlagBlockAgenda = 1; 4552 globalFlagBlockAgenda = 1;
4553 emit calendarViewExpanded( !mLeftFrame->isHidden() ); 4553 emit calendarViewExpanded( !mLeftFrame->isHidden() );
4554 globalFlagBlockAgenda = 5; 4554 globalFlagBlockAgenda = 5;
4555 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() ); 4555 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() );
4556 //mViewManager->showView( 0, true ); 4556 //mViewManager->showView( 0, true );
4557} 4557}
4558 4558
4559void CalendarView::calendarModified( bool modified, Calendar * ) 4559void CalendarView::calendarModified( bool modified, Calendar * )
4560{ 4560{
4561 setModified( modified ); 4561 setModified( modified );
4562} 4562}
4563 4563
4564Todo *CalendarView::selectedTodo() 4564Todo *CalendarView::selectedTodo()
4565{ 4565{
4566 Incidence *incidence = currentSelection(); 4566 Incidence *incidence = currentSelection();
4567 if ( incidence && incidence->typeID() == todoID ) { 4567 if ( incidence && incidence->typeID() == todoID ) {
4568 return static_cast<Todo *>( incidence ); 4568 return static_cast<Todo *>( incidence );
4569 } 4569 }
4570 4570
4571 incidence = mTodoList->selectedIncidences().first(); 4571 incidence = mTodoList->selectedIncidences().first();
4572 if ( incidence && incidence->typeID() == todoID ) { 4572 if ( incidence && incidence->typeID() == todoID ) {
4573 return static_cast<Todo *>( incidence ); 4573 return static_cast<Todo *>( incidence );
4574 } 4574 }
4575 4575
4576 return 0; 4576 return 0;
4577} 4577}
4578 4578
4579void CalendarView::showIncidence() 4579void CalendarView::showIncidence()
4580{ 4580{
4581 mViewerCallerIsSearchDialog = false; 4581 mViewerCallerIsSearchDialog = false;
4582 Incidence *incidence = currentSelection(); 4582 Incidence *incidence = currentSelection();
4583 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 4583 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
4584 if ( incidence ) { 4584 if ( incidence ) {
4585 ShowIncidenceVisitor v; 4585 ShowIncidenceVisitor v;
4586 v.act( incidence, this ); 4586 v.act( incidence, this );
4587 } 4587 }
4588} 4588}
4589void CalendarView::editIncidenceDescription() 4589void CalendarView::editIncidenceDescription()
4590{ 4590{
4591 mFlagEditDescription = true; 4591 mFlagEditDescription = true;
4592 editIncidence(); 4592 editIncidence();
4593 mFlagEditDescription = false; 4593 mFlagEditDescription = false;
4594} 4594}
4595void CalendarView::editIncidence() 4595void CalendarView::editIncidence()
4596{ 4596{
4597 // qDebug("editIncidence() "); 4597 // qDebug("editIncidence() ");
4598 Incidence *incidence = currentSelection(); 4598 Incidence *incidence = currentSelection();
4599 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 4599 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
4600 if ( incidence ) { 4600 if ( incidence ) {
4601 EditIncidenceVisitor v; 4601 EditIncidenceVisitor v;
4602 v.act( incidence, this ); 4602 v.act( incidence, this );
4603 } 4603 }
4604} 4604}
4605 4605
4606void CalendarView::deleteIncidence() 4606void CalendarView::deleteIncidence()
4607{ 4607{
4608 Incidence *incidence = currentSelection(); 4608 Incidence *incidence = currentSelection();
4609 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 4609 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
4610 if ( incidence ) { 4610 if ( incidence ) {
4611 deleteIncidence(incidence); 4611 deleteIncidence(incidence);
4612 } 4612 }
4613} 4613}
4614void CalendarView::showIncidence(QString uid) 4614void CalendarView::showIncidence(QString uid)
4615{ 4615{
4616 Incidence *inc = mCalendar->incidence( uid ); 4616 Incidence *inc = mCalendar->incidence( uid );
4617 if ( inc ) 4617 if ( inc )
4618 showIncidence( inc ); 4618 showIncidence( inc );
4619} 4619}
4620void CalendarView::showIncidence(Incidence *incidence) 4620void CalendarView::showIncidence(Incidence *incidence)
4621{ 4621{
4622 mViewerCallerIsSearchDialog = false; 4622 mViewerCallerIsSearchDialog = false;
4623 //qDebug("%x %x ",sender (), mDialogManager->getSearchDialog() ); 4623 //qDebug("%x %x ",sender (), mDialogManager->getSearchDialog() );
4624 if ( sender() && mDialogManager->getSearchDialog() ) { 4624 if ( sender() && mDialogManager->getSearchDialog() ) {
4625 if ( sender () == mDialogManager->getSearchDialog()->listview() ) { 4625 if ( sender () == mDialogManager->getSearchDialog()->listview() ) {
4626 mViewerCallerIsSearchDialog = true; 4626 mViewerCallerIsSearchDialog = true;
4627 } 4627 }
4628 } 4628 }
4629 if ( incidence ) { 4629 if ( incidence ) {
4630 ShowIncidenceVisitor v; 4630 ShowIncidenceVisitor v;
4631 v.act( incidence, this ); 4631 v.act( incidence, this );
4632 } 4632 }
4633} 4633}
4634 4634
4635void CalendarView::editIncidence(Incidence *incidence) 4635void CalendarView::editIncidence(Incidence *incidence)
4636{ 4636{
4637 if ( incidence ) { 4637 if ( incidence ) {
4638 4638
4639 EditIncidenceVisitor v; 4639 EditIncidenceVisitor v;
4640 v.act( incidence, this ); 4640 v.act( incidence, this );
4641 4641
4642 } 4642 }
4643} 4643}
4644 4644
4645void CalendarView::deleteIncidence(Incidence *incidence) 4645void CalendarView::deleteIncidence(Incidence *incidence)
4646{ 4646{
4647 //qDebug(" CalendarView::deleteIncidence "); 4647 //qDebug(" CalendarView::deleteIncidence ");
4648 if ( incidence == 0 ) { 4648 if ( incidence == 0 ) {
4649 updateView(); 4649 updateView();
4650 emit updateSearchDialog(); 4650 emit updateSearchDialog();
4651 return; 4651 return;
4652 } 4652 }
4653 if ( incidence ) { 4653 if ( incidence ) {
4654 DeleteIncidenceVisitor v; 4654 DeleteIncidenceVisitor v;
4655 v.act( incidence, this ); 4655 v.act( incidence, this );
4656 } 4656 }
4657} 4657}
4658 4658
4659 4659
4660void CalendarView::lookForOutgoingMessages() 4660void CalendarView::lookForOutgoingMessages()
4661{ 4661{
4662 OutgoingDialog *ogd = mDialogManager->outgoingDialog(); 4662 OutgoingDialog *ogd = mDialogManager->outgoingDialog();
4663 ogd->loadMessages(); 4663 ogd->loadMessages();
4664} 4664}
4665 4665
4666void CalendarView::lookForIncomingMessages() 4666void CalendarView::lookForIncomingMessages()
4667{ 4667{
4668 IncomingDialog *icd = mDialogManager->incomingDialog(); 4668 IncomingDialog *icd = mDialogManager->incomingDialog();
4669 icd->retrieve(); 4669 icd->retrieve();
4670} 4670}
4671 4671
4672bool CalendarView::removeCompletedSubTodos( Todo* t ) 4672bool CalendarView::removeCompletedSubTodos( Todo* t )
4673{ 4673{
4674 bool deleteTodo = true; 4674 bool deleteTodo = true;
4675 QPtrList<Incidence> subTodos; 4675 QPtrList<Incidence> subTodos;
4676 Incidence *aTodo; 4676 Incidence *aTodo;
4677 subTodos = t->relations(); 4677 subTodos = t->relations();
4678 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) { 4678 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) {
4679 if (! removeCompletedSubTodos( (Todo*) aTodo )) 4679 if (! removeCompletedSubTodos( (Todo*) aTodo ))
4680 deleteTodo = false; 4680 deleteTodo = false;
4681 } 4681 }
4682 if ( deleteTodo ) { 4682 if ( deleteTodo ) {
4683 if ( t->isCompleted() && !t->doesRecur()) { 4683 if ( t->isCompleted() && !t->doesRecur()) {
4684 checkExternalId( t ); 4684 checkExternalId( t );
4685 mCalendar->deleteTodo( t ); 4685 mCalendar->deleteTodo( t );
4686 changeTodoDisplay( t,KOGlobals::EVENTDELETED ); 4686 changeTodoDisplay( t,KOGlobals::EVENTDELETED );
4687 } 4687 }
4688 else 4688 else
4689 deleteTodo = false; 4689 deleteTodo = false;
4690 } 4690 }
4691 return deleteTodo; 4691 return deleteTodo;
4692 4692
4693} 4693}
4694void CalendarView::purgeCompleted() 4694void CalendarView::purgeCompleted()
4695{ 4695{
4696 int result = KMessageBox::warningContinueCancel(this, 4696 int result = KMessageBox::warningContinueCancel(this,
4697 i18n("Delete all completed todos?\n(Completed recurring todos\nwill not be deleted!)"),i18n("Purge Todos"),i18n("Purge")); 4697 i18n("Delete all completed todos?\n(Completed recurring todos\nwill not be deleted!)"),i18n("Purge Todos"),i18n("Purge"));
4698 4698
4699 if (result == KMessageBox::Continue) { 4699 if (result == KMessageBox::Continue) {
4700 4700
4701 QPtrList<Todo> todoCal; 4701 QPtrList<Todo> todoCal;
4702 QPtrList<Todo> rootTodos; 4702 QPtrList<Todo> rootTodos;
4703 //QPtrList<Incidence> rel; 4703 //QPtrList<Incidence> rel;
4704 Todo *aTodo; 4704 Todo *aTodo;
4705 todoCal = calendar()->todos(); 4705 todoCal = calendar()->todos();
4706 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { 4706 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) {
4707 if ( !aTodo->relatedTo() ) 4707 if ( !aTodo->relatedTo() )
4708 rootTodos.append( aTodo ); 4708 rootTodos.append( aTodo );
4709 } 4709 }
4710 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { 4710 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) {
4711 removeCompletedSubTodos( aTodo ); 4711 removeCompletedSubTodos( aTodo );
4712 } 4712 }
4713 4713
4714 updateView(); 4714 updateView();
4715 } 4715 }
4716} 4716}
4717 4717
4718void CalendarView::slotCalendarChanged() 4718void CalendarView::slotCalendarChanged()
4719{ 4719{
4720 ; 4720 ;
4721} 4721}
4722 4722
4723void CalendarView::keyPressEvent ( QKeyEvent *e) 4723void CalendarView::keyPressEvent ( QKeyEvent *e)
4724{ 4724{
4725 //qDebug("CalendarView::keyPressEvent "); 4725 //qDebug("CalendarView::keyPressEvent ");
4726 e->ignore(); 4726 e->ignore();
4727} 4727}
4728 4728
4729 4729
4730bool CalendarView::sync(KSyncManager* manager, QString filename, int mode) 4730bool CalendarView::sync(KSyncManager* manager, QString filename, int mode)
4731{ 4731{
4732 4732
4733 if ( manager != mSyncManager) 4733 if ( manager != mSyncManager)
4734 qDebug("KO: Internal error-1. SyncManager mismatch "); 4734 qDebug("KO: Internal error-1. SyncManager mismatch ");
4735 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) { 4735 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) {
4736 qDebug("KO: SyncKDE request detected!"); 4736 qDebug("KO: SyncKDE request detected!");
4737 } 4737 }
4738 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 4738 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
4739 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 4739 mCurrentSyncName = mSyncManager->getCurrentSyncName();
4740 return syncCalendar( filename, mode ); 4740 return syncCalendar( filename, mode );
4741} 4741}
4742bool CalendarView::syncExternal(KSyncManager* manager, QString resource) 4742bool CalendarView::syncExternal(KSyncManager* manager, QString resource)
4743{ 4743{
4744 //mSyncManager = manager; 4744 //mSyncManager = manager;
4745 if ( manager != mSyncManager) 4745 if ( manager != mSyncManager)
4746 qDebug("KO: Internal error-2. SyncManager mismatch "); 4746 qDebug("KO: Internal error-2. SyncManager mismatch ");
4747 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 4747 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
4748 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 4748 mCurrentSyncName = mSyncManager->getCurrentSyncName();
4749 if ( resource == "sharp" ) 4749 if ( resource == "sharp" )
4750 syncExternal( 0 ); 4750 syncExternal( 0 );
4751 if ( resource == "phone" ) 4751 if ( resource == "phone" )
4752 syncExternal( 1 ); 4752 syncExternal( 1 );
4753 // pending setmodified 4753 // pending setmodified
4754 return true; 4754 return true;
4755} 4755}
4756void CalendarView::setSyncManager(KSyncManager* manager) 4756void CalendarView::setSyncManager(KSyncManager* manager)
4757{ 4757{
4758 mSyncManager = manager; 4758 mSyncManager = manager;
4759} 4759}
4760 4760
4761void CalendarView::removeSyncInfo( QString syncProfile) 4761void CalendarView::removeSyncInfo( QString syncProfile)
4762{ 4762{
4763 qDebug("KO: removeSyncInfo for profile %s ", syncProfile.latin1()); 4763 qDebug("KO: removeSyncInfo for profile %s ", syncProfile.latin1());
4764 mCalendar->removeSyncInfo( syncProfile ); 4764 mCalendar->removeSyncInfo( syncProfile );
4765 4765
4766} 4766}
4767 4767
4768void CalendarView::undo_delete() 4768void CalendarView::undo_delete()
4769{ 4769{
4770 //qDebug("undo_delete() "); 4770 //qDebug("undo_delete() ");
4771 Incidence* undo = mCalendar->undoIncidence(); 4771 Incidence* undo = mCalendar->undoIncidence();
4772 if ( !undo ) { 4772 if ( !undo ) {
4773 KMessageBox::sorry(this,i18n("There is nothing to undo!"), 4773 KMessageBox::sorry(this,i18n("There is nothing to undo!"),
4774 i18n("KO/Pi")); 4774 i18n("KO/Pi"));
4775 return; 4775 return;
4776 } 4776 }
4777 if ( KMessageBox::Continue ==KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( undo->summary(),0 ) + 4777 if ( KMessageBox::Continue ==KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( undo->summary(),0 ) +
4778 i18n("\nAre you sure you want\nto restore this?"), 4778 i18n("\nAre you sure you want\nto restore this?"),
4779 i18n("KO/Pi Confirmation"),i18n("Restore"))) { 4779 i18n("KO/Pi Confirmation"),i18n("Restore"))) {
4780 mCalendar->undoDeleteIncidence(); 4780 mCalendar->undoDeleteIncidence();
4781 updateView(); 4781 updateView();
4782 } 4782 }
4783} 4783}
4784 4784
4785void CalendarView::slotViewerClosed() 4785void CalendarView::slotViewerClosed()
4786{ 4786{
4787 QTimer::singleShot( 50, this, SLOT ( resetFocus() ) ); 4787 QTimer::singleShot( 50, this, SLOT ( resetFocus() ) );
4788} 4788}
4789 4789
4790void CalendarView::resetFocus() 4790void CalendarView::resetFocus()
4791{ 4791{
4792 if ( mViewerCallerIsSearchDialog ) { 4792 if ( mViewerCallerIsSearchDialog ) {
4793 if ( mDialogManager->getSearchDialog()->isVisible() ){ 4793 if ( mDialogManager->getSearchDialog()->isVisible() ){
4794 mDialogManager->getSearchDialog()->raise(); 4794 mDialogManager->getSearchDialog()->raise();
4795 mDialogManager->getSearchDialog()->setActiveWindow(); 4795 mDialogManager->getSearchDialog()->setActiveWindow();
4796 mDialogManager->getSearchDialog()->listview()->resetFocus(); 4796 mDialogManager->getSearchDialog()->listview()->resetFocus();
4797 } else 4797 } else
4798 mViewerCallerIsSearchDialog = false; 4798 mViewerCallerIsSearchDialog = false;
4799 } 4799 }
4800 if ( !mViewerCallerIsSearchDialog ) { 4800 if ( !mViewerCallerIsSearchDialog ) {
4801 //mViewManager->currentView()->setFocus(); 4801 //mViewManager->currentView()->setFocus();
4802 //qDebug("sssssssssssssssset focus "); 4802 //qDebug("sssssssssssssssset focus ");
4803 topLevelWidget()->raise(); 4803 topLevelWidget()->raise();
4804 setActiveWindow(); 4804 setActiveWindow();
4805 //setFocus(); 4805 //setFocus();
4806 } 4806 }
4807 mViewerCallerIsSearchDialog = false; 4807 mViewerCallerIsSearchDialog = false;
4808} 4808}
4809 4809
4810void CalendarView::showNextAlarms() 4810void CalendarView::showNextAlarms()
4811{ 4811{
4812 QString message; 4812 QString message;
4813 QDateTime nextAl = mCalendar->nextAlarmEventDateTime(); 4813 QDateTime nextAl = mCalendar->nextAlarmEventDateTime();
4814 if ( nextAl.isValid() && mNextAlarmDateTime > QDateTime::currentDateTime() ) { 4814 if ( nextAl.isValid() && mNextAlarmDateTime > QDateTime::currentDateTime() ) {
4815 QString sum = mCalendar->nextSummary(); 4815 QString sum = mCalendar->nextSummary();
4816 QDateTime nextA = mNextAlarmDateTime; 4816 QDateTime nextA = mNextAlarmDateTime;
4817 QDateTime cur = QDateTime::currentDateTime(); 4817 QDateTime cur = QDateTime::currentDateTime();
4818 int secs = cur.secsTo( nextA ); 4818 int secs = cur.secsTo( nextA );
4819 int min = secs /60; 4819 int min = secs /60;
4820 int hours = min /60; 4820 int hours = min /60;
4821 min = min % 60; 4821 min = min % 60;
4822 int days = hours /24; 4822 int days = hours /24;
4823 hours = hours % 24; 4823 hours = hours % 24;
4824 4824
4825 //message = i18n("The next alarm is in:\n"); 4825 //message = i18n("The next alarm is in:\n");
4826 if ( days > 1 ) 4826 if ( days > 1 )
4827 message += i18n("%1 days\n").arg( days ); 4827 message += i18n("%1 days\n").arg( days );
4828 else if ( days == 1 ) 4828 else if ( days == 1 )
4829 message += i18n("1 day\n"); 4829 message += i18n("1 day\n");
4830 if ( hours > 1 ) 4830 if ( hours > 1 )
4831 message += i18n("%1 hours\n").arg( hours ); 4831 message += i18n("%1 hours\n").arg( hours );
4832 else if ( hours == 1 ) 4832 else if ( hours == 1 )
4833 message += i18n("1 hour\n"); 4833 message += i18n("1 hour\n");
4834 if ( min > 1 ) 4834 if ( min > 1 )
4835 message += i18n("%1 minutes\n").arg( min ); 4835 message += i18n("%1 minutes\n").arg( min );
4836 else if ( min == 1 ) 4836 else if ( min == 1 )
4837 message += i18n("1 minute\n"); 4837 message += i18n("1 minute\n");
4838 if ( message.isEmpty() ) 4838 if ( message.isEmpty() )
4839 message = i18n("The next alarm is in\nless than one minute!"); 4839 message = i18n("The next alarm is in\nless than one minute!");
4840 else 4840 else
4841 message = i18n("The next alarm is in:\n") + message; 4841 message = i18n("The next alarm is in:\n") + message;
4842 message += i18n("\n(%1)\n\n%2\n(%3)\n").arg( KGlobal::locale()->formatDateTime(nextA , false)).arg(sum ).arg( KGlobal::locale()->formatDateTime(nextAl , false)) ; 4842 message += i18n("\n(%1)\n\n%2\n(%3)\n").arg( KGlobal::locale()->formatDateTime(nextA , false)).arg(sum ).arg( KGlobal::locale()->formatDateTime(nextAl , false)) ;
4843 } else { 4843 } else {
4844 message = i18n("There is no next alarm."); 4844 message = i18n("There is no next alarm.");
4845 4845
4846 } 4846 }
4847#ifdef DESKTOP_VERSION 4847#ifdef DESKTOP_VERSION
4848 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 4848 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
4849 message += i18n("\nThe internal alarm notification is disabled!\n"); 4849 message += i18n("\nThe internal alarm notification is disabled!\n");
4850 message += i18n("Enable it in the settings menu, TAB alarm."); 4850 message += i18n("Enable it in the settings menu, TAB alarm.");
4851 } 4851 }
4852 4852
4853#endif 4853#endif
4854 KMessageBox::information( this, message); 4854 KMessageBox::information( this, message);
4855} 4855}
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp
index 0dd5ef5..c738f7e 100644
--- a/korganizer/koagenda.cpp
+++ b/korganizer/koagenda.cpp
@@ -1,2268 +1,2268 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 Marcus Bains line. 5 Marcus Bains line.
6 Copyright (c) 2001 Ali Rahimi 6 Copyright (c) 2001 Ali Rahimi
7 7
8 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 (at your option) any later version.
12 12
13 This program is distributed in the hope that it will be useful, 13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 GNU General Public License for more details.
17 17
18 You should have received a copy of the GNU General Public License 18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software 19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 21
22 As a special exception, permission is given to link this program 22 As a special exception, permission is given to link this program
23 with any edition of Qt, and distribute the resulting executable, 23 with any edition of Qt, and distribute the resulting executable,
24 without including the source code for Qt in the source distribution. 24 without including the source code for Qt in the source distribution.
25*/ 25*/
26 26
27#ifndef _WIN32_ 27#ifndef _WIN32_
28#define protected public 28#define protected public
29#include <qwidget.h> 29#include <qwidget.h>
30#undef protected 30#undef protected
31#endif 31#endif
32#include <qintdict.h> 32#include <qintdict.h>
33#include <qdatetime.h> 33#include <qdatetime.h>
34#include <qapplication.h> 34#include <qapplication.h>
35#include <qpopupmenu.h> 35#include <qpopupmenu.h>
36#include <qcursor.h> 36#include <qcursor.h>
37#include <qpainter.h> 37#include <qpainter.h>
38 38
39#include <kdebug.h> 39#include <kdebug.h>
40#include <klocale.h> 40#include <klocale.h>
41#include <kiconloader.h> 41#include <kiconloader.h>
42#include <kglobal.h> 42#include <kglobal.h>
43 43
44#include "koagendaitem.h" 44#include "koagendaitem.h"
45#include "koprefs.h" 45#include "koprefs.h"
46#include "koglobals.h" 46#include "koglobals.h"
47 47
48#include "koagenda.h" 48#include "koagenda.h"
49 49
50#include <libkcal/event.h> 50#include <libkcal/event.h>
51#include <libkcal/todo.h> 51#include <libkcal/todo.h>
52 52
53#ifndef DESKTOP_VERSION 53#ifndef DESKTOP_VERSION
54#include <qpe/qpeapplication.h> 54#include <qpe/qpeapplication.h>
55#endif 55#endif
56 56
57//extern bool globalFlagBlockPainting; 57//extern bool globalFlagBlockPainting;
58extern int globalFlagBlockAgenda; 58extern int globalFlagBlockAgenda;
59extern int globalFlagBlockAgendaItemPaint; 59extern int globalFlagBlockAgendaItemPaint;
60extern int globalFlagBlockAgendaItemUpdate; 60extern int globalFlagBlockAgendaItemUpdate;
61extern int globalFlagBlockStartup; 61extern int globalFlagBlockStartup;
62 62
63 63
64//////////////////////////////////////////////////////////////////////////// 64////////////////////////////////////////////////////////////////////////////
65MarcusBains::MarcusBains(KOAgenda *_agenda,const char *name) 65MarcusBains::MarcusBains(KOAgenda *_agenda,const char *name)
66 : QFrame(_agenda->viewport(),name), agenda(_agenda) 66 : QFrame(_agenda->viewport(),name), agenda(_agenda)
67{ 67{
68 setLineWidth(0); 68 setLineWidth(0);
69 setMargin(0); 69 setMargin(0);
70 setBackgroundColor(Qt::red); 70 setBackgroundColor(Qt::red);
71 minutes = new QTimer(this); 71 minutes = new QTimer(this);
72 connect(minutes, SIGNAL(timeout()), this, SLOT(updateLoc())); 72 connect(minutes, SIGNAL(timeout()), this, SLOT(updateLoc()));
73 minutes->start(0, true); 73 minutes->start(0, true);
74 mTimeBox = new QLabel(this); 74 mTimeBox = new QLabel(this);
75 mTimeBox->setAlignment(Qt::AlignRight | Qt::AlignBottom); 75 mTimeBox->setAlignment(Qt::AlignRight | Qt::AlignBottom);
76 QPalette pal = mTimeBox->palette(); 76 QPalette pal = mTimeBox->palette();
77 pal.setColor(QColorGroup::Foreground, Qt::red); 77 pal.setColor(QColorGroup::Foreground, Qt::red);
78 mTimeBox->setPalette(pal); 78 mTimeBox->setPalette(pal);
79 //mTimeBox->setAutoMask(true); 79 //mTimeBox->setAutoMask(true);
80 80
81 agenda->addChild(mTimeBox); 81 agenda->addChild(mTimeBox);
82 82
83 oldToday = -1; 83 oldToday = -1;
84} 84}
85 85
86MarcusBains::~MarcusBains() 86MarcusBains::~MarcusBains()
87{ 87{
88 //delete minutes; 88 //delete minutes;
89} 89}
90 90
91int MarcusBains::todayColumn() 91int MarcusBains::todayColumn()
92{ 92{
93 QDate currentDate = QDate::currentDate(); 93 QDate currentDate = QDate::currentDate();
94 94
95 DateList dateList = agenda->dateList(); 95 DateList dateList = agenda->dateList();
96 DateList::ConstIterator it; 96 DateList::ConstIterator it;
97 int col = 0; 97 int col = 0;
98 for(it = dateList.begin(); it != dateList.end(); ++it) { 98 for(it = dateList.begin(); it != dateList.end(); ++it) {
99 if((*it) == currentDate) 99 if((*it) == currentDate)
100 return KOGlobals::self()->reverseLayout() ? 100 return KOGlobals::self()->reverseLayout() ?
101 agenda->columns() - 1 - col : col; 101 agenda->columns() - 1 - col : col;
102 ++col; 102 ++col;
103 } 103 }
104 104
105 return -1; 105 return -1;
106} 106}
107void MarcusBains::updateLoc() 107void MarcusBains::updateLoc()
108{ 108{
109 updateLocation(); 109 updateLocation();
110} 110}
111void MarcusBains::updateLocation(bool recalculate) 111void MarcusBains::updateLocation(bool recalculate)
112{ 112{
113 113
114 QTime tim = QTime::currentTime(); 114 QTime tim = QTime::currentTime();
115 //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1()); 115 //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1());
116 if((tim.hour() == 0) && (oldTime.hour()==23)) 116 if((tim.hour() == 0) && (oldTime.hour()==23))
117 recalculate = true; 117 recalculate = true;
118 118
119 int mins = tim.hour()*60 + tim.minute(); 119 int mins = tim.hour()*60 + tim.minute();
120 int minutesPerCell = 24 * 60 / agenda->rows(); 120 int minutesPerCell = 24 * 60 / agenda->rows();
121 int y = mins*agenda->gridSpacingY()/minutesPerCell; 121 int y = mins*agenda->gridSpacingY()/minutesPerCell;
122 int today = recalculate ? todayColumn() : oldToday; 122 int today = recalculate ? todayColumn() : oldToday;
123 int x = agenda->gridSpacingX()*today; 123 int x = agenda->gridSpacingX()*today;
124 bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled); 124 bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled);
125 125
126 oldTime = tim; 126 oldTime = tim;
127 oldToday = today; 127 oldToday = today;
128 128
129 if(disabled || (today<0)) { 129 if(disabled || (today<0)) {
130 hide(); mTimeBox->hide(); 130 hide(); mTimeBox->hide();
131 return; 131 return;
132 } else { 132 } else {
133 show(); mTimeBox->show(); 133 show(); mTimeBox->show();
134 } 134 }
135 135
136 if(recalculate) 136 if(recalculate)
137 setFixedSize(agenda->gridSpacingX(),1); 137 setFixedSize(agenda->gridSpacingX(),1);
138 agenda->moveChild(this, x, y); 138 agenda->moveChild(this, x, y);
139 raise(); 139 raise();
140 140
141 if(recalculate) 141 if(recalculate)
142 //mTimeBox->setFont(QFont("helvetica",10)); 142 //mTimeBox->setFont(QFont("helvetica",10));
143 mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont); 143 mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont);
144 144
145 mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds)); 145 mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds));
146 mTimeBox->adjustSize(); 146 mTimeBox->adjustSize();
147 // the -2 below is there because there is a bug in this program 147 // the -2 below is there because there is a bug in this program
148 // somewhere, where the last column of this widget is a few pixels 148 // somewhere, where the last column of this widget is a few pixels
149 // narrower than the other columns. 149 // narrower than the other columns.
150 int offs = (today==agenda->columns()-1) ? -4 : 0; 150 int offs = (today==agenda->columns()-1) ? -4 : 0;
151 agenda->moveChild(mTimeBox, 151 agenda->moveChild(mTimeBox,
152 x+agenda->gridSpacingX()-mTimeBox->width()+offs-1, 152 x+agenda->gridSpacingX()-mTimeBox->width()+offs-1,
153 y-mTimeBox->height()); 153 y-mTimeBox->height());
154 mTimeBox->raise(); 154 mTimeBox->raise();
155 //mTimeBox->setAutoMask(true); 155 //mTimeBox->setAutoMask(true);
156 int secs = QTime::currentTime().second(); 156 int secs = QTime::currentTime().second();
157 minutes->start( (60 - secs +1)*1000 ,true); 157 minutes->start( (60 - secs +1)*1000 ,true);
158} 158}
159 159
160 160
161//////////////////////////////////////////////////////////////////////////// 161////////////////////////////////////////////////////////////////////////////
162 162
163 163
164/* 164/*
165 Create an agenda widget with rows rows and columns columns. 165 Create an agenda widget with rows rows and columns columns.
166*/ 166*/
167KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent, 167KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent,
168 const char *name,WFlags f) : 168 const char *name,WFlags f) :
169 QScrollView(parent,name,f) 169 QScrollView(parent,name,f)
170{ 170{
171 171
172 mAllAgendaPopup = 0; 172 mAllAgendaPopup = 0;
173 mColumns = columns; 173 mColumns = columns;
174 mRows = rows; 174 mRows = rows;
175 mGridSpacingY = rowSize; 175 mGridSpacingY = rowSize;
176 mAllDayMode = false; 176 mAllDayMode = false;
177#ifndef DESKTOP_VERSION 177#ifndef DESKTOP_VERSION
178 //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 178 //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
179#endif 179#endif
180 mHolidayMask = 0; 180 mHolidayMask = 0;
181 init(); 181 init();
182 connect ( this, SIGNAL (contentsMoving ( int , int ) ), this, SLOT ( slotContentMove(int,int)) ); 182 connect ( this, SIGNAL (contentsMoving ( int , int ) ), this, SLOT ( slotContentMove(int,int)) );
183} 183}
184 184
185/* 185/*
186 Create an agenda widget with columns columns and one row. This is used for 186 Create an agenda widget with columns columns and one row. This is used for
187 all-day events. 187 all-day events.
188*/ 188*/
189KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) : 189KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) :
190 QScrollView(parent,name,f) 190 QScrollView(parent,name,f)
191{ 191{
192 mAllAgendaPopup = 0; 192 mAllAgendaPopup = 0;
193 blockResize = false; 193 blockResize = false;
194 mColumns = columns; 194 mColumns = columns;
195 mRows = 1; 195 mRows = 1;
196 //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize); 196 //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize);
197 mGridSpacingY = KOPrefs::instance()->mAllDaySize; 197 mGridSpacingY = KOPrefs::instance()->mAllDaySize;
198 mAllDayMode = true; 198 mAllDayMode = true;
199#ifndef DESKTOP_VERSION 199#ifndef DESKTOP_VERSION
200 //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 200 //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
201#endif 201#endif
202 mHolidayMask = 0; 202 mHolidayMask = 0;
203 init(); 203 init();
204} 204}
205 205
206 206
207KOAgenda::~KOAgenda() 207KOAgenda::~KOAgenda()
208{ 208{
209 if(mMarcusBains) delete mMarcusBains; 209 if(mMarcusBains) delete mMarcusBains;
210 210
211} 211}
212 212
213Incidence *KOAgenda::selectedIncidence() const 213Incidence *KOAgenda::selectedIncidence() const
214{ 214{
215 return (mSelectedItem ? mSelectedItem->incidence() : 0); 215 return (mSelectedItem ? mSelectedItem->incidence() : 0);
216} 216}
217 217
218 218
219QDate KOAgenda::selectedIncidenceDate() const 219QDate KOAgenda::selectedIncidenceDate() const
220{ 220{
221 return (mSelectedItem ? mSelectedItem->itemDate() : QDate()); 221 return (mSelectedItem ? mSelectedItem->itemDate() : QDate());
222} 222}
223 223
224 224
225void KOAgenda::init() 225void KOAgenda::init()
226{ 226{
227 mPopupTimer = new QTimer(this); 227 mPopupTimer = new QTimer(this);
228 connect(mPopupTimer , SIGNAL(timeout()), this, SLOT(popupMenu())); 228 connect(mPopupTimer , SIGNAL(timeout()), this, SLOT(popupMenu()));
229 229
230 mNewItemPopup = new QPopupMenu( this ); 230 mNewItemPopup = new QPopupMenu( this );
231 connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) ); 231 connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) );
232 QString pathString = ""; 232 QString pathString = "";
233 if ( !KOPrefs::instance()->mToolBarMiniIcons ) { 233 if ( !KOPrefs::instance()->mToolBarMiniIcons ) {
234 if ( QApplication::desktop()->width() < 480 ) 234 if ( QApplication::desktop()->width() < 480 )
235 pathString += "icons16/"; 235 pathString += "icons16/";
236 } else 236 } else
237 pathString += "iconsmini/"; 237 pathString += "iconsmini/";
238 238
239 mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 ); 239 mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 );
240 mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 ); 240 mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 );
241 mNewItemPopup->insertSeparator ( ); 241 mNewItemPopup->insertSeparator ( );
242 mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 ); 242 mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 );
243 mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 ); 243 mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 );
244 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 ); 244 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 );
245 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 ); 245 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 );
246 mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("This month"),6 ); 246 mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("This month"),6 );
247 mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 ); 247 mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 );
248#ifndef _WIN32_ 248#ifndef _WIN32_
249 int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase 249 int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase
250 viewport()->setWFlags ( wflags); 250 viewport()->setWFlags ( wflags);
251#endif 251#endif
252 mGridSpacingX = 80; 252 mGridSpacingX = 80;
253 mResizeBorderWidth = 8; 253 mResizeBorderWidth = 8;
254 mScrollBorderWidth = 8; 254 mScrollBorderWidth = 8;
255 mScrollDelay = 30; 255 mScrollDelay = 30;
256 mScrollOffset = 10; 256 mScrollOffset = 10;
257 mPaintPixmap.resize( 20,20); 257 mPaintPixmap.resize( 20,20);
258 //enableClipper(true); 258 //enableClipper(true);
259 259
260 // Grab key strokes for keyboard navigation of agenda. Seems to have no 260 // Grab key strokes for keyboard navigation of agenda. Seems to have no
261 // effect. Has to be fixed. 261 // effect. Has to be fixed.
262 setFocusPolicy(WheelFocus); 262 setFocusPolicy(WheelFocus);
263 263
264 connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp())); 264 connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp()));
265 connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown())); 265 connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown()));
266 connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize())); 266 connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize()));
267 267
268 mStartCellX = 0; 268 mStartCellX = 0;
269 mStartCellY = 0; 269 mStartCellY = 0;
270 mCurrentCellX = 0; 270 mCurrentCellX = 0;
271 mCurrentCellY = 0; 271 mCurrentCellY = 0;
272 272
273 mSelectionCellX = 0; 273 mSelectionCellX = 0;
274 mSelectionYTop = 0; 274 mSelectionYTop = 0;
275 mSelectionHeight = 0; 275 mSelectionHeight = 0;
276 276
277 mOldLowerScrollValue = -1; 277 mOldLowerScrollValue = -1;
278 mOldUpperScrollValue = -1; 278 mOldUpperScrollValue = -1;
279 279
280 mClickedItem = 0; 280 mClickedItem = 0;
281 281
282 mActionItem = 0; 282 mActionItem = 0;
283 mActionType = NOP; 283 mActionType = NOP;
284 mItemMoved = false; 284 mItemMoved = false;
285 285
286 mSelectedItem = 0; 286 mSelectedItem = 0;
287 287
288 // mItems.setAutoDelete(true); 288 // mItems.setAutoDelete(true);
289 289
290 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 290 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
291 291
292 viewport()->update(); 292 viewport()->update();
293 293
294 setMinimumSize(30, 1); 294 setMinimumSize(30, 1);
295// setMaximumHeight(mGridSpacingY * mRows + 5); 295// setMaximumHeight(mGridSpacingY * mRows + 5);
296 296
297 // Disable horizontal scrollbar. This is a hack. The geometry should be 297 // Disable horizontal scrollbar. This is a hack. The geometry should be
298 // controlled in a way that the contents horizontally always fits. Then it is 298 // controlled in a way that the contents horizontally always fits. Then it is
299 // not necessary to turn off the scrollbar. 299 // not necessary to turn off the scrollbar.
300 setHScrollBarMode(AlwaysOff); 300 setHScrollBarMode(AlwaysOff);
301 if ( ! mAllDayMode ) 301 if ( ! mAllDayMode )
302 setVScrollBarMode(AlwaysOn); 302 setVScrollBarMode(AlwaysOn);
303 else 303 else
304 setVScrollBarMode(AlwaysOff); 304 setVScrollBarMode(AlwaysOff);
305 305
306 setStartHour(KOPrefs::instance()->mDayBegins); 306 setStartHour(KOPrefs::instance()->mDayBegins);
307 307
308 calculateWorkingHours(); 308 calculateWorkingHours();
309 309
310 connect(verticalScrollBar(),SIGNAL(valueChanged(int)), 310 connect(verticalScrollBar(),SIGNAL(valueChanged(int)),
311 SLOT(checkScrollBoundaries(int))); 311 SLOT(checkScrollBoundaries(int)));
312 312
313 // Create the Marcus Bains line. 313 // Create the Marcus Bains line.
314 if(mAllDayMode) 314 if(mAllDayMode)
315 mMarcusBains = 0; 315 mMarcusBains = 0;
316 else { 316 else {
317 mMarcusBains = new MarcusBains(this); 317 mMarcusBains = new MarcusBains(this);
318 addChild(mMarcusBains); 318 addChild(mMarcusBains);
319 } 319 }
320 mPopupKind = 0; 320 mPopupKind = 0;
321 mPopupItem = 0; 321 mPopupItem = 0;
322 mInvalidPixmap = false; 322 mInvalidPixmap = false;
323 323
324} 324}
325 325
326void KOAgenda::shrinkPixmap() 326void KOAgenda::shrinkPixmap()
327{ 327{
328 mPaintPixmap.resize( 20,20); 328 mPaintPixmap.resize( 20,20);
329 mInvalidPixmap = true; 329 mInvalidPixmap = true;
330} 330}
331void KOAgenda::slotContentMove(int,int) 331void KOAgenda::slotContentMove(int,int)
332{ 332{
333 emit sendPing(); 333 emit sendPing();
334 if ( mActionType == NOP ) 334 if ( mActionType == NOP )
335 slotClearSelection(); 335 slotClearSelection();
336 if ( mSelectedItem && !mActionItem ) { 336 if ( mSelectedItem && !mActionItem ) {
337 deselectItem(); 337 deselectItem();
338 emit incidenceSelected( 0 ); 338 emit incidenceSelected( 0 );
339 } 339 }
340} 340}
341void KOAgenda::clear() 341void KOAgenda::clear()
342{ 342{
343 KOAgendaItem *item; 343 KOAgendaItem *item;
344 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 344 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
345 mUnusedItems.append( item ); 345 mUnusedItems.append( item );
346 //item->hide(); 346 //item->hide();
347 } 347 }
348 mItems.clear(); 348 mItems.clear();
349 mSelectedItem = 0; 349 mSelectedItem = 0;
350 clearSelection(); 350 clearSelection();
351} 351}
352 352
353void KOAgenda::clearSelection() 353void KOAgenda::clearSelection()
354{ 354{
355 mSelectionCellX = 0; 355 mSelectionCellX = 0;
356 mSelectionYTop = 0; 356 mSelectionYTop = 0;
357 mSelectionHeight = 0; 357 mSelectionHeight = 0;
358} 358}
359 359
360void KOAgenda::marcus_bains() 360void KOAgenda::marcus_bains()
361{ 361{
362 if(mMarcusBains) mMarcusBains->updateLocation(true); 362 if(mMarcusBains) mMarcusBains->updateLocation(true);
363} 363}
364 364
365 365
366void KOAgenda::changeColumns(int columns) 366void KOAgenda::changeColumns(int columns)
367{ 367{
368 if (columns == 0) { 368 if (columns == 0) {
369 qDebug("KOAgenda::changeColumns() called with argument 0 "); 369 qDebug("KOAgenda::changeColumns() called with argument 0 ");
370 return; 370 return;
371 } 371 }
372 clear(); 372 clear();
373 mColumns = columns; 373 mColumns = columns;
374 computeSizes(); 374 computeSizes();
375} 375}
376 376
377/* 377/*
378 This is the eventFilter function, which gets all events from the KOAgendaItems 378 This is the eventFilter function, which gets all events from the KOAgendaItems
379 contained in the agenda. It has to handle moving and resizing for all items. 379 contained in the agenda. It has to handle moving and resizing for all items.
380*/ 380*/
381bool KOAgenda::eventFilter ( QObject *object, QEvent *event ) 381bool KOAgenda::eventFilter ( QObject *object, QEvent *event )
382{ 382{
383 // kdDebug() << "KOAgenda::eventFilter" << endl; 383 // kdDebug() << "KOAgenda::eventFilter" << endl;
384 switch(event->type()) { 384 switch(event->type()) {
385 case QEvent::MouseButtonPress: 385 case QEvent::MouseButtonPress:
386 case QEvent::MouseButtonDblClick: 386 case QEvent::MouseButtonDblClick:
387 case QEvent::MouseButtonRelease: 387 case QEvent::MouseButtonRelease:
388 case QEvent::MouseMove: 388 case QEvent::MouseMove:
389 return eventFilter_mouse(object, static_cast<QMouseEvent *>(event)); 389 return eventFilter_mouse(object, static_cast<QMouseEvent *>(event));
390 390
391 case (QEvent::Leave): 391 case (QEvent::Leave):
392 if (!mActionItem) 392 if (!mActionItem)
393 setCursor(arrowCursor); 393 setCursor(arrowCursor);
394 return true; 394 return true;
395 395
396 default: 396 default:
397 return QScrollView::eventFilter(object,event); 397 return QScrollView::eventFilter(object,event);
398 } 398 }
399} 399}
400void KOAgenda::popupMenu() 400void KOAgenda::popupMenu()
401{ 401{
402 mPopupTimer->stop(); 402 mPopupTimer->stop();
403 if ( mPopupKind == 1 || mPopupKind == 3 ) { 403 if ( mPopupKind == 1 || mPopupKind == 3 ) {
404 if (mActionItem ) { 404 if (mActionItem ) {
405 endItemAction(); 405 endItemAction();
406 } 406 }
407 mLeftMouseDown = false; // no more leftMouse computation 407 mLeftMouseDown = false; // no more leftMouse computation
408 if (mPopupItem) { 408 if (mPopupItem) {
409 //mClickedItem = mPopupItem; 409 //mClickedItem = mPopupItem;
410 selectItem(mPopupItem); 410 selectItem(mPopupItem);
411 if ( mAllAgendaPopup && KOPrefs::instance()->mBlockPopupMenu && mPopupKind == 1 ) 411 if ( mAllAgendaPopup && KOPrefs::instance()->mBlockPopupMenu && mPopupKind == 1 )
412 mAllAgendaPopup->installEventFilter( this ); 412 mAllAgendaPopup->installEventFilter( this );
413 emit showIncidencePopupSignal(mPopupItem->incidence()); 413 emit showIncidencePopupSignal(mPopupItem->incidence());
414 414
415 } 415 }
416 } else if ( mPopupKind == 2 || mPopupKind == 4 ) { 416 } else if ( mPopupKind == 2 || mPopupKind == 4 ) {
417 if ( mLeftMouseDown ) { // we have a simulated right click - clear left mouse action 417 if ( mLeftMouseDown ) { // we have a simulated right click - clear left mouse action
418 endSelectAction( false ); // do not emit new event signal 418 endSelectAction( false ); // do not emit new event signal
419 mLeftMouseDown = false; // no more leftMouse computation 419 mLeftMouseDown = false; // no more leftMouse computation
420 } 420 }
421 if ( KOPrefs::instance()->mBlockPopupMenu && mPopupKind == 2 ) 421 if ( KOPrefs::instance()->mBlockPopupMenu && mPopupKind == 2 )
422 mNewItemPopup->installEventFilter( this ); 422 mNewItemPopup->installEventFilter( this );
423 mNewItemPopup->popup( mPopupPos); 423 mNewItemPopup->popup( mPopupPos);
424 424
425 } 425 }
426 mLeftMouseDown = false; 426 mLeftMouseDown = false;
427 mPopupItem = 0; 427 mPopupItem = 0;
428 mPopupKind = 0; 428 mPopupKind = 0;
429} 429}
430void KOAgenda::categoryChanged(Incidence * inc) 430void KOAgenda::categoryChanged(Incidence * inc)
431{ 431{
432 KOAgendaItem *item; 432 KOAgendaItem *item;
433 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 433 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
434 if ( item->incidence() == inc ) { 434 if ( item->incidence() == inc ) {
435 item->initColor (); 435 item->initColor ();
436 item->updateItem(); 436 item->updateItem();
437 } 437 }
438 } 438 }
439} 439}
440bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) 440bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me)
441{ 441{
442 442
443 if ( mInvalidPixmap ) { 443 if ( mInvalidPixmap ) {
444 mInvalidPixmap = false; 444 mInvalidPixmap = false;
445 qDebug("KO: Upsizing Pixmaps "); 445 qDebug("KO: Upsizing Pixmaps ");
446 computeSizes(); 446 computeSizes();
447 emit updateViewSignal(); 447 emit updateViewSignal();
448 return true; 448 return true;
449 } 449 }
450 emit sendPing(); 450 emit sendPing();
451 static int startX = 0; 451 static int startX = 0;
452 static int startY = 0; 452 static int startY = 0;
453 int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 7 : 9 ); 453 int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 7 : 9 );
454 static bool blockMoving = true; 454 static bool blockMoving = true;
455 455
456 //qDebug("KOAgenda::eventFilter_mous "); 456 //qDebug("KOAgenda::eventFilter_mous ");
457 if ( object == mNewItemPopup ) { 457 if ( object == mNewItemPopup ) {
458 //qDebug("mNewItemPopup "); 458 //qDebug("mNewItemPopup ");
459 if ( me->type() == QEvent::MouseButtonRelease ) { 459 if ( me->type() == QEvent::MouseButtonRelease ) {
460 mNewItemPopup->removeEventFilter( this ); 460 mNewItemPopup->removeEventFilter( this );
461 int dX = me->globalPos().x() - mPopupPos.x();; 461 int dX = me->globalPos().x() - mPopupPos.x();;
462 if ( dX < 0 ) 462 if ( dX < 0 )
463 dX = -dX; 463 dX = -dX;
464 int dY = me->globalPos().y() - mPopupPos.y(); 464 int dY = me->globalPos().y() - mPopupPos.y();
465 if ( dY < 0 ) 465 if ( dY < 0 )
466 dY = -dY; 466 dY = -dY;
467 if ( dX > blockmoveDist || dY > blockmoveDist ) { 467 if ( dX > blockmoveDist || dY > blockmoveDist ) {
468 mNewItemPopup->hide(); 468 mNewItemPopup->hide();
469 } 469 }
470 } 470 }
471 return true; 471 return true;
472 } 472 }
473 if ( object == mAllAgendaPopup ) { 473 if ( object == mAllAgendaPopup ) {
474 //qDebug(" mAllAgendaPopup "); 474 //qDebug(" mAllAgendaPopup ");
475 if ( me->type() == QEvent::MouseButtonRelease ) { 475 if ( me->type() == QEvent::MouseButtonRelease ) {
476 mAllAgendaPopup->removeEventFilter( this ); 476 mAllAgendaPopup->removeEventFilter( this );
477 int dX = me->globalPos().x() - mPopupPos.x();; 477 int dX = me->globalPos().x() - mPopupPos.x();;
478 if ( dX < 0 ) 478 if ( dX < 0 )
479 dX = -dX; 479 dX = -dX;
480 int dY = me->globalPos().y() - mPopupPos.y(); 480 int dY = me->globalPos().y() - mPopupPos.y();
481 if ( dY < 0 ) 481 if ( dY < 0 )
482 dY = -dY; 482 dY = -dY;
483 if ( dX > blockmoveDist || dY > blockmoveDist ) { 483 if ( dX > blockmoveDist || dY > blockmoveDist ) {
484 mAllAgendaPopup->hide(); 484 mAllAgendaPopup->hide();
485 } 485 }
486 } 486 }
487 return true; 487 return true;
488 } 488 }
489 QPoint viewportPos; 489 QPoint viewportPos;
490 if (object != viewport()) { 490 if (object != viewport()) {
491 blockmoveDist = blockmoveDist*2; 491 blockmoveDist = blockmoveDist*2;
492 viewportPos = ((QWidget *)object)->mapToParent(me->pos()); 492 viewportPos = ((QWidget *)object)->mapToParent(me->pos());
493 } else { 493 } else {
494 viewportPos = me->pos(); 494 viewportPos = me->pos();
495 } 495 }
496 bool objIsNotViewport = (object != viewport()); 496 bool objIsNotViewport = (object != viewport());
497 bool leftButt = false; 497 bool leftButt = false;
498#ifdef DESKTOP_VERSION 498#ifdef DESKTOP_VERSION
499 leftButt = (me->button() == LeftButton); 499 leftButt = (me->button() == LeftButton);
500#endif 500#endif
501 switch (me->type()) { 501 switch (me->type()) {
502 case QEvent::MouseButtonPress: 502 case QEvent::MouseButtonPress:
503 if (me->button() == LeftButton) { 503 if (me->button() == LeftButton) {
504 mPopupTimer->start( 600 ); 504 mPopupTimer->start( 600 );
505 mLeftMouseDown = true; 505 mLeftMouseDown = true;
506 } 506 }
507 blockMoving = true; 507 blockMoving = true;
508 startX = viewportPos.x(); 508 startX = viewportPos.x();
509 startY = viewportPos.y(); 509 startY = viewportPos.y();
510 mPopupPos = me->globalPos(); 510 mPopupPos = me->globalPos();
511 if ( objIsNotViewport && !leftButt ) { 511 if ( objIsNotViewport && !leftButt ) {
512 KOAgendaItem * tempItem = (KOAgendaItem *)object; 512 KOAgendaItem * tempItem = (KOAgendaItem *)object;
513 if (mAllDayMode) { 513 if (mAllDayMode) {
514 if ( tempItem->height() > 10 ) { 514 if ( tempItem->height() > 10 ) {
515 int minV = tempItem->height()/4; 515 int minV = tempItem->height()/4;
516 if ( minV > (blockmoveDist/2)-2 ) { 516 if ( minV > (blockmoveDist/2)-2 ) {
517 if ( minV > blockmoveDist ) 517 if ( minV > blockmoveDist )
518 minV = blockmoveDist; 518 minV = blockmoveDist;
519 else 519 else
520 minV = (blockmoveDist/2); 520 minV = (blockmoveDist/2);
521 } 521 }
522 bool border = false; 522 bool border = false;
523 int diff = tempItem->y() - viewportPos.y(); 523 int diff = tempItem->y() - viewportPos.y();
524 if ( diff < 0 ) 524 if ( diff < 0 )
525 diff *= -1; 525 diff *= -1;
526 if ( diff < minV ) { 526 if ( diff < minV ) {
527 border = true; 527 border = true;
528 objIsNotViewport = false; 528 objIsNotViewport = false;
529 } 529 }
530 if ( ! border ) { 530 if ( ! border ) {
531 diff = tempItem->y() + tempItem->height()- viewportPos.y(); 531 diff = tempItem->y() + tempItem->height()- viewportPos.y();
532 if ( diff < 0 ) 532 if ( diff < 0 )
533 diff *= -1; 533 diff *= -1;
534 if ( diff < minV ) { 534 if ( diff < minV ) {
535 border = true; 535 border = true;
536 objIsNotViewport = false; 536 objIsNotViewport = false;
537 } 537 }
538 } 538 }
539 } 539 }
540 } else { // not allday 540 } else { // not allday
541 if ( tempItem->width() > 10 ) { 541 if ( tempItem->width() > 10 ) {
542 int minH = tempItem->width()/4; 542 int minH = tempItem->width()/4;
543 if ( minH > (blockmoveDist/2)-2 ) { 543 if ( minH > (blockmoveDist/2)-2 ) {
544 if ( minH > blockmoveDist ) 544 if ( minH > blockmoveDist )
545 minH = blockmoveDist; 545 minH = blockmoveDist;
546 else 546 else
547 minH = (blockmoveDist/2); 547 minH = (blockmoveDist/2);
548 } 548 }
549 bool border = false; 549 bool border = false;
550 int diff = tempItem->x() - viewportPos.x(); 550 int diff = tempItem->x() - viewportPos.x();
551 if ( diff < 0 ) 551 if ( diff < 0 )
552 diff *= -1; 552 diff *= -1;
553 if ( diff < minH ) { 553 if ( diff < minH ) {
554 border = true; 554 border = true;
555 objIsNotViewport = false; 555 objIsNotViewport = false;
556 } 556 }
557 if ( ! border ) { 557 if ( ! border ) {
558 diff = tempItem->x() + tempItem->width() - viewportPos.x(); 558 diff = tempItem->x() + tempItem->width() - viewportPos.x();
559 if ( diff < 0 ) 559 if ( diff < 0 )
560 diff *= -1; 560 diff *= -1;
561 if ( diff < minH ) { 561 if ( diff < minH ) {
562 border = true; 562 border = true;
563 objIsNotViewport = false; 563 objIsNotViewport = false;
564 } 564 }
565 } 565 }
566 } 566 }
567 } 567 }
568 } 568 }
569 if ( objIsNotViewport ) { 569 if ( objIsNotViewport ) {
570 mPopupItem = (KOAgendaItem *)object; 570 mPopupItem = (KOAgendaItem *)object;
571 mPopupKind = 1; 571 mPopupKind = 1;
572 if (me->button() == RightButton) { 572 if (me->button() == RightButton) {
573 mPopupKind = 3; 573 mPopupKind = 3;
574 popupMenu(); 574 popupMenu();
575 } else if (me->button() == LeftButton) { 575 } else if (me->button() == LeftButton) {
576 mActionItem = (KOAgendaItem *)object; 576 mActionItem = (KOAgendaItem *)object;
577 if (mActionItem) { 577 if (mActionItem) {
578 emit signalClearSelection(); 578 emit signalClearSelection();
579 slotClearSelection(); 579 slotClearSelection();
580 selectItem(mActionItem); 580 selectItem(mActionItem);
581 Incidence *incidence = mActionItem->incidence(); 581 Incidence *incidence = mActionItem->incidence();
582 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { 582 if ( incidence->isReadOnly() /*|| incidence->doesRecur() */) {
583 mActionItem = 0; 583 mActionItem = 0;
584 } else { 584 } else {
585 startItemAction(viewportPos); 585 startItemAction(viewportPos);
586 } 586 }
587 } 587 }
588 } 588 }
589 } else { // ---------- viewport() 589 } else { // ---------- viewport()
590 mPopupItem = 0; 590 mPopupItem = 0;
591 mPopupKind = 2; 591 mPopupKind = 2;
592 selectItem(0); 592 selectItem(0);
593 mActionItem = 0; 593 mActionItem = 0;
594 if (me->button() == RightButton) { 594 if (me->button() == RightButton) {
595 int x,y; 595 int x,y;
596 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 596 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
597 int gx,gy; 597 int gx,gy;
598 contentsToGrid(x,y,gx,gy); 598 contentsToGrid(x,y,gx,gy);
599 mCurrentCellX = gx; 599 mCurrentCellX = gx;
600 mCurrentCellY = gy; 600 mCurrentCellY = gy;
601 mStartCellX = gx; 601 mStartCellX = gx;
602 mStartCellY = gy; 602 mStartCellY = gy;
603 mPopupKind = 4; 603 mPopupKind = 4;
604 popupMenu(); 604 popupMenu();
605 } else if (me->button() == LeftButton) { 605 } else if (me->button() == LeftButton) {
606 setCursor(arrowCursor); 606 setCursor(arrowCursor);
607 startSelectAction(viewportPos); 607 startSelectAction(viewportPos);
608 } 608 }
609 } 609 }
610 break; 610 break;
611 611
612 case QEvent::MouseButtonRelease: 612 case QEvent::MouseButtonRelease:
613 if (me->button() == LeftButton ) { 613 if (me->button() == LeftButton ) {
614 mPopupTimer->stop(); 614 mPopupTimer->stop();
615 } 615 }
616 if (object != viewport()) { 616 if (object != viewport()) {
617 if (me->button() == LeftButton && mLeftMouseDown) { 617 if (me->button() == LeftButton && mLeftMouseDown) {
618 if (mActionItem) { 618 if (mActionItem) {
619 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 619 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos));
620 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); 620 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 );
621 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { 621 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) {
622 mScrollUpTimer.stop(); 622 mScrollUpTimer.stop();
623 mScrollDownTimer.stop(); 623 mScrollDownTimer.stop();
624 mActionItem->resetMove(); 624 mActionItem->resetMove();
625 placeSubCells( mActionItem ); 625 placeSubCells( mActionItem );
626 // emit startDragSignal( mActionItem->incidence() ); 626 // emit startDragSignal( mActionItem->incidence() );
627 setCursor( arrowCursor ); 627 setCursor( arrowCursor );
628 mActionItem = 0; 628 mActionItem = 0;
629 mActionType = NOP; 629 mActionType = NOP;
630 mItemMoved = 0; 630 mItemMoved = 0;
631 mLeftMouseDown = false; 631 mLeftMouseDown = false;
632 return true; 632 return true;
633 } 633 }
634 endItemAction(); 634 endItemAction();
635 } 635 }
636 } 636 }
637 637
638 } else { // ---------- viewport() 638 } else { // ---------- viewport()
639 if (me->button() == LeftButton && mLeftMouseDown ) { //left click 639 if (me->button() == LeftButton && mLeftMouseDown ) { //left click
640 endSelectAction( true ); // emit new event signal 640 endSelectAction( true ); // emit new event signal
641 } 641 }
642 } 642 }
643 if (me->button() == LeftButton) 643 if (me->button() == LeftButton)
644 mLeftMouseDown = false; 644 mLeftMouseDown = false;
645 645
646 break; 646 break;
647 647
648 case QEvent::MouseMove: 648 case QEvent::MouseMove:
649 //qDebug("mm "); 649 //qDebug("mm ");
650 if ( !mLeftMouseDown ) 650 if ( !mLeftMouseDown )
651 return false; 651 return false;
652 if ( blockMoving ) { 652 if ( blockMoving ) {
653 int dX, dY; 653 int dX, dY;
654 dX = startX - viewportPos.x(); 654 dX = startX - viewportPos.x();
655 if ( dX < 0 ) 655 if ( dX < 0 )
656 dX = -dX; 656 dX = -dX;
657 dY = viewportPos.y() - startY; 657 dY = viewportPos.y() - startY;
658 if ( dY < 0 ) 658 if ( dY < 0 )
659 dY = -dY; 659 dY = -dY;
660 //qDebug("%d %d %d ", dX, dY , blockmoveDist ); 660 //qDebug("%d %d %d ", dX, dY , blockmoveDist );
661 if ( dX > blockmoveDist || dY > blockmoveDist ) { 661 if ( dX > blockmoveDist || dY > blockmoveDist ) {
662 blockMoving = false; 662 blockMoving = false;
663 } 663 }
664 } 664 }
665 if ( ! blockMoving ) 665 if ( ! blockMoving )
666 mPopupTimer->stop(); 666 mPopupTimer->stop();
667 if (object != viewport()) { 667 if (object != viewport()) {
668 KOAgendaItem *moveItem = (KOAgendaItem *)object; 668 KOAgendaItem *moveItem = (KOAgendaItem *)object;
669 if (!moveItem->incidence()->isReadOnly() ) { 669 if (!moveItem->incidence()->isReadOnly() ) {
670 if (!mActionItem) 670 if (!mActionItem)
671 setNoActionCursor(moveItem,viewportPos); 671 setNoActionCursor(moveItem,viewportPos);
672 else { 672 else {
673 if ( !blockMoving ) 673 if ( !blockMoving )
674 performItemAction(viewportPos); 674 performItemAction(viewportPos);
675 } 675 }
676 } 676 }
677 } else { // ---------- viewport() 677 } else { // ---------- viewport()
678 mPopupPos = viewport()->mapToGlobal( me->pos() ); 678 mPopupPos = viewport()->mapToGlobal( me->pos() );
679 if ( mActionType == SELECT ) { 679 if ( mActionType == SELECT ) {
680 performSelectAction( viewportPos ); 680 performSelectAction( viewportPos );
681 } 681 }
682 } 682 }
683 break; 683 break;
684 684
685 case QEvent::MouseButtonDblClick: 685 case QEvent::MouseButtonDblClick:
686 mPopupTimer->stop(); 686 mPopupTimer->stop();
687 if (object == viewport()) { 687 if (object == viewport()) {
688 selectItem(0); 688 selectItem(0);
689 int x,y; 689 int x,y;
690 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 690 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
691 int gx,gy; 691 int gx,gy;
692 contentsToGrid(x,y,gx,gy); 692 contentsToGrid(x,y,gx,gy);
693 emit newEventSignal(gx,gy); 693 emit newEventSignal(gx,gy);
694 } else { 694 } else {
695 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; 695 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object;
696 selectItem(doubleClickedItem); 696 selectItem(doubleClickedItem);
697 if ( KOPrefs::instance()->mEditOnDoubleClick ) 697 if ( KOPrefs::instance()->mEditOnDoubleClick )
698 emit editIncidenceSignal(doubleClickedItem->incidence()); 698 emit editIncidenceSignal(doubleClickedItem->incidence());
699 else 699 else
700 emit showIncidenceSignal(doubleClickedItem->incidence()); 700 emit showIncidenceSignal(doubleClickedItem->incidence());
701 } 701 }
702 break; 702 break;
703 703
704 default: 704 default:
705 break; 705 break;
706 } 706 }
707 return true; 707 return true;
708 708
709} 709}
710 710
711void KOAgenda::newItem( int item ) 711void KOAgenda::newItem( int item )
712{ 712{
713 if ( item == 1 ) { //new event 713 if ( item == 1 ) { //new event
714 newEventSignal(mStartCellX ,mStartCellY ); 714 newEventSignal(mStartCellX ,mStartCellY );
715 } else 715 } else
716 if ( item == 2 ) { //new event 716 if ( item == 2 ) { //new event
717 newTodoSignal(mStartCellX ,mStartCellY ); 717 newTodoSignal(mStartCellX ,mStartCellY );
718 } else 718 } else
719 { 719 {
720 emit showDateView( item, mStartCellX ); 720 emit showDateView( item, mStartCellX );
721 // 3Day view 721 // 3Day view
722 // 4Week view 722 // 4Week view
723 // 5Month view 723 // 5Month view
724 // 6Journal view 724 // 6Journal view
725 } 725 }
726} 726}
727void KOAgenda::slotClearSelection() 727void KOAgenda::slotClearSelection()
728{ 728{
729 if (mSelectionHeight) { 729 if (mSelectionHeight) {
730 int selectionX = mSelectionCellX * mGridSpacingX; 730 int selectionX = mSelectionCellX * mGridSpacingX;
731 int top = mSelectionYTop - 2 *mGridSpacingY; 731 int top = mSelectionYTop - 2 *mGridSpacingY;
732 int hei = mSelectionHeight + 4 *mGridSpacingY; 732 int hei = mSelectionHeight + 4 *mGridSpacingY;
733 clearSelection(); 733 clearSelection();
734 repaintContents( selectionX, top, 734 repaintContents( selectionX, top,
735 mGridSpacingX, hei ,false ); 735 mGridSpacingX, hei ,false );
736 } 736 }
737 737
738} 738}
739void KOAgenda::startSelectAction(QPoint viewportPos) 739void KOAgenda::startSelectAction(QPoint viewportPos)
740{ 740{
741 741
742 emit signalClearSelection(); 742 emit signalClearSelection();
743 slotClearSelection(); 743 slotClearSelection();
744 744
745 mActionType = SELECT; 745 mActionType = SELECT;
746 746
747 int x,y; 747 int x,y;
748 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 748 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
749 int gx,gy; 749 int gx,gy;
750 contentsToGrid(x,y,gx,gy); 750 contentsToGrid(x,y,gx,gy);
751 751
752 mStartCellX = gx; 752 mStartCellX = gx;
753 mStartCellY = gy; 753 mStartCellY = gy;
754 mCurrentCellX = gx; 754 mCurrentCellX = gx;
755 mCurrentCellY = gy; 755 mCurrentCellY = gy;
756 756
757 // Store new selection 757 // Store new selection
758 mSelectionCellX = gx; 758 mSelectionCellX = gx;
759 mSelectionYTop = gy * mGridSpacingY; 759 mSelectionYTop = gy * mGridSpacingY;
760 mSelectionHeight = mGridSpacingY; 760 mSelectionHeight = mGridSpacingY;
761 761
762 // Paint new selection 762 // Paint new selection
763 repaintContents( mSelectionCellX * mGridSpacingX+1, mSelectionYTop, 763 repaintContents( mSelectionCellX * mGridSpacingX+1, mSelectionYTop,
764 mGridSpacingX-1, mSelectionHeight ); 764 mGridSpacingX-1, mSelectionHeight );
765} 765}
766 766
767void KOAgenda::performSelectAction(QPoint viewportPos) 767void KOAgenda::performSelectAction(QPoint viewportPos)
768{ 768{
769 int x,y; 769 int x,y;
770 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 770 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
771 int gx,gy; 771 int gx,gy;
772 contentsToGrid(x,y,gx,gy); 772 contentsToGrid(x,y,gx,gy);
773 773
774 QPoint clipperPos = clipper()-> 774 QPoint clipperPos = clipper()->
775 mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 775 mapFromGlobal(viewport()->mapToGlobal(viewportPos));
776 776
777 // Scroll if cursor was moved to upper or lower end of agenda. 777 // Scroll if cursor was moved to upper or lower end of agenda.
778 if (clipperPos.y() < mScrollBorderWidth) { 778 if (clipperPos.y() < mScrollBorderWidth) {
779 mScrollUpTimer.start(mScrollDelay); 779 mScrollUpTimer.start(mScrollDelay);
780 } else if (visibleHeight() - clipperPos.y() < 780 } else if (visibleHeight() - clipperPos.y() <
781 mScrollBorderWidth) { 781 mScrollBorderWidth) {
782 mScrollDownTimer.start(mScrollDelay); 782 mScrollDownTimer.start(mScrollDelay);
783 } else { 783 } else {
784 mScrollUpTimer.stop(); 784 mScrollUpTimer.stop();
785 mScrollDownTimer.stop(); 785 mScrollDownTimer.stop();
786 } 786 }
787 787
788 if ( gy > mCurrentCellY ) { 788 if ( gy > mCurrentCellY ) {
789 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; 789 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop;
790 790
791 791
792 repaintContents( (KOGlobals::self()->reverseLayout() ? 792 repaintContents( (KOGlobals::self()->reverseLayout() ?
793 mColumns - 1 - mSelectionCellX : mSelectionCellX) * 793 mColumns - 1 - mSelectionCellX : mSelectionCellX) *
794 mGridSpacingX, mSelectionYTop, 794 mGridSpacingX, mSelectionYTop,
795 mGridSpacingX, mSelectionHeight , false); 795 mGridSpacingX, mSelectionHeight , false);
796 796
797 mCurrentCellY = gy; 797 mCurrentCellY = gy;
798 } else if ( gy < mCurrentCellY ) { 798 } else if ( gy < mCurrentCellY ) {
799 if ( gy >= mStartCellY ) { 799 if ( gy >= mStartCellY ) {
800 int selectionHeight = mSelectionHeight; 800 int selectionHeight = mSelectionHeight;
801 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; 801 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop;
802 802
803 repaintContents( (KOGlobals::self()->reverseLayout() ? 803 repaintContents( (KOGlobals::self()->reverseLayout() ?
804 mColumns - 1 - mSelectionCellX : mSelectionCellX) * 804 mColumns - 1 - mSelectionCellX : mSelectionCellX) *
805 mGridSpacingX, mSelectionYTop, 805 mGridSpacingX, mSelectionYTop,
806 mGridSpacingX, selectionHeight,false ); 806 mGridSpacingX, selectionHeight,false );
807 807
808 mCurrentCellY = gy; 808 mCurrentCellY = gy;
809 } else { 809 } else {
810 } 810 }
811 } 811 }
812} 812}
813 813
814void KOAgenda::endSelectAction( bool emitNewEvent ) 814void KOAgenda::endSelectAction( bool emitNewEvent )
815{ 815{
816 mActionType = NOP; 816 mActionType = NOP;
817 mScrollUpTimer.stop(); 817 mScrollUpTimer.stop();
818 mScrollDownTimer.stop(); 818 mScrollDownTimer.stop();
819 819
820 emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); 820 emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY);
821 if ( emitNewEvent && mStartCellY < mCurrentCellY ) { 821 if ( emitNewEvent && mStartCellY < mCurrentCellY ) {
822 emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); 822 emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY);
823 } 823 }
824} 824}
825 825
826void KOAgenda::startItemAction(QPoint viewportPos) 826void KOAgenda::startItemAction(QPoint viewportPos)
827{ 827{
828 int x,y; 828 int x,y;
829 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 829 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
830 int gx,gy; 830 int gx,gy;
831 contentsToGrid(x,y,gx,gy); 831 contentsToGrid(x,y,gx,gy);
832 832
833 mStartCellX = gx; 833 mStartCellX = gx;
834 mStartCellY = gy; 834 mStartCellY = gy;
835 mCurrentCellX = gx; 835 mCurrentCellX = gx;
836 mCurrentCellY = gy; 836 mCurrentCellY = gy;
837 837
838 if (mAllDayMode) { 838 if (mAllDayMode) {
839 int gridDistanceX = (x - gx * mGridSpacingX); 839 int gridDistanceX = (x - gx * mGridSpacingX);
840 if (gridDistanceX < mResizeBorderWidth && 840 if (gridDistanceX < mResizeBorderWidth &&
841 mActionItem->cellX() == mCurrentCellX) { 841 mActionItem->cellX() == mCurrentCellX) {
842 mActionType = RESIZELEFT; 842 mActionType = RESIZELEFT;
843 setCursor(sizeHorCursor); 843 setCursor(sizeHorCursor);
844 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && 844 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth &&
845 mActionItem->cellXWidth() == mCurrentCellX) { 845 mActionItem->cellXWidth() == mCurrentCellX) {
846 mActionType = RESIZERIGHT; 846 mActionType = RESIZERIGHT;
847 setCursor(sizeHorCursor); 847 setCursor(sizeHorCursor);
848 } else { 848 } else {
849 mActionType = MOVE; 849 mActionType = MOVE;
850 mActionItem->startMove(); 850 mActionItem->startMove();
851 setCursor(sizeAllCursor); 851 setCursor(sizeAllCursor);
852 } 852 }
853 } else { 853 } else {
854 int gridDistanceY = (y - gy * mGridSpacingY); 854 int gridDistanceY = (y - gy * mGridSpacingY);
855 bool allowResize = ( mActionItem->incidence()->typeID() != todoID ); 855 bool allowResize = ( mActionItem->incidence()->typeID() != todoID );
856 if (allowResize && gridDistanceY < mResizeBorderWidth && 856 if (allowResize && gridDistanceY < mResizeBorderWidth &&
857 mActionItem->cellYTop() == mCurrentCellY && 857 mActionItem->cellYTop() == mCurrentCellY &&
858 !mActionItem->firstMultiItem()) { 858 !mActionItem->firstMultiItem()) {
859 mActionType = RESIZETOP; 859 mActionType = RESIZETOP;
860 setCursor(sizeVerCursor); 860 setCursor(sizeVerCursor);
861 } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth && 861 } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth &&
862 mActionItem->cellYBottom() == mCurrentCellY && 862 mActionItem->cellYBottom() == mCurrentCellY &&
863 !mActionItem->lastMultiItem()) { 863 !mActionItem->lastMultiItem()) {
864 mActionType = RESIZEBOTTOM; 864 mActionType = RESIZEBOTTOM;
865 setCursor(sizeVerCursor); 865 setCursor(sizeVerCursor);
866 } else { 866 } else {
867 mActionType = MOVE; 867 mActionType = MOVE;
868 mActionItem->startMove(); 868 mActionItem->startMove();
869 setCursor(sizeAllCursor); 869 setCursor(sizeAllCursor);
870 } 870 }
871 } 871 }
872} 872}
873 873
874void KOAgenda::performItemAction(QPoint viewportPos) 874void KOAgenda::performItemAction(QPoint viewportPos)
875{ 875{
876// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; 876// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl;
877// QPoint point = viewport()->mapToGlobal(viewportPos); 877// QPoint point = viewport()->mapToGlobal(viewportPos);
878// kdDebug() << "Global: " << point.x() << "," << point.y() << endl; 878// kdDebug() << "Global: " << point.x() << "," << point.y() << endl;
879// point = clipper()->mapFromGlobal(point); 879// point = clipper()->mapFromGlobal(point);
880// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; 880// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl;
881// kdDebug() << "visible height: " << visibleHeight() << endl; 881// kdDebug() << "visible height: " << visibleHeight() << endl;
882 int x,y; 882 int x,y;
883 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 883 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
884// kdDebug() << "contents: " << x << "," << y << "\n" << endl; 884// kdDebug() << "contents: " << x << "," << y << "\n" << endl;
885 int gx,gy; 885 int gx,gy;
886 contentsToGrid(x,y,gx,gy); 886 contentsToGrid(x,y,gx,gy);
887 QPoint clipperPos = clipper()-> 887 QPoint clipperPos = clipper()->
888 mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 888 mapFromGlobal(viewport()->mapToGlobal(viewportPos));
889 889
890 // Cursor left active agenda area. 890 // Cursor left active agenda area.
891 // This starts a drag. 891 // This starts a drag.
892 if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/ 892 if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/
893 clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) { 893 clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) {
894 if ( mActionType == MOVE ) { 894 if ( mActionType == MOVE ) {
895 mScrollUpTimer.stop(); 895 mScrollUpTimer.stop();
896 mScrollDownTimer.stop(); 896 mScrollDownTimer.stop();
897 mActionItem->resetMove(); 897 mActionItem->resetMove();
898 placeSubCells( mActionItem ); 898 placeSubCells( mActionItem );
899 // emit startDragSignal( mActionItem->incidence() ); 899 // emit startDragSignal( mActionItem->incidence() );
900 setCursor( arrowCursor ); 900 setCursor( arrowCursor );
901 mActionItem = 0; 901 mActionItem = 0;
902 mActionType = NOP; 902 mActionType = NOP;
903 mItemMoved = 0; 903 mItemMoved = 0;
904 return; 904 return;
905 } 905 }
906 } else { 906 } else {
907 switch ( mActionType ) { 907 switch ( mActionType ) {
908 case MOVE: 908 case MOVE:
909 setCursor( sizeAllCursor ); 909 setCursor( sizeAllCursor );
910 break; 910 break;
911 case RESIZETOP: 911 case RESIZETOP:
912 case RESIZEBOTTOM: 912 case RESIZEBOTTOM:
913 setCursor( sizeVerCursor ); 913 setCursor( sizeVerCursor );
914 break; 914 break;
915 case RESIZELEFT: 915 case RESIZELEFT:
916 case RESIZERIGHT: 916 case RESIZERIGHT:
917 setCursor( sizeHorCursor ); 917 setCursor( sizeHorCursor );
918 break; 918 break;
919 default: 919 default:
920 setCursor( arrowCursor ); 920 setCursor( arrowCursor );
921 } 921 }
922 } 922 }
923 923
924 // Scroll if item was moved to upper or lower end of agenda. 924 // Scroll if item was moved to upper or lower end of agenda.
925 if (clipperPos.y() < mScrollBorderWidth) { 925 if (clipperPos.y() < mScrollBorderWidth) {
926 mScrollUpTimer.start(mScrollDelay); 926 mScrollUpTimer.start(mScrollDelay);
927 } else if (visibleHeight() - clipperPos.y() < 927 } else if (visibleHeight() - clipperPos.y() <
928 mScrollBorderWidth) { 928 mScrollBorderWidth) {
929 mScrollDownTimer.start(mScrollDelay); 929 mScrollDownTimer.start(mScrollDelay);
930 } else { 930 } else {
931 mScrollUpTimer.stop(); 931 mScrollUpTimer.stop();
932 mScrollDownTimer.stop(); 932 mScrollDownTimer.stop();
933 } 933 }
934 934
935 // Move or resize item if necessary 935 // Move or resize item if necessary
936 if (mCurrentCellX != gx || mCurrentCellY != gy) { 936 if (mCurrentCellX != gx || mCurrentCellY != gy) {
937 mItemMoved = true; 937 mItemMoved = true;
938 mActionItem->raise(); 938 mActionItem->raise();
939 if (mActionType == MOVE) { 939 if (mActionType == MOVE) {
940 // Move all items belonging to a multi item 940 // Move all items belonging to a multi item
941 KOAgendaItem *moveItem = mActionItem->firstMultiItem(); 941 KOAgendaItem *moveItem = mActionItem->firstMultiItem();
942 bool isMultiItem = (moveItem || mActionItem->lastMultiItem()); 942 bool isMultiItem = (moveItem || mActionItem->lastMultiItem());
943 if (!moveItem) moveItem = mActionItem; 943 if (!moveItem) moveItem = mActionItem;
944 while (moveItem) { 944 while (moveItem) {
945 int dy; 945 int dy;
946 if (isMultiItem) dy = 0; 946 if (isMultiItem) dy = 0;
947 else dy = gy - mCurrentCellY; 947 else dy = gy - mCurrentCellY;
948 moveItem->moveRelative(gx - mCurrentCellX,dy); 948 moveItem->moveRelative(gx - mCurrentCellX,dy);
949 int x,y; 949 int x,y;
950 gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y); 950 gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y);
951 moveItem->resize(mGridSpacingX * moveItem->cellWidth(), 951 moveItem->resize(mGridSpacingX * moveItem->cellWidth(),
952 mGridSpacingY * moveItem->cellHeight()); 952 mGridSpacingY * moveItem->cellHeight());
953 moveItem->raise(); 953 moveItem->raise();
954 moveChild(moveItem,x,y); 954 moveChild(moveItem,x,y);
955 moveItem = moveItem->nextMultiItem(); 955 moveItem = moveItem->nextMultiItem();
956 } 956 }
957 } else if (mActionType == RESIZETOP) { 957 } else if (mActionType == RESIZETOP) {
958 if (mCurrentCellY <= mActionItem->cellYBottom()) { 958 if (mCurrentCellY <= mActionItem->cellYBottom()) {
959 mActionItem->expandTop(gy - mCurrentCellY); 959 mActionItem->expandTop(gy - mCurrentCellY);
960 mActionItem->resize(mActionItem->width(), 960 mActionItem->resize(mActionItem->width(),
961 mGridSpacingY * mActionItem->cellHeight()); 961 mGridSpacingY * mActionItem->cellHeight());
962 int x,y; 962 int x,y;
963 gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y); 963 gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y);
964 //moveChild(mActionItem,childX(mActionItem),y); 964 //moveChild(mActionItem,childX(mActionItem),y);
965 QScrollView::moveChild( mActionItem,childX(mActionItem),y ); 965 QScrollView::moveChild( mActionItem,childX(mActionItem),y );
966 } 966 }
967 } else if (mActionType == RESIZEBOTTOM) { 967 } else if (mActionType == RESIZEBOTTOM) {
968 if (mCurrentCellY >= mActionItem->cellYTop()) { 968 if (mCurrentCellY >= mActionItem->cellYTop()) {
969 mActionItem->expandBottom(gy - mCurrentCellY); 969 mActionItem->expandBottom(gy - mCurrentCellY);
970 mActionItem->resize(mActionItem->width(), 970 mActionItem->resize(mActionItem->width(),
971 mGridSpacingY * mActionItem->cellHeight()); 971 mGridSpacingY * mActionItem->cellHeight());
972 } 972 }
973 } else if (mActionType == RESIZELEFT) { 973 } else if (mActionType == RESIZELEFT) {
974 if (mCurrentCellX <= mActionItem->cellXWidth()) { 974 if (mCurrentCellX <= mActionItem->cellXWidth()) {
975 mActionItem->expandLeft(gx - mCurrentCellX); 975 mActionItem->expandLeft(gx - mCurrentCellX);
976 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), 976 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(),
977 mActionItem->height()); 977 mActionItem->height());
978 int x,y; 978 int x,y;
979 gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y); 979 gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y);
980 moveChild(mActionItem,x,childY(mActionItem)); 980 moveChild(mActionItem,x,childY(mActionItem));
981 } 981 }
982 } else if (mActionType == RESIZERIGHT) { 982 } else if (mActionType == RESIZERIGHT) {
983 if (mCurrentCellX >= mActionItem->cellX()) { 983 if (mCurrentCellX >= mActionItem->cellX()) {
984 mActionItem->expandRight(gx - mCurrentCellX); 984 mActionItem->expandRight(gx - mCurrentCellX);
985 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), 985 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(),
986 mActionItem->height()); 986 mActionItem->height());
987 } 987 }
988 } 988 }
989 mCurrentCellX = gx; 989 mCurrentCellX = gx;
990 mCurrentCellY = gy; 990 mCurrentCellY = gy;
991 } 991 }
992} 992}
993 993
994void KOAgenda::endItemAction() 994void KOAgenda::endItemAction()
995{ 995{
996 996
997 if ( mItemMoved ) { 997 if ( mItemMoved ) {
998 KOAgendaItem *placeItem = mActionItem->firstMultiItem(); 998 KOAgendaItem *placeItem = mActionItem->firstMultiItem();
999 if ( !placeItem ) { 999 if ( !placeItem ) {
1000 placeItem = mActionItem; 1000 placeItem = mActionItem;
1001 } 1001 }
1002 if ( placeItem->incidence()->recurrence()->doesRecur() ) { 1002 if ( placeItem->incidence()->doesRecur() ) {
1003 Incidence* oldInc = placeItem->incidence(); 1003 Incidence* oldInc = placeItem->incidence();
1004 placeItem->recreateIncidence(); 1004 placeItem->recreateIncidence();
1005 emit addToCalSignal(placeItem->incidence(), oldInc ); 1005 emit addToCalSignal(placeItem->incidence(), oldInc );
1006 } 1006 }
1007 int type = mActionType; 1007 int type = mActionType;
1008 if ( mAllDayMode ) 1008 if ( mAllDayMode )
1009 type = -1; 1009 type = -1;
1010 KOAgendaItem *modifiedItem = placeItem; 1010 KOAgendaItem *modifiedItem = placeItem;
1011 //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */); 1011 //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */);
1012 QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems(); 1012 QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems();
1013 KOAgendaItem *item; 1013 KOAgendaItem *item;
1014 1014
1015 if ( placeItem->incidence()->typeID() == todoID ) { 1015 if ( placeItem->incidence()->typeID() == todoID ) {
1016 mSelectedItem = 0; 1016 mSelectedItem = 0;
1017 //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth()); 1017 //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth());
1018 modifiedItem->mLastMoveXPos = mCurrentCellX; 1018 modifiedItem->mLastMoveXPos = mCurrentCellX;
1019 emit itemModified( modifiedItem, mActionType ); 1019 emit itemModified( modifiedItem, mActionType );
1020 } 1020 }
1021 else { 1021 else {
1022 1022
1023 1023
1024 globalFlagBlockAgendaItemPaint = 1; 1024 globalFlagBlockAgendaItemPaint = 1;
1025 for ( item=oldconflictItems.first(); item != 0; 1025 for ( item=oldconflictItems.first(); item != 0;
1026 item=oldconflictItems.next() ) { 1026 item=oldconflictItems.next() ) {
1027 placeSubCells(item); 1027 placeSubCells(item);
1028 } 1028 }
1029 while ( placeItem ) { 1029 while ( placeItem ) {
1030 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 1030 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
1031 oldconflictItems = placeItem->conflictItems(); 1031 oldconflictItems = placeItem->conflictItems();
1032 for ( item=oldconflictItems.first(); item != 0; 1032 for ( item=oldconflictItems.first(); item != 0;
1033 item=oldconflictItems.next() ) { 1033 item=oldconflictItems.next() ) {
1034 placeSubCells(item); 1034 placeSubCells(item);
1035 } 1035 }
1036 placeSubCells( placeItem ); 1036 placeSubCells( placeItem );
1037 placeItem = placeItem->nextMultiItem(); 1037 placeItem = placeItem->nextMultiItem();
1038 } 1038 }
1039 globalFlagBlockAgendaItemPaint = 0; 1039 globalFlagBlockAgendaItemPaint = 0;
1040 for ( item=oldconflictItems.first(); item != 0; 1040 for ( item=oldconflictItems.first(); item != 0;
1041 item=oldconflictItems.next() ) { 1041 item=oldconflictItems.next() ) {
1042 globalFlagBlockAgendaItemUpdate = 0; 1042 globalFlagBlockAgendaItemUpdate = 0;
1043 item->repaintMe(); 1043 item->repaintMe();
1044 globalFlagBlockAgendaItemUpdate = 1; 1044 globalFlagBlockAgendaItemUpdate = 1;
1045 item->repaint( false ); 1045 item->repaint( false );
1046 } 1046 }
1047 placeItem = modifiedItem; 1047 placeItem = modifiedItem;
1048 1048
1049 while ( placeItem ) { 1049 while ( placeItem ) {
1050 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 1050 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
1051 globalFlagBlockAgendaItemUpdate = 0; 1051 globalFlagBlockAgendaItemUpdate = 0;
1052 placeItem->repaintMe(); 1052 placeItem->repaintMe();
1053 globalFlagBlockAgendaItemUpdate = 1; 1053 globalFlagBlockAgendaItemUpdate = 1;
1054 placeItem->repaint(false); 1054 placeItem->repaint(false);
1055 placeItem = placeItem->nextMultiItem(); 1055 placeItem = placeItem->nextMultiItem();
1056 } 1056 }
1057 emit itemModified( modifiedItem, mActionType ); 1057 emit itemModified( modifiedItem, mActionType );
1058 1058
1059 1059
1060 placeItem = modifiedItem; 1060 placeItem = modifiedItem;
1061 while ( placeItem ) { 1061 while ( placeItem ) {
1062 oldconflictItems = placeItem->conflictItems(); 1062 oldconflictItems = placeItem->conflictItems();
1063 for ( item=oldconflictItems.first(); item != 0; 1063 for ( item=oldconflictItems.first(); item != 0;
1064 item=oldconflictItems.next() ) { 1064 item=oldconflictItems.next() ) {
1065 placeSubCells(item); 1065 placeSubCells(item);
1066 } 1066 }
1067 placeSubCells( placeItem ); 1067 placeSubCells( placeItem );
1068 placeItem = placeItem->nextMultiItem(); 1068 placeItem = placeItem->nextMultiItem();
1069 1069
1070 } 1070 }
1071 placeItem = modifiedItem; 1071 placeItem = modifiedItem;
1072 while ( placeItem ) { 1072 while ( placeItem ) {
1073 oldconflictItems = placeItem->conflictItems(); 1073 oldconflictItems = placeItem->conflictItems();
1074 for ( item=oldconflictItems.first(); item != 0; 1074 for ( item=oldconflictItems.first(); item != 0;
1075 item=oldconflictItems.next() ) { 1075 item=oldconflictItems.next() ) {
1076 globalFlagBlockAgendaItemUpdate = 0; 1076 globalFlagBlockAgendaItemUpdate = 0;
1077 item->repaintMe(); 1077 item->repaintMe();
1078 globalFlagBlockAgendaItemUpdate = 1; 1078 globalFlagBlockAgendaItemUpdate = 1;
1079 item->repaint(false); 1079 item->repaint(false);
1080 } 1080 }
1081 placeItem = placeItem->nextMultiItem(); 1081 placeItem = placeItem->nextMultiItem();
1082 } 1082 }
1083 /* 1083 /*
1084 1084
1085 oldconflictItems = modifiedItem->conflictItems(); 1085 oldconflictItems = modifiedItem->conflictItems();
1086 for ( item=oldconflictItems.first(); item != 0; 1086 for ( item=oldconflictItems.first(); item != 0;
1087 item=oldconflictItems.next() ) { 1087 item=oldconflictItems.next() ) {
1088 globalFlagBlockAgendaItemUpdate = 0; 1088 globalFlagBlockAgendaItemUpdate = 0;
1089 item->paintMe(false); 1089 item->paintMe(false);
1090 globalFlagBlockAgendaItemUpdate = 1; 1090 globalFlagBlockAgendaItemUpdate = 1;
1091 item->repaint(false); 1091 item->repaint(false);
1092 } 1092 }
1093 */ 1093 */
1094 1094
1095 1095
1096 } 1096 }
1097 1097
1098 } 1098 }
1099 if ( mActionItem ) 1099 if ( mActionItem )
1100 emit incidenceSelected( mActionItem->incidence() ); 1100 emit incidenceSelected( mActionItem->incidence() );
1101 mScrollUpTimer.stop(); 1101 mScrollUpTimer.stop();
1102 mScrollDownTimer.stop(); 1102 mScrollDownTimer.stop();
1103 setCursor( arrowCursor ); 1103 setCursor( arrowCursor );
1104 mActionItem = 0; 1104 mActionItem = 0;
1105 mActionType = NOP; 1105 mActionType = NOP;
1106 mItemMoved = 0; 1106 mItemMoved = 0;
1107 1107
1108} 1108}
1109 1109
1110void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos) 1110void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos)
1111{ 1111{
1112// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; 1112// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl;
1113// QPoint point = viewport()->mapToGlobal(viewportPos); 1113// QPoint point = viewport()->mapToGlobal(viewportPos);
1114// kdDebug() << "Global: " << point.x() << "," << point.y() << endl; 1114// kdDebug() << "Global: " << point.x() << "," << point.y() << endl;
1115// point = clipper()->mapFromGlobal(point); 1115// point = clipper()->mapFromGlobal(point);
1116// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; 1116// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl;
1117 1117
1118 int x,y; 1118 int x,y;
1119 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 1119 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
1120// kdDebug() << "contents: " << x << "," << y << "\n" << endl; 1120// kdDebug() << "contents: " << x << "," << y << "\n" << endl;
1121 int gx,gy; 1121 int gx,gy;
1122 contentsToGrid(x,y,gx,gy); 1122 contentsToGrid(x,y,gx,gy);
1123 1123
1124 // Change cursor to resize cursor if appropriate 1124 // Change cursor to resize cursor if appropriate
1125 if (mAllDayMode) { 1125 if (mAllDayMode) {
1126 int gridDistanceX = (x - gx * mGridSpacingX); 1126 int gridDistanceX = (x - gx * mGridSpacingX);
1127 if (gridDistanceX < mResizeBorderWidth && 1127 if (gridDistanceX < mResizeBorderWidth &&
1128 moveItem->cellX() == gx) { 1128 moveItem->cellX() == gx) {
1129 setCursor(sizeHorCursor); 1129 setCursor(sizeHorCursor);
1130 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && 1130 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth &&
1131 moveItem->cellXWidth() == gx) { 1131 moveItem->cellXWidth() == gx) {
1132 setCursor(sizeHorCursor); 1132 setCursor(sizeHorCursor);
1133 } else { 1133 } else {
1134 setCursor(arrowCursor); 1134 setCursor(arrowCursor);
1135 } 1135 }
1136 } else { 1136 } else {
1137 int gridDistanceY = (y - gy * mGridSpacingY); 1137 int gridDistanceY = (y - gy * mGridSpacingY);
1138 if (gridDistanceY < mResizeBorderWidth && 1138 if (gridDistanceY < mResizeBorderWidth &&
1139 moveItem->cellYTop() == gy && 1139 moveItem->cellYTop() == gy &&
1140 !moveItem->firstMultiItem()) { 1140 !moveItem->firstMultiItem()) {
1141 setCursor(sizeVerCursor); 1141 setCursor(sizeVerCursor);
1142 } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth && 1142 } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth &&
1143 moveItem->cellYBottom() == gy && 1143 moveItem->cellYBottom() == gy &&
1144 !moveItem->lastMultiItem()) { 1144 !moveItem->lastMultiItem()) {
1145 setCursor(sizeVerCursor); 1145 setCursor(sizeVerCursor);
1146 } else { 1146 } else {
1147 setCursor(arrowCursor); 1147 setCursor(arrowCursor);
1148 } 1148 }
1149 } 1149 }
1150} 1150}
1151 1151
1152 1152
1153/* 1153/*
1154 Place item in cell and take care that multiple items using the same cell do 1154 Place item in cell and take care that multiple items using the same cell do
1155 not overlap. This method is not yet optimal. It doesn´t use the maximum space 1155 not overlap. This method is not yet optimal. It doesn´t use the maximum space
1156 it can get in all cases. 1156 it can get in all cases.
1157 At the moment the method has a bug: When an item is placed only the sub cell 1157 At the moment the method has a bug: When an item is placed only the sub cell
1158 widths of the items are changed, which are within the Y region the item to 1158 widths of the items are changed, which are within the Y region the item to
1159 place spans. When the sub cell width change of one of this items affects a 1159 place spans. When the sub cell width change of one of this items affects a
1160 cell, where other items are, which do not overlap in Y with the item to place, 1160 cell, where other items are, which do not overlap in Y with the item to place,
1161 the display gets corrupted, although the corruption looks quite nice. 1161 the display gets corrupted, although the corruption looks quite nice.
1162*/ 1162*/
1163void KOAgenda::placeSubCells(KOAgendaItem *placeItem) 1163void KOAgenda::placeSubCells(KOAgendaItem *placeItem)
1164{ 1164{
1165 1165
1166 QPtrList<KOAgendaItem> conflictItems; 1166 QPtrList<KOAgendaItem> conflictItems;
1167 int maxSubCells = 0; 1167 int maxSubCells = 0;
1168 QIntDict<KOAgendaItem> subCellDict(7); 1168 QIntDict<KOAgendaItem> subCellDict(7);
1169 1169
1170 KOAgendaItem *item; 1170 KOAgendaItem *item;
1171 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1171 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1172 if (item != placeItem) { 1172 if (item != placeItem) {
1173 if (placeItem->cellX() <= item->cellXWidth() && 1173 if (placeItem->cellX() <= item->cellXWidth() &&
1174 placeItem->cellXWidth() >= item->cellX()) { 1174 placeItem->cellXWidth() >= item->cellX()) {
1175 if ((placeItem->cellYTop() <= item->cellYBottom()) && 1175 if ((placeItem->cellYTop() <= item->cellYBottom()) &&
1176 (placeItem->cellYBottom() >= item->cellYTop())) { 1176 (placeItem->cellYBottom() >= item->cellYTop())) {
1177 conflictItems.append(item); 1177 conflictItems.append(item);
1178 if (item->subCells() > maxSubCells) 1178 if (item->subCells() > maxSubCells)
1179 maxSubCells = item->subCells(); 1179 maxSubCells = item->subCells();
1180 subCellDict.insert(item->subCell(),item); 1180 subCellDict.insert(item->subCell(),item);
1181 } 1181 }
1182 } 1182 }
1183 } 1183 }
1184 } 1184 }
1185 1185
1186 if (conflictItems.count() > 0) { 1186 if (conflictItems.count() > 0) {
1187 // Look for unused sub cell and insert item 1187 // Look for unused sub cell and insert item
1188 int i; 1188 int i;
1189 for(i=0;i<maxSubCells;++i) { 1189 for(i=0;i<maxSubCells;++i) {
1190 if (!subCellDict.find(i)) { 1190 if (!subCellDict.find(i)) {
1191 placeItem->setSubCell(i); 1191 placeItem->setSubCell(i);
1192 break; 1192 break;
1193 } 1193 }
1194 } 1194 }
1195 if (i == maxSubCells) { 1195 if (i == maxSubCells) {
1196 placeItem->setSubCell(maxSubCells); 1196 placeItem->setSubCell(maxSubCells);
1197 maxSubCells++; // add new item to number of sub cells 1197 maxSubCells++; // add new item to number of sub cells
1198 } 1198 }
1199 1199
1200 // Prepare for sub cell geometry adjustment 1200 // Prepare for sub cell geometry adjustment
1201 int newSubCellWidth; 1201 int newSubCellWidth;
1202 if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells; 1202 if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells;
1203 else newSubCellWidth = mGridSpacingX / maxSubCells; 1203 else newSubCellWidth = mGridSpacingX / maxSubCells;
1204 conflictItems.append(placeItem); 1204 conflictItems.append(placeItem);
1205 1205
1206 1206
1207 // Adjust sub cell geometry of all direct conflict items 1207 // Adjust sub cell geometry of all direct conflict items
1208 for ( item=conflictItems.first(); item != 0; 1208 for ( item=conflictItems.first(); item != 0;
1209 item=conflictItems.next() ) { 1209 item=conflictItems.next() ) {
1210 item->setSubCells(maxSubCells); 1210 item->setSubCells(maxSubCells);
1211 if (mAllDayMode) { 1211 if (mAllDayMode) {
1212 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); 1212 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth);
1213 } else { 1213 } else {
1214 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); 1214 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY);
1215 } 1215 }
1216 int x,y; 1216 int x,y;
1217 gridToContents(item->cellX(),item->cellYTop(),x,y); 1217 gridToContents(item->cellX(),item->cellYTop(),x,y);
1218 if (mAllDayMode) { 1218 if (mAllDayMode) {
1219 y += item->subCell() * newSubCellWidth; 1219 y += item->subCell() * newSubCellWidth;
1220 } else { 1220 } else {
1221 x += item->subCell() * newSubCellWidth; 1221 x += item->subCell() * newSubCellWidth;
1222 } 1222 }
1223 moveChild(item,x,y); 1223 moveChild(item,x,y);
1224 // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y); 1224 // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y);
1225 //item->updateItem(); 1225 //item->updateItem();
1226 } 1226 }
1227 // Adjust sub cell geometry of all conflict items of all conflict items 1227 // Adjust sub cell geometry of all conflict items of all conflict items
1228 for ( item=conflictItems.first(); item != 0; 1228 for ( item=conflictItems.first(); item != 0;
1229 item=conflictItems.next() ) { 1229 item=conflictItems.next() ) {
1230 if ( placeItem != item ) { 1230 if ( placeItem != item ) {
1231 KOAgendaItem *item2; 1231 KOAgendaItem *item2;
1232 QPtrList<KOAgendaItem> conflictItems2 = item->conflictItems(); 1232 QPtrList<KOAgendaItem> conflictItems2 = item->conflictItems();
1233 for ( item2=conflictItems2.first(); item2 != 0; 1233 for ( item2=conflictItems2.first(); item2 != 0;
1234 item2=conflictItems2.next() ) { 1234 item2=conflictItems2.next() ) {
1235 if ( item2->subCells() != maxSubCells) { 1235 if ( item2->subCells() != maxSubCells) {
1236 item2->setSubCells(maxSubCells); 1236 item2->setSubCells(maxSubCells);
1237 if (mAllDayMode) { 1237 if (mAllDayMode) {
1238 item2->resize(item2->cellWidth() * mGridSpacingX, newSubCellWidth); 1238 item2->resize(item2->cellWidth() * mGridSpacingX, newSubCellWidth);
1239 } else { 1239 } else {
1240 item2->resize(newSubCellWidth, item2->cellHeight() * mGridSpacingY); 1240 item2->resize(newSubCellWidth, item2->cellHeight() * mGridSpacingY);
1241 } 1241 }
1242 int x,y; 1242 int x,y;
1243 gridToContents(item2->cellX(),item2->cellYTop(),x,y); 1243 gridToContents(item2->cellX(),item2->cellYTop(),x,y);
1244 if (mAllDayMode) { 1244 if (mAllDayMode) {
1245 y += item2->subCell() * newSubCellWidth; 1245 y += item2->subCell() * newSubCellWidth;
1246 } else { 1246 } else {
1247 x += item2->subCell() * newSubCellWidth; 1247 x += item2->subCell() * newSubCellWidth;
1248 } 1248 }
1249 moveChild(item2,x,y); 1249 moveChild(item2,x,y);
1250 //qDebug("setttttt %d %s",maxSubCells, item2->text().latin1() ); 1250 //qDebug("setttttt %d %s",maxSubCells, item2->text().latin1() );
1251 } 1251 }
1252 } 1252 }
1253 } 1253 }
1254 } 1254 }
1255 } else { 1255 } else {
1256 placeItem->setSubCell(0); 1256 placeItem->setSubCell(0);
1257 placeItem->setSubCells(1); 1257 placeItem->setSubCells(1);
1258 if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY); 1258 if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY);
1259 else placeItem->resize(mGridSpacingX,placeItem->height()); 1259 else placeItem->resize(mGridSpacingX,placeItem->height());
1260 int x,y; 1260 int x,y;
1261 gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y); 1261 gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y);
1262 moveChild(placeItem,x,y); 1262 moveChild(placeItem,x,y);
1263 } 1263 }
1264 placeItem->setConflictItems(conflictItems); 1264 placeItem->setConflictItems(conflictItems);
1265 // for ( item=conflictItems.first(); item != 0; 1265 // for ( item=conflictItems.first(); item != 0;
1266// item=conflictItems.next() ) { 1266// item=conflictItems.next() ) {
1267// //item->updateItem(); 1267// //item->updateItem();
1268// //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() ); 1268// //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() );
1269// } 1269// }
1270// placeItem->updateItem(); 1270// placeItem->updateItem();
1271} 1271}
1272 1272
1273void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch) 1273void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch)
1274{ 1274{
1275 if ( globalFlagBlockAgenda ) 1275 if ( globalFlagBlockAgenda )
1276 return; 1276 return;
1277 1277
1278 if ( mInvalidPixmap ) { 1278 if ( mInvalidPixmap ) {
1279 mInvalidPixmap = false; 1279 mInvalidPixmap = false;
1280 qDebug("KO: Upsizing Pixmaps "); 1280 qDebug("KO: Upsizing Pixmaps ");
1281 computeSizes(); 1281 computeSizes();
1282 emit updateViewSignal(); 1282 emit updateViewSignal();
1283 return; 1283 return;
1284 } 1284 }
1285 if ( ! mAllDayMode ) { 1285 if ( ! mAllDayMode ) {
1286 // currently not working for 1286 // currently not working for
1287 1287
1288 //qDebug("KOAgenda::drawContents "); 1288 //qDebug("KOAgenda::drawContents ");
1289#if 0 1289#if 0
1290 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) { 1290 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) {
1291 qDebug("WAU "); 1291 qDebug("WAU ");
1292 drawContentsToPainter(); 1292 drawContentsToPainter();
1293 } 1293 }
1294#endif 1294#endif
1295 QPaintDevice* pd = p->device(); 1295 QPaintDevice* pd = p->device();
1296 p->end(); 1296 p->end();
1297 int vx, vy; 1297 int vx, vy;
1298 int selectionX = KOGlobals::self()->reverseLayout() ? 1298 int selectionX = KOGlobals::self()->reverseLayout() ?
1299 (mColumns - 1 - mSelectionCellX) * mGridSpacingX : 1299 (mColumns - 1 - mSelectionCellX) * mGridSpacingX :
1300 mSelectionCellX * mGridSpacingX; 1300 mSelectionCellX * mGridSpacingX;
1301 contentsToViewport ( cx, cy, vx,vy); 1301 contentsToViewport ( cx, cy, vx,vy);
1302 //qDebug(" %d %d %d %d %d", cx, cy, cw,ch,mGridSpacingX-1) ; 1302 //qDebug(" %d %d %d %d %d", cx, cy, cw,ch,mGridSpacingX-1) ;
1303 1303
1304 if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) ) { 1304 if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) ) {
1305 if ( mGridSpacingX == cw && mSelectionHeight > 0 && ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && 1305 if ( mGridSpacingX == cw && mSelectionHeight > 0 && ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) &&
1306 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) ) { 1306 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) ) {
1307 1307
1308 int vxSel, vySel; 1308 int vxSel, vySel;
1309 contentsToViewport ( selectionX, mSelectionYTop, vxSel,vySel); 1309 contentsToViewport ( selectionX, mSelectionYTop, vxSel,vySel);
1310 int off = mSelectionHeight; 1310 int off = mSelectionHeight;
1311 if ( vySel < 0 ) 1311 if ( vySel < 0 )
1312 off += vySel; 1312 off += vySel;
1313 //qDebug("OFF %d %d %d", off,vySel, vy ); 1313 //qDebug("OFF %d %d %d", off,vySel, vy );
1314 bitBlt ( pd, vx, vy+off, &mPaintPixmap, cx, cy+off, cw , ch-off ,CopyROP); 1314 bitBlt ( pd, vx, vy+off, &mPaintPixmap, cx, cy+off, cw , ch-off ,CopyROP);
1315 } else { 1315 } else {
1316 bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP); 1316 bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP);
1317 } 1317 }
1318 } 1318 }
1319 if ( mSelectionHeight > 0 ) { 1319 if ( mSelectionHeight > 0 ) {
1320 //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight ); 1320 //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight );
1321 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && 1321 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) &&
1322 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { 1322 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) {
1323 contentsToViewport ( selectionX, mSelectionYTop, vx,vy); 1323 contentsToViewport ( selectionX, mSelectionYTop, vx,vy);
1324 // bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP); 1324 // bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP);
1325 int hei = mSelectionHeight; 1325 int hei = mSelectionHeight;
1326 int offset = 0; 1326 int offset = 0;
1327 while ( hei > 0 ) { 1327 while ( hei > 0 ) {
1328 int p_hei = 5; 1328 int p_hei = 5;
1329 if ( hei < 5 ) p_hei = hei; 1329 if ( hei < 5 ) p_hei = hei;
1330 hei -= 5; 1330 hei -= 5;
1331 bitBlt ( pd, vx+1, vy+offset, &mHighlightPixmap, 0, 0, mGridSpacingX-1, p_hei ,CopyROP); 1331 bitBlt ( pd, vx+1, vy+offset, &mHighlightPixmap, 0, 0, mGridSpacingX-1, p_hei ,CopyROP);
1332 offset += 5; 1332 offset += 5;
1333 } 1333 }
1334 } 1334 }
1335 } 1335 }
1336 p->begin( pd ); 1336 p->begin( pd );
1337 } else { 1337 } else {
1338#if 0 1338#if 0
1339 qDebug("mCurPixWid %d %d ",mCurPixWid, contentsWidth() ); 1339 qDebug("mCurPixWid %d %d ",mCurPixWid, contentsWidth() );
1340 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) { 1340 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) {
1341 qDebug("WAUWAU "); 1341 qDebug("WAUWAU ");
1342 drawContentsToPainter(); 1342 drawContentsToPainter();
1343 } 1343 }
1344#endif 1344#endif
1345 QPaintDevice* pd = p->device(); 1345 QPaintDevice* pd = p->device();
1346 p->end(); 1346 p->end();
1347 int vx, vy; 1347 int vx, vy;
1348 int selectionX = KOGlobals::self()->reverseLayout() ? 1348 int selectionX = KOGlobals::self()->reverseLayout() ?
1349 (mColumns - 1 - mSelectionCellX) * mGridSpacingX : 1349 (mColumns - 1 - mSelectionCellX) * mGridSpacingX :
1350 mSelectionCellX * mGridSpacingX; 1350 mSelectionCellX * mGridSpacingX;
1351 contentsToViewport ( cx, cy, vx,vy); 1351 contentsToViewport ( cx, cy, vx,vy);
1352 // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ; 1352 // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ;
1353 if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) ) 1353 if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) )
1354 bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP); 1354 bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP);
1355 1355
1356 if ( mSelectionHeight > 0 ) { 1356 if ( mSelectionHeight > 0 ) {
1357 //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight ); 1357 //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight );
1358 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && 1358 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) &&
1359 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { 1359 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) {
1360 contentsToViewport ( selectionX, mSelectionYTop, vx,vy); 1360 contentsToViewport ( selectionX, mSelectionYTop, vx,vy);
1361 //bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP); 1361 //bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP);
1362 int hei = mSelectionHeight; 1362 int hei = mSelectionHeight;
1363 int offset = 0; 1363 int offset = 0;
1364 while ( hei > 0 ) { 1364 while ( hei > 0 ) {
1365 int p_hei = 5; 1365 int p_hei = 5;
1366 if ( hei < 5 ) p_hei = hei; 1366 if ( hei < 5 ) p_hei = hei;
1367 hei -= 5; 1367 hei -= 5;
1368 bitBlt ( pd, vx+1, vy+offset, &mHighlightPixmap, 0, 0, mGridSpacingX-1, p_hei ,CopyROP); 1368 bitBlt ( pd, vx+1, vy+offset, &mHighlightPixmap, 0, 0, mGridSpacingX-1, p_hei ,CopyROP);
1369 offset += 5; 1369 offset += 5;
1370 } 1370 }
1371 } 1371 }
1372 } 1372 }
1373 p->begin( pd ); 1373 p->begin( pd );
1374 } 1374 }
1375 1375
1376} 1376}
1377 1377
1378void KOAgenda::finishUpdate() 1378void KOAgenda::finishUpdate()
1379{ 1379{
1380 1380
1381 KOAgendaItem *item; 1381 KOAgendaItem *item;
1382 globalFlagBlockAgendaItemPaint = 1; 1382 globalFlagBlockAgendaItemPaint = 1;
1383 // Adjust sub cell geometry of all conflict items of all conflict items of all conflict items ... of the conflict item with the max number of conflictitems 1383 // Adjust sub cell geometry of all conflict items of all conflict items of all conflict items ... of the conflict item with the max number of conflictitems
1384 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1384 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1385 if ( !item->checkLayout() ) { 1385 if ( !item->checkLayout() ) {
1386 //qDebug(" conflictitem found "); 1386 //qDebug(" conflictitem found ");
1387 int newSubCellWidth; 1387 int newSubCellWidth;
1388 if (mAllDayMode) newSubCellWidth = mGridSpacingY / item->subCells(); 1388 if (mAllDayMode) newSubCellWidth = mGridSpacingY / item->subCells();
1389 else newSubCellWidth = mGridSpacingX / item->subCells(); 1389 else newSubCellWidth = mGridSpacingX / item->subCells();
1390 1390
1391 if (mAllDayMode) { 1391 if (mAllDayMode) {
1392 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); 1392 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth);
1393 } else { 1393 } else {
1394 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); 1394 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY);
1395 } 1395 }
1396 int x,y; 1396 int x,y;
1397 gridToContents(item->cellX(),item->cellYTop(),x,y); 1397 gridToContents(item->cellX(),item->cellYTop(),x,y);
1398 if (mAllDayMode) { 1398 if (mAllDayMode) {
1399 y += item->subCell() * newSubCellWidth; 1399 y += item->subCell() * newSubCellWidth;
1400 } else { 1400 } else {
1401 x += item->subCell() * newSubCellWidth; 1401 x += item->subCell() * newSubCellWidth;
1402 } 1402 }
1403 moveChild(item,x,y); 1403 moveChild(item,x,y);
1404 } 1404 }
1405 } 1405 }
1406 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1406 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1407 if ( !item->isVisible() ) 1407 if ( !item->isVisible() )
1408 item->show(); 1408 item->show();
1409 1409
1410 } 1410 }
1411 globalFlagBlockAgendaItemUpdate = 0; 1411 globalFlagBlockAgendaItemUpdate = 0;
1412 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1412 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1413 item->repaintMe( ); 1413 item->repaintMe( );
1414 } 1414 }
1415 globalFlagBlockAgendaItemUpdate = 1; 1415 globalFlagBlockAgendaItemUpdate = 1;
1416 qApp->processEvents(); 1416 qApp->processEvents();
1417 globalFlagBlockAgendaItemPaint = 0; 1417 globalFlagBlockAgendaItemPaint = 0;
1418 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1418 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1419 item->repaint( false ); 1419 item->repaint( false );
1420 } 1420 }
1421 marcus_bains(); 1421 marcus_bains();
1422} 1422}
1423 1423
1424/* 1424/*
1425 Draw grid in the background of the agenda. 1425 Draw grid in the background of the agenda.
1426*/ 1426*/
1427void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch) 1427void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch)
1428{ 1428{
1429 1429
1430 1430
1431 if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask ) 1431 if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask )
1432 return; 1432 return;
1433 if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 ) 1433 if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 )
1434 return; 1434 return;
1435 int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight(); 1435 int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight();
1436 if ( ch < 1 ) 1436 if ( ch < 1 )
1437 ch = 1; 1437 ch = 1;
1438 if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) { 1438 if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) {
1439 mPaintPixmap.resize( contentsWidth()+42, ch ); 1439 mPaintPixmap.resize( contentsWidth()+42, ch );
1440 } 1440 }
1441 mCurPixWid = contentsWidth(); 1441 mCurPixWid = contentsWidth();
1442 mCurPixHei = ch; 1442 mCurPixHei = ch;
1443 if ( mHighlightPixmap.width() < mGridSpacingX-1 ) { 1443 if ( mHighlightPixmap.width() < mGridSpacingX-1 ) {
1444 mHighlightPixmap.resize( mGridSpacingX-1, 5 ); 1444 mHighlightPixmap.resize( mGridSpacingX-1, 5 );
1445 mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor ); 1445 mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor );
1446 } 1446 }
1447 mPixPainter.begin( &mPaintPixmap) ; 1447 mPixPainter.begin( &mPaintPixmap) ;
1448 //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() ); 1448 //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() );
1449 QPainter * p ; 1449 QPainter * p ;
1450 if (paint == 0) { 1450 if (paint == 0) {
1451 mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor); 1451 mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor);
1452 p = &mPixPainter; 1452 p = &mPixPainter;
1453 } 1453 }
1454 else 1454 else
1455 p = paint ; 1455 p = paint ;
1456 // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch); 1456 // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch);
1457 1457
1458 //--cx;++cw; 1458 //--cx;++cw;
1459 int lGridSpacingY = mGridSpacingY*2; 1459 int lGridSpacingY = mGridSpacingY*2;
1460 int selDay; 1460 int selDay;
1461 QDate curDate = QDate::currentDate(); 1461 QDate curDate = QDate::currentDate();
1462 if ( !backgroundOnly ) { 1462 if ( !backgroundOnly ) {
1463 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) 1463 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay)
1464 { 1464 {
1465 if ( mSelectedDates[selDay] == curDate && KOPrefs::instance()->mHighlightCurrentDay) { 1465 if ( mSelectedDates[selDay] == curDate && KOPrefs::instance()->mHighlightCurrentDay) {
1466 int x1 = cx; 1466 int x1 = cx;
1467 int y1 = 0; 1467 int y1 = 0;
1468 if (y1 < cy) y1 = cy; 1468 if (y1 < cy) y1 = cy;
1469 int x2 = cx+cw-1; 1469 int x2 = cx+cw-1;
1470 int y2 = contentsHeight(); 1470 int y2 = contentsHeight();
1471 if (y2 > cy+ch-1) y2=cy+ch-1; 1471 if (y2 > cy+ch-1) y2=cy+ch-1;
1472 if (x2 >= x1 && y2 >= y1) { 1472 if (x2 >= x1 && y2 >= y1) {
1473 int gxStart = selDay; 1473 int gxStart = selDay;
1474 int gxEnd = gxStart ; 1474 int gxEnd = gxStart ;
1475 int xStart = KOGlobals::self()->reverseLayout() ? 1475 int xStart = KOGlobals::self()->reverseLayout() ?
1476 (mColumns - 1 - gxStart)*mGridSpacingX : 1476 (mColumns - 1 - gxStart)*mGridSpacingX :
1477 gxStart*mGridSpacingX; 1477 gxStart*mGridSpacingX;
1478 if (xStart < x1) xStart = x1; 1478 if (xStart < x1) xStart = x1;
1479 int xEnd = KOGlobals::self()->reverseLayout() ? 1479 int xEnd = KOGlobals::self()->reverseLayout() ?
1480 (mColumns - gxStart)*mGridSpacingX-1 : 1480 (mColumns - gxStart)*mGridSpacingX-1 :
1481 (gxStart+1)*mGridSpacingX-1; 1481 (gxStart+1)*mGridSpacingX-1;
1482 if (xEnd > x2) xEnd = x2; 1482 if (xEnd > x2) xEnd = x2;
1483 if ( KOPrefs::instance()->mUseHighlightLightColor ) 1483 if ( KOPrefs::instance()->mUseHighlightLightColor )
1484 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1484 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1485 KOPrefs::instance()->mAgendaBgColor.light()); 1485 KOPrefs::instance()->mAgendaBgColor.light());
1486 else 1486 else
1487 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1487 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1488 KOPrefs::instance()->mAgendaBgColor.dark()); 1488 KOPrefs::instance()->mAgendaBgColor.dark());
1489 1489
1490 } 1490 }
1491 } 1491 }
1492 } 1492 }
1493 } 1493 }
1494 // Highlight working hours 1494 // Highlight working hours
1495 1495
1496 if ( !backgroundOnly ) 1496 if ( !backgroundOnly )
1497 if (mWorkingHoursEnable) { 1497 if (mWorkingHoursEnable) {
1498 int x1 = cx; 1498 int x1 = cx;
1499 int y1 = mWorkingHoursYTop; 1499 int y1 = mWorkingHoursYTop;
1500 if (y1 < cy) y1 = cy; 1500 if (y1 < cy) y1 = cy;
1501 int x2 = cx+cw-1; 1501 int x2 = cx+cw-1;
1502 // int x2 = mGridSpacingX * 5 - 1; 1502 // int x2 = mGridSpacingX * 5 - 1;
1503 // if (x2 > cx+cw-1) x2 = cx + cw - 1; 1503 // if (x2 > cx+cw-1) x2 = cx + cw - 1;
1504 int y2 = mWorkingHoursYBottom; 1504 int y2 = mWorkingHoursYBottom;
1505 if (y2 > cy+ch-1) y2=cy+ch-1; 1505 if (y2 > cy+ch-1) y2=cy+ch-1;
1506 1506
1507 if (x2 >= x1 && y2 >= y1) { 1507 if (x2 >= x1 && y2 >= y1) {
1508 // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX ); 1508 // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX );
1509 int gxStart = x1/mGridSpacingX; 1509 int gxStart = x1/mGridSpacingX;
1510 int gxEnd = x2/mGridSpacingX; 1510 int gxEnd = x2/mGridSpacingX;
1511 while(gxStart <= gxEnd) { 1511 while(gxStart <= gxEnd) {
1512 if (gxStart < int(mHolidayMask->count()) && 1512 if (gxStart < int(mHolidayMask->count()) &&
1513 !mHolidayMask->at(gxStart)) { 1513 !mHolidayMask->at(gxStart)) {
1514 int xStart = KOGlobals::self()->reverseLayout() ? 1514 int xStart = KOGlobals::self()->reverseLayout() ?
1515 (mColumns - 1 - gxStart)*mGridSpacingX : 1515 (mColumns - 1 - gxStart)*mGridSpacingX :
1516 gxStart*mGridSpacingX; 1516 gxStart*mGridSpacingX;
1517 if (xStart < x1) xStart = x1; 1517 if (xStart < x1) xStart = x1;
1518 int xEnd = KOGlobals::self()->reverseLayout() ? 1518 int xEnd = KOGlobals::self()->reverseLayout() ?
1519 (mColumns - gxStart)*mGridSpacingX-1 : 1519 (mColumns - gxStart)*mGridSpacingX-1 :
1520 (gxStart+1)*mGridSpacingX-1; 1520 (gxStart+1)*mGridSpacingX-1;
1521 if (xEnd > x2) xEnd = x2; 1521 if (xEnd > x2) xEnd = x2;
1522 if ( mSelectedDates[gxStart] == curDate && KOPrefs::instance()->mHighlightCurrentDay ) { 1522 if ( mSelectedDates[gxStart] == curDate && KOPrefs::instance()->mHighlightCurrentDay ) {
1523 if ( KOPrefs::instance()->mUseHighlightLightColor ) 1523 if ( KOPrefs::instance()->mUseHighlightLightColor )
1524 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1524 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1525 KOPrefs::instance()->mWorkingHoursColor.light()); 1525 KOPrefs::instance()->mWorkingHoursColor.light());
1526 else 1526 else
1527 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1527 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1528 KOPrefs::instance()->mWorkingHoursColor.dark()); 1528 KOPrefs::instance()->mWorkingHoursColor.dark());
1529 } else { 1529 } else {
1530 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1530 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1531 KOPrefs::instance()->mWorkingHoursColor); 1531 KOPrefs::instance()->mWorkingHoursColor);
1532 } 1532 }
1533 } 1533 }
1534 ++gxStart; 1534 ++gxStart;
1535 } 1535 }
1536 } 1536 }
1537 } 1537 }
1538 /* 1538 /*
1539 int selectionX = KOGlobals::self()->reverseLayout() ? 1539 int selectionX = KOGlobals::self()->reverseLayout() ?
1540 (mColumns - 1 - mSelectionCellX) * mGridSpacingX : 1540 (mColumns - 1 - mSelectionCellX) * mGridSpacingX :
1541 mSelectionCellX * mGridSpacingX; 1541 mSelectionCellX * mGridSpacingX;
1542 1542
1543 // Draw selection 1543 // Draw selection
1544 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && 1544 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) &&
1545 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { 1545 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) {
1546 // TODO: paint only part within cx,cy,cw,ch 1546 // TODO: paint only part within cx,cy,cw,ch
1547 p->fillRect( selectionX, mSelectionYTop, mGridSpacingX, 1547 p->fillRect( selectionX, mSelectionYTop, mGridSpacingX,
1548 mSelectionHeight, KOPrefs::instance()->mHighlightColor ); 1548 mSelectionHeight, KOPrefs::instance()->mHighlightColor );
1549 } 1549 }
1550 */ 1550 */
1551 // Draw vertical lines of grid 1551 // Draw vertical lines of grid
1552 1552
1553 int x = ((int)(cx/mGridSpacingX))*mGridSpacingX; 1553 int x = ((int)(cx/mGridSpacingX))*mGridSpacingX;
1554 if ( mGridSpacingX > 0 ) { 1554 if ( mGridSpacingX > 0 ) {
1555 while (x < cx + cw) { 1555 while (x < cx + cw) {
1556 p->drawLine(x,cy,x,cy+ch); 1556 p->drawLine(x,cy,x,cy+ch);
1557 x+=mGridSpacingX; 1557 x+=mGridSpacingX;
1558 } 1558 }
1559 } 1559 }
1560 // Draw horizontal lines of grid 1560 // Draw horizontal lines of grid
1561 int y = ((int)(cy/lGridSpacingY))*lGridSpacingY; 1561 int y = ((int)(cy/lGridSpacingY))*lGridSpacingY;
1562 if ( lGridSpacingY > 0 ) { 1562 if ( lGridSpacingY > 0 ) {
1563 while (y < cy + ch) { 1563 while (y < cy + ch) {
1564 p->setPen( SolidLine ); 1564 p->setPen( SolidLine );
1565 p->drawLine(cx,y,cx+cw,y); 1565 p->drawLine(cx,y,cx+cw,y);
1566 y+=lGridSpacingY; 1566 y+=lGridSpacingY;
1567 p->setPen( DotLine ); 1567 p->setPen( DotLine );
1568 p->drawLine(cx,y,cx+cw,y); 1568 p->drawLine(cx,y,cx+cw,y);
1569 y+=lGridSpacingY; 1569 y+=lGridSpacingY;
1570 } 1570 }
1571 p->setPen( SolidLine ); 1571 p->setPen( SolidLine );
1572 } 1572 }
1573 mPixPainter.end() ; 1573 mPixPainter.end() ;
1574} 1574}
1575 1575
1576/* 1576/*
1577 Convert srcollview contents coordinates to agenda grid coordinates. 1577 Convert srcollview contents coordinates to agenda grid coordinates.
1578*/ 1578*/
1579void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy) 1579void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy)
1580{ 1580{
1581 gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX : 1581 gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX :
1582 x/mGridSpacingX; 1582 x/mGridSpacingX;
1583 gy = y/mGridSpacingY; 1583 gy = y/mGridSpacingY;
1584} 1584}
1585 1585
1586/* 1586/*
1587 Convert agenda grid coordinates to scrollview contents coordinates. 1587 Convert agenda grid coordinates to scrollview contents coordinates.
1588*/ 1588*/
1589void KOAgenda::gridToContents (int gx, int gy, int& x, int& y) 1589void KOAgenda::gridToContents (int gx, int gy, int& x, int& y)
1590{ 1590{
1591 x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX: 1591 x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX:
1592 gx*mGridSpacingX; 1592 gx*mGridSpacingX;
1593 y = gy*mGridSpacingY; 1593 y = gy*mGridSpacingY;
1594} 1594}
1595 1595
1596 1596
1597/* 1597/*
1598 Return Y coordinate corresponding to time. Coordinates are rounded to fit into 1598 Return Y coordinate corresponding to time. Coordinates are rounded to fit into
1599 the grid. 1599 the grid.
1600*/ 1600*/
1601int KOAgenda::timeToY(const QTime &time) 1601int KOAgenda::timeToY(const QTime &time)
1602{ 1602{
1603 int minutesPerCell = 24 * 60 / mRows; 1603 int minutesPerCell = 24 * 60 / mRows;
1604 int timeMinutes = time.hour() * 60 + time.minute(); 1604 int timeMinutes = time.hour() * 60 + time.minute();
1605 int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell; 1605 int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell;
1606 return Y; 1606 return Y;
1607} 1607}
1608 1608
1609 1609
1610/* 1610/*
1611 Return time corresponding to cell y coordinate. Coordinates are rounded to 1611 Return time corresponding to cell y coordinate. Coordinates are rounded to
1612 fit into the grid. 1612 fit into the grid.
1613*/ 1613*/
1614QTime KOAgenda::gyToTime(int gy) 1614QTime KOAgenda::gyToTime(int gy)
1615{ 1615{
1616 1616
1617 int secondsPerCell = 24 * 60 * 60/ mRows; 1617 int secondsPerCell = 24 * 60 * 60/ mRows;
1618 1618
1619 int timeSeconds = secondsPerCell * gy; 1619 int timeSeconds = secondsPerCell * gy;
1620 1620
1621 QTime time( 0, 0, 0 ); 1621 QTime time( 0, 0, 0 );
1622 if ( timeSeconds < 24 * 60 * 60 ) { 1622 if ( timeSeconds < 24 * 60 * 60 ) {
1623 time = time.addSecs(timeSeconds); 1623 time = time.addSecs(timeSeconds);
1624 } else { 1624 } else {
1625 time.setHMS( 23, 59, 59 ); 1625 time.setHMS( 23, 59, 59 );
1626 } 1626 }
1627 1627
1628 return time; 1628 return time;
1629} 1629}
1630 1630
1631void KOAgenda::setStartHour(int startHour) 1631void KOAgenda::setStartHour(int startHour)
1632{ 1632{
1633 int startCell = startHour * mRows / 24; 1633 int startCell = startHour * mRows / 24;
1634 setContentsPos(0,startCell * gridSpacingY()); 1634 setContentsPos(0,startCell * gridSpacingY());
1635} 1635}
1636QTime KOAgenda::getEndTime() 1636QTime KOAgenda::getEndTime()
1637{ 1637{
1638 int tim = (contentsY ()+viewport()->height())*24/contentsHeight (); 1638 int tim = (contentsY ()+viewport()->height())*24/contentsHeight ();
1639 if ( tim > 23 ) 1639 if ( tim > 23 )
1640 return QTime ( 23,59,59); 1640 return QTime ( 23,59,59);
1641 return QTime ( tim,0,0); 1641 return QTime ( tim,0,0);
1642} 1642}
1643void KOAgenda::hideUnused() 1643void KOAgenda::hideUnused()
1644{ 1644{
1645 // experimental only 1645 // experimental only
1646 // return; 1646 // return;
1647 KOAgendaItem *item; 1647 KOAgendaItem *item;
1648 for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) { 1648 for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) {
1649 item->hide(); 1649 item->hide();
1650 } 1650 }
1651} 1651}
1652 1652
1653 1653
1654KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view) 1654KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view)
1655{ 1655{
1656 1656
1657 KOAgendaItem *fi; 1657 KOAgendaItem *fi;
1658 for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) { 1658 for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) {
1659 if ( fi->incidence() == event ) { 1659 if ( fi->incidence() == event ) {
1660 mUnusedItems.remove(); 1660 mUnusedItems.remove();
1661 fi->init( event, qd ); 1661 fi->init( event, qd );
1662 return fi; 1662 return fi;
1663 } 1663 }
1664 } 1664 }
1665 fi=mUnusedItems.first(); 1665 fi=mUnusedItems.first();
1666 if ( fi ) { 1666 if ( fi ) {
1667 mUnusedItems.remove(); 1667 mUnusedItems.remove();
1668 fi->init( event, qd ); 1668 fi->init( event, qd );
1669 return fi; 1669 return fi;
1670 } 1670 }
1671 // qDebug("new KOAgendaItem "); 1671 // qDebug("new KOAgendaItem ");
1672 1672
1673 KOAgendaItem* agendaItem = new KOAgendaItem( event, qd, view, mAllDayMode ); 1673 KOAgendaItem* agendaItem = new KOAgendaItem( event, qd, view, mAllDayMode );
1674 agendaItem->installEventFilter(this); 1674 agendaItem->installEventFilter(this);
1675 addChild(agendaItem,0,0); 1675 addChild(agendaItem,0,0);
1676 return agendaItem; 1676 return agendaItem;
1677} 1677}
1678KOAgendaItem * KOAgenda::getItemForTodo ( Todo * todo ) 1678KOAgendaItem * KOAgenda::getItemForTodo ( Todo * todo )
1679{ 1679{
1680 KOAgendaItem *item; 1680 KOAgendaItem *item;
1681 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1681 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1682 if ( item->incidence() == todo ) { 1682 if ( item->incidence() == todo ) {
1683 mItems.remove(); 1683 mItems.remove();
1684 return item; 1684 return item;
1685 } 1685 }
1686 } 1686 }
1687 return 0; 1687 return 0;
1688} 1688}
1689 1689
1690 1690
1691void KOAgenda::updateTodo( Todo * todo, int days, bool remove) 1691void KOAgenda::updateTodo( Todo * todo, int days, bool remove)
1692{ 1692{
1693 // ( todo->hasCompletedDate() && todo->completed().date() == currentDate )|| 1693 // ( todo->hasCompletedDate() && todo->completed().date() == currentDate )||
1694 KOAgendaItem *item; 1694 KOAgendaItem *item;
1695 item = getItemForTodo ( todo ); 1695 item = getItemForTodo ( todo );
1696 //qDebug("KOAgenda::updateTodo %d %d %d %d", this, todo, days, remove); 1696 //qDebug("KOAgenda::updateTodo %d %d %d %d", this, todo, days, remove);
1697 if ( item ) { 1697 if ( item ) {
1698 blockSignals( true ); 1698 blockSignals( true );
1699 //qDebug("item found "); 1699 //qDebug("item found ");
1700 item->hide(); 1700 item->hide();
1701 item->setCellX(-2, -1 ); 1701 item->setCellX(-2, -1 );
1702 item->select(false); 1702 item->select(false);
1703 mUnusedItems.append( item ); 1703 mUnusedItems.append( item );
1704 mItems.remove( item ); 1704 mItems.remove( item );
1705 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); 1705 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems();
1706 KOAgendaItem *itemit; 1706 KOAgendaItem *itemit;
1707 //globalFlagBlockAgendaItemPaint = 1; 1707 //globalFlagBlockAgendaItemPaint = 1;
1708 for ( itemit=oldconflictItems.first(); itemit != 0; 1708 for ( itemit=oldconflictItems.first(); itemit != 0;
1709 itemit=oldconflictItems.next() ) { 1709 itemit=oldconflictItems.next() ) {
1710 if ( itemit != item ) 1710 if ( itemit != item )
1711 placeSubCells(itemit); 1711 placeSubCells(itemit);
1712 } 1712 }
1713 qApp->processEvents(); 1713 qApp->processEvents();
1714 //globalFlagBlockAgendaItemPaint = 0; 1714 //globalFlagBlockAgendaItemPaint = 0;
1715 for ( itemit=oldconflictItems.first(); itemit != 0; 1715 for ( itemit=oldconflictItems.first(); itemit != 0;
1716 itemit=oldconflictItems.next() ) { 1716 itemit=oldconflictItems.next() ) {
1717 globalFlagBlockAgendaItemUpdate = 0; 1717 globalFlagBlockAgendaItemUpdate = 0;
1718 if ( itemit != item ) 1718 if ( itemit != item )
1719 itemit->repaintMe(); 1719 itemit->repaintMe();
1720 globalFlagBlockAgendaItemUpdate = 1; 1720 globalFlagBlockAgendaItemUpdate = 1;
1721 //qDebug("sigleshot "); 1721 //qDebug("sigleshot ");
1722 QTimer::singleShot( 0, itemit, SLOT ( repaintItem() )); 1722 QTimer::singleShot( 0, itemit, SLOT ( repaintItem() ));
1723 //itemit->repaint( false ); repaintItem() 1723 //itemit->repaint( false ); repaintItem()
1724 } 1724 }
1725 blockSignals( false ); 1725 blockSignals( false );
1726 } 1726 }
1727 if ( remove ) { 1727 if ( remove ) {
1728 //qDebug("remove****************************************** "); 1728 //qDebug("remove****************************************** ");
1729 return; 1729 return;
1730 } 1730 }
1731 if ( todo->hasCompletedDate() && !KOPrefs::instance()->mShowCompletedTodoInAgenda ) 1731 if ( todo->hasCompletedDate() && !KOPrefs::instance()->mShowCompletedTodoInAgenda )
1732 return; 1732 return;
1733 //qDebug("updateTodo+++++++++++++++++++++++++++++++++++++ "); 1733 //qDebug("updateTodo+++++++++++++++++++++++++++++++++++++ ");
1734 QDate currentDate = QDate::currentDate(); 1734 QDate currentDate = QDate::currentDate();
1735 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < currentDate)&& ( KOPrefs::instance()->mShowTodoInAgenda ); 1735 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < currentDate)&& ( KOPrefs::instance()->mShowTodoInAgenda );
1736 QDateTime dt; 1736 QDateTime dt;
1737 if ( todo->hasCompletedDate() ) 1737 if ( todo->hasCompletedDate() )
1738 dt = todo->completed(); 1738 dt = todo->completed();
1739 else 1739 else
1740 dt = todo->dtDue(); 1740 dt = todo->dtDue();
1741 if ( overdue ) { 1741 if ( overdue ) {
1742 days += todo->dtDue().date().daysTo( currentDate ); 1742 days += todo->dtDue().date().daysTo( currentDate );
1743 } 1743 }
1744 else 1744 else
1745 currentDate = dt.date(); 1745 currentDate = dt.date();
1746 1746
1747 if (( todo->doesFloat() || overdue) && !todo->hasCompletedDate() ) { 1747 if (( todo->doesFloat() || overdue) && !todo->hasCompletedDate() ) {
1748 if ( ! mAllDayMode ) return; 1748 if ( ! mAllDayMode ) return;
1749 // aldayagenda 1749 // aldayagenda
1750 globalFlagBlockAgendaItemPaint = 1; 1750 globalFlagBlockAgendaItemPaint = 1;
1751 item = insertAllDayItem(todo, currentDate,days, days); 1751 item = insertAllDayItem(todo, currentDate,days, days);
1752 item->show(); 1752 item->show();
1753 1753
1754 } 1754 }
1755 else { 1755 else {
1756 if ( mAllDayMode ) return; 1756 if ( mAllDayMode ) return;
1757 // mAgenda 1757 // mAgenda
1758 globalFlagBlockAgendaItemPaint = 1; 1758 globalFlagBlockAgendaItemPaint = 1;
1759 int endY = timeToY(dt.time()) - 1; 1759 int endY = timeToY(dt.time()) - 1;
1760 int hi = 12/KOPrefs::instance()->mHourSize; 1760 int hi = 12/KOPrefs::instance()->mHourSize;
1761 int startY = endY - 1-hi; 1761 int startY = endY - 1-hi;
1762 item = insertItem(todo,currentDate,days,startY,endY); 1762 item = insertItem(todo,currentDate,days,startY,endY);
1763 item->show(); 1763 item->show();
1764 } 1764 }
1765 qApp->processEvents(); 1765 qApp->processEvents();
1766 globalFlagBlockAgendaItemPaint = 0; 1766 globalFlagBlockAgendaItemPaint = 0;
1767 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); 1767 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems();
1768 KOAgendaItem *itemit; 1768 KOAgendaItem *itemit;
1769 for ( itemit=oldconflictItems.first(); itemit != 0; 1769 for ( itemit=oldconflictItems.first(); itemit != 0;
1770 itemit=oldconflictItems.next() ) { 1770 itemit=oldconflictItems.next() ) {
1771 globalFlagBlockAgendaItemUpdate = 0; 1771 globalFlagBlockAgendaItemUpdate = 0;
1772 itemit->repaintMe(); 1772 itemit->repaintMe();
1773 globalFlagBlockAgendaItemUpdate = 1; 1773 globalFlagBlockAgendaItemUpdate = 1;
1774 itemit->repaint(); 1774 itemit->repaint();
1775 } 1775 }
1776 globalFlagBlockAgendaItemUpdate = 0; 1776 globalFlagBlockAgendaItemUpdate = 0;
1777 item->repaintMe(); 1777 item->repaintMe();
1778 globalFlagBlockAgendaItemUpdate = 1; 1778 globalFlagBlockAgendaItemUpdate = 1;
1779 item->repaint(); 1779 item->repaint();
1780} 1780}
1781/* 1781/*
1782 Insert KOAgendaItem into agenda. 1782 Insert KOAgendaItem into agenda.
1783*/ 1783*/
1784KOAgendaItem *KOAgenda::insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom) 1784KOAgendaItem *KOAgenda::insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom)
1785{ 1785{
1786 if (mAllDayMode) { 1786 if (mAllDayMode) {
1787 qDebug("KOAgenda: calling insertItem in all-day mode is illegal. "); 1787 qDebug("KOAgenda: calling insertItem in all-day mode is illegal. ");
1788 return 0; 1788 return 0;
1789 } 1789 }
1790 1790
1791 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); 1791 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport());
1792 //agendaItem->setFrameStyle(WinPanel|Raised); 1792 //agendaItem->setFrameStyle(WinPanel|Raised);
1793 1793
1794 int YSize = YBottom - YTop + 1; 1794 int YSize = YBottom - YTop + 1;
1795 if (YSize < 0) { 1795 if (YSize < 0) {
1796 YSize = 1; 1796 YSize = 1;
1797 } 1797 }
1798 int iheight = mGridSpacingY * YSize; 1798 int iheight = mGridSpacingY * YSize;
1799 1799
1800 agendaItem->resize(mGridSpacingX,iheight ); 1800 agendaItem->resize(mGridSpacingX,iheight );
1801 agendaItem->setCellXY(X,YTop,YBottom); 1801 agendaItem->setCellXY(X,YTop,YBottom);
1802 agendaItem->setCellXWidth(X); 1802 agendaItem->setCellXWidth(X);
1803 1803
1804 //addChild(agendaItem,X*mGridSpacingX,YTop*mGridSpacingY); 1804 //addChild(agendaItem,X*mGridSpacingX,YTop*mGridSpacingY);
1805 mItems.append(agendaItem); 1805 mItems.append(agendaItem);
1806 1806
1807 placeSubCells(agendaItem); 1807 placeSubCells(agendaItem);
1808 1808
1809 //agendaItem->show(); 1809 //agendaItem->show();
1810 1810
1811 1811
1812 return agendaItem; 1812 return agendaItem;
1813} 1813}
1814 1814
1815 1815
1816/* 1816/*
1817 Insert all-day KOAgendaItem into agenda. 1817 Insert all-day KOAgendaItem into agenda.
1818*/ 1818*/
1819KOAgendaItem *KOAgenda::insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd) 1819KOAgendaItem *KOAgenda::insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd)
1820{ 1820{
1821 if (!mAllDayMode) { 1821 if (!mAllDayMode) {
1822 return 0; 1822 return 0;
1823 } 1823 }
1824 1824
1825 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); 1825 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport());
1826 1826
1827 agendaItem->setCellXY(XBegin,0,0); 1827 agendaItem->setCellXY(XBegin,0,0);
1828 agendaItem->setCellXWidth(XEnd); 1828 agendaItem->setCellXWidth(XEnd);
1829 agendaItem->resize(mGridSpacingX * agendaItem->cellWidth(),mGridSpacingY); 1829 agendaItem->resize(mGridSpacingX * agendaItem->cellWidth(),mGridSpacingY);
1830 1830
1831 //addChild(agendaItem,XBegin*mGridSpacingX,0); 1831 //addChild(agendaItem,XBegin*mGridSpacingX,0);
1832 mItems.append(agendaItem); 1832 mItems.append(agendaItem);
1833 1833
1834 placeSubCells(agendaItem); 1834 placeSubCells(agendaItem);
1835 1835
1836 //agendaItem->show(); 1836 //agendaItem->show();
1837 1837
1838 return agendaItem; 1838 return agendaItem;
1839} 1839}
1840 1840
1841 1841
1842void KOAgenda::insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd, 1842void KOAgenda::insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd,
1843 int YTop,int YBottom) 1843 int YTop,int YBottom)
1844{ 1844{
1845 if (mAllDayMode) { 1845 if (mAllDayMode) {
1846 ; 1846 ;
1847 return; 1847 return;
1848 } 1848 }
1849 1849
1850 int cellX,cellYTop,cellYBottom; 1850 int cellX,cellYTop,cellYBottom;
1851 QString newtext; 1851 QString newtext;
1852 int width = XEnd - XBegin + 1; 1852 int width = XEnd - XBegin + 1;
1853 int count = 0; 1853 int count = 0;
1854 KOAgendaItem *current = 0; 1854 KOAgendaItem *current = 0;
1855 QPtrList<KOAgendaItem> multiItems; 1855 QPtrList<KOAgendaItem> multiItems;
1856 for (cellX = XBegin;cellX <= XEnd;++cellX) { 1856 for (cellX = XBegin;cellX <= XEnd;++cellX) {
1857 if (cellX == XBegin) cellYTop = YTop; 1857 if (cellX == XBegin) cellYTop = YTop;
1858 else cellYTop = 0; 1858 else cellYTop = 0;
1859 if (cellX == XEnd) cellYBottom = YBottom; 1859 if (cellX == XEnd) cellYBottom = YBottom;
1860 else cellYBottom = rows() - 1; 1860 else cellYBottom = rows() - 1;
1861 newtext = QString("(%1/%2): ").arg(++count).arg(width); 1861 newtext = QString("(%1/%2): ").arg(++count).arg(width);
1862 newtext.append(event->summary()); 1862 newtext.append(event->summary());
1863 current = insertItem(event,qd,cellX,cellYTop,cellYBottom); 1863 current = insertItem(event,qd,cellX,cellYTop,cellYBottom);
1864 current->setText(newtext); 1864 current->setText(newtext);
1865 multiItems.append(current); 1865 multiItems.append(current);
1866 } 1866 }
1867 1867
1868 KOAgendaItem *next = 0; 1868 KOAgendaItem *next = 0;
1869 KOAgendaItem *last = multiItems.last(); 1869 KOAgendaItem *last = multiItems.last();
1870 KOAgendaItem *first = multiItems.first(); 1870 KOAgendaItem *first = multiItems.first();
1871 KOAgendaItem *setFirst,*setLast; 1871 KOAgendaItem *setFirst,*setLast;
1872 current = first; 1872 current = first;
1873 while (current) { 1873 while (current) {
1874 next = multiItems.next(); 1874 next = multiItems.next();
1875 if (current == first) setFirst = 0; 1875 if (current == first) setFirst = 0;
1876 else setFirst = first; 1876 else setFirst = first;
1877 if (current == last) setLast = 0; 1877 if (current == last) setLast = 0;
1878 else setLast = last; 1878 else setLast = last;
1879 1879
1880 current->setMultiItem(setFirst,next,setLast); 1880 current->setMultiItem(setFirst,next,setLast);
1881 current = next; 1881 current = next;
1882 } 1882 }
1883} 1883}
1884 1884
1885 1885
1886//QSizePolicy KOAgenda::sizePolicy() const 1886//QSizePolicy KOAgenda::sizePolicy() const
1887//{ 1887//{
1888 // Thought this would make the all-day event agenda minimum size and the 1888 // Thought this would make the all-day event agenda minimum size and the
1889 // normal agenda take the remaining space. But it doesn´t work. The QSplitter 1889 // normal agenda take the remaining space. But it doesn´t work. The QSplitter
1890 // don´t seem to think that an Expanding widget needs more space than a 1890 // don´t seem to think that an Expanding widget needs more space than a
1891 // Preferred one. 1891 // Preferred one.
1892 // But it doesn´t hurt, so it stays. 1892 // But it doesn´t hurt, so it stays.
1893// if (mAllDayMode) { 1893// if (mAllDayMode) {
1894// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); 1894// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
1895// } else { 1895// } else {
1896// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); 1896// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
1897// } 1897// }
1898//} 1898//}
1899void KOAgenda::finishResize ( ) 1899void KOAgenda::finishResize ( )
1900{ 1900{
1901 //qDebug("finishResize+++++++++++++++++++++++++++++++ ( ) "); 1901 //qDebug("finishResize+++++++++++++++++++++++++++++++ ( ) ");
1902 if ( globalFlagBlockAgenda == 0 ) { 1902 if ( globalFlagBlockAgenda == 0 ) {
1903 finishUpdate(); 1903 finishUpdate();
1904 //qDebug("finishUpdate() called "); 1904 //qDebug("finishUpdate() called ");
1905 } 1905 }
1906} 1906}
1907/* 1907/*
1908 Overridden from QScrollView to provide proper resizing of KOAgendaItems. 1908 Overridden from QScrollView to provide proper resizing of KOAgendaItems.
1909*/ 1909*/
1910void KOAgenda::resizeEvent ( QResizeEvent *ev ) 1910void KOAgenda::resizeEvent ( QResizeEvent *ev )
1911{ 1911{
1912 mSelectionHeight = 0; 1912 mSelectionHeight = 0;
1913 mResizeTimer.start( 150 , true ); 1913 mResizeTimer.start( 150 , true );
1914 computeSizes(); 1914 computeSizes();
1915 return; 1915 return;
1916 1916
1917} 1917}
1918void KOAgenda::computeSizes() 1918void KOAgenda::computeSizes()
1919{ 1919{
1920 if ( globalFlagBlockStartup ) 1920 if ( globalFlagBlockStartup )
1921 return; 1921 return;
1922 int frameOffset = frameWidth() * 2 +1; 1922 int frameOffset = frameWidth() * 2 +1;
1923 if (mAllDayMode) { 1923 if (mAllDayMode) {
1924 mGridSpacingX = (width()-frameOffset) / mColumns; 1924 mGridSpacingX = (width()-frameOffset) / mColumns;
1925 mGridSpacingY = height() - 2 * frameWidth() - 1; 1925 mGridSpacingY = height() - 2 * frameWidth() - 1;
1926 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY + 1); 1926 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY + 1);
1927 // mGridSpacingY = height(); 1927 // mGridSpacingY = height();
1928 // resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1928 // resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1929 1929
1930 KOAgendaItem *item; 1930 KOAgendaItem *item;
1931 int subCellWidth; 1931 int subCellWidth;
1932 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1932 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1933 subCellWidth = mGridSpacingY / item->subCells(); 1933 subCellWidth = mGridSpacingY / item->subCells();
1934 item->resize(mGridSpacingX * item->cellWidth(),subCellWidth); 1934 item->resize(mGridSpacingX * item->cellWidth(),subCellWidth);
1935 moveChild(item,KOGlobals::self()->reverseLayout() ? 1935 moveChild(item,KOGlobals::self()->reverseLayout() ?
1936 (mColumns - 1 - item->cellX()) * mGridSpacingX : 1936 (mColumns - 1 - item->cellX()) * mGridSpacingX :
1937 item->cellX() * mGridSpacingX, 1937 item->cellX() * mGridSpacingX,
1938 item->subCell() * subCellWidth); 1938 item->subCell() * subCellWidth);
1939 } 1939 }
1940 KOPrefs::instance()->mAllDaySize = mGridSpacingY; 1940 KOPrefs::instance()->mAllDaySize = mGridSpacingY;
1941 } else { 1941 } else {
1942 mGridSpacingX = (width() - verticalScrollBar()->width()-frameOffset)/mColumns; 1942 mGridSpacingX = (width() - verticalScrollBar()->width()-frameOffset)/mColumns;
1943 if (height() > mGridSpacingY * mRows + 1 ) { 1943 if (height() > mGridSpacingY * mRows + 1 ) {
1944 KOPrefs::instance()->mHourSize = ((height())/mRows)+1; 1944 KOPrefs::instance()->mHourSize = ((height())/mRows)+1;
1945 mGridSpacingY = KOPrefs::instance()->mHourSize ; 1945 mGridSpacingY = KOPrefs::instance()->mHourSize ;
1946 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1946 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1947 emit resizedSignal(); 1947 emit resizedSignal();
1948 } else 1948 } else
1949 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1949 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1950 KOAgendaItem *item; 1950 KOAgendaItem *item;
1951 int subCellWidth; 1951 int subCellWidth;
1952 1952
1953 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1953 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1954 subCellWidth = mGridSpacingX / item->subCells(); 1954 subCellWidth = mGridSpacingX / item->subCells();
1955 item->resize(subCellWidth,item->height()); 1955 item->resize(subCellWidth,item->height());
1956 moveChild(item,(KOGlobals::self()->reverseLayout() ? 1956 moveChild(item,(KOGlobals::self()->reverseLayout() ?
1957 (mColumns - 1 - item->cellX()) * mGridSpacingX : 1957 (mColumns - 1 - item->cellX()) * mGridSpacingX :
1958 item->cellX() * mGridSpacingX) + 1958 item->cellX() * mGridSpacingX) +
1959 item->subCell() * subCellWidth,childY(item)); 1959 item->subCell() * subCellWidth,childY(item));
1960 } 1960 }
1961 } 1961 }
1962 int cw = contentsWidth(); 1962 int cw = contentsWidth();
1963 int ch = contentsHeight(); 1963 int ch = contentsHeight();
1964 if ( mAllDayMode ) { 1964 if ( mAllDayMode ) {
1965 QPixmap* paintPixAll = KOAgendaItem::paintPixAllday(); 1965 QPixmap* paintPixAll = KOAgendaItem::paintPixAllday();
1966 if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 ) { 1966 if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 ) {
1967 //qDebug("paintPixAll->resize "); 1967 //qDebug("paintPixAll->resize ");
1968 paintPixAll->resize( cw, ch ); 1968 paintPixAll->resize( cw, ch );
1969 } 1969 }
1970 } else { 1970 } else {
1971 QPixmap* paintPix = KOAgendaItem::paintPix(); 1971 QPixmap* paintPix = KOAgendaItem::paintPix();
1972 if ( paintPix->width() < cw || paintPix->height() < ch ) { 1972 if ( paintPix->width() < cw || paintPix->height() < ch ) {
1973 //qDebug("paintPix->resize "); 1973 //qDebug("paintPix->resize ");
1974 paintPix->resize( cw , ch ); 1974 paintPix->resize( cw , ch );
1975 } 1975 }
1976 } 1976 }
1977 1977
1978 checkScrollBoundaries(); 1978 checkScrollBoundaries();
1979 drawContentsToPainter(); 1979 drawContentsToPainter();
1980 viewport()->repaint(false); 1980 viewport()->repaint(false);
1981} 1981}
1982 1982
1983void KOAgenda::scrollUp() 1983void KOAgenda::scrollUp()
1984{ 1984{
1985 scrollBy(0,-mScrollOffset); 1985 scrollBy(0,-mScrollOffset);
1986} 1986}
1987 1987
1988 1988
1989void KOAgenda::scrollDown() 1989void KOAgenda::scrollDown()
1990{ 1990{
1991 scrollBy(0,mScrollOffset); 1991 scrollBy(0,mScrollOffset);
1992} 1992}
1993 1993
1994void KOAgenda::popupAlarm() 1994void KOAgenda::popupAlarm()
1995{ 1995{
1996 if (!mClickedItem) { 1996 if (!mClickedItem) {
1997 qDebug("KOAgenda::popupAlarm() called without having a clicked item "); 1997 qDebug("KOAgenda::popupAlarm() called without having a clicked item ");
1998 return; 1998 return;
1999 } 1999 }
2000 // TODO: deal correctly with multiple alarms 2000 // TODO: deal correctly with multiple alarms
2001 Alarm* alarm; 2001 Alarm* alarm;
2002 QPtrList<Alarm> list(mClickedItem->incidence()->alarms()); 2002 QPtrList<Alarm> list(mClickedItem->incidence()->alarms());
2003 for(alarm=list.first();alarm;alarm=list.next()) { 2003 for(alarm=list.first();alarm;alarm=list.next()) {
2004 alarm->toggleAlarm(); 2004 alarm->toggleAlarm();
2005 } 2005 }
2006 emit itemModified( mClickedItem , KOGlobals::EVENTEDITED ); 2006 emit itemModified( mClickedItem , KOGlobals::EVENTEDITED );
2007 mClickedItem->paintMe( true ); 2007 mClickedItem->paintMe( true );
2008 mClickedItem->repaint( false ); 2008 mClickedItem->repaint( false );
2009} 2009}
2010 2010
2011/* 2011/*
2012 Calculates the minimum width 2012 Calculates the minimum width
2013*/ 2013*/
2014int KOAgenda::minimumWidth() const 2014int KOAgenda::minimumWidth() const
2015{ 2015{
2016 // TODO:: develop a way to dynamically determine the minimum width 2016 // TODO:: develop a way to dynamically determine the minimum width
2017 int min = 100; 2017 int min = 100;
2018 2018
2019 return min; 2019 return min;
2020} 2020}
2021 2021
2022void KOAgenda::updateConfig() 2022void KOAgenda::updateConfig()
2023{ 2023{
2024 if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor) 2024 if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor)
2025 viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor); 2025 viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor);
2026 if ( mAllDayMode ) { 2026 if ( mAllDayMode ) {
2027 mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize; 2027 mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize;
2028 //mGridSpacingY = KOPrefs::instance()->mAllDaySize; 2028 //mGridSpacingY = KOPrefs::instance()->mAllDaySize;
2029 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 ); 2029 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 );
2030 // setMaximumHeight( mGridSpacingY+1 ); 2030 // setMaximumHeight( mGridSpacingY+1 );
2031 viewport()->repaint( false ); 2031 viewport()->repaint( false );
2032 //setFixedHeight( mGridSpacingY+1 ); 2032 //setFixedHeight( mGridSpacingY+1 );
2033 //qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize); 2033 //qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize);
2034 } 2034 }
2035 else { 2035 else {
2036 mGridSpacingY = KOPrefs::instance()->mHourSize; 2036 mGridSpacingY = KOPrefs::instance()->mHourSize;
2037 calculateWorkingHours(); 2037 calculateWorkingHours();
2038 } 2038 }
2039} 2039}
2040 2040
2041void KOAgenda::checkScrollBoundaries() 2041void KOAgenda::checkScrollBoundaries()
2042{ 2042{
2043 // Invalidate old values to force update 2043 // Invalidate old values to force update
2044 mOldLowerScrollValue = -1; 2044 mOldLowerScrollValue = -1;
2045 mOldUpperScrollValue = -1; 2045 mOldUpperScrollValue = -1;
2046 2046
2047 checkScrollBoundaries(verticalScrollBar()->value()); 2047 checkScrollBoundaries(verticalScrollBar()->value());
2048} 2048}
2049 2049
2050void KOAgenda::checkScrollBoundaries(int v) 2050void KOAgenda::checkScrollBoundaries(int v)
2051{ 2051{
2052 if ( mGridSpacingY == 0 ) 2052 if ( mGridSpacingY == 0 )
2053 return; 2053 return;
2054 int yMin = v/mGridSpacingY; 2054 int yMin = v/mGridSpacingY;
2055 int yMax = (v+visibleHeight())/mGridSpacingY; 2055 int yMax = (v+visibleHeight())/mGridSpacingY;
2056 2056
2057// kdDebug() << "--- yMin: " << yMin << " yMax: " << yMax << endl; 2057// kdDebug() << "--- yMin: " << yMin << " yMax: " << yMax << endl;
2058 2058
2059 if (yMin != mOldLowerScrollValue) { 2059 if (yMin != mOldLowerScrollValue) {
2060 mOldLowerScrollValue = yMin; 2060 mOldLowerScrollValue = yMin;
2061 emit lowerYChanged(yMin); 2061 emit lowerYChanged(yMin);
2062 } 2062 }
2063 if (yMax != mOldUpperScrollValue) { 2063 if (yMax != mOldUpperScrollValue) {
2064 mOldUpperScrollValue = yMax; 2064 mOldUpperScrollValue = yMax;
2065 emit upperYChanged(yMax); 2065 emit upperYChanged(yMax);
2066 } 2066 }
2067} 2067}
2068 2068
2069void KOAgenda::deselectItem() 2069void KOAgenda::deselectItem()
2070{ 2070{
2071 if (mSelectedItem.isNull()) return; 2071 if (mSelectedItem.isNull()) return;
2072 mSelectedItem->select(false); 2072 mSelectedItem->select(false);
2073 mSelectedItem = 0; 2073 mSelectedItem = 0;
2074} 2074}
2075 2075
2076void KOAgenda::selectItem(KOAgendaItem *item) 2076void KOAgenda::selectItem(KOAgendaItem *item)
2077{ 2077{
2078 if ((KOAgendaItem *)mSelectedItem == item) return; 2078 if ((KOAgendaItem *)mSelectedItem == item) return;
2079 deselectItem(); 2079 deselectItem();
2080 if (item == 0) { 2080 if (item == 0) {
2081 emit incidenceSelected( 0 ); 2081 emit incidenceSelected( 0 );
2082 return; 2082 return;
2083 } 2083 }
2084 mSelectedItem = item; 2084 mSelectedItem = item;
2085 mSelectedItem->select(); 2085 mSelectedItem->select();
2086 emit incidenceSelected( mSelectedItem->incidence() ); 2086 emit incidenceSelected( mSelectedItem->incidence() );
2087} 2087}
2088 2088
2089// This function seems never be called. 2089// This function seems never be called.
2090void KOAgenda::keyPressEvent( QKeyEvent *kev ) 2090void KOAgenda::keyPressEvent( QKeyEvent *kev )
2091{ 2091{
2092 switch(kev->key()) { 2092 switch(kev->key()) {
2093 case Key_PageDown: 2093 case Key_PageDown:
2094 verticalScrollBar()->addPage(); 2094 verticalScrollBar()->addPage();
2095 break; 2095 break;
2096 case Key_PageUp: 2096 case Key_PageUp:
2097 verticalScrollBar()->subtractPage(); 2097 verticalScrollBar()->subtractPage();
2098 break; 2098 break;
2099 case Key_Down: 2099 case Key_Down:
2100 verticalScrollBar()->addLine(); 2100 verticalScrollBar()->addLine();
2101 break; 2101 break;
2102 case Key_Up: 2102 case Key_Up:
2103 verticalScrollBar()->subtractLine(); 2103 verticalScrollBar()->subtractLine();
2104 break; 2104 break;
2105 default: 2105 default:
2106 ; 2106 ;
2107 } 2107 }
2108} 2108}
2109 2109
2110void KOAgenda::calculateWorkingHours() 2110void KOAgenda::calculateWorkingHours()
2111{ 2111{
2112// mWorkingHoursEnable = KOPrefs::instance()->mEnableWorkingHours; 2112// mWorkingHoursEnable = KOPrefs::instance()->mEnableWorkingHours;
2113 mWorkingHoursEnable = !mAllDayMode; 2113 mWorkingHoursEnable = !mAllDayMode;
2114 2114
2115 mWorkingHoursYTop = mGridSpacingY * 2115 mWorkingHoursYTop = mGridSpacingY *
2116 KOPrefs::instance()->mWorkingHoursStart * 4; 2116 KOPrefs::instance()->mWorkingHoursStart * 4;
2117 mWorkingHoursYBottom = mGridSpacingY * 2117 mWorkingHoursYBottom = mGridSpacingY *
2118 KOPrefs::instance()->mWorkingHoursEnd * 4 - 1; 2118 KOPrefs::instance()->mWorkingHoursEnd * 4 - 1;
2119} 2119}
2120 2120
2121 2121
2122DateList KOAgenda::dateList() const 2122DateList KOAgenda::dateList() const
2123{ 2123{
2124 return mSelectedDates; 2124 return mSelectedDates;
2125} 2125}
2126 2126
2127void KOAgenda::setDateList(const DateList &selectedDates) 2127void KOAgenda::setDateList(const DateList &selectedDates)
2128{ 2128{
2129 mSelectedDates = selectedDates; 2129 mSelectedDates = selectedDates;
2130} 2130}
2131 2131
2132void KOAgenda::setHolidayMask(QMemArray<bool> *mask) 2132void KOAgenda::setHolidayMask(QMemArray<bool> *mask)
2133{ 2133{
2134 mHolidayMask = mask; 2134 mHolidayMask = mask;
2135 2135
2136/* 2136/*
2137 kdDebug() << "HolidayMask: "; 2137 kdDebug() << "HolidayMask: ";
2138 for(uint i=0;i<mask->count();++i) { 2138 for(uint i=0;i<mask->count();++i) {
2139 kdDebug() << (mask->at(i) ? "*" : "o"); 2139 kdDebug() << (mask->at(i) ? "*" : "o");
2140 } 2140 }
2141 kdDebug() << endl; 2141 kdDebug() << endl;
2142*/ 2142*/
2143} 2143}
2144 2144
2145void KOAgenda::contentsMousePressEvent ( QMouseEvent *event ) 2145void KOAgenda::contentsMousePressEvent ( QMouseEvent *event )
2146{ 2146{
2147 2147
2148 QScrollView::contentsMousePressEvent(event); 2148 QScrollView::contentsMousePressEvent(event);
2149} 2149}
2150 2150
2151void KOAgenda::storePosition() 2151void KOAgenda::storePosition()
2152{ 2152{
2153 //mContentPosition 2153 //mContentPosition
2154 int max = mGridSpacingY*4*24; 2154 int max = mGridSpacingY*4*24;
2155 if ( contentsY() < 5 && max > viewport()->height()*3/2 ) 2155 if ( contentsY() < 5 && max > viewport()->height()*3/2 )
2156 mContentPosition = 0; 2156 mContentPosition = 0;
2157 else if ( contentsY() + viewport()->height() > max - 5 && max > viewport()->height()*3/2) 2157 else if ( contentsY() + viewport()->height() > max - 5 && max > viewport()->height()*3/2)
2158 mContentPosition = -1.0; 2158 mContentPosition = -1.0;
2159 else 2159 else
2160 mContentPosition = ((float) max)/ ((float)(contentsY()+ ( viewport()->height()/2))); 2160 mContentPosition = ((float) max)/ ((float)(contentsY()+ ( viewport()->height()/2)));
2161 //qDebug("mContentPosition %f %d %d %d",mContentPosition , max, contentsY() ,viewport()->height()); 2161 //qDebug("mContentPosition %f %d %d %d",mContentPosition , max, contentsY() ,viewport()->height());
2162 2162
2163} 2163}
2164void KOAgenda::restorePosition() 2164void KOAgenda::restorePosition()
2165{ 2165{
2166 int posY; 2166 int posY;
2167 int max = mGridSpacingY*4*24; 2167 int max = mGridSpacingY*4*24;
2168 if ( mContentPosition < 0 ) 2168 if ( mContentPosition < 0 )
2169 posY = max-viewport()->height(); 2169 posY = max-viewport()->height();
2170 else 2170 else
2171 if ( mContentPosition == 0 ) 2171 if ( mContentPosition == 0 )
2172 posY = 0; 2172 posY = 0;
2173 else 2173 else
2174 posY = (max/mContentPosition)-(viewport()->height()/2); 2174 posY = (max/mContentPosition)-(viewport()->height()/2);
2175 setContentsPos (0, posY ); 2175 setContentsPos (0, posY );
2176 //qDebug("posY %d hei %d", posY, max); 2176 //qDebug("posY %d hei %d", posY, max);
2177 2177
2178} 2178}
2179void KOAgenda::moveChild( QWidget *w, int x , int y ) 2179void KOAgenda::moveChild( QWidget *w, int x , int y )
2180{ 2180{
2181 ++x; 2181 ++x;
2182 QScrollView::moveChild( w, x , y ); 2182 QScrollView::moveChild( w, x , y );
2183} 2183}
2184#include <qmessagebox.h> 2184#include <qmessagebox.h>
2185#ifdef DESKTOP_VERSION 2185#ifdef DESKTOP_VERSION
2186#include <qprinter.h> 2186#include <qprinter.h>
2187#include <qpainter.h> 2187#include <qpainter.h>
2188#include <qpaintdevicemetrics.h> 2188#include <qpaintdevicemetrics.h>
2189 2189
2190#endif 2190#endif
2191void KOAgenda::printSelection() 2191void KOAgenda::printSelection()
2192{ 2192{
2193#ifdef DESKTOP_VERSION 2193#ifdef DESKTOP_VERSION
2194 if ( mStartCellY == mCurrentCellY ) { 2194 if ( mStartCellY == mCurrentCellY ) {
2195 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2195 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2196 i18n("Nothing selected!\n\nThis prints the full width of the Agenda view as you see it!\n\nTo determine the vertical range of the printing, please select\na vertical range (with the left mouse button down) in one column. "), 2196 i18n("Nothing selected!\n\nThis prints the full width of the Agenda view as you see it!\n\nTo determine the vertical range of the printing, please select\na vertical range (with the left mouse button down) in one column. "),
2197 i18n("OK"), 0, 0, 2197 i18n("OK"), 0, 0,
2198 0, 1 ); 2198 0, 1 );
2199 return; 2199 return;
2200 } 2200 }
2201 2201
2202 float dx, dy; 2202 float dx, dy;
2203 int x,y,w,h; 2203 int x,y,w,h;
2204 x= 0; 2204 x= 0;
2205 w= contentsWidth()+2; 2205 w= contentsWidth()+2;
2206 // h= contentsHeight(); 2206 // h= contentsHeight();
2207 y = mGridSpacingY*mStartCellY; 2207 y = mGridSpacingY*mStartCellY;
2208 h = mGridSpacingY*(mCurrentCellY+1)-y+2; 2208 h = mGridSpacingY*(mCurrentCellY+1)-y+2;
2209 2209
2210 //return; 2210 //return;
2211 QPrinter* printer = new QPrinter(); 2211 QPrinter* printer = new QPrinter();
2212 if ( !printer->setup()) { 2212 if ( !printer->setup()) {
2213 delete printer; 2213 delete printer;
2214 return; 2214 return;
2215 } 2215 }
2216 QPainter p( printer ); 2216 QPainter p( printer );
2217 QPaintDeviceMetrics m = QPaintDeviceMetrics ( printer ); 2217 QPaintDeviceMetrics m = QPaintDeviceMetrics ( printer );
2218 QString date = i18n("Date range: ")+KGlobal::locale()->formatDate( mSelectedDates.first() )+" - "+KGlobal::locale()->formatDate( mSelectedDates.last() ); 2218 QString date = i18n("Date range: ")+KGlobal::locale()->formatDate( mSelectedDates.first() )+" - "+KGlobal::locale()->formatDate( mSelectedDates.last() );
2219 //date += " --- printing time: " + KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), true ); 2219 //date += " --- printing time: " + KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), true );
2220 int hei = p.boundingRect(0,0, 5, 5, Qt::AlignLeft, date ).height(); 2220 int hei = p.boundingRect(0,0, 5, 5, Qt::AlignLeft, date ).height();
2221 // p.drawText( 0, 0, date ); 2221 // p.drawText( 0, 0, date );
2222 int offset = m.width()/8; 2222 int offset = m.width()/8;
2223 // compute the scale 2223 // compute the scale
2224 dx = ((float) m.width()-offset) / (float)w; 2224 dx = ((float) m.width()-offset) / (float)w;
2225 dy = (float)(m.height() - ( 2 * hei )-offset ) / (float)h; 2225 dy = (float)(m.height() - ( 2 * hei )-offset ) / (float)h;
2226 float scale; 2226 float scale;
2227 // scale to fit the width or height of the paper 2227 // scale to fit the width or height of the paper
2228 if ( dx < dy ) 2228 if ( dx < dy )
2229 scale = dx; 2229 scale = dx;
2230 else 2230 else
2231 scale = dy; 2231 scale = dy;
2232 // set the scale 2232 // set the scale
2233 p.drawText( offset* scale, offset* scale*3/4, date ); 2233 p.drawText( offset* scale, offset* scale*3/4, date );
2234 2234
2235 int selDay; 2235 int selDay;
2236 float widOffset = ((float) m.width()-offset) / ((float)(mSelectedDates.count())); 2236 float widOffset = ((float) m.width()-offset) / ((float)(mSelectedDates.count()));
2237 float startX = 1; 2237 float startX = 1;
2238 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) 2238 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay)
2239 { 2239 {
2240 QString text = KGlobal::locale()->formatDate( mSelectedDates[selDay],true ); 2240 QString text = KGlobal::locale()->formatDate( mSelectedDates[selDay],true );
2241 p.setClipRect(offset* scale+startX , 0, widOffset-4, offset* scale+(2*hei* scale) ); 2241 p.setClipRect(offset* scale+startX , 0, widOffset-4, offset* scale+(2*hei* scale) );
2242 p.drawText( offset* scale+startX, (offset+hei)* scale, text ); 2242 p.drawText( offset* scale+startX, (offset+hei)* scale, text );
2243 startX += widOffset; 2243 startX += widOffset;
2244 2244
2245 } 2245 }
2246 p.translate( offset* scale,offset* scale+ (-y * scale)+(2*hei* scale)); 2246 p.translate( offset* scale,offset* scale+ (-y * scale)+(2*hei* scale));
2247 p.scale( scale, scale ); 2247 p.scale( scale, scale );
2248 p.setClipRect( offset* scale, offset* scale+(2*hei* scale), w*scale, h*scale ); 2248 p.setClipRect( offset* scale, offset* scale+(2*hei* scale), w*scale, h*scale );
2249 // now printing with y offset: 2 hei 2249 // now printing with y offset: 2 hei
2250 // p.translate( 0, -y*scale); 2250 // p.translate( 0, -y*scale);
2251 2251
2252 drawContentsToPainter(&p, true ); 2252 drawContentsToPainter(&p, true );
2253 globalFlagBlockAgendaItemUpdate = false; 2253 globalFlagBlockAgendaItemUpdate = false;
2254 KOAgendaItem *item; 2254 KOAgendaItem *item;
2255 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 2255 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
2256 item->select(false); 2256 item->select(false);
2257 item->paintMe( false, &p ); 2257 item->paintMe( false, &p );
2258 } 2258 }
2259 globalFlagBlockAgendaItemUpdate = true; 2259 globalFlagBlockAgendaItemUpdate = true;
2260 p.end(); 2260 p.end();
2261 delete printer; 2261 delete printer;
2262#else 2262#else
2263 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2263 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2264 i18n("Not supported \non PDA!\n"), 2264 i18n("Not supported \non PDA!\n"),
2265 i18n("OK"), 0, 0, 2265 i18n("OK"), 0, 0,
2266 0, 1 ); 2266 0, 1 );
2267#endif 2267#endif
2268} 2268}
diff --git a/korganizer/koagendaitem.cpp b/korganizer/koagendaitem.cpp
index 303a92a..49ad9b8 100644
--- a/korganizer/koagendaitem.cpp
+++ b/korganizer/koagendaitem.cpp
@@ -1,850 +1,850 @@
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 19
20#include <qlabel.h> 20#include <qlabel.h>
21#include <qlayout.h> 21#include <qlayout.h>
22#include <qhbox.h> 22#include <qhbox.h>
23#include <qvbox.h> 23#include <qvbox.h>
24#include <qtooltip.h> 24#include <qtooltip.h>
25#include <qwhatsthis.h> 25#include <qwhatsthis.h>
26#include <qdragobject.h> 26#include <qdragobject.h>
27#include <qdrawutil.h> 27#include <qdrawutil.h>
28#include <qpainter.h> 28#include <qpainter.h>
29 29
30#include <kiconloader.h> 30#include <kiconloader.h>
31#include <kdebug.h> 31#include <kdebug.h>
32#include <kglobal.h> 32#include <kglobal.h>
33#include <klocale.h> 33#include <klocale.h>
34#ifndef DESKTOP_VERSION 34#ifndef DESKTOP_VERSION
35#include <qpe/qpeapplication.h> 35#include <qpe/qpeapplication.h>
36#define AGENDA_ICON_SIZE 5 36#define AGENDA_ICON_SIZE 5
37#else 37#else
38#include <qapplication.h> 38#include <qapplication.h>
39#define AGENDA_ICON_SIZE 7 39#define AGENDA_ICON_SIZE 7
40#endif 40#endif
41#include <libkcal/icaldrag.h> 41#include <libkcal/icaldrag.h>
42#include <libkcal/vcaldrag.h> 42#include <libkcal/vcaldrag.h>
43#include <libkcal/kincidenceformatter.h> 43#include <libkcal/kincidenceformatter.h>
44extern int globalFlagBlockAgenda; 44extern int globalFlagBlockAgenda;
45extern int globalFlagBlockAgendaItemPaint; 45extern int globalFlagBlockAgendaItemPaint;
46extern int globalFlagBlockAgendaItemUpdate; 46extern int globalFlagBlockAgendaItemUpdate;
47 47
48#include "koprefs.h" 48#include "koprefs.h"
49 49
50#include "koagendaitem.h" 50#include "koagendaitem.h"
51//#include "koagendaitem.moc" 51//#include "koagendaitem.moc"
52 52
53 53
54//-------------------------------------------------------------------------- 54//--------------------------------------------------------------------------
55 55
56QToolTipGroup *KOAgendaItem::mToolTipGroup = 0; 56QToolTipGroup *KOAgendaItem::mToolTipGroup = 0;
57 57
58//-------------------------------------------------------------------------- 58//--------------------------------------------------------------------------
59 59
60class KOAgendaItemWhatsThis :public QWhatsThis 60class KOAgendaItemWhatsThis :public QWhatsThis
61{ 61{
62public: 62public:
63 KOAgendaItemWhatsThis( KOAgendaItem* view ) : QWhatsThis( view ),_view (view) { }; 63 KOAgendaItemWhatsThis( KOAgendaItem* view ) : QWhatsThis( view ),_view (view) { };
64 64
65protected: 65protected:
66 virtual QString text( const QPoint& ) 66 virtual QString text( const QPoint& )
67 { 67 {
68 return _view->getWhatsThisText() ; 68 return _view->getWhatsThisText() ;
69 } 69 }
70private: 70private:
71 KOAgendaItem * _view; 71 KOAgendaItem * _view;
72}; 72};
73 73
74KOAgendaItem::KOAgendaItem(Incidence *incidence, QDate qd, QWidget *parent,bool allday, 74KOAgendaItem::KOAgendaItem(Incidence *incidence, QDate qd, QWidget *parent,bool allday,
75 const char *name,WFlags) : 75 const char *name,WFlags) :
76 QWidget(parent, name), mIncidence(incidence), mDate(qd) 76 QWidget(parent, name), mIncidence(incidence), mDate(qd)
77{ 77{
78#ifndef DESKTOP_VERSION 78#ifndef DESKTOP_VERSION
79 //QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); 79 //QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold );
80#endif 80#endif
81 mKOAgendaItemWhatsThis = new KOAgendaItemWhatsThis(this); 81 mKOAgendaItemWhatsThis = new KOAgendaItemWhatsThis(this);
82 int wflags = getWFlags() |WRepaintNoErase;// WResizeNoErase 82 int wflags = getWFlags() |WRepaintNoErase;// WResizeNoErase
83 setWFlags ( wflags); 83 setWFlags ( wflags);
84 mAllDay = allday; 84 mAllDay = allday;
85 init ( incidence, qd ); 85 init ( incidence, qd );
86 //setMouseTracking(true); 86 //setMouseTracking(true);
87 //setAcceptDrops(true); 87 //setAcceptDrops(true);
88 xPaintCoord = -1; 88 xPaintCoord = -1;
89 yPaintCoord = -1; 89 yPaintCoord = -1;
90} 90}
91QString KOAgendaItem::getWhatsThisText() 91QString KOAgendaItem::getWhatsThisText()
92{ 92{
93 if ( mIncidence ) 93 if ( mIncidence )
94 return KIncidenceFormatter::instance()->getFormattedText( mIncidence, 94 return KIncidenceFormatter::instance()->getFormattedText( mIncidence,
95 KOPrefs::instance()->mWTshowDetails, 95 KOPrefs::instance()->mWTshowDetails,
96 KOPrefs::instance()->mWTshowCreated, 96 KOPrefs::instance()->mWTshowCreated,
97 KOPrefs::instance()->mWTshowChanged); 97 KOPrefs::instance()->mWTshowChanged);
98 return "KOAgendaItem::getWhatsThisText()::internal error"; 98 return "KOAgendaItem::getWhatsThisText()::internal error";
99} 99}
100 100
101void KOAgendaItem::initColor () 101void KOAgendaItem::initColor ()
102{ 102{
103 if ( (mIncidence->typeID() == todoID ) && 103 if ( (mIncidence->typeID() == todoID ) &&
104 ( !((static_cast<Todo*>(mIncidence))->isCompleted()) && 104 ( !((static_cast<Todo*>(mIncidence))->isCompleted()) &&
105 ((static_cast<Todo*>(mIncidence))->dtDue().date() <= QDate::currentDate()) ) ) { 105 ((static_cast<Todo*>(mIncidence))->dtDue().date() <= QDate::currentDate()) ) ) {
106 if ( (static_cast<Todo*>(mIncidence))->dtDue() < QDateTime::currentDateTime().date()) 106 if ( (static_cast<Todo*>(mIncidence))->dtDue() < QDateTime::currentDateTime().date())
107 mBackgroundColor = KOPrefs::instance()->mTodoOverdueColor ; 107 mBackgroundColor = KOPrefs::instance()->mTodoOverdueColor ;
108 else 108 else
109 mBackgroundColor = KOPrefs::instance()->mTodoDueTodayColor; 109 mBackgroundColor = KOPrefs::instance()->mTodoDueTodayColor;
110 } 110 }
111 else { 111 else {
112 QStringList categories = mIncidence->categories(); 112 QStringList categories = mIncidence->categories();
113 QString cat = categories.first(); 113 QString cat = categories.first();
114 if (cat.isEmpty()) { 114 if (cat.isEmpty()) {
115 if ( (mIncidence->typeID() == todoID ) &&((static_cast<Todo*>(mIncidence))->isCompleted()) ) 115 if ( (mIncidence->typeID() == todoID ) &&((static_cast<Todo*>(mIncidence))->isCompleted()) )
116 mBackgroundColor =KOPrefs::instance()->mTodoDoneColor; 116 mBackgroundColor =KOPrefs::instance()->mTodoDoneColor;
117 else 117 else
118 mBackgroundColor =KOPrefs::instance()->defaultColor( mIncidence->calID() ); 118 mBackgroundColor =KOPrefs::instance()->defaultColor( mIncidence->calID() );
119 } else { 119 } else {
120 mBackgroundColor = *KOPrefs::instance()->categoryColor(cat); 120 mBackgroundColor = *KOPrefs::instance()->categoryColor(cat);
121 if ( (mIncidence->typeID() == todoID ) &&((static_cast<Todo*>(mIncidence))->isCompleted()) ) { 121 if ( (mIncidence->typeID() == todoID ) &&((static_cast<Todo*>(mIncidence))->isCompleted()) ) {
122 if ( mBackgroundColor == KOPrefs::instance()->mEventColor ) 122 if ( mBackgroundColor == KOPrefs::instance()->mEventColor )
123 mBackgroundColor = KOPrefs::instance()->mTodoDoneColor; 123 mBackgroundColor = KOPrefs::instance()->mTodoDoneColor;
124 } 124 }
125 } 125 }
126 126
127 } 127 }
128 128
129 QColor BackgroundColor ( mBackgroundColor ); 129 QColor BackgroundColor ( mBackgroundColor );
130 if ( mIncidence->calID() > 1 ) { 130 if ( mIncidence->calID() > 1 ) {
131 //BackgroundColor = KOPrefs::instance()->defaultColor( mIncidence->calID() ); 131 //BackgroundColor = KOPrefs::instance()->defaultColor( mIncidence->calID() );
132 } 132 }
133 mColorGroup = QColorGroup( BackgroundColor.light(), 133 mColorGroup = QColorGroup( BackgroundColor.light(),
134 BackgroundColor.dark(),BackgroundColor.light(), 134 BackgroundColor.dark(),BackgroundColor.light(),
135 BackgroundColor.dark(),BackgroundColor, black, BackgroundColor) ; 135 BackgroundColor.dark(),BackgroundColor, black, BackgroundColor) ;
136 setBackgroundColor( mBackgroundColor ); 136 setBackgroundColor( mBackgroundColor );
137 mWhiteText = (mBackgroundColor.red() + mBackgroundColor.green() + mBackgroundColor.blue() < 250); 137 mWhiteText = (mBackgroundColor.red() + mBackgroundColor.green() + mBackgroundColor.blue() < 250);
138} 138}
139void KOAgendaItem::init ( Incidence *incidence, QDate qd ) 139void KOAgendaItem::init ( Incidence *incidence, QDate qd )
140{ 140{
141 mIncidence = incidence; 141 mIncidence = incidence;
142 mDate = qd; 142 mDate = qd;
143 mFirstMultiItem = 0; 143 mFirstMultiItem = 0;
144 mNextMultiItem = 0; 144 mNextMultiItem = 0;
145 mLastMultiItem = 0; 145 mLastMultiItem = 0;
146 computeText(); 146 computeText();
147 initColor(); 147 initColor();
148 mConflictItems.clear(); 148 mConflictItems.clear();
149 setCellXY(0,0,1); 149 setCellXY(0,0,1);
150 setCellXWidth(0); 150 setCellXWidth(0);
151 setSubCell(0); 151 setSubCell(0);
152 setSubCells(1); 152 setSubCells(1);
153 setMultiItem(0,0,0); 153 setMultiItem(0,0,0);
154 startMove(); 154 startMove();
155 mSelected = true; 155 mSelected = true;
156 select(false); 156 select(false);
157 QFontMetrics fontinf(KOPrefs::instance()->mAgendaViewFont); 157 QFontMetrics fontinf(KOPrefs::instance()->mAgendaViewFont);
158 mFontPixelSize = fontinf.height();; 158 mFontPixelSize = fontinf.height();;
159 hide(); 159 hide();
160 xPaintCoord = -1; 160 xPaintCoord = -1;
161 yPaintCoord = -1; 161 yPaintCoord = -1;
162} 162}
163 163
164 164
165KOAgendaItem::~KOAgendaItem() 165KOAgendaItem::~KOAgendaItem()
166{ 166{
167#if QT_VERSION >= 0x030000 167#if QT_VERSION >= 0x030000
168 168
169#else 169#else
170 delete mKOAgendaItemWhatsThis; 170 delete mKOAgendaItemWhatsThis;
171#endif 171#endif
172 172
173} 173}
174 174
175void KOAgendaItem::recreateIncidence() 175void KOAgendaItem::recreateIncidence()
176{ 176{
177#if 0 177#if 0
178 Incidence* newInc = mIncidence->clone(); 178 Incidence* newInc = mIncidence->clone();
179 newInc->recreate(); 179 newInc->recreate();
180 if ( mIncidence->doesRecur() ) { 180 if ( mIncidence->doesRecur() ) {
181 mIncidence->addExDate( mDate ); 181 mIncidence->addExDate( mDate );
182 newInc->recurrence()->unsetRecurs(); 182 newInc->recurrence()->unsetRecurs();
183 int len = mIncidence->dtStart().secsTo( ((Event*)mIncidence)->dtEnd()); 183 int len = mIncidence->dtStart().secsTo( ((Event*)mIncidence)->dtEnd());
184 QTime tim = mIncidence->dtStart().time(); 184 QTime tim = mIncidence->dtStart().time();
185 newInc->setDtStart( QDateTime(mDate, tim) ); 185 newInc->setDtStart( QDateTime(mDate, tim) );
186 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); 186 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) );
187 } 187 }
188#endif 188#endif
189 mIncidence = mIncidence->recreateCloneException( mDate ); 189 mIncidence = mIncidence->recreateCloneException( mDate );
190} 190}
191bool KOAgendaItem::updateIcons(QPainter * p, bool horLayout) 191bool KOAgendaItem::updateIcons(QPainter * p, bool horLayout)
192{ 192{
193 int size = AGENDA_ICON_SIZE; 193 int size = AGENDA_ICON_SIZE;
194 194
195 int yOff = 0; 195 int yOff = 0;
196 int xOff = 0; 196 int xOff = 0;
197 int x = pos().x(); 197 int x = pos().x();
198 198
199 if ( x < 0 ) x = 0; 199 if ( x < 0 ) x = 0;
200 x += 3; 200 x += 3;
201 int y; 201 int y;
202 if ( mAllDay ) 202 if ( mAllDay )
203 y = pos().y()+3; 203 y = pos().y()+3;
204 else 204 else
205 y = mCellYTop * ( height() / cellHeight() ) +3; 205 y = mCellYTop * ( height() / cellHeight() ) +3;
206 206
207 207
208 if ( mIncidence->calID() > 1 ) { 208 if ( mIncidence->calID() > 1 ) {
209 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, KOPrefs::instance()->defaultColor( mIncidence->calID() ) ); 209 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, KOPrefs::instance()->defaultColor( mIncidence->calID() ) );
210 p->drawRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x-1, yOff*( 1 +AGENDA_ICON_SIZE)+y-1, AGENDA_ICON_SIZE+2, AGENDA_ICON_SIZE+2 ); 210 p->drawRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x-1, yOff*( 1 +AGENDA_ICON_SIZE)+y-1, AGENDA_ICON_SIZE+2, AGENDA_ICON_SIZE+2 );
211 if ( horLayout ){ 211 if ( horLayout ){
212 ++xOff; 212 ++xOff;
213 ++x; 213 ++x;
214 } 214 }
215 else { 215 else {
216 ++yOff; 216 ++yOff;
217 ++y; 217 ++y;
218 } 218 }
219 } 219 }
220 if (mIncidence->cancelled() && height() < 20 ) { 220 if (mIncidence->cancelled() && height() < 20 ) {
221 int xpos = xOff*( 1 +AGENDA_ICON_SIZE )+x; 221 int xpos = xOff*( 1 +AGENDA_ICON_SIZE )+x;
222 int ypos = yOff*( 1 +AGENDA_ICON_SIZE)+y; 222 int ypos = yOff*( 1 +AGENDA_ICON_SIZE)+y;
223 p->drawLine( xpos, ypos, xpos+AGENDA_ICON_SIZE-1, ypos+AGENDA_ICON_SIZE-1 ); 223 p->drawLine( xpos, ypos, xpos+AGENDA_ICON_SIZE-1, ypos+AGENDA_ICON_SIZE-1 );
224 p->drawLine( xpos, ypos+AGENDA_ICON_SIZE-1, xpos+AGENDA_ICON_SIZE-1, ypos ); 224 p->drawLine( xpos, ypos+AGENDA_ICON_SIZE-1, xpos+AGENDA_ICON_SIZE-1, ypos );
225 if ( horLayout ) 225 if ( horLayout )
226 ++xOff; 226 ++xOff;
227 else 227 else
228 ++yOff; 228 ++yOff;
229 } 229 }
230 if (mIncidence->isAlarmEnabled() && mIncidence->alarmEnabled()) { 230 if (mIncidence->isAlarmEnabled() && mIncidence->alarmEnabled()) {
231 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, red ); 231 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, red );
232 if ( horLayout ) 232 if ( horLayout )
233 ++xOff; 233 ++xOff;
234 else 234 else
235 ++yOff; 235 ++yOff;
236 } 236 }
237 if (mIncidence->recurrence()->doesRecur()) { 237 if (mIncidence->doesRecur()) {
238 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, blue ); 238 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, blue );
239 if ( horLayout ) 239 if ( horLayout )
240 ++xOff; 240 ++xOff;
241 else 241 else
242 ++yOff; 242 ++yOff;
243 } 243 }
244 if (mIncidence->description().length() > 0) { 244 if (mIncidence->description().length() > 0) {
245 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkGreen ); 245 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkGreen );
246 if ( horLayout ) 246 if ( horLayout )
247 ++xOff; 247 ++xOff;
248 else 248 else
249 ++yOff; 249 ++yOff;
250 } 250 }
251 if (mIncidence->isReadOnly()) { 251 if (mIncidence->isReadOnly()) {
252 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, white ); 252 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, white );
253 if ( horLayout ) 253 if ( horLayout )
254 ++xOff; 254 ++xOff;
255 else 255 else
256 ++yOff; 256 ++yOff;
257 } 257 }
258 258
259 if (mIncidence->attendeeCount()>0) { 259 if (mIncidence->attendeeCount()>0) {
260 260
261 if (mIncidence->organizer() == KOPrefs::instance()->email()) { 261 if (mIncidence->organizer() == KOPrefs::instance()->email()) {
262 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, black ); 262 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, black );
263 if ( horLayout ) 263 if ( horLayout )
264 ++xOff; 264 ++xOff;
265 else 265 else
266 ++yOff; 266 ++yOff;
267 } else { 267 } else {
268 Attendee *me = mIncidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 268 Attendee *me = mIncidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
269 if (me!=0) { 269 if (me!=0) {
270 270
271 271
272 } else { 272 } else {
273 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, yellow ); 273 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, yellow );
274 if ( horLayout ) 274 if ( horLayout )
275 ++xOff; 275 ++xOff;
276 else 276 else
277 ++yOff; 277 ++yOff;
278 278
279 } 279 }
280 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkYellow ); 280 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkYellow );
281 if ( horLayout ) 281 if ( horLayout )
282 ++xOff; 282 ++xOff;
283 else 283 else
284 ++yOff; 284 ++yOff;
285 285
286 } 286 }
287 287
288 } 288 }
289 return ( yOff || xOff ); 289 return ( yOff || xOff );
290} 290}
291 291
292 292
293void KOAgendaItem::select(bool selected) 293void KOAgendaItem::select(bool selected)
294{ 294{
295 //qDebug("select %d %d",firstMultiItem(), nextMultiItem() ); 295 //qDebug("select %d %d",firstMultiItem(), nextMultiItem() );
296 if (mSelected == selected) return; 296 if (mSelected == selected) return;
297 mSelected = selected; 297 mSelected = selected;
298 if ( ! isVisible() ) 298 if ( ! isVisible() )
299 return; 299 return;
300 if ( firstMultiItem() ) 300 if ( firstMultiItem() )
301 firstMultiItem()->select( selected ); 301 firstMultiItem()->select( selected );
302 if ( !firstMultiItem() && nextMultiItem() ) { 302 if ( !firstMultiItem() && nextMultiItem() ) {
303 KOAgendaItem * placeItem = nextMultiItem(); 303 KOAgendaItem * placeItem = nextMultiItem();
304 while ( placeItem ) { 304 while ( placeItem ) {
305 placeItem->select( selected ); 305 placeItem->select( selected );
306 placeItem = placeItem->nextMultiItem(); 306 placeItem = placeItem->nextMultiItem();
307 } 307 }
308 } 308 }
309 globalFlagBlockAgendaItemUpdate = 0; 309 globalFlagBlockAgendaItemUpdate = 0;
310 paintMe( selected ); 310 paintMe( selected );
311 globalFlagBlockAgendaItemUpdate = 1; 311 globalFlagBlockAgendaItemUpdate = 1;
312 repaint( false ); 312 repaint( false );
313} 313}
314 314
315 315
316/* 316/*
317 The eventFilter has to filter the mouse events of the agenda item childs. The 317 The eventFilter has to filter the mouse events of the agenda item childs. The
318 events are fed into the event handling method of KOAgendaItem. This allows the 318 events are fed into the event handling method of KOAgendaItem. This allows the
319 KOAgenda to handle the KOAgendaItems by using an eventFilter. 319 KOAgenda to handle the KOAgendaItems by using an eventFilter.
320*/ 320*/
321bool KOAgendaItem::eventFilter ( QObject *object, QEvent *e ) 321bool KOAgendaItem::eventFilter ( QObject *object, QEvent *e )
322{ 322{
323 if (e->type() == QEvent::MouseButtonPress || 323 if (e->type() == QEvent::MouseButtonPress ||
324 e->type() == QEvent::MouseButtonDblClick || 324 e->type() == QEvent::MouseButtonDblClick ||
325 e->type() == QEvent::MouseButtonRelease || 325 e->type() == QEvent::MouseButtonRelease ||
326 e->type() == QEvent::MouseMove) { 326 e->type() == QEvent::MouseMove) {
327 QMouseEvent *me = (QMouseEvent *)e; 327 QMouseEvent *me = (QMouseEvent *)e;
328 QPoint itemPos = this->mapFromGlobal(((QWidget *)object)-> 328 QPoint itemPos = this->mapFromGlobal(((QWidget *)object)->
329 mapToGlobal(me->pos())); 329 mapToGlobal(me->pos()));
330 QMouseEvent returnEvent (e->type(),itemPos,me->button(),me->state()); 330 QMouseEvent returnEvent (e->type(),itemPos,me->button(),me->state());
331 return event(&returnEvent); 331 return event(&returnEvent);
332 } else { 332 } else {
333 return false; 333 return false;
334 } 334 }
335} 335}
336void KOAgendaItem::repaintMe( ) 336void KOAgendaItem::repaintMe( )
337{ 337{
338 paintMe ( mSelected ); 338 paintMe ( mSelected );
339} 339}
340void KOAgendaItem::paintMe( bool selected, QPainter* paint ) 340void KOAgendaItem::paintMe( bool selected, QPainter* paint )
341{ 341{
342 if ( globalFlagBlockAgendaItemUpdate && ! selected) 342 if ( globalFlagBlockAgendaItemUpdate && ! selected)
343 return; 343 return;
344 QPainter pa; 344 QPainter pa;
345 345
346 if ( mSelected ) { 346 if ( mSelected ) {
347 pa.begin( this ); 347 pa.begin( this );
348 } else { 348 } else {
349 if ( mAllDay ) 349 if ( mAllDay )
350 pa.begin( paintPixAllday() ); 350 pa.begin( paintPixAllday() );
351 else 351 else
352 pa.begin( paintPix() ); 352 pa.begin( paintPix() );
353 } 353 }
354 int x, yy, w, h; 354 int x, yy, w, h;
355 float nfh = 7.0; 355 float nfh = 7.0;
356 x = pos().x(); w = width(); h = height (); 356 x = pos().x(); w = width(); h = height ();
357 if ( mAllDay ) 357 if ( mAllDay )
358 yy = y(); 358 yy = y();
359 else 359 else
360 yy = mCellYTop * ( height() / cellHeight() ); 360 yy = mCellYTop * ( height() / cellHeight() );
361 if ( mSelected ) { 361 if ( mSelected ) {
362 pa.translate( -x, -yy ); 362 pa.translate( -x, -yy );
363 } 363 }
364 xPaintCoord= x; 364 xPaintCoord= x;
365 yPaintCoord = yy; 365 yPaintCoord = yy;
366 wPaintCoord = width(); 366 wPaintCoord = width();
367 hPaintCoord = height(); 367 hPaintCoord = height();
368 //qDebug("paintMe %s %d %d %d %d",incidence()->summary().latin1(), x, yy, width(), height()); 368 //qDebug("paintMe %s %d %d %d %d",incidence()->summary().latin1(), x, yy, width(), height());
369 if ( paint == 0 ) 369 if ( paint == 0 )
370 paint = &pa; 370 paint = &pa;
371 bool horLayout = ( w < h ); 371 bool horLayout = ( w < h );
372 int maxhei = mFontPixelSize+4; 372 int maxhei = mFontPixelSize+4;
373 if ( horLayout ) 373 if ( horLayout )
374 maxhei += AGENDA_ICON_SIZE -4; 374 maxhei += AGENDA_ICON_SIZE -4;
375 bool small = ( h < maxhei ); 375 bool small = ( h < maxhei );
376 if ( ! small ) 376 if ( ! small )
377 paint->setFont(KOPrefs::instance()->mAgendaViewFont); 377 paint->setFont(KOPrefs::instance()->mAgendaViewFont);
378 else { 378 else {
379 QFont f = KOPrefs::instance()->mAgendaViewFont; 379 QFont f = KOPrefs::instance()->mAgendaViewFont;
380 f.setBold( false ); 380 f.setBold( false );
381 int fh = f.pointSize(); 381 int fh = f.pointSize();
382 nfh = (((float)height())/(float)(mFontPixelSize+4))*fh; 382 nfh = (((float)height())/(float)(mFontPixelSize+4))*fh;
383 if ( nfh < 6 ) 383 if ( nfh < 6 )
384 nfh = 6; 384 nfh = 6;
385 f.setPointSize( nfh ); 385 f.setPointSize( nfh );
386 paint->setFont(f); 386 paint->setFont(f);
387 } 387 }
388 paint->fillRect ( x, yy, w, h, mBackgroundColor ); 388 paint->fillRect ( x, yy, w, h, mBackgroundColor );
389 static const QPixmap completedPxmp = SmallIcon("greenhook16"); 389 static const QPixmap completedPxmp = SmallIcon("greenhook16");
390 static const QPixmap overduePxmp = SmallIcon("redcross16"); 390 static const QPixmap overduePxmp = SmallIcon("redcross16");
391 if ( mIncidence->typeID() == todoID ) { 391 if ( mIncidence->typeID() == todoID ) {
392 Todo* tempTodo = static_cast<Todo*>(mIncidence); 392 Todo* tempTodo = static_cast<Todo*>(mIncidence);
393 int xx = pos().x()+(width()-completedPxmp.width()-3 ); 393 int xx = pos().x()+(width()-completedPxmp.width()-3 );
394 int yyy = yy+3; 394 int yyy = yy+3;
395 if ( tempTodo->isCompleted() ) 395 if ( tempTodo->isCompleted() )
396 paint->drawPixmap ( xx, yyy, completedPxmp ); 396 paint->drawPixmap ( xx, yyy, completedPxmp );
397 else { 397 else {
398 paint->drawPixmap ( xx, yyy, overduePxmp ); 398 paint->drawPixmap ( xx, yyy, overduePxmp );
399 399
400 } 400 }
401 } 401 }
402 bool addIcon = false; 402 bool addIcon = false;
403 if ( ! small || w > 3 * h || h > 3* w ) 403 if ( ! small || w > 3 * h || h > 3* w )
404 addIcon = updateIcons( paint, horLayout ); 404 addIcon = updateIcons( paint, horLayout );
405 405
406 //qDrawShadePanel (paint, x, yy, w, h, mColorGroup, selected , 2, 0); 406 //qDrawShadePanel (paint, x, yy, w, h, mColorGroup, selected , 2, 0);
407 qDrawWinPanel (paint, x, yy, w, h, mColorGroup, selected ,0); 407 qDrawWinPanel (paint, x, yy, w, h, mColorGroup, selected ,0);
408 //qDebug("draw rect %d %d %d %d ",x, yy, w, h ); 408 //qDebug("draw rect %d %d %d %d ",x, yy, w, h );
409 if ( ! small ) { 409 if ( ! small ) {
410 x += 3; yy += 3;w -= 6; h-= 5; 410 x += 3; yy += 3;w -= 6; h-= 5;
411 } else { 411 } else {
412 x += 2; yy += 1;w -= 4; h-= 4; 412 x += 2; yy += 1;w -= 4; h-= 4;
413 if ( nfh < 6.01 ) { 413 if ( nfh < 6.01 ) {
414 yy -= 2; 414 yy -= 2;
415 h += 4; 415 h += 4;
416 } 416 }
417 else 417 else
418 if ( nfh < h -2 ) 418 if ( nfh < h -2 )
419 ++yy; 419 ++yy;
420 } 420 }
421 int align; 421 int align;
422#ifndef DESKTOP_VERSION 422#ifndef DESKTOP_VERSION
423 align = ( AlignLeft|WordBreak|AlignTop); 423 align = ( AlignLeft|WordBreak|AlignTop);
424#else 424#else
425 align = ( AlignLeft|BreakAnywhere|WordBreak|AlignTop); 425 align = ( AlignLeft|BreakAnywhere|WordBreak|AlignTop);
426#endif 426#endif
427 if ( addIcon ) { 427 if ( addIcon ) {
428 if ( ! horLayout ) { 428 if ( ! horLayout ) {
429 x += AGENDA_ICON_SIZE+3; 429 x += AGENDA_ICON_SIZE+3;
430 w -= (AGENDA_ICON_SIZE+3); 430 w -= (AGENDA_ICON_SIZE+3);
431 } 431 }
432 else { 432 else {
433 yy+= AGENDA_ICON_SIZE+2; 433 yy+= AGENDA_ICON_SIZE+2;
434 h -=(AGENDA_ICON_SIZE+3); 434 h -=(AGENDA_ICON_SIZE+3);
435 } 435 }
436 } 436 }
437 if ( mWhiteText ) 437 if ( mWhiteText )
438 paint->setPen ( white); 438 paint->setPen ( white);
439 if ( x < 0 ) { 439 if ( x < 0 ) {
440 w = w+x-3; 440 w = w+x-3;
441 x = 3; 441 x = 3;
442 if ( !horLayout && addIcon ) 442 if ( !horLayout && addIcon )
443 x += AGENDA_ICON_SIZE+3; 443 x += AGENDA_ICON_SIZE+3;
444 if ( w > parentWidget()->width() ){ 444 if ( w > parentWidget()->width() ){
445 w = parentWidget()->width() - 6; 445 w = parentWidget()->width() - 6;
446#ifndef DESKTOP_VERSION 446#ifndef DESKTOP_VERSION
447 align = ( AlignHCenter|WordBreak|AlignTop); 447 align = ( AlignHCenter|WordBreak|AlignTop);
448#else 448#else
449 align = ( AlignHCenter|BreakAnywhere|WordBreak|AlignTop); 449 align = ( AlignHCenter|BreakAnywhere|WordBreak|AlignTop);
450#endif 450#endif
451 451
452 } 452 }
453 } 453 }
454 QRect dr; 454 QRect dr;
455 if ( w + x > parentWidget()->width() ) 455 if ( w + x > parentWidget()->width() )
456 w = parentWidget()->width()-x; 456 w = parentWidget()->width()-x;
457 paint->drawText ( x, yy, w, h, align, mDisplayedText, -1, &dr ); 457 paint->drawText ( x, yy, w, h, align, mDisplayedText, -1, &dr );
458 //qDebug("%d %d %d %d ", x, yy, w, h ); 458 //qDebug("%d %d %d %d ", x, yy, w, h );
459 if ( mIncidence->cancelled() ){ 459 if ( mIncidence->cancelled() ){
460 460
461 461
462 small = ( height() < 20 ); 462 small = ( height() < 20 );
463 463
464 if ( ! small ) { 464 if ( ! small ) {
465 QFontMetrics fm ( paint->font() ); 465 QFontMetrics fm ( paint->font() );
466 paint->drawLine(dr.left(), yy+fm.height()/2, dr.right()-2, yy+fm.height()/2); 466 paint->drawLine(dr.left(), yy+fm.height()/2, dr.right()-2, yy+fm.height()/2);
467 } 467 }
468 468
469 } 469 }
470 pa.end(); 470 pa.end();
471 471
472} 472}
473 473
474QPixmap * KOAgendaItem::paintPix() 474QPixmap * KOAgendaItem::paintPix()
475{ 475{
476 static QPixmap* mPaintPix = 0; 476 static QPixmap* mPaintPix = 0;
477 if ( ! mPaintPix ) { 477 if ( ! mPaintPix ) {
478 int w = QApplication::desktop()->width(); 478 int w = QApplication::desktop()->width();
479 int h = QApplication::desktop()->height(); 479 int h = QApplication::desktop()->height();
480 mPaintPix = new QPixmap(w,h); 480 mPaintPix = new QPixmap(w,h);
481 } 481 }
482 return mPaintPix ; 482 return mPaintPix ;
483} 483}
484QPixmap * KOAgendaItem::paintPixAllday() 484QPixmap * KOAgendaItem::paintPixAllday()
485{ 485{
486 static QPixmap* mPaintPixA = 0; 486 static QPixmap* mPaintPixA = 0;
487 if ( ! mPaintPixA ) { 487 if ( ! mPaintPixA ) {
488 int w = QApplication::desktop()->width(); 488 int w = QApplication::desktop()->width();
489 int h = QApplication::desktop()->height()/5; 489 int h = QApplication::desktop()->height()/5;
490 mPaintPixA = new QPixmap(w,h); 490 mPaintPixA = new QPixmap(w,h);
491 } 491 }
492 return mPaintPixA ; 492 return mPaintPixA ;
493} 493}
494 494
495void KOAgendaItem::repaintItem() 495void KOAgendaItem::repaintItem()
496{ 496{
497 globalFlagBlockAgendaItemPaint = 0; 497 globalFlagBlockAgendaItemPaint = 0;
498 globalFlagBlockAgenda = 0; 498 globalFlagBlockAgenda = 0;
499 repaint( false ); 499 repaint( false );
500} 500}
501void KOAgendaItem::paintEvent ( QPaintEvent *e ) 501void KOAgendaItem::paintEvent ( QPaintEvent *e )
502{ 502{
503 503
504 if ( globalFlagBlockAgendaItemPaint ) 504 if ( globalFlagBlockAgendaItemPaint )
505 return; 505 return;
506 if ( globalFlagBlockAgenda > 0 && globalFlagBlockAgenda < 5 ) 506 if ( globalFlagBlockAgenda > 0 && globalFlagBlockAgenda < 5 )
507 return; 507 return;
508 int yy; 508 int yy;
509 if ( mAllDay ) 509 if ( mAllDay )
510 yy = y(); 510 yy = y();
511 else 511 else
512 yy = mCellYTop * ( height() / cellHeight() ); 512 yy = mCellYTop * ( height() / cellHeight() );
513 int xx = x(); 513 int xx = x();
514 514
515 if ( xPaintCoord != xx || yPaintCoord != yy || 515 if ( xPaintCoord != xx || yPaintCoord != yy ||
516 wPaintCoord != width() || hPaintCoord != height()) { 516 wPaintCoord != width() || hPaintCoord != height()) {
517 xPaintCoord= xx; 517 xPaintCoord= xx;
518 yPaintCoord = yy; 518 yPaintCoord = yy;
519 wPaintCoord = width(); 519 wPaintCoord = width();
520 hPaintCoord = height(); 520 hPaintCoord = height();
521 globalFlagBlockAgendaItemUpdate = 0; 521 globalFlagBlockAgendaItemUpdate = 0;
522 paintMe( mSelected ); 522 paintMe( mSelected );
523 //qDebug("calling paintMe "); 523 //qDebug("calling paintMe ");
524 globalFlagBlockAgendaItemUpdate = 1; 524 globalFlagBlockAgendaItemUpdate = 1;
525 if ( mSelected ) 525 if ( mSelected )
526 return; 526 return;
527 } 527 }
528 int rx, ry, rw, rh; 528 int rx, ry, rw, rh;
529 rx = e->rect().x(); 529 rx = e->rect().x();
530 ry = e->rect().y(); 530 ry = e->rect().y();
531 rw = e->rect().width(); 531 rw = e->rect().width();
532 rh = e->rect().height(); 532 rh = e->rect().height();
533 //qDebug(" paintevent %s %d %d %d %d", mIncidence->summary().latin1(), x(), yy, width(), height()); 533 //qDebug(" paintevent %s %d %d %d %d", mIncidence->summary().latin1(), x(), yy, width(), height());
534 534
535 QPixmap* paintFrom ; 535 QPixmap* paintFrom ;
536 if ( mSelected ) { 536 if ( mSelected ) {
537 paintMe( mSelected ); 537 paintMe( mSelected );
538 return; 538 return;
539 } else { 539 } else {
540 if ( mAllDay ) 540 if ( mAllDay )
541 paintFrom = paintPixAllday(); 541 paintFrom = paintPixAllday();
542 else 542 else
543 paintFrom = paintPix(); 543 paintFrom = paintPix();
544 } 544 }
545 xx += rx; 545 xx += rx;
546 546
547 if ( xx < 0 ) { 547 if ( xx < 0 ) {
548 rw = rw + xx; 548 rw = rw + xx;
549 rx -= xx; 549 rx -= xx;
550 xx = 0; 550 xx = 0;
551 if ( rw <= 1 ) { 551 if ( rw <= 1 ) {
552 //qDebug("KOAgendaItem::Width1 <= 1 (%d). Returning. %s",rw,mDisplayedText.latin1()); 552 //qDebug("KOAgendaItem::Width1 <= 1 (%d). Returning. %s",rw,mDisplayedText.latin1());
553 return; 553 return;
554 } 554 }
555 } 555 }
556 if ( paintFrom->width() < xx+rw ) { 556 if ( paintFrom->width() < xx+rw ) {
557 rw = paintFrom->width() - xx; 557 rw = paintFrom->width() - xx;
558 if ( rw <= 1 ) { 558 if ( rw <= 1 ) {
559 //qDebug("KOAgendaItem::Width2 <= 1 (%d). Returning.%s ",rw,mDisplayedText.latin1() ); 559 //qDebug("KOAgendaItem::Width2 <= 1 (%d). Returning.%s ",rw,mDisplayedText.latin1() );
560 return; 560 return;
561 } 561 }
562 } 562 }
563 //qDebug("%d %d %d %d %d %d %d",rx, ry, paintFrom, xx ,yPaintCoord+ry, rw, rh); 563 //qDebug("%d %d %d %d %d %d %d",rx, ry, paintFrom, xx ,yPaintCoord+ry, rw, rh);
564 bitBlt (this, rx, ry, paintFrom, xx ,yPaintCoord+ry, rw, rh ,CopyROP); 564 bitBlt (this, rx, ry, paintFrom, xx ,yPaintCoord+ry, rw, rh ,CopyROP);
565} 565}
566void KOAgendaItem::computeText() 566void KOAgendaItem::computeText()
567{ 567{
568 mDisplayedText = mIncidence->summary(); 568 mDisplayedText = mIncidence->summary();
569 if ( (mIncidence->typeID() == todoID ) ) { 569 if ( (mIncidence->typeID() == todoID ) ) {
570 if ( static_cast<Todo*>(mIncidence)->hasDueDate() ) { 570 if ( static_cast<Todo*>(mIncidence)->hasDueDate() ) {
571 if ( static_cast<Todo*>(mIncidence)->dtDue().date() < QDate::currentDate() ) 571 if ( static_cast<Todo*>(mIncidence)->dtDue().date() < QDate::currentDate() )
572 mDisplayedText += i18n(" (") +KGlobal::locale()->formatDate((static_cast<Todo*>(mIncidence))->dtDue().date(), true)+")"; 572 mDisplayedText += i18n(" (") +KGlobal::locale()->formatDate((static_cast<Todo*>(mIncidence))->dtDue().date(), true)+")";
573 else if ( !(mIncidence->doesFloat())) 573 else if ( !(mIncidence->doesFloat()))
574 mDisplayedText += i18n(" (") +KGlobal::locale()->formatTime((static_cast<Todo*>(mIncidence))->dtDue().time())+")"; 574 mDisplayedText += i18n(" (") +KGlobal::locale()->formatTime((static_cast<Todo*>(mIncidence))->dtDue().time())+")";
575 } 575 }
576 } else { 576 } else {
577 if ( !(mIncidence->doesFloat()) && KOPrefs::instance()->mShowTimeInAgenda) 577 if ( !(mIncidence->doesFloat()) && KOPrefs::instance()->mShowTimeInAgenda)
578 mDisplayedText += ": " +KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtStart().time()) + " - " + KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtEnd().time()) ; 578 mDisplayedText += ": " +KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtStart().time()) + " - " + KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtEnd().time()) ;
579 579
580 if ( mAllDay ) { 580 if ( mAllDay ) {
581 if ( mIncidence->dtStart().date().addDays(3) < mIncidence->dtEnd().date() ) { 581 if ( mIncidence->dtStart().date().addDays(3) < mIncidence->dtEnd().date() ) {
582 if ( mIncidence->doesRecur() ) { 582 if ( mIncidence->doesRecur() ) {
583 mDisplayedText += " (" + mIncidence->recurrence()->recurrenceText() + ")"; 583 mDisplayedText += " (" + mIncidence->recurrence()->recurrenceText() + ")";
584 } else { 584 } else {
585 mDisplayedText += ": " +KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtStart().date(), true) + " - " + KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtEnd().date(), true) ; 585 mDisplayedText += ": " +KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtStart().date(), true) + " - " + KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtEnd().date(), true) ;
586 } 586 }
587 } 587 }
588 } 588 }
589 } 589 }
590 590
591 if ( !mIncidence->location().isEmpty() ) { 591 if ( !mIncidence->location().isEmpty() ) {
592 if ( mAllDay ) 592 if ( mAllDay )
593 mDisplayedText += " ("; 593 mDisplayedText += " (";
594 else 594 else
595 mDisplayedText += "\n("; 595 mDisplayedText += "\n(";
596 mDisplayedText += mIncidence->location() +")"; 596 mDisplayedText += mIncidence->location() +")";
597 } 597 }
598#ifdef DESKTOP_VERSION 598#ifdef DESKTOP_VERSION
599 QString tipText = mIncidence->summary(); 599 QString tipText = mIncidence->summary();
600 if ( !mIncidence->doesFloat() ) { 600 if ( !mIncidence->doesFloat() ) {
601 if ( mIncidence->typeID() == eventID ) { 601 if ( mIncidence->typeID() == eventID ) {
602 if ( (static_cast<Event*>(mIncidence))->isMultiDay() ) { 602 if ( (static_cast<Event*>(mIncidence))->isMultiDay() ) {
603 tipText += "\n"+i18n("From: ")+mIncidence->dtStartStr(); 603 tipText += "\n"+i18n("From: ")+mIncidence->dtStartStr();
604 tipText += "\n"+i18n("To: ")+(static_cast<Event*>(mIncidence))->dtEndStr(); 604 tipText += "\n"+i18n("To: ")+(static_cast<Event*>(mIncidence))->dtEndStr();
605 } 605 }
606 else { 606 else {
607 tipText += "\n"+i18n("Time: ")+mIncidence->dtStartTimeStr(); 607 tipText += "\n"+i18n("Time: ")+mIncidence->dtStartTimeStr();
608 tipText += " - "+(static_cast<Event*>(mIncidence))->dtEndTimeStr(); 608 tipText += " - "+(static_cast<Event*>(mIncidence))->dtEndTimeStr();
609 } 609 }
610 } 610 }
611 else if ( mIncidence->typeID() == todoID ) { 611 else if ( mIncidence->typeID() == todoID ) {
612 if (mIncidence->hasStartDate()) 612 if (mIncidence->hasStartDate())
613 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartStr(); 613 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartStr();
614 if (((Todo*)mIncidence)->hasDueDate()) 614 if (((Todo*)mIncidence)->hasDueDate())
615 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueStr(); 615 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueStr();
616 } 616 }
617 } else if ( mIncidence->typeID() == todoID ) { 617 } else if ( mIncidence->typeID() == todoID ) {
618 if (mIncidence->hasStartDate()) 618 if (mIncidence->hasStartDate())
619 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartDateStr(); 619 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartDateStr();
620 if (((Todo*)mIncidence)->hasDueDate()) 620 if (((Todo*)mIncidence)->hasDueDate())
621 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueDateStr(); 621 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueDateStr();
622 } 622 }
623 623
624 if (!mIncidence->location().isEmpty()) { 624 if (!mIncidence->location().isEmpty()) {
625 tipText += "\n"+i18n("Location: ")+mIncidence->location(); 625 tipText += "\n"+i18n("Location: ")+mIncidence->location();
626 } 626 }
627 QToolTip::add(this,tipText,toolTipGroup(),""); 627 QToolTip::add(this,tipText,toolTipGroup(),"");
628#endif 628#endif
629} 629}
630void KOAgendaItem::updateItem() 630void KOAgendaItem::updateItem()
631{ 631{
632 computeText(); 632 computeText();
633 633
634 //qDebug("KOAgendaItem:: updateItem() %s %d %d ",incidence()->summary().latin1(), x(), y()); 634 //qDebug("KOAgendaItem:: updateItem() %s %d %d ",incidence()->summary().latin1(), x(), y());
635 paintMe( mSelected ); 635 paintMe( mSelected );
636 repaint( false); 636 repaint( false);
637} 637}
638 638
639void KOAgendaItem::resizeEvent ( QResizeEvent *ev ) 639void KOAgendaItem::resizeEvent ( QResizeEvent *ev )
640{ 640{
641 //qDebug("KOAgendaItem::resizeEvent %s ", mIncidence->summary().latin1()); 641 //qDebug("KOAgendaItem::resizeEvent %s ", mIncidence->summary().latin1());
642 paintMe( mSelected ); 642 paintMe( mSelected );
643 repaint( false ); 643 repaint( false );
644} 644}
645 645
646/* 646/*
647 Return height of item in units of agenda cells 647 Return height of item in units of agenda cells
648*/ 648*/
649int KOAgendaItem::cellHeight() 649int KOAgendaItem::cellHeight()
650{ 650{
651 int ret = mCellYBottom - mCellYTop + 1; 651 int ret = mCellYBottom - mCellYTop + 1;
652 if ( ret <= 0 ) { 652 if ( ret <= 0 ) {
653 ret = 1; 653 ret = 1;
654 mCellYBottom = 0; 654 mCellYBottom = 0;
655 mCellYTop = 0; 655 mCellYTop = 0;
656 } 656 }
657 return ret; 657 return ret;
658} 658}
659 659
660/* 660/*
661 Return height of item in units of agenda cells 661 Return height of item in units of agenda cells
662*/ 662*/
663int KOAgendaItem::cellWidth() 663int KOAgendaItem::cellWidth()
664{ 664{
665 return mCellXWidth - mCellX + 1; 665 return mCellXWidth - mCellX + 1;
666} 666}
667 667
668void KOAgendaItem::setItemDate(QDate qd) 668void KOAgendaItem::setItemDate(QDate qd)
669{ 669{
670 mDate = qd; 670 mDate = qd;
671} 671}
672 672
673void KOAgendaItem::setCellXY(int X, int YTop, int YBottom) 673void KOAgendaItem::setCellXY(int X, int YTop, int YBottom)
674{ 674{
675 mCellX = X; 675 mCellX = X;
676 mCellYTop = YTop; 676 mCellYTop = YTop;
677 mCellYBottom = YBottom; 677 mCellYBottom = YBottom;
678} 678}
679 679
680void KOAgendaItem::setCellXWidth(int xwidth) 680void KOAgendaItem::setCellXWidth(int xwidth)
681{ 681{
682 mCellXWidth = xwidth; 682 mCellXWidth = xwidth;
683} 683}
684 684
685void KOAgendaItem::setCellX(int XLeft, int XRight) 685void KOAgendaItem::setCellX(int XLeft, int XRight)
686{ 686{
687 mCellX = XLeft; 687 mCellX = XLeft;
688 mCellXWidth = XRight; 688 mCellXWidth = XRight;
689} 689}
690 690
691void KOAgendaItem::setCellY(int YTop, int YBottom) 691void KOAgendaItem::setCellY(int YTop, int YBottom)
692{ 692{
693 mCellYTop = YTop; 693 mCellYTop = YTop;
694 mCellYBottom = YBottom; 694 mCellYBottom = YBottom;
695} 695}
696 696
697void KOAgendaItem::setSubCell(int subCell) 697void KOAgendaItem::setSubCell(int subCell)
698{ 698{
699 mSubCell = subCell; 699 mSubCell = subCell;
700} 700}
701 701
702void KOAgendaItem::setSubCells(int subCells) 702void KOAgendaItem::setSubCells(int subCells)
703{ 703{
704 mSubCells = subCells; 704 mSubCells = subCells;
705} 705}
706 706
707void KOAgendaItem::setMultiItem(KOAgendaItem *first,KOAgendaItem *next, 707void KOAgendaItem::setMultiItem(KOAgendaItem *first,KOAgendaItem *next,
708 KOAgendaItem *last) 708 KOAgendaItem *last)
709{ 709{
710 mFirstMultiItem = first; 710 mFirstMultiItem = first;
711 mNextMultiItem = next; 711 mNextMultiItem = next;
712 mLastMultiItem = last; 712 mLastMultiItem = last;
713} 713}
714 714
715void KOAgendaItem::startMove() 715void KOAgendaItem::startMove()
716{ 716{
717 mStartCellX = mCellX; 717 mStartCellX = mCellX;
718 mStartCellXWidth = mCellXWidth; 718 mStartCellXWidth = mCellXWidth;
719 mStartCellYTop = mCellYTop; 719 mStartCellYTop = mCellYTop;
720 mStartCellYBottom = mCellYBottom; 720 mStartCellYBottom = mCellYBottom;
721} 721}
722 722
723void KOAgendaItem::resetMove() 723void KOAgendaItem::resetMove()
724{ 724{
725 mCellX = mStartCellX; 725 mCellX = mStartCellX;
726 mCellXWidth = mStartCellXWidth; 726 mCellXWidth = mStartCellXWidth;
727 mCellYTop = mStartCellYTop; 727 mCellYTop = mStartCellYTop;
728 mCellYBottom = mStartCellYBottom; 728 mCellYBottom = mStartCellYBottom;
729} 729}
730 730
731void KOAgendaItem::moveRelative(int dx, int dy) 731void KOAgendaItem::moveRelative(int dx, int dy)
732{ 732{
733 int newX = cellX() + dx; 733 int newX = cellX() + dx;
734 int newXWidth = cellXWidth() + dx; 734 int newXWidth = cellXWidth() + dx;
735 int newYTop = cellYTop() + dy; 735 int newYTop = cellYTop() + dy;
736 int newYBottom = cellYBottom() + dy; 736 int newYBottom = cellYBottom() + dy;
737 setCellXY(newX,newYTop,newYBottom); 737 setCellXY(newX,newYTop,newYBottom);
738 setCellXWidth(newXWidth); 738 setCellXWidth(newXWidth);
739} 739}
740 740
741void KOAgendaItem::expandTop(int dy) 741void KOAgendaItem::expandTop(int dy)
742{ 742{
743 int newYTop = cellYTop() + dy; 743 int newYTop = cellYTop() + dy;
744 int newYBottom = cellYBottom(); 744 int newYBottom = cellYBottom();
745 if (newYTop > newYBottom) newYTop = newYBottom; 745 if (newYTop > newYBottom) newYTop = newYBottom;
746 setCellY(newYTop, newYBottom); 746 setCellY(newYTop, newYBottom);
747} 747}
748 748
749void KOAgendaItem::expandBottom(int dy) 749void KOAgendaItem::expandBottom(int dy)
750{ 750{
751 int newYTop = cellYTop(); 751 int newYTop = cellYTop();
752 int newYBottom = cellYBottom() + dy; 752 int newYBottom = cellYBottom() + dy;
753 if (newYBottom < newYTop) newYBottom = newYTop; 753 if (newYBottom < newYTop) newYBottom = newYTop;
754 setCellY(newYTop, newYBottom); 754 setCellY(newYTop, newYBottom);
755} 755}
756 756
757void KOAgendaItem::expandLeft(int dx) 757void KOAgendaItem::expandLeft(int dx)
758{ 758{
759 int newX = cellX() + dx; 759 int newX = cellX() + dx;
760 int newXWidth = cellXWidth(); 760 int newXWidth = cellXWidth();
761 if (newX > newXWidth) newX = newXWidth; 761 if (newX > newXWidth) newX = newXWidth;
762 setCellX(newX,newXWidth); 762 setCellX(newX,newXWidth);
763} 763}
764 764
765void KOAgendaItem::expandRight(int dx) 765void KOAgendaItem::expandRight(int dx)
766{ 766{
767 int newX = cellX(); 767 int newX = cellX();
768 int newXWidth = cellXWidth() + dx; 768 int newXWidth = cellXWidth() + dx;
769 if (newXWidth < newX) newXWidth = newX; 769 if (newXWidth < newX) newXWidth = newX;
770 setCellX(newX,newXWidth); 770 setCellX(newX,newXWidth);
771} 771}
772 772
773QToolTipGroup *KOAgendaItem::toolTipGroup() 773QToolTipGroup *KOAgendaItem::toolTipGroup()
774{ 774{
775 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); 775 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0);
776 return mToolTipGroup; 776 return mToolTipGroup;
777} 777}
778 778
779void KOAgendaItem::dragEnterEvent( QDragEnterEvent *e ) 779void KOAgendaItem::dragEnterEvent( QDragEnterEvent *e )
780{ 780{
781#ifndef KORG_NODND 781#ifndef KORG_NODND
782 if ( ICalDrag::canDecode( e ) || VCalDrag::canDecode( e ) || 782 if ( ICalDrag::canDecode( e ) || VCalDrag::canDecode( e ) ||
783 !QTextDrag::canDecode( e ) ) { 783 !QTextDrag::canDecode( e ) ) {
784 e->ignore(); 784 e->ignore();
785 return; 785 return;
786 } 786 }
787 e->accept(); 787 e->accept();
788#endif 788#endif
789} 789}
790 790
791void KOAgendaItem::dropEvent( QDropEvent *e ) 791void KOAgendaItem::dropEvent( QDropEvent *e )
792{ 792{
793#ifndef KORG_NODND 793#ifndef KORG_NODND
794 QString text; 794 QString text;
795 if(QTextDrag::decode(e,text)) 795 if(QTextDrag::decode(e,text))
796 { 796 {
797 kdDebug() << "Dropped : " << text << endl; 797 kdDebug() << "Dropped : " << text << endl;
798 QStringList emails = QStringList::split(",",text); 798 QStringList emails = QStringList::split(",",text);
799 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) { 799 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
800 kdDebug() << " Email: " << (*it) << endl; 800 kdDebug() << " Email: " << (*it) << endl;
801 int pos = (*it).find("<"); 801 int pos = (*it).find("<");
802 QString name = (*it).left(pos); 802 QString name = (*it).left(pos);
803 QString email = (*it).mid(pos); 803 QString email = (*it).mid(pos);
804 if (!email.isEmpty()) { 804 if (!email.isEmpty()) {
805 mIncidence->addAttendee(new Attendee(name,email)); 805 mIncidence->addAttendee(new Attendee(name,email));
806 } 806 }
807 } 807 }
808 } 808 }
809#endif 809#endif
810} 810}
811 811
812 812
813QPtrList<KOAgendaItem> KOAgendaItem::conflictItems() 813QPtrList<KOAgendaItem> KOAgendaItem::conflictItems()
814{ 814{
815 return mConflictItems; 815 return mConflictItems;
816} 816}
817 817
818void KOAgendaItem::setConflictItems(QPtrList<KOAgendaItem> ci) 818void KOAgendaItem::setConflictItems(QPtrList<KOAgendaItem> ci)
819{ 819{
820 mConflictItems = ci; 820 mConflictItems = ci;
821 KOAgendaItem *item; 821 KOAgendaItem *item;
822 for ( item=mConflictItems.first(); item != 0; 822 for ( item=mConflictItems.first(); item != 0;
823 item=mConflictItems.next() ) { 823 item=mConflictItems.next() ) {
824 item->addConflictItem(this); 824 item->addConflictItem(this);
825 } 825 }
826} 826}
827 827
828void KOAgendaItem::addConflictItem(KOAgendaItem *ci) 828void KOAgendaItem::addConflictItem(KOAgendaItem *ci)
829{ 829{
830 if (mConflictItems.find(ci)<0) 830 if (mConflictItems.find(ci)<0)
831 mConflictItems.append(ci); 831 mConflictItems.append(ci);
832} 832}
833 833
834bool KOAgendaItem::checkLayout() 834bool KOAgendaItem::checkLayout()
835{ 835{
836 if ( !mConflictItems.count() ) 836 if ( !mConflictItems.count() )
837 return true; 837 return true;
838 int max = 0; 838 int max = 0;
839 KOAgendaItem *item; 839 KOAgendaItem *item;
840 for ( item=mConflictItems.first(); item != 0; 840 for ( item=mConflictItems.first(); item != 0;
841 item=mConflictItems.next() ) { 841 item=mConflictItems.next() ) {
842 if ( item->subCells() > max ) 842 if ( item->subCells() > max )
843 max = item->subCells(); 843 max = item->subCells();
844 } 844 }
845 if ( max > subCells() ) { 845 if ( max > subCells() ) {
846 setSubCells( max ); 846 setSubCells( max );
847 return false; 847 return false;
848 } 848 }
849 return true; 849 return true;
850} 850}
diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp
index a01323a..04f30bb 100644
--- a/korganizer/koagendaview.cpp
+++ b/korganizer/koagendaview.cpp
@@ -1,1690 +1,1690 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qhbox.h> 24#include <qhbox.h>
25#include <qvbox.h> 25#include <qvbox.h>
26#include <qlabel.h> 26#include <qlabel.h>
27#include <qframe.h> 27#include <qframe.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#ifndef KORG_NOSPLITTER 29#ifndef KORG_NOSPLITTER
30#include <qsplitter.h> 30#include <qsplitter.h>
31#endif 31#endif
32#include <qfont.h> 32#include <qfont.h>
33#include <qfontmetrics.h> 33#include <qfontmetrics.h>
34#include <qpopupmenu.h> 34#include <qpopupmenu.h>
35#include <qtooltip.h> 35#include <qtooltip.h>
36#include <qpainter.h> 36#include <qpainter.h>
37#include <qpushbutton.h> 37#include <qpushbutton.h>
38#include <qapplication.h> 38#include <qapplication.h>
39 39
40#include <kapplication.h> 40#include <kapplication.h>
41#include <KDGanttMinimizeSplitter.h> 41#include <KDGanttMinimizeSplitter.h>
42#include <kdebug.h> 42#include <kdebug.h>
43#include <kstandarddirs.h> 43#include <kstandarddirs.h>
44#include <kiconloader.h> 44#include <kiconloader.h>
45#include <klocale.h> 45#include <klocale.h>
46#include <kconfig.h> 46#include <kconfig.h>
47#include <kglobal.h> 47#include <kglobal.h>
48#include "calendarview.h" 48#include "calendarview.h"
49#include "koviewmanager.h" 49#include "koviewmanager.h"
50 50
51#include <libkcal/calendar.h> 51#include <libkcal/calendar.h>
52#include <libkcal/icaldrag.h> 52#include <libkcal/icaldrag.h>
53#include <libkcal/dndfactory.h> 53#include <libkcal/dndfactory.h>
54 54
55#include <kcalendarsystem.h> 55#include <kcalendarsystem.h>
56 56
57#include "koglobals.h" 57#include "koglobals.h"
58#ifndef KORG_NOPLUGINS 58#ifndef KORG_NOPLUGINS
59#include "kocore.h" 59#include "kocore.h"
60#endif 60#endif
61#include "koprefs.h" 61#include "koprefs.h"
62#include "koagenda.h" 62#include "koagenda.h"
63#include "koagendaitem.h" 63#include "koagendaitem.h"
64#ifndef KORG_NOPRINTER 64#ifndef KORG_NOPRINTER
65#include "calprinter.h" 65#include "calprinter.h"
66#endif 66#endif
67 67
68#include "koagendaview.h" 68#include "koagendaview.h"
69//#include "koagendaview.moc" 69//#include "koagendaview.moc"
70 70
71//extern bool globalFlagBlockPainting; 71//extern bool globalFlagBlockPainting;
72extern int globalFlagBlockAgenda; 72extern int globalFlagBlockAgenda;
73extern int globalFlagBlockStartup; 73extern int globalFlagBlockStartup;
74extern int globalFlagBlockAgendaItemPaint; 74extern int globalFlagBlockAgendaItemPaint;
75extern int globalFlagBlockAgendaItemUpdate; 75extern int globalFlagBlockAgendaItemUpdate;
76extern int globalFlagBlockLabel; 76extern int globalFlagBlockLabel;
77using namespace KOrg; 77using namespace KOrg;
78 78
79#define IDLETIMEOUT 45 79#define IDLETIMEOUT 45
80 80
81TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) : 81TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) :
82 QScrollView(parent,name,f) 82 QScrollView(parent,name,f)
83{ 83{
84 myPix.resize( 1, 1 ); 84 myPix.resize( 1, 1 );
85 mRows = rows; 85 mRows = rows;
86 86
87 mRedrawNeeded = true; 87 mRedrawNeeded = true;
88 setMinimumHeight( 20 ); 88 setMinimumHeight( 20 );
89 mCellHeight = KOPrefs::instance()->mHourSize*4; 89 mCellHeight = KOPrefs::instance()->mHourSize*4;
90 90
91 enableClipper(true); 91 enableClipper(true);
92 92
93 setHScrollBarMode(AlwaysOff); 93 setHScrollBarMode(AlwaysOff);
94 setVScrollBarMode(AlwaysOff); 94 setVScrollBarMode(AlwaysOff);
95 95
96 resizeContents(50,mRows * mCellHeight); 96 resizeContents(50,mRows * mCellHeight);
97 97
98 viewport()->setBackgroundMode( PaletteBackground ); 98 viewport()->setBackgroundMode( PaletteBackground );
99} 99}
100 100
101void TimeLabels::setCellHeight(int height) 101void TimeLabels::setCellHeight(int height)
102{ 102{
103 mCellHeight = height; 103 mCellHeight = height;
104} 104}
105 105
106/* 106/*
107 Optimization so that only the "dirty" portion of the scroll view 107 Optimization so that only the "dirty" portion of the scroll view
108 is redrawn. Unfortunately, this is not called by default paintEvent() method. 108 is redrawn. Unfortunately, this is not called by default paintEvent() method.
109*/ 109*/
110void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch) 110void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch)
111{ 111{
112 112
113 cx = contentsX() + frameWidth()*2; 113 cx = contentsX() + frameWidth()*2;
114 cw = contentsWidth() ; 114 cw = contentsWidth() ;
115 // end of workaround 115 // end of workaround
116 116
117 int cell = ((int)(cy/mCellHeight)); 117 int cell = ((int)(cy/mCellHeight));
118 int y = cell * mCellHeight; 118 int y = cell * mCellHeight;
119 QFontMetrics fm = fontMetrics(); 119 QFontMetrics fm = fontMetrics();
120 QString hour; 120 QString hour;
121 QString suffix = "am"; 121 QString suffix = "am";
122 int timeHeight = fm.ascent(); 122 int timeHeight = fm.ascent();
123 QFont nFont = font(); 123 QFont nFont = font();
124 p->setFont( font()); 124 p->setFont( font());
125 125
126 if (!KGlobal::locale()->use12Clock()) { 126 if (!KGlobal::locale()->use12Clock()) {
127 suffix = "00"; 127 suffix = "00";
128 } else 128 } else
129 if (cell > 11) suffix = "pm"; 129 if (cell > 11) suffix = "pm";
130 130
131 if ( timeHeight > mCellHeight ) { 131 if ( timeHeight > mCellHeight ) {
132 timeHeight = mCellHeight-1; 132 timeHeight = mCellHeight-1;
133 int pointS = nFont.pointSize(); 133 int pointS = nFont.pointSize();
134 while ( pointS > 4 ) { 134 while ( pointS > 4 ) {
135 nFont.setPointSize( pointS ); 135 nFont.setPointSize( pointS );
136 fm = QFontMetrics( nFont ); 136 fm = QFontMetrics( nFont );
137 if ( fm.ascent() < mCellHeight ) 137 if ( fm.ascent() < mCellHeight )
138 break; 138 break;
139 -- pointS; 139 -- pointS;
140 } 140 }
141 fm = QFontMetrics( nFont ); 141 fm = QFontMetrics( nFont );
142 timeHeight = fm.ascent(); 142 timeHeight = fm.ascent();
143 } 143 }
144 //timeHeight -= (timeHeight/4-2); 144 //timeHeight -= (timeHeight/4-2);
145 QFont sFont = nFont; 145 QFont sFont = nFont;
146 sFont.setPointSize( sFont.pointSize()/2 ); 146 sFont.setPointSize( sFont.pointSize()/2 );
147 QFontMetrics fmS( sFont ); 147 QFontMetrics fmS( sFont );
148 int sHei = fmS.ascent() ; 148 int sHei = fmS.ascent() ;
149 //sHei -= (sHei/4-2); 149 //sHei -= (sHei/4-2);
150 int startW = mMiniWidth - frameWidth()-2 ; 150 int startW = mMiniWidth - frameWidth()-2 ;
151 int tw2 = fmS.width(suffix); 151 int tw2 = fmS.width(suffix);
152 timeHeight = (timeHeight-1) /2 -1; 152 timeHeight = (timeHeight-1) /2 -1;
153 //testline 153 //testline
154 //p->drawLine(0,0,0,contentsHeight()); 154 //p->drawLine(0,0,0,contentsHeight());
155 while (y < cy + ch+mCellHeight) { 155 while (y < cy + ch+mCellHeight) {
156 p->drawLine(startW-tw2+1 ,y,cw+2,y); 156 p->drawLine(startW-tw2+1 ,y,cw+2,y);
157 hour.setNum(cell); 157 hour.setNum(cell);
158 // handle 24h and am/pm time formats 158 // handle 24h and am/pm time formats
159 if (KGlobal::locale()->use12Clock()) { 159 if (KGlobal::locale()->use12Clock()) {
160 if (cell == 12) suffix = "pm"; 160 if (cell == 12) suffix = "pm";
161 if (cell == 0) hour.setNum(12); 161 if (cell == 0) hour.setNum(12);
162 if (cell > 12) hour.setNum(cell - 12); 162 if (cell > 12) hour.setNum(cell - 12);
163 } 163 }
164 164
165 // center and draw the time label 165 // center and draw the time label
166 int timeWidth = fm.width(hour); 166 int timeWidth = fm.width(hour);
167 int offset = startW - timeWidth - tw2 -1 ; 167 int offset = startW - timeWidth - tw2 -1 ;
168 p->setFont( nFont ); 168 p->setFont( nFont );
169 p->drawText( offset, y+ timeHeight, hour); 169 p->drawText( offset, y+ timeHeight, hour);
170 p->setFont( sFont ); 170 p->setFont( sFont );
171 offset = startW - tw2; 171 offset = startW - tw2;
172 p->drawText( offset, y -1, suffix); 172 p->drawText( offset, y -1, suffix);
173 173
174 // increment indices 174 // increment indices
175 y += mCellHeight; 175 y += mCellHeight;
176 cell++; 176 cell++;
177 } 177 }
178 178
179 179
180 180
181 181
182} 182}
183 183
184/** 184/**
185 Calculates the minimum width. 185 Calculates the minimum width.
186*/ 186*/
187int TimeLabels::minimumWidth() const 187int TimeLabels::minimumWidth() const
188{ 188{
189 return mMiniWidth; 189 return mMiniWidth;
190} 190}
191 191
192/** updates widget's internal state */ 192/** updates widget's internal state */
193void TimeLabels::updateConfig() 193void TimeLabels::updateConfig()
194{ 194{
195 mRedrawNeeded = true; 195 mRedrawNeeded = true;
196 // set the font 196 // set the font
197 // config->setGroup("Fonts"); 197 // config->setGroup("Fonts");
198 // QFont font = config->readFontEntry("TimeBar Font"); 198 // QFont font = config->readFontEntry("TimeBar Font");
199 setFont(KOPrefs::instance()->mTimeBarFont); 199 setFont(KOPrefs::instance()->mTimeBarFont);
200 QString test = "20"; 200 QString test = "20";
201 if (KGlobal::locale()->use12Clock()) 201 if (KGlobal::locale()->use12Clock())
202 test = "12"; 202 test = "12";
203 mMiniWidth = fontMetrics().width(test); 203 mMiniWidth = fontMetrics().width(test);
204 if (KGlobal::locale()->use12Clock()) 204 if (KGlobal::locale()->use12Clock())
205 test = "pm"; 205 test = "pm";
206 else { 206 else {
207 test = "00"; 207 test = "00";
208 } 208 }
209 QFont sFont = font(); 209 QFont sFont = font();
210 sFont.setPointSize( sFont.pointSize()/2 ); 210 sFont.setPointSize( sFont.pointSize()/2 );
211 QFontMetrics fmS( sFont ); 211 QFontMetrics fmS( sFont );
212 mMiniWidth += fmS.width( test ) + frameWidth()*2+4 ; 212 mMiniWidth += fmS.width( test ) + frameWidth()*2+4 ;
213 // update geometry restrictions based on new settings 213 // update geometry restrictions based on new settings
214 setFixedWidth( mMiniWidth ); 214 setFixedWidth( mMiniWidth );
215 215
216 // update HourSize 216 // update HourSize
217 mCellHeight = KOPrefs::instance()->mHourSize*4; 217 mCellHeight = KOPrefs::instance()->mHourSize*4;
218 resizeContents(mMiniWidth,mRows * mCellHeight+1); 218 resizeContents(mMiniWidth,mRows * mCellHeight+1);
219} 219}
220 220
221/** update time label positions */ 221/** update time label positions */
222void TimeLabels::positionChanged() 222void TimeLabels::positionChanged()
223{ 223{
224 int adjustment = mAgenda->contentsY(); 224 int adjustment = mAgenda->contentsY();
225 setContentsPos(0, adjustment); 225 setContentsPos(0, adjustment);
226} 226}
227 227
228/** */ 228/** */
229void TimeLabels::setAgenda(KOAgenda* agenda) 229void TimeLabels::setAgenda(KOAgenda* agenda)
230{ 230{
231 mAgenda = agenda; 231 mAgenda = agenda;
232} 232}
233 233
234void TimeLabels::contentsMousePressEvent ( QMouseEvent * e) 234void TimeLabels::contentsMousePressEvent ( QMouseEvent * e)
235{ 235{
236 mMouseDownY = e->pos().y(); 236 mMouseDownY = e->pos().y();
237 mOrgCap = topLevelWidget()->caption(); 237 mOrgCap = topLevelWidget()->caption();
238} 238}
239 239
240void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e ) 240void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e )
241{ 241{
242 int diff = mMouseDownY - e->pos().y(); 242 int diff = mMouseDownY - e->pos().y();
243 if ( diff < 10 && diff > -10 ) 243 if ( diff < 10 && diff > -10 )
244 return; 244 return;
245 int tSize = KOPrefs::instance()->mHourSize + (diff/10) ; 245 int tSize = KOPrefs::instance()->mHourSize + (diff/10) ;
246 if ( tSize < 4 ) 246 if ( tSize < 4 )
247 tSize = 4; 247 tSize = 4;
248 if ( tSize > 22 ) 248 if ( tSize > 22 )
249 tSize = 22; 249 tSize = 22;
250 tSize = (tSize-2)/2; 250 tSize = (tSize-2)/2;
251 topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize)); 251 topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize));
252 252
253} 253}
254void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e ) 254void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e )
255{ 255{
256 topLevelWidget()->setCaption( mOrgCap ); 256 topLevelWidget()->setCaption( mOrgCap );
257 int diff = mMouseDownY - e->pos().y(); 257 int diff = mMouseDownY - e->pos().y();
258 if ( diff < 10 && diff > -10 ) 258 if ( diff < 10 && diff > -10 )
259 return; 259 return;
260 int tSize = KOPrefs::instance()->mHourSize + (diff/10); 260 int tSize = KOPrefs::instance()->mHourSize + (diff/10);
261 if ( tSize < 4 ) 261 if ( tSize < 4 )
262 tSize = 4; 262 tSize = 4;
263 if ( tSize > 22 ) 263 if ( tSize > 22 )
264 tSize = 22; 264 tSize = 22;
265 tSize = (tSize/2)*2; 265 tSize = (tSize/2)*2;
266 if ( tSize == KOPrefs::instance()->mHourSize ) 266 if ( tSize == KOPrefs::instance()->mHourSize )
267 return; 267 return;
268 KOPrefs::instance()->mHourSize = tSize; 268 KOPrefs::instance()->mHourSize = tSize;
269 emit scaleChanged(); 269 emit scaleChanged();
270} 270}
271 271
272/** This is called in response to repaint() */ 272/** This is called in response to repaint() */
273void TimeLabels::paintEvent(QPaintEvent*) 273void TimeLabels::paintEvent(QPaintEvent*)
274{ 274{
275 275
276 // kdDebug() << "paintevent..." << endl; 276 // kdDebug() << "paintevent..." << endl;
277 // this is another hack! 277 // this is another hack!
278 // QPainter painter(this); 278 // QPainter painter(this);
279 //QString c 279 //QString c
280 repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight()); 280 repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight());
281} 281}
282 282
283//////////////////////////////////////////////////////////////////////////// 283////////////////////////////////////////////////////////////////////////////
284 284
285EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name) 285EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name)
286 : QFrame(parent,name) 286 : QFrame(parent,name)
287{ 287{
288 mColumns = 1; 288 mColumns = 1;
289 mTopBox = 0; 289 mTopBox = 0;
290 mLocation = loc; 290 mLocation = loc;
291 mTopLayout = 0; 291 mTopLayout = 0;
292 mPaintWidget = 0; 292 mPaintWidget = 0;
293 mXOffset = 0; 293 mXOffset = 0;
294 if (mLocation == Top) mPixmap = SmallIcon("1uparrow"); 294 if (mLocation == Top) mPixmap = SmallIcon("1uparrow");
295 else mPixmap = SmallIcon("1downarrow"); 295 else mPixmap = SmallIcon("1downarrow");
296 mEnabled.resize(mColumns); 296 mEnabled.resize(mColumns);
297 mEnabled.fill( false ); 297 mEnabled.fill( false );
298 setMinimumHeight(mPixmap.height()); 298 setMinimumHeight(mPixmap.height());
299} 299}
300 300
301EventIndicator::~EventIndicator() 301EventIndicator::~EventIndicator()
302{ 302{
303} 303}
304 304
305void EventIndicator::drawContents(QPainter *p) 305void EventIndicator::drawContents(QPainter *p)
306{ 306{
307 307
308 // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl; 308 // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl;
309 KDGanttSplitterHandle* han = 0; 309 KDGanttSplitterHandle* han = 0;
310 if ( mPaintWidget ) 310 if ( mPaintWidget )
311 han = mPaintWidget->firstHandle(); 311 han = mPaintWidget->firstHandle();
312 if ( ! han ) { 312 if ( ! han ) {
313 int i; 313 int i;
314 for(i=0;i<mColumns;++i) { 314 for(i=0;i<mColumns;++i) {
315 if (mEnabled[i]) { 315 if (mEnabled[i]) {
316 int cellWidth = contentsRect().right()/mColumns; 316 int cellWidth = contentsRect().right()/mColumns;
317 int xOffset = KOGlobals::self()->reverseLayout() ? 317 int xOffset = KOGlobals::self()->reverseLayout() ?
318 (mColumns - 1 - i)*cellWidth + (cellWidth -mPixmap.width())/2 : 318 (mColumns - 1 - i)*cellWidth + (cellWidth -mPixmap.width())/2 :
319 i*cellWidth + (cellWidth -mPixmap.width()) /2; 319 i*cellWidth + (cellWidth -mPixmap.width()) /2;
320 p->drawPixmap(QPoint(1+xOffset,0),mPixmap); 320 p->drawPixmap(QPoint(1+xOffset,0),mPixmap);
321 } 321 }
322 } 322 }
323 } else { 323 } else {
324 han->repaint(); 324 han->repaint();
325 //mPaintWidget->setBackgroundColor( red ); 325 //mPaintWidget->setBackgroundColor( red );
326 326
327 QPainter pa( han ); 327 QPainter pa( han );
328 int i; 328 int i;
329 bool setColor = false; 329 bool setColor = false;
330 for(i=0;i<mColumns;++i) { 330 for(i=0;i<mColumns;++i) {
331 if (mEnabled[i]) { 331 if (mEnabled[i]) {
332 setColor = true; 332 setColor = true;
333 333
334 int cellWidth = contentsRect().right()/mColumns; 334 int cellWidth = contentsRect().right()/mColumns;
335 int xOffset = KOGlobals::self()->reverseLayout() ? 335 int xOffset = KOGlobals::self()->reverseLayout() ?
336 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 : 336 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 :
337 i*cellWidth + cellWidth/2 -mPixmap.width()/2; 337 i*cellWidth + cellWidth/2 -mPixmap.width()/2;
338 pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap); 338 pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap);
339 //qDebug("222draw pix %d ",xOffset ); 339 //qDebug("222draw pix %d ",xOffset );
340 340
341 } 341 }
342 342
343 } 343 }
344 pa.end(); 344 pa.end();
345 345
346 } 346 }
347} 347}
348 348
349void EventIndicator::setXOffset( int x ) 349void EventIndicator::setXOffset( int x )
350{ 350{
351 mXOffset = x; 351 mXOffset = x;
352} 352}
353void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w ) 353void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w )
354{ 354{
355 mPaintWidget = w; 355 mPaintWidget = w;
356 setMaximumHeight(0); 356 setMaximumHeight(0);
357 setMinimumHeight(0); 357 setMinimumHeight(0);
358} 358}
359void EventIndicator::changeColumns(int columns) 359void EventIndicator::changeColumns(int columns)
360{ 360{
361 mColumns = columns; 361 mColumns = columns;
362 mEnabled.resize(mColumns); 362 mEnabled.resize(mColumns);
363 363
364 update(); 364 update();
365} 365}
366 366
367void EventIndicator::enableColumn(int column, bool enable) 367void EventIndicator::enableColumn(int column, bool enable)
368{ 368{
369 mEnabled[column] = enable; 369 mEnabled[column] = enable;
370} 370}
371 371
372 372
373//////////////////////////////////////////////////////////////////////////// 373////////////////////////////////////////////////////////////////////////////
374//////////////////////////////////////////////////////////////////////////// 374////////////////////////////////////////////////////////////////////////////
375//////////////////////////////////////////////////////////////////////////// 375////////////////////////////////////////////////////////////////////////////
376 376
377KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) : 377KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) :
378 KOEventView (cal,parent,name) 378 KOEventView (cal,parent,name)
379{ 379{
380 mBlockUpdating = true; 380 mBlockUpdating = true;
381 mStartHour = 8; 381 mStartHour = 8;
382 mSelectedDates.append(QDate::currentDate()); 382 mSelectedDates.append(QDate::currentDate());
383 383
384 mLayoutDayLabels = 0; 384 mLayoutDayLabels = 0;
385 mDayLabelsFrame = 0; 385 mDayLabelsFrame = 0;
386 mDayLabels = 0; 386 mDayLabels = 0;
387 bool isRTL = KOGlobals::self()->reverseLayout(); 387 bool isRTL = KOGlobals::self()->reverseLayout();
388 QPixmap expandPix; 388 QPixmap expandPix;
389 if ( KOPrefs::instance()->mVerticalScreen ) { 389 if ( KOPrefs::instance()->mVerticalScreen ) {
390 expandPix = SmallIcon( "1updownarrow" ); 390 expandPix = SmallIcon( "1updownarrow" );
391 } else { 391 } else {
392 expandPix = SmallIcon("1leftrightarrow" ); 392 expandPix = SmallIcon("1leftrightarrow" );
393 } 393 }
394 394
395 QBoxLayout *topLayout = new QVBoxLayout(this); 395 QBoxLayout *topLayout = new QVBoxLayout(this);
396 396
397 // Create day name labels for agenda columns 397 // Create day name labels for agenda columns
398 // Create agenda splitter 398 // Create agenda splitter
399 399
400 mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this); 400 mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this);
401 mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 401 mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
402 topLayout->addWidget( mSplitterAgenda ); 402 topLayout->addWidget( mSplitterAgenda );
403 mAllDayFrame = new QHBox(mSplitterAgenda); 403 mAllDayFrame = new QHBox(mSplitterAgenda);
404 mAllDayFrame->setFocusPolicy(NoFocus); 404 mAllDayFrame->setFocusPolicy(NoFocus);
405 QWidget *agendaFrame = new QWidget(mSplitterAgenda); 405 QWidget *agendaFrame = new QWidget(mSplitterAgenda);
406 agendaFrame->setFocusPolicy(NoFocus); 406 agendaFrame->setFocusPolicy(NoFocus);
407 407
408 // Create all-day agenda widget 408 // Create all-day agenda widget
409 mDummyAllDayLeft = new QVBox( mAllDayFrame ); 409 mDummyAllDayLeft = new QVBox( mAllDayFrame );
410 410
411 mExpandButton = new QPushButton(mDummyAllDayLeft); 411 mExpandButton = new QPushButton(mDummyAllDayLeft);
412 mExpandButton->setPixmap( expandPix ); 412 mExpandButton->setPixmap( expandPix );
413 int widebut = mExpandButton->sizeHint().width()+4; 413 int widebut = mExpandButton->sizeHint().width()+4;
414 int heibut = mExpandButton->sizeHint().height()+4; 414 int heibut = mExpandButton->sizeHint().height()+4;
415 if ( heibut > widebut ) 415 if ( heibut > widebut )
416 widebut = heibut ; 416 widebut = heibut ;
417 417
418 //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, 418 //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed,
419 // QSizePolicy::Fixed ) ); 419 // QSizePolicy::Fixed ) );
420 mExpandButton->setFixedSize( widebut, widebut); 420 mExpandButton->setFixedSize( widebut, widebut);
421 connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) ); 421 connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) );
422 mExpandButton->setFocusPolicy(NoFocus); 422 mExpandButton->setFocusPolicy(NoFocus);
423 mAllDayAgenda = new KOAgenda(1,mAllDayFrame); 423 mAllDayAgenda = new KOAgenda(1,mAllDayFrame);
424 mAllDayAgenda->setFocusPolicy(NoFocus); 424 mAllDayAgenda->setFocusPolicy(NoFocus);
425 QLabel *dummyAllDayRight = new QLabel (mAllDayFrame); 425 QLabel *dummyAllDayRight = new QLabel (mAllDayFrame);
426 426
427 // Create event context menu for all day agenda 427 // Create event context menu for all day agenda
428 //mAllDayAgendaPopup = eventPopup(); 428 //mAllDayAgendaPopup = eventPopup();
429 429
430 // Create agenda frame 430 // Create agenda frame
431 QGridLayout *agendaLayout = new QGridLayout(agendaFrame,4,3); 431 QGridLayout *agendaLayout = new QGridLayout(agendaFrame,4,3);
432 // QHBox *agendaFrame = new QHBox(splitterAgenda); 432 // QHBox *agendaFrame = new QHBox(splitterAgenda);
433 433
434 // create event indicator bars 434 // create event indicator bars
435 mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame); 435 mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame);
436#ifndef DESKTOP_VERSION 436#ifndef DESKTOP_VERSION
437 mEventIndicatorTop->setPaintWidget( mSplitterAgenda ); 437 mEventIndicatorTop->setPaintWidget( mSplitterAgenda );
438#endif 438#endif
439 mDayLabelsFrame = new QHBox(agendaFrame); 439 mDayLabelsFrame = new QHBox(agendaFrame);
440 //topLayout->addWidget(mDayLabelsFrame); 440 //topLayout->addWidget(mDayLabelsFrame);
441 mDayLabels = new QFrame (mDayLabelsFrame); 441 mDayLabels = new QFrame (mDayLabelsFrame);
442 mLayoutDayLabels = new QHBoxLayout(mDayLabels); 442 mLayoutDayLabels = new QHBoxLayout(mDayLabels);
443 agendaLayout->addMultiCellWidget(mDayLabelsFrame ,0,0,0,2); 443 agendaLayout->addMultiCellWidget(mDayLabelsFrame ,0,0,0,2);
444 agendaLayout->addWidget(mEventIndicatorTop,1,1); 444 agendaLayout->addWidget(mEventIndicatorTop,1,1);
445 445
446 mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom, 446 mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom,
447 agendaFrame); 447 agendaFrame);
448 agendaLayout->addWidget(mEventIndicatorBottom,3,1); 448 agendaLayout->addWidget(mEventIndicatorBottom,3,1);
449 QWidget *dummyAgendaRight = new QWidget(agendaFrame); 449 QWidget *dummyAgendaRight = new QWidget(agendaFrame);
450 agendaLayout->addWidget(dummyAgendaRight,1,2); 450 agendaLayout->addWidget(dummyAgendaRight,1,2);
451 451
452 // Create time labels 452 // Create time labels
453 mTimeLabels = new TimeLabels(24,agendaFrame); 453 mTimeLabels = new TimeLabels(24,agendaFrame);
454 agendaLayout->addWidget(mTimeLabels,2,0); 454 agendaLayout->addWidget(mTimeLabels,2,0);
455 connect(mTimeLabels,SIGNAL( scaleChanged()), 455 connect(mTimeLabels,SIGNAL( scaleChanged()),
456 this,SLOT(updateConfig())); 456 this,SLOT(updateConfig()));
457 457
458 // Create agenda 458 // Create agenda
459 mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame); 459 mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame);
460 agendaLayout->addMultiCellWidget(mAgenda,2,2,1,2); 460 agendaLayout->addMultiCellWidget(mAgenda,2,2,1,2);
461 agendaLayout->setColStretch(1,1); 461 agendaLayout->setColStretch(1,1);
462 mAgenda->setFocusPolicy(NoFocus); 462 mAgenda->setFocusPolicy(NoFocus);
463 // Create event context menu for agenda 463 // Create event context menu for agenda
464 mAllAgendaPopup = eventPopup(); 464 mAllAgendaPopup = eventPopup();
465 465
466#if 0 466#if 0
467 mAllAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")), 467 mAllAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")),
468 i18n("Toggle Alarm"),mAgenda, 468 i18n("Toggle Alarm"),mAgenda,
469 SLOT(popupAlarm()),true); 469 SLOT(popupAlarm()),true);
470 470
471#endif 471#endif
472 connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), 472 connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)),
473 mAllAgendaPopup,SLOT(showIncidencePopup(Incidence *))); 473 mAllAgendaPopup,SLOT(showIncidencePopup(Incidence *)));
474 474
475 connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), 475 connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)),
476 mAllAgendaPopup,SLOT(showIncidencePopup(Incidence *))); 476 mAllAgendaPopup,SLOT(showIncidencePopup(Incidence *)));
477 477
478 connect(mAllAgendaPopup,SIGNAL(categoryChanged(Incidence *)), 478 connect(mAllAgendaPopup,SIGNAL(categoryChanged(Incidence *)),
479 this,SLOT(categoryChanged(Incidence *))); 479 this,SLOT(categoryChanged(Incidence *)));
480 480
481 481
482 mAgenda->setPopup( mAllAgendaPopup ); 482 mAgenda->setPopup( mAllAgendaPopup );
483 mAllDayAgenda->setPopup( mAllAgendaPopup ); 483 mAllDayAgenda->setPopup( mAllAgendaPopup );
484 // make connections between dependent widgets 484 // make connections between dependent widgets
485 mTimeLabels->setAgenda(mAgenda); 485 mTimeLabels->setAgenda(mAgenda);
486 486
487 // Update widgets to reflect user preferences 487 // Update widgets to reflect user preferences
488 // updateConfig(); 488 // updateConfig();
489 489
490 // createDayLabels(); 490 // createDayLabels();
491 491
492 // these blank widgets make the All Day Event box line up with the agenda 492 // these blank widgets make the All Day Event box line up with the agenda
493 dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); 493 dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
494 dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); 494 dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
495 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); 495 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
496 496
497 // Scrolling 497 // Scrolling
498 connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)), 498 connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)),
499 mTimeLabels, SLOT(positionChanged())); 499 mTimeLabels, SLOT(positionChanged()));
500 connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)), 500 connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)),
501 SLOT(setContentsPos(int))); 501 SLOT(setContentsPos(int)));
502 502
503 connect(mAgenda,SIGNAL(showDateView( int, int)),SLOT(slotShowDateView( int, int ))); 503 connect(mAgenda,SIGNAL(showDateView( int, int)),SLOT(slotShowDateView( int, int )));
504 connect(mAllDayAgenda,SIGNAL(showDateView( int, int )), SLOT(slotShowDateView( int, int ) )); 504 connect(mAllDayAgenda,SIGNAL(showDateView( int, int )), SLOT(slotShowDateView( int, int ) ));
505 505
506 // Create/Show/Edit/Delete Event 506 // Create/Show/Edit/Delete Event
507 connect(mAgenda,SIGNAL(newEventSignal(int,int)), 507 connect(mAgenda,SIGNAL(newEventSignal(int,int)),
508 SLOT(newEvent(int,int))); 508 SLOT(newEvent(int,int)));
509 connect(mAgenda,SIGNAL(newTodoSignal(int,int)), 509 connect(mAgenda,SIGNAL(newTodoSignal(int,int)),
510 SLOT(newTodo(int,int))); 510 SLOT(newTodo(int,int)));
511 connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)), 511 connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)),
512 SLOT(newEvent(int,int,int,int))); 512 SLOT(newEvent(int,int,int,int)));
513 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)), 513 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)),
514 SLOT(newEventAllDay(int,int))); 514 SLOT(newEventAllDay(int,int)));
515 connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)), 515 connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)),
516 SLOT(newTodoAllDay(int,int))); 516 SLOT(newTodoAllDay(int,int)));
517 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)), 517 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)),
518 SLOT(newEventAllDay(int,int))); 518 SLOT(newEventAllDay(int,int)));
519 connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), 519 connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
520 SLOT(newTimeSpanSelected(int,int,int,int))); 520 SLOT(newTimeSpanSelected(int,int,int,int)));
521 connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), 521 connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
522 SLOT(newTimeSpanSelectedAllDay(int,int,int,int))); 522 SLOT(newTimeSpanSelectedAllDay(int,int,int,int)));
523 connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); 523 connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
524 connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); 524 connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
525 525
526 connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)), 526 connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)),
527 SIGNAL(editIncidenceSignal(Incidence *))); 527 SIGNAL(editIncidenceSignal(Incidence *)));
528 connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)), 528 connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)),
529 SIGNAL(editIncidenceSignal(Incidence *))); 529 SIGNAL(editIncidenceSignal(Incidence *)));
530 connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)), 530 connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)),
531 SIGNAL(showIncidenceSignal(Incidence *))); 531 SIGNAL(showIncidenceSignal(Incidence *)));
532 connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)), 532 connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)),
533 SIGNAL(showIncidenceSignal(Incidence *))); 533 SIGNAL(showIncidenceSignal(Incidence *)));
534 connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), 534 connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)),
535 SIGNAL(deleteIncidenceSignal(Incidence *))); 535 SIGNAL(deleteIncidenceSignal(Incidence *)));
536 connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), 536 connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)),
537 SIGNAL(deleteIncidenceSignal(Incidence *))); 537 SIGNAL(deleteIncidenceSignal(Incidence *)));
538 538
539 connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), 539 connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )),
540 SLOT(updateEventDates(KOAgendaItem *, int ))); 540 SLOT(updateEventDates(KOAgendaItem *, int )));
541 connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), 541 connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )),
542 SLOT(updateEventDates(KOAgendaItem *, int))); 542 SLOT(updateEventDates(KOAgendaItem *, int)));
543 543
544 // event indicator update 544 // event indicator update
545 connect(mAgenda,SIGNAL(lowerYChanged(int)), 545 connect(mAgenda,SIGNAL(lowerYChanged(int)),
546 SLOT(updateEventIndicatorTop(int))); 546 SLOT(updateEventIndicatorTop(int)));
547 connect(mAgenda,SIGNAL(upperYChanged(int)), 547 connect(mAgenda,SIGNAL(upperYChanged(int)),
548 SLOT(updateEventIndicatorBottom(int))); 548 SLOT(updateEventIndicatorBottom(int)));
549 // drag signals 549 // drag signals
550 /* 550 /*
551 connect(mAgenda,SIGNAL(startDragSignal(Event *)), 551 connect(mAgenda,SIGNAL(startDragSignal(Event *)),
552 SLOT(startDrag(Event *))); 552 SLOT(startDrag(Event *)));
553 connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)), 553 connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)),
554 SLOT(startDrag(Event *))); 554 SLOT(startDrag(Event *)));
555 */ 555 */
556 // synchronize selections 556 // synchronize selections
557 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 557 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
558 mAllDayAgenda, SLOT( deselectItem() ) ); 558 mAllDayAgenda, SLOT( deselectItem() ) );
559 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 559 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
560 mAgenda, SLOT( deselectItem() ) ); 560 mAgenda, SLOT( deselectItem() ) );
561 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 561 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
562 SIGNAL( incidenceSelected( Incidence * ) ) ); 562 SIGNAL( incidenceSelected( Incidence * ) ) );
563 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 563 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
564 SIGNAL( incidenceSelected( Incidence * ) ) ); 564 SIGNAL( incidenceSelected( Incidence * ) ) );
565 connect( mAgenda, SIGNAL( resizedSignal() ), 565 connect( mAgenda, SIGNAL( resizedSignal() ),
566 SLOT( updateConfig( ) ) ); 566 SLOT( updateConfig( ) ) );
567 connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ), 567 connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ),
568 SLOT( addToCalSlot(Incidence *, Incidence * ) ) ); 568 SLOT( addToCalSlot(Incidence *, Incidence * ) ) );
569 connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ), 569 connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ),
570 SLOT( addToCalSlot(Incidence * , Incidence *) ) ); 570 SLOT( addToCalSlot(Incidence * , Incidence *) ) );
571 // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); 571 // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) );
572 //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); 572 //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) );
573 573
574 connect( mAllDayAgenda, SIGNAL( signalClearSelection() ),mAgenda, SLOT( slotClearSelection()) ); 574 connect( mAllDayAgenda, SIGNAL( signalClearSelection() ),mAgenda, SLOT( slotClearSelection()) );
575 connect( mAgenda, SIGNAL( signalClearSelection() ),mAllDayAgenda, SLOT( slotClearSelection()) ); 575 connect( mAgenda, SIGNAL( signalClearSelection() ),mAllDayAgenda, SLOT( slotClearSelection()) );
576#ifndef DESKTOP_VERSION 576#ifndef DESKTOP_VERSION
577 connect( mAllDayAgenda, SIGNAL( updateViewSignal() ),this, SLOT( fillAgenda()) ); 577 connect( mAllDayAgenda, SIGNAL( updateViewSignal() ),this, SLOT( fillAgenda()) );
578 connect( mAgenda, SIGNAL( updateViewSignal() ), this, SLOT( fillAgenda()) ); 578 connect( mAgenda, SIGNAL( updateViewSignal() ), this, SLOT( fillAgenda()) );
579 connect( mAllDayAgenda, SIGNAL( sendPing() ),this, SLOT( startIdleTimeout()) ); 579 connect( mAllDayAgenda, SIGNAL( sendPing() ),this, SLOT( startIdleTimeout()) );
580 connect( mAgenda, SIGNAL( sendPing() ), this, SLOT( startIdleTimeout()) ); 580 connect( mAgenda, SIGNAL( sendPing() ), this, SLOT( startIdleTimeout()) );
581 mIdleTimer = new QTimer ( this );; 581 mIdleTimer = new QTimer ( this );;
582 connect(mIdleTimer,SIGNAL(timeout()),SLOT(slotIdleTimeout())); 582 connect(mIdleTimer,SIGNAL(timeout()),SLOT(slotIdleTimeout()));
583#endif 583#endif
584} 584}
585void KOAgendaView::startIdleTimeout() 585void KOAgendaView::startIdleTimeout()
586{ 586{
587#ifndef DESKTOP_VERSION 587#ifndef DESKTOP_VERSION
588 mIdleStart = QDateTime::currentDateTime(); 588 mIdleStart = QDateTime::currentDateTime();
589 mIdleTimer->start( IDLETIMEOUT * 1000 ); 589 mIdleTimer->start( IDLETIMEOUT * 1000 );
590#endif 590#endif
591} 591}
592void KOAgendaView::slotIdleTimeout() 592void KOAgendaView::slotIdleTimeout()
593{ 593{
594#ifndef DESKTOP_VERSION 594#ifndef DESKTOP_VERSION
595 //qDebug("SECS TO %d ",mIdleStart.secsTo( QDateTime::currentDateTime() ) ); 595 //qDebug("SECS TO %d ",mIdleStart.secsTo( QDateTime::currentDateTime() ) );
596 int secsfromstart = mIdleStart.secsTo( QDateTime::currentDateTime() ); 596 int secsfromstart = mIdleStart.secsTo( QDateTime::currentDateTime() );
597 mIdleTimer->stop(); 597 mIdleTimer->stop();
598 bool isActice = topLevelWidget()->isActiveWindow(); 598 bool isActice = topLevelWidget()->isActiveWindow();
599 //qDebug("KO: Active Window %d %d", isActice, isVisible()); 599 //qDebug("KO: Active Window %d %d", isActice, isVisible());
600 // we do nothing if we wake up from a suspend 600 // we do nothing if we wake up from a suspend
601 if ( secsfromstart > IDLETIMEOUT + 30 && isActice ) { 601 if ( secsfromstart > IDLETIMEOUT + 30 && isActice ) {
602 qDebug("KO: Wakeup from suspend "); 602 qDebug("KO: Wakeup from suspend ");
603 startIdleTimeout(); 603 startIdleTimeout();
604 return; 604 return;
605 } 605 }
606 qDebug("KO: Downsizing Pixmaps "); 606 qDebug("KO: Downsizing Pixmaps ");
607 mAgenda->shrinkPixmap(); 607 mAgenda->shrinkPixmap();
608 mAllDayAgenda->shrinkPixmap(); 608 mAllDayAgenda->shrinkPixmap();
609 KOAgendaItem::paintPix()->resize( 20,20); 609 KOAgendaItem::paintPix()->resize( 20,20);
610 KOAgendaItem::paintPixAllday()->resize( 20,20); 610 KOAgendaItem::paintPixAllday()->resize( 20,20);
611#endif 611#endif
612 612
613} 613}
614void KOAgendaView::toggleAllDay() 614void KOAgendaView::toggleAllDay()
615{ 615{
616 if ( mSplitterAgenda->firstHandle() ) 616 if ( mSplitterAgenda->firstHandle() )
617 mSplitterAgenda->firstHandle()->toggle(); 617 mSplitterAgenda->firstHandle()->toggle();
618} 618}
619void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld ) 619void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld )
620{ 620{
621 calendar()->addIncidence( inc ); 621 calendar()->addIncidence( inc );
622 622
623 if ( incOld ) { 623 if ( incOld ) {
624 if ( incOld->typeID() == todoID ) 624 if ( incOld->typeID() == todoID )
625 emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED ); 625 emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED );
626 else 626 else
627 emit incidenceChanged(incOld, KOGlobals::EVENTEDITED); 627 emit incidenceChanged(incOld, KOGlobals::EVENTEDITED);
628 } 628 }
629 629
630} 630}
631void KOAgendaView::categoryChanged(Incidence * inc) 631void KOAgendaView::categoryChanged(Incidence * inc)
632{ 632{
633 mAgenda->categoryChanged( inc ); 633 mAgenda->categoryChanged( inc );
634 mAllDayAgenda->categoryChanged( inc ); 634 mAllDayAgenda->categoryChanged( inc );
635} 635}
636KOAgendaView::~KOAgendaView() 636KOAgendaView::~KOAgendaView()
637{ 637{
638 delete mAllAgendaPopup; 638 delete mAllAgendaPopup;
639 //delete mAllDayAgendaPopup; 639 //delete mAllDayAgendaPopup;
640 delete KOAgendaItem::paintPix(); 640 delete KOAgendaItem::paintPix();
641 delete KOAgendaItem::paintPixAllday(); 641 delete KOAgendaItem::paintPixAllday();
642} 642}
643void KOAgendaView::resizeEvent( QResizeEvent* e ) 643void KOAgendaView::resizeEvent( QResizeEvent* e )
644{ 644{
645 //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width()); 645 //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width());
646 bool uc = false; 646 bool uc = false;
647 int ow = e->oldSize().width(); 647 int ow = e->oldSize().width();
648 int oh = e->oldSize().height(); 648 int oh = e->oldSize().height();
649 int w = e->size().width(); 649 int w = e->size().width();
650 int h = e->size().height(); 650 int h = e->size().height();
651 if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) { 651 if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) {
652 if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda ) 652 if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda )
653 uc = true; 653 uc = true;
654 //qDebug("view changed %d %d %d %d ", ow, oh , w , h); 654 //qDebug("view changed %d %d %d %d ", ow, oh , w , h);
655 } 655 }
656 mUpcomingWidth = e->size().width() ; 656 mUpcomingWidth = e->size().width() ;
657 if ( mBlockUpdating || uc ) { 657 if ( mBlockUpdating || uc ) {
658 mBlockUpdating = false; 658 mBlockUpdating = false;
659 //mAgenda->setMinimumSize(800 , 600 ); 659 //mAgenda->setMinimumSize(800 , 600 );
660 //qDebug("mAgenda->resize+++++++++++++++ "); 660 //qDebug("mAgenda->resize+++++++++++++++ ");
661 updateConfig(); 661 updateConfig();
662 //qDebug("KOAgendaView::Updating now possible "); 662 //qDebug("KOAgendaView::Updating now possible ");
663 } else 663 } else
664 createDayLabels(); 664 createDayLabels();
665 //qDebug("resizeEvent end "); 665 //qDebug("resizeEvent end ");
666 666
667} 667}
668void KOAgendaView::slotDaylabelClicked( int num ) 668void KOAgendaView::slotDaylabelClicked( int num )
669{ 669{
670 670
671 QDate firstDate = mSelectedDates.first(); 671 QDate firstDate = mSelectedDates.first();
672 if ( num == -1 ) 672 if ( num == -1 )
673 emit showDateView( 6, firstDate ); 673 emit showDateView( 6, firstDate );
674 else if (num >= 0 ) { 674 else if (num >= 0 ) {
675 if ( mSelectedDates.count() == 1) 675 if ( mSelectedDates.count() == 1)
676 emit showDateView( 9, firstDate.addDays( num ) ); 676 emit showDateView( 9, firstDate.addDays( num ) );
677 else 677 else
678 emit showDateView( 3, firstDate.addDays( num ) ); 678 emit showDateView( 3, firstDate.addDays( num ) );
679 } 679 }
680 else 680 else
681 showDateView( 10, firstDate.addDays(1) ); 681 showDateView( 10, firstDate.addDays(1) );
682} 682}
683 683
684KOAgendaButton* KOAgendaView::getNewDaylabel() 684KOAgendaButton* KOAgendaView::getNewDaylabel()
685{ 685{
686 686
687 KOAgendaButton * dayLabel = new KOAgendaButton(mDayLabels); 687 KOAgendaButton * dayLabel = new KOAgendaButton(mDayLabels);
688 connect( dayLabel, SIGNAL( numClicked(int) ), this, SLOT ( slotDaylabelClicked(int) ) ); 688 connect( dayLabel, SIGNAL( numClicked(int) ), this, SLOT ( slotDaylabelClicked(int) ) );
689 mDayLabelsList.append( dayLabel ); 689 mDayLabelsList.append( dayLabel );
690 mLayoutDayLabels->addWidget(dayLabel); 690 mLayoutDayLabels->addWidget(dayLabel);
691 return dayLabel ; 691 return dayLabel ;
692} 692}
693 693
694void KOAgendaView::createDayLabels() 694void KOAgendaView::createDayLabels()
695{ 695{
696 696
697 if ( mBlockUpdating || globalFlagBlockLabel == 1) { 697 if ( mBlockUpdating || globalFlagBlockLabel == 1) {
698 // qDebug(" KOAgendaView::createDayLabels() blocked "); 698 // qDebug(" KOAgendaView::createDayLabels() blocked ");
699 return; 699 return;
700 700
701 } 701 }
702 int newHight; 702 int newHight;
703 if ( !mSelectedDates.count()) 703 if ( !mSelectedDates.count())
704 return; 704 return;
705 705
706 // ### Before deleting and recreating we could check if mSelectedDates changed... 706 // ### Before deleting and recreating we could check if mSelectedDates changed...
707 // It would remove some flickering and gain speed (since this is called by 707 // It would remove some flickering and gain speed (since this is called by
708 // each updateView() call) 708 // each updateView() call)
709 709
710 int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - mAgenda->frameWidth()*2; 710 int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - mAgenda->frameWidth()*2;
711 mDayLabelsFrame->setMaximumWidth( mUpcomingWidth ); 711 mDayLabelsFrame->setMaximumWidth( mUpcomingWidth );
712 if ( maxWid < 20 ) 712 if ( maxWid < 20 )
713 maxWid = 20; 713 maxWid = 20;
714 714
715 QFont dlf = KOPrefs::instance()->mTimeLabelsFont; 715 QFont dlf = KOPrefs::instance()->mTimeLabelsFont;
716 QFontMetrics fm ( dlf ); 716 QFontMetrics fm ( dlf );
717 dlf.setBold( true ); 717 dlf.setBold( true );
718 int selCount = mSelectedDates.count(); 718 int selCount = mSelectedDates.count();
719 int widModulo = maxWid - (mAgenda->gridSpacingX() * selCount)+1; 719 int widModulo = maxWid - (mAgenda->gridSpacingX() * selCount)+1;
720 QString dayTest = "Mon 20"; 720 QString dayTest = "Mon 20";
721 //QString dayTest = "Mon 20"; 721 //QString dayTest = "Mon 20";
722 int wid = fm.width( dayTest ); 722 int wid = fm.width( dayTest );
723 //maxWid -= ( selCount * 3 ); //working for QLabels 723 //maxWid -= ( selCount * 3 ); //working for QLabels
724 if ( QApplication::desktop()->width() <= 320 ) 724 if ( QApplication::desktop()->width() <= 320 )
725 maxWid -= ( selCount * 3 ); //working for QPushButton 725 maxWid -= ( selCount * 3 ); //working for QPushButton
726 else 726 else
727 maxWid -= ( selCount * 4 ); //working for QPushButton 727 maxWid -= ( selCount * 4 ); //working for QPushButton
728 if ( maxWid < 0 ) 728 if ( maxWid < 0 )
729 maxWid = 20; 729 maxWid = 20;
730 int needWid = wid * selCount; 730 int needWid = wid * selCount;
731 //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid ); 731 //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid );
732 //if ( needWid > maxWid ) 732 //if ( needWid > maxWid )
733 // qDebug("DAYLABELS TOOOOOOO BIG "); 733 // qDebug("DAYLABELS TOOOOOOO BIG ");
734 while ( needWid > maxWid ) { 734 while ( needWid > maxWid ) {
735 dayTest = dayTest.left( dayTest.length() - 1 ); 735 dayTest = dayTest.left( dayTest.length() - 1 );
736 wid = fm.width( dayTest ); 736 wid = fm.width( dayTest );
737 needWid = wid * selCount; 737 needWid = wid * selCount;
738 } 738 }
739 int maxLen = dayTest.length(); 739 int maxLen = dayTest.length();
740 int fontPoint = dlf.pointSize(); 740 int fontPoint = dlf.pointSize();
741 if ( maxLen < 2 ) { 741 if ( maxLen < 2 ) {
742 int fontPoint = dlf.pointSize(); 742 int fontPoint = dlf.pointSize();
743 while ( fontPoint > 4 ) { 743 while ( fontPoint > 4 ) {
744 --fontPoint; 744 --fontPoint;
745 dlf.setPointSize( fontPoint ); 745 dlf.setPointSize( fontPoint );
746 QFontMetrics f( dlf ); 746 QFontMetrics f( dlf );
747 wid = f.width( "30" ); 747 wid = f.width( "30" );
748 needWid = wid * selCount; 748 needWid = wid * selCount;
749 if ( needWid < maxWid ) 749 if ( needWid < maxWid )
750 break; 750 break;
751 } 751 }
752 maxLen = 2; 752 maxLen = 2;
753 } 753 }
754 //qDebug("Max len %d ", dayTest.length() ); 754 //qDebug("Max len %d ", dayTest.length() );
755 if ( !KOPrefs::instance()->mTimeLabelsFont.bold() ) 755 if ( !KOPrefs::instance()->mTimeLabelsFont.bold() )
756 dlf.setBold( false ); 756 dlf.setBold( false );
757 QFontMetrics tempF( dlf ); 757 QFontMetrics tempF( dlf );
758 newHight = tempF.height(); 758 newHight = tempF.height();
759 mDayLabels->setFont( dlf ); 759 mDayLabels->setFont( dlf );
760 // mLayoutDayLabels = new QHBoxLayout(mDayLabels);; 760 // mLayoutDayLabels = new QHBoxLayout(mDayLabels);;
761 // mLayoutDayLabels->addSpacing(mTimeLabels->width()); 761 // mLayoutDayLabels->addSpacing(mTimeLabels->width());
762 //mLayoutDayLabels->addSpacing( 2 ); 762 //mLayoutDayLabels->addSpacing( 2 );
763 // QFont lFont = dlf; 763 // QFont lFont = dlf;
764 bool appendLabels = false; 764 bool appendLabels = false;
765 KOAgendaButton *dayLabel; 765 KOAgendaButton *dayLabel;
766 dayLabel = mDayLabelsList.first(); 766 dayLabel = mDayLabelsList.first();
767 if ( !dayLabel ) { 767 if ( !dayLabel ) {
768 appendLabels = true; 768 appendLabels = true;
769 dayLabel = getNewDaylabel(); 769 dayLabel = getNewDaylabel();
770 } 770 }
771 dayLabel->setFixedWidth( mTimeLabels->width()+mAgenda->frameWidth() ); 771 dayLabel->setFixedWidth( mTimeLabels->width()+mAgenda->frameWidth() );
772 dayLabel->setFont( dlf ); 772 dayLabel->setFont( dlf );
773 dayLabel->setNum( -1 ); 773 dayLabel->setNum( -1 );
774 //dayLabel->setAlignment(QLabel::AlignHCenter); 774 //dayLabel->setAlignment(QLabel::AlignHCenter);
775 775
776 dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) ); 776 dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) );
777 dayLabel->show(); 777 dayLabel->show();
778 DateList::ConstIterator dit; 778 DateList::ConstIterator dit;
779 bool oneday = (mSelectedDates.first() == mSelectedDates.last() ); 779 bool oneday = (mSelectedDates.first() == mSelectedDates.last() );
780 int counter = -1; 780 int counter = -1;
781 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { 781 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) {
782 ++counter; 782 ++counter;
783 QDate date = *dit; 783 QDate date = *dit;
784 // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels); 784 // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels);
785 if ( ! appendLabels ) { 785 if ( ! appendLabels ) {
786 dayLabel = mDayLabelsList.next(); 786 dayLabel = mDayLabelsList.next();
787 if ( !dayLabel ) 787 if ( !dayLabel )
788 appendLabels = true; 788 appendLabels = true;
789 } 789 }
790 if ( appendLabels ) { 790 if ( appendLabels ) {
791 dayLabel = getNewDaylabel(); 791 dayLabel = getNewDaylabel();
792 } 792 }
793 dayLabel->setMinimumWidth( 1 ); 793 dayLabel->setMinimumWidth( 1 );
794 dayLabel->setMaximumWidth( 10240 ); 794 dayLabel->setMaximumWidth( 10240 );
795 dayLabel->setFont( dlf ); 795 dayLabel->setFont( dlf );
796 dayLabel->show(); 796 dayLabel->show();
797 dayLabel->setAutoRepeat( false ); 797 dayLabel->setAutoRepeat( false );
798 dayLabel->setNum( counter ); 798 dayLabel->setNum( counter );
799 QString str; 799 QString str;
800 int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date); 800 int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date);
801 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true ); 801 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true );
802 switch ( maxLen ) { 802 switch ( maxLen ) {
803 case 2: 803 case 2:
804 str = QString::number( date.day() ); 804 str = QString::number( date.day() );
805 break; 805 break;
806 806
807 case 3: 807 case 3:
808 str = dayName.left( 1 ) +QString::number( date.day()); 808 str = dayName.left( 1 ) +QString::number( date.day());
809 809
810 break; 810 break;
811 case 4: 811 case 4:
812 str = dayName.left( 1 ) + " " +QString::number( date.day()); 812 str = dayName.left( 1 ) + " " +QString::number( date.day());
813 813
814 break; 814 break;
815 case 5: 815 case 5:
816 str = dayName.left( 2 ) + " " +QString::number( date.day()); 816 str = dayName.left( 2 ) + " " +QString::number( date.day());
817 817
818 break; 818 break;
819 case 6: 819 case 6:
820 str = dayName.left( 3 ) + " " +QString::number( date.day()); 820 str = dayName.left( 3 ) + " " +QString::number( date.day());
821 break; 821 break;
822 822
823 default: 823 default:
824 break; 824 break;
825 } 825 }
826 if ( oneday ) { 826 if ( oneday ) {
827 QString addString; 827 QString addString;
828 if ( mSelectedDates.first() == QDateTime::currentDateTime().date() ) 828 if ( mSelectedDates.first() == QDateTime::currentDateTime().date() )
829 addString = i18n("Today"); 829 addString = i18n("Today");
830 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) ) 830 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) )
831 addString = i18n("Tomorrow"); 831 addString = i18n("Tomorrow");
832 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) ) 832 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) )
833 addString = i18n("Yesterday"); 833 addString = i18n("Yesterday");
834 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) ) 834 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) )
835 addString = i18n("Day before yesterday"); 835 addString = i18n("Day before yesterday");
836 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) ) 836 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) )
837 addString = i18n("Day after tomorrow"); 837 addString = i18n("Day after tomorrow");
838 if ( !addString.isEmpty() ) { 838 if ( !addString.isEmpty() ) {
839 if ( QApplication::desktop()->width() < 640 ) 839 if ( QApplication::desktop()->width() < 640 )
840 str = addString+", " + str; 840 str = addString+", " + str;
841 else 841 else
842 str = addString+", "+ KGlobal::locale()->formatDate( date, false); 842 str = addString+", "+ KGlobal::locale()->formatDate( date, false);
843 } else { 843 } else {
844 str = KGlobal::locale()->formatDate( date, KOPrefs::instance()->mShortDateInViewer); 844 str = KGlobal::locale()->formatDate( date, KOPrefs::instance()->mShortDateInViewer);
845 } 845 }
846 } 846 }
847 dayLabel->setText(str); 847 dayLabel->setText(str);
848 //dayLabel->setAlignment(QLabel::AlignHCenter); 848 //dayLabel->setAlignment(QLabel::AlignHCenter);
849 if (date == QDate::currentDate()) { 849 if (date == QDate::currentDate()) {
850 QFont bFont = dlf; 850 QFont bFont = dlf;
851 bFont.setBold( true ); 851 bFont.setBold( true );
852 dayLabel->setFont(bFont); 852 dayLabel->setFont(bFont);
853 } 853 }
854 //dayLayout->addWidget(dayLabel); 854 //dayLayout->addWidget(dayLabel);
855 855
856#ifndef KORG_NOPLUGINS 856#ifndef KORG_NOPLUGINS
857 CalendarDecoration::List cds = KOCore::self()->calendarDecorations(); 857 CalendarDecoration::List cds = KOCore::self()->calendarDecorations();
858 CalendarDecoration *it; 858 CalendarDecoration *it;
859 for(it = cds.first(); it; it = cds.next()) { 859 for(it = cds.first(); it; it = cds.next()) {
860 QString text = it->shortText( date ); 860 QString text = it->shortText( date );
861 if ( !text.isEmpty() ) { 861 if ( !text.isEmpty() ) {
862 QLabel *label = new QLabel(text,mDayLabels); 862 QLabel *label = new QLabel(text,mDayLabels);
863 label->setAlignment(AlignCenter); 863 label->setAlignment(AlignCenter);
864 dayLayout->addWidget(label); 864 dayLayout->addWidget(label);
865 } 865 }
866 } 866 }
867 867
868 for(it = cds.first(); it; it = cds.next()) { 868 for(it = cds.first(); it; it = cds.next()) {
869 QWidget *wid = it->smallWidget(mDayLabels,date); 869 QWidget *wid = it->smallWidget(mDayLabels,date);
870 if ( wid ) { 870 if ( wid ) {
871 // wid->setHeight(20); 871 // wid->setHeight(20);
872 dayLayout->addWidget(wid); 872 dayLayout->addWidget(wid);
873 } 873 }
874 } 874 }
875#endif 875#endif
876 } 876 }
877 if ( ! appendLabels ) { 877 if ( ! appendLabels ) {
878 dayLabel = mDayLabelsList.next(); 878 dayLabel = mDayLabelsList.next();
879 if ( !dayLabel ) 879 if ( !dayLabel )
880 appendLabels = true; 880 appendLabels = true;
881 } 881 }
882 if ( appendLabels ) { 882 if ( appendLabels ) {
883 dayLabel = getNewDaylabel(); 883 dayLabel = getNewDaylabel();
884 } 884 }
885 //dayLabel->hide();//test only 885 //dayLabel->hide();//test only
886 886
887 dayLabel->setText(">"); 887 dayLabel->setText(">");
888 dayLabel->setFont( dlf ); 888 dayLabel->setFont( dlf );
889 dayLabel->setAutoRepeat( true ); 889 dayLabel->setAutoRepeat( true );
890 dayLabel->show(); 890 dayLabel->show();
891 dayLabel->setNum( -2 ); 891 dayLabel->setNum( -2 );
892 dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ widModulo ); 892 dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ widModulo );
893 893
894 //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2); 894 //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2);
895 if ( !appendLabels ) { 895 if ( !appendLabels ) {
896 dayLabel = mDayLabelsList.next(); 896 dayLabel = mDayLabelsList.next();
897 while ( dayLabel ) { 897 while ( dayLabel ) {
898 //qDebug("!dayLabel %d",dayLabel ); 898 //qDebug("!dayLabel %d",dayLabel );
899 dayLabel->hide(); 899 dayLabel->hide();
900 dayLabel = mDayLabelsList.next(); 900 dayLabel = mDayLabelsList.next();
901 } 901 }
902 } 902 }
903 903
904 mDayLabelsFrame->setFixedHeight( newHight + 4 ); 904 mDayLabelsFrame->setFixedHeight( newHight + 4 );
905} 905}
906 906
907int KOAgendaView::maxDatesHint() 907int KOAgendaView::maxDatesHint()
908{ 908{
909 // Not sure about the max number of events, so return 0 for now. 909 // Not sure about the max number of events, so return 0 for now.
910 return 0; 910 return 0;
911} 911}
912 912
913int KOAgendaView::currentDateCount() 913int KOAgendaView::currentDateCount()
914{ 914{
915 return mSelectedDates.count(); 915 return mSelectedDates.count();
916} 916}
917 917
918QPtrList<Incidence> KOAgendaView::selectedIncidences() 918QPtrList<Incidence> KOAgendaView::selectedIncidences()
919{ 919{
920 QPtrList<Incidence> selected; 920 QPtrList<Incidence> selected;
921 Incidence *incidence; 921 Incidence *incidence;
922 922
923 incidence = mAgenda->selectedIncidence(); 923 incidence = mAgenda->selectedIncidence();
924 if (incidence) selected.append(incidence); 924 if (incidence) selected.append(incidence);
925 925
926 incidence = mAllDayAgenda->selectedIncidence(); 926 incidence = mAllDayAgenda->selectedIncidence();
927 if (incidence) selected.append(incidence); 927 if (incidence) selected.append(incidence);
928 928
929 return selected; 929 return selected;
930} 930}
931 931
932DateList KOAgendaView::selectedDates() 932DateList KOAgendaView::selectedDates()
933{ 933{
934 DateList selected; 934 DateList selected;
935 QDate qd; 935 QDate qd;
936 936
937 qd = mAgenda->selectedIncidenceDate(); 937 qd = mAgenda->selectedIncidenceDate();
938 if (qd.isValid()) selected.append(qd); 938 if (qd.isValid()) selected.append(qd);
939 939
940 qd = mAllDayAgenda->selectedIncidenceDate(); 940 qd = mAllDayAgenda->selectedIncidenceDate();
941 if (qd.isValid()) selected.append(qd); 941 if (qd.isValid()) selected.append(qd);
942 942
943 return selected; 943 return selected;
944} 944}
945 945
946 946
947void KOAgendaView::updateView() 947void KOAgendaView::updateView()
948{ 948{
949 if ( mBlockUpdating ) 949 if ( mBlockUpdating )
950 return; 950 return;
951 // kdDebug() << "KOAgendaView::updateView()" << endl; 951 // kdDebug() << "KOAgendaView::updateView()" << endl;
952 fillAgenda(); 952 fillAgenda();
953 953
954} 954}
955 955
956 956
957/* 957/*
958 Update configuration settings for the agenda view. This method is not 958 Update configuration settings for the agenda view. This method is not
959 complete. 959 complete.
960*/ 960*/
961void KOAgendaView::updateConfig() 961void KOAgendaView::updateConfig()
962{ 962{
963 if ( mBlockUpdating ) 963 if ( mBlockUpdating )
964 return; 964 return;
965 if ( mAgenda->height() > 96 * KOPrefs::instance()->mHourSize ) { 965 if ( mAgenda->height() > 96 * KOPrefs::instance()->mHourSize ) {
966 int old = KOPrefs::instance()->mHourSize; 966 int old = KOPrefs::instance()->mHourSize;
967 KOPrefs::instance()->mHourSize = mAgenda->height()/96 +1; 967 KOPrefs::instance()->mHourSize = mAgenda->height()/96 +1;
968 //qDebug("KOPrefs::instance()->mHourSize adjusted %d to %d ", old,KOPrefs::instance()->mHourSize ); 968 //qDebug("KOPrefs::instance()->mHourSize adjusted %d to %d ", old,KOPrefs::instance()->mHourSize );
969 } 969 }
970 970
971 971
972 // update config for children 972 // update config for children
973 mTimeLabels->updateConfig(); 973 mTimeLabels->updateConfig();
974 mAgenda->storePosition(); 974 mAgenda->storePosition();
975 mAgenda->updateConfig(); 975 mAgenda->updateConfig();
976 mAllDayAgenda->updateConfig(); 976 mAllDayAgenda->updateConfig();
977 // widget synchronization 977 // widget synchronization
978 //TODO: find a better way, maybe signal/slot 978 //TODO: find a better way, maybe signal/slot
979 mTimeLabels->positionChanged(); 979 mTimeLabels->positionChanged();
980 980
981 // for some reason, this needs to be called explicitly 981 // for some reason, this needs to be called explicitly
982 mTimeLabels->repaint(); 982 mTimeLabels->repaint();
983 983
984 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); 984 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
985 985
986 // ToolTips displaying summary of events 986 // ToolTips displaying summary of events
987 KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance() 987 KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance()
988 ->mEnableToolTips); 988 ->mEnableToolTips);
989 989
990 //setHolidayMasks(); 990 //setHolidayMasks();
991 991
992 //createDayLabels(); called by via updateView(); 992 //createDayLabels(); called by via updateView();
993 mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth()); 993 mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth());
994 updateView(); 994 updateView();
995 mAgenda->restorePosition(); 995 mAgenda->restorePosition();
996} 996}
997 997
998 998
999void KOAgendaView::updateEventDates(KOAgendaItem *item, int type) 999void KOAgendaView::updateEventDates(KOAgendaItem *item, int type)
1000{ 1000{
1001 1001
1002 1002
1003 int xxx = item->cellX(); 1003 int xxx = item->cellX();
1004 //qDebug("KOAgendaView::updateEventDates %d %d %d %d %d", xxx, mMinY.at(xxx),mMaxY.at(xxx),item->cellYTop(),item->cellYBottom() ); 1004 //qDebug("KOAgendaView::updateEventDates %d %d %d %d %d", xxx, mMinY.at(xxx),mMaxY.at(xxx),item->cellYTop(),item->cellYBottom() );
1005 if ( mMinY.at(xxx) > item->cellYTop() ) 1005 if ( mMinY.at(xxx) > item->cellYTop() )
1006 mMinY.at(xxx) = item->cellYTop(); 1006 mMinY.at(xxx) = item->cellYTop();
1007 if ( mMaxY.at(xxx) < item->cellYBottom() ) 1007 if ( mMaxY.at(xxx) < item->cellYBottom() )
1008 mMaxY.at(xxx) = item->cellYBottom(); 1008 mMaxY.at(xxx) = item->cellYBottom();
1009 1009
1010 QDateTime startDt,endDt; 1010 QDateTime startDt,endDt;
1011 QDate startDate; 1011 QDate startDate;
1012 int lenInSecs; 1012 int lenInSecs;
1013 // if ( type == KOAgenda::RESIZETOP ) 1013 // if ( type == KOAgenda::RESIZETOP )
1014 // qDebug("RESIZETOP "); 1014 // qDebug("RESIZETOP ");
1015 // if ( type == KOAgenda::RESIZEBOTTOM ) 1015 // if ( type == KOAgenda::RESIZEBOTTOM )
1016 // qDebug("RESIZEBOTTOM "); 1016 // qDebug("RESIZEBOTTOM ");
1017 // if ( type == KOAgenda::MOVE ) 1017 // if ( type == KOAgenda::MOVE )
1018 // qDebug("MOVE "); 1018 // qDebug("MOVE ");
1019 if ( item->incidence()->typeID() == eventID ) { 1019 if ( item->incidence()->typeID() == eventID ) {
1020 startDt =item->incidence()->dtStart(); 1020 startDt =item->incidence()->dtStart();
1021 endDt = item->incidence()->dtEnd(); 1021 endDt = item->incidence()->dtEnd();
1022 lenInSecs = startDt.secsTo( endDt ); 1022 lenInSecs = startDt.secsTo( endDt );
1023 } 1023 }
1024 1024
1025 // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED ); 1025 // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED );
1026 1026
1027 if ( item->incidence()->typeID()== todoID && item->mLastMoveXPos > 0 ) { 1027 if ( item->incidence()->typeID()== todoID && item->mLastMoveXPos > 0 ) {
1028 startDate = mSelectedDates[item->mLastMoveXPos]; 1028 startDate = mSelectedDates[item->mLastMoveXPos];
1029 } else { 1029 } else {
1030 if (item->cellX() < 0) { 1030 if (item->cellX() < 0) {
1031 startDate = (mSelectedDates.first()).addDays(item->cellX()); 1031 startDate = (mSelectedDates.first()).addDays(item->cellX());
1032 } else { 1032 } else {
1033 startDate = mSelectedDates[item->cellX()]; 1033 startDate = mSelectedDates[item->cellX()];
1034 } 1034 }
1035 } 1035 }
1036 startDt.setDate(startDate); 1036 startDt.setDate(startDate);
1037 1037
1038 if (item->incidence()->doesFloat()) { 1038 if (item->incidence()->doesFloat()) {
1039 endDt.setDate(startDate.addDays(item->cellWidth() - 1)); 1039 endDt.setDate(startDate.addDays(item->cellWidth() - 1));
1040 } else { 1040 } else {
1041 if ( type == KOAgenda::RESIZETOP || type == KOAgenda::MOVE ) 1041 if ( type == KOAgenda::RESIZETOP || type == KOAgenda::MOVE )
1042 startDt.setTime(mAgenda->gyToTime(item->cellYTop())); 1042 startDt.setTime(mAgenda->gyToTime(item->cellYTop()));
1043 if ( item->incidence()->typeID() == eventID ) { 1043 if ( item->incidence()->typeID() == eventID ) {
1044 if ( type == KOAgenda::MOVE ) { 1044 if ( type == KOAgenda::MOVE ) {
1045 endDt = startDt.addSecs(lenInSecs); 1045 endDt = startDt.addSecs(lenInSecs);
1046 1046
1047 } else if ( type == KOAgenda::RESIZEBOTTOM ) { 1047 } else if ( type == KOAgenda::RESIZEBOTTOM ) {
1048 if (item->lastMultiItem()) { 1048 if (item->lastMultiItem()) {
1049 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); 1049 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1));
1050 endDt.setDate(startDate. 1050 endDt.setDate(startDate.
1051 addDays(item->lastMultiItem()->cellX() - item->cellX())); 1051 addDays(item->lastMultiItem()->cellX() - item->cellX()));
1052 } else { 1052 } else {
1053 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); 1053 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1));
1054 endDt.setDate(startDate); 1054 endDt.setDate(startDate);
1055 } 1055 }
1056 } 1056 }
1057 } else { 1057 } else {
1058 // todo 1058 // todo
1059 if (item->lastMultiItem()) { 1059 if (item->lastMultiItem()) {
1060 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); 1060 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1));
1061 endDt.setDate(startDate. 1061 endDt.setDate(startDate.
1062 addDays(item->lastMultiItem()->cellX() - item->cellX())); 1062 addDays(item->lastMultiItem()->cellX() - item->cellX()));
1063 } else { 1063 } else {
1064 //qDebug("tem->cellYBottom() %d",item->cellYBottom() ); 1064 //qDebug("tem->cellYBottom() %d",item->cellYBottom() );
1065 if ( item->cellYBottom() > 0 ) 1065 if ( item->cellYBottom() > 0 )
1066 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); 1066 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1));
1067 else 1067 else
1068 endDt.setTime((static_cast<Todo*>(item->incidence()))->dtDue().time()); 1068 endDt.setTime((static_cast<Todo*>(item->incidence()))->dtDue().time());
1069 endDt.setDate(startDate); 1069 endDt.setDate(startDate);
1070 } 1070 }
1071 } 1071 }
1072 } 1072 }
1073 if ( item->incidence()->typeID() == eventID ) { 1073 if ( item->incidence()->typeID() == eventID ) {
1074 item->incidence()->setDtStart(startDt); 1074 item->incidence()->setDtStart(startDt);
1075 (static_cast<Event*>(item->incidence()))->setDtEnd(endDt); 1075 (static_cast<Event*>(item->incidence()))->setDtEnd(endDt);
1076 } else if ( item->incidence()->typeID() == todoID ) { 1076 } else if ( item->incidence()->typeID() == todoID ) {
1077 Todo* to = static_cast<Todo*>(item->incidence()); 1077 Todo* to = static_cast<Todo*>(item->incidence());
1078 1078
1079 to->setDtDue(endDt); 1079 to->setDtDue(endDt);
1080 if ( to->hasStartDate() ) { 1080 if ( to->hasStartDate() ) {
1081 if (to->dtStart() >= to->dtDue() ) 1081 if (to->dtStart() >= to->dtDue() )
1082 to->setDtStart(to->dtDue().addDays( -2 )); 1082 to->setDtStart(to->dtDue().addDays( -2 ));
1083 } 1083 }
1084 1084
1085 } 1085 }
1086 //qDebug("KOAgendaView::updateEventDates stsart %s end %s ", startDt.toString().latin1(), endDt.toString().latin1() ); 1086 //qDebug("KOAgendaView::updateEventDates stsart %s end %s ", startDt.toString().latin1(), endDt.toString().latin1() );
1087 item->incidence()->setRevision(item->incidence()->revision()+1); 1087 item->incidence()->setRevision(item->incidence()->revision()+1);
1088 item->setItemDate(startDt.date()); 1088 item->setItemDate(startDt.date());
1089 //item->updateItem(); 1089 //item->updateItem();
1090 if ( item->incidence()->typeID() == todoID ) { 1090 if ( item->incidence()->typeID() == todoID ) {
1091 emit todoMoved((Todo*)item->incidence(), KOGlobals::EVENTEDITED ); 1091 emit todoMoved((Todo*)item->incidence(), KOGlobals::EVENTEDITED );
1092 1092
1093 } 1093 }
1094 else 1094 else
1095 emit incidenceChanged(item->incidence(), KOGlobals::EVENTEDITED); 1095 emit incidenceChanged(item->incidence(), KOGlobals::EVENTEDITED);
1096 item->updateItem(); 1096 item->updateItem();
1097} 1097}
1098 1098
1099void KOAgendaView::showDates( const QDate &start, const QDate &end ) 1099void KOAgendaView::showDates( const QDate &start, const QDate &end )
1100{ 1100{
1101 // kdDebug() << "KOAgendaView::selectDates" << endl; 1101 // kdDebug() << "KOAgendaView::selectDates" << endl;
1102 1102
1103 mSelectedDates.clear(); 1103 mSelectedDates.clear();
1104 // qDebug("KOAgendaView::showDates "); 1104 // qDebug("KOAgendaView::showDates ");
1105 QDate d = start; 1105 QDate d = start;
1106 while (d <= end) { 1106 while (d <= end) {
1107 mSelectedDates.append(d); 1107 mSelectedDates.append(d);
1108 d = d.addDays( 1 ); 1108 d = d.addDays( 1 );
1109 } 1109 }
1110 1110
1111 // and update the view 1111 // and update the view
1112 fillAgenda(); 1112 fillAgenda();
1113} 1113}
1114 1114
1115 1115
1116void KOAgendaView::showEvents(QPtrList<Event>) 1116void KOAgendaView::showEvents(QPtrList<Event>)
1117{ 1117{
1118 kdDebug() << "KOAgendaView::showEvents() is not yet implemented" << endl; 1118 kdDebug() << "KOAgendaView::showEvents() is not yet implemented" << endl;
1119} 1119}
1120 1120
1121void KOAgendaView::changeEventDisplay(Event *, int) 1121void KOAgendaView::changeEventDisplay(Event *, int)
1122{ 1122{
1123 // qDebug("KOAgendaView::changeEventDisplay "); 1123 // qDebug("KOAgendaView::changeEventDisplay ");
1124 // kdDebug() << "KOAgendaView::changeEventDisplay" << endl; 1124 // kdDebug() << "KOAgendaView::changeEventDisplay" << endl;
1125 // this should be re-written to be MUCH smarter. Right now we 1125 // this should be re-written to be MUCH smarter. Right now we
1126 // are just playing dumb. 1126 // are just playing dumb.
1127 fillAgenda(); 1127 fillAgenda();
1128} 1128}
1129 1129
1130void KOAgendaView::fillAgenda(const QDate &) 1130void KOAgendaView::fillAgenda(const QDate &)
1131{ 1131{
1132 // qDebug("KOAgendaView::fillAgenda "); 1132 // qDebug("KOAgendaView::fillAgenda ");
1133 fillAgenda(); 1133 fillAgenda();
1134} 1134}
1135 1135
1136void KOAgendaView::fillAgenda() 1136void KOAgendaView::fillAgenda()
1137{ 1137{
1138 if ( globalFlagBlockStartup ) 1138 if ( globalFlagBlockStartup )
1139 return; 1139 return;
1140 if ( globalFlagBlockAgenda == 1 ) 1140 if ( globalFlagBlockAgenda == 1 )
1141 return; 1141 return;
1142 static bool onlyOne = false; 1142 static bool onlyOne = false;
1143 if ( onlyOne ) 1143 if ( onlyOne )
1144 return; 1144 return;
1145 onlyOne = true; 1145 onlyOne = true;
1146 //if ( globalFlagBlockAgenda == 2 ) 1146 //if ( globalFlagBlockAgenda == 2 )
1147 //globalFlagBlockAgenda = 0; 1147 //globalFlagBlockAgenda = 0;
1148 // globalFlagBlockPainting = false; 1148 // globalFlagBlockPainting = false;
1149 if ( globalFlagBlockAgenda == 0 ) 1149 if ( globalFlagBlockAgenda == 0 )
1150 globalFlagBlockAgenda = 1; 1150 globalFlagBlockAgenda = 1;
1151 // clearView(); 1151 // clearView();
1152 //qDebug("fillAgenda()++++ "); 1152 //qDebug("fillAgenda()++++ ");
1153 globalFlagBlockAgendaItemPaint = 1; 1153 globalFlagBlockAgendaItemPaint = 1;
1154 1154
1155 mAllDayAgenda->changeColumns(mSelectedDates.count()); 1155 mAllDayAgenda->changeColumns(mSelectedDates.count());
1156 mAgenda->changeColumns(mSelectedDates.count()); 1156 mAgenda->changeColumns(mSelectedDates.count());
1157 qApp->processEvents(); 1157 qApp->processEvents();
1158 mEventIndicatorTop->changeColumns(mSelectedDates.count()); 1158 mEventIndicatorTop->changeColumns(mSelectedDates.count());
1159 mEventIndicatorBottom->changeColumns(mSelectedDates.count()); 1159 mEventIndicatorBottom->changeColumns(mSelectedDates.count());
1160 setHolidayMasks(); 1160 setHolidayMasks();
1161 1161
1162 mMinY.resize(mSelectedDates.count()); 1162 mMinY.resize(mSelectedDates.count());
1163 mMaxY.resize(mSelectedDates.count()); 1163 mMaxY.resize(mSelectedDates.count());
1164 1164
1165 QPtrList<Event> dayEvents; 1165 QPtrList<Event> dayEvents;
1166 1166
1167 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. 1167 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue.
1168 // Therefore, gtodoset all of them. 1168 // Therefore, gtodoset all of them.
1169 QPtrList<Todo> todos = calendar()->todos(); 1169 QPtrList<Todo> todos = calendar()->todos();
1170 1170
1171 mAgenda->setDateList(mSelectedDates); 1171 mAgenda->setDateList(mSelectedDates);
1172 1172
1173 QDate today = QDate::currentDate(); 1173 QDate today = QDate::currentDate();
1174 1174
1175 DateList::ConstIterator dit; 1175 DateList::ConstIterator dit;
1176 int curCol = 0; 1176 int curCol = 0;
1177 int maxCol = mSelectedDates.count()-1; 1177 int maxCol = mSelectedDates.count()-1;
1178 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { 1178 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) {
1179 QDate currentDate = *dit; 1179 QDate currentDate = *dit;
1180 // kdDebug() << "KOAgendaView::fillAgenda(): " << currentDate.toString() 1180 // kdDebug() << "KOAgendaView::fillAgenda(): " << currentDate.toString()
1181 // << endl; 1181 // << endl;
1182 1182
1183 dayEvents = calendar()->events(currentDate,false); 1183 dayEvents = calendar()->events(currentDate,false);
1184 1184
1185 // Default values, which can never be reached 1185 // Default values, which can never be reached
1186 mMinY[curCol] = mAgenda->timeToY(QTime(23,59)) + 1; 1186 mMinY[curCol] = mAgenda->timeToY(QTime(23,59)) + 1;
1187 mMaxY[curCol] = mAgenda->timeToY(QTime(0,0)) - 1; 1187 mMaxY[curCol] = mAgenda->timeToY(QTime(0,0)) - 1;
1188 1188
1189 unsigned int numEvent; 1189 unsigned int numEvent;
1190 //qDebug("+++++NUMEVENT %d", dayEvents.count()); 1190 //qDebug("+++++NUMEVENT %d", dayEvents.count());
1191 for(numEvent=0;numEvent<dayEvents.count();++numEvent) { 1191 for(numEvent=0;numEvent<dayEvents.count();++numEvent) {
1192 Event *event = dayEvents.at(numEvent); 1192 Event *event = dayEvents.at(numEvent);
1193 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") ) 1193 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") )
1194 if ( event->uid().left(15) == QString("last-syncEvent-") ) 1194 if ( event->uid().left(15) == QString("last-syncEvent-") )
1195 continue; 1195 continue;
1196 // kdDebug() << " Event: " << event->summary() << endl; 1196 // kdDebug() << " Event: " << event->summary() << endl;
1197 1197
1198 int beginX = currentDate.daysTo(event->dtStart().date()) + curCol; 1198 int beginX = currentDate.daysTo(event->dtStart().date()) + curCol;
1199 int endX = currentDate.daysTo(event->dtEnd().date()) + curCol; 1199 int endX = currentDate.daysTo(event->dtEnd().date()) + curCol;
1200 1200
1201 // kdDebug() << " beginX: " << beginX << " endX: " << endX << endl; 1201 // kdDebug() << " beginX: " << beginX << " endX: " << endX << endl;
1202 1202
1203 if (event->doesFloat()) { 1203 if (event->doesFloat()) {
1204 if (event->recurrence()->doesRecur()) { 1204 if (event->doesRecur()) {
1205 if (event->isMultiDay() ) { 1205 if (event->isMultiDay() ) {
1206 endX = endX - beginX;// endX is now number of days 1206 endX = endX - beginX;// endX is now number of days
1207 if ( event->recursOn( currentDate ) ) { 1207 if ( event->recursOn( currentDate ) ) {
1208 endX += curCol; 1208 endX += curCol;
1209 beginX = curCol; 1209 beginX = curCol;
1210 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); 1210 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX);
1211 } else { 1211 } else {
1212 //qDebug("days endX %d curCol %d max Col %d %s",endX ,curCol, maxCol, currentDate.toString().latin1()); 1212 //qDebug("days endX %d curCol %d max Col %d %s",endX ,curCol, maxCol, currentDate.toString().latin1());
1213 if ( curCol == maxCol && maxCol+1 < endX ) { 1213 if ( curCol == maxCol && maxCol+1 < endX ) {
1214 int i; 1214 int i;
1215 for ( i = 1; i< endX; ++i ) { 1215 for ( i = 1; i< endX; ++i ) {
1216 if ( event->recursOn( currentDate.addDays( -i ) ) ) 1216 if ( event->recursOn( currentDate.addDays( -i ) ) )
1217 break; 1217 break;
1218 } 1218 }
1219 if ( i > maxCol ) { 1219 if ( i > maxCol ) {
1220 mAllDayAgenda->insertAllDayItem(event,currentDate,0,curCol); 1220 mAllDayAgenda->insertAllDayItem(event,currentDate,0,curCol);
1221 //qDebug("BINGO "); 1221 //qDebug("BINGO ");
1222 } 1222 }
1223 1223
1224 } else { 1224 } else {
1225 QDate dateit = currentDate.addDays( -endX ); 1225 QDate dateit = currentDate.addDays( -endX );
1226 if ( event->recursOn( dateit ) ) { 1226 if ( event->recursOn( dateit ) ) {
1227 //qDebug("found %d %d %d %s", endX,curCol, curCol-endX ,dateit.toString().latin1() ); 1227 //qDebug("found %d %d %d %s", endX,curCol, curCol-endX ,dateit.toString().latin1() );
1228 if ( curCol-endX < 0 ) { 1228 if ( curCol-endX < 0 ) {
1229 mAllDayAgenda->insertAllDayItem(event,currentDate,0,curCol); 1229 mAllDayAgenda->insertAllDayItem(event,currentDate,0,curCol);
1230 } 1230 }
1231 } 1231 }
1232 } 1232 }
1233 } 1233 }
1234 } else { 1234 } else {
1235 mAllDayAgenda->insertAllDayItem(event,currentDate,curCol,curCol); 1235 mAllDayAgenda->insertAllDayItem(event,currentDate,curCol,curCol);
1236 } 1236 }
1237 1237
1238 } else { 1238 } else {
1239 if (beginX <= 0 && curCol == 0) { 1239 if (beginX <= 0 && curCol == 0) {
1240 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); 1240 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX);
1241 } else if (beginX == curCol) { 1241 } else if (beginX == curCol) {
1242 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); 1242 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX);
1243 } 1243 }
1244 } 1244 }
1245 } else if (event->isMultiDay()) { 1245 } else if (event->isMultiDay()) {
1246 if ( event->doesRecur () ) { 1246 if ( event->doesRecur () ) {
1247 QDate dateit = currentDate; 1247 QDate dateit = currentDate;
1248 int count = 0; 1248 int count = 0;
1249 int max = event->dtStart().daysTo( event->dtEnd() ) +2; 1249 int max = event->dtStart().daysTo( event->dtEnd() ) +2;
1250 while (! event->recursOn( dateit ) && count <= max ) { 1250 while (! event->recursOn( dateit ) && count <= max ) {
1251 ++count; 1251 ++count;
1252 dateit = dateit.addDays( -1 ); 1252 dateit = dateit.addDays( -1 );
1253 } 1253 }
1254 bool ok; 1254 bool ok;
1255 QDateTime nextOcstart = event->getNextOccurence( QDateTime(dateit) ,&ok ); 1255 QDateTime nextOcstart = event->getNextOccurence( QDateTime(dateit) ,&ok );
1256 if ( ok ) 1256 if ( ok )
1257 { 1257 {
1258 int secs = event->dtStart().secsTo( event->dtEnd() ); 1258 int secs = event->dtStart().secsTo( event->dtEnd() );
1259 QDateTime nextOcend =nextOcstart.addSecs( secs ); ; 1259 QDateTime nextOcend =nextOcstart.addSecs( secs ); ;
1260 beginX = currentDate.daysTo(nextOcstart.date()) + curCol; 1260 beginX = currentDate.daysTo(nextOcstart.date()) + curCol;
1261 endX = currentDate.daysTo(nextOcend.date()) + curCol; 1261 endX = currentDate.daysTo(nextOcend.date()) + curCol;
1262 1262
1263 } 1263 }
1264 } 1264 }
1265 int startY = mAgenda->timeToY(event->dtStart().time()); 1265 int startY = mAgenda->timeToY(event->dtStart().time());
1266 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; 1266 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1;
1267 //qDebug("insert %d %d %d %d %d ",beginX,endX,startY,endY , curCol ); 1267 //qDebug("insert %d %d %d %d %d ",beginX,endX,startY,endY , curCol );
1268 if ((beginX <= 0 && curCol == 0) || beginX == curCol) { 1268 if ((beginX <= 0 && curCol == 0) || beginX == curCol) {
1269 //qDebug("insert!!! "); 1269 //qDebug("insert!!! ");
1270 mAgenda->insertMultiItem(event,currentDate,beginX,endX,startY,endY); 1270 mAgenda->insertMultiItem(event,currentDate,beginX,endX,startY,endY);
1271 } 1271 }
1272 if (beginX == curCol) { 1272 if (beginX == curCol) {
1273 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); 1273 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59));
1274 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1274 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1275 } else if (endX == curCol) { 1275 } else if (endX == curCol) {
1276 mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); 1276 mMinY[curCol] = mAgenda->timeToY(QTime(0,0));
1277 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1277 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1278 } else { 1278 } else {
1279 mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); 1279 mMinY[curCol] = mAgenda->timeToY(QTime(0,0));
1280 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); 1280 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59));
1281 } 1281 }
1282 } else { 1282 } else {
1283 int startY = mAgenda->timeToY(event->dtStart().time()); 1283 int startY = mAgenda->timeToY(event->dtStart().time());
1284 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; 1284 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1;
1285 if (endY < startY) endY = startY; 1285 if (endY < startY) endY = startY;
1286 mAgenda->insertItem(event,currentDate,curCol,startY,endY); 1286 mAgenda->insertItem(event,currentDate,curCol,startY,endY);
1287 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1287 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1288 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1288 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1289 } 1289 }
1290 } 1290 }
1291 // ---------- [display Todos -------------- 1291 // ---------- [display Todos --------------
1292 unsigned int numTodo; 1292 unsigned int numTodo;
1293 for (numTodo = 0; numTodo < todos.count(); ++numTodo) { 1293 for (numTodo = 0; numTodo < todos.count(); ++numTodo) {
1294 Todo *todo = todos.at(numTodo); 1294 Todo *todo = todos.at(numTodo);
1295 1295
1296 if ( ! todo->hasDueDate() && !todo->hasCompletedDate()) continue; // todo shall not be displayed if it has no date 1296 if ( ! todo->hasDueDate() && !todo->hasCompletedDate()) continue; // todo shall not be displayed if it has no date
1297 if ( todo->hasCompletedDate() && !KOPrefs::instance()->mShowCompletedTodoInAgenda ) continue; 1297 if ( todo->hasCompletedDate() && !KOPrefs::instance()->mShowCompletedTodoInAgenda ) continue;
1298 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. 1298 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue.
1299 // Already completed items can be displayed on their original due date 1299 // Already completed items can be displayed on their original due date
1300 //if not KOPrefs::instance()->mShowTodoInAgenda, show overdue in agenda 1300 //if not KOPrefs::instance()->mShowTodoInAgenda, show overdue in agenda
1301 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < today) && KOPrefs::instance()->mShowTodoInAgenda; 1301 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < today) && KOPrefs::instance()->mShowTodoInAgenda;
1302 bool fillIn = false; 1302 bool fillIn = false;
1303 if ( todo->hasCompletedDate() && todo->completed().date() == currentDate ) 1303 if ( todo->hasCompletedDate() && todo->completed().date() == currentDate )
1304 fillIn = true; 1304 fillIn = true;
1305 if ( ! fillIn && !todo->hasCompletedDate() ) 1305 if ( ! fillIn && !todo->hasCompletedDate() )
1306 fillIn = ((todo->dtDue().date() == currentDate) && !overdue) || ((currentDate == today) && overdue); 1306 fillIn = ((todo->dtDue().date() == currentDate) && !overdue) || ((currentDate == today) && overdue);
1307 if ( fillIn ) { 1307 if ( fillIn ) {
1308 if ( (todo->doesFloat() || overdue ) && !todo->hasCompletedDate() ) { // Todo has no due-time set or is already overdue 1308 if ( (todo->doesFloat() || overdue ) && !todo->hasCompletedDate() ) { // Todo has no due-time set or is already overdue
1309 if ( KOPrefs::instance()->mShowTodoInAgenda ) 1309 if ( KOPrefs::instance()->mShowTodoInAgenda )
1310 mAllDayAgenda->insertAllDayItem(todo, currentDate, curCol, curCol); 1310 mAllDayAgenda->insertAllDayItem(todo, currentDate, curCol, curCol);
1311 } 1311 }
1312 else { 1312 else {
1313 QDateTime dt; 1313 QDateTime dt;
1314 if ( todo->hasCompletedDate() ) 1314 if ( todo->hasCompletedDate() )
1315 dt = todo->completed(); 1315 dt = todo->completed();
1316 else 1316 else
1317 dt = todo->dtDue();; 1317 dt = todo->dtDue();;
1318 1318
1319 1319
1320 int endY = mAgenda->timeToY(dt.time()) - 1; 1320 int endY = mAgenda->timeToY(dt.time()) - 1;
1321 int hi = (18/KOPrefs::instance()->mHourSize); 1321 int hi = (18/KOPrefs::instance()->mHourSize);
1322 //qDebug("hei %d ",KOPrefs::instance()->mHourSize); 1322 //qDebug("hei %d ",KOPrefs::instance()->mHourSize);
1323 int startY = endY -hi; 1323 int startY = endY -hi;
1324 1324
1325 mAgenda->insertItem(todo,currentDate,curCol,startY,endY); 1325 mAgenda->insertItem(todo,currentDate,curCol,startY,endY);
1326 1326
1327 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1327 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1328 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1328 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1329 } 1329 }
1330 } 1330 }
1331 } 1331 }
1332 // ---------- display Todos] -------------- 1332 // ---------- display Todos] --------------
1333 1333
1334 ++curCol; 1334 ++curCol;
1335 } 1335 }
1336 mAgenda->hideUnused(); 1336 mAgenda->hideUnused();
1337 mAllDayAgenda->hideUnused(); 1337 mAllDayAgenda->hideUnused();
1338 mAgenda->checkScrollBoundaries(); 1338 mAgenda->checkScrollBoundaries();
1339 deleteSelectedDateTime(); 1339 deleteSelectedDateTime();
1340 createDayLabels(); 1340 createDayLabels();
1341 emit incidenceSelected( 0 ); 1341 emit incidenceSelected( 0 );
1342 1342
1343 if ( globalFlagBlockAgenda == 2 ) { 1343 if ( globalFlagBlockAgenda == 2 ) {
1344 if ( KOPrefs::instance()->mSetTimeToDayStartAt ) 1344 if ( KOPrefs::instance()->mSetTimeToDayStartAt )
1345 setStartHour( KOPrefs::instance()->mDayBegins ); 1345 setStartHour( KOPrefs::instance()->mDayBegins );
1346 else if ( KOPrefs::instance()->mCenterOnCurrentTime ) 1346 else if ( KOPrefs::instance()->mCenterOnCurrentTime )
1347 setStartHour( QTime::currentTime ().hour() ); 1347 setStartHour( QTime::currentTime ().hour() );
1348 } 1348 }
1349 qApp->processEvents(); 1349 qApp->processEvents();
1350 globalFlagBlockAgenda = 0; 1350 globalFlagBlockAgenda = 0;
1351 mAllDayAgenda->drawContentsToPainter(); 1351 mAllDayAgenda->drawContentsToPainter();
1352 mAgenda->drawContentsToPainter(); 1352 mAgenda->drawContentsToPainter();
1353 repaintAgenda(); 1353 repaintAgenda();
1354 startIdleTimeout(); 1354 startIdleTimeout();
1355 onlyOne = false; 1355 onlyOne = false;
1356} 1356}
1357void KOAgendaView::repaintAgenda() 1357void KOAgendaView::repaintAgenda()
1358{ 1358{
1359 mAgenda->viewport()->repaint( false ); 1359 mAgenda->viewport()->repaint( false );
1360 mAllDayAgenda->viewport()->repaint( false ); 1360 mAllDayAgenda->viewport()->repaint( false );
1361 mAgenda->finishUpdate(); 1361 mAgenda->finishUpdate();
1362 mAllDayAgenda->finishUpdate(); 1362 mAllDayAgenda->finishUpdate();
1363} 1363}
1364 1364
1365 1365
1366void KOAgendaView::clearView() 1366void KOAgendaView::clearView()
1367{ 1367{
1368 mAllDayAgenda->clear(); 1368 mAllDayAgenda->clear();
1369 mAgenda->clear(); 1369 mAgenda->clear();
1370} 1370}
1371void KOAgendaView::clearList() 1371void KOAgendaView::clearList()
1372{ 1372{
1373 clearView(); 1373 clearView();
1374 mAllDayAgenda->hideUnused(); 1374 mAllDayAgenda->hideUnused();
1375 mAgenda->hideUnused(); 1375 mAgenda->hideUnused();
1376} 1376}
1377 1377
1378void KOAgendaView::printPreview(CalPrinter *calPrinter, const QDate &fd, 1378void KOAgendaView::printPreview(CalPrinter *calPrinter, const QDate &fd,
1379 const QDate &td) 1379 const QDate &td)
1380{ 1380{
1381#ifndef KORG_NOPRINTER 1381#ifndef KORG_NOPRINTER
1382 if (fd == td) 1382 if (fd == td)
1383 calPrinter->preview(CalPrinter::Day, fd, td); 1383 calPrinter->preview(CalPrinter::Day, fd, td);
1384 else 1384 else
1385 calPrinter->preview(CalPrinter::Week, fd, td); 1385 calPrinter->preview(CalPrinter::Week, fd, td);
1386#endif 1386#endif
1387} 1387}
1388 1388
1389// void KOAgendaView::updateMovedTodo() 1389// void KOAgendaView::updateMovedTodo()
1390// { 1390// {
1391// // updateConfig(); 1391// // updateConfig();
1392// // emit updateTodoViews(); 1392// // emit updateTodoViews();
1393// } 1393// }
1394 1394
1395void KOAgendaView::slotShowDateView( int mode , int d ) 1395void KOAgendaView::slotShowDateView( int mode , int d )
1396{ 1396{
1397 if ( d >= mSelectedDates.count() ) { 1397 if ( d >= mSelectedDates.count() ) {
1398 qDebug("KOAgendaView::slotShowDateView datecounterror %d %d ", d, mSelectedDates.count() ); 1398 qDebug("KOAgendaView::slotShowDateView datecounterror %d %d ", d, mSelectedDates.count() );
1399 1399
1400 } else { 1400 } else {
1401 QDate day = mSelectedDates[d]; 1401 QDate day = mSelectedDates[d];
1402 emit showDateView(mode , day ); 1402 emit showDateView(mode , day );
1403 } 1403 }
1404 1404
1405} 1405}
1406void KOAgendaView::newEvent(int gx, int gy) 1406void KOAgendaView::newEvent(int gx, int gy)
1407{ 1407{
1408 if (!mSelectedDates.count()) return; 1408 if (!mSelectedDates.count()) return;
1409 1409
1410 QDate day = mSelectedDates[gx]; 1410 QDate day = mSelectedDates[gx];
1411 1411
1412 QTime time = mAgenda->gyToTime(gy); 1412 QTime time = mAgenda->gyToTime(gy);
1413 QDateTime dt(day,time); 1413 QDateTime dt(day,time);
1414 // if ( dt < QDateTime::currentDateTime () ) 1414 // if ( dt < QDateTime::currentDateTime () )
1415 // dt = QDateTime::currentDateTime ().addSecs( 3600 ); 1415 // dt = QDateTime::currentDateTime ().addSecs( 3600 );
1416 emit newEventSignal(dt); 1416 emit newEventSignal(dt);
1417} 1417}
1418 1418
1419void KOAgendaView::newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd) 1419void KOAgendaView::newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd)
1420{ 1420{
1421 if (!mSelectedDates.count()) return; 1421 if (!mSelectedDates.count()) return;
1422 1422
1423 QDate dayStart = mSelectedDates[gxStart]; 1423 QDate dayStart = mSelectedDates[gxStart];
1424 QDate dayEnd = mSelectedDates[gxEnd]; 1424 QDate dayEnd = mSelectedDates[gxEnd];
1425 1425
1426 QTime timeStart = mAgenda->gyToTime(gyStart); 1426 QTime timeStart = mAgenda->gyToTime(gyStart);
1427 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); 1427 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 );
1428 1428
1429 QDateTime dtStart(dayStart,timeStart); 1429 QDateTime dtStart(dayStart,timeStart);
1430 QDateTime dtEnd(dayEnd,timeEnd); 1430 QDateTime dtEnd(dayEnd,timeEnd);
1431 1431
1432 emit newEventSignal(dtStart,dtEnd); 1432 emit newEventSignal(dtStart,dtEnd);
1433} 1433}
1434 1434
1435void KOAgendaView::newEventAllDay(int gx, int ) 1435void KOAgendaView::newEventAllDay(int gx, int )
1436{ 1436{
1437 if (!mSelectedDates.count()) return; 1437 if (!mSelectedDates.count()) return;
1438 1438
1439 QDate day = mSelectedDates[gx]; 1439 QDate day = mSelectedDates[gx];
1440 1440
1441 emit newEventSignal(day); 1441 emit newEventSignal(day);
1442} 1442}
1443void KOAgendaView::newTodoAllDay(int gx, int ) 1443void KOAgendaView::newTodoAllDay(int gx, int )
1444{ 1444{
1445 if (!mSelectedDates.count()) return; 1445 if (!mSelectedDates.count()) return;
1446 1446
1447 QDateTime day (mSelectedDates[gx] ); 1447 QDateTime day (mSelectedDates[gx] );
1448 emit newTodoSignal(day, true); 1448 emit newTodoSignal(day, true);
1449} 1449}
1450void KOAgendaView::newTodo(int gx, int gy ) 1450void KOAgendaView::newTodo(int gx, int gy )
1451{ 1451{
1452 if (!mSelectedDates.count()) return; 1452 if (!mSelectedDates.count()) return;
1453 QDate dayStart = mSelectedDates[gx]; 1453 QDate dayStart = mSelectedDates[gx];
1454 QTime timeStart = mAgenda->gyToTime(gy); 1454 QTime timeStart = mAgenda->gyToTime(gy);
1455 QDateTime dt (dayStart,timeStart); 1455 QDateTime dt (dayStart,timeStart);
1456 emit newTodoSignal( dt, false ); 1456 emit newTodoSignal( dt, false );
1457} 1457}
1458 1458
1459void KOAgendaView::updateEventIndicatorTop(int newY) 1459void KOAgendaView::updateEventIndicatorTop(int newY)
1460{ 1460{
1461 uint i; 1461 uint i;
1462 for(i=0;i<mMinY.size();++i) { 1462 for(i=0;i<mMinY.size();++i) {
1463 if (newY >= mMinY.at(i)) mEventIndicatorTop->enableColumn(i,true); 1463 if (newY >= mMinY.at(i)) mEventIndicatorTop->enableColumn(i,true);
1464 else mEventIndicatorTop->enableColumn(i,false); 1464 else mEventIndicatorTop->enableColumn(i,false);
1465 } 1465 }
1466 1466
1467 mEventIndicatorTop->update(); 1467 mEventIndicatorTop->update();
1468} 1468}
1469 1469
1470void KOAgendaView::updateEventIndicatorBottom(int newY) 1470void KOAgendaView::updateEventIndicatorBottom(int newY)
1471{ 1471{
1472 uint i; 1472 uint i;
1473 for(i=0;i<mMaxY.size();++i) { 1473 for(i=0;i<mMaxY.size();++i) {
1474 if (newY <= mMaxY.at(i)) mEventIndicatorBottom->enableColumn(i,true); 1474 if (newY <= mMaxY.at(i)) mEventIndicatorBottom->enableColumn(i,true);
1475 else mEventIndicatorBottom->enableColumn(i,false); 1475 else mEventIndicatorBottom->enableColumn(i,false);
1476 } 1476 }
1477 1477
1478 mEventIndicatorBottom->update(); 1478 mEventIndicatorBottom->update();
1479} 1479}
1480 1480
1481void KOAgendaView::startDrag(Event *event) 1481void KOAgendaView::startDrag(Event *event)
1482{ 1482{
1483#ifndef KORG_NODND 1483#ifndef KORG_NODND
1484 DndFactory factory( calendar() ); 1484 DndFactory factory( calendar() );
1485 ICalDrag *vd = factory.createDrag(event,this); 1485 ICalDrag *vd = factory.createDrag(event,this);
1486 if (vd->drag()) { 1486 if (vd->drag()) {
1487 kdDebug() << "KOAgendaView::startDrag(): Delete drag source" << endl; 1487 kdDebug() << "KOAgendaView::startDrag(): Delete drag source" << endl;
1488 } 1488 }
1489#endif 1489#endif
1490} 1490}
1491 1491
1492void KOAgendaView::readSettings() 1492void KOAgendaView::readSettings()
1493{ 1493{
1494 readSettings(KOGlobals::config()); 1494 readSettings(KOGlobals::config());
1495} 1495}
1496 1496
1497void KOAgendaView::readSettings(KConfig *config) 1497void KOAgendaView::readSettings(KConfig *config)
1498{ 1498{
1499 // kdDebug() << "KOAgendaView::readSettings()" << endl; 1499 // kdDebug() << "KOAgendaView::readSettings()" << endl;
1500 1500
1501 config->setGroup("Views"); 1501 config->setGroup("Views");
1502 1502
1503 //#ifndef KORG_NOSPLITTER 1503 //#ifndef KORG_NOSPLITTER
1504 QValueList<int> sizes = config->readIntListEntry("Separator AgendaView"); 1504 QValueList<int> sizes = config->readIntListEntry("Separator AgendaView");
1505 if (sizes.count() == 2) { 1505 if (sizes.count() == 2) {
1506 if ( sizes[0] < 20 ) { 1506 if ( sizes[0] < 20 ) {
1507 sizes[1] = sizes[1] +20 - sizes[0]; 1507 sizes[1] = sizes[1] +20 - sizes[0];
1508 sizes[0] = 20; 1508 sizes[0] = 20;
1509 } 1509 }
1510 mSplitterAgenda->setSizes(sizes); 1510 mSplitterAgenda->setSizes(sizes);
1511 // qDebug("read %d %d ",sizes[0],sizes[1] ); 1511 // qDebug("read %d %d ",sizes[0],sizes[1] );
1512 } 1512 }
1513 //#endif 1513 //#endif
1514 1514
1515 // updateConfig(); 1515 // updateConfig();
1516} 1516}
1517 1517
1518void KOAgendaView::writeSettings(KConfig *config) 1518void KOAgendaView::writeSettings(KConfig *config)
1519{ 1519{
1520 // kdDebug() << "KOAgendaView::writeSettings()" << endl; 1520 // kdDebug() << "KOAgendaView::writeSettings()" << endl;
1521 1521
1522 config->setGroup("Views"); 1522 config->setGroup("Views");
1523 1523
1524 //#ifndef KORG_NOSPLITTER 1524 //#ifndef KORG_NOSPLITTER
1525 QValueList<int> list = mSplitterAgenda->sizes(); 1525 QValueList<int> list = mSplitterAgenda->sizes();
1526 config->writeEntry("Separator AgendaView",list); 1526 config->writeEntry("Separator AgendaView",list);
1527 //qDebug("write %d %d ", list[0],list[1] ); 1527 //qDebug("write %d %d ", list[0],list[1] );
1528 //#endif 1528 //#endif
1529} 1529}
1530 1530
1531void KOAgendaView::setHolidayMasks() 1531void KOAgendaView::setHolidayMasks()
1532{ 1532{
1533 mHolidayMask.resize(mSelectedDates.count()); 1533 mHolidayMask.resize(mSelectedDates.count());
1534 1534
1535 uint i; 1535 uint i;
1536 for(i=0;i<mSelectedDates.count();++i) { 1536 for(i=0;i<mSelectedDates.count();++i) {
1537 QDate date = mSelectedDates[i]; 1537 QDate date = mSelectedDates[i];
1538 bool showSaturday = KOPrefs::instance()->mExcludeSaturdays && (date.dayOfWeek() == 6); 1538 bool showSaturday = KOPrefs::instance()->mExcludeSaturdays && (date.dayOfWeek() == 6);
1539 bool showSunday = KOPrefs::instance()->mExcludeHolidays && (date.dayOfWeek() == 7); 1539 bool showSunday = KOPrefs::instance()->mExcludeHolidays && (date.dayOfWeek() == 7);
1540 bool showHoliday = false; 1540 bool showHoliday = false;
1541 if ( KOPrefs::instance()->mExcludeHolidays ) { 1541 if ( KOPrefs::instance()->mExcludeHolidays ) {
1542 QPtrList<Event> events = calendar()->events( date, true ); 1542 QPtrList<Event> events = calendar()->events( date, true );
1543 Event *event; 1543 Event *event;
1544 for( event = events.first(); event; event = events.next() ) { 1544 for( event = events.first(); event; event = events.next() ) {
1545 if ( event->isHoliday()) { 1545 if ( event->isHoliday()) {
1546 showHoliday = true; 1546 showHoliday = true;
1547 break; 1547 break;
1548 } 1548 }
1549 } 1549 }
1550 1550
1551 } 1551 }
1552 1552
1553#ifndef KORG_NOPLUGINS 1553#ifndef KORG_NOPLUGINS
1554 bool showHoliday = KOPrefs::instance()->mExcludeHolidays && 1554 bool showHoliday = KOPrefs::instance()->mExcludeHolidays &&
1555 !KOCore::self()->holiday(date).isEmpty(); 1555 !KOCore::self()->holiday(date).isEmpty();
1556#endif 1556#endif
1557 bool showDay = showSaturday || showSunday || showHoliday; 1557 bool showDay = showSaturday || showSunday || showHoliday;
1558 1558
1559 if (showDay) { 1559 if (showDay) {
1560 mHolidayMask.at(i) = true; 1560 mHolidayMask.at(i) = true;
1561 } else { 1561 } else {
1562 mHolidayMask.at(i) = false; 1562 mHolidayMask.at(i) = false;
1563 } 1563 }
1564 } 1564 }
1565 1565
1566 mAgenda->setHolidayMask(&mHolidayMask); 1566 mAgenda->setHolidayMask(&mHolidayMask);
1567 mAllDayAgenda->setHolidayMask(&mHolidayMask); 1567 mAllDayAgenda->setHolidayMask(&mHolidayMask);
1568} 1568}
1569 1569
1570void KOAgendaView::setContentsPos(int y) 1570void KOAgendaView::setContentsPos(int y)
1571{ 1571{
1572 mAgenda->setContentsPos(0,y); 1572 mAgenda->setContentsPos(0,y);
1573} 1573}
1574 1574
1575void KOAgendaView::clearSelection() 1575void KOAgendaView::clearSelection()
1576{ 1576{
1577 mAgenda->deselectItem(); 1577 mAgenda->deselectItem();
1578 mAllDayAgenda->deselectItem(); 1578 mAllDayAgenda->deselectItem();
1579} 1579}
1580 1580
1581void KOAgendaView::newTimeSpanSelectedAllDay(int gxStart, int gyStart, 1581void KOAgendaView::newTimeSpanSelectedAllDay(int gxStart, int gyStart,
1582 int gxEnd, int gyEnd) 1582 int gxEnd, int gyEnd)
1583{ 1583{
1584 mTimeSpanInAllDay = true; 1584 mTimeSpanInAllDay = true;
1585 newTimeSpanSelected(gxStart,gyStart,gxEnd,gyEnd); 1585 newTimeSpanSelected(gxStart,gyStart,gxEnd,gyEnd);
1586} 1586}
1587 1587
1588 1588
1589 1589
1590 1590
1591void KOAgendaView::newTimeSpanSelected(int gxStart, int gyStart, 1591void KOAgendaView::newTimeSpanSelected(int gxStart, int gyStart,
1592 int gxEnd, int gyEnd) 1592 int gxEnd, int gyEnd)
1593{ 1593{
1594 if (!mSelectedDates.count()) return; 1594 if (!mSelectedDates.count()) return;
1595 1595
1596 QDate dayStart = mSelectedDates[gxStart]; 1596 QDate dayStart = mSelectedDates[gxStart];
1597 QDate dayEnd = mSelectedDates[gxEnd]; 1597 QDate dayEnd = mSelectedDates[gxEnd];
1598 1598
1599 QTime timeStart = mAgenda->gyToTime(gyStart); 1599 QTime timeStart = mAgenda->gyToTime(gyStart);
1600 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); 1600 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 );
1601 1601
1602 QDateTime dtStart(dayStart,timeStart); 1602 QDateTime dtStart(dayStart,timeStart);
1603 QDateTime dtEnd(dayEnd,timeEnd); 1603 QDateTime dtEnd(dayEnd,timeEnd);
1604 1604
1605 mTimeSpanBegin = dtStart; 1605 mTimeSpanBegin = dtStart;
1606 mTimeSpanEnd = dtEnd; 1606 mTimeSpanEnd = dtEnd;
1607 1607
1608} 1608}
1609 1609
1610void KOAgendaView::deleteSelectedDateTime() 1610void KOAgendaView::deleteSelectedDateTime()
1611{ 1611{
1612 mTimeSpanBegin.setDate(QDate()); 1612 mTimeSpanBegin.setDate(QDate());
1613 mTimeSpanEnd.setDate(QDate()); 1613 mTimeSpanEnd.setDate(QDate());
1614 mTimeSpanInAllDay = false; 1614 mTimeSpanInAllDay = false;
1615} 1615}
1616 1616
1617void KOAgendaView::keyPressEvent ( QKeyEvent * e ) 1617void KOAgendaView::keyPressEvent ( QKeyEvent * e )
1618{ 1618{
1619 e->ignore(); 1619 e->ignore();
1620} 1620}
1621 1621
1622void KOAgendaView::scrollOneHourUp() 1622void KOAgendaView::scrollOneHourUp()
1623{ 1623{
1624 1624
1625 mAgenda->scrollBy ( 0, -mAgenda->contentsHeight () / 24 ); 1625 mAgenda->scrollBy ( 0, -mAgenda->contentsHeight () / 24 );
1626} 1626}
1627void KOAgendaView::scrollOneHourDown() 1627void KOAgendaView::scrollOneHourDown()
1628{ 1628{
1629 mAgenda->scrollBy ( 0, mAgenda->contentsHeight () / 24 ); 1629 mAgenda->scrollBy ( 0, mAgenda->contentsHeight () / 24 );
1630} 1630}
1631 1631
1632void KOAgendaView::setStartHour( int h ) 1632void KOAgendaView::setStartHour( int h )
1633{ 1633{
1634 mAgenda->setStartHour( h ); 1634 mAgenda->setStartHour( h );
1635 1635
1636} 1636}
1637void KOAgendaView::setInitStartHour() 1637void KOAgendaView::setInitStartHour()
1638{ 1638{
1639 1639
1640 if ( KOPrefs::instance()->mCenterOnCurrentTime ) 1640 if ( KOPrefs::instance()->mCenterOnCurrentTime )
1641 setStartHour( QTime::currentTime ().hour() ); 1641 setStartHour( QTime::currentTime ().hour() );
1642 else 1642 else
1643 setStartHour( KOPrefs::instance()->mDayBegins ); 1643 setStartHour( KOPrefs::instance()->mDayBegins );
1644 1644
1645} 1645}
1646 1646
1647 1647
1648void KOAgendaView::updateTodo( Todo * t, int ) 1648void KOAgendaView::updateTodo( Todo * t, int )
1649{ 1649{
1650 if ( !isVisible() ) 1650 if ( !isVisible() )
1651 return; 1651 return;
1652 bool remove = false; 1652 bool remove = false;
1653 bool removeAD = false; 1653 bool removeAD = false;
1654 QDate da; 1654 QDate da;
1655 if ( t->hasCompletedDate() ) 1655 if ( t->hasCompletedDate() )
1656 da = t->completed().date(); 1656 da = t->completed().date();
1657 else 1657 else
1658 da = t->dtDue().date(); 1658 da = t->dtDue().date();
1659 if ( ! t->hasDueDate() && !t->hasCompletedDate() ) { 1659 if ( ! t->hasDueDate() && !t->hasCompletedDate() ) {
1660 remove = true; 1660 remove = true;
1661 removeAD = true; 1661 removeAD = true;
1662 } 1662 }
1663 else { 1663 else {
1664 bool overdue = (!t->isCompleted()) && (t->dtDue() < QDate::currentDate()) && KOPrefs::instance()->mShowTodoInAgenda ; 1664 bool overdue = (!t->isCompleted()) && (t->dtDue() < QDate::currentDate()) && KOPrefs::instance()->mShowTodoInAgenda ;
1665 if ( overdue && 1665 if ( overdue &&
1666 QDate::currentDate() >= mSelectedDates.first() && 1666 QDate::currentDate() >= mSelectedDates.first() &&
1667 QDate::currentDate() <= mSelectedDates.last()) { 1667 QDate::currentDate() <= mSelectedDates.last()) {
1668 removeAD = false; 1668 removeAD = false;
1669 remove = true; 1669 remove = true;
1670 } 1670 }
1671 else { 1671 else {
1672 1672
1673 if ( da < mSelectedDates.first() || 1673 if ( da < mSelectedDates.first() ||
1674 da > mSelectedDates.last() ) { 1674 da > mSelectedDates.last() ) {
1675 remove = true; 1675 remove = true;
1676 removeAD = true; 1676 removeAD = true;
1677 } else { 1677 } else {
1678 remove = t->doesFloat() && !t->hasCompletedDate(); 1678 remove = t->doesFloat() && !t->hasCompletedDate();
1679 removeAD = !remove; 1679 removeAD = !remove;
1680 } 1680 }
1681 } 1681 }
1682 } 1682 }
1683 int days = mSelectedDates.first().daysTo( da ); 1683 int days = mSelectedDates.first().daysTo( da );
1684 //qDebug("daysto %d %d %d", days, remove,removeAD ); 1684 //qDebug("daysto %d %d %d", days, remove,removeAD );
1685 mAgenda->updateTodo( t , days, remove); 1685 mAgenda->updateTodo( t , days, remove);
1686 if ( KOPrefs::instance()->mShowTodoInAgenda ) 1686 if ( KOPrefs::instance()->mShowTodoInAgenda )
1687 mAllDayAgenda->updateTodo( t , days, removeAD); 1687 mAllDayAgenda->updateTodo( t , days, removeAD);
1688 //qDebug("KOAgendaView::updateTodo( Todo *, int ) "); 1688 //qDebug("KOAgendaView::updateTodo( Todo *, int ) ");
1689 1689
1690} 1690}
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index ec1154a..057df0d 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -1,1217 +1,1217 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at> 3 Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at>
4 Parts of the source code have been copied from kdpdatebutton.cpp 4 Parts of the source code have been copied from kdpdatebutton.cpp
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or 8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software 17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 19
20 As a special exception, permission is given to link this program 20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable, 21 with any edition of Qt, and distribute the resulting executable,
22 without including the source ode for Qt in the source distribution. 22 without including the source ode for Qt in the source distribution.
23*/ 23*/
24 24
25#include <qevent.h> 25#include <qevent.h>
26#include <qpainter.h> 26#include <qpainter.h>
27#include <qptrlist.h> 27#include <qptrlist.h>
28#include <qtimer.h> 28#include <qtimer.h>
29#include <qwhatsthis.h> 29#include <qwhatsthis.h>
30 30
31#include <kglobal.h> 31#include <kglobal.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <klocale.h> 33#include <klocale.h>
34 34
35#include <libkcal/vcaldrag.h> 35#include <libkcal/vcaldrag.h>
36#include <libkcal/icaldrag.h> 36#include <libkcal/icaldrag.h>
37#include <libkcal/dndfactory.h> 37#include <libkcal/dndfactory.h>
38#include <libkcal/calendarresources.h> 38#include <libkcal/calendarresources.h>
39#include <libkcal/resourcecalendar.h> 39#include <libkcal/resourcecalendar.h>
40#include <kresources/resourceselectdialog.h> 40#include <kresources/resourceselectdialog.h>
41 41
42#include <kcalendarsystem.h> 42#include <kcalendarsystem.h>
43 43
44#ifndef KORG_NOPLUGINS 44#ifndef KORG_NOPLUGINS
45#include "kocore.h" 45#include "kocore.h"
46#endif 46#endif
47#include "koprefs.h" 47#include "koprefs.h"
48#include "koglobals.h" 48#include "koglobals.h"
49 49
50#include "kodaymatrix.h" 50#include "kodaymatrix.h"
51 51
52// ============================================================================ 52// ============================================================================
53// D Y N A M I C T I P 53// D Y N A M I C T I P
54// ============================================================================ 54// ============================================================================
55 55
56DynamicTip::DynamicTip( QWidget * parent ) 56DynamicTip::DynamicTip( QWidget * parent )
57 : QToolTip( parent ) 57 : QToolTip( parent )
58{ 58{
59 matrix = (KODayMatrix*)parent; 59 matrix = (KODayMatrix*)parent;
60} 60}
61 61
62class KODaymatrixWhatsThis :public QWhatsThis 62class KODaymatrixWhatsThis :public QWhatsThis
63{ 63{
64public: 64public:
65 KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;}; 65 KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;};
66 ~KODaymatrixWhatsThis() { ; }; 66 ~KODaymatrixWhatsThis() { ; };
67 67
68protected: 68protected:
69 virtual QString text( const QPoint& p ) 69 virtual QString text( const QPoint& p )
70 { 70 {
71 return _view->getWhatsThisText( p ) ; 71 return _view->getWhatsThisText( p ) ;
72 } 72 }
73private: 73private:
74 KODayMatrix * _view; 74 KODayMatrix * _view;
75}; 75};
76 76
77void DynamicTip::maybeTip( const QPoint &pos ) 77void DynamicTip::maybeTip( const QPoint &pos )
78{ 78{
79 //calculate which cell of the matrix the mouse is in 79 //calculate which cell of the matrix the mouse is in
80 QRect sz = matrix->frameRect(); 80 QRect sz = matrix->frameRect();
81 int dheight = sz.height()*7 / 42; 81 int dheight = sz.height()*7 / 42;
82 int dwidth = sz.width() / 7; 82 int dwidth = sz.width() / 7;
83 int row = pos.y()/dheight; 83 int row = pos.y()/dheight;
84 int col = pos.x()/dwidth; 84 int col = pos.x()/dwidth;
85 85
86 QRect rct(col*dwidth, row*dheight, dwidth, dheight); 86 QRect rct(col*dwidth, row*dheight, dwidth, dheight);
87 87
88// kdDebug() << "DynamicTip::maybeTip matrix cell index [" << 88// kdDebug() << "DynamicTip::maybeTip matrix cell index [" <<
89// col << "][" << row << "] => " <<(col+row*7) << endl; 89// col << "][" << row << "] => " <<(col+row*7) << endl;
90 90
91 //show holiday names only 91 //show holiday names only
92 QString str = matrix->getHolidayLabel(col+row*7); 92 QString str = matrix->getHolidayLabel(col+row*7);
93 if (str.isEmpty()) return; 93 if (str.isEmpty()) return;
94 tip(rct, str); 94 tip(rct, str);
95} 95}
96 96
97 97
98// ============================================================================ 98// ============================================================================
99// K O D A Y M A T R I X 99// K O D A Y M A T R I X
100// ============================================================================ 100// ============================================================================
101 101
102const int KODayMatrix::NOSELECTION = -1000; 102const int KODayMatrix::NOSELECTION = -1000;
103const int KODayMatrix::NUMDAYS = 42; 103const int KODayMatrix::NUMDAYS = 42;
104 104
105KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) 105KODayMatrix::KODayMatrix( QWidget *parent, const char *name )
106 : QFrame( parent, name , Qt::WRepaintNoErase ), mCalendar( 0 ) 106 : QFrame( parent, name , Qt::WRepaintNoErase ), mCalendar( 0 )
107 107
108 108
109{ 109{
110 mLastView = -1; 110 mLastView = -1;
111 oldW = 0; 111 oldW = 0;
112 oldH = 0; 112 oldH = 0;
113 myPix.resize( 150, 120 ); 113 myPix.resize( 150, 120 );
114 mRedrawNeeded = true; 114 mRedrawNeeded = true;
115 mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this); 115 mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this);
116 mPendingUpdateBeforeRepaint = false; 116 mPendingUpdateBeforeRepaint = false;
117 mouseDown = false; 117 mouseDown = false;
118 // initialize dynamic arrays 118 // initialize dynamic arrays
119 bDays.resize ( NUMDAYS ); 119 bDays.resize ( NUMDAYS );
120 pDays.resize ( NUMDAYS ); 120 pDays.resize ( NUMDAYS );
121 hDays.resize ( NUMDAYS ); 121 hDays.resize ( NUMDAYS );
122 eDays.resize ( NUMDAYS ); 122 eDays.resize ( NUMDAYS );
123 days = new QDate[NUMDAYS]; 123 days = new QDate[NUMDAYS];
124 daylbls = new QString[NUMDAYS]; 124 daylbls = new QString[NUMDAYS];
125 //events = new int[NUMDAYS]; 125 //events = new int[NUMDAYS];
126 mToolTip = new DynamicTip(this); 126 mToolTip = new DynamicTip(this);
127 127
128 // set default values used for drawing the matrix 128 // set default values used for drawing the matrix
129 mDefaultBackColor = palette().active().base(); 129 mDefaultBackColor = palette().active().base();
130 mDefaultTextColor = palette().active().foreground(); 130 mDefaultTextColor = palette().active().foreground();
131 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); 131 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor);
132 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); 132 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor);
133 mSelectedDaysColor = QColor("white"); 133 mSelectedDaysColor = QColor("white");
134 mTodayMarginWidth = 2; 134 mTodayMarginWidth = 2;
135 mSelEnd = mSelStart = NOSELECTION; 135 mSelEnd = mSelStart = NOSELECTION;
136 136
137 setAcceptDrops(true); 137 setAcceptDrops(true);
138 //setFont( QFont("Arial", 10) ); 138 //setFont( QFont("Arial", 10) );
139 139
140 mUpdateTimer = new QTimer( this ); 140 mUpdateTimer = new QTimer( this );
141 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); 141 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() ));
142 mRepaintTimer = new QTimer( this ); 142 mRepaintTimer = new QTimer( this );
143 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); 143 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() ));
144 mDayChanged = false; 144 mDayChanged = false;
145 updateView(); 145 updateView();
146} 146}
147QString KODayMatrix::getWhatsThisText( QPoint p ) 147QString KODayMatrix::getWhatsThisText( QPoint p )
148{ 148{
149 149
150 int tmp = getDayIndexFrom(p.x(), p.y()); 150 int tmp = getDayIndexFrom(p.x(), p.y());
151 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) 151 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar )
152 return QString(); 152 return QString();
153 QDate mDate = days[tmp]; 153 QDate mDate = days[tmp];
154 QPtrList<Event> eventlist = mCalendar->events(mDate); 154 QPtrList<Event> eventlist = mCalendar->events(mDate);
155 Event *event; 155 Event *event;
156 QStringList mToolTip; 156 QStringList mToolTip;
157 for(event=eventlist.first();event != 0;event=eventlist.next()) { 157 for(event=eventlist.first();event != 0;event=eventlist.next()) {
158 QString mToolTipText; 158 QString mToolTipText;
159 QString text; 159 QString text;
160 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day 160 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day
161 if (event->isMultiDay()) { 161 if (event->isMultiDay()) {
162 QString prefix = "<->";multiday = 2; 162 QString prefix = "<->";multiday = 2;
163 QString time; 163 QString time;
164 if ( event->doesRecur() ) { 164 if ( event->doesRecur() ) {
165 if ( event->recursOn( mDate) ) { 165 if ( event->recursOn( mDate) ) {
166 prefix ="->" ;multiday = 1; 166 prefix ="->" ;multiday = 1;
167 } 167 }
168 else { 168 else {
169 int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); 169 int days = event->dtStart().date().daysTo ( event->dtEnd().date() );
170 if ( event->recursOn( mDate.addDays( -days)) ) { 170 if ( event->recursOn( mDate.addDays( -days)) ) {
171 prefix ="<-" ;multiday = 3; 171 prefix ="<-" ;multiday = 3;
172 } 172 }
173 } 173 }
174 } else { 174 } else {
175 if (mDate == event->dtStart().date()) { 175 if (mDate == event->dtStart().date()) {
176 prefix ="->" ;multiday = 1; 176 prefix ="->" ;multiday = 1;
177 } else if (mDate == event->dtEnd().date()) { 177 } else if (mDate == event->dtEnd().date()) {
178 prefix ="<-" ;multiday = 3; 178 prefix ="<-" ;multiday = 3;
179 } 179 }
180 } 180 }
181 if ( !event->doesFloat() ) { 181 if ( !event->doesFloat() ) {
182 if ( mDate == event->dtStart().date () ) 182 if ( mDate == event->dtStart().date () )
183 time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; 183 time = KGlobal::locale()->formatTime(event->dtStart().time())+" ";
184 else if ( mDate == event->dtEnd().date () ) 184 else if ( mDate == event->dtEnd().date () )
185 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; 185 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" ";
186 186
187 } 187 }
188 text = time + event->summary(); 188 text = time + event->summary();
189 mToolTipText += prefix + text; 189 mToolTipText += prefix + text;
190 } else { 190 } else {
191 if (event->doesFloat()) { 191 if (event->doesFloat()) {
192 text = event->summary(); 192 text = event->summary();
193 mToolTipText += text; 193 mToolTipText += text;
194 } 194 }
195 else { 195 else {
196 text = KGlobal::locale()->formatTime(event->dtStart().time()); 196 text = KGlobal::locale()->formatTime(event->dtStart().time());
197 text += " " + event->summary(); 197 text += " " + event->summary();
198 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); 198 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary();
199 } 199 }
200 } 200 }
201 if ( !event->location().isEmpty() ) 201 if ( !event->location().isEmpty() )
202 mToolTipText += " (" + event->location() + ")"; 202 mToolTipText += " (" + event->location() + ")";
203 //qDebug("TTT: %s ", mToolTipText.latin1()); 203 //qDebug("TTT: %s ", mToolTipText.latin1());
204 mToolTip.append( deTag( mToolTipText ) ); 204 mToolTip.append( deTag( mToolTipText ) );
205 } 205 }
206 mToolTip.sort(); 206 mToolTip.sort();
207 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) { 207 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) {
208 QPtrList<Todo> todolist = mCalendar->todos(mDate); 208 QPtrList<Todo> todolist = mCalendar->todos(mDate);
209 Todo *todo; 209 Todo *todo;
210 for(todo=todolist.first();todo != 0;todo=todolist.next()) { 210 for(todo=todolist.first();todo != 0;todo=todolist.next()) {
211 QString mToolTipText; 211 QString mToolTipText;
212 if ( !todo->doesFloat() ) 212 if ( !todo->doesFloat() )
213 mToolTipText += KGlobal::locale()->formatTime(todo->dtDue().time())+" "; 213 mToolTipText += KGlobal::locale()->formatTime(todo->dtDue().time())+" ";
214 mToolTipText += todo->summary(); 214 mToolTipText += todo->summary();
215 if ( !todo->location().isEmpty() ) 215 if ( !todo->location().isEmpty() )
216 mToolTipText += " (" + todo->location() + ")"; 216 mToolTipText += " (" + todo->location() + ")";
217 mToolTipText = deTag( mToolTipText); 217 mToolTipText = deTag( mToolTipText);
218 mToolTipText = "<b>" + i18n("Todo: ") + "</b>"+ mToolTipText; 218 mToolTipText = "<b>" + i18n("Todo: ") + "</b>"+ mToolTipText;
219 mToolTip.append( mToolTipText ); 219 mToolTip.append( mToolTipText );
220 } 220 }
221 } 221 }
222 if (KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) { 222 if (KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) {
223 QPtrList<Journal> j_list = mCalendar->journals4Date( mDate ); 223 QPtrList<Journal> j_list = mCalendar->journals4Date( mDate );
224 Journal *j = j_list.first(); 224 Journal *j = j_list.first();
225 while ( j ) { 225 while ( j ) {
226 QString mToolTipText; 226 QString mToolTipText;
227 if ( !j->summary().isEmpty() ) { 227 if ( !j->summary().isEmpty() ) {
228 mToolTipText = j->summary().left(30); 228 mToolTipText = j->summary().left(30);
229 if ( j->summary().length() > 30 ) 229 if ( j->summary().length() > 30 )
230 mToolTipText += " ..."; 230 mToolTipText += " ...";
231 } else { 231 } else {
232 mToolTipText = j->description().left(25); 232 mToolTipText = j->description().left(25);
233 if ( j->description().length() > 25 ) 233 if ( j->description().length() > 25 )
234 mToolTipText += " ..."; 234 mToolTipText += " ...";
235 mToolTipText = deTag( mToolTipText); 235 mToolTipText = deTag( mToolTipText);
236 } 236 }
237 mToolTipText = "<b>" + i18n("Journal: ") + "</b>"+ mToolTipText; 237 mToolTipText = "<b>" + i18n("Journal: ") + "</b>"+ mToolTipText;
238 mToolTip.append( mToolTipText ); 238 mToolTip.append( mToolTipText );
239 j = j_list.next(); 239 j = j_list.next();
240 } 240 }
241 } 241 }
242 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); 242 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>");
243} 243}
244 244
245 245
246QString KODayMatrix::deTag( QString mToolTipText ) 246QString KODayMatrix::deTag( QString mToolTipText )
247{ 247{
248 248
249#if QT_VERSION >= 0x030000 249#if QT_VERSION >= 0x030000
250 mToolTipText.replace( '<' , "&lt;" ); 250 mToolTipText.replace( '<' , "&lt;" );
251 mToolTipText.replace( '>' , "&gt;" ); 251 mToolTipText.replace( '>' , "&gt;" );
252#else 252#else
253 if ( mToolTipText.find ('<') >= 0 ) { 253 if ( mToolTipText.find ('<') >= 0 ) {
254 mToolTipText.replace( QRegExp("<") , "&lt;" ); 254 mToolTipText.replace( QRegExp("<") , "&lt;" );
255 } 255 }
256 if ( mToolTipText.find ('>') >= 0 ) { 256 if ( mToolTipText.find ('>') >= 0 ) {
257 mToolTipText.replace( QRegExp(">") , "&gt;" ); 257 mToolTipText.replace( QRegExp(">") , "&gt;" );
258 } 258 }
259#endif 259#endif
260 return mToolTipText; 260 return mToolTipText;
261} 261}
262void KODayMatrix::setCalendar( Calendar *cal ) 262void KODayMatrix::setCalendar( Calendar *cal )
263{ 263{
264 mCalendar = cal; 264 mCalendar = cal;
265 265
266 setAcceptDrops( mCalendar ); 266 setAcceptDrops( mCalendar );
267 267
268 updateEvents(); 268 updateEvents();
269} 269}
270 270
271QColor KODayMatrix::getShadedColor(QColor color) 271QColor KODayMatrix::getShadedColor(QColor color)
272{ 272{
273 QColor shaded; 273 QColor shaded;
274 int h=0; 274 int h=0;
275 int s=0; 275 int s=0;
276 int v=0; 276 int v=0;
277 color.hsv(&h,&s,&v); 277 color.hsv(&h,&s,&v);
278 s = s/4; 278 s = s/4;
279 v = 192+v/4; 279 v = 192+v/4;
280 shaded.setHsv(h,s,v); 280 shaded.setHsv(h,s,v);
281 281
282 return shaded; 282 return shaded;
283} 283}
284 284
285KODayMatrix::~KODayMatrix() 285KODayMatrix::~KODayMatrix()
286{ 286{
287#if QT_VERSION >= 0x030000 287#if QT_VERSION >= 0x030000
288 288
289#else 289#else
290 delete mKODaymatrixWhatsThis; 290 delete mKODaymatrixWhatsThis;
291#endif 291#endif
292 292
293 // delete mKODaymatrixWhatsThis; 293 // delete mKODaymatrixWhatsThis;
294 delete [] days; 294 delete [] days;
295 delete [] daylbls; 295 delete [] daylbls;
296 //delete [] events; 296 //delete [] events;
297 delete mToolTip; 297 delete mToolTip;
298} 298}
299 299
300/* 300/*
301void KODayMatrix::setStartDate(QDate start) 301void KODayMatrix::setStartDate(QDate start)
302{ 302{
303 updateView(start); 303 updateView(start);
304} 304}
305*/ 305*/
306 306
307void KODayMatrix::addSelectedDaysTo(DateList& selDays) 307void KODayMatrix::addSelectedDaysTo(DateList& selDays)
308{ 308{
309 309
310 if (mSelStart == NOSELECTION) { 310 if (mSelStart == NOSELECTION) {
311 return; 311 return;
312 } 312 }
313 313
314 //cope with selection being out of matrix limits at top (< 0) 314 //cope with selection being out of matrix limits at top (< 0)
315 int i0 = mSelStart; 315 int i0 = mSelStart;
316 if (i0 < 0) { 316 if (i0 < 0) {
317 for (int i = i0; i < 0; i++) { 317 for (int i = i0; i < 0; i++) {
318 selDays.append(days[0].addDays(i)); 318 selDays.append(days[0].addDays(i));
319 } 319 }
320 i0 = 0; 320 i0 = 0;
321 } 321 }
322 322
323 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) 323 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1)
324 if (mSelEnd > NUMDAYS-1) { 324 if (mSelEnd > NUMDAYS-1) {
325 for (int i = i0; i <= NUMDAYS-1; i++) { 325 for (int i = i0; i <= NUMDAYS-1; i++) {
326 selDays.append(days[i]); 326 selDays.append(days[i]);
327 } 327 }
328 for (int i = NUMDAYS; i < mSelEnd; i++) { 328 for (int i = NUMDAYS; i < mSelEnd; i++) {
329 selDays.append(days[0].addDays(i)); 329 selDays.append(days[0].addDays(i));
330 } 330 }
331 331
332 // apply normal routine to selection being entirely within matrix limits 332 // apply normal routine to selection being entirely within matrix limits
333 } else { 333 } else {
334 for (int i = i0; i <= mSelEnd; i++) { 334 for (int i = i0; i <= mSelEnd; i++) {
335 selDays.append(days[i]); 335 selDays.append(days[i]);
336 } 336 }
337 } 337 }
338} 338}
339 339
340bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) 340bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end)
341{ 341{
342 mRedrawNeeded = true; 342 mRedrawNeeded = true;
343 bool noSel = (mSelEnd == NOSELECTION && mSelStart == NOSELECTION ); 343 bool noSel = (mSelEnd == NOSELECTION && mSelStart == NOSELECTION );
344 mSelStart = startdate.daysTo(start); 344 mSelStart = startdate.daysTo(start);
345 if ( mSelStart < 0 ) 345 if ( mSelStart < 0 )
346 mSelStart = 0; 346 mSelStart = 0;
347 mSelEnd = startdate.daysTo(end); 347 mSelEnd = startdate.daysTo(end);
348 if ( mSelEnd > NUMDAYS-1 ) 348 if ( mSelEnd > NUMDAYS-1 )
349 mSelEnd = NUMDAYS-1; 349 mSelEnd = NUMDAYS-1;
350 if ( mSelEnd < 0 || mSelStart > NUMDAYS-1 ) { 350 if ( mSelEnd < 0 || mSelStart > NUMDAYS-1 ) {
351 clearSelection(); 351 clearSelection();
352 if ( noSel ) 352 if ( noSel )
353 return false; 353 return false;
354 } 354 }
355 355
356 return true; 356 return true;
357} 357}
358void KODayMatrix::clearSelection() 358void KODayMatrix::clearSelection()
359{ 359{
360 mSelEnd = mSelStart = NOSELECTION; 360 mSelEnd = mSelStart = NOSELECTION;
361} 361}
362 362
363 363
364void KODayMatrix::recalculateToday() 364void KODayMatrix::recalculateToday()
365{ 365{
366 today = -1; 366 today = -1;
367 for (int i=0; i<NUMDAYS; i++) { 367 for (int i=0; i<NUMDAYS; i++) {
368 //events[i] = 0; 368 //events[i] = 0;
369 days[i] = startdate.addDays(i); 369 days[i] = startdate.addDays(i);
370 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); 370 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] ));
371 371
372 // if today is in the currently displayed month, hilight today 372 // if today is in the currently displayed month, hilight today
373 if (days[i].year() == QDate::currentDate().year() && 373 if (days[i].year() == QDate::currentDate().year() &&
374 days[i].month() == QDate::currentDate().month() && 374 days[i].month() == QDate::currentDate().month() &&
375 days[i].day() == QDate::currentDate().day()) { 375 days[i].day() == QDate::currentDate().day()) {
376 today = i; 376 today = i;
377 } 377 }
378 } 378 }
379 // qDebug(QString("Today is visible at %1.").arg(today)); 379 // qDebug(QString("Today is visible at %1.").arg(today));
380} 380}
381 381
382void KODayMatrix::updateView() 382void KODayMatrix::updateView()
383{ 383{
384 updateView(startdate); 384 updateView(startdate);
385} 385}
386void KODayMatrix::repaintViewTimed() 386void KODayMatrix::repaintViewTimed()
387{ 387{
388 mRedrawNeeded = true; 388 mRedrawNeeded = true;
389 // bDays.fill( false); 389 // bDays.fill( false);
390 //pDays.fill( false); 390 //pDays.fill( false);
391 //hDays.fill( false); 391 //hDays.fill( false);
392 //eDays.fill( false); 392 //eDays.fill( false);
393 mRepaintTimer->stop(); 393 mRepaintTimer->stop();
394 int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday 394 int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday
395 int i; 395 int i;
396 for(i = 0; i < NUMDAYS; i++) { 396 for(i = 0; i < NUMDAYS; i++) {
397 if ( ( (i+startDay) % 7 == 0 ) ) { 397 if ( ( (i+startDay) % 7 == 0 ) ) {
398 pDays.setBit(i); 398 pDays.setBit(i);
399 } 399 }
400 } 400 }
401 repaint(false); 401 repaint(false);
402} 402}
403void KODayMatrix::computeEvent(Event *event, int i ) 403void KODayMatrix::computeEvent(Event *event, int i )
404{ 404{
405 QString holiStr = mHolidays[i]; 405 QString holiStr = mHolidays[i];
406 if ( event->isHoliday()) { 406 if ( event->isHoliday()) {
407 pDays.setBit(i); 407 pDays.setBit(i);
408 hDays.setBit(i); 408 hDays.setBit(i);
409 if ( !holiStr.isEmpty() ) 409 if ( !holiStr.isEmpty() )
410 holiStr += "\n"; 410 holiStr += "\n";
411 holiStr += event->summary(); 411 holiStr += event->summary();
412 if ( !event->location().isEmpty() ) 412 if ( !event->location().isEmpty() )
413 holiStr += " (" + event->location() + ")"; 413 holiStr += " (" + event->location() + ")";
414 mHolidays[i] =holiStr ; 414 mHolidays[i] =holiStr ;
415 eDays.setBit(i); 415 eDays.setBit(i);
416 } 416 }
417 if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_T_VIEW && KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) { 417 if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_T_VIEW && KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) {
418 if ( event->isBirthday()) { 418 if ( event->isBirthday()) {
419 pDays.setBit(i); 419 pDays.setBit(i);
420 if ( !holiStr.isEmpty() ) 420 if ( !holiStr.isEmpty() )
421 holiStr += "\n"; 421 holiStr += "\n";
422 holiStr += i18n("Birthday") + ": "+event->summary(); 422 holiStr += i18n("Birthday") + ": "+event->summary();
423 if ( !event->location().isEmpty() ) 423 if ( !event->location().isEmpty() )
424 holiStr += " (" + event->location() + ")"; 424 holiStr += " (" + event->location() + ")";
425 bDays.setBit(i); 425 bDays.setBit(i);
426 mHolidays[i] =holiStr ; 426 mHolidays[i] =holiStr ;
427 } 427 }
428 } 428 }
429 if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) 429 if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW )
430 eDays.setBit(i); 430 eDays.setBit(i);
431} 431}
432void KODayMatrix::updateViewTimed() 432void KODayMatrix::updateViewTimed()
433{ 433{
434 mUpdateTimer->stop(); 434 mUpdateTimer->stop();
435 if ( !mCalendar ) { 435 if ( !mCalendar ) {
436 qDebug("NOT CAL "); 436 qDebug("NOT CAL ");
437 return; 437 return;
438 } 438 }
439#if 1 439#if 1
440 440
441 441
442 int i; 442 int i;
443 int timeSpan = NUMDAYS-1; 443 int timeSpan = NUMDAYS-1;
444 QPtrList<Event> events = mCalendar->events(); 444 QPtrList<Event> events = mCalendar->events();
445 Event *event; 445 Event *event;
446 QDateTime dt; 446 QDateTime dt;
447 bool ok; 447 bool ok;
448 bDays.fill( false); 448 bDays.fill( false);
449 pDays.fill( false); 449 pDays.fill( false);
450 hDays.fill( false); 450 hDays.fill( false);
451 eDays.fill( false); 451 eDays.fill( false);
452 mHolidays.clear(); 452 mHolidays.clear();
453 QDate mStartDate = days[0]; 453 QDate mStartDate = days[0];
454 QDate endDate = mStartDate.addDays( timeSpan ); 454 QDate endDate = mStartDate.addDays( timeSpan );
455 for( event = events.first(); event; event = events.next() ) { // for event 455 for( event = events.first(); event; event = events.next() ) { // for event
456 ushort recurType = event->recurrence()->doesRecur(); 456 ushort recurType = event->doesRecur();
457 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || 457 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
458 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { 458 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
459 continue; 459 continue;
460 } 460 }
461 if ( event->doesRecur() ) { 461 if ( event->doesRecur() ) {
462 bool last; 462 bool last;
463 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); 463 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last );
464 QDateTime incidenceEnd; 464 QDateTime incidenceEnd;
465 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); 465 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() );
466 bool invalid = false; 466 bool invalid = false;
467 while( true ) { 467 while( true ) {
468 if ( incidenceStart.isValid() ) { 468 if ( incidenceStart.isValid() ) {
469 incidenceEnd = incidenceStart.addDays( eventlen ); 469 incidenceEnd = incidenceStart.addDays( eventlen );
470 int st = incidenceStart.date().daysTo( endDate ); 470 int st = incidenceStart.date().daysTo( endDate );
471 if ( st >= 0 ) { // start before timeend 471 if ( st >= 0 ) { // start before timeend
472 int end = mStartDate.daysTo( incidenceEnd.date() ); 472 int end = mStartDate.daysTo( incidenceEnd.date() );
473 if ( end >= 0 ) { // end after timestart --- got one! 473 if ( end >= 0 ) { // end after timestart --- got one!
474 //normalize 474 //normalize
475 st = timeSpan - st; 475 st = timeSpan - st;
476 if ( st < 0 ) st = 0; 476 if ( st < 0 ) st = 0;
477 if ( end > timeSpan ) end = timeSpan; 477 if ( end > timeSpan ) end = timeSpan;
478 int iii; 478 int iii;
479 //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); 479 //qDebug("found %s %d %d ",event->summary().latin1(), st, end );
480 for ( iii = st;iii<= end;++iii) { 480 for ( iii = st;iii<= end;++iii) {
481 computeEvent( event, iii ); 481 computeEvent( event, iii );
482 } 482 }
483 } 483 }
484 } 484 }
485 } else { 485 } else {
486 if ( invalid ) 486 if ( invalid )
487 break; 487 break;
488 invalid = true; 488 invalid = true;
489 //qDebug("invalid %s", event->summary().latin1()); 489 //qDebug("invalid %s", event->summary().latin1());
490 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; 490 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );;
491 } 491 }
492 if ( last ) 492 if ( last )
493 break; 493 break;
494 bool ok; 494 bool ok;
495 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); 495 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok );
496 if ( ! ok ) 496 if ( ! ok )
497 break; 497 break;
498 if ( incidenceStart.date() > endDate ) 498 if ( incidenceStart.date() > endDate )
499 break; 499 break;
500 } 500 }
501 } else { // no recur 501 } else { // no recur
502 int st = event->dtStart().date().daysTo( endDate ); 502 int st = event->dtStart().date().daysTo( endDate );
503 if ( st >= 0 ) { // start before timeend 503 if ( st >= 0 ) { // start before timeend
504 int end = mStartDate.daysTo( event->dtEnd().date() ); 504 int end = mStartDate.daysTo( event->dtEnd().date() );
505 if ( end >= 0 ) { // end after timestart --- got one! 505 if ( end >= 0 ) { // end after timestart --- got one!
506 //normalize 506 //normalize
507 st = timeSpan - st; 507 st = timeSpan - st;
508 if ( st < 0 ) st = 0; 508 if ( st < 0 ) st = 0;
509 if ( end > timeSpan ) end = timeSpan; 509 if ( end > timeSpan ) end = timeSpan;
510 int iii; 510 int iii;
511 for ( iii = st;iii<= end;++iii) 511 for ( iii = st;iii<= end;++iii)
512 computeEvent( event, iii ); 512 computeEvent( event, iii );
513 } 513 }
514 } 514 }
515 } 515 }
516 } 516 }
517 int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday 517 int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday
518 for(i = 0; i < NUMDAYS; i++) { 518 for(i = 0; i < NUMDAYS; i++) {
519 if ( ( (i+startDay) % 7 == 0 ) ) { 519 if ( ( (i+startDay) % 7 == 0 ) ) {
520 pDays.setBit(i); 520 pDays.setBit(i);
521 } 521 }
522 } 522 }
523 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) { 523 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) {
524 bDays.fill( false); 524 bDays.fill( false);
525 // insert due todos 525 // insert due todos
526 QPtrList<Todo> todos = mCalendar->todos( ); 526 QPtrList<Todo> todos = mCalendar->todos( );
527 Todo *todo; 527 Todo *todo;
528 for(todo = todos.first(); todo; todo = todos.next()) { 528 for(todo = todos.first(); todo; todo = todos.next()) {
529 //insertTodo( todo ); 529 //insertTodo( todo );
530 if ( todo->hasDueDate() ) { 530 if ( todo->hasDueDate() ) {
531 int day = mStartDate.daysTo( todo->dtDue().date() ); 531 int day = mStartDate.daysTo( todo->dtDue().date() );
532 if ( day >= 0 && day < timeSpan + 1) { 532 if ( day >= 0 && day < timeSpan + 1) {
533 int i = day; 533 int i = day;
534 QString holiStr = mHolidays[i]; 534 QString holiStr = mHolidays[i];
535 pDays.setBit(i); 535 pDays.setBit(i);
536 if ( !holiStr.isEmpty() ) 536 if ( !holiStr.isEmpty() )
537 holiStr += "\n"; 537 holiStr += "\n";
538 holiStr += i18n("Todo") + ": "+todo->summary(); 538 holiStr += i18n("Todo") + ": "+todo->summary();
539 if ( !todo->location().isEmpty() ) 539 if ( !todo->location().isEmpty() )
540 holiStr += " (" + todo->location() + ")"; 540 holiStr += " (" + todo->location() + ")";
541 bDays.setBit(i); 541 bDays.setBit(i);
542 mHolidays[i] =holiStr ; 542 mHolidays[i] =holiStr ;
543 eDays.setBit(i); 543 eDays.setBit(i);
544 } 544 }
545 } 545 }
546 } 546 }
547 } 547 }
548 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) { 548 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) {
549 bDays.fill( false); 549 bDays.fill( false);
550 // insert due todos 550 // insert due todos
551 QPtrList<Journal> todos = mCalendar->journals( ); 551 QPtrList<Journal> todos = mCalendar->journals( );
552 Journal *todo; 552 Journal *todo;
553 for(todo = todos.first(); todo; todo = todos.next()) { 553 for(todo = todos.first(); todo; todo = todos.next()) {
554 int day = mStartDate.daysTo( todo->dtStart().date() ); 554 int day = mStartDate.daysTo( todo->dtStart().date() );
555 if ( day >= 0 && day < timeSpan + 1) { 555 if ( day >= 0 && day < timeSpan + 1) {
556 int i = day; 556 int i = day;
557 QString holiStr = mHolidays[i]; 557 QString holiStr = mHolidays[i];
558 pDays.setBit(i); 558 pDays.setBit(i);
559 if ( !holiStr.isEmpty() ) 559 if ( !holiStr.isEmpty() )
560 holiStr += "\n"; 560 holiStr += "\n";
561 holiStr += i18n("Journal: ")+todo->summary().left(25); 561 holiStr += i18n("Journal: ")+todo->summary().left(25);
562 if ( todo->summary().length() > 25 ) 562 if ( todo->summary().length() > 25 )
563 holiStr +="..."; 563 holiStr +="...";
564 bDays.setBit(i); 564 bDays.setBit(i);
565 mHolidays[i] =holiStr ; 565 mHolidays[i] =holiStr ;
566 eDays.setBit(i); 566 eDays.setBit(i);
567 567
568 } 568 }
569 } 569 }
570 } 570 }
571#else 571#else
572 //qDebug("KODayMatrix::updateViewTimed "); 572 //qDebug("KODayMatrix::updateViewTimed ");
573 for(int i = 0; i < NUMDAYS; i++) { 573 for(int i = 0; i < NUMDAYS; i++) {
574 // if events are set for the day then remember to draw it bold 574 // if events are set for the day then remember to draw it bold
575 QPtrList<Event> eventlist = mCalendar->events(days[i]); 575 QPtrList<Event> eventlist = mCalendar->events(days[i]);
576 Event *event; 576 Event *event;
577 int numEvents = eventlist.count(); 577 int numEvents = eventlist.count();
578 QString holiStr = ""; 578 QString holiStr = "";
579 bDays.clearBit(i); 579 bDays.clearBit(i);
580 hDays.clearBit(i); 580 hDays.clearBit(i);
581 eDays.clearBit(i); 581 eDays.clearBit(i);
582 for(event=eventlist.first();event != 0;event=eventlist.next()) { 582 for(event=eventlist.first();event != 0;event=eventlist.next()) {
583 ushort recurType = event->recurrence()->doesRecur(); 583 ushort recurType = event->recurrence()->doesRecur();
584 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || 584 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
585 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { 585 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
586 numEvents--; 586 numEvents--;
587 } 587 }
588 if ( event->isHoliday()) { 588 if ( event->isHoliday()) {
589 hDays.setBit(i); 589 hDays.setBit(i);
590 if ( !holiStr.isEmpty() ) 590 if ( !holiStr.isEmpty() )
591 holiStr += "\n"; 591 holiStr += "\n";
592 holiStr += event->summary(); 592 holiStr += event->summary();
593 if ( !event->location().isEmpty() ) 593 if ( !event->location().isEmpty() )
594 holiStr += " (" + event->location() + ")"; 594 holiStr += " (" + event->location() + ")";
595 } 595 }
596 if ( event->isBirthday()) { 596 if ( event->isBirthday()) {
597 if ( !holiStr.isEmpty() ) 597 if ( !holiStr.isEmpty() )
598 holiStr += "\n"; 598 holiStr += "\n";
599 holiStr += i18n("Birthday") + ": "+event->summary(); 599 holiStr += i18n("Birthday") + ": "+event->summary();
600 if ( !event->location().isEmpty() ) 600 if ( !event->location().isEmpty() )
601 holiStr += " (" + event->location() + ")"; 601 holiStr += " (" + event->location() + ")";
602 bDays.setBit(i); 602 bDays.setBit(i);
603 } 603 }
604 } 604 }
605 if ( numEvents ) 605 if ( numEvents )
606 eDays.setBit(i); 606 eDays.setBit(i);
607 //if it is a holy day then draw it red. Sundays are consider holidays, too 607 //if it is a holy day then draw it red. Sundays are consider holidays, too
608 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || 608 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) ||
609 !holiStr.isEmpty()) { 609 !holiStr.isEmpty()) {
610 mHolidays[i] = holiStr; 610 mHolidays[i] = holiStr;
611 } else { 611 } else {
612 mHolidays[i] = QString::null; 612 mHolidays[i] = QString::null;
613 } 613 }
614 } 614 }
615#endif 615#endif
616 mRedrawNeeded = true; 616 mRedrawNeeded = true;
617 if ( ! mPendingUpdateBeforeRepaint ) 617 if ( ! mPendingUpdateBeforeRepaint )
618 repaint(false); 618 repaint(false);
619} 619}
620void KODayMatrix::updateView(QDate actdate) 620void KODayMatrix::updateView(QDate actdate)
621{ 621{
622 if ( mLastView != KOPrefs::instance()->mCurrentDisplayedView ) 622 if ( mLastView != KOPrefs::instance()->mCurrentDisplayedView )
623 mRedrawNeeded = true; 623 mRedrawNeeded = true;
624 mLastView = KOPrefs::instance()->mCurrentDisplayedView; 624 mLastView = KOPrefs::instance()->mCurrentDisplayedView;
625 if ( ! actdate.isValid() ) { 625 if ( ! actdate.isValid() ) {
626 //qDebug("date not valid "); 626 //qDebug("date not valid ");
627 return; 627 return;
628 } 628 }
629 mDayChanged = false; 629 mDayChanged = false;
630 //flag to indicate if the starting day of the matrix has changed by this call 630 //flag to indicate if the starting day of the matrix has changed by this call
631 //mDayChanged = false; 631 //mDayChanged = false;
632 // if a new startdate is to be set then apply Cornelius's calculation 632 // if a new startdate is to be set then apply Cornelius's calculation
633 // of the first day to be shown 633 // of the first day to be shown
634 if (actdate != startdate) { 634 if (actdate != startdate) {
635 // reset index of selection according to shift of starting date from startdate to actdate 635 // reset index of selection according to shift of starting date from startdate to actdate
636 if (mSelStart != NOSELECTION) { 636 if (mSelStart != NOSELECTION) {
637 int tmp = actdate.daysTo(startdate); 637 int tmp = actdate.daysTo(startdate);
638 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; 638 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl;
639 // shift selection if new one would be visible at least partly ! 639 // shift selection if new one would be visible at least partly !
640 640
641 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { 641 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) {
642 // nested if is required for next X display pushed from a different month - correction required 642 // nested if is required for next X display pushed from a different month - correction required
643 // otherwise, for month forward and backward, it must be avoided 643 // otherwise, for month forward and backward, it must be avoided
644 if( mSelStart > NUMDAYS || mSelStart < 0 ) 644 if( mSelStart > NUMDAYS || mSelStart < 0 )
645 mSelStart = mSelStart + tmp; 645 mSelStart = mSelStart + tmp;
646 if( mSelEnd > NUMDAYS || mSelEnd < 0 ) 646 if( mSelEnd > NUMDAYS || mSelEnd < 0 )
647 mSelEnd = mSelEnd + tmp; 647 mSelEnd = mSelEnd + tmp;
648 } 648 }
649 } 649 }
650 startdate = actdate; 650 startdate = actdate;
651 mDayChanged = true; 651 mDayChanged = true;
652 recalculateToday(); 652 recalculateToday();
653 mRedrawNeeded = true; 653 mRedrawNeeded = true;
654 } 654 }
655 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); 655 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() );
656 if ( !isVisible() ) { 656 if ( !isVisible() ) {
657 mPendingUpdateBeforeRepaint = true; 657 mPendingUpdateBeforeRepaint = true;
658 } else { 658 } else {
659#ifdef DESKTOP_VERSION 659#ifdef DESKTOP_VERSION
660 //mRepaintTimer->start( 100 ); 660 //mRepaintTimer->start( 100 );
661 //updateViewTimed(); 661 //updateViewTimed();
662 mUpdateTimer->start( 50 ); 662 mUpdateTimer->start( 50 );
663#else 663#else
664 mRepaintTimer->start( 350 ); 664 mRepaintTimer->start( 350 );
665 mUpdateTimer->start( 800 ); 665 mUpdateTimer->start( 800 );
666#endif 666#endif
667 } 667 }
668} 668}
669void KODayMatrix::updateEvents() 669void KODayMatrix::updateEvents()
670{ 670{
671 if ( !mCalendar ) return; 671 if ( !mCalendar ) return;
672 672
673 for( int i = 0; i < NUMDAYS; i++ ) { 673 for( int i = 0; i < NUMDAYS; i++ ) {
674 // if events are set for the day then remember to draw it bold 674 // if events are set for the day then remember to draw it bold
675 QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); 675 QPtrList<Event> eventlist = mCalendar->events( days[ i ] );
676 int numEvents = eventlist.count(); 676 int numEvents = eventlist.count();
677 Event *event; 677 Event *event;
678 for( event = eventlist.first(); event != 0;event=eventlist.next()) { 678 for( event = eventlist.first(); event != 0;event=eventlist.next()) {
679 ushort recurType = event->doesRecur(); 679 ushort recurType = event->doesRecur();
680 680
681 if ( ( recurType == Recurrence::rDaily && 681 if ( ( recurType == Recurrence::rDaily &&
682 !KOPrefs::instance()->mDailyRecur ) || 682 !KOPrefs::instance()->mDailyRecur ) ||
683 ( recurType == Recurrence::rWeekly && 683 ( recurType == Recurrence::rWeekly &&
684 !KOPrefs::instance()->mWeeklyRecur ) ) { 684 !KOPrefs::instance()->mWeeklyRecur ) ) {
685 numEvents--; 685 numEvents--;
686 } 686 }
687 } 687 }
688 if ( numEvents ) 688 if ( numEvents )
689 eDays.setBit(i); 689 eDays.setBit(i);
690 else 690 else
691 eDays.clearBit(i); 691 eDays.clearBit(i);
692 } 692 }
693} 693}
694 694
695const QDate& KODayMatrix::getDate(int offset) 695const QDate& KODayMatrix::getDate(int offset)
696{ 696{
697 if (offset < 0 || offset > NUMDAYS-1) { 697 if (offset < 0 || offset > NUMDAYS-1) {
698 qDebug("Wrong offset2 %d", offset); 698 qDebug("Wrong offset2 %d", offset);
699 return days[0]; 699 return days[0];
700 } 700 }
701 return days[offset]; 701 return days[offset];
702} 702}
703 703
704QString KODayMatrix::getHolidayLabel(int offset) 704QString KODayMatrix::getHolidayLabel(int offset)
705{ 705{
706 if (offset < 0 || offset > NUMDAYS-1) { 706 if (offset < 0 || offset > NUMDAYS-1) {
707 qDebug("Wrong offset1 %d", offset); 707 qDebug("Wrong offset1 %d", offset);
708 return QString(); 708 return QString();
709 } 709 }
710 return mHolidays[offset]; 710 return mHolidays[offset];
711} 711}
712 712
713int KODayMatrix::getDayIndexFrom(int x, int y) 713int KODayMatrix::getDayIndexFrom(int x, int y)
714{ 714{
715 int colModulo = (width()-2) % 7; 715 int colModulo = (width()-2) % 7;
716 int rowModulo = (height()-2) % 6; 716 int rowModulo = (height()-2) % 6;
717#if 0 717#if 0
718 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? 718 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ?
719 6 - x/daysize.width() : x/daysize.width()); 719 6 - x/daysize.width() : x/daysize.width());
720#endif 720#endif
721 int xVal = (x-colModulo/2-2)/daysize.width(); 721 int xVal = (x-colModulo/2-2)/daysize.width();
722 int yVal = (y-rowModulo/2-2)/daysize.height(); 722 int yVal = (y-rowModulo/2-2)/daysize.height();
723 723
724 724
725 return 7*(yVal) + xVal; 725 return 7*(yVal) + xVal;
726 726
727} 727}
728 728
729// ---------------------------------------------------------------------------- 729// ----------------------------------------------------------------------------
730// M O U S E E V E N T H A N D L I N G 730// M O U S E E V E N T H A N D L I N G
731// ---------------------------------------------------------------------------- 731// ----------------------------------------------------------------------------
732 732
733void KODayMatrix::mousePressEvent (QMouseEvent* e) 733void KODayMatrix::mousePressEvent (QMouseEvent* e)
734{ 734{
735 735
736 if ( e->button() == LeftButton ) 736 if ( e->button() == LeftButton )
737 mouseDown = true; 737 mouseDown = true;
738 mSelStart = getDayIndexFrom(e->x(), e->y()); 738 mSelStart = getDayIndexFrom(e->x(), e->y());
739 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; 739 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1;
740 mSelInit = mSelStart; 740 mSelInit = mSelStart;
741 mSelEnd = mSelStart; 741 mSelEnd = mSelStart;
742 mRedrawNeeded = true; 742 mRedrawNeeded = true;
743 repaint(false); 743 repaint(false);
744} 744}
745 745
746void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) 746void KODayMatrix::mouseReleaseEvent (QMouseEvent* e)
747{ 747{
748 mRedrawNeeded = true; 748 mRedrawNeeded = true;
749 if ( e->button() == LeftButton ) 749 if ( e->button() == LeftButton )
750 if ( ! mouseDown ) { 750 if ( ! mouseDown ) {
751 return; 751 return;
752 } 752 }
753 else 753 else
754 mouseDown = false; 754 mouseDown = false;
755 int tmp = getDayIndexFrom(e->x(), e->y()); 755 int tmp = getDayIndexFrom(e->x(), e->y());
756 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 756 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
757 757
758 if (mSelInit > tmp) { 758 if (mSelInit > tmp) {
759 mSelEnd = mSelInit; 759 mSelEnd = mSelInit;
760 if (tmp != mSelStart) { 760 if (tmp != mSelStart) {
761 mSelStart = tmp; 761 mSelStart = tmp;
762 repaint(false); 762 repaint(false);
763 } 763 }
764 } else { 764 } else {
765 mSelStart = mSelInit; 765 mSelStart = mSelInit;
766 766
767 //repaint only if selection has changed 767 //repaint only if selection has changed
768 if (tmp != mSelEnd) { 768 if (tmp != mSelEnd) {
769 mSelEnd = tmp; 769 mSelEnd = tmp;
770 repaint(false); 770 repaint(false);
771 } 771 }
772 } 772 }
773 773
774 DateList daylist; 774 DateList daylist;
775 if ( mSelStart < 0 ) 775 if ( mSelStart < 0 )
776 mSelStart = 0; 776 mSelStart = 0;
777 for (int i = mSelStart; i <= mSelEnd; i++) { 777 for (int i = mSelStart; i <= mSelEnd; i++) {
778 daylist.append(days[i]); 778 daylist.append(days[i]);
779 } 779 }
780 emit selected((const DateList)daylist); 780 emit selected((const DateList)daylist);
781 781
782} 782}
783 783
784void KODayMatrix::mouseMoveEvent (QMouseEvent* e) 784void KODayMatrix::mouseMoveEvent (QMouseEvent* e)
785{ 785{
786 if ( ! mouseDown ) { 786 if ( ! mouseDown ) {
787 return; 787 return;
788 } 788 }
789 mRedrawNeeded = true; 789 mRedrawNeeded = true;
790 int tmp = getDayIndexFrom(e->x(), e->y()); 790 int tmp = getDayIndexFrom(e->x(), e->y());
791 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 791 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
792 792
793 if (mSelInit > tmp) { 793 if (mSelInit > tmp) {
794 mSelEnd = mSelInit; 794 mSelEnd = mSelInit;
795 if (tmp != mSelStart) { 795 if (tmp != mSelStart) {
796 mSelStart = tmp; 796 mSelStart = tmp;
797 repaint(false); 797 repaint(false);
798 } 798 }
799 } else { 799 } else {
800 mSelStart = mSelInit; 800 mSelStart = mSelInit;
801 801
802 //repaint only if selection has changed 802 //repaint only if selection has changed
803 if (tmp != mSelEnd) { 803 if (tmp != mSelEnd) {
804 mSelEnd = tmp; 804 mSelEnd = tmp;
805 repaint(false); 805 repaint(false);
806 } 806 }
807 } 807 }
808} 808}
809 809
810// ---------------------------------------------------------------------------- 810// ----------------------------------------------------------------------------
811// D R A G ' N D R O P H A N D L I N G 811// D R A G ' N D R O P H A N D L I N G
812// ---------------------------------------------------------------------------- 812// ----------------------------------------------------------------------------
813 813
814void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) 814void KODayMatrix::dragEnterEvent(QDragEnterEvent *e)
815{ 815{
816#ifndef KORG_NODND 816#ifndef KORG_NODND
817 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 817 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
818 e->ignore(); 818 e->ignore();
819 return; 819 return;
820 } 820 }
821 821
822 // some visual feedback 822 // some visual feedback
823// oldPalette = palette(); 823// oldPalette = palette();
824// setPalette(my_HilitePalette); 824// setPalette(my_HilitePalette);
825// update(); 825// update();
826#endif 826#endif
827} 827}
828 828
829void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) 829void KODayMatrix::dragMoveEvent(QDragMoveEvent *e)
830{ 830{
831#ifndef KORG_NODND 831#ifndef KORG_NODND
832 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 832 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
833 e->ignore(); 833 e->ignore();
834 return; 834 return;
835 } 835 }
836 836
837 e->accept(); 837 e->accept();
838#endif 838#endif
839} 839}
840 840
841void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) 841void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/)
842{ 842{
843#ifndef KORG_NODND 843#ifndef KORG_NODND
844// setPalette(oldPalette); 844// setPalette(oldPalette);
845// update(); 845// update();
846#endif 846#endif
847} 847}
848 848
849void KODayMatrix::dropEvent(QDropEvent *e) 849void KODayMatrix::dropEvent(QDropEvent *e)
850{ 850{
851#ifndef KORG_NODND 851#ifndef KORG_NODND
852// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; 852// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl;
853 853
854 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 854 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
855 e->ignore(); 855 e->ignore();
856 return; 856 return;
857 } 857 }
858 858
859 DndFactory factory( mCalendar ); 859 DndFactory factory( mCalendar );
860 Event *event = factory.createDrop(e); 860 Event *event = factory.createDrop(e);
861 861
862 if (event) { 862 if (event) {
863 e->acceptAction(); 863 e->acceptAction();
864 864
865 Event *existingEvent = mCalendar->event(event->uid()); 865 Event *existingEvent = mCalendar->event(event->uid());
866 866
867 if(existingEvent) { 867 if(existingEvent) {
868 // uniquify event 868 // uniquify event
869 event->recreate(); 869 event->recreate();
870/* 870/*
871 KMessageBox::sorry(this, 871 KMessageBox::sorry(this,
872 i18n("Event already exists in this calendar."), 872 i18n("Event already exists in this calendar."),
873 i18n("Drop Event")); 873 i18n("Drop Event"));
874 delete event; 874 delete event;
875 return; 875 return;
876*/ 876*/
877 } 877 }
878// kdDebug() << "Drop new Event" << endl; 878// kdDebug() << "Drop new Event" << endl;
879 // Adjust date 879 // Adjust date
880 QDateTime start = event->dtStart(); 880 QDateTime start = event->dtStart();
881 QDateTime end = event->dtEnd(); 881 QDateTime end = event->dtEnd();
882 int duration = start.daysTo(end); 882 int duration = start.daysTo(end);
883 int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); 883 int idx = getDayIndexFrom(e->pos().x(), e->pos().y());
884 884
885 start.setDate(days[idx]); 885 start.setDate(days[idx]);
886 end.setDate(days[idx].addDays(duration)); 886 end.setDate(days[idx].addDays(duration));
887 887
888 event->setDtStart(start); 888 event->setDtStart(start);
889 event->setDtEnd(end); 889 event->setDtEnd(end);
890 mCalendar->addEvent(event); 890 mCalendar->addEvent(event);
891 891
892 emit eventDropped(event); 892 emit eventDropped(event);
893 } else { 893 } else {
894// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; 894// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl;
895 e->ignore(); 895 e->ignore();
896 } 896 }
897#endif 897#endif
898} 898}
899 899
900// ---------------------------------------------------------------------------- 900// ----------------------------------------------------------------------------
901// P A I N T E V E N T H A N D L I N G 901// P A I N T E V E N T H A N D L I N G
902// ---------------------------------------------------------------------------- 902// ----------------------------------------------------------------------------
903 903
904void KODayMatrix::paintEvent(QPaintEvent * pevent) 904void KODayMatrix::paintEvent(QPaintEvent * pevent)
905{ 905{
906 906
907 if ( width() <= 0 || height() <= 0 ) 907 if ( width() <= 0 || height() <= 0 )
908 return; 908 return;
909 if ( mPendingUpdateBeforeRepaint ) { 909 if ( mPendingUpdateBeforeRepaint ) {
910 updateViewTimed(); 910 updateViewTimed();
911 mPendingUpdateBeforeRepaint = false; 911 mPendingUpdateBeforeRepaint = false;
912 } 912 }
913#if 0 913#if 0
914 if ( myPix.width() != width() || myPix.height()!=height() ) { 914 if ( myPix.width() != width() || myPix.height()!=height() ) {
915 myPix.resize(size() ); 915 myPix.resize(size() );
916 mRedrawNeeded = true; 916 mRedrawNeeded = true;
917 } 917 }
918#endif 918#endif
919 if ( oldW != width() || oldH !=height() ) 919 if ( oldW != width() || oldH !=height() )
920 mRedrawNeeded = true; 920 mRedrawNeeded = true;
921 921
922 oldH = height() ; 922 oldH = height() ;
923 oldW = width(); 923 oldW = width();
924 if ( myPix.width() < width() || myPix.height() < height() ) { 924 if ( myPix.width() < width() || myPix.height() < height() ) {
925 myPix.resize(size() ); 925 myPix.resize(size() );
926 mRedrawNeeded = true; 926 mRedrawNeeded = true;
927 927
928 } 928 }
929 929
930 if ( mRedrawNeeded ) { 930 if ( mRedrawNeeded ) {
931 //qDebug("REDRAW "); 931 //qDebug("REDRAW ");
932 QPainter p(&myPix); 932 QPainter p(&myPix);
933 p.setFont(font()); 933 p.setFont(font());
934 934
935 935
936 int dheight = daysize.height(); 936 int dheight = daysize.height();
937 int dwidth = daysize.width(); 937 int dwidth = daysize.width();
938 int row,col; 938 int row,col;
939 int selw, selh; 939 int selw, selh;
940 int xyOff = frameWidth(); 940 int xyOff = frameWidth();
941 int colModulo = (width()-2) % 7; 941 int colModulo = (width()-2) % 7;
942 int rowModulo = (height()-2) % 6; 942 int rowModulo = (height()-2) % 6;
943 //qDebug("col %d row %d ",colModulo,rowModulo ); 943 //qDebug("col %d row %d ",colModulo,rowModulo );
944 944
945 bool isRTL = KOGlobals::self()->reverseLayout(); 945 bool isRTL = KOGlobals::self()->reverseLayout();
946 946
947 // draw background and topleft frame 947 // draw background and topleft frame
948 p.fillRect(0,0,width(),height(), mDefaultBackColor); 948 p.fillRect(0,0,width(),height(), mDefaultBackColor);
949 //p.setPen(mDefaultTextColor); 949 //p.setPen(mDefaultTextColor);
950 //p.drawRect(0, 0, width(), height()); 950 //p.drawRect(0, 0, width(), height());
951 int mSelStartT = mSelStart; 951 int mSelStartT = mSelStart;
952 int mSelEndT = mSelEnd; 952 int mSelEndT = mSelEnd;
953 if ( mSelEndT >= NUMDAYS ) 953 if ( mSelEndT >= NUMDAYS )
954 mSelEndT = NUMDAYS-1; 954 mSelEndT = NUMDAYS-1;
955 // draw selected days with highlighted background color 955 // draw selected days with highlighted background color
956 if (mSelStart != NOSELECTION) { 956 if (mSelStart != NOSELECTION) {
957 bool skip = false; 957 bool skip = false;
958 if ( ! mouseDown ) { 958 if ( ! mouseDown ) {
959 int mo = days[20].month(); 959 int mo = days[20].month();
960 //qDebug("-- %d %d ", mSelStartT, mSelEndT); 960 //qDebug("-- %d %d ", mSelStartT, mSelEndT);
961 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); 961 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() );
962 int startMo = days[mSelStartT].month(); 962 int startMo = days[mSelStartT].month();
963 int endMo = days[mSelEndT].month(); 963 int endMo = days[mSelEndT].month();
964 if ( startMo == 12 && mo == 1 && endMo <= 2 ) 964 if ( startMo == 12 && mo == 1 && endMo <= 2 )
965 startMo = 1; 965 startMo = 1;
966 if ( endMo == 1 && mo == 12 ) 966 if ( endMo == 1 && mo == 12 )
967 endMo = 12; 967 endMo = 12;
968 if ( mo == 12 && startMo == 1 ) 968 if ( mo == 12 && startMo == 1 )
969 startMo = 13; 969 startMo = 13;
970 if ( (startMo > mo || endMo < mo) ) { 970 if ( (startMo > mo || endMo < mo) ) {
971 skip = true; 971 skip = true;
972 } else { 972 } else {
973 if ( days[mSelStartT].month() != mo ) { 973 if ( days[mSelStartT].month() != mo ) {
974 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); 974 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day();
975 mSelStartT += add +1; 975 mSelStartT += add +1;
976 } 976 }
977 if ( days[mSelEndT].month() != mo ) { 977 if ( days[mSelEndT].month() != mo ) {
978 int sub = days[mSelEndT].day(); 978 int sub = days[mSelEndT].day();
979 mSelEndT -= sub ; 979 mSelEndT -= sub ;
980 } 980 }
981 } 981 }
982 } 982 }
983 //qDebug("SKIP %d ", skip); 983 //qDebug("SKIP %d ", skip);
984 if ( ! skip ) { 984 if ( ! skip ) {
985 row = mSelStartT/7; 985 row = mSelStartT/7;
986 col = mSelStartT -row*7; 986 col = mSelStartT -row*7;
987 QColor selcol = KOPrefs::instance()->mHighlightColor; 987 QColor selcol = KOPrefs::instance()->mHighlightColor;
988 int addCol = 0; 988 int addCol = 0;
989 int addRow = 0; 989 int addRow = 0;
990 int addRow2 = 0; 990 int addRow2 = 0;
991 int addCol2 = 0; 991 int addCol2 = 0;
992 if (row == mSelEndT/7) { 992 if (row == mSelEndT/7) {
993 if ( rowModulo ) { 993 if ( rowModulo ) {
994 if ( row >= 6 - rowModulo ) 994 if ( row >= 6 - rowModulo )
995 addRow = row - 5 + rowModulo; 995 addRow = row - 5 + rowModulo;
996 } 996 }
997 if ( colModulo ) { 997 if ( colModulo ) {
998 int colt1 = mSelEndT%7; 998 int colt1 = mSelEndT%7;
999 //qDebug("colt1 %d ", colt1 ); 999 //qDebug("colt1 %d ", colt1 );
1000 if ( colt1 >= 7 - colModulo ) 1000 if ( colt1 >= 7 - colModulo )
1001 addCol = colt1 - 7 + colModulo+1; 1001 addCol = colt1 - 7 + colModulo+1;
1002 int colt = mSelStartT%7; 1002 int colt = mSelStartT%7;
1003 if ( colt >= 7 - colModulo ) 1003 if ( colt >= 7 - colModulo )
1004 addCol2 = colt - 7 + colModulo; 1004 addCol2 = colt - 7 + colModulo;
1005 addCol -= addCol2; 1005 addCol -= addCol2;
1006 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); 1006 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 );
1007 } 1007 }
1008 // Single row selection 1008 // Single row selection
1009 //if ( row == 0) 1009 //if ( row == 0)
1010 // addRow = 1; 1010 // addRow = 1;
1011 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2, 1011 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2,
1012 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); 1012 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol);
1013 } else { 1013 } else {
1014 // draw first row to the right 1014 // draw first row to the right
1015 if ( colModulo ) { 1015 if ( colModulo ) {
1016 if ( col >= 7 - colModulo ) 1016 if ( col >= 7 - colModulo )
1017 addCol2 = col - 7 + colModulo; 1017 addCol2 = col - 7 + colModulo;
1018 } 1018 }
1019 if ( rowModulo ) { 1019 if ( rowModulo ) {
1020 if ( row >= 6 - rowModulo ) 1020 if ( row >= 6 - rowModulo )
1021 addRow = row - 5 + rowModulo; 1021 addRow = row - 5 + rowModulo;
1022 } 1022 }
1023 //if ( row == 0) 1023 //if ( row == 0)
1024 // addRow = 1; 1024 // addRow = 1;
1025 int drawWid = width()-(col*dwidth+1+addCol2)-1; 1025 int drawWid = width()-(col*dwidth+1+addCol2)-1;
1026 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, drawWid, 1026 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, drawWid,
1027 dheight+1, selcol); 1027 dheight+1, selcol);
1028 // draw full block till last line 1028 // draw full block till last line
1029 selh = mSelEndT/7-row; 1029 selh = mSelEndT/7-row;
1030 addRow = 0; 1030 addRow = 0;
1031 if ( rowModulo ) { 1031 if ( rowModulo ) {
1032 if ( mSelEndT/7 >= 6 - rowModulo ) 1032 if ( mSelEndT/7 >= 6 - rowModulo )
1033 addRow = mSelEndT/7 - 5 + rowModulo; 1033 addRow = mSelEndT/7 - 5 + rowModulo;
1034 } 1034 }
1035 //qDebug("%d %d %d ",selh, row, addRow ); 1035 //qDebug("%d %d %d ",selh, row, addRow );
1036 int addrow2 = addRow-selh+1; 1036 int addrow2 = addRow-selh+1;
1037 if ( addrow2 < 0 ) 1037 if ( addrow2 < 0 )
1038 addrow2 = 0; 1038 addrow2 = 0;
1039 if (selh > 1) { 1039 if (selh > 1) {
1040 p.fillRect(1, (row+1)*dheight+addrow2, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol); 1040 p.fillRect(1, (row+1)*dheight+addrow2, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol);
1041 } 1041 }
1042 // draw last block from left to mSelEndT 1042 // draw last block from left to mSelEndT
1043 selw = mSelEndT-7*(mSelEndT/7)+1; 1043 selw = mSelEndT-7*(mSelEndT/7)+1;
1044 //qDebug("esl %d ",selw ); 1044 //qDebug("esl %d ",selw );
1045 int add = 0; 1045 int add = 0;
1046 if ( colModulo ) { 1046 if ( colModulo ) {
1047 add = 7 - colModulo; 1047 add = 7 - colModulo;
1048 if ( selw > add ) 1048 if ( selw > add )
1049 add = selw - add; 1049 add = selw - add;
1050 else 1050 else
1051 add = 0; 1051 add = 0;
1052 } 1052 }
1053 //qDebug("add %d ", add); 1053 //qDebug("add %d ", add);
1054 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow, 1054 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow,
1055 selw*dwidth+add, dheight+1, selcol); 1055 selw*dwidth+add, dheight+1, selcol);
1056 } 1056 }
1057 } 1057 }
1058 } 1058 }
1059 1059
1060 // iterate over all days in the matrix and draw the day label in appropriate colors 1060 // iterate over all days in the matrix and draw the day label in appropriate colors
1061 QColor actcol = mDefaultTextColorShaded; 1061 QColor actcol = mDefaultTextColorShaded;
1062 p.setPen(actcol); 1062 p.setPen(actcol);
1063 QPen tmppen; 1063 QPen tmppen;
1064 for(int i = 0; i < NUMDAYS; i++) { 1064 for(int i = 0; i < NUMDAYS; i++) {
1065 row = i/7; 1065 row = i/7;
1066 col = isRTL ? 6-(i-row*7) : i-row*7; 1066 col = isRTL ? 6-(i-row*7) : i-row*7;
1067 1067
1068 // if it is the first day of a month switch color from normal to shaded and vice versa 1068 // if it is the first day of a month switch color from normal to shaded and vice versa
1069 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { 1069 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) {
1070 if (actcol == mDefaultTextColorShaded) { 1070 if (actcol == mDefaultTextColorShaded) {
1071 actcol = mDefaultTextColor; 1071 actcol = mDefaultTextColor;
1072 } else { 1072 } else {
1073 actcol = mDefaultTextColorShaded; 1073 actcol = mDefaultTextColorShaded;
1074 } 1074 }
1075 p.setPen(actcol); 1075 p.setPen(actcol);
1076 } 1076 }
1077 if (actcol == mDefaultTextColorShaded) { 1077 if (actcol == mDefaultTextColorShaded) {
1078 if ( ! mouseDown ) { 1078 if ( ! mouseDown ) {
1079 continue; 1079 continue;
1080 } 1080 }
1081 } 1081 }
1082 //Reset pen color after selected days block 1082 //Reset pen color after selected days block
1083 if (i == mSelEndT+1) { 1083 if (i == mSelEndT+1) {
1084 p.setPen(actcol); 1084 p.setPen(actcol);
1085 } 1085 }
1086 1086
1087 // if today then draw rectangle around day 1087 // if today then draw rectangle around day
1088 if (today == i) { 1088 if (today == i) {
1089 tmppen = p.pen(); 1089 tmppen = p.pen();
1090 QPen mTodayPen(p.pen()); 1090 QPen mTodayPen(p.pen());
1091 if ( daysize.width() < 20 ) 1091 if ( daysize.width() < 20 )
1092 mTodayPen.setWidth(1); 1092 mTodayPen.setWidth(1);
1093 else 1093 else
1094 mTodayPen.setWidth(mTodayMarginWidth); 1094 mTodayPen.setWidth(mTodayMarginWidth);
1095 //draw red rectangle for holidays 1095 //draw red rectangle for holidays
1096 if (pDays.testBit(i)) { 1096 if (pDays.testBit(i)) {
1097 if (actcol == mDefaultTextColor) { 1097 if (actcol == mDefaultTextColor) {
1098 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); 1098 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor);
1099 } else { 1099 } else {
1100 mTodayPen.setColor(mHolidayColorShaded); 1100 mTodayPen.setColor(mHolidayColorShaded);
1101 } 1101 }
1102 } 1102 }
1103 //draw gray rectangle for today if in selection 1103 //draw gray rectangle for today if in selection
1104 if (i >= mSelStartT && i <= mSelEndT) { 1104 if (i >= mSelStartT && i <= mSelEndT) {
1105 QColor grey("grey"); 1105 QColor grey("grey");
1106 mTodayPen.setColor(grey); 1106 mTodayPen.setColor(grey);
1107 } 1107 }
1108 p.setPen(mTodayPen); 1108 p.setPen(mTodayPen);
1109 1109
1110 1110
1111 int addCol = 0; 1111 int addCol = 0;
1112 int addRow = 0; 1112 int addRow = 0;
1113 if (rowModulo) { 1113 if (rowModulo) {
1114 if ( row >= 6 - rowModulo ) 1114 if ( row >= 6 - rowModulo )
1115 addRow = row - 5 + rowModulo; 1115 addRow = row - 5 + rowModulo;
1116 } 1116 }
1117 if ( colModulo ) { 1117 if ( colModulo ) {
1118 if ( col >= 7 - colModulo ) 1118 if ( col >= 7 - colModulo )
1119 addCol = col - 6 + colModulo-1; 1119 addCol = col - 6 + colModulo-1;
1120 } 1120 }
1121 1121
1122 addCol += 1; 1122 addCol += 1;
1123 if ( row == 0 ) 1123 if ( row == 0 )
1124 addRow = 1; 1124 addRow = 1;
1125 p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth+1, dheight+1); 1125 p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth+1, dheight+1);
1126 p.setPen(tmppen); 1126 p.setPen(tmppen);
1127 } 1127 }
1128 1128
1129 // if any events are on that day then draw it using a bold font 1129 // if any events are on that day then draw it using a bold font
1130 if ( eDays.testBit(i) ) { 1130 if ( eDays.testBit(i) ) {
1131 QFont myFont = font(); 1131 QFont myFont = font();
1132 myFont.setBold(true); 1132 myFont.setBold(true);
1133 p.setFont(myFont); 1133 p.setFont(myFont);
1134 } 1134 }
1135 1135
1136 // if it is a holiday then use the default holiday color 1136 // if it is a holiday then use the default holiday color
1137 if ( pDays.testBit(i)) { 1137 if ( pDays.testBit(i)) {
1138 if ( bDays.testBit(i) ) { 1138 if ( bDays.testBit(i) ) {
1139 if ( hDays.testBit(i) ) 1139 if ( hDays.testBit(i) )
1140 p.setPen(QColor(0,200,0)); 1140 p.setPen(QColor(0,200,0));
1141 else 1141 else
1142 p.setPen(QColor(Qt::blue)); 1142 p.setPen(QColor(Qt::blue));
1143 } else { 1143 } else {
1144 if (actcol == mDefaultTextColor ) { 1144 if (actcol == mDefaultTextColor ) {
1145 p.setPen(KOPrefs::instance()->mHolidayColor); 1145 p.setPen(KOPrefs::instance()->mHolidayColor);
1146 } else { 1146 } else {
1147 p.setPen(mHolidayColorShaded); 1147 p.setPen(mHolidayColorShaded);
1148 } 1148 }
1149 } 1149 }
1150 } 1150 }
1151 1151
1152 // draw selected days with special color 1152 // draw selected days with special color
1153 // DO NOT specially highlight holidays in selection ! 1153 // DO NOT specially highlight holidays in selection !
1154 if (i >= mSelStartT && i <= mSelEndT) { 1154 if (i >= mSelStartT && i <= mSelEndT) {
1155 ;//p.setPen(mSelectedDaysColor); 1155 ;//p.setPen(mSelectedDaysColor);
1156 } 1156 }
1157 1157
1158 int addCol = 0; 1158 int addCol = 0;
1159 int addRow = 0; 1159 int addRow = 0;
1160 if ( colModulo ) { 1160 if ( colModulo ) {
1161 if ( col >= 7 - colModulo ) 1161 if ( col >= 7 - colModulo )
1162 addCol = col - 7 + colModulo; 1162 addCol = col - 7 + colModulo;
1163 } 1163 }
1164 if ( rowModulo ) { 1164 if ( rowModulo ) {
1165 if ( row >= 6 - rowModulo ) 1165 if ( row >= 6 - rowModulo )
1166 addRow = row - 5 + rowModulo; 1166 addRow = row - 5 + rowModulo;
1167 } 1167 }
1168 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); 1168 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow);
1169 ++addCol;//++addCol; 1169 ++addCol;//++addCol;
1170 if ( row == 0) 1170 if ( row == 0)
1171 addRow = 1; 1171 addRow = 1;
1172 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, 1172 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight,
1173 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); 1173 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]);
1174 1174
1175 // reset color to actual color 1175 // reset color to actual color
1176 if (pDays.testBit(i)) { 1176 if (pDays.testBit(i)) {
1177 p.setPen(actcol); 1177 p.setPen(actcol);
1178 } 1178 }
1179 // reset bold font to plain font 1179 // reset bold font to plain font
1180 if ( eDays.testBit(i)) { 1180 if ( eDays.testBit(i)) {
1181 QFont myFont = font(); 1181 QFont myFont = font();
1182 myFont.setBold(false); 1182 myFont.setBold(false);
1183 p.setFont(myFont); 1183 p.setFont(myFont);
1184 } 1184 }
1185 } 1185 }
1186 p.setPen(mDefaultTextColor); 1186 p.setPen(mDefaultTextColor);
1187 p.drawRect(0, 0, width(), height()); 1187 p.drawRect(0, 0, width(), height());
1188 } else { 1188 } else {
1189 //qDebug("NO redraw "); 1189 //qDebug("NO redraw ");
1190 } 1190 }
1191 1191
1192 bitBlt (this, pevent->rect().topLeft(), &myPix , pevent->rect() ,CopyROP); 1192 bitBlt (this, pevent->rect().topLeft(), &myPix , pevent->rect() ,CopyROP);
1193 mRedrawNeeded = false; 1193 mRedrawNeeded = false;
1194} 1194}
1195 1195
1196// ---------------------------------------------------------------------------- 1196// ----------------------------------------------------------------------------
1197// R E SI Z E E V E N T H A N D L I N G 1197// R E SI Z E E V E N T H A N D L I N G
1198// ---------------------------------------------------------------------------- 1198// ----------------------------------------------------------------------------
1199 1199
1200void KODayMatrix::resizeEvent(QResizeEvent * e) 1200void KODayMatrix::resizeEvent(QResizeEvent * e)
1201{ 1201{
1202 QRect sz = frameRect(); 1202 QRect sz = frameRect();
1203 daysize.setHeight(sz.height()*7 / NUMDAYS); 1203 daysize.setHeight(sz.height()*7 / NUMDAYS);
1204 daysize.setWidth(sz.width() / 7); 1204 daysize.setWidth(sz.width() / 7);
1205 QFrame::resizeEvent( e ); 1205 QFrame::resizeEvent( e );
1206} 1206}
1207 1207
1208QSize KODayMatrix::sizeHint() const 1208QSize KODayMatrix::sizeHint() const
1209{ 1209{
1210 1210
1211 QFontMetrics fm ( font() ); 1211 QFontMetrics fm ( font() );
1212 int wid = fm.width( "30") *7+3; 1212 int wid = fm.width( "30") *7+3;
1213 int hei = fm.height() * 6+3; 1213 int hei = fm.height() * 6+3;
1214 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); 1214 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei);
1215 return QSize ( wid, hei ); 1215 return QSize ( wid, hei );
1216 1216
1217} 1217}
diff --git a/korganizer/koeditorrecurrence.cpp b/korganizer/koeditorrecurrence.cpp
index de4e4f7..89504db 100644
--- a/korganizer/koeditorrecurrence.cpp
+++ b/korganizer/koeditorrecurrence.cpp
@@ -1,1120 +1,1126 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000-2003 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000-2003 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 <qtooltip.h> 24#include <qtooltip.h>
25#include <qfiledialog.h> 25#include <qfiledialog.h>
26#include <qlayout.h> 26#include <qlayout.h>
27#include <qvbox.h> 27#include <qvbox.h>
28#include <qbuttongroup.h> 28#include <qbuttongroup.h>
29#include <qvgroupbox.h> 29#include <qvgroupbox.h>
30#include <qwidgetstack.h> 30#include <qwidgetstack.h>
31#include <qdatetime.h> 31#include <qdatetime.h>
32#include <qlistbox.h> 32#include <qlistbox.h>
33#include <qspinbox.h> 33#include <qspinbox.h>
34#include <qcheckbox.h> 34#include <qcheckbox.h>
35#include <qapplication.h> 35#include <qapplication.h>
36 36
37#include <kdialog.h> 37#include <kdialog.h>
38#include <kglobal.h> 38#include <kglobal.h>
39#include <klocale.h> 39#include <klocale.h>
40#include <kiconloader.h> 40#include <kiconloader.h>
41#include <kdebug.h> 41#include <kdebug.h>
42#include <knumvalidator.h> 42#include <knumvalidator.h>
43 43
44#include <libkcal/event.h> 44#include <libkcal/event.h>
45#include <libkcal/todo.h> 45#include <libkcal/todo.h>
46 46
47#include <libkdepim/kdateedit.h> 47#include <libkdepim/kdateedit.h>
48 48
49#include "koprefs.h" 49#include "koprefs.h"
50 50
51#include "koeditorrecurrence.h" 51#include "koeditorrecurrence.h"
52 52
53/////////////////////////// RecurBase /////////////////////////////// 53/////////////////////////// RecurBase ///////////////////////////////
54 54
55RecurBase::RecurBase( QWidget *parent, const char *name ) : 55RecurBase::RecurBase( QWidget *parent, const char *name ) :
56 QWidget( parent, name ) 56 QWidget( parent, name )
57{ 57{
58 mFrequencyEdit = new QSpinBox( 1, 9999, 1, this ); 58 mFrequencyEdit = new QSpinBox( 1, 9999, 1, this );
59 mFrequencyEdit->setValue( 1 ); 59 mFrequencyEdit->setValue( 1 );
60} 60}
61 61
62QWidget *RecurBase::frequencyEdit() 62QWidget *RecurBase::frequencyEdit()
63{ 63{
64 return mFrequencyEdit; 64 return mFrequencyEdit;
65} 65}
66 66
67void RecurBase::setFrequency( int f ) 67void RecurBase::setFrequency( int f )
68{ 68{
69 if ( f < 1 ) f = 1; 69 if ( f < 1 ) f = 1;
70 70
71 mFrequencyEdit->setValue( f ); 71 mFrequencyEdit->setValue( f );
72} 72}
73 73
74int RecurBase::frequency() 74int RecurBase::frequency()
75{ 75{
76 return mFrequencyEdit->value(); 76 return mFrequencyEdit->value();
77} 77}
78 78
79/////////////////////////// RecurDaily /////////////////////////////// 79/////////////////////////// RecurDaily ///////////////////////////////
80 80
81RecurDaily::RecurDaily( QWidget *parent, const char *name ) : 81RecurDaily::RecurDaily( QWidget *parent, const char *name ) :
82 RecurBase( parent, name ) 82 RecurBase( parent, name )
83{ 83{
84 QBoxLayout *topLayout = new QHBoxLayout( this ); 84 QBoxLayout *topLayout = new QHBoxLayout( this );
85 topLayout->setSpacing( KDialog::spacingHint() ); 85 topLayout->setSpacing( KDialog::spacingHint() );
86 topLayout->setMargin( KDialog::marginHintSmall() ); 86 topLayout->setMargin( KDialog::marginHintSmall() );
87 87
88 QLabel *preLabel = new QLabel( i18n("Recur every"), this ); 88 QLabel *preLabel = new QLabel( i18n("Recur every"), this );
89 topLayout->addWidget( preLabel ); 89 topLayout->addWidget( preLabel );
90 90
91 topLayout->addWidget( frequencyEdit() ); 91 topLayout->addWidget( frequencyEdit() );
92 92
93 QLabel *postLabel = new QLabel( i18n("day(s)"), this ); 93 QLabel *postLabel = new QLabel( i18n("day(s)"), this );
94 topLayout->addWidget( postLabel ); 94 topLayout->addWidget( postLabel );
95} 95}
96 96
97 97
98/////////////////////////// RecurWeekly /////////////////////////////// 98/////////////////////////// RecurWeekly ///////////////////////////////
99 99
100RecurWeekly::RecurWeekly( QWidget *parent, const char *name ) : 100RecurWeekly::RecurWeekly( QWidget *parent, const char *name ) :
101 RecurBase( parent, name ) 101 RecurBase( parent, name )
102{ 102{
103 QBoxLayout *topLayout = new QVBoxLayout( this ); 103 QBoxLayout *topLayout = new QVBoxLayout( this );
104 topLayout->setSpacing( KDialog::spacingHint() ); 104 topLayout->setSpacing( KDialog::spacingHint() );
105 topLayout->setMargin( KDialog::marginHintSmall() ); 105 topLayout->setMargin( KDialog::marginHintSmall() );
106 106
107 //topLayout->addStretch( 1 ); 107 //topLayout->addStretch( 1 );
108 108
109 QBoxLayout *weeksLayout = new QHBoxLayout( topLayout ); 109 QBoxLayout *weeksLayout = new QHBoxLayout( topLayout );
110 110
111 QLabel *preLabel = new QLabel( i18n("Recur every"), this ); 111 QLabel *preLabel = new QLabel( i18n("Recur every"), this );
112 weeksLayout->addWidget( preLabel ); 112 weeksLayout->addWidget( preLabel );
113 113
114 weeksLayout->addWidget( frequencyEdit() ); 114 weeksLayout->addWidget( frequencyEdit() );
115 115
116 QLabel *postLabel = new QLabel( i18n("week(s) on:"), this ); 116 QLabel *postLabel = new QLabel( i18n("week(s) on:"), this );
117 weeksLayout->addWidget( postLabel ); 117 weeksLayout->addWidget( postLabel );
118 118
119 QHBox *dayBox = new QHBox( this ); 119 QHBox *dayBox = new QHBox( this );
120 topLayout->addWidget( dayBox, 1, AlignVCenter ); 120 topLayout->addWidget( dayBox, 1, AlignVCenter );
121 // TODO: Respect start of week setting 121 // TODO: Respect start of week setting
122 for ( int i = 0; i < 7; ++i ) { 122 for ( int i = 0; i < 7; ++i ) {
123 QString weekDayName = KGlobal::locale()->weekDayName( i + 1, true ); 123 QString weekDayName = KGlobal::locale()->weekDayName( i + 1, true );
124 int left = 1; 124 int left = 1;
125 if ( QApplication::desktop()->width() > 480 ) { 125 if ( QApplication::desktop()->width() > 480 ) {
126 ++left; 126 ++left;
127 if ( QApplication::desktop()->width() > 640 ) 127 if ( QApplication::desktop()->width() > 640 )
128 ++left; 128 ++left;
129 } 129 }
130 mDayBoxes[ i ] = new QCheckBox( weekDayName.left( left ), dayBox ); 130 mDayBoxes[ i ] = new QCheckBox( weekDayName.left( left ), dayBox );
131 } 131 }
132 132
133 topLayout->addStretch( ); 133 topLayout->addStretch( );
134} 134}
135 135
136void RecurWeekly::setDays( const QBitArray &days ) 136void RecurWeekly::setDays( const QBitArray &days )
137{ 137{
138 for ( int i = 0; i < 7; ++i ) { 138 for ( int i = 0; i < 7; ++i ) {
139 mDayBoxes[ i ]->setChecked( days.testBit( i ) ); 139 mDayBoxes[ i ]->setChecked( days.testBit( i ) );
140 } 140 }
141} 141}
142 142
143QBitArray RecurWeekly::days() 143QBitArray RecurWeekly::days()
144{ 144{
145 QBitArray days( 7 ); 145 QBitArray days( 7 );
146 146
147 for ( int i = 0; i < 7; ++i ) { 147 for ( int i = 0; i < 7; ++i ) {
148 days.setBit( i, mDayBoxes[ i ]->isChecked() ); 148 days.setBit( i, mDayBoxes[ i ]->isChecked() );
149 } 149 }
150 150
151 return days; 151 return days;
152} 152}
153 153
154/////////////////////////// RecurMonthly /////////////////////////////// 154/////////////////////////// RecurMonthly ///////////////////////////////
155 155
156RecurMonthly::RecurMonthly( QWidget *parent, const char *name ) : 156RecurMonthly::RecurMonthly( QWidget *parent, const char *name ) :
157 RecurBase( parent, name ) 157 RecurBase( parent, name )
158{ 158{
159 QBoxLayout *topLayout = new QVBoxLayout( this ); 159 QBoxLayout *topLayout = new QVBoxLayout( this );
160 topLayout->setSpacing( KDialog::spacingHint() ); 160 topLayout->setSpacing( KDialog::spacingHint() );
161 topLayout->setMargin( KDialog::marginHintSmall() ); 161 topLayout->setMargin( KDialog::marginHintSmall() );
162 162
163 163
164 QBoxLayout *freqLayout = new QHBoxLayout( topLayout ); 164 QBoxLayout *freqLayout = new QHBoxLayout( topLayout );
165 165
166 QLabel *preLabel = new QLabel( i18n("every"), this ); 166 QLabel *preLabel = new QLabel( i18n("every"), this );
167 freqLayout->addWidget( preLabel ); 167 freqLayout->addWidget( preLabel );
168 168
169 freqLayout->addWidget( frequencyEdit() ); 169 freqLayout->addWidget( frequencyEdit() );
170 170
171 QLabel *postLabel = new QLabel( i18n("month(s)"), this ); 171 QLabel *postLabel = new QLabel( i18n("month(s)"), this );
172 freqLayout->addWidget( postLabel ); 172 freqLayout->addWidget( postLabel );
173 173
174 174
175 QButtonGroup *buttonGroup = new QButtonGroup( this ); 175 QButtonGroup *buttonGroup = new QButtonGroup( this );
176 buttonGroup->setFrameStyle( QFrame::NoFrame ); 176 buttonGroup->setFrameStyle( QFrame::NoFrame );
177 topLayout->addWidget( buttonGroup, 1, AlignVCenter ); 177 topLayout->addWidget( buttonGroup, 1, AlignVCenter );
178 178
179 QGridLayout *buttonLayout = new QGridLayout( buttonGroup, 3, 2 ); 179 QGridLayout *buttonLayout = new QGridLayout( buttonGroup, 3, 2 );
180 buttonLayout->setSpacing( KDialog::spacingHint() ); 180 buttonLayout->setSpacing( KDialog::spacingHint() );
181 buttonLayout->setMargin( KDialog::marginHintSmall() ); 181 buttonLayout->setMargin( KDialog::marginHintSmall() );
182 182
183 183
184 QString recurOnText; 184 QString recurOnText;
185 if ( QApplication::desktop()->width() > 320 ) { 185 if ( QApplication::desktop()->width() > 320 ) {
186 recurOnText = i18n("Recur on the"); 186 recurOnText = i18n("Recur on the");
187 } 187 }
188 188
189 mByDayRadio = new QRadioButton( recurOnText, buttonGroup ); 189 mByDayRadio = new QRadioButton( recurOnText, buttonGroup );
190 buttonLayout->addWidget( mByDayRadio, 0, 0 ); 190 buttonLayout->addWidget( mByDayRadio, 0, 0 );
191 191
192 mByDayCombo = new QComboBox( buttonGroup ); 192 mByDayCombo = new QComboBox( buttonGroup );
193 mByDayCombo->setSizeLimit( 7 ); 193 mByDayCombo->setSizeLimit( 7 );
194 mByDayCombo->insertItem( i18n("1st") ); 194 mByDayCombo->insertItem( i18n("1st") );
195 mByDayCombo->insertItem( i18n("2nd") ); 195 mByDayCombo->insertItem( i18n("2nd") );
196 mByDayCombo->insertItem( i18n("3rd") ); 196 mByDayCombo->insertItem( i18n("3rd") );
197 mByDayCombo->insertItem( i18n("4th") ); 197 mByDayCombo->insertItem( i18n("4th") );
198 mByDayCombo->insertItem( i18n("5th") ); 198 mByDayCombo->insertItem( i18n("5th") );
199 mByDayCombo->insertItem( i18n("6th") ); 199 mByDayCombo->insertItem( i18n("6th") );
200 mByDayCombo->insertItem( i18n("7th") ); 200 mByDayCombo->insertItem( i18n("7th") );
201 mByDayCombo->insertItem( i18n("8th") ); 201 mByDayCombo->insertItem( i18n("8th") );
202 mByDayCombo->insertItem( i18n("9th") ); 202 mByDayCombo->insertItem( i18n("9th") );
203 mByDayCombo->insertItem( i18n("10th") ); 203 mByDayCombo->insertItem( i18n("10th") );
204 mByDayCombo->insertItem( i18n("11th") ); 204 mByDayCombo->insertItem( i18n("11th") );
205 mByDayCombo->insertItem( i18n("12th") ); 205 mByDayCombo->insertItem( i18n("12th") );
206 mByDayCombo->insertItem( i18n("13th") ); 206 mByDayCombo->insertItem( i18n("13th") );
207 mByDayCombo->insertItem( i18n("14th") ); 207 mByDayCombo->insertItem( i18n("14th") );
208 mByDayCombo->insertItem( i18n("15th") ); 208 mByDayCombo->insertItem( i18n("15th") );
209 mByDayCombo->insertItem( i18n("16th") ); 209 mByDayCombo->insertItem( i18n("16th") );
210 mByDayCombo->insertItem( i18n("17th") ); 210 mByDayCombo->insertItem( i18n("17th") );
211 mByDayCombo->insertItem( i18n("18th") ); 211 mByDayCombo->insertItem( i18n("18th") );
212 mByDayCombo->insertItem( i18n("19th") ); 212 mByDayCombo->insertItem( i18n("19th") );
213 mByDayCombo->insertItem( i18n("20th") ); 213 mByDayCombo->insertItem( i18n("20th") );
214 mByDayCombo->insertItem( i18n("21st") ); 214 mByDayCombo->insertItem( i18n("21st") );
215 mByDayCombo->insertItem( i18n("22nd") ); 215 mByDayCombo->insertItem( i18n("22nd") );
216 mByDayCombo->insertItem( i18n("23rd") ); 216 mByDayCombo->insertItem( i18n("23rd") );
217 mByDayCombo->insertItem( i18n("24th") ); 217 mByDayCombo->insertItem( i18n("24th") );
218 mByDayCombo->insertItem( i18n("25th") ); 218 mByDayCombo->insertItem( i18n("25th") );
219 mByDayCombo->insertItem( i18n("26th") ); 219 mByDayCombo->insertItem( i18n("26th") );
220 mByDayCombo->insertItem( i18n("27th") ); 220 mByDayCombo->insertItem( i18n("27th") );
221 mByDayCombo->insertItem( i18n("28th") ); 221 mByDayCombo->insertItem( i18n("28th") );
222 mByDayCombo->insertItem( i18n("29th") ); 222 mByDayCombo->insertItem( i18n("29th") );
223 mByDayCombo->insertItem( i18n("30th") ); 223 mByDayCombo->insertItem( i18n("30th") );
224 mByDayCombo->insertItem( i18n("31st") ); 224 mByDayCombo->insertItem( i18n("31st") );
225 buttonLayout->addWidget( mByDayCombo, 0, 1 ); 225 buttonLayout->addWidget( mByDayCombo, 0, 1 );
226 226
227 QLabel *byDayLabel = new QLabel( i18n("day"), buttonGroup ); 227 QLabel *byDayLabel = new QLabel( i18n("day"), buttonGroup );
228 buttonLayout->addWidget( byDayLabel, 0, 2 ); 228 buttonLayout->addWidget( byDayLabel, 0, 2 );
229 229
230 230
231 mByPosRadio = new QRadioButton( recurOnText, buttonGroup); 231 mByPosRadio = new QRadioButton( recurOnText, buttonGroup);
232 buttonLayout->addWidget( mByPosRadio, 1, 0 ); 232 buttonLayout->addWidget( mByPosRadio, 1, 0 );
233 233
234 mByPosCountCombo = new QComboBox( buttonGroup ); 234 mByPosCountCombo = new QComboBox( buttonGroup );
235 mByPosCountCombo->insertItem( i18n("1st") ); 235 mByPosCountCombo->insertItem( i18n("1st") );
236 mByPosCountCombo->insertItem( i18n("2nd") ); 236 mByPosCountCombo->insertItem( i18n("2nd") );
237 mByPosCountCombo->insertItem( i18n("3rd") ); 237 mByPosCountCombo->insertItem( i18n("3rd") );
238 mByPosCountCombo->insertItem( i18n("4th") ); 238 mByPosCountCombo->insertItem( i18n("4th") );
239 mByPosCountCombo->insertItem( i18n("5th") ); 239 mByPosCountCombo->insertItem( i18n("5th") );
240 buttonLayout->addWidget( mByPosCountCombo, 1, 1 ); 240 buttonLayout->addWidget( mByPosCountCombo, 1, 1 );
241 241
242 mByPosWeekdayCombo = new QComboBox( buttonGroup ); 242 mByPosWeekdayCombo = new QComboBox( buttonGroup );
243 mByPosWeekdayCombo->insertItem( i18n("Monday") ); 243 mByPosWeekdayCombo->insertItem( i18n("Monday") );
244 mByPosWeekdayCombo->insertItem( i18n("Tuesday") ); 244 mByPosWeekdayCombo->insertItem( i18n("Tuesday") );
245 mByPosWeekdayCombo->insertItem( i18n("Wednesday") ); 245 mByPosWeekdayCombo->insertItem( i18n("Wednesday") );
246 mByPosWeekdayCombo->insertItem( i18n("Thursday") ); 246 mByPosWeekdayCombo->insertItem( i18n("Thursday") );
247 mByPosWeekdayCombo->insertItem( i18n("Friday") ); 247 mByPosWeekdayCombo->insertItem( i18n("Friday") );
248 mByPosWeekdayCombo->insertItem( i18n("Saturday") ); 248 mByPosWeekdayCombo->insertItem( i18n("Saturday") );
249 mByPosWeekdayCombo->insertItem( i18n("Sunday") ); 249 mByPosWeekdayCombo->insertItem( i18n("Sunday") );
250 buttonLayout->addWidget( mByPosWeekdayCombo, 1, 2 ); 250 buttonLayout->addWidget( mByPosWeekdayCombo, 1, 2 );
251} 251}
252 252
253void RecurMonthly::setByDay( int day ) 253void RecurMonthly::setByDay( int day )
254{ 254{
255 mByDayRadio->setChecked( true ); 255 mByDayRadio->setChecked( true );
256 mByDayCombo->setCurrentItem( day ); 256 mByDayCombo->setCurrentItem( day );
257} 257}
258 258
259void RecurMonthly::setByPos( int count, int weekday ) 259void RecurMonthly::setByPos( int count, int weekday )
260{ 260{
261 mByPosRadio->setChecked( true ); 261 mByPosRadio->setChecked( true );
262 mByPosCountCombo->setCurrentItem( count ); 262 mByPosCountCombo->setCurrentItem( count );
263 mByPosWeekdayCombo->setCurrentItem( weekday ); 263 mByPosWeekdayCombo->setCurrentItem( weekday );
264} 264}
265 265
266bool RecurMonthly::byDay() 266bool RecurMonthly::byDay()
267{ 267{
268 return mByDayRadio->isChecked(); 268 return mByDayRadio->isChecked();
269} 269}
270 270
271bool RecurMonthly::byPos() 271bool RecurMonthly::byPos()
272{ 272{
273 return mByPosRadio->isChecked(); 273 return mByPosRadio->isChecked();
274} 274}
275 275
276int RecurMonthly::day() 276int RecurMonthly::day()
277{ 277{
278 return mByDayCombo->currentItem() + 1; 278 return mByDayCombo->currentItem() + 1;
279} 279}
280 280
281int RecurMonthly::count() 281int RecurMonthly::count()
282{ 282{
283 return mByPosCountCombo->currentItem() + 1; 283 return mByPosCountCombo->currentItem() + 1;
284} 284}
285 285
286int RecurMonthly::weekday() 286int RecurMonthly::weekday()
287{ 287{
288 return mByPosWeekdayCombo->currentItem(); 288 return mByPosWeekdayCombo->currentItem();
289} 289}
290 290
291/////////////////////////// RecurYearly /////////////////////////////// 291/////////////////////////// RecurYearly ///////////////////////////////
292 292
293RecurYearly::RecurYearly( QWidget *parent, const char *name ) : 293RecurYearly::RecurYearly( QWidget *parent, const char *name ) :
294 RecurBase( parent, name ) 294 RecurBase( parent, name )
295{ 295{
296 QBoxLayout *topLayout = new QVBoxLayout( this ); 296 QBoxLayout *topLayout = new QVBoxLayout( this );
297 topLayout->setSpacing( KDialog::spacingHint() ); 297 topLayout->setSpacing( KDialog::spacingHint() );
298 topLayout->setMargin( KDialog::marginHintSmall() ); 298 topLayout->setMargin( KDialog::marginHintSmall() );
299 299
300 300
301 QBoxLayout *freqLayout = new QHBoxLayout( topLayout ); 301 QBoxLayout *freqLayout = new QHBoxLayout( topLayout );
302 302
303 QLabel *preLabel = new QLabel( i18n("every"), this ); 303 QLabel *preLabel = new QLabel( i18n("every"), this );
304 freqLayout->addWidget( preLabel ); 304 freqLayout->addWidget( preLabel );
305 305
306 freqLayout->addWidget( frequencyEdit() ); 306 freqLayout->addWidget( frequencyEdit() );
307 307
308 QLabel *postLabel = new QLabel( i18n("year(s)"), this ); 308 QLabel *postLabel = new QLabel( i18n("year(s)"), this );
309 freqLayout->addWidget( postLabel ); 309 freqLayout->addWidget( postLabel );
310 310
311 311
312 QButtonGroup *buttonGroup = new QButtonGroup( this ); 312 QButtonGroup *buttonGroup = new QButtonGroup( this );
313 buttonGroup->setFrameStyle( QFrame::NoFrame ); 313 buttonGroup->setFrameStyle( QFrame::NoFrame );
314 topLayout->addWidget( buttonGroup, 1, AlignVCenter ); 314 topLayout->addWidget( buttonGroup, 1, AlignVCenter );
315 315
316 QGridLayout *buttonLayout = new QGridLayout( buttonGroup, 2, 3 ); 316 QGridLayout *buttonLayout = new QGridLayout( buttonGroup, 2, 3 );
317 317
318 mByMonthRadio = new QRadioButton( i18n("On day "), buttonGroup); 318 mByMonthRadio = new QRadioButton( i18n("On day "), buttonGroup);
319 buttonLayout->addWidget( mByMonthRadio, 0, 0 , Qt::AlignRight); 319 buttonLayout->addWidget( mByMonthRadio, 0, 0 , Qt::AlignRight);
320 mByDayLabel = new QLabel( i18n("%1 of ").arg(1), buttonGroup ); 320 mByDayLabel = new QLabel( i18n("%1 of ").arg(1), buttonGroup );
321 321
322 buttonLayout->addWidget( mByDayLabel, 0, 1 ); 322 buttonLayout->addWidget( mByDayLabel, 0, 1 );
323 mByMonthCombo = new QComboBox( buttonGroup ); 323 mByMonthCombo = new QComboBox( buttonGroup );
324 mByMonthCombo->insertItem( i18n("January") ); 324 mByMonthCombo->insertItem( i18n("January") );
325 mByMonthCombo->insertItem( i18n("February") ); 325 mByMonthCombo->insertItem( i18n("February") );
326 mByMonthCombo->insertItem( i18n("March") ); 326 mByMonthCombo->insertItem( i18n("March") );
327 mByMonthCombo->insertItem( i18n("April") ); 327 mByMonthCombo->insertItem( i18n("April") );
328 mByMonthCombo->insertItem( i18n("May") ); 328 mByMonthCombo->insertItem( i18n("May") );
329 mByMonthCombo->insertItem( i18n("June") ); 329 mByMonthCombo->insertItem( i18n("June") );
330 mByMonthCombo->insertItem( i18n("July") ); 330 mByMonthCombo->insertItem( i18n("July") );
331 mByMonthCombo->insertItem( i18n("August") ); 331 mByMonthCombo->insertItem( i18n("August") );
332 mByMonthCombo->insertItem( i18n("September") ); 332 mByMonthCombo->insertItem( i18n("September") );
333 mByMonthCombo->insertItem( i18n("October") ); 333 mByMonthCombo->insertItem( i18n("October") );
334 mByMonthCombo->insertItem( i18n("November") ); 334 mByMonthCombo->insertItem( i18n("November") );
335 mByMonthCombo->insertItem( i18n("December") ); 335 mByMonthCombo->insertItem( i18n("December") );
336 buttonLayout->addWidget( mByMonthCombo, 0, 2,Qt::AlignLeft ); 336 buttonLayout->addWidget( mByMonthCombo, 0, 2,Qt::AlignLeft );
337 if ( QApplication::desktop()->width() <= 640 ) { 337 if ( QApplication::desktop()->width() <= 640 ) {
338 mByMonthCombo->setSizeLimit( 6 ); 338 mByMonthCombo->setSizeLimit( 6 );
339 } 339 }
340 340
341 mByDayRadio = new QRadioButton( i18n("On day "), buttonGroup); 341 mByDayRadio = new QRadioButton( i18n("On day "), buttonGroup);
342 buttonLayout->addWidget( mByDayRadio, 1, 0 , Qt::AlignRight); 342 buttonLayout->addWidget( mByDayRadio, 1, 0 , Qt::AlignRight);
343 mDayOfLabel = new QLabel( i18n("%1 of the year").arg(1), buttonGroup ); 343 mDayOfLabel = new QLabel( i18n("%1 of the year").arg(1), buttonGroup );
344 buttonLayout->addMultiCellWidget( mDayOfLabel, 1, 1, 1,3 ); 344 buttonLayout->addMultiCellWidget( mDayOfLabel, 1, 1, 1,3 );
345 345
346} 346}
347 347
348void RecurYearly::setByDay( int doy ) 348void RecurYearly::setByDay( int doy )
349{ 349{
350 mByDayRadio->setChecked( true ); 350 mByDayRadio->setChecked( true );
351 mDayOfLabel->setText(i18n("%1 of the year").arg( doy ) ); 351 mDayOfLabel->setText(i18n("%1 of the year").arg( doy ) );
352} 352}
353 353
354void RecurYearly::setByMonth( int month, int day ) 354void RecurYearly::setByMonth( int month, int day )
355{ 355{
356 mByMonthRadio->setChecked( true ); 356 mByMonthRadio->setChecked( true );
357 mByMonthCombo->setCurrentItem( month - 1 ); 357 mByMonthCombo->setCurrentItem( month - 1 );
358 mByDayLabel->setText(i18n("%1 of ").arg( day ) ); 358 mByDayLabel->setText(i18n("%1 of ").arg( day ) );
359 mDay = day; 359 mDay = day;
360} 360}
361 361
362bool RecurYearly::byMonth() 362bool RecurYearly::byMonth()
363{ 363{
364 return mByMonthRadio->isChecked(); 364 return mByMonthRadio->isChecked();
365} 365}
366 366
367bool RecurYearly::byDay() 367bool RecurYearly::byDay()
368{ 368{
369 return mByDayRadio->isChecked(); 369 return mByDayRadio->isChecked();
370} 370}
371 371
372int RecurYearly::month() 372int RecurYearly::month()
373{ 373{
374 return mByMonthCombo->currentItem() + 1; 374 return mByMonthCombo->currentItem() + 1;
375} 375}
376int RecurYearly::day() 376int RecurYearly::day()
377{ 377{
378 return mDay;//mByDayCombo->currentItem() + 1; 378 return mDay;//mByDayCombo->currentItem() + 1;
379} 379}
380 380
381//////////////////////////// ExceptionsWidget ////////////////////////// 381//////////////////////////// ExceptionsWidget //////////////////////////
382 382
383ExceptionsWidget::ExceptionsWidget( QWidget *parent, const char *name ) : 383ExceptionsWidget::ExceptionsWidget( QWidget *parent, const char *name ) :
384 QWidget( parent, name ) 384 QWidget( parent, name )
385{ 385{
386 QBoxLayout *topLayout = new QVBoxLayout( this ); 386 QBoxLayout *topLayout = new QVBoxLayout( this );
387 387
388 QGroupBox *groupBox = new QGroupBox( 1, Horizontal, i18n("Exceptions"), 388 QGroupBox *groupBox = new QGroupBox( 1, Horizontal, i18n("Exceptions"),
389 this ); 389 this );
390 topLayout->addWidget( groupBox ); 390 topLayout->addWidget( groupBox );
391 391
392 QWidget *box = new QWidget( groupBox ); 392 QWidget *box = new QWidget( groupBox );
393 393
394 QGridLayout *boxLayout = new QGridLayout( box ); 394 QGridLayout *boxLayout = new QGridLayout( box );
395 395
396 mExceptionDateEdit = new KDateEdit( box ); 396 mExceptionDateEdit = new KDateEdit( box );
397 boxLayout->addWidget( mExceptionDateEdit, 0, 0 ); 397 boxLayout->addWidget( mExceptionDateEdit, 0, 0 );
398 398
399 QPushButton *addExceptionButton = new QPushButton( i18n("Add"), box ); 399 QPushButton *addExceptionButton = new QPushButton( i18n("Add"), box );
400 boxLayout->addWidget( addExceptionButton, 1, 0 ); 400 boxLayout->addWidget( addExceptionButton, 1, 0 );
401 QPushButton *changeExceptionButton = new QPushButton( i18n("Change"), box ); 401 QPushButton *changeExceptionButton = new QPushButton( i18n("Change"), box );
402 boxLayout->addWidget( changeExceptionButton, 2, 0 ); 402 boxLayout->addWidget( changeExceptionButton, 2, 0 );
403 QPushButton *deleteExceptionButton = new QPushButton( i18n("Delete"), box ); 403 QPushButton *deleteExceptionButton = new QPushButton( i18n("Delete"), box );
404 boxLayout->addWidget( deleteExceptionButton, 3, 0 ); 404 boxLayout->addWidget( deleteExceptionButton, 3, 0 );
405 405
406 mExceptionList = new QListBox( box ); 406 mExceptionList = new QListBox( box );
407 boxLayout->addMultiCellWidget( mExceptionList, 0, 3, 1, 1 ); 407 boxLayout->addMultiCellWidget( mExceptionList, 0, 3, 1, 1 );
408 408
409 boxLayout->setRowStretch( 4, 1 ); 409 boxLayout->setRowStretch( 4, 1 );
410 boxLayout->setColStretch( 1, 3 ); 410 boxLayout->setColStretch( 1, 3 );
411 411
412 connect( addExceptionButton, SIGNAL( clicked() ), 412 connect( addExceptionButton, SIGNAL( clicked() ),
413 SLOT( addException() ) ); 413 SLOT( addException() ) );
414 connect( changeExceptionButton, SIGNAL( clicked() ), 414 connect( changeExceptionButton, SIGNAL( clicked() ),
415 SLOT( changeException() ) ); 415 SLOT( changeException() ) );
416 connect( deleteExceptionButton, SIGNAL( clicked() ), 416 connect( deleteExceptionButton, SIGNAL( clicked() ),
417 SLOT( deleteException() ) ); 417 SLOT( deleteException() ) );
418 if ( QApplication::desktop()->width() < 480 ) { 418 if ( QApplication::desktop()->width() < 480 ) {
419 setMinimumWidth( 220 ); 419 setMinimumWidth( 220 );
420 } else { 420 } else {
421 setMinimumWidth( 440 ); 421 setMinimumWidth( 440 );
422 mExceptionDateEdit->setMinimumWidth( 200 ); 422 mExceptionDateEdit->setMinimumWidth( 200 );
423 } 423 }
424} 424}
425 425
426void ExceptionsWidget::setDefaults( const QDateTime &from ) 426void ExceptionsWidget::setDefaults( const QDateTime &from )
427{ 427{
428 mExceptionDateEdit->setDate( from.date() ); 428 mExceptionDateEdit->setDate( from.date() );
429} 429}
430 430
431void ExceptionsWidget::addException() 431void ExceptionsWidget::addException()
432{ 432{
433 QDate date = mExceptionDateEdit->date(); 433 QDate date = mExceptionDateEdit->date();
434 QString dateStr = KGlobal::locale()->formatDate( date ); 434 QString dateStr = KGlobal::locale()->formatDate( date );
435 if( !mExceptionList->findItem( dateStr ) ) { 435 if( !mExceptionList->findItem( dateStr ) ) {
436 mExceptionDates.append( date ); 436 mExceptionDates.append( date );
437 mExceptionList->insertItem( dateStr ); 437 mExceptionList->insertItem( dateStr );
438 } 438 }
439} 439}
440 440
441void ExceptionsWidget::changeException() 441void ExceptionsWidget::changeException()
442{ 442{
443 int pos = mExceptionList->currentItem(); 443 int pos = mExceptionList->currentItem();
444 if ( pos < 0 ) return; 444 if ( pos < 0 ) return;
445 445
446 QDate date = mExceptionDateEdit->date(); 446 QDate date = mExceptionDateEdit->date();
447 mExceptionDates[ pos ] = date; 447 mExceptionDates[ pos ] = date;
448 mExceptionList->changeItem( KGlobal::locale()->formatDate( date ), pos ); 448 mExceptionList->changeItem( KGlobal::locale()->formatDate( date ), pos );
449} 449}
450 450
451void ExceptionsWidget::deleteException() 451void ExceptionsWidget::deleteException()
452{ 452{
453 int pos = mExceptionList->currentItem(); 453 int pos = mExceptionList->currentItem();
454 if ( pos < 0 ) return; 454 if ( pos < 0 ) return;
455 455
456 mExceptionDates.remove( mExceptionDates.at( pos ) ); 456 mExceptionDates.remove( mExceptionDates.at( pos ) );
457 mExceptionList->removeItem( pos ); 457 mExceptionList->removeItem( pos );
458} 458}
459 459
460void ExceptionsWidget::setDates( const DateList &dates ) 460void ExceptionsWidget::setDates( const DateList &dates )
461{ 461{
462 mExceptionList->clear(); 462 mExceptionList->clear();
463 mExceptionDates.clear(); 463 mExceptionDates.clear();
464 DateList::ConstIterator dit; 464 DateList::ConstIterator dit;
465 for ( dit = dates.begin(); dit != dates.end(); ++dit ) { 465 for ( dit = dates.begin(); dit != dates.end(); ++dit ) {
466 mExceptionList->insertItem( KGlobal::locale()->formatDate(* dit ) ); 466 mExceptionList->insertItem( KGlobal::locale()->formatDate(* dit ) );
467 mExceptionDates.append( *dit ); 467 mExceptionDates.append( *dit );
468 } 468 }
469} 469}
470 470
471DateList ExceptionsWidget::dates() 471DateList ExceptionsWidget::dates()
472{ 472{
473 return mExceptionDates; 473 return mExceptionDates;
474} 474}
475 475
476///////////////////////// ExceptionsDialog /////////////////////////// 476///////////////////////// ExceptionsDialog ///////////////////////////
477 477
478ExceptionsDialog::ExceptionsDialog( QWidget *parent, const char *name ) : 478ExceptionsDialog::ExceptionsDialog( QWidget *parent, const char *name ) :
479 KDialogBase( parent, name, true, i18n("Edit exceptions"), Ok|Cancel ) 479 KDialogBase( parent, name, true, i18n("Edit exceptions"), Ok|Cancel )
480{ 480{
481 mExceptions = new ExceptionsWidget( this ); 481 mExceptions = new ExceptionsWidget( this );
482 setMainWidget( mExceptions ); 482 setMainWidget( mExceptions );
483 resize(220,10); 483 resize(220,10);
484} 484}
485 485
486void ExceptionsDialog::setDefaults( const QDateTime &from ) 486void ExceptionsDialog::setDefaults( const QDateTime &from )
487{ 487{
488 mExceptions->setDefaults( from ); 488 mExceptions->setDefaults( from );
489} 489}
490 490
491void ExceptionsDialog::setDates( const DateList &dates ) 491void ExceptionsDialog::setDates( const DateList &dates )
492{ 492{
493 mExceptions->setDates( dates ); 493 mExceptions->setDates( dates );
494} 494}
495 495
496DateList ExceptionsDialog::dates() 496DateList ExceptionsDialog::dates()
497{ 497{
498 return mExceptions->dates(); 498 return mExceptions->dates();
499} 499}
500 500
501///////////////////////// RecurrenceRangeWidget /////////////////////////// 501///////////////////////// RecurrenceRangeWidget ///////////////////////////
502 502
503RecurrenceRangeWidget::RecurrenceRangeWidget( QWidget *parent, 503RecurrenceRangeWidget::RecurrenceRangeWidget( QWidget *parent,
504 const char *name ) 504 const char *name )
505 : QWidget( parent, name ) 505 : QWidget( parent, name )
506{ 506{
507 QBoxLayout *topLayout = new QVBoxLayout( this ); 507 QBoxLayout *topLayout = new QVBoxLayout( this );
508 508
509 mRangeGroupBox = new QGroupBox( 1, Horizontal, i18n("Recurrence Range"), 509 mRangeGroupBox = new QGroupBox( 1, Horizontal, i18n("Recurrence Range"),
510 this ); 510 this );
511 topLayout->addWidget( mRangeGroupBox ); 511 topLayout->addWidget( mRangeGroupBox );
512 512
513 QWidget *rangeBox = new QWidget( mRangeGroupBox ); 513 QWidget *rangeBox = new QWidget( mRangeGroupBox );
514 QVBoxLayout *rangeLayout = new QVBoxLayout( rangeBox ); 514 QVBoxLayout *rangeLayout = new QVBoxLayout( rangeBox );
515 rangeLayout->setSpacing( KDialog::spacingHint() ); 515 rangeLayout->setSpacing( KDialog::spacingHint() );
516 rangeLayout->setMargin( KDialog::marginHintSmall() ); 516 rangeLayout->setMargin( KDialog::marginHintSmall() );
517 517
518 mStartDateLabel = new QLabel( i18n("Begin on:"), rangeBox ); 518 mStartDateLabel = new QLabel( i18n("Begin on:"), rangeBox );
519 rangeLayout->addWidget( mStartDateLabel ); 519 rangeLayout->addWidget( mStartDateLabel );
520 520
521 QButtonGroup *rangeButtonGroup = new QButtonGroup; 521 QButtonGroup *rangeButtonGroup = new QButtonGroup;
522 522
523 mNoEndDateButton = new QRadioButton( i18n("No ending date"), rangeBox ); 523 mNoEndDateButton = new QRadioButton( i18n("No ending date"), rangeBox );
524 rangeButtonGroup->insert( mNoEndDateButton ); 524 rangeButtonGroup->insert( mNoEndDateButton );
525 rangeLayout->addWidget( mNoEndDateButton ); 525 rangeLayout->addWidget( mNoEndDateButton );
526 526
527 QBoxLayout *durationLayout = new QHBoxLayout( rangeLayout ); 527 QBoxLayout *durationLayout = new QHBoxLayout( rangeLayout );
528 durationLayout->setSpacing( KDialog::spacingHint() ); 528 durationLayout->setSpacing( KDialog::spacingHint() );
529 529
530 mEndDurationButton = new QRadioButton( i18n("End after"), rangeBox ); 530 mEndDurationButton = new QRadioButton( i18n("End after"), rangeBox );
531 rangeButtonGroup->insert( mEndDurationButton ); 531 rangeButtonGroup->insert( mEndDurationButton );
532 durationLayout->addWidget( mEndDurationButton ); 532 durationLayout->addWidget( mEndDurationButton );
533 533
534 mEndDurationEdit = new QSpinBox( 1, 9999, 1, rangeBox ); 534 mEndDurationEdit = new QSpinBox( 1, 9999, 1, rangeBox );
535 durationLayout->addWidget( mEndDurationEdit ); 535 durationLayout->addWidget( mEndDurationEdit );
536 536
537 QLabel *endDurationLabel = new QLabel( i18n("occurrence(s)"), rangeBox ); 537 QLabel *endDurationLabel = new QLabel( i18n("occurrence(s)"), rangeBox );
538 durationLayout ->addWidget( endDurationLabel ); 538 durationLayout ->addWidget( endDurationLabel );
539 539
540 QBoxLayout *endDateLayout = new QHBoxLayout( rangeLayout ); 540 QBoxLayout *endDateLayout = new QHBoxLayout( rangeLayout );
541 endDateLayout->setSpacing( KDialog::spacingHint() ); 541 endDateLayout->setSpacing( KDialog::spacingHint() );
542 542
543 mEndDateButton = new QRadioButton( i18n("End by:"), rangeBox ); 543 mEndDateButton = new QRadioButton( i18n("End by:"), rangeBox );
544 rangeButtonGroup->insert( mEndDateButton ); 544 rangeButtonGroup->insert( mEndDateButton );
545 endDateLayout->addWidget( mEndDateButton ); 545 endDateLayout->addWidget( mEndDateButton );
546 546
547 mEndDateEdit = new KDateEdit( rangeBox ); 547 mEndDateEdit = new KDateEdit( rangeBox );
548 endDateLayout->addWidget( mEndDateEdit ); 548 endDateLayout->addWidget( mEndDateEdit );
549 549
550 //endDateLayout->addStretch( 1 ); 550 //endDateLayout->addStretch( 1 );
551 551
552 connect( mNoEndDateButton, SIGNAL( toggled( bool ) ), 552 connect( mNoEndDateButton, SIGNAL( toggled( bool ) ),
553 SLOT( showCurrentRange() ) ); 553 SLOT( showCurrentRange() ) );
554 connect( mEndDurationButton, SIGNAL( toggled( bool ) ), 554 connect( mEndDurationButton, SIGNAL( toggled( bool ) ),
555 SLOT( showCurrentRange() ) ); 555 SLOT( showCurrentRange() ) );
556 connect( mEndDateButton, SIGNAL( toggled( bool ) ), 556 connect( mEndDateButton, SIGNAL( toggled( bool ) ),
557 SLOT( showCurrentRange() ) ); 557 SLOT( showCurrentRange() ) );
558} 558}
559 559
560void RecurrenceRangeWidget::setDefaults( const QDateTime &from ) 560void RecurrenceRangeWidget::setDefaults( const QDateTime &from )
561{ 561{
562 mNoEndDateButton->setChecked( true ); 562 mNoEndDateButton->setChecked( true );
563 563
564 setDateTimes( from ); 564 setDateTimes( from );
565 mEndDateEdit->setDate( from.date() ); 565 mEndDateEdit->setDate( from.date() );
566} 566}
567 567
568void RecurrenceRangeWidget::setDuration( int duration ) 568void RecurrenceRangeWidget::setDuration( int duration )
569{ 569{
570 if ( duration == -1 ) { 570 if ( duration == -1 ) {
571 mNoEndDateButton->setChecked( true ); 571 mNoEndDateButton->setChecked( true );
572 } else if ( duration == 0 ) { 572 } else if ( duration == 0 ) {
573 mEndDateButton->setChecked( true ); 573 mEndDateButton->setChecked( true );
574 } else { 574 } else {
575 mEndDurationButton->setChecked( true ); 575 mEndDurationButton->setChecked( true );
576 mEndDurationEdit->setValue( duration ); 576 mEndDurationEdit->setValue( duration );
577 } 577 }
578} 578}
579 579
580int RecurrenceRangeWidget::duration() 580int RecurrenceRangeWidget::duration()
581{ 581{
582 if ( mNoEndDateButton->isChecked() ) { 582 if ( mNoEndDateButton->isChecked() ) {
583 return -1; 583 return -1;
584 } else if ( mEndDurationButton->isChecked() ) { 584 } else if ( mEndDurationButton->isChecked() ) {
585 return mEndDurationEdit->value(); 585 return mEndDurationEdit->value();
586 } else { 586 } else {
587 return 0; 587 return 0;
588 } 588 }
589} 589}
590 590
591void RecurrenceRangeWidget::setEndDate( const QDate &date ) 591void RecurrenceRangeWidget::setEndDate( const QDate &date )
592{ 592{
593 mEndDateEdit->setDate( date ); 593 mEndDateEdit->setDate( date );
594} 594}
595 595
596QDate RecurrenceRangeWidget::endDate() 596QDate RecurrenceRangeWidget::endDate()
597{ 597{
598 return mEndDateEdit->date(); 598 return mEndDateEdit->date();
599} 599}
600 600
601void RecurrenceRangeWidget::showCurrentRange() 601void RecurrenceRangeWidget::showCurrentRange()
602{ 602{
603 mEndDurationEdit->setEnabled( mEndDurationButton->isChecked() ); 603 mEndDurationEdit->setEnabled( mEndDurationButton->isChecked() );
604 mEndDateEdit->setEnabled( mEndDateButton->isChecked() ); 604 mEndDateEdit->setEnabled( mEndDateButton->isChecked() );
605} 605}
606 606
607void RecurrenceRangeWidget::setDateTimes( const QDateTime &start, 607void RecurrenceRangeWidget::setDateTimes( const QDateTime &start,
608 const QDateTime & ) 608 const QDateTime & )
609{ 609{
610 mStartDateLabel->setText( i18n("Start date: %1") 610 mStartDateLabel->setText( i18n("Start date: %1")
611 .arg( KGlobal::locale()->formatDate( start.date() ) ) ); 611 .arg( KGlobal::locale()->formatDate( start.date() ) ) );
612 612
613 if(!mEndDateButton->isChecked()) 613 if(!mEndDateButton->isChecked())
614 mEndDateEdit->setDate( start.date() ); 614 mEndDateEdit->setDate( start.date() );
615} 615}
616 616
617///////////////////////// RecurrenceRangeDialog /////////////////////////// 617///////////////////////// RecurrenceRangeDialog ///////////////////////////
618 618
619RecurrenceRangeDialog::RecurrenceRangeDialog( QWidget *parent, 619RecurrenceRangeDialog::RecurrenceRangeDialog( QWidget *parent,
620 const char *name ) : 620 const char *name ) :
621 KDialogBase( parent, name, true, i18n("Edit Recurrence Range"), Ok|Cancel ) 621 KDialogBase( parent, name, true, i18n("Edit Recurrence Range"), Ok|Cancel )
622{ 622{
623 mRecurrenceRangeWidget = new RecurrenceRangeWidget( this ); 623 mRecurrenceRangeWidget = new RecurrenceRangeWidget( this );
624 setMainWidget( mRecurrenceRangeWidget ); 624 setMainWidget( mRecurrenceRangeWidget );
625} 625}
626 626
627void RecurrenceRangeDialog::setDefaults( const QDateTime &from ) 627void RecurrenceRangeDialog::setDefaults( const QDateTime &from )
628{ 628{
629 mRecurrenceRangeWidget->setDefaults( from ); 629 mRecurrenceRangeWidget->setDefaults( from );
630} 630}
631 631
632void RecurrenceRangeDialog::setDuration( int duration ) 632void RecurrenceRangeDialog::setDuration( int duration )
633{ 633{
634 mRecurrenceRangeWidget->setDuration( duration ); 634 mRecurrenceRangeWidget->setDuration( duration );
635} 635}
636 636
637int RecurrenceRangeDialog::duration() 637int RecurrenceRangeDialog::duration()
638{ 638{
639 return mRecurrenceRangeWidget->duration(); 639 return mRecurrenceRangeWidget->duration();
640} 640}
641 641
642void RecurrenceRangeDialog::setEndDate( const QDate &date ) 642void RecurrenceRangeDialog::setEndDate( const QDate &date )
643{ 643{
644 mRecurrenceRangeWidget->setEndDate( date ); 644 mRecurrenceRangeWidget->setEndDate( date );
645} 645}
646 646
647QDate RecurrenceRangeDialog::endDate() 647QDate RecurrenceRangeDialog::endDate()
648{ 648{
649 return mRecurrenceRangeWidget->endDate(); 649 return mRecurrenceRangeWidget->endDate();
650} 650}
651 651
652void RecurrenceRangeDialog::setDateTimes( const QDateTime &start, 652void RecurrenceRangeDialog::setDateTimes( const QDateTime &start,
653 const QDateTime &end ) 653 const QDateTime &end )
654{ 654{
655 mRecurrenceRangeWidget->setDateTimes( start, end ); 655 mRecurrenceRangeWidget->setDateTimes( start, end );
656} 656}
657 657
658//////////////////////////// RecurrenceChooser //////////////////////// 658//////////////////////////// RecurrenceChooser ////////////////////////
659 659
660RecurrenceChooser::RecurrenceChooser( QWidget *parent, const char *name ) : 660RecurrenceChooser::RecurrenceChooser( QWidget *parent, const char *name ) :
661 QWidget( parent, name ) 661 QWidget( parent, name )
662{ 662{
663 QBoxLayout *topLayout = new QVBoxLayout( this ); 663 QBoxLayout *topLayout = new QVBoxLayout( this );
664 664
665 mTypeCombo = new QComboBox( this ); 665 mTypeCombo = new QComboBox( this );
666 mTypeCombo->insertItem( i18n("Daily") ); 666 mTypeCombo->insertItem( i18n("Daily") );
667 mTypeCombo->insertItem( i18n("Weekly") ); 667 mTypeCombo->insertItem( i18n("Weekly") );
668 mTypeCombo->insertItem( i18n("Monthly") ); 668 mTypeCombo->insertItem( i18n("Monthly") );
669 mTypeCombo->insertItem( i18n("Yearly") ); 669 mTypeCombo->insertItem( i18n("Yearly") );
670 670
671 topLayout->addWidget( mTypeCombo ); 671 topLayout->addWidget( mTypeCombo );
672 672
673 connect( mTypeCombo, SIGNAL( activated( int ) ), SLOT( emitChoice() ) ); 673 connect( mTypeCombo, SIGNAL( activated( int ) ), SLOT( emitChoice() ) );
674 674
675} 675}
676 676
677int RecurrenceChooser::type() 677int RecurrenceChooser::type()
678{ 678{
679 if ( mTypeCombo ) { 679 if ( mTypeCombo ) {
680 return mTypeCombo->currentItem(); 680 return mTypeCombo->currentItem();
681 } else { 681 } else {
682 if ( mDailyButton->isChecked() ) return Daily; 682 if ( mDailyButton->isChecked() ) return Daily;
683 else if ( mWeeklyButton->isChecked() ) return Weekly; 683 else if ( mWeeklyButton->isChecked() ) return Weekly;
684 else if ( mMonthlyButton->isChecked() ) return Monthly; 684 else if ( mMonthlyButton->isChecked() ) return Monthly;
685 else return Yearly; 685 else return Yearly;
686 } 686 }
687} 687}
688 688
689void RecurrenceChooser::setType( int type ) 689void RecurrenceChooser::setType( int type )
690{ 690{
691 if ( mTypeCombo ) { 691 if ( mTypeCombo ) {
692 mTypeCombo->setCurrentItem( type ); 692 mTypeCombo->setCurrentItem( type );
693 } else { 693 } else {
694 switch ( type ) { 694 switch ( type ) {
695 case Daily: 695 case Daily:
696 mDailyButton->setChecked( true ); 696 mDailyButton->setChecked( true );
697 break; 697 break;
698 case Weekly: 698 case Weekly:
699 mWeeklyButton->setChecked( true ); 699 mWeeklyButton->setChecked( true );
700 break; 700 break;
701 case Monthly: 701 case Monthly:
702 mMonthlyButton->setChecked( true ); 702 mMonthlyButton->setChecked( true );
703 break; 703 break;
704 case Yearly: 704 case Yearly:
705 default: 705 default:
706 mYearlyButton->setChecked( true ); 706 mYearlyButton->setChecked( true );
707 break; 707 break;
708 } 708 }
709 } 709 }
710} 710}
711 711
712void RecurrenceChooser::emitChoice() 712void RecurrenceChooser::emitChoice()
713{ 713{
714 emit chosen ( type() ); 714 emit chosen ( type() );
715} 715}
716 716
717/////////////////////////////// Main Widget ///////////////////////////// 717/////////////////////////////// Main Widget /////////////////////////////
718 718
719KOEditorRecurrence::KOEditorRecurrence( QWidget* parent, const char *name ) : 719KOEditorRecurrence::KOEditorRecurrence( QWidget* parent, const char *name ) :
720 QWidget( parent, name ) 720 QWidget( parent, name )
721{ 721{
722 QGridLayout *topLayout = new QGridLayout( this, 2,2 ); 722 QGridLayout *topLayout = new QGridLayout( this, 2,2 );
723 topLayout->setSpacing( KDialog::spacingHint() ); 723 topLayout->setSpacing( KDialog::spacingHint() );
724 topLayout->setMargin( KDialog::marginHintSmall() ); 724 topLayout->setMargin( KDialog::marginHintSmall() );
725 725
726 mEnabledCheck = new QCheckBox( i18n("Enable Recurrence"), this ); 726 mEnabledCheck = new QCheckBox( i18n("Enable Recurrence"), this );
727 connect( mEnabledCheck, SIGNAL( toggled( bool ) ), 727 connect( mEnabledCheck, SIGNAL( toggled( bool ) ),
728 SLOT( setEnabled( bool ) ) ); 728 SLOT( setEnabled( bool ) ) );
729 topLayout->addMultiCellWidget( mEnabledCheck, 0, 0, 0, 1 ); 729 topLayout->addMultiCellWidget( mEnabledCheck, 0, 0, 0, 1 );
730 730
731 731
732 mTimeGroupBox = new QGroupBox( 1, Horizontal, i18n("Time"), 732 mTimeGroupBox = new QGroupBox( 1, Horizontal, i18n("Time"),
733 this ); 733 this );
734 topLayout->addMultiCellWidget( mTimeGroupBox, 1, 1 , 0 , 1 ); 734 topLayout->addMultiCellWidget( mTimeGroupBox, 1, 1 , 0 , 1 );
735 735
736 if ( QApplication::desktop()->width() <= 640 ) { 736 if ( QApplication::desktop()->width() <= 640 ) {
737 mTimeGroupBox->hide(); 737 mTimeGroupBox->hide();
738 } 738 }
739 739
740// QFrame *timeFrame = new QFrame( mTimeGroupBox ); 740// QFrame *timeFrame = new QFrame( mTimeGroupBox );
741// QBoxLayout *layoutTimeFrame = new QHBoxLayout( timeFrame ); 741// QBoxLayout *layoutTimeFrame = new QHBoxLayout( timeFrame );
742// layoutTimeFrame->setSpacing( KDialog::spacingHint() ); 742// layoutTimeFrame->setSpacing( KDialog::spacingHint() );
743 743
744 mDateTimeLabel = new QLabel( mTimeGroupBox ); 744 mDateTimeLabel = new QLabel( mTimeGroupBox );
745// mDateTimeLabel = new QLabel( timeFrame ); 745// mDateTimeLabel = new QLabel( timeFrame );
746// layoutTimeFrame->addWidget( mDateTimeLabel ); 746// layoutTimeFrame->addWidget( mDateTimeLabel );
747 //mTimeGroupBox->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ) ); 747 //mTimeGroupBox->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ) );
748 //mDateTimeLabel->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum) ); 748 //mDateTimeLabel->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum) );
749 mRuleBox = new QGroupBox( 1, Horizontal, i18n("Recurrence Rule"), this ); 749 mRuleBox = new QGroupBox( 1, Horizontal, i18n("Recurrence Rule"), this );
750 topLayout->addMultiCellWidget( mRuleBox, 2, 2, 0, 1 ); 750 topLayout->addMultiCellWidget( mRuleBox, 2, 2, 0, 1 );
751 mRecurrenceChooser = new RecurrenceChooser( mRuleBox ); 751 mRecurrenceChooser = new RecurrenceChooser( mRuleBox );
752 connect( mRecurrenceChooser, SIGNAL( chosen( int ) ), 752 connect( mRecurrenceChooser, SIGNAL( chosen( int ) ),
753 SLOT( showCurrentRule( int ) ) ); 753 SLOT( showCurrentRule( int ) ) );
754 754
755 755
756 mRuleStack = new QWidgetStack( mRuleBox ); 756 mRuleStack = new QWidgetStack( mRuleBox );
757 757
758 mDaily = new RecurDaily( mRuleStack ); 758 mDaily = new RecurDaily( mRuleStack );
759 mRuleStack->addWidget( mDaily, 0 ); 759 mRuleStack->addWidget( mDaily, 0 );
760 760
761 mWeekly = new RecurWeekly( mRuleStack ); 761 mWeekly = new RecurWeekly( mRuleStack );
762 mRuleStack->addWidget( mWeekly, 0 ); 762 mRuleStack->addWidget( mWeekly, 0 );
763 763
764 mMonthly = new RecurMonthly( mRuleStack ); 764 mMonthly = new RecurMonthly( mRuleStack );
765 mRuleStack->addWidget( mMonthly, 0 ); 765 mRuleStack->addWidget( mMonthly, 0 );
766 766
767 mYearly = new RecurYearly( mRuleStack ); 767 mYearly = new RecurYearly( mRuleStack );
768 mRuleStack->addWidget( mYearly, 0 ); 768 mRuleStack->addWidget( mYearly, 0 );
769 769
770 showCurrentRule( mRecurrenceChooser->type() ); 770 showCurrentRule( mRecurrenceChooser->type() );
771 mRecurrenceRangeWidget = 0; 771 mRecurrenceRangeWidget = 0;
772 mRecurrenceRangeDialog = new RecurrenceRangeDialog( this ); 772 mRecurrenceRangeDialog = new RecurrenceRangeDialog( this );
773 mRecurrenceRange = mRecurrenceRangeDialog; 773 mRecurrenceRange = mRecurrenceRangeDialog;
774 mRecurrenceRangeButton = new QPushButton( i18n("Recurrence Range..."), 774 mRecurrenceRangeButton = new QPushButton( i18n("Recurrence Range..."),
775 this ); 775 this );
776 776
777 connect( mRecurrenceRangeButton, SIGNAL( clicked() ), 777 connect( mRecurrenceRangeButton, SIGNAL( clicked() ),
778 SLOT( showRecurrenceRangeDialog() ) ); 778 SLOT( showRecurrenceRangeDialog() ) );
779 779
780 mExceptionsWidget = 0; 780 mExceptionsWidget = 0;
781 mExceptionsDialog = new ExceptionsDialog( this ); 781 mExceptionsDialog = new ExceptionsDialog( this );
782 mExceptions = mExceptionsDialog; 782 mExceptions = mExceptionsDialog;
783 mExceptionsButton = new QPushButton( i18n("Exceptions..."), this ); 783 mExceptionsButton = new QPushButton( i18n("Exceptions..."), this );
784 if ( QApplication::desktop()->width() < 320 ) { 784 if ( QApplication::desktop()->width() < 320 ) {
785 topLayout->addMultiCellWidget( mRecurrenceRangeButton, 3, 3, 0, 1 ); 785 topLayout->addMultiCellWidget( mRecurrenceRangeButton, 3, 3, 0, 1 );
786 topLayout->addMultiCellWidget( mExceptionsButton, 4, 4, 0, 1 ); 786 topLayout->addMultiCellWidget( mExceptionsButton, 4, 4, 0, 1 );
787 } else { 787 } else {
788 topLayout->addWidget( mRecurrenceRangeButton, 3, 0 ); 788 topLayout->addWidget( mRecurrenceRangeButton, 3, 0 );
789 topLayout->addWidget( mExceptionsButton, 3, 1 ); 789 topLayout->addWidget( mExceptionsButton, 3, 1 );
790 } 790 }
791 connect( mExceptionsButton, SIGNAL( clicked() ), 791 connect( mExceptionsButton, SIGNAL( clicked() ),
792 SLOT( showExceptionsDialog() ) ); 792 SLOT( showExceptionsDialog() ) );
793} 793}
794 794
795KOEditorRecurrence::~KOEditorRecurrence() 795KOEditorRecurrence::~KOEditorRecurrence()
796{ 796{
797} 797}
798 798
799void KOEditorRecurrence::setEnabled( bool enabled ) 799void KOEditorRecurrence::setEnabled( bool enabled )
800{ 800{
801// kdDebug() << "KOEditorRecurrence::setEnabled(): " << (enabled ? "on" : "off") << endl; 801// kdDebug() << "KOEditorRecurrence::setEnabled(): " << (enabled ? "on" : "off") << endl;
802 802
803 mTimeGroupBox->setEnabled( enabled ); 803 mTimeGroupBox->setEnabled( enabled );
804 if ( mRecurrenceRangeWidget ) mRecurrenceRangeWidget->setEnabled( enabled ); 804 if ( mRecurrenceRangeWidget ) mRecurrenceRangeWidget->setEnabled( enabled );
805 if ( mRecurrenceRangeButton ) mRecurrenceRangeButton->setEnabled( enabled ); 805 if ( mRecurrenceRangeButton ) mRecurrenceRangeButton->setEnabled( enabled );
806 if ( mExceptionsWidget ) mExceptionsWidget->setEnabled( enabled ); 806 if ( mExceptionsWidget ) mExceptionsWidget->setEnabled( enabled );
807 if ( mExceptionsButton ) mExceptionsButton->setEnabled( enabled ); 807 if ( mExceptionsButton ) mExceptionsButton->setEnabled( enabled );
808 mRuleBox->setEnabled( enabled ); 808 mRuleBox->setEnabled( enabled );
809} 809}
810 810
811void KOEditorRecurrence::showCurrentRule( int current ) 811void KOEditorRecurrence::showCurrentRule( int current )
812{ 812{
813 switch ( current ) { 813 switch ( current ) {
814 case Daily: 814 case Daily:
815 mRuleStack->raiseWidget( mDaily ); 815 mRuleStack->raiseWidget( mDaily );
816 break; 816 break;
817 case Weekly: 817 case Weekly:
818 mRuleStack->raiseWidget( mWeekly ); 818 mRuleStack->raiseWidget( mWeekly );
819 break; 819 break;
820 case Monthly: 820 case Monthly:
821 mRuleStack->raiseWidget( mMonthly ); 821 mRuleStack->raiseWidget( mMonthly );
822 break; 822 break;
823 default: 823 default:
824 case Yearly: 824 case Yearly:
825 mRuleStack->raiseWidget( mYearly ); 825 mRuleStack->raiseWidget( mYearly );
826 break; 826 break;
827 } 827 }
828} 828}
829 829
830void KOEditorRecurrence::setDateTimes( QDateTime start, QDateTime end ) 830void KOEditorRecurrence::setDateTimes( QDateTime start, QDateTime end )
831{ 831{
832// kdDebug() << "KOEditorRecurrence::setDateTimes" << endl; 832// kdDebug() << "KOEditorRecurrence::setDateTimes" << endl;
833 833
834 mRecurrenceRange->setDateTimes( start, end ); 834 mRecurrenceRange->setDateTimes( start, end );
835 mExceptions->setDefaults( end ); 835 mExceptions->setDefaults( end );
836 836
837} 837}
838void KOEditorRecurrence::setDefaultsDates( QDateTime from, QDateTime to ) 838void KOEditorRecurrence::setDefaultsDates( QDateTime from, QDateTime to )
839{ 839{
840 setDateTimes( from, to ); 840 setDateTimes( from, to );
841 QBitArray days( 7 ); 841 QBitArray days( 7 );
842 days.fill( 0 ); 842 days.fill( 0 );
843 days.setBit( from.date().dayOfWeek()- 1); 843 days.setBit( from.date().dayOfWeek()- 1);
844 mWeekly->setDays( days ); 844 mWeekly->setDays( days );
845 bool byPos = mMonthly->byPos(); 845 bool byPos = mMonthly->byPos();
846 if ( byPos ) 846 if ( byPos )
847 mMonthly->setByDay( from.date().day()-1 ); 847 mMonthly->setByDay( from.date().day()-1 );
848 mMonthly->setByPos((from.date().day()/7), from.date().dayOfWeek()-1 ); 848 mMonthly->setByPos((from.date().day()/7), from.date().dayOfWeek()-1 );
849 if ( ! byPos) 849 if ( ! byPos)
850 mMonthly->setByDay( from.date().day()-1 ); 850 mMonthly->setByDay( from.date().day()-1 );
851 851
852 bool byDay = mYearly->byDay(); 852 bool byDay = mYearly->byDay();
853 if ( ! byDay ) 853 if ( ! byDay )
854 mYearly->setByDay( from.date().dayOfYear() ); 854 mYearly->setByDay( from.date().dayOfYear() );
855 mYearly->setByMonth( from.date().month(), from.date().day() ); 855 mYearly->setByMonth( from.date().month(), from.date().day() );
856 if ( byDay ) 856 if ( byDay )
857 mYearly->setByDay( from.date().dayOfYear() ); 857 mYearly->setByDay( from.date().dayOfYear() );
858} 858}
859void KOEditorRecurrence::setDefaults( QDateTime from, QDateTime to ) 859void KOEditorRecurrence::setDefaults( QDateTime from, QDateTime to )
860{ 860{
861 861
862 // qDebug("KOEditorRecurrence::setDefaults %s %s ",from.toString().latin1(),to.toString().latin1() ); 862 // qDebug("KOEditorRecurrence::setDefaults %s %s ",from.toString().latin1(),to.toString().latin1() );
863 //setDateTimes( from, to ); 863 //setDateTimes( from, to );
864 864
865 bool enabled = false; 865 bool enabled = false;
866 mEnabledCheck->setChecked( enabled ); 866 mEnabledCheck->setChecked( enabled );
867 setEnabled( enabled ); 867 setEnabled( enabled );
868 868
869 mExceptions->setDefaults( to ); 869 mExceptions->setDefaults( to );
870 mRecurrenceRange->setDefaults( to ); 870 mRecurrenceRange->setDefaults( to );
871 871
872 mRecurrenceChooser->setType( RecurrenceChooser::Weekly ); 872 mRecurrenceChooser->setType( RecurrenceChooser::Weekly );
873 showCurrentRule( mRecurrenceChooser->type() ); 873 showCurrentRule( mRecurrenceChooser->type() );
874 874
875 mDaily->setFrequency( 1 ); 875 mDaily->setFrequency( 1 );
876 mWeekly->setFrequency( 1 ); 876 mWeekly->setFrequency( 1 );
877 mMonthly->setFrequency( 1 ); 877 mMonthly->setFrequency( 1 );
878 mYearly->setFrequency( 1 ); 878 mYearly->setFrequency( 1 );
879 setDefaultsDates( from, to ); 879 setDefaultsDates( from, to );
880} 880}
881 881
882void KOEditorRecurrence::readEvent(Incidence *event) 882void KOEditorRecurrence::readEvent(Incidence *event)
883{ 883{
884 884
885 QDateTime dtEnd; 885 QDateTime dtEnd;
886 if ( event->typeID() == eventID ) 886 if ( event->typeID() == eventID )
887 dtEnd = ((Event*)event)->dtEnd(); 887 dtEnd = ((Event*)event)->dtEnd();
888 else 888 else
889 dtEnd = ((Todo*)event)->dtDue(); 889 dtEnd = ((Todo*)event)->dtDue();
890 890
891 setDefaults( event->dtStart(), dtEnd ); 891 setDefaults( event->dtStart(), dtEnd );
892 QBitArray rDays( 7 ); 892 QBitArray rDays( 7 );
893 QPtrList<Recurrence::rMonthPos> rmp; 893 QPtrList<Recurrence::rMonthPos> rmp;
894 QPtrList<int> rmd; 894 QPtrList<int> rmd;
895 int day = 0; 895 int day = 0;
896 int count = 0; 896 int count = 0;
897 int month = 0; 897 int month = 0;
898 setDateTimes( event->dtStart(), dtEnd ); 898 setDateTimes( event->dtStart(), dtEnd );
899 899
900 Recurrence *r = event->recurrence(); 900
901 int f = r->frequency();
902 901
903 int recurs = r->doesRecur(); 902 int recurs = event->doesRecur();
904 903
905 mEnabledCheck->setChecked( recurs ); 904 mEnabledCheck->setChecked( recurs );
906 setEnabled( recurs ); 905 setEnabled( recurs );
907 906
908 int recurrenceType = RecurrenceChooser::Weekly; 907 int recurrenceType = RecurrenceChooser::Weekly;
909 908 if ( recurs ) {
910 switch ( recurs ) { 909 Recurrence *r = event->recurrence();
911 case Recurrence::rNone: 910 int f = r->frequency();
912 setDefaults( event->dtStart(), dtEnd ); 911 switch ( recurs ) {
913 break; 912 case Recurrence::rNone:
914 case Recurrence::rDaily: 913 setDefaults( event->dtStart(), dtEnd );
915 recurrenceType = RecurrenceChooser::Daily; 914 break;
916 mDaily->setFrequency( f ); 915 case Recurrence::rDaily:
917 break; 916 recurrenceType = RecurrenceChooser::Daily;
918 case Recurrence::rWeekly: 917 mDaily->setFrequency( f );
919 recurrenceType = RecurrenceChooser::Weekly; 918 break;
920 mWeekly->setFrequency( f ); 919 case Recurrence::rWeekly:
921 mWeekly->setDays( r->days() ); 920 recurrenceType = RecurrenceChooser::Weekly;
922 break; 921 mWeekly->setFrequency( f );
923 case Recurrence::rMonthlyPos: 922 mWeekly->setDays( r->days() );
924 // we only handle one possibility in the list right now, 923 break;
925 // so I have hardcoded calls with first(). If we make the GUI 924 case Recurrence::rMonthlyPos:
926 // more extended, this can be changed. 925 // we only handle one possibility in the list right now,
927 recurrenceType = RecurrenceChooser::Monthly; 926 // so I have hardcoded calls with first(). If we make the GUI
928 927 // more extended, this can be changed.
929 rmp = r->monthPositions(); 928 recurrenceType = RecurrenceChooser::Monthly;
930 if ( rmp.first()->negative ) 929
931 count = 5 - rmp.first()->rPos - 1; 930 rmp = r->monthPositions();
932 else 931 if ( rmp.first()->negative )
933 count = rmp.first()->rPos - 1; 932 count = 5 - rmp.first()->rPos - 1;
934 day = 0; 933 else
935 while ( !rmp.first()->rDays.testBit( day ) ) ++day; 934 count = rmp.first()->rPos - 1;
936 mMonthly->setByPos( count, day ); 935 day = 0;
937 936 while ( !rmp.first()->rDays.testBit( day ) ) ++day;
938 mMonthly->setFrequency( f ); 937 mMonthly->setByPos( count, day );
939 938
940 break; 939 mMonthly->setFrequency( f );
941 case Recurrence::rMonthlyDay: 940
942 recurrenceType = RecurrenceChooser::Monthly; 941 break;
943 942 case Recurrence::rMonthlyDay:
944 rmd = r->monthDays(); 943 recurrenceType = RecurrenceChooser::Monthly;
945 day = *rmd.first() - 1; 944
946 mMonthly->setByDay( day ); 945 rmd = r->monthDays();
947 946 day = *rmd.first() - 1;
948 mMonthly->setFrequency( f ); 947 mMonthly->setByDay( day );
949 948
950 break; 949 mMonthly->setFrequency( f );
951 case Recurrence::rYearlyMonth: 950
952 { 951 break;
953 recurrenceType = RecurrenceChooser::Yearly; 952 case Recurrence::rYearlyMonth:
954 //qDebug("Recurrence::rYearlyMonth: "); 953 {
955 day = event->dtStart().date().day(); 954 recurrenceType = RecurrenceChooser::Yearly;
956 rmd = r->yearNums(); 955 //qDebug("Recurrence::rYearlyMonth: ");
957 if ( rmd.count() > 0 ) 956 day = event->dtStart().date().day();
958 month = *rmd.first(); 957 rmd = r->yearNums();
959 else 958 if ( rmd.count() > 0 )
960 month = event->dtStart().date().month() ; 959 month = *rmd.first();
961 mYearly->setByMonth( month, day ); 960 else
961 month = event->dtStart().date().month() ;
962 mYearly->setByMonth( month, day );
962#if 0 963#if 0
963 //qDebug("2day = %d ",day ); 964 //qDebug("2day = %d ",day );
964 QPtrList<Recurrence::rMonthPos> monthlist = r->yearMonthPositions(); 965 QPtrList<Recurrence::rMonthPos> monthlist = r->yearMonthPositions();
965 int month; 966 int month;
966 if ( !monthlist.isEmpty() ) { 967 if ( !monthlist.isEmpty() ) {
967 month = monthlist.first()->rPos ; 968 month = monthlist.first()->rPos ;
968 } else { 969 } else {
969 month = event->dtStart().date().month() ; 970 month = event->dtStart().date().month() ;
970 } 971 }
971 mYearly->setByMonth( day, month ); 972 mYearly->setByMonth( day, month );
972#endif 973#endif
973 mYearly->setFrequency( f ); 974 mYearly->setFrequency( f );
974 } 975 }
975 976
976 break; 977 break;
977 case Recurrence::rYearlyDay: 978 case Recurrence::rYearlyDay:
978 //qDebug("Recurrence::rYearlyDay: "); 979 //qDebug("Recurrence::rYearlyDay: ");
979 recurrenceType = RecurrenceChooser::Yearly; 980 recurrenceType = RecurrenceChooser::Yearly;
980 mYearly->setByDay( event->dtStart().date().dayOfYear() ); 981 mYearly->setByDay( event->dtStart().date().dayOfYear() );
981 mYearly->setFrequency( f ); 982 mYearly->setFrequency( f );
982 break; 983 break;
983 default: 984 default:
984 setDefaults( event->dtStart(), dtEnd ); 985 setDefaults( event->dtStart(), dtEnd );
985 break; 986 break;
987 }
986 } 988 }
987
988 mRecurrenceChooser->setType( recurrenceType ); 989 mRecurrenceChooser->setType( recurrenceType );
989 showCurrentRule( recurrenceType ); 990 showCurrentRule( recurrenceType );
990 991
991 mRecurrenceRange->setDateTimes( event->dtStart() ); 992 mRecurrenceRange->setDateTimes( event->dtStart() );
992 993
993 if ( r->doesRecur() ) { 994 if ( event->doesRecur() ) {
995 Recurrence *r = event->recurrence();
994 mRecurrenceRange->setDuration( r->duration() ); 996 mRecurrenceRange->setDuration( r->duration() );
995 if ( r->duration() == 0 ) 997 if ( r->duration() == 0 )
996 { 998 {
997 if ( r->endDate() < event->dtStart().date() ) 999 if ( r->endDate() < event->dtStart().date() )
998 mRecurrenceRange->setEndDate( event->dtStart().date() ); 1000 mRecurrenceRange->setEndDate( event->dtStart().date() );
999 else 1001 else
1000 mRecurrenceRange->setEndDate( r->endDate() ); 1002 mRecurrenceRange->setEndDate( r->endDate() );
1001 } else 1003 } else
1002 mRecurrenceRange->setEndDate( event->dtStart().date() ); 1004 mRecurrenceRange->setEndDate( event->dtStart().date() );
1003 } 1005 }
1004 1006
1005 mExceptions->setDates( event->exDates() ); 1007 mExceptions->setDates( event->exDates() );
1006} 1008}
1007 1009
1008void KOEditorRecurrence::writeEvent( Incidence *event ) 1010void KOEditorRecurrence::writeEvent( Incidence *event )
1009{ 1011{
1010 Recurrence *r = event->recurrence(); 1012
1011 1013
1012 // clear out any old settings; 1014 if ( !mEnabledCheck->isChecked() ) {
1013 r->unsetRecurs(); 1015 if ( event->doesRecur() )
1016 event->recurrence()->unsetRecurs();
1017 } else {
1018 Recurrence *r = event->recurrence();
1014 1019
1015 if ( mEnabledCheck->isChecked() ) { 1020 // clear out any old settings;
1021 r->unsetRecurs();
1016 int duration = mRecurrenceRange->duration(); 1022 int duration = mRecurrenceRange->duration();
1017 QDate endDate; 1023 QDate endDate;
1018 if ( duration == 0 ) endDate = mRecurrenceRange->endDate(); 1024 if ( duration == 0 ) endDate = mRecurrenceRange->endDate();
1019 1025
1020 int recurrenceType = mRecurrenceChooser->type(); 1026 int recurrenceType = mRecurrenceChooser->type();
1021 1027
1022 if ( recurrenceType == RecurrenceChooser::Daily ) { 1028 if ( recurrenceType == RecurrenceChooser::Daily ) {
1023 int freq = mDaily->frequency(); 1029 int freq = mDaily->frequency();
1024 if ( duration != 0 ) r->setDaily( freq, duration ); 1030 if ( duration != 0 ) r->setDaily( freq, duration );
1025 else r->setDaily( freq, endDate ); 1031 else r->setDaily( freq, endDate );
1026 } else if ( recurrenceType == RecurrenceChooser::Weekly ) { 1032 } else if ( recurrenceType == RecurrenceChooser::Weekly ) {
1027 int freq = mWeekly->frequency(); 1033 int freq = mWeekly->frequency();
1028 QBitArray days = mWeekly->days(); 1034 QBitArray days = mWeekly->days();
1029 int j; 1035 int j;
1030 bool found = false; 1036 bool found = false;
1031 for (j = 0; j < 7 ; ++j ) { 1037 for (j = 0; j < 7 ; ++j ) {
1032 found |=days.at(j); 1038 found |=days.at(j);
1033 } 1039 }
1034 if ( !found ) { 1040 if ( !found ) {
1035 days.setBit( event->dtStart().date().dayOfWeek()-1); 1041 days.setBit( event->dtStart().date().dayOfWeek()-1);
1036 //qDebug("bit set %d ", event->dtStart().date().dayOfWeek()-1); 1042 //qDebug("bit set %d ", event->dtStart().date().dayOfWeek()-1);
1037 } 1043 }
1038 if ( duration != 0 ) r->setWeekly( freq, days, duration ); 1044 if ( duration != 0 ) r->setWeekly( freq, days, duration );
1039 else r->setWeekly( freq, days, endDate ); 1045 else r->setWeekly( freq, days, endDate );
1040 } else if ( recurrenceType == RecurrenceChooser::Monthly ) { 1046 } else if ( recurrenceType == RecurrenceChooser::Monthly ) {
1041 int freq = mMonthly->frequency(); 1047 int freq = mMonthly->frequency();
1042 if ( mMonthly->byPos() ) { 1048 if ( mMonthly->byPos() ) {
1043 int pos = mMonthly->count(); 1049 int pos = mMonthly->count();
1044 1050
1045 QBitArray days( 7 ); 1051 QBitArray days( 7 );
1046 days.fill( false ); 1052 days.fill( false );
1047 1053
1048 days.setBit( mMonthly->weekday() ); 1054 days.setBit( mMonthly->weekday() );
1049 if ( duration != 0 ) 1055 if ( duration != 0 )
1050 r->setMonthly( Recurrence::rMonthlyPos, freq, duration ); 1056 r->setMonthly( Recurrence::rMonthlyPos, freq, duration );
1051 else 1057 else
1052 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); 1058 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
1053 r->addMonthlyPos( pos, days ); 1059 r->addMonthlyPos( pos, days );
1054 } else { 1060 } else {
1055 // it's by day 1061 // it's by day
1056 int day = mMonthly->day(); 1062 int day = mMonthly->day();
1057 1063
1058 if ( duration != 0 ) { 1064 if ( duration != 0 ) {
1059 r->setMonthly( Recurrence::rMonthlyDay, freq, duration ); 1065 r->setMonthly( Recurrence::rMonthlyDay, freq, duration );
1060 } else { 1066 } else {
1061 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); 1067 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
1062 } 1068 }
1063 r->addMonthlyDay( day ); 1069 r->addMonthlyDay( day );
1064 } 1070 }
1065 } else if ( recurrenceType == RecurrenceChooser::Yearly ) { 1071 } else if ( recurrenceType == RecurrenceChooser::Yearly ) {
1066 //qDebug("RecurrenceChooser::Yearly "); 1072 //qDebug("RecurrenceChooser::Yearly ");
1067 int freq = mYearly->frequency(); 1073 int freq = mYearly->frequency();
1068 if ( mYearly->byDay() ) { 1074 if ( mYearly->byDay() ) {
1069 if ( duration != 0 ) { 1075 if ( duration != 0 ) {
1070 r->setYearly( Recurrence::rYearlyDay, freq, duration ); 1076 r->setYearly( Recurrence::rYearlyDay, freq, duration );
1071 } else { 1077 } else {
1072 r->setYearly( Recurrence::rYearlyDay, freq, endDate ); 1078 r->setYearly( Recurrence::rYearlyDay, freq, endDate );
1073 } 1079 }
1074 r->addYearlyNum( event->dtStart().date().dayOfYear() ); 1080 r->addYearlyNum( event->dtStart().date().dayOfYear() );
1075 } else { 1081 } else {
1076 if ( duration != 0 ) { 1082 if ( duration != 0 ) {
1077 r->setYearly( Recurrence::rYearlyMonth, freq, duration ); 1083 r->setYearly( Recurrence::rYearlyMonth, freq, duration );
1078 } else { 1084 } else {
1079 r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); 1085 r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
1080 } 1086 }
1081 r->addYearlyNum( mYearly->month() ); 1087 r->addYearlyNum( mYearly->month() );
1082 } 1088 }
1083 1089
1084 } 1090 }
1085 1091
1086 event->setExDates( mExceptions->dates() ); 1092 event->setExDates( mExceptions->dates() );
1087 } 1093 }
1088} 1094}
1089 1095
1090void KOEditorRecurrence::setDateTimeStr( const QString &str ) 1096void KOEditorRecurrence::setDateTimeStr( const QString &str )
1091{ 1097{
1092 mDateTimeLabel->setText( str ); 1098 mDateTimeLabel->setText( str );
1093} 1099}
1094 1100
1095bool KOEditorRecurrence::validateInput() 1101bool KOEditorRecurrence::validateInput()
1096{ 1102{
1097 // Check input here 1103 // Check input here
1098 1104
1099 return true; 1105 return true;
1100} 1106}
1101 1107
1102void KOEditorRecurrence::showExceptionsDialog() 1108void KOEditorRecurrence::showExceptionsDialog()
1103{ 1109{
1104 DateList dates = mExceptions->dates(); 1110 DateList dates = mExceptions->dates();
1105 int result = mExceptionsDialog->exec(); 1111 int result = mExceptionsDialog->exec();
1106 if ( result == QDialog::Rejected ) mExceptions->setDates( dates ); 1112 if ( result == QDialog::Rejected ) mExceptions->setDates( dates );
1107} 1113}
1108 1114
1109void KOEditorRecurrence::showRecurrenceRangeDialog() 1115void KOEditorRecurrence::showRecurrenceRangeDialog()
1110{ 1116{
1111 int duration = mRecurrenceRange->duration(); 1117 int duration = mRecurrenceRange->duration();
1112 QDate endDate = mRecurrenceRange->endDate(); 1118 QDate endDate = mRecurrenceRange->endDate();
1113 1119
1114 int result = mRecurrenceRangeDialog->exec(); 1120 int result = mRecurrenceRangeDialog->exec();
1115 if ( result == QDialog::Rejected ) { 1121 if ( result == QDialog::Rejected ) {
1116 mRecurrenceRange->setDuration( duration ); 1122 mRecurrenceRange->setDuration( duration );
1117 mRecurrenceRange->setEndDate( endDate ); 1123 mRecurrenceRange->setEndDate( endDate );
1118 } 1124 }
1119 1125
1120} 1126}
diff --git a/korganizer/koeventviewer.cpp b/korganizer/koeventviewer.cpp
index a690ab1..db695f5 100644
--- a/korganizer/koeventviewer.cpp
+++ b/korganizer/koeventviewer.cpp
@@ -1,831 +1,831 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#include <qcstring.h> 20#include <qcstring.h>
21#include <qwhatsthis.h> 21#include <qwhatsthis.h>
22#include <qdialog.h> 22#include <qdialog.h>
23#include <qapplication.h> 23#include <qapplication.h>
24#include <qlabel.h> 24#include <qlabel.h>
25#include <qlayout.h> 25#include <qlayout.h>
26 26
27#include <klocale.h> 27#include <klocale.h>
28#include <kapplication.h> 28#include <kapplication.h>
29#include <libkcal/event.h> 29#include <libkcal/event.h>
30#include <libkcal/todo.h> 30#include <libkcal/todo.h>
31#include <kdebug.h> 31#include <kdebug.h>
32#include <kiconloader.h> 32#include <kiconloader.h>
33#include <krun.h> 33#include <krun.h>
34#include <kglobal.h> 34#include <kglobal.h>
35#include <kprocess.h> 35#include <kprocess.h>
36#include "koprefs.h" 36#include "koprefs.h"
37 37
38#include <kabc/stdaddressbook.h> 38#include <kabc/stdaddressbook.h>
39 39
40#ifndef KORG_NODCOP 40#ifndef KORG_NODCOP
41#include <dcopclient.h> 41#include <dcopclient.h>
42#include "korganizer.h" 42#include "korganizer.h"
43#include "koprefs.h" 43#include "koprefs.h"
44#include "actionmanager.h" 44#include "actionmanager.h"
45#endif 45#endif
46 46
47#include "koeventviewer.h" 47#include "koeventviewer.h"
48//#ifndef KORG_NOKABC 48//#ifndef KORG_NOKABC
49//#include <kabc/stdaddressbook.h> 49//#include <kabc/stdaddressbook.h>
50//#define size count 50//#define size count
51//#endif 51//#endif
52 52
53#ifdef DESKTOP_VERSION 53#ifdef DESKTOP_VERSION
54#include <kabc/addresseedialog.h> 54#include <kabc/addresseedialog.h>
55#include <kabc/addresseeview.h> 55#include <kabc/addresseeview.h>
56#include <qprinter.h> 56#include <qprinter.h>
57#include <qpainter.h> 57#include <qpainter.h>
58#include <qpaintdevicemetrics.h> 58#include <qpaintdevicemetrics.h>
59#else //DESKTOP_VERSION 59#else //DESKTOP_VERSION
60#include <externalapphandler.h> 60#include <externalapphandler.h>
61#include <qtopia/qcopenvelope_qws.h> 61#include <qtopia/qcopenvelope_qws.h>
62#endif //DESKTOP_VERSION 62#endif //DESKTOP_VERSION
63 63
64KOEventViewer::KOEventViewer(QWidget *parent,const char *name) 64KOEventViewer::KOEventViewer(QWidget *parent,const char *name)
65 : QTextBrowser(parent,name) 65 : QTextBrowser(parent,name)
66{ 66{
67 mSyncMode = false; 67 mSyncMode = false;
68 mColorMode = 0; 68 mColorMode = 0;
69} 69}
70 70
71KOEventViewer::~KOEventViewer() 71KOEventViewer::~KOEventViewer()
72{ 72{
73} 73}
74 74
75void KOEventViewer::printMe() 75void KOEventViewer::printMe()
76{ 76{
77#ifdef DESKTOP_VERSION 77#ifdef DESKTOP_VERSION
78 78
79 KOPrintPrefs pp ( this ); 79 KOPrintPrefs pp ( this );
80 if (!pp.exec() ) 80 if (!pp.exec() )
81 return; 81 return;
82 int scaleval = pp.printMode() ; 82 int scaleval = pp.printMode() ;
83 83
84 QPrinter printer; 84 QPrinter printer;
85 if (!printer.setup() ) 85 if (!printer.setup() )
86 return; 86 return;
87 QPainter p; 87 QPainter p;
88 p.begin ( &printer ); 88 p.begin ( &printer );
89 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer ); 89 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer );
90 float dx, dy; 90 float dx, dy;
91 int wid = (m.width() * 9)/10; 91 int wid = (m.width() * 9)/10;
92 dx = (float) wid/(float)contentsWidth (); 92 dx = (float) wid/(float)contentsWidth ();
93 dy = (float)(m.height()) / (float)contentsHeight (); 93 dy = (float)(m.height()) / (float)contentsHeight ();
94 float scale; 94 float scale;
95 // scale to fit the width or height of the paper 95 // scale to fit the width or height of the paper
96 if ( dx < dy ) 96 if ( dx < dy )
97 scale = dx; 97 scale = dx;
98 else 98 else
99 scale = dy; 99 scale = dy;
100 100
101 p.translate( m.width()/10,0 ); 101 p.translate( m.width()/10,0 );
102 if ( scaleval == 2 || scaleval == 1 && scale < 1.0 ) { 102 if ( scaleval == 2 || scaleval == 1 && scale < 1.0 ) {
103 p.scale( scale, scale ); 103 p.scale( scale, scale );
104 } 104 }
105 drawContents ( &p, 0,0, contentsWidth (), contentsHeight () ); 105 drawContents ( &p, 0,0, contentsWidth (), contentsHeight () );
106 p.end(); 106 p.end();
107#endif 107#endif
108 108
109} 109}
110void KOEventViewer::setSource(const QString& n) 110void KOEventViewer::setSource(const QString& n)
111{ 111{
112 112
113 if ( n.left(8) == "todo_uid" ) { 113 if ( n.left(8) == "todo_uid" ) {
114 int midstr = 9; 114 int midstr = 9;
115#ifdef DESKTOP_VERSION 115#ifdef DESKTOP_VERSION
116 midstr = 11; 116 midstr = 11;
117#endif 117#endif
118 //qDebug("-%s- ", n.mid(midstr).latin1()); 118 //qDebug("-%s- ", n.mid(midstr).latin1());
119 emit showIncidence( n.mid(midstr) ); 119 emit showIncidence( n.mid(midstr) );
120 return; 120 return;
121 } 121 }
122 122
123 if ( n.left(3) == "uid" ) 123 if ( n.left(3) == "uid" )
124#ifdef DESKTOP_VERSION 124#ifdef DESKTOP_VERSION
125 { 125 {
126 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 126 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
127 KABC::AddressBook::Iterator it; 127 KABC::AddressBook::Iterator it;
128 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 128 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
129 // LR I do not understand, why the uid string is different on zaurus and desktop 129 // LR I do not understand, why the uid string is different on zaurus and desktop
130 QString uid = "uid://"+(*it).uid(); 130 QString uid = "uid://"+(*it).uid();
131 131
132 //qDebug("for *%s* +%s+ ", n.latin1(), uid.latin1()); 132 //qDebug("for *%s* +%s+ ", n.latin1(), uid.latin1());
133 if (n == uid ) { 133 if (n == uid ) {
134 //qDebug("found %s ",(*it).mobileHomePhone().latin1() ); 134 //qDebug("found %s ",(*it).mobileHomePhone().latin1() );
135 QDialog dia( this,"dia123", true ); 135 QDialog dia( this,"dia123", true );
136 dia.setCaption( i18n("Details of attendee") ); 136 dia.setCaption( i18n("Details of attendee") );
137 QVBoxLayout lay ( &dia ); 137 QVBoxLayout lay ( &dia );
138 KABC::AddresseeView av ( &dia ); 138 KABC::AddresseeView av ( &dia );
139 av.setAddressee( (*it) ); 139 av.setAddressee( (*it) );
140 lay.addWidget( &av ); 140 lay.addWidget( &av );
141 if ( QApplication::desktop()->width() < 480 ) 141 if ( QApplication::desktop()->width() < 480 )
142 dia.resize( 220, 240); 142 dia.resize( 220, 240);
143 else { 143 else {
144 dia.resize( 400,400); 144 dia.resize( 400,400);
145 } 145 }
146 dia.exec(); 146 dia.exec();
147 break; 147 break;
148 } 148 }
149 } 149 }
150 return; 150 return;
151 } 151 }
152#else 152#else
153 { 153 {
154 if ( "uid:organizer" == n ) { 154 if ( "uid:organizer" == n ) {
155 ExternalAppHandler::instance()->requestDetailsFromKAPI("", mCurrentIncidence->organizer(),""); 155 ExternalAppHandler::instance()->requestDetailsFromKAPI("", mCurrentIncidence->organizer(),"");
156 return; 156 return;
157 } 157 }
158 QPtrList<Attendee> attendees = mCurrentIncidence->attendees(); 158 QPtrList<Attendee> attendees = mCurrentIncidence->attendees();
159 if (attendees.count()) { 159 if (attendees.count()) {
160 Attendee *a; 160 Attendee *a;
161 for(a=attendees.first();a;a=attendees.next()) { 161 for(a=attendees.first();a;a=attendees.next()) {
162 if ( "uid:"+a->uid() == n ) { 162 if ( "uid:"+a->uid() == n ) {
163 bool res = ExternalAppHandler::instance()->requestDetailsFromKAPI(a->name(), a->email(), a->uid()); 163 bool res = ExternalAppHandler::instance()->requestDetailsFromKAPI(a->name(), a->email(), a->uid());
164 return; 164 return;
165 } 165 }
166 } 166 }
167 } 167 }
168 return; 168 return;
169 } 169 }
170 //requestNameEmailUidListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 170 //requestNameEmailUidListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
171 // the result should now arrive through method insertAttendees 171 // the result should now arrive through method insertAttendees
172 //QString uid = "uid:"+(*it).uid(); 172 //QString uid = "uid:"+(*it).uid();
173#endif 173#endif
174 if ( n.left(6) == "mailto" ) { 174 if ( n.left(6) == "mailto" ) {
175 // qDebug("KOEventViewer::setSource %s ", n.mid(7).latin1()); 175 // qDebug("KOEventViewer::setSource %s ", n.mid(7).latin1());
176#ifndef DESKTOP_VERSION 176#ifndef DESKTOP_VERSION
177 if ( n.mid(7,3) == "ALL" ) { 177 if ( n.mid(7,3) == "ALL" ) {
178 mailToAttendees( true ); 178 mailToAttendees( true );
179 } else if ( n.mid(7,4) == "RSVP" ) { 179 } else if ( n.mid(7,4) == "RSVP" ) {
180 mailToAttendees( false ); 180 mailToAttendees( false );
181 } else { 181 } else {
182 QCopEnvelope e("QPE/Application/ompi", "newMail(QString)" ); 182 QCopEnvelope e("QPE/Application/ompi", "newMail(QString)" );
183 e << n.mid(7); 183 e << n.mid(7);
184 } 184 }
185#endif 185#endif
186 186
187 } 187 }
188 188
189 189
190#ifndef KORG_NODCOP 190#ifndef KORG_NODCOP
191 kdDebug() << "KOEventViewer::setSource(): " << n << endl; 191 kdDebug() << "KOEventViewer::setSource(): " << n << endl;
192 QString tmpStr; 192 QString tmpStr;
193 if (n.startsWith("mailto:")) { 193 if (n.startsWith("mailto:")) {
194 KApplication::kApplication()->invokeMailer(n.mid(7),QString::null); 194 KApplication::kApplication()->invokeMailer(n.mid(7),QString::null);
195 //emit showIncidence(n); 195 //emit showIncidence(n);
196 return; 196 return;
197 } else if (n.startsWith("uid:")) { 197 } else if (n.startsWith("uid:")) {
198 DCOPClient *client = KApplication::kApplication()->dcopClient(); 198 DCOPClient *client = KApplication::kApplication()->dcopClient();
199 const QByteArray noParamData; 199 const QByteArray noParamData;
200 const QByteArray paramData; 200 const QByteArray paramData;
201 QByteArray replyData; 201 QByteArray replyData;
202 QCString replyTypeStr; 202 QCString replyTypeStr;
203#define PING_ABBROWSER (client->call("kaddressbook", "KAddressBookIface", "interfaces()", noParamData, replyTypeStr, replyData)) 203#define PING_ABBROWSER (client->call("kaddressbook", "KAddressBookIface", "interfaces()", noParamData, replyTypeStr, replyData))
204 bool foundAbbrowser = PING_ABBROWSER; 204 bool foundAbbrowser = PING_ABBROWSER;
205 205
206 if (foundAbbrowser) { 206 if (foundAbbrowser) {
207 //KAddressbook is already running, so just DCOP to it to bring up the contact editor 207 //KAddressbook is already running, so just DCOP to it to bring up the contact editor
208 //client->send("kaddressbook","KAddressBookIface", 208 //client->send("kaddressbook","KAddressBookIface",
209 QDataStream arg(paramData, IO_WriteOnly); 209 QDataStream arg(paramData, IO_WriteOnly);
210 arg << n.mid(6); 210 arg << n.mid(6);
211 client->send("kaddressbook", "KAddressBookIface", "showContactEditor( QString )", paramData); 211 client->send("kaddressbook", "KAddressBookIface", "showContactEditor( QString )", paramData);
212 return; 212 return;
213 } else { 213 } else {
214 /* 214 /*
215 KaddressBook is not already running. Pass it the UID of the contact via the command line while starting it - its neater. 215 KaddressBook is not already running. Pass it the UID of the contact via the command line while starting it - its neater.
216 We start it without its main interface 216 We start it without its main interface
217 */ 217 */
218 KIconLoader* iconLoader = new KIconLoader(); 218 KIconLoader* iconLoader = new KIconLoader();
219 QString iconPath = iconLoader->iconPath("go",KIcon::Small); 219 QString iconPath = iconLoader->iconPath("go",KIcon::Small);
220 ActionManager::setStartedKAddressBook(true); 220 ActionManager::setStartedKAddressBook(true);
221 tmpStr = "kaddressbook --editor-only --uid "; 221 tmpStr = "kaddressbook --editor-only --uid ";
222 tmpStr += KProcess::quote(n.mid(6)); 222 tmpStr += KProcess::quote(n.mid(6));
223 KRun::runCommand(tmpStr,"KAddressBook",iconPath); 223 KRun::runCommand(tmpStr,"KAddressBook",iconPath);
224 return; 224 return;
225 } 225 }
226 } else { 226 } else {
227 //QTextBrowser::setSource(n); 227 //QTextBrowser::setSource(n);
228 } 228 }
229#endif 229#endif
230} 230}
231void KOEventViewer::mailToAttendees( bool all ) 231void KOEventViewer::mailToAttendees( bool all )
232{ 232{
233 QPtrList<Attendee> attendees = mCurrentIncidence->attendees(); 233 QPtrList<Attendee> attendees = mCurrentIncidence->attendees();
234 if (attendees.count() == 0) return; 234 if (attendees.count() == 0) return;
235 QStringList nameList; 235 QStringList nameList;
236 QStringList emailList; 236 QStringList emailList;
237 QStringList uidList; 237 QStringList uidList;
238 Attendee* a; 238 Attendee* a;
239 for(a=attendees.first();a;a=attendees.next()) { 239 for(a=attendees.first();a;a=attendees.next()) {
240 if ( !all && !a->RSVP() ) continue; 240 if ( !all && !a->RSVP() ) continue;
241 if (!a->email().isEmpty()) { 241 if (!a->email().isEmpty()) {
242 nameList.append (a->name() ); 242 nameList.append (a->name() );
243 emailList.append (a->email() ); 243 emailList.append (a->email() );
244 uidList.append (a->uid() ); 244 uidList.append (a->uid() );
245 } 245 }
246 } 246 }
247 QString uid = "ComposeMailUIpick2"+mMailSubject; 247 QString uid = "ComposeMailUIpick2"+mMailSubject;
248#ifndef DESKTOP_VERSION 248#ifndef DESKTOP_VERSION
249 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); 249 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList);
250#endif 250#endif
251 251
252} 252}
253void KOEventViewer::addTag(const QString & tag,const QString & text) 253void KOEventViewer::addTag(const QString & tag,const QString & text)
254{ 254{
255 int number=text.contains("\n"); 255 int number=text.contains("\n");
256 QString str = "<" + tag + ">"; 256 QString str = "<" + tag + ">";
257 QString tmpText=text; 257 QString tmpText=text;
258 QString tmpStr=str; 258 QString tmpStr=str;
259 if(number !=-1) 259 if(number !=-1)
260 { 260 {
261 if (number > 0) { 261 if (number > 0) {
262 int pos=0; 262 int pos=0;
263 QString tmp; 263 QString tmp;
264 for(int i=0;i<=number;i++) { 264 for(int i=0;i<=number;i++) {
265 pos=tmpText.find("\n"); 265 pos=tmpText.find("\n");
266 tmp=tmpText.left(pos); 266 tmp=tmpText.left(pos);
267 tmpText=tmpText.right(tmpText.length()-pos-1); 267 tmpText=tmpText.right(tmpText.length()-pos-1);
268 tmpStr+=tmp+"<br>"; 268 tmpStr+=tmp+"<br>";
269 } 269 }
270 } 270 }
271 else tmpStr += tmpText; 271 else tmpStr += tmpText;
272 tmpStr+="</" + tag + ">"; 272 tmpStr+="</" + tag + ">";
273 mText.append(tmpStr); 273 mText.append(tmpStr);
274 } 274 }
275 else 275 else
276 { 276 {
277 str += text + "</" + tag + ">"; 277 str += text + "</" + tag + ">";
278 mText.append(str); 278 mText.append(str);
279 } 279 }
280} 280}
281 281
282void KOEventViewer::setColorMode( int m ) 282void KOEventViewer::setColorMode( int m )
283{ 283{
284 mColorMode = m; 284 mColorMode = m;
285} 285}
286void KOEventViewer::appendEvent(Event *event, int mode ) 286void KOEventViewer::appendEvent(Event *event, int mode )
287{ 287{
288 mMailSubject = ""; 288 mMailSubject = "";
289 mCurrentIncidence = event; 289 mCurrentIncidence = event;
290 bool shortDate = KOPrefs::instance()->mShortDateInViewer; 290 bool shortDate = KOPrefs::instance()->mShortDateInViewer;
291 bool wideScreen = ( QApplication::desktop()->width() >= 640 ); 291 bool wideScreen = ( QApplication::desktop()->width() >= 640 );
292 topLevelWidget()->setCaption(i18n("Event Viewer")); 292 topLevelWidget()->setCaption(i18n("Event Viewer"));
293 if ( mode == 0 ) { 293 if ( mode == 0 ) {
294 addTag("h2",deTag(event->summary())); 294 addTag("h2",deTag(event->summary()));
295 formatReadOnly(event); 295 formatReadOnly(event);
296 } 296 }
297 else { 297 else {
298 if ( mColorMode == 1 ) { 298 if ( mColorMode == 1 ) {
299 mText +="<font color=\"#00A000\">"; 299 mText +="<font color=\"#00A000\">";
300 } 300 }
301 if ( mColorMode == 2 ) { 301 if ( mColorMode == 2 ) {
302 mText +="<font color=\"#C00000\">"; 302 mText +="<font color=\"#C00000\">";
303 } 303 }
304 // mText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>"; 304 // mText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>";
305 if ( mode == 1 ) { 305 if ( mode == 1 ) {
306 addTag("h2",i18n( "Local: " ) +deTag(event->summary())); 306 addTag("h2",i18n( "Local: " ) +deTag(event->summary()));
307 } else { 307 } else {
308 addTag("h2",i18n( "Remote: " ) +deTag(event->summary())); 308 addTag("h2",i18n( "Remote: " ) +deTag(event->summary()));
309 } 309 }
310 formatReadOnly(event); 310 formatReadOnly(event);
311 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); 311 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) );
312 if ( mColorMode ) 312 if ( mColorMode )
313 mText += "</font>"; 313 mText += "</font>";
314 } 314 }
315 mMailSubject += i18n( "Meeting " )+ event->summary(); 315 mMailSubject += i18n( "Meeting " )+ event->summary();
316 if (event->cancelled ()) { 316 if (event->cancelled ()) {
317 mText +="<font color=\"#B00000\">"; 317 mText +="<font color=\"#B00000\">";
318 addTag("i",i18n("This event has been cancelled!")); 318 addTag("i",i18n("This event has been cancelled!"));
319 mText.append("<br>"); 319 mText.append("<br>");
320 mText += "</font>"; 320 mText += "</font>";
321 mMailSubject += i18n("(cancelled)"); 321 mMailSubject += i18n("(cancelled)");
322 } 322 }
323 323
324 if (event->doesFloat()) { 324 if (event->doesFloat()) {
325 if (event->isMultiDay()) { 325 if (event->isMultiDay()) {
326 mText.append(i18n("<p><b>From:</b> %1 </p><p><b>To:</b> %2</p>") 326 mText.append(i18n("<p><b>From:</b> %1 </p><p><b>To:</b> %2</p>")
327 .arg(event->dtStartDateStr(shortDate)) 327 .arg(event->dtStartDateStr(shortDate))
328 .arg(event->dtEndDateStr(shortDate))); 328 .arg(event->dtEndDateStr(shortDate)));
329 } else { 329 } else {
330 mText.append(i18n("<p><b>On:</b> %1</p>").arg(event->dtStartDateStr( shortDate ))); 330 mText.append(i18n("<p><b>On:</b> %1</p>").arg(event->dtStartDateStr( shortDate )));
331 } 331 }
332 } else { 332 } else {
333 if (event->isMultiDay()) { 333 if (event->isMultiDay()) {
334 mText.append(i18n("<p><b>From:</b> %1</p> ") 334 mText.append(i18n("<p><b>From:</b> %1</p> ")
335 .arg(event->dtStartStr( shortDate))); 335 .arg(event->dtStartStr( shortDate)));
336 mText.append(i18n("<p><b>To:</b> %1</p>") 336 mText.append(i18n("<p><b>To:</b> %1</p>")
337 .arg(event->dtEndStr(shortDate))); 337 .arg(event->dtEndStr(shortDate)));
338 } else { 338 } else {
339 mText.append(i18n("<p><b>From:</b> %1 <b>To:</b> %2</p>") 339 mText.append(i18n("<p><b>From:</b> %1 <b>To:</b> %2</p>")
340 .arg(event->dtStartTimeStr()) 340 .arg(event->dtStartTimeStr())
341 .arg(event->dtEndTimeStr())); 341 .arg(event->dtEndTimeStr()));
342 mText.append(i18n("<p><b>On:</b> %1</p> ") 342 mText.append(i18n("<p><b>On:</b> %1</p> ")
343 .arg(event->dtStartDateStr( shortDate ))); 343 .arg(event->dtStartDateStr( shortDate )));
344 } 344 }
345 } 345 }
346 if (!event->location().isEmpty()) { 346 if (!event->location().isEmpty()) {
347 addTag("p","<b>"+i18n("Location: ")+"</b>"+ deTag(event->location() ) ); 347 addTag("p","<b>"+i18n("Location: ")+"</b>"+ deTag(event->location() ) );
348 mMailSubject += i18n(" at ") + event->location(); 348 mMailSubject += i18n(" at ") + event->location();
349 } 349 }
350 if (event->recurrence()->doesRecur()) { 350 if (event->doesRecur()) {
351 351
352 QString recurText = event->recurrence()->recurrenceText(); 352 QString recurText = event->recurrenceText();
353 addTag("p","<em>" + i18n("This is a %1 recurring event.").arg(recurText ) + "</em>"); 353 addTag("p","<em>" + i18n("This is a %1 recurring event.").arg(recurText ) + "</em>");
354 bool ok; 354 bool ok;
355 QDate start = QDate::currentDate(); 355 QDate start = QDate::currentDate();
356 QDateTime next; 356 QDateTime next;
357 next = event->getNextOccurence( QDateTime::currentDateTime() , &ok ); 357 next = event->getNextOccurence( QDateTime::currentDateTime() , &ok );
358 if ( ok ) { 358 if ( ok ) {
359 if ( wideScreen ){ 359 if ( wideScreen ){
360 addTag("p",i18n("<b>Next recurrence is on:</b>") +" " + KGlobal::locale()->formatDate( next.date(), shortDate ) ); 360 addTag("p",i18n("<b>Next recurrence is on:</b>") +" " + KGlobal::locale()->formatDate( next.date(), shortDate ) );
361 } else { 361 } else {
362 addTag("p",i18n("<b>Next recurrence is on:</b>") ); 362 addTag("p",i18n("<b>Next recurrence is on:</b>") );
363 addTag("p", KGlobal::locale()->formatDate( next.date(), shortDate )); 363 addTag("p", KGlobal::locale()->formatDate( next.date(), shortDate ));
364 } 364 }
365 mMailSubject += i18n(" - " )+ KGlobal::locale()->formatDateTime( next, true ); 365 mMailSubject += i18n(" - " )+ KGlobal::locale()->formatDateTime( next, true );
366 366
367 } else { 367 } else {
368 bool last; 368 bool last;
369 QDate nextd; 369 QDate nextd;
370 nextd = event->recurrence()->getPreviousDate( QDate::currentDate() , &last ); 370 nextd = event->recurrence()->getPreviousDate( QDate::currentDate() , &last );
371 if ( last ) { 371 if ( last ) {
372 if ( wideScreen ){ 372 if ( wideScreen ){
373 addTag("p",i18n("<b>Last recurrence was on:</b>") +" " + KGlobal::locale()->formatDate( nextd, shortDate )); 373 addTag("p",i18n("<b>Last recurrence was on:</b>") +" " + KGlobal::locale()->formatDate( nextd, shortDate ));
374 } else{ 374 } else{
375 addTag("p",i18n("<b>Last recurrence was on:</b>") ); 375 addTag("p",i18n("<b>Last recurrence was on:</b>") );
376 addTag("p", KGlobal::locale()->formatDate( nextd, shortDate )); 376 addTag("p", KGlobal::locale()->formatDate( nextd, shortDate ));
377 } 377 }
378 } 378 }
379 } 379 }
380 } else { 380 } else {
381 mMailSubject += i18n(" - " )+event->dtStartStr( true ); 381 mMailSubject += i18n(" - " )+event->dtStartStr( true );
382 382
383 } 383 }
384 384
385 385
386 if (event->isAlarmEnabled()) { 386 if (event->isAlarmEnabled()) {
387 Alarm *alarm =event->alarms().first() ; 387 Alarm *alarm =event->alarms().first() ;
388 QDateTime t = alarm->time(); 388 QDateTime t = alarm->time();
389 QString s =i18n("( %1 before )").arg( alarm->offsetText() ); 389 QString s =i18n("( %1 before )").arg( alarm->offsetText() );
390 if(wideScreen ){ 390 if(wideScreen ){
391 addTag("p",i18n("<b>Alarm on: ") + s +" </b>"+ KGlobal::locale()->formatDateTime( t, shortDate )); 391 addTag("p",i18n("<b>Alarm on: ") + s +" </b>"+ KGlobal::locale()->formatDateTime( t, shortDate ));
392 }else{ 392 }else{
393 addTag("p",i18n("<b>Alarm on: ") + s +" </b>"); 393 addTag("p",i18n("<b>Alarm on: ") + s +" </b>");
394 addTag("p", KGlobal::locale()->formatDateTime( t, shortDate )); 394 addTag("p", KGlobal::locale()->formatDateTime( t, shortDate ));
395 } 395 }
396 //addTag("p",s); 396 //addTag("p",s);
397 } 397 }
398 398
399 addTag("p","<b>"+i18n("Access: ") + "</b>" + event->secrecyStr()); 399 addTag("p","<b>"+i18n("Access: ") + "</b>" + event->secrecyStr());
400 400
401 formatCategories(event); 401 formatCategories(event);
402 402
403 formatAttendees(event); 403 formatAttendees(event);
404 404
405 if ( KOPrefs::instance()->mEVshowCreated ) { 405 if ( KOPrefs::instance()->mEVshowCreated ) {
406 if(wideScreen ){ 406 if(wideScreen ){
407 addTag("p",i18n("<b>Created: ") +" </b>"+KGlobal::locale()->formatDateTime( event->created(), shortDate )); 407 addTag("p",i18n("<b>Created: ") +" </b>"+KGlobal::locale()->formatDateTime( event->created(), shortDate ));
408 }else{ 408 }else{
409 addTag("p",i18n("<b>Created: ") +" </b>"); 409 addTag("p",i18n("<b>Created: ") +" </b>");
410 addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate )); 410 addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate ));
411 } 411 }
412 412
413 413
414 } 414 }
415 if ( KOPrefs::instance()->mEVshowChanged ) { 415 if ( KOPrefs::instance()->mEVshowChanged ) {
416 if(wideScreen ){ 416 if(wideScreen ){
417 addTag("p",i18n("<b>Last modified: ") +" </b>" + KGlobal::locale()->formatDateTime( event->lastModified(), shortDate ) ); 417 addTag("p",i18n("<b>Last modified: ") +" </b>" + KGlobal::locale()->formatDateTime( event->lastModified(), shortDate ) );
418 }else{ 418 }else{
419 addTag("p",i18n("<b>Last modified: ") +" </b>"); 419 addTag("p",i18n("<b>Last modified: ") +" </b>");
420 addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); 420 addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate ));
421 } 421 }
422 422
423 } 423 }
424 if ( KOPrefs::instance()->mEVshowDetails ) { 424 if ( KOPrefs::instance()->mEVshowDetails ) {
425 if (!event->description().isEmpty()) { 425 if (!event->description().isEmpty()) {
426 addTag("p",i18n("<b>Details: </b>")); 426 addTag("p",i18n("<b>Details: </b>"));
427 addTag("p",deTag(event->description())); 427 addTag("p",deTag(event->description()));
428 } 428 }
429 } 429 }
430 setText(mText); 430 setText(mText);
431 //QWhatsThis::add(this,mText); 431 //QWhatsThis::add(this,mText);
432 432
433} 433}
434 434
435void KOEventViewer::appendTodo(Todo *event, int mode ) 435void KOEventViewer::appendTodo(Todo *event, int mode )
436{ 436{
437 mMailSubject = ""; 437 mMailSubject = "";
438 mCurrentIncidence = event; 438 mCurrentIncidence = event;
439 topLevelWidget()->setCaption(i18n("Todo Viewer")); 439 topLevelWidget()->setCaption(i18n("Todo Viewer"));
440 bool shortDate = KOPrefs::instance()->mShortDateInViewer; 440 bool shortDate = KOPrefs::instance()->mShortDateInViewer;
441 bool wideScreen = ( QApplication::desktop()->width() >= 640 ); 441 bool wideScreen = ( QApplication::desktop()->width() >= 640 );
442 if (mode == 0 ) { 442 if (mode == 0 ) {
443 addTag("h2",deTag(event->summary())); 443 addTag("h2",deTag(event->summary()));
444 formatReadOnly(event); 444 formatReadOnly(event);
445 } 445 }
446 else { 446 else {
447 if ( mColorMode == 1 ) { 447 if ( mColorMode == 1 ) {
448 mText +="<font color=\"#00A000\">"; 448 mText +="<font color=\"#00A000\">";
449 } 449 }
450 if ( mColorMode == 2 ) { 450 if ( mColorMode == 2 ) {
451 mText +="<font color=\"#B00000\">"; 451 mText +="<font color=\"#B00000\">";
452 } 452 }
453 if ( mode == 1 ) { 453 if ( mode == 1 ) {
454 addTag("h2",i18n( "Local: " ) +deTag(event->summary())); 454 addTag("h2",i18n( "Local: " ) +deTag(event->summary()));
455 } else { 455 } else {
456 addTag("h2",i18n( "Remote: " ) +deTag(event->summary())); 456 addTag("h2",i18n( "Remote: " ) +deTag(event->summary()));
457 } 457 }
458 formatReadOnly(event); 458 formatReadOnly(event);
459 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); 459 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) );
460 if ( mColorMode ) 460 if ( mColorMode )
461 mText += "</font>"; 461 mText += "</font>";
462 } 462 }
463 mMailSubject += i18n( "Todo " )+ event->summary(); 463 mMailSubject += i18n( "Todo " )+ event->summary();
464 464
465 if ( event->percentComplete() == 100 && event->hasCompletedDate() ) { 465 if ( event->percentComplete() == 100 && event->hasCompletedDate() ) {
466 mText +="<font color=\"#B00000\">"; 466 mText +="<font color=\"#B00000\">";
467 addTag("i", i18n("<p><i>Completed on %1</i></p>").arg( event->completedStr(KOPrefs::instance()->mShortDateInViewer) ) ); 467 addTag("i", i18n("<p><i>Completed on %1</i></p>").arg( event->completedStr(KOPrefs::instance()->mShortDateInViewer) ) );
468 mText += "</font>"; 468 mText += "</font>";
469 } else { 469 } else {
470 mText.append(i18n("<p><i>%1 % completed</i></p>") 470 mText.append(i18n("<p><i>%1 % completed</i></p>")
471 .arg(event->percentComplete())); 471 .arg(event->percentComplete()));
472 } 472 }
473 473
474 if (event->cancelled ()) { 474 if (event->cancelled ()) {
475 mText +="<font color=\"#B00000\">"; 475 mText +="<font color=\"#B00000\">";
476 addTag("i",i18n("This todo has been cancelled!")); 476 addTag("i",i18n("This todo has been cancelled!"));
477 mText.append("<br>"); 477 mText.append("<br>");
478 mText += "</font>"; 478 mText += "</font>";
479 mMailSubject += i18n("(cancelled)"); 479 mMailSubject += i18n("(cancelled)");
480 } 480 }
481 481
482 482
483 483
484 if (event->recurrence()->doesRecur()) { 484 if (event->doesRecur()) {
485 485
486 QString recurText = event->recurrence()->recurrenceText(); 486 QString recurText = event->recurrence()->recurrenceText();
487 addTag("p","<em>" + i18n("This is a %1 recurring todo.").arg(recurText ) + "</em>"); 487 addTag("p","<em>" + i18n("This is a %1 recurring todo.").arg(recurText ) + "</em>");
488 488
489 } 489 }
490 if (event->hasStartDate()) { 490 if (event->hasStartDate()) {
491 mText.append(i18n("<p><b>Start on:</b> %1</p>").arg(event->dtStartStr(KOPrefs::instance()->mShortDateInViewer))); 491 mText.append(i18n("<p><b>Start on:</b> %1</p>").arg(event->dtStartStr(KOPrefs::instance()->mShortDateInViewer)));
492 } 492 }
493 if (event->hasDueDate()) { 493 if (event->hasDueDate()) {
494 mText.append(i18n("<p><b>Due on:</b> %1</p>").arg(event->dtDueStr(KOPrefs::instance()->mShortDateInViewer))); 494 mText.append(i18n("<p><b>Due on:</b> %1</p>").arg(event->dtDueStr(KOPrefs::instance()->mShortDateInViewer)));
495 mMailSubject += i18n(" - " )+event->dtDueStr( true ); 495 mMailSubject += i18n(" - " )+event->dtDueStr( true );
496 } 496 }
497 if (!event->location().isEmpty()) { 497 if (!event->location().isEmpty()) {
498 addTag("p","<b>"+i18n("Location: ")+"</b>"+ deTag(event->location() ) ); 498 addTag("p","<b>"+i18n("Location: ")+"</b>"+ deTag(event->location() ) );
499 mMailSubject += i18n(" at ") + event->location(); 499 mMailSubject += i18n(" at ") + event->location();
500 } 500 }
501 mText.append(i18n("<p><b>Priority:</b> %2</p>") 501 mText.append(i18n("<p><b>Priority:</b> %2</p>")
502 .arg(QString::number(event->priority()))); 502 .arg(QString::number(event->priority())));
503 503
504 if (event->isAlarmEnabled()) { 504 if (event->isAlarmEnabled()) {
505 Alarm *alarm =event->alarms().first() ; 505 Alarm *alarm =event->alarms().first() ;
506 QDateTime t = alarm->time(); 506 QDateTime t = alarm->time();
507 QString s =i18n("( %1 before )").arg( alarm->offsetText() ); 507 QString s =i18n("( %1 before )").arg( alarm->offsetText() );
508 if ( wideScreen ) { 508 if ( wideScreen ) {
509 addTag("p",i18n("<b>Alarm on: ") + s +" </b>"+ KGlobal::locale()->formatDateTime( t, shortDate )); 509 addTag("p",i18n("<b>Alarm on: ") + s +" </b>"+ KGlobal::locale()->formatDateTime( t, shortDate ));
510 } else { 510 } else {
511 addTag("p",i18n("<b>Alarm on: ") + s +" </b>"); 511 addTag("p",i18n("<b>Alarm on: ") + s +" </b>");
512 addTag("p", KGlobal::locale()->formatDateTime( t, shortDate )); 512 addTag("p", KGlobal::locale()->formatDateTime( t, shortDate ));
513 } 513 }
514 } 514 }
515 515
516 addTag("p","<b>"+i18n("Access: ") + "</b>" + event->secrecyStr()); 516 addTag("p","<b>"+i18n("Access: ") + "</b>" + event->secrecyStr());
517 517
518 formatCategories(event); 518 formatCategories(event);
519 519
520 formatAttendees(event); 520 formatAttendees(event);
521 521
522 if ( KOPrefs::instance()->mEVshowCreated ) { 522 if ( KOPrefs::instance()->mEVshowCreated ) {
523 if(wideScreen ){ 523 if(wideScreen ){
524 524
525 addTag("p",i18n("<b>Created: ") +" </b>"+KGlobal::locale()->formatDateTime( event->created(), shortDate )); 525 addTag("p",i18n("<b>Created: ") +" </b>"+KGlobal::locale()->formatDateTime( event->created(), shortDate ));
526 526
527 } else { 527 } else {
528 addTag("p",i18n("<b>Created: ") +" </b>"); 528 addTag("p",i18n("<b>Created: ") +" </b>");
529 addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate )); 529 addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate ));
530 } 530 }
531 } 531 }
532 if ( KOPrefs::instance()->mEVshowChanged ) { 532 if ( KOPrefs::instance()->mEVshowChanged ) {
533 if(wideScreen ){ 533 if(wideScreen ){
534 addTag("p",i18n("<b>Last modified: ") +" </b>" +KGlobal::locale()->formatDateTime( event->lastModified(), shortDate ) ); 534 addTag("p",i18n("<b>Last modified: ") +" </b>" +KGlobal::locale()->formatDateTime( event->lastModified(), shortDate ) );
535 535
536 } else { 536 } else {
537 addTag("p",i18n("<b>Last modified: ") +" </b>"); 537 addTag("p",i18n("<b>Last modified: ") +" </b>");
538 addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); 538 addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate ));
539 } 539 }
540 } 540 }
541 if ( event->relatedTo() ) { 541 if ( event->relatedTo() ) {
542 addTag("b",i18n("Parent todo:<br>")); 542 addTag("b",i18n("Parent todo:<br>"));
543 543
544 QString t_name = "[" +QString::number(event->relatedTo()->priority()) + "/" + QString::number(((Todo*)event->relatedTo())->percentComplete())+"%] ";// +event->relatedTo()->summary()); 544 QString t_name = "[" +QString::number(event->relatedTo()->priority()) + "/" + QString::number(((Todo*)event->relatedTo())->percentComplete())+"%] ";// +event->relatedTo()->summary());
545 545
546 mText += t_name; 546 mText += t_name;
547 mText += "<a href=\"todo_uid:" + event->relatedTo()->uid() + "\">"; 547 mText += "<a href=\"todo_uid:" + event->relatedTo()->uid() + "\">";
548 mText += deTag(event->relatedTo()->summary()); 548 mText += deTag(event->relatedTo()->summary());
549 mText += "</a><br>"; 549 mText += "</a><br>";
550 550
551 // mText.append(deTag("[" +QString::number(event->relatedTo()->priority()) + "/" + QString::number(((Todo*)event->relatedTo())->percentComplete())+"%] " +event->relatedTo()->summary()) +"<br>"); 551 // mText.append(deTag("[" +QString::number(event->relatedTo()->priority()) + "/" + QString::number(((Todo*)event->relatedTo())->percentComplete())+"%] " +event->relatedTo()->summary()) +"<br>");
552 } 552 }
553 QPtrList<Incidence> Relations = event->relations(); 553 QPtrList<Incidence> Relations = event->relations();
554 Incidence *to; 554 Incidence *to;
555 if ( Relations.first() ) 555 if ( Relations.first() )
556 addTag("b",i18n("Sub todos:<br>")); 556 addTag("b",i18n("Sub todos:<br>"));
557 for (to=Relations.first();to;to=Relations.next()) { 557 for (to=Relations.first();to;to=Relations.next()) {
558 QString t_name = "[" +QString::number(((Todo*)to)->priority()) + "/" + QString::number(((Todo*)to)->percentComplete())+"%] ";// +to->relatedTo()->summary()); 558 QString t_name = "[" +QString::number(((Todo*)to)->priority()) + "/" + QString::number(((Todo*)to)->percentComplete())+"%] ";// +to->relatedTo()->summary());
559 mText += t_name; 559 mText += t_name;
560 mText += "<a href=\"todo_uid:" + to->uid() + "\">"; 560 mText += "<a href=\"todo_uid:" + to->uid() + "\">";
561 mText += deTag(to->summary()); 561 mText += deTag(to->summary());
562 mText += "</a><br>"; 562 mText += "</a><br>";
563 563
564 } 564 }
565 565
566 if ( KOPrefs::instance()->mEVshowDetails ) { 566 if ( KOPrefs::instance()->mEVshowDetails ) {
567 if (!event->description().isEmpty()) { 567 if (!event->description().isEmpty()) {
568 addTag("p",i18n("<b>Details: </b>")); 568 addTag("p",i18n("<b>Details: </b>"));
569 addTag("p",deTag(event->description())); 569 addTag("p",deTag(event->description()));
570 } 570 }
571 } 571 }
572 setText(mText); 572 setText(mText);
573} 573}
574 574
575void KOEventViewer::formatCategories(Incidence *event) 575void KOEventViewer::formatCategories(Incidence *event)
576{ 576{
577 if (!event->categoriesStr().isEmpty()) { 577 if (!event->categoriesStr().isEmpty()) {
578 if (event->categories().count() == 1) { 578 if (event->categories().count() == 1) {
579 addTag("p","<b>"+i18n("Category") + ":</b> " + event->categoriesStrWithSpace()); 579 addTag("p","<b>"+i18n("Category") + ":</b> " + event->categoriesStrWithSpace());
580 } else { 580 } else {
581 addTag("p","<b>"+i18n("Categories")+":</b> " + event->categoriesStrWithSpace() ) ; 581 addTag("p","<b>"+i18n("Categories")+":</b> " + event->categoriesStrWithSpace() ) ;
582 } 582 }
583 } 583 }
584} 584}
585void KOEventViewer::formatAttendees(Incidence *event) 585void KOEventViewer::formatAttendees(Incidence *event)
586{ 586{
587 QPtrList<Attendee> attendees = event->attendees(); 587 QPtrList<Attendee> attendees = event->attendees();
588 if (attendees.count()) { 588 if (attendees.count()) {
589 589
590 590
591 QString iconPath = KGlobal::iconLoader()->iconPath("mailappt",KIcon::Small); 591 QString iconPath = KGlobal::iconLoader()->iconPath("mailappt",KIcon::Small);
592 QString NOiconPath = KGlobal::iconLoader()->iconPath("nomailappt",KIcon::Small); 592 QString NOiconPath = KGlobal::iconLoader()->iconPath("nomailappt",KIcon::Small);
593 addTag("h3",i18n("Organizer")); 593 addTag("h3",i18n("Organizer"));
594 mText.append("<ul><li>"); 594 mText.append("<ul><li>");
595#ifndef KORG_NOKABC 595#ifndef KORG_NOKABC
596 596
597#ifdef DESKTOP_VERSION 597#ifdef DESKTOP_VERSION
598 KABC::AddressBook *add_book = KABC::StdAddressBook::self(); 598 KABC::AddressBook *add_book = KABC::StdAddressBook::self();
599 KABC::Addressee::List addressList; 599 KABC::Addressee::List addressList;
600 addressList = add_book->findByEmail(event->organizer()); 600 addressList = add_book->findByEmail(event->organizer());
601 KABC::Addressee o = addressList.first(); 601 KABC::Addressee o = addressList.first();
602 if (!o.isEmpty() && addressList.size()<2) { 602 if (!o.isEmpty() && addressList.size()<2) {
603 mText += "<a href=\"uid:" + o.uid() + "\">"; 603 mText += "<a href=\"uid:" + o.uid() + "\">";
604 mText += o.formattedName(); 604 mText += o.formattedName();
605 mText += "</a>\n"; 605 mText += "</a>\n";
606 } else { 606 } else {
607 mText.append(event->organizer()); 607 mText.append(event->organizer());
608 } 608 }
609#else //DESKTOP_VERSION 609#else //DESKTOP_VERSION
610 mText += "<a href=\"uid:organizer\">"; 610 mText += "<a href=\"uid:organizer\">";
611 mText += event->organizer(); 611 mText += event->organizer();
612 mText += "</a>\n"; 612 mText += "</a>\n";
613#endif //DESKTOP_VERSION 613#endif //DESKTOP_VERSION
614 614
615 615
616#else 616#else
617 mText.append(event->organizer()); 617 mText.append(event->organizer());
618#endif 618#endif
619 619
620 if (iconPath) { 620 if (iconPath) {
621 mText += " <a href=\"mailto:" + event->organizer() + "\">"; 621 mText += " <a href=\"mailto:" + event->organizer() + "\">";
622 mText += "<IMG src=\"" + iconPath + "\">"; 622 mText += "<IMG src=\"" + iconPath + "\">";
623 mText += "</a>\n"; 623 mText += "</a>\n";
624 } 624 }
625 mText.append("</li></ul>"); 625 mText.append("</li></ul>");
626 626
627 addTag("h3",i18n("Attendees")); 627 addTag("h3",i18n("Attendees"));
628 Attendee *a; 628 Attendee *a;
629 mText.append("<ul>"); 629 mText.append("<ul>");
630 int a_count = 0; 630 int a_count = 0;
631 int a_count_nr = 0; 631 int a_count_nr = 0;
632 632
633 for(a=attendees.first();a;a=attendees.next()) { 633 for(a=attendees.first();a;a=attendees.next()) {
634#ifndef KORG_NOKABC 634#ifndef KORG_NOKABC
635#ifdef DESKTOP_VERSION 635#ifdef DESKTOP_VERSION
636 if (a->name().isEmpty()) { 636 if (a->name().isEmpty()) {
637 addressList = add_book->findByEmail(a->email()); 637 addressList = add_book->findByEmail(a->email());
638 KABC::Addressee o = addressList.first(); 638 KABC::Addressee o = addressList.first();
639 if (!o.isEmpty() && addressList.size()<2) { 639 if (!o.isEmpty() && addressList.size()<2) {
640 mText += "<a href=\"uid:" + o.uid() + "\">"; 640 mText += "<a href=\"uid:" + o.uid() + "\">";
641 mText += o.formattedName(); 641 mText += o.formattedName();
642 mText += "</a>\n"; 642 mText += "</a>\n";
643 } else { 643 } else {
644 mText += "<li>"; 644 mText += "<li>";
645 mText.append(a->email()); 645 mText.append(a->email());
646 mText += "\n"; 646 mText += "\n";
647 } 647 }
648 } else { 648 } else {
649 mText += "<li><a href=\"uid:" + a->uid() + "\">"; 649 mText += "<li><a href=\"uid:" + a->uid() + "\">";
650 if (!a->name().isEmpty()) mText += a->name(); 650 if (!a->name().isEmpty()) mText += a->name();
651 else mText += a->email(); 651 else mText += a->email();
652 mText += "</a>\n"; 652 mText += "</a>\n";
653 } 653 }
654#else //DESKTOP_VERSION 654#else //DESKTOP_VERSION
655 mText += "<li><a href=\"uid:" + a->uid() + "\">"; 655 mText += "<li><a href=\"uid:" + a->uid() + "\">";
656 if (!a->name().isEmpty()) mText += a->name(); 656 if (!a->name().isEmpty()) mText += a->name();
657 else mText += a->email(); 657 else mText += a->email();
658 mText += "</a>\n"; 658 mText += "</a>\n";
659#endif //DESKTOP_VERSION 659#endif //DESKTOP_VERSION
660#else 660#else
661 //qDebug("nokabc "); 661 //qDebug("nokabc ");
662 mText += "<li><a href=\"uid:" + a->uid() + "\">"; 662 mText += "<li><a href=\"uid:" + a->uid() + "\">";
663 if (!a->name().isEmpty()) mText += a->name(); 663 if (!a->name().isEmpty()) mText += a->name();
664 else mText += a->email(); 664 else mText += a->email();
665 mText += "</a>\n"; 665 mText += "</a>\n";
666#endif 666#endif
667 667
668 668
669 if (!a->email().isEmpty()) { 669 if (!a->email().isEmpty()) {
670 if (iconPath) { 670 if (iconPath) {
671 mText += "<a href=\"mailto:" + a->name() +" <" + a->email() + ">:" + mMailSubject + "\">"; 671 mText += "<a href=\"mailto:" + a->name() +" <" + a->email() + ">:" + mMailSubject + "\">";
672 if ( a->RSVP() ) { 672 if ( a->RSVP() ) {
673 ++a_count_nr; 673 ++a_count_nr;
674 mText += "<IMG src=\"" + iconPath + "\">"; 674 mText += "<IMG src=\"" + iconPath + "\">";
675 } 675 }
676 else { 676 else {
677 ++a_count; 677 ++a_count;
678 mText += "<IMG src=\"" + NOiconPath + "\">"; 678 mText += "<IMG src=\"" + NOiconPath + "\">";
679 } 679 }
680 mText += "</a>\n"; 680 mText += "</a>\n";
681 } 681 }
682 } 682 }
683 if (a->status() != Attendee::NeedsAction ) 683 if (a->status() != Attendee::NeedsAction )
684 mText +="[" + a->statusStr() + "] "; 684 mText +="[" + a->statusStr() + "] ";
685 if (a->role() == Attendee::Chair ) 685 if (a->role() == Attendee::Chair )
686 mText +="(" + a->roleStr().left(1) + ".)"; 686 mText +="(" + a->roleStr().left(1) + ".)";
687 } 687 }
688 mText.append("</li></ul>"); 688 mText.append("</li></ul>");
689 if ( (a_count+a_count_nr) > 1 ) { 689 if ( (a_count+a_count_nr) > 1 ) {
690 mText += "<a href=\"mailto:ALL\">"; 690 mText += "<a href=\"mailto:ALL\">";
691 mText += i18n( "Mail to all" ); 691 mText += i18n( "Mail to all" );
692 mText += "</a> ( "; 692 mText += "</a> ( ";
693 mText += "<IMG src=\"" + iconPath + "\">"; 693 mText += "<IMG src=\"" + iconPath + "\">";
694 mText += i18n( " and " ); 694 mText += i18n( " and " );
695 mText += "<IMG src=\"" + NOiconPath + "\"> )"; 695 mText += "<IMG src=\"" + NOiconPath + "\"> )";
696 mText += "<br>\n"; 696 mText += "<br>\n";
697 697
698 698
699 } 699 }
700 if ( a_count_nr > 1 ) { 700 if ( a_count_nr > 1 ) {
701 mText += "<a href=\"mailto:RSVP\">"; 701 mText += "<a href=\"mailto:RSVP\">";
702 mText += i18n( "Mail to selected" ); 702 mText += i18n( "Mail to selected" );
703 mText += "</a> ( "; 703 mText += "</a> ( ";
704 mText += i18n( "<IMG src=\"%1\"> only )").arg ( iconPath ); 704 mText += i18n( "<IMG src=\"%1\"> only )").arg ( iconPath );
705 mText += "<br>\n"; 705 mText += "<br>\n";
706 } 706 }
707 } 707 }
708 708
709} 709}
710void KOEventViewer::appendJournal(Journal *jour, int mode ) 710void KOEventViewer::appendJournal(Journal *jour, int mode )
711{ 711{
712 bool shortDate = KOPrefs::instance()->mShortDateInViewer; 712 bool shortDate = KOPrefs::instance()->mShortDateInViewer;
713 QString text_d = i18n("Journal from: "); 713 QString text_d = i18n("Journal from: ");
714 if ( !jour->summary().isEmpty() ) 714 if ( !jour->summary().isEmpty() )
715 text_d = jour->summary(); 715 text_d = jour->summary();
716 if (mode == 0 ) { 716 if (mode == 0 ) {
717 addTag("h2", text_d ); 717 addTag("h2", text_d );
718 } 718 }
719 else { 719 else {
720 if ( mode == 1 ) { 720 if ( mode == 1 ) {
721 addTag("h3",i18n( "Local: " ) + text_d ); 721 addTag("h3",i18n( "Local: " ) + text_d );
722 } else { 722 } else {
723 addTag("h3",i18n( "Remote: " ) + text_d ); 723 addTag("h3",i18n( "Remote: " ) + text_d );
724 } 724 }
725 } 725 }
726 topLevelWidget()->setCaption(i18n("Journal viewer")); 726 topLevelWidget()->setCaption(i18n("Journal viewer"));
727 mText.append(i18n("<h3> %1 </h3> ").arg(jour->dtStartDateStr(KOPrefs::instance()->mShortDateInViewer))); 727 mText.append(i18n("<h3> %1 </h3> ").arg(jour->dtStartDateStr(KOPrefs::instance()->mShortDateInViewer)));
728 formatReadOnly(jour); 728 formatReadOnly(jour);
729 addTag("p","<b>"+i18n( "Last modified: " ) + "</b>"+KGlobal::locale()->formatDateTime(jour->lastModified(),shortDate ) ); 729 addTag("p","<b>"+i18n( "Last modified: " ) + "</b>"+KGlobal::locale()->formatDateTime(jour->lastModified(),shortDate ) );
730 730
731 if (!jour->description().isEmpty()) { 731 if (!jour->description().isEmpty()) {
732 addTag("p",deTag(jour->description())); 732 addTag("p",deTag(jour->description()));
733 } 733 }
734 setText(mText); 734 setText(mText);
735} 735}
736 736
737void KOEventViewer::formatReadOnly(Incidence *event) 737void KOEventViewer::formatReadOnly(Incidence *event)
738{ 738{
739 int id = event->calID(); 739 int id = event->calID();
740 if ( id > 1 ) { 740 if ( id > 1 ) {
741 addTag("p", "<em>("+i18n("Calendar:")+" " + KOPrefs::instance()->getCalendar( id )->mName + ")</em>"); 741 addTag("p", "<em>("+i18n("Calendar:")+" " + KOPrefs::instance()->getCalendar( id )->mName + ")</em>");
742 } 742 }
743 if (event->isReadOnly()) { 743 if (event->isReadOnly()) {
744 addTag("p","<em>(" + i18n("read-only") + ")</em>"); 744 addTag("p","<em>(" + i18n("read-only") + ")</em>");
745 } 745 }
746} 746}
747void KOEventViewer::setSyncMode( bool b ) 747void KOEventViewer::setSyncMode( bool b )
748{ 748{
749 mSyncMode = b; 749 mSyncMode = b;
750} 750}
751 751
752void KOEventViewer::setTodo(Todo *event, bool clearV ) 752void KOEventViewer::setTodo(Todo *event, bool clearV )
753{ 753{
754 if ( clearV ) 754 if ( clearV )
755 clearEvents(); 755 clearEvents();
756 if ( mSyncMode ) { 756 if ( mSyncMode ) {
757 if ( clearV ) 757 if ( clearV )
758 appendTodo(event,1 ); 758 appendTodo(event,1 );
759 else 759 else
760 appendTodo(event,2); 760 appendTodo(event,2);
761 } else 761 } else
762 appendTodo(event); 762 appendTodo(event);
763} 763}
764void KOEventViewer::setJournal(Journal *event, bool clearV ) 764void KOEventViewer::setJournal(Journal *event, bool clearV )
765{ 765{
766 if ( clearV ) 766 if ( clearV )
767 clearEvents(); 767 clearEvents();
768 if ( mSyncMode ) { 768 if ( mSyncMode ) {
769 if ( clearV ) 769 if ( clearV )
770 appendJournal(event, 1); 770 appendJournal(event, 1);
771 else 771 else
772 appendJournal(event, 2); 772 appendJournal(event, 2);
773 } else 773 } else
774 appendJournal(event); 774 appendJournal(event);
775} 775}
776 776
777void KOEventViewer::setEvent(Event *event) 777void KOEventViewer::setEvent(Event *event)
778{ 778{
779 clearEvents(); 779 clearEvents();
780 if ( mSyncMode ) 780 if ( mSyncMode )
781 appendEvent(event, 1); 781 appendEvent(event, 1);
782 else 782 else
783 appendEvent(event); 783 appendEvent(event);
784} 784}
785 785
786void KOEventViewer::addEvent(Event *event) 786void KOEventViewer::addEvent(Event *event)
787{ 787{
788 if ( mSyncMode ) 788 if ( mSyncMode )
789 appendEvent(event, 2); 789 appendEvent(event, 2);
790 else 790 else
791 appendEvent(event); 791 appendEvent(event);
792} 792}
793 793
794void KOEventViewer::clearEvents(bool now) 794void KOEventViewer::clearEvents(bool now)
795{ 795{
796 mText = ""; 796 mText = "";
797 if (now) setText(mText); 797 if (now) setText(mText);
798} 798}
799 799
800void KOEventViewer::addText(QString text) 800void KOEventViewer::addText(QString text)
801{ 801{
802 mText.append(text); 802 mText.append(text);
803 setText(mText); 803 setText(mText);
804} 804}
805QString KOEventViewer::deTag(QString text) 805QString KOEventViewer::deTag(QString text)
806{ 806{
807#if QT_VERSION >= 0x030000 807#if QT_VERSION >= 0x030000
808 text.replace( '<' , "&lt;" ); 808 text.replace( '<' , "&lt;" );
809 text.replace( '>' , "&gt;" ); 809 text.replace( '>' , "&gt;" );
810#else 810#else
811 if ( text.find ('<') >= 0 ) { 811 if ( text.find ('<') >= 0 ) {
812 text.replace( QRegExp("<") , "&lt;" ); 812 text.replace( QRegExp("<") , "&lt;" );
813 } 813 }
814 if ( text.find ('>') >= 0 ) { 814 if ( text.find ('>') >= 0 ) {
815 text.replace( QRegExp(">") , "&gt;" ); 815 text.replace( QRegExp(">") , "&gt;" );
816 } 816 }
817#endif 817#endif
818 return text; 818 return text;
819} 819}
820void KOEventViewer::keyPressEvent ( QKeyEvent * e ) 820void KOEventViewer::keyPressEvent ( QKeyEvent * e )
821{ 821{
822 switch ( e->key() ) { 822 switch ( e->key() ) {
823 case Qt::Key_Return: 823 case Qt::Key_Return:
824 case Qt::Key_Enter : 824 case Qt::Key_Enter :
825 e->ignore(); 825 e->ignore();
826 break; 826 break;
827 default: 827 default:
828 QTextBrowser::keyPressEvent ( e ); 828 QTextBrowser::keyPressEvent ( e );
829 break; 829 break;
830 } 830 }
831} 831}
diff --git a/korganizer/kolistview.cpp b/korganizer/kolistview.cpp
index d25f671..e7a5e0e 100644
--- a/korganizer/kolistview.cpp
+++ b/korganizer/kolistview.cpp
@@ -1,1447 +1,1447 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 1999 Preston Brown 3 Copyright (c) 1999 Preston Brown
4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or 8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software 17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 19
20 As a special exception, permission is given to link this program 20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable, 21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution. 22 without including the source code for Qt in the source distribution.
23*/ 23*/
24 24
25#include <qlistview.h> 25#include <qlistview.h>
26#include <qlayout.h> 26#include <qlayout.h>
27#include <qlabel.h> 27#include <qlabel.h>
28#include <qpopupmenu.h> 28#include <qpopupmenu.h>
29#include <qprogressbar.h> 29#include <qprogressbar.h>
30#include <qfileinfo.h> 30#include <qfileinfo.h>
31#include <qmessagebox.h> 31#include <qmessagebox.h>
32#include <qdialog.h> 32#include <qdialog.h>
33#include <qtextstream.h> 33#include <qtextstream.h>
34#include <qdir.h> 34#include <qdir.h>
35#include <qwhatsthis.h> 35#include <qwhatsthis.h>
36#include <qregexp.h> 36#include <qregexp.h>
37#include <qpainter.h> 37#include <qpainter.h>
38#include <qpaintdevicemetrics.h> 38#include <qpaintdevicemetrics.h>
39 39
40#include <klocale.h> 40#include <klocale.h>
41#include <kdebug.h> 41#include <kdebug.h>
42#include <kiconloader.h> 42#include <kiconloader.h>
43#include <kglobal.h> 43#include <kglobal.h>
44 44
45#include <libkdepim/kpimglobalprefs.h> 45#include <libkdepim/kpimglobalprefs.h>
46#include <libkcal/calendar.h> 46#include <libkcal/calendar.h>
47#include <libkcal/calendarlocal.h> 47#include <libkcal/calendarlocal.h>
48#include <libkcal/icalformat.h> 48#include <libkcal/icalformat.h>
49#include <libkcal/vcalformat.h> 49#include <libkcal/vcalformat.h>
50#include <libkcal/recurrence.h> 50#include <libkcal/recurrence.h>
51#include <libkcal/filestorage.h> 51#include <libkcal/filestorage.h>
52#include <libkdepim/categoryselectdialog.h> 52#include <libkdepim/categoryselectdialog.h>
53#include <libkcal/kincidenceformatter.h> 53#include <libkcal/kincidenceformatter.h>
54#ifndef DESKTOP_VERSION 54#ifndef DESKTOP_VERSION
55#include <qpe/qpeapplication.h> 55#include <qpe/qpeapplication.h>
56#else 56#else
57#include <qapplication.h> 57#include <qapplication.h>
58#endif 58#endif
59 59
60#ifndef KORG_NOPRINTER 60#ifndef KORG_NOPRINTER
61#include "calprinter.h" 61#include "calprinter.h"
62#endif 62#endif
63#include "koglobals.h" 63#include "koglobals.h"
64#include "koprefs.h" 64#include "koprefs.h"
65#include "kfiledialog.h" 65#include "kfiledialog.h"
66 66
67#include "kolistview.h" 67#include "kolistview.h"
68#include "koeventviewer.h" 68#include "koeventviewer.h"
69 69
70extern QPixmap* sgListViewCompletedPix[6]; 70extern QPixmap* sgListViewCompletedPix[6];
71extern QPixmap* sgListViewJournalPix; 71extern QPixmap* sgListViewJournalPix;
72 72
73class KOListViewWhatsThis :public QWhatsThis 73class KOListViewWhatsThis :public QWhatsThis
74{ 74{
75public: 75public:
76 KOListViewWhatsThis( QWidget *wid, KOListView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { }; 76 KOListViewWhatsThis( QWidget *wid, KOListView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { };
77 77
78protected: 78protected:
79 virtual QString text( const QPoint& p) 79 virtual QString text( const QPoint& p)
80 { 80 {
81 return _view->getWhatsThisText(p) ; 81 return _view->getWhatsThisText(p) ;
82 } 82 }
83private: 83private:
84 QWidget* _wid; 84 QWidget* _wid;
85 KOListView * _view; 85 KOListView * _view;
86}; 86};
87 87
88 88
89ListItemVisitor::ListItemVisitor(KOListViewItem *item, QDate date ) 89ListItemVisitor::ListItemVisitor(KOListViewItem *item, QDate date )
90{ 90{
91 mItem = item; 91 mItem = item;
92 mDate = date; 92 mDate = date;
93} 93}
94 94
95ListItemVisitor::~ListItemVisitor() 95ListItemVisitor::~ListItemVisitor()
96{ 96{
97} 97}
98 98
99bool ListItemVisitor::visit(Event *e) 99bool ListItemVisitor::visit(Event *e)
100{ 100{
101 bool ok = false; 101 bool ok = false;
102 QString start, end; 102 QString start, end;
103 QDate ds, de; 103 QDate ds, de;
104 if ( e->doesRecur() ) { 104 if ( e->doesRecur() ) {
105 ds = e->getNextOccurence( QDateTime( mDate, QTime(0,0,0)), &ok ).date(); 105 ds = e->getNextOccurence( QDateTime( mDate, QTime(0,0,0)), &ok ).date();
106 if ( ok ) { 106 if ( ok ) {
107 int days = e->dtStart().date().daysTo(e->dtEnd().date() ); 107 int days = e->dtStart().date().daysTo(e->dtEnd().date() );
108 start = KGlobal::locale()->formatDate(ds,true); 108 start = KGlobal::locale()->formatDate(ds,true);
109 de = ds.addDays( days); 109 de = ds.addDays( days);
110 end = KGlobal::locale()->formatDate(de,true); 110 end = KGlobal::locale()->formatDate(de,true);
111 } 111 }
112 112
113 } 113 }
114 if ( ! ok ) { 114 if ( ! ok ) {
115 start =e->dtStartDateStr(); 115 start =e->dtStartDateStr();
116 end = e->dtEndDateStr(); 116 end = e->dtEndDateStr();
117 ds = e->dtStart().date(); 117 ds = e->dtStart().date();
118 de = e->dtEnd().date(); 118 de = e->dtEnd().date();
119 } 119 }
120 mItem->setText(0,e->summary()); 120 mItem->setText(0,e->summary());
121 mItem->setText(1,start); 121 mItem->setText(1,start);
122 if ( e->doesFloat() ) 122 if ( e->doesFloat() )
123 mItem->setText(2,"---"); 123 mItem->setText(2,"---");
124 else 124 else
125 mItem->setText(2,e->dtStartTimeStr()); 125 mItem->setText(2,e->dtStartTimeStr());
126 mItem->setText(3,end); 126 mItem->setText(3,end);
127 if ( e->doesFloat() ) 127 if ( e->doesFloat() )
128 mItem->setText(4,"---"); 128 mItem->setText(4,"---");
129 else 129 else
130 mItem->setText(4,e->dtEndTimeStr()); 130 mItem->setText(4,e->dtEndTimeStr());
131 if ( e->isAlarmEnabled() ) { 131 if ( e->isAlarmEnabled() ) {
132 mItem->setText(5,e->alarms().first()->offsetText() ); 132 mItem->setText(5,e->alarms().first()->offsetText() );
133 } else { 133 } else {
134 mItem->setText(5, i18n("No")); 134 mItem->setText(5, i18n("No"));
135 } 135 }
136 mItem->setText(6, e->recurrence()->recurrenceText()); 136 mItem->setText(6, e->recurrenceText());
137 if( ! e->doesRecur() ) 137 if( ! e->doesRecur() )
138 mItem->setSortKey( 6, "-" ); 138 mItem->setSortKey( 6, "-" );
139 mItem->setText(7,"---"); 139 mItem->setText(7,"---");
140 mItem->setText(8,"---"); 140 mItem->setText(8,"---");
141 mItem->setText(9, e->cancelled() ? i18n("Yes") : i18n("No")); 141 mItem->setText(9, e->cancelled() ? i18n("Yes") : i18n("No"));
142 mItem->setText(10,e->categoriesStr()); 142 mItem->setText(10,e->categoriesStr());
143 mItem->setText(11, KOPrefs::instance()->calName( e->calID() )); 143 mItem->setText(11, KOPrefs::instance()->calName( e->calID() ));
144 mItem->setText(12, KGlobal::locale()->formatDateTime( e->lastModified(), true, true )); 144 mItem->setText(12, KGlobal::locale()->formatDateTime( e->lastModified(), true, true ));
145 145
146 QString key; 146 QString key;
147 QDate d = e->lastModified().date(); 147 QDate d = e->lastModified().date();
148 QTime t = e->lastModified().time(); 148 QTime t = e->lastModified().time();
149 key.sprintf("%04d%02d%02d%02d%02d%02d",d.year(),d.month(),d.day(),t.hour(),t.minute(),t.second() ); 149 key.sprintf("%04d%02d%02d%02d%02d%02d",d.year(),d.month(),d.day(),t.hour(),t.minute(),t.second() );
150 mItem->setSortKey(12,key); 150 mItem->setSortKey(12,key);
151 t = e->doesFloat() ? QTime(0,0) : e->dtStart().time(); 151 t = e->doesFloat() ? QTime(0,0) : e->dtStart().time();
152 key.sprintf("%04d%02d%02d%02d%02d",ds.year(),ds.month(),ds.day(),t.hour(),t.minute()); 152 key.sprintf("%04d%02d%02d%02d%02d",ds.year(),ds.month(),ds.day(),t.hour(),t.minute());
153 mItem->setSortKey(1,key); 153 mItem->setSortKey(1,key);
154 154
155 t = e->doesFloat() ? QTime(0,0) : e->dtEnd().time(); 155 t = e->doesFloat() ? QTime(0,0) : e->dtEnd().time();
156 key.sprintf("%04d%02d%02d%02d%02d",de.year(),de.month(),de.day(),t.hour(),t.minute()); 156 key.sprintf("%04d%02d%02d%02d%02d",de.year(),de.month(),de.day(),t.hour(),t.minute());
157 mItem->setSortKey(3,key); 157 mItem->setSortKey(3,key);
158 return true; 158 return true;
159} 159}
160 160
161bool ListItemVisitor::visit(Todo *t) 161bool ListItemVisitor::visit(Todo *t)
162{ 162{
163 mItem->setText(0,t->summary()); 163 mItem->setText(0,t->summary());
164 if ( t->isCompleted() ) { 164 if ( t->isCompleted() ) {
165 mItem->setSortKey(0,"99"+ t->summary().left(10)); 165 mItem->setSortKey(0,"99"+ t->summary().left(10));
166 } else 166 } else
167 mItem->setSortKey(0,QString::number( t->percentComplete()+1 )+ t->summary().left(10)); 167 mItem->setSortKey(0,QString::number( t->percentComplete()+1 )+ t->summary().left(10));
168 mItem->setPixmap( 0, *(sgListViewCompletedPix[t->percentComplete()/20])); 168 mItem->setPixmap( 0, *(sgListViewCompletedPix[t->percentComplete()/20]));
169 if (t->hasStartDate()) { 169 if (t->hasStartDate()) {
170 mItem->setText(1,t->dtStartDateStr()); 170 mItem->setText(1,t->dtStartDateStr());
171 if (t->doesFloat()) { 171 if (t->doesFloat()) {
172 mItem->setText(2,"---"); 172 mItem->setText(2,"---");
173 } else { 173 } else {
174 mItem->setText(2,t->dtStartTimeStr()); 174 mItem->setText(2,t->dtStartTimeStr());
175 } 175 }
176 } else { 176 } else {
177 mItem->setText(1,"---"); 177 mItem->setText(1,"---");
178 mItem->setText(2,"---"); 178 mItem->setText(2,"---");
179 } 179 }
180 mItem->setText(3,"---"); 180 mItem->setText(3,"---");
181 mItem->setText(4,"---"); 181 mItem->setText(4,"---");
182 if ( t->isAlarmEnabled() ) { 182 if ( t->isAlarmEnabled() ) {
183 mItem->setText(5,t->alarms().first()->offsetText() ); 183 mItem->setText(5,t->alarms().first()->offsetText() );
184 } else { 184 } else {
185 mItem->setText(5, i18n("No")); 185 mItem->setText(5, i18n("No"));
186 } 186 }
187 mItem->setText(6, t->recurrence()->recurrenceText()); 187 mItem->setText(6, t->recurrenceText());
188 if( ! t->doesRecur() ) 188 if( ! t->doesRecur() )
189 mItem->setSortKey( 6, "-" ); 189 mItem->setSortKey( 6, "-" );
190 if (t->hasDueDate()) { 190 if (t->hasDueDate()) {
191 mItem->setText(7,t->dtDueDateStr()); 191 mItem->setText(7,t->dtDueDateStr());
192 if (t->doesFloat()) { 192 if (t->doesFloat()) {
193 mItem->setText(8,"---"); 193 mItem->setText(8,"---");
194 } else { 194 } else {
195 mItem->setText(8,t->dtDueTimeStr()); 195 mItem->setText(8,t->dtDueTimeStr());
196 } 196 }
197 } else { 197 } else {
198 mItem->setText(7,"---"); 198 mItem->setText(7,"---");
199 mItem->setText(8,"---"); 199 mItem->setText(8,"---");
200 } 200 }
201 mItem->setText(9, t->cancelled() ? i18n("Yes") : i18n("No")); 201 mItem->setText(9, t->cancelled() ? i18n("Yes") : i18n("No"));
202 mItem->setText(10,t->categoriesStr()); 202 mItem->setText(10,t->categoriesStr());
203 mItem->setText(11, KOPrefs::instance()->calName( t->calID() )); 203 mItem->setText(11, KOPrefs::instance()->calName( t->calID() ));
204 mItem->setText(12, KGlobal::locale()->formatDateTime( t->lastModified(), true, true )); 204 mItem->setText(12, KGlobal::locale()->formatDateTime( t->lastModified(), true, true ));
205 QString key; 205 QString key;
206 QDate d = t->lastModified().date(); 206 QDate d = t->lastModified().date();
207 QTime tm = t->lastModified().time(); 207 QTime tm = t->lastModified().time();
208 key.sprintf("%04d%02d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute(),tm.second() ); 208 key.sprintf("%04d%02d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute(),tm.second() );
209 mItem->setSortKey(12,key); 209 mItem->setSortKey(12,key);
210 if (t->hasDueDate()) { 210 if (t->hasDueDate()) {
211 d = t->dtDue().date(); 211 d = t->dtDue().date();
212 tm = t->doesFloat() ? QTime(0,0) : t->dtDue().time(); 212 tm = t->doesFloat() ? QTime(0,0) : t->dtDue().time();
213 key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute()); 213 key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute());
214 mItem->setSortKey(7,key); 214 mItem->setSortKey(7,key);
215 } 215 }
216 if ( t->hasStartDate() ) { 216 if ( t->hasStartDate() ) {
217 d = t->dtStart().date(); 217 d = t->dtStart().date();
218 tm = t->doesFloat() ? QTime(0,0) : t->dtStart().time(); 218 tm = t->doesFloat() ? QTime(0,0) : t->dtStart().time();
219 key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute()); 219 key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute());
220 mItem->setSortKey(1,key); 220 mItem->setSortKey(1,key);
221 } 221 }
222 return true; 222 return true;
223} 223}
224 224
225bool ListItemVisitor::visit(Journal * j) 225bool ListItemVisitor::visit(Journal * j)
226{ 226{
227 227
228 QString des; 228 QString des;
229 mItem->setPixmap( 0, *sgListViewJournalPix); 229 mItem->setPixmap( 0, *sgListViewJournalPix);
230 if ( !j->summary().isEmpty() ) { 230 if ( !j->summary().isEmpty() ) {
231 des = j->summary(); 231 des = j->summary();
232 } else { 232 } else {
233 des = j->description().left(30); 233 des = j->description().left(30);
234 des = des.simplifyWhiteSpace (); 234 des = des.simplifyWhiteSpace ();
235 des.replace (QRegExp ("\\n"),"" ); 235 des.replace (QRegExp ("\\n"),"" );
236 des.replace (QRegExp ("\\r"),"" ); 236 des.replace (QRegExp ("\\r"),"" );
237 } 237 }
238 mItem->setText(0,des.left(25)); 238 mItem->setText(0,des.left(25));
239 mItem->setSortKey(0,"0"+ des.left(25)); 239 mItem->setSortKey(0,"0"+ des.left(25));
240 mItem->setText(1,j->dtStartDateStr()); 240 mItem->setText(1,j->dtStartDateStr());
241 mItem->setText(2,"---"); 241 mItem->setText(2,"---");
242 mItem->setText(3,"---"); 242 mItem->setText(3,"---");
243 mItem->setText(4,"---"); 243 mItem->setText(4,"---");
244 mItem->setText(5,"---"); 244 mItem->setText(5,"---");
245 mItem->setText(6,"---"); 245 mItem->setText(6,"---");
246 mItem->setText(7,j->dtStartDateStr()); 246 mItem->setText(7,j->dtStartDateStr());
247 mItem->setText(8,"---"); 247 mItem->setText(8,"---");
248 mItem->setText(9,"---"); 248 mItem->setText(9,"---");
249 mItem->setText(10,j->categoriesStr()); 249 mItem->setText(10,j->categoriesStr());
250 mItem->setText(11, KOPrefs::instance()->calName( j->calID() )); 250 mItem->setText(11, KOPrefs::instance()->calName( j->calID() ));
251 mItem->setText(12, KGlobal::locale()->formatDateTime( j->lastModified(), true, true )); 251 mItem->setText(12, KGlobal::locale()->formatDateTime( j->lastModified(), true, true ));
252 252
253 QString key; 253 QString key;
254 QDate d = j->lastModified().date(); 254 QDate d = j->lastModified().date();
255 QTime tm = j->lastModified().time(); 255 QTime tm = j->lastModified().time();
256 key.sprintf("%04d%02d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute(),tm.second() ); 256 key.sprintf("%04d%02d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute(),tm.second() );
257 mItem->setSortKey(12,key); 257 mItem->setSortKey(12,key);
258 d = j->dtStart().date(); 258 d = j->dtStart().date();
259 key.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 259 key.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
260 mItem->setSortKey(1,key); 260 mItem->setSortKey(1,key);
261 mItem->setSortKey(7,key); 261 mItem->setSortKey(7,key);
262 262
263 return true; 263 return true;
264} 264}
265 265
266KOListView::KOListView(Calendar *calendar, QWidget *parent, 266KOListView::KOListView(Calendar *calendar, QWidget *parent,
267 const char *name) 267 const char *name)
268 : KOEventView(calendar, parent, name) 268 : KOEventView(calendar, parent, name)
269{ 269{
270 270
271 mActiveItem = 0; 271 mActiveItem = 0;
272 mForceShowCompletedTodos = false; 272 mForceShowCompletedTodos = false;
273 mListView = new KOListViewListView(this); 273 mListView = new KOListViewListView(this);
274 mListView->addColumn(i18n("Summary")); 274 mListView->addColumn(i18n("Summary"));
275 mListView->addColumn(i18n("Start Date")); 275 mListView->addColumn(i18n("Start Date"));
276 mListView->addColumn(i18n("Start Time")); 276 mListView->addColumn(i18n("Start Time"));
277 mListView->addColumn(i18n("End Date")); 277 mListView->addColumn(i18n("End Date"));
278 mListView->addColumn(i18n("End Time")); 278 mListView->addColumn(i18n("End Time"));
279 mListView->addColumn(i18n("Alarm")); // alarm set? 279 mListView->addColumn(i18n("Alarm")); // alarm set?
280 mListView->addColumn(i18n("Recurs")); // recurs? 280 mListView->addColumn(i18n("Recurs")); // recurs?
281 mListView->addColumn(i18n("Due Date")); 281 mListView->addColumn(i18n("Due Date"));
282 mListView->addColumn(i18n("Due Time")); 282 mListView->addColumn(i18n("Due Time"));
283 mListView->addColumn(i18n("Cancelled")); 283 mListView->addColumn(i18n("Cancelled"));
284 mListView->addColumn(i18n("Categories")); 284 mListView->addColumn(i18n("Categories"));
285 mListView->addColumn(i18n("Calendar")); 285 mListView->addColumn(i18n("Calendar"));
286 mListView->addColumn(i18n("Last Modified")); 286 mListView->addColumn(i18n("Last Modified"));
287 287
288 mListView->setColumnAlignment(0,AlignLeft); 288 mListView->setColumnAlignment(0,AlignLeft);
289 mListView->setColumnAlignment(1,AlignLeft); 289 mListView->setColumnAlignment(1,AlignLeft);
290 mListView->setColumnAlignment(2,AlignHCenter); 290 mListView->setColumnAlignment(2,AlignHCenter);
291 mListView->setColumnAlignment(3,AlignLeft); 291 mListView->setColumnAlignment(3,AlignLeft);
292 mListView->setColumnAlignment(4,AlignHCenter); 292 mListView->setColumnAlignment(4,AlignHCenter);
293 mListView->setColumnAlignment(5,AlignLeft); 293 mListView->setColumnAlignment(5,AlignLeft);
294 mListView->setColumnAlignment(6,AlignLeft); 294 mListView->setColumnAlignment(6,AlignLeft);
295 mListView->setColumnAlignment(7,AlignLeft); 295 mListView->setColumnAlignment(7,AlignLeft);
296 mListView->setColumnAlignment(8,AlignLeft); 296 mListView->setColumnAlignment(8,AlignLeft);
297 mListView->setColumnAlignment(9,AlignLeft); 297 mListView->setColumnAlignment(9,AlignLeft);
298 mListView->setColumnAlignment(10,AlignLeft); 298 mListView->setColumnAlignment(10,AlignLeft);
299 mListView->setColumnAlignment(11,AlignLeft); 299 mListView->setColumnAlignment(11,AlignLeft);
300 mListView->setColumnAlignment(12,AlignLeft); 300 mListView->setColumnAlignment(12,AlignLeft);
301 mKOListViewWhatsThis = new KOListViewWhatsThis(mListView->viewport(),this); 301 mKOListViewWhatsThis = new KOListViewWhatsThis(mListView->viewport(),this);
302 302
303 int iii = 0; 303 int iii = 0;
304 for ( iii = 0; iii< 13 ; ++iii ) 304 for ( iii = 0; iii< 13 ; ++iii )
305 mListView->setColumnWidthMode( iii, QListView::Manual ); 305 mListView->setColumnWidthMode( iii, QListView::Manual );
306 306
307 QBoxLayout *layoutTop = new QVBoxLayout(this); 307 QBoxLayout *layoutTop = new QVBoxLayout(this);
308 layoutTop->addWidget(mListView); 308 layoutTop->addWidget(mListView);
309 mListView->setFont ( KOPrefs::instance()->mListViewFont ); 309 mListView->setFont ( KOPrefs::instance()->mListViewFont );
310 mPopupMenu = eventPopup(); 310 mPopupMenu = eventPopup();
311 QPopupMenu* selPopup = new QPopupMenu ( this ); 311 QPopupMenu* selPopup = new QPopupMenu ( this );
312 mPopupMenu->insertSeparator(); 312 mPopupMenu->insertSeparator();
313 313
314 selPopup->insertItem(i18n("All"),this, 314 selPopup->insertItem(i18n("All"),this,
315 SLOT(allSelection())); 315 SLOT(allSelection()));
316 selPopup->insertItem(i18n("None"),this, 316 selPopup->insertItem(i18n("None"),this,
317 SLOT(clearSelection())); 317 SLOT(clearSelection()));
318 selPopup->insertItem(i18n("Delete selected..."),this, 318 selPopup->insertItem(i18n("Delete selected..."),this,
319 SLOT(deleteAll())); 319 SLOT(deleteAll()));
320 mPopupMenu->insertItem(i18n("Selection"), selPopup ); 320 mPopupMenu->insertItem(i18n("Selection"), selPopup );
321 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), 321 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
322 i18n("Hide all selected"),this, 322 i18n("Hide all selected"),this,
323 SLOT(hideAll()),true); 323 SLOT(hideAll()),true);
324 324
325 selPopup->insertSeparator(); 325 selPopup->insertSeparator();
326 QPopupMenu * exportPO = new QPopupMenu ( this ); 326 QPopupMenu * exportPO = new QPopupMenu ( this );
327 selPopup->insertItem( i18n("Export"), exportPO ); 327 selPopup->insertItem( i18n("Export"), exportPO );
328#ifdef DESKTOP_VERSION 328#ifdef DESKTOP_VERSION
329 mPopupMenu->insertSeparator(); 329 mPopupMenu->insertSeparator();
330 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), 330 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
331 i18n("Print complete list..."),this, 331 i18n("Print complete list..."),this,
332 SLOT(printList()),true); 332 SLOT(printList()),true);
333#endif 333#endif
334 mCalPopup = new QPopupMenu ( this ); 334 mCalPopup = new QPopupMenu ( this );
335 selPopup->insertItem( i18n("Set Calendar"), mCalPopup ); 335 selPopup->insertItem( i18n("Set Calendar"), mCalPopup );
336 336
337 selPopup->insertItem(i18n("Set categories")+"...",this, 337 selPopup->insertItem(i18n("Set categories")+"...",this,
338 SLOT(setCat()) ); 338 SLOT(setCat()) );
339 selPopup->insertItem( i18n("Set alarm..."),this, 339 selPopup->insertItem( i18n("Set alarm..."),this,
340 SLOT(setAlarm())); 340 SLOT(setAlarm()));
341#if 0 341#if 0
342 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), 342 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
343 i18n("Set categories")+"...",this, 343 i18n("Set categories")+"...",this,
344 SLOT(setCat()),true); 344 SLOT(setCat()),true);
345 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), 345 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
346 i18n("Set alarm..."),this, 346 i18n("Set alarm..."),this,
347 SLOT(setAlarm()),true); 347 SLOT(setAlarm()),true);
348#endif 348#endif
349 QObject::connect(mCalPopup,SIGNAL(aboutToShow()),this, 349 QObject::connect(mCalPopup,SIGNAL(aboutToShow()),this,
350 SLOT( populateCalPopup() )); 350 SLOT( populateCalPopup() ));
351 QObject::connect(mCalPopup,SIGNAL(activated( int )),this, 351 QObject::connect(mCalPopup,SIGNAL(activated( int )),this,
352 SLOT( setCalendar( int ) )); 352 SLOT( setCalendar( int ) ));
353 QObject::connect(mPopupMenu,SIGNAL(categoryChanged( Incidence * )),this, 353 QObject::connect(mPopupMenu,SIGNAL(categoryChanged( Incidence * )),this,
354 SLOT( catChanged( Incidence * ) )); 354 SLOT( catChanged( Incidence * ) ));
355 exportPO->insertItem( i18n("As iCal (ics) file..."),this, 355 exportPO->insertItem( i18n("As iCal (ics) file..."),this,
356 SLOT(saveToFile())); 356 SLOT(saveToFile()));
357 exportPO->insertItem( i18n("As vCal (vcs) file..."),this, 357 exportPO->insertItem( i18n("As vCal (vcs) file..."),this,
358 SLOT(saveToFileVCS())); 358 SLOT(saveToFileVCS()));
359 exportPO->insertItem( i18n("Journal/Details..."),this, 359 exportPO->insertItem( i18n("Journal/Details..."),this,
360 SLOT(saveDescriptionToFile())); 360 SLOT(saveDescriptionToFile()));
361 // mPopupMenu->insertSeparator(); 361 // mPopupMenu->insertSeparator();
362 // mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), 362 // mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
363 // i18n("Add Categ. to selected..."),this, 363 // i18n("Add Categ. to selected..."),this,
364 // SLOT(addCat()),true); 364 // SLOT(addCat()),true);
365 //mPopupMenu->insertSeparator(); 365 //mPopupMenu->insertSeparator();
366#ifndef DESKTOP_VERSION 366#ifndef DESKTOP_VERSION
367 selPopup->insertSeparator(); 367 selPopup->insertSeparator();
368 selPopup->insertItem( i18n("Beam via IR..."),this, 368 selPopup->insertItem( i18n("Beam via IR..."),this,
369 SLOT(beamSelected())); 369 SLOT(beamSelected()));
370#if 0 370#if 0
371 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), 371 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
372 i18n("Beam via IR"),this, 372 i18n("Beam via IR"),this,
373 SLOT(beamSelected()),true); 373 SLOT(beamSelected()),true);
374#endif 374#endif
375#endif 375#endif
376 /* 376 /*
377 mPopupMenu = new QPopupMenu; 377 mPopupMenu = new QPopupMenu;
378 mPopupMenu->insertItem(i18n("Edit Event"), this, 378 mPopupMenu->insertItem(i18n("Edit Event"), this,
379 SLOT (editEvent())); 379 SLOT (editEvent()));
380 mPopupMenu->insertItem(SmallIcon("delete"), i18n("Delete Event"), this, 380 mPopupMenu->insertItem(SmallIcon("delete"), i18n("Delete Event"), this,
381 SLOT (deleteEvent())); 381 SLOT (deleteEvent()));
382 mPopupMenu->insertSeparator(); 382 mPopupMenu->insertSeparator();
383 mPopupMenu->insertItem(i18n("Show Dates"), this, 383 mPopupMenu->insertItem(i18n("Show Dates"), this,
384 SLOT(showDates())); 384 SLOT(showDates()));
385 mPopupMenu->insertItem(i18n("Hide Dates"), this, 385 mPopupMenu->insertItem(i18n("Hide Dates"), this,
386 SLOT(hideDates())); 386 SLOT(hideDates()));
387 */ 387 */
388 QObject::connect(mListView,SIGNAL( newEvent()), 388 QObject::connect(mListView,SIGNAL( newEvent()),
389 this,SIGNAL(signalNewEvent())); 389 this,SIGNAL(signalNewEvent()));
390 QObject::connect(mListView,SIGNAL(doubleClicked(QListViewItem *)), 390 QObject::connect(mListView,SIGNAL(doubleClicked(QListViewItem *)),
391 this,SLOT(defaultItemAction(QListViewItem *))); 391 this,SLOT(defaultItemAction(QListViewItem *)));
392 QObject::connect(mListView,SIGNAL(rightButtonPressed( QListViewItem *, 392 QObject::connect(mListView,SIGNAL(rightButtonPressed( QListViewItem *,
393 const QPoint &, int )), 393 const QPoint &, int )),
394 this,SLOT(popupMenu(QListViewItem *,const QPoint &,int))); 394 this,SLOT(popupMenu(QListViewItem *,const QPoint &,int)));
395 QObject::connect(mListView,SIGNAL(currentChanged(QListViewItem *)), 395 QObject::connect(mListView,SIGNAL(currentChanged(QListViewItem *)),
396 SLOT(processSelectionChange(QListViewItem *))); 396 SLOT(processSelectionChange(QListViewItem *)));
397 QObject::connect(mListView,SIGNAL(showIncidence(Incidence *)), 397 QObject::connect(mListView,SIGNAL(showIncidence(Incidence *)),
398 SIGNAL(showIncidenceSignal(Incidence *)) ); 398 SIGNAL(showIncidenceSignal(Incidence *)) );
399 399
400 readSettings(KOGlobals::config(),"KOListView Layout"); 400 readSettings(KOGlobals::config(),"KOListView Layout");
401} 401}
402 402
403KOListView::~KOListView() 403KOListView::~KOListView()
404{ 404{
405 delete mPopupMenu; 405 delete mPopupMenu;
406#if QT_VERSION >= 0x030000 406#if QT_VERSION >= 0x030000
407 407
408#else 408#else
409 delete mKOListViewWhatsThis; 409 delete mKOListViewWhatsThis;
410#endif 410#endif
411} 411}
412 412
413void KOListView::catChanged( Incidence* inc) 413void KOListView::catChanged( Incidence* inc)
414{ 414{
415 KOListViewItem* item = getItemForEvent(inc); 415 KOListViewItem* item = getItemForEvent(inc);
416 if (item) { 416 if (item) {
417 ListItemVisitor v(item, mStartDate ); 417 ListItemVisitor v(item, mStartDate );
418 inc->accept(v); 418 inc->accept(v);
419 } 419 }
420} 420}
421QString KOListView::getWhatsThisText(QPoint p) 421QString KOListView::getWhatsThisText(QPoint p)
422{ 422{
423 KOListViewItem* item = ( KOListViewItem* ) mListView->itemAt( p ); 423 KOListViewItem* item = ( KOListViewItem* ) mListView->itemAt( p );
424 if ( item ) 424 if ( item )
425 return KIncidenceFormatter::instance()->getFormattedText( item->data(), 425 return KIncidenceFormatter::instance()->getFormattedText( item->data(),
426 KOPrefs::instance()->mWTshowDetails, 426 KOPrefs::instance()->mWTshowDetails,
427 KOPrefs::instance()->mWTshowCreated, 427 KOPrefs::instance()->mWTshowCreated,
428 KOPrefs::instance()->mWTshowChanged); 428 KOPrefs::instance()->mWTshowChanged);
429 return i18n("That is the list view" ); 429 return i18n("That is the list view" );
430 430
431} 431}
432 432
433void KOListView::setCalendar( int c ) 433void KOListView::setCalendar( int c )
434{ 434{
435 int result = QMessageBox::warning( this, i18n("KO/Pi: Information!"), 435 int result = QMessageBox::warning( this, i18n("KO/Pi: Information!"),
436 i18n("This adds the selected\nitems to the calendar\n%1\nand removes them from\ntheir current calendar!").arg( KOPrefs::instance()->calName( c ) ), 436 i18n("This adds the selected\nitems to the calendar\n%1\nand removes them from\ntheir current calendar!").arg( KOPrefs::instance()->calName( c ) ),
437 i18n("Continue"), i18n("Cancel"), 0, 437 i18n("Continue"), i18n("Cancel"), 0,
438 0, 1 ); 438 0, 1 );
439 if ( result != 0 ) { 439 if ( result != 0 ) {
440 return; 440 return;
441 } 441 }
442 442
443 QPtrList<Incidence> delSel = getSelectedIncidences() ; 443 QPtrList<Incidence> delSel = getSelectedIncidences() ;
444 int icount = delSel.count(); 444 int icount = delSel.count();
445 if ( icount ) { 445 if ( icount ) {
446 Incidence *incidence = delSel.first(); 446 Incidence *incidence = delSel.first();
447 while ( incidence ) { 447 while ( incidence ) {
448 incidence->setCalID( c ); 448 incidence->setCalID( c );
449 KOListViewItem * item = getItemForEvent( incidence ); 449 KOListViewItem * item = getItemForEvent( incidence );
450 if ( item ) { 450 if ( item ) {
451 ListItemVisitor v(item, mStartDate ); 451 ListItemVisitor v(item, mStartDate );
452 incidence->accept(v); 452 incidence->accept(v);
453 } 453 }
454 incidence = delSel.next(); 454 incidence = delSel.next();
455 } 455 }
456 } 456 }
457 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 457 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
458 KopiCalendarFile * cal = calendars.first(); 458 KopiCalendarFile * cal = calendars.first();
459 while ( cal ) { 459 while ( cal ) {
460 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); 460 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled );
461 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); 461 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled );
462 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); 462 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly );
463 if ( cal->isStandard ) 463 if ( cal->isStandard )
464 mCalendar->setDefaultCalendar( cal->mCalNumber ); 464 mCalendar->setDefaultCalendar( cal->mCalNumber );
465 cal = calendars.next(); 465 cal = calendars.next();
466 } 466 }
467 mCalendar->setSyncEventsReadOnly(); 467 mCalendar->setSyncEventsReadOnly();
468 mCalendar->reInitAlarmSettings(); 468 mCalendar->reInitAlarmSettings();
469 469
470} 470}
471void KOListView::populateCalPopup() 471void KOListView::populateCalPopup()
472{ 472{
473 mCalPopup->clear(); 473 mCalPopup->clear();
474 KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first(); 474 KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first();
475 while ( kkf ) { 475 while ( kkf ) {
476 int index = mCalPopup->insertItem( kkf->mName+"...", kkf->mCalNumber); 476 int index = mCalPopup->insertItem( kkf->mName+"...", kkf->mCalNumber);
477 if ( kkf->mErrorOnLoad || kkf->isReadOnly ) 477 if ( kkf->mErrorOnLoad || kkf->isReadOnly )
478 mCalPopup->setItemEnabled( index, false ); 478 mCalPopup->setItemEnabled( index, false );
479 kkf = KOPrefs::instance()->mCalendars.next(); 479 kkf = KOPrefs::instance()->mCalendars.next();
480 } 480 }
481} 481}
482void KOListView::updateList() 482void KOListView::updateList()
483{ 483{
484 // qDebug(" KOListView::updateList() "); 484 // qDebug(" KOListView::updateList() ");
485 485
486} 486}
487 487
488void KOListView::clearList() 488void KOListView::clearList()
489{ 489{
490 clear (); 490 clear ();
491} 491}
492 492
493void KOListView::setCat() 493void KOListView::setCat()
494{ 494{
495 495
496 bool set = true; 496 bool set = true;
497 int result = KMessageBox::warningYesNoCancel(this, 497 int result = KMessageBox::warningYesNoCancel(this,
498 i18n("Do you want to <b>add</b> categories to the selected items or <b>reset</b> the list (i.e. remove current categories)?"), 498 i18n("Do you want to <b>add</b> categories to the selected items or <b>reset</b> the list (i.e. remove current categories)?"),
499 i18n("Set categories"), 499 i18n("Set categories"),
500 i18n("Add"), 500 i18n("Add"),
501 i18n("Reset")); 501 i18n("Reset"));
502 if (result == KMessageBox::Cancel) return; 502 if (result == KMessageBox::Cancel) return;
503 if (result == KMessageBox::Yes) set = false; 503 if (result == KMessageBox::Yes) set = false;
504 setCategories( set ); 504 setCategories( set );
505} 505}
506 506
507void KOListView::setAlarm() 507void KOListView::setAlarm()
508{ 508{
509 KOAlarmPrefs kap( this); 509 KOAlarmPrefs kap( this);
510 if ( !kap.exec() ) 510 if ( !kap.exec() )
511 return; 511 return;
512 QPtrList<Incidence> delSel = getSelectedIncidences( true, true, false, true ); // no journals, only due todos 512 QPtrList<Incidence> delSel = getSelectedIncidences( true, true, false, true ); // no journals, only due todos
513 Incidence* inc = delSel.first(); 513 Incidence* inc = delSel.first();
514 int count = 0; 514 int count = 0;
515 while ( inc ) { 515 while ( inc ) {
516 ++count; 516 ++count;
517 if (kap.mAlarmButton->isChecked()) { 517 if (kap.mAlarmButton->isChecked()) {
518 if (inc->alarms().count() == 0) 518 if (inc->alarms().count() == 0)
519 inc->newAlarm(); 519 inc->newAlarm();
520 Alarm *alarm = inc->alarms().first(); 520 Alarm *alarm = inc->alarms().first();
521 alarm->setEnabled(true); 521 alarm->setEnabled(true);
522 int j = kap.mAlarmTimeEdit->value()* -60; 522 int j = kap.mAlarmTimeEdit->value()* -60;
523 if (kap.mAlarmIncrCombo->currentItem() == 1) 523 if (kap.mAlarmIncrCombo->currentItem() == 1)
524 j = j * 60; 524 j = j * 60;
525 else if (kap.mAlarmIncrCombo->currentItem() == 2) 525 else if (kap.mAlarmIncrCombo->currentItem() == 2)
526 j = j * (60 * 24); 526 j = j * (60 * 24);
527 alarm->setStartOffset( j ); 527 alarm->setStartOffset( j );
528 528
529 if (!kap.mAlarmProgram.isEmpty() && kap.mAlarmProgramButton->isOn()) { 529 if (!kap.mAlarmProgram.isEmpty() && kap.mAlarmProgramButton->isOn()) {
530 alarm->setProcedureAlarm(kap.mAlarmProgram); 530 alarm->setProcedureAlarm(kap.mAlarmProgram);
531 } 531 }
532 else if (!kap.mAlarmSound.isEmpty() && kap.mAlarmSoundButton->isOn()) 532 else if (!kap.mAlarmSound.isEmpty() && kap.mAlarmSoundButton->isOn())
533 alarm->setAudioAlarm(kap.mAlarmSound); 533 alarm->setAudioAlarm(kap.mAlarmSound);
534 else 534 else
535 alarm->setType(Alarm::Invalid); 535 alarm->setType(Alarm::Invalid);
536 } else { 536 } else {
537 QPtrList<Alarm> alarms = inc->alarms(); 537 QPtrList<Alarm> alarms = inc->alarms();
538 Alarm *alarm; 538 Alarm *alarm;
539 for (alarm = alarms.first(); alarm; alarm = alarms.next() ) { 539 for (alarm = alarms.first(); alarm; alarm = alarms.next() ) {
540 alarm->setEnabled(false); 540 alarm->setEnabled(false);
541 alarm->setType(Alarm::Invalid); 541 alarm->setType(Alarm::Invalid);
542 } 542 }
543 } 543 }
544 KOListViewItem* item = getItemForEvent(inc); 544 KOListViewItem* item = getItemForEvent(inc);
545 if (item) { 545 if (item) {
546 ListItemVisitor v(item, mStartDate ); 546 ListItemVisitor v(item, mStartDate );
547 inc->accept(v); 547 inc->accept(v);
548 } 548 }
549 inc = delSel.next(); 549 inc = delSel.next();
550 } 550 }
551 topLevelWidget()->setCaption( i18n("Changed alarm for %1 items").arg( count ) ); 551 topLevelWidget()->setCaption( i18n("Changed alarm for %1 items").arg( count ) );
552 qDebug("KO: Set alarm for %d items", count); 552 qDebug("KO: Set alarm for %d items", count);
553 calendar()->reInitAlarmSettings(); 553 calendar()->reInitAlarmSettings();
554 QTimer::singleShot( 1, this, SLOT ( resetFocus() ) ); 554 QTimer::singleShot( 1, this, SLOT ( resetFocus() ) );
555} 555}
556void KOListView::setCategories( bool removeOld ) 556void KOListView::setCategories( bool removeOld )
557{ 557{
558 558
559 KPIM::CategorySelectDialog* csd = new KPIM::CategorySelectDialog( KOPrefs::instance(), 0 ); 559 KPIM::CategorySelectDialog* csd = new KPIM::CategorySelectDialog( KOPrefs::instance(), 0 );
560 csd->setColorEnabled(); 560 csd->setColorEnabled();
561 if (! csd->exec()) { 561 if (! csd->exec()) {
562 delete csd; 562 delete csd;
563 return; 563 return;
564 } 564 }
565 QStringList catList = csd->selectedCategories(); 565 QStringList catList = csd->selectedCategories();
566 delete csd; 566 delete csd;
567 QPtrList<Incidence> delSel = getSelectedIncidences(); // all inc allowed; 567 QPtrList<Incidence> delSel = getSelectedIncidences(); // all inc allowed;
568 Incidence* inc = delSel.first(); 568 Incidence* inc = delSel.first();
569 while ( inc ) { 569 while ( inc ) {
570 if ( removeOld ) { 570 if ( removeOld ) {
571 inc->setCategories( catList, false ); 571 inc->setCategories( catList, false );
572 } else { 572 } else {
573 inc->addCategories( catList, false ); 573 inc->addCategories( catList, false );
574 } 574 }
575 KOListViewItem* item = getItemForEvent(inc); 575 KOListViewItem* item = getItemForEvent(inc);
576 if (item) { 576 if (item) {
577 ListItemVisitor v(item, mStartDate ); 577 ListItemVisitor v(item, mStartDate );
578 inc->accept(v); 578 inc->accept(v);
579 } 579 }
580 inc = delSel.next(); 580 inc = delSel.next();
581 } 581 }
582 QTimer::singleShot( 1, this, SLOT ( resetFocus() ) ); 582 QTimer::singleShot( 1, this, SLOT ( resetFocus() ) );
583} 583}
584 584
585void KOListView::beamSelected() 585void KOListView::beamSelected()
586{ 586{
587 QPtrList<Incidence> delSel = getSelectedIncidences() ; 587 QPtrList<Incidence> delSel = getSelectedIncidences() ;
588 if ( delSel.count() ) 588 if ( delSel.count() )
589 emit beamIncidenceList( delSel ); 589 emit beamIncidenceList( delSel );
590} 590}
591 591
592void KOListView::saveDescriptionToFile() 592void KOListView::saveDescriptionToFile()
593{ 593{
594 594
595 int result = QMessageBox::warning( this, i18n("KO/Pi: Information!"), 595 int result = QMessageBox::warning( this, i18n("KO/Pi: Information!"),
596 i18n("This saves the text/details of selected\nJournals and Events/Todos\nto a text file."), 596 i18n("This saves the text/details of selected\nJournals and Events/Todos\nto a text file."),
597 i18n("Continue"), i18n("Cancel"), 0, 597 i18n("Continue"), i18n("Cancel"), 0,
598 0, 1 ); 598 0, 1 );
599 if ( result != 0 ) { 599 if ( result != 0 ) {
600 return; 600 return;
601 } 601 }
602 QPtrList<Incidence> delSel = getSelectedIncidences() ; 602 QPtrList<Incidence> delSel = getSelectedIncidences() ;
603 int icount = delSel.count(); 603 int icount = delSel.count();
604 if ( icount ) { 604 if ( icount ) {
605 QString fn = KOPrefs::instance()->mLastSaveFile; 605 QString fn = KOPrefs::instance()->mLastSaveFile;
606 fn = KFileDialog::getSaveFileName( fn, i18n("Save filename"), this ); 606 fn = KFileDialog::getSaveFileName( fn, i18n("Save filename"), this );
607 607
608 if ( fn == "" ) 608 if ( fn == "" )
609 return; 609 return;
610 QFileInfo info; 610 QFileInfo info;
611 info.setFile( fn ); 611 info.setFile( fn );
612 QString mes; 612 QString mes;
613 bool createbup = true; 613 bool createbup = true;
614 if ( info. exists() ) { 614 if ( info. exists() ) {
615 mes = i18n("File already exists!\nOld file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); 615 mes = i18n("File already exists!\nOld file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) );
616 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, 616 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes,
617 i18n("Overwrite!"), i18n("Cancel"), 0, 617 i18n("Overwrite!"), i18n("Cancel"), 0,
618 0, 1 ); 618 0, 1 );
619 if ( result != 0 ) { 619 if ( result != 0 ) {
620 createbup = false; 620 createbup = false;
621 } 621 }
622 } 622 }
623 if ( createbup ) { 623 if ( createbup ) {
624 QString text = i18n("KO/Pi Description/Journal save file.\nSave date: ") + 624 QString text = i18n("KO/Pi Description/Journal save file.\nSave date: ") +
625 KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), false); 625 KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), false);
626 Incidence *incidence = delSel.first(); 626 Incidence *incidence = delSel.first();
627 icount = 0; 627 icount = 0;
628 while ( incidence ) { 628 while ( incidence ) {
629 if ( incidence->typeID() == journalID ) { 629 if ( incidence->typeID() == journalID ) {
630 text += "\n************************************\n"; 630 text += "\n************************************\n";
631 if ( !incidence->summary().isEmpty() ) 631 if ( !incidence->summary().isEmpty() )
632 text += i18n("Journal: %1 from ").arg( incidence->summary() ) +incidence->dtStartDateStr( false ); 632 text += i18n("Journal: %1 from ").arg( incidence->summary() ) +incidence->dtStartDateStr( false );
633 else 633 else
634 text += i18n("Journal from: ") +incidence->dtStartDateStr( false ); 634 text += i18n("Journal from: ") +incidence->dtStartDateStr( false );
635 if ( !incidence->location().isEmpty() ) 635 if ( !incidence->location().isEmpty() )
636 text +="\n(" + i18n("Location: ") + incidence->location()+ ")"; 636 text +="\n(" + i18n("Location: ") + incidence->location()+ ")";
637 text +="\n" + i18n("Last modified: ") +KGlobal::locale()->formatDateTime(incidence->lastModified(), false); 637 text +="\n" + i18n("Last modified: ") +KGlobal::locale()->formatDateTime(incidence->lastModified(), false);
638 text +="\n" + i18n("Description: ") + "\n"+ incidence->description(); 638 text +="\n" + i18n("Description: ") + "\n"+ incidence->description();
639 ++icount; 639 ++icount;
640 640
641 } else { 641 } else {
642 if ( !incidence->description().isEmpty() ) { 642 if ( !incidence->description().isEmpty() ) {
643 text += "\n************************************\n"; 643 text += "\n************************************\n";
644 if ( incidence->typeID() == todoID ) 644 if ( incidence->typeID() == todoID )
645 text += i18n("To-Do: "); 645 text += i18n("To-Do: ");
646 text += incidence->summary(); 646 text += incidence->summary();
647 if ( !incidence->location().isEmpty() ) 647 if ( !incidence->location().isEmpty() )
648 text +="\n(" + i18n("Location: ") + incidence->location()+ ")"; 648 text +="\n(" + i18n("Location: ") + incidence->location()+ ")";
649 if ( incidence->hasStartDate() ) 649 if ( incidence->hasStartDate() )
650 text +="\n"+ i18n("Start Date: ") + incidence->dtStartStr( false ); 650 text +="\n"+ i18n("Start Date: ") + incidence->dtStartStr( false );
651 text +="\n"+ i18n("Last modified: ") +KGlobal::locale()->formatDateTime(incidence->lastModified(), false); 651 text +="\n"+ i18n("Last modified: ") +KGlobal::locale()->formatDateTime(incidence->lastModified(), false);
652 text += "\n" + i18n("Description: ") + "\n" + incidence->description(); 652 text += "\n" + i18n("Description: ") + "\n" + incidence->description();
653 ++icount; 653 ++icount;
654 654
655 } 655 }
656 } 656 }
657 incidence = delSel.next(); 657 incidence = delSel.next();
658 } 658 }
659 QFile file( fn ); 659 QFile file( fn );
660 if (!file.open( IO_WriteOnly ) ) { 660 if (!file.open( IO_WriteOnly ) ) {
661 topLevelWidget()->setCaption(i18n("File open error - nothing saved!") ); 661 topLevelWidget()->setCaption(i18n("File open error - nothing saved!") );
662 return; 662 return;
663 } 663 }
664 QTextStream ts( &file ); 664 QTextStream ts( &file );
665 ts << text; 665 ts << text;
666 file.close(); 666 file.close();
667 //qDebug("%s ", text.latin1()); 667 //qDebug("%s ", text.latin1());
668 mes = i18n("KO/Pi:Saved %1 descriptions/journals").arg(icount ); 668 mes = i18n("KO/Pi:Saved %1 descriptions/journals").arg(icount );
669 KOPrefs::instance()->mLastSaveFile = fn; 669 KOPrefs::instance()->mLastSaveFile = fn;
670 topLevelWidget()->setCaption(mes); 670 topLevelWidget()->setCaption(mes);
671 } 671 }
672 } 672 }
673} 673}
674void KOListView::saveToFileVCS() 674void KOListView::saveToFileVCS()
675{ 675{
676 writeToFile( false ); 676 writeToFile( false );
677} 677}
678void KOListView::saveToFile() 678void KOListView::saveToFile()
679{ 679{
680 writeToFile( true ); 680 writeToFile( true );
681} 681}
682QPtrList<Incidence> KOListView::getSelectedIncidences( bool includeEvents, bool includeTodos, bool includeJournals, bool onlyDueTodos ) 682QPtrList<Incidence> KOListView::getSelectedIncidences( bool includeEvents, bool includeTodos, bool includeJournals, bool onlyDueTodos )
683{ 683{
684 QPtrList<Incidence> delSel ; 684 QPtrList<Incidence> delSel ;
685 bool addSubTodos = false; 685 bool addSubTodos = false;
686 bool askSubTodos = true; 686 bool askSubTodos = true;
687 QListViewItem *item = mListView->firstChild (); 687 QListViewItem *item = mListView->firstChild ();
688 while ( item ) { 688 while ( item ) {
689 if ( item->isSelected() ) { 689 if ( item->isSelected() ) {
690 Incidence* inc = ((KOListViewItem *)item)->data(); 690 Incidence* inc = ((KOListViewItem *)item)->data();
691 if ( ( addSubTodos && delSel.findRef( inc ) == -1) || !addSubTodos ) { 691 if ( ( addSubTodos && delSel.findRef( inc ) == -1) || !addSubTodos ) {
692 if ( (inc->typeID() == todoID && includeTodos) || 692 if ( (inc->typeID() == todoID && includeTodos) ||
693 (inc->typeID() == eventID && includeEvents) || 693 (inc->typeID() == eventID && includeEvents) ||
694 (inc->typeID() == journalID && includeJournals) ) { 694 (inc->typeID() == journalID && includeJournals) ) {
695 if ( inc->typeID() == todoID && onlyDueTodos ) { 695 if ( inc->typeID() == todoID && onlyDueTodos ) {
696 if ( ((Todo*)inc)->hasDueDate() ) 696 if ( ((Todo*)inc)->hasDueDate() )
697 delSel.append( inc ); 697 delSel.append( inc );
698 } else 698 } else
699 delSel.append( inc ); 699 delSel.append( inc );
700 700
701 } 701 }
702 } 702 }
703 if ( inc->typeID() == todoID ) { 703 if ( inc->typeID() == todoID ) {
704 Todo * todo = (Todo*) inc; 704 Todo * todo = (Todo*) inc;
705 if ( todo->relations().count() ) { 705 if ( todo->relations().count() ) {
706 if ( askSubTodos ) { 706 if ( askSubTodos ) {
707 int result = KMessageBox::warningYesNoCancel(this, 707 int result = KMessageBox::warningYesNoCancel(this,
708 i18n("One (or more) selected\ntodo has subtodos!\nDo you want to select\nall subtodos of all\nselected todos as well?"), 708 i18n("One (or more) selected\ntodo has subtodos!\nDo you want to select\nall subtodos of all\nselected todos as well?"),
709 i18n("Todo has subtodos"), 709 i18n("Todo has subtodos"),
710 i18n("Yes"), 710 i18n("Yes"),
711 i18n("No")); 711 i18n("No"));
712 if ( result == KMessageBox::Cancel ) { 712 if ( result == KMessageBox::Cancel ) {
713 delSel.clear(); 713 delSel.clear();
714 return delSel; 714 return delSel;
715 } 715 }
716 if (result == KMessageBox::Yes) 716 if (result == KMessageBox::Yes)
717 addSubTodos = true; 717 addSubTodos = true;
718 askSubTodos = false; 718 askSubTodos = false;
719 } 719 }
720 if ( addSubTodos ) { 720 if ( addSubTodos ) {
721 QPtrList<Incidence> tempSel ; 721 QPtrList<Incidence> tempSel ;
722 inc->addRelationsToList( &tempSel ); 722 inc->addRelationsToList( &tempSel );
723 Incidence* tempinc = tempSel.first(); 723 Incidence* tempinc = tempSel.first();
724 while ( tempinc ) { 724 while ( tempinc ) {
725 if ( delSel.findRef( tempinc ) == -1 ) { 725 if ( delSel.findRef( tempinc ) == -1 ) {
726 if ( tempinc->typeID() == todoID && onlyDueTodos ) { 726 if ( tempinc->typeID() == todoID && onlyDueTodos ) {
727 if ( ((Todo*)tempinc)->hasDueDate() ) 727 if ( ((Todo*)tempinc)->hasDueDate() )
728 delSel.append( tempinc ); 728 delSel.append( tempinc );
729 } else 729 } else
730 delSel.append( tempinc ); 730 delSel.append( tempinc );
731 } 731 }
732 tempinc = tempSel.next(); 732 tempinc = tempSel.next();
733 } 733 }
734 } 734 }
735 } 735 }
736 } 736 }
737 } 737 }
738 item = item->nextSibling(); 738 item = item->nextSibling();
739 } 739 }
740 return delSel; 740 return delSel;
741} 741}
742 742
743void KOListView::writeToFile( bool iCal ) 743void KOListView::writeToFile( bool iCal )
744{ 744{
745 QPtrList<Incidence> delSel = getSelectedIncidences(); // all inc allowed; 745 QPtrList<Incidence> delSel = getSelectedIncidences(); // all inc allowed;
746 if ( !iCal ) { 746 if ( !iCal ) {
747 bool journal = false; 747 bool journal = false;
748 Incidence *incidence = delSel.first(); 748 Incidence *incidence = delSel.first();
749 while ( incidence ) { 749 while ( incidence ) {
750 if ( incidence->typeID() == journalID ) { 750 if ( incidence->typeID() == journalID ) {
751 journal = true; 751 journal = true;
752 break; 752 break;
753 } 753 }
754 incidence = delSel.next(); 754 incidence = delSel.next();
755 } 755 }
756 if ( journal ) { 756 if ( journal ) {
757 int result = KMessageBox::warningContinueCancel(this, 757 int result = KMessageBox::warningContinueCancel(this,
758 i18n("The journal entries can not be\nexported to a vCalendar file."), 758 i18n("The journal entries can not be\nexported to a vCalendar file."),
759 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 759 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
760 true); 760 true);
761 if (result != KMessageBox::Continue) return; 761 if (result != KMessageBox::Continue) return;
762 } 762 }
763 } 763 }
764 if ( delSel.count() ) { 764 if ( delSel.count() ) {
765 QString fn = KOPrefs::instance()->mLastSaveFile; 765 QString fn = KOPrefs::instance()->mLastSaveFile;
766 QString extension; 766 QString extension;
767 if ( iCal ) { 767 if ( iCal ) {
768 if ( fn.right( 4 ).lower() == ".vcs" ) { 768 if ( fn.right( 4 ).lower() == ".vcs" ) {
769 fn = fn.left( fn.length() -3) + "ics"; 769 fn = fn.left( fn.length() -3) + "ics";
770 } 770 }
771 } else { 771 } else {
772 if ( fn.right( 4 ).lower() == ".ics" ) { 772 if ( fn.right( 4 ).lower() == ".ics" ) {
773 fn = fn.left( fn.length() -3) + "vcs"; 773 fn = fn.left( fn.length() -3) + "vcs";
774 } 774 }
775 } 775 }
776 fn = KFileDialog::getSaveFileName( fn, i18n("Save filename"), this ); 776 fn = KFileDialog::getSaveFileName( fn, i18n("Save filename"), this );
777 777
778 if ( fn == "" ) 778 if ( fn == "" )
779 return; 779 return;
780 QFileInfo info; 780 QFileInfo info;
781 info.setFile( fn ); 781 info.setFile( fn );
782 QString mes; 782 QString mes;
783 bool createbup = true; 783 bool createbup = true;
784 if ( info. exists() ) { 784 if ( info. exists() ) {
785 mes = i18n("File already exists!\nOld file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); 785 mes = i18n("File already exists!\nOld file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) );
786 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, 786 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes,
787 i18n("Overwrite!"), i18n("Cancel"), 0, 787 i18n("Overwrite!"), i18n("Cancel"), 0,
788 0, 1 ); 788 0, 1 );
789 if ( result != 0 ) { 789 if ( result != 0 ) {
790 createbup = false; 790 createbup = false;
791 } 791 }
792 } 792 }
793 if ( createbup ) { 793 if ( createbup ) {
794 CalendarLocal cal; 794 CalendarLocal cal;
795 cal.setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 795 cal.setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
796 Incidence *incidence = delSel.first(); 796 Incidence *incidence = delSel.first();
797 while ( incidence ) { 797 while ( incidence ) {
798 cal.addIncidence( incidence->clone() ); 798 cal.addIncidence( incidence->clone() );
799 incidence = delSel.next(); 799 incidence = delSel.next();
800 } 800 }
801 if ( iCal ) { 801 if ( iCal ) {
802 ICalFormat format; 802 ICalFormat format;
803 format.save( &cal, fn ); 803 format.save( &cal, fn );
804 } else { 804 } else {
805 805
806 VCalFormat format; 806 VCalFormat format;
807 format.save( &cal, fn ); 807 format.save( &cal, fn );
808 } 808 }
809 mes = i18n("KO/Pi:Saved %1").arg(fn ); 809 mes = i18n("KO/Pi:Saved %1").arg(fn );
810 KOPrefs::instance()->mLastSaveFile = fn; 810 KOPrefs::instance()->mLastSaveFile = fn;
811 topLevelWidget()->setCaption(mes); 811 topLevelWidget()->setCaption(mes);
812 } 812 }
813 } 813 }
814 QTimer::singleShot( 1, this, SLOT ( resetFocus() ) ); 814 QTimer::singleShot( 1, this, SLOT ( resetFocus() ) );
815} 815}
816void KOListView::hideAll() 816void KOListView::hideAll()
817{ 817{
818 QPtrList<QListViewItem> delSel ; 818 QPtrList<QListViewItem> delSel ;
819 QListViewItem *item = mListView->firstChild (); 819 QListViewItem *item = mListView->firstChild ();
820 while ( item ) { 820 while ( item ) {
821 if ( item->isSelected() ) { 821 if ( item->isSelected() ) {
822 delSel.append(item); 822 delSel.append(item);
823 } 823 }
824 item = item->nextSibling(); 824 item = item->nextSibling();
825 } 825 }
826 item = delSel.first() ; 826 item = delSel.first() ;
827 while ( item ) { 827 while ( item ) {
828 QListViewItem * del = item; 828 QListViewItem * del = item;
829 item = delSel.next(); 829 item = delSel.next();
830 delete del; 830 delete del;
831 } 831 }
832} 832}
833void KOListView::printList() 833void KOListView::printList()
834{ 834{
835 mListView->printList(); 835 mListView->printList();
836} 836}
837void KOListView::deleteAll() 837void KOListView::deleteAll()
838{ 838{
839 QPtrList<Incidence> delSel = getSelectedIncidences(); // all inc allowed;; 839 QPtrList<Incidence> delSel = getSelectedIncidences(); // all inc allowed;;
840 if ( delSel.count() ) { 840 if ( delSel.count() ) {
841 int icount = delSel.count(); 841 int icount = delSel.count();
842 Incidence *incidence = delSel.first(); 842 Incidence *incidence = delSel.first();
843 Incidence *toDelete; 843 Incidence *toDelete;
844 KOPrefs *p = KOPrefs::instance(); 844 KOPrefs *p = KOPrefs::instance();
845 bool confirm = p->mConfirm; 845 bool confirm = p->mConfirm;
846 QString mess; 846 QString mess;
847 mess = mess.sprintf( i18n("You have %d item(s) selected.\n"), icount ); 847 mess = mess.sprintf( i18n("You have %d item(s) selected.\n"), icount );
848 if ( KMessageBox::Continue == KMessageBox::warningContinueCancel(this, mess + i18n("All selected items will be\npermanently deleted.\n(Deleting items will take\nsome time on a PDA)\n"), i18n("KO/Pi Confirmation"),i18n("Delete")) ) { 848 if ( KMessageBox::Continue == KMessageBox::warningContinueCancel(this, mess + i18n("All selected items will be\npermanently deleted.\n(Deleting items will take\nsome time on a PDA)\n"), i18n("KO/Pi Confirmation"),i18n("Delete")) ) {
849 p->mConfirm = false; 849 p->mConfirm = false;
850 int delCounter = 0; 850 int delCounter = 0;
851 QDialog dia ( this, "p-dialog", true ); 851 QDialog dia ( this, "p-dialog", true );
852 QLabel lab (i18n("Close dialog to abort deletion!"), &dia ); 852 QLabel lab (i18n("Close dialog to abort deletion!"), &dia );
853 QVBoxLayout lay( &dia ); 853 QVBoxLayout lay( &dia );
854 lay.setMargin(7); 854 lay.setMargin(7);
855 lay.setSpacing(7); 855 lay.setSpacing(7);
856 lay.addWidget( &lab); 856 lay.addWidget( &lab);
857 QProgressBar bar( icount, &dia ); 857 QProgressBar bar( icount, &dia );
858 lay.addWidget( &bar); 858 lay.addWidget( &bar);
859 int w = 220; 859 int w = 220;
860 int h = 50; 860 int h = 50;
861 int dw = QApplication::desktop()->width(); 861 int dw = QApplication::desktop()->width();
862 int dh = QApplication::desktop()->height(); 862 int dh = QApplication::desktop()->height();
863 dia.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 863 dia.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
864 //dia.resize( 240,50 ); 864 //dia.resize( 240,50 );
865 dia.show(); 865 dia.show();
866 KOPrefs::instance()->mGlobalUpdateDisabled = true; 866 KOPrefs::instance()->mGlobalUpdateDisabled = true;
867 while ( incidence ) { 867 while ( incidence ) {
868 bar.setProgress( delCounter ); 868 bar.setProgress( delCounter );
869 mess = mess.sprintf( i18n("Deleting item %d ..."), ++delCounter ); 869 mess = mess.sprintf( i18n("Deleting item %d ..."), ++delCounter );
870 dia.setCaption( mess ); 870 dia.setCaption( mess );
871 qApp->processEvents(); 871 qApp->processEvents();
872 toDelete = (incidence); 872 toDelete = (incidence);
873 incidence = delSel.next(); 873 incidence = delSel.next();
874 emit deleteIncidenceSignal(toDelete ); 874 emit deleteIncidenceSignal(toDelete );
875 if ( dia.result() != 0 ) 875 if ( dia.result() != 0 )
876 break; 876 break;
877 877
878 } 878 }
879 KOPrefs::instance()->mGlobalUpdateDisabled = false; 879 KOPrefs::instance()->mGlobalUpdateDisabled = false;
880 emit deleteIncidenceSignal( 0 ); 880 emit deleteIncidenceSignal( 0 );
881 mess = mess.sprintf( i18n("%d items remaining in list."), count() ); 881 mess = mess.sprintf( i18n("%d items remaining in list."), count() );
882 topLevelWidget ()->setCaption( mess ); 882 topLevelWidget ()->setCaption( mess );
883 p->mConfirm = confirm; 883 p->mConfirm = confirm;
884 } 884 }
885 } 885 }
886 886
887 887
888} 888}
889int KOListView::maxDatesHint() 889int KOListView::maxDatesHint()
890{ 890{
891 return 0; 891 return 0;
892} 892}
893 893
894int KOListView::currentDateCount() 894int KOListView::currentDateCount()
895{ 895{
896 return 0; 896 return 0;
897} 897}
898 898
899QPtrList<Incidence> KOListView::selectedIncidences() 899QPtrList<Incidence> KOListView::selectedIncidences()
900{ 900{
901 QPtrList<Incidence> eventList; 901 QPtrList<Incidence> eventList;
902 QListViewItem *item = mListView->firstChild (); 902 QListViewItem *item = mListView->firstChild ();
903 while ( item ) { 903 while ( item ) {
904 if ( item->isSelected() ) { 904 if ( item->isSelected() ) {
905 eventList.append(((KOListViewItem *)item)->data()); 905 eventList.append(((KOListViewItem *)item)->data());
906 } 906 }
907 907
908 item = item->nextSibling(); 908 item = item->nextSibling();
909 } 909 }
910 910
911 // // QListViewItem *item = mListView->selectedItem(); 911 // // QListViewItem *item = mListView->selectedItem();
912 //if (item) eventList.append(((KOListViewItem *)item)->data()); 912 //if (item) eventList.append(((KOListViewItem *)item)->data());
913 913
914 return eventList; 914 return eventList;
915} 915}
916 916
917DateList KOListView::selectedDates() 917DateList KOListView::selectedDates()
918{ 918{
919 DateList eventList; 919 DateList eventList;
920 return eventList; 920 return eventList;
921} 921}
922 922
923void KOListView::showDates(bool show) 923void KOListView::showDates(bool show)
924{ 924{
925 // Shouldn't we set it to a value greater 0? When showDates is called with 925 // Shouldn't we set it to a value greater 0? When showDates is called with
926 // show == true at first, then the columnwidths are set to zero. 926 // show == true at first, then the columnwidths are set to zero.
927 static int oldColWidth1 = 0; 927 static int oldColWidth1 = 0;
928 static int oldColWidth3 = 0; 928 static int oldColWidth3 = 0;
929 929
930 if (!show) { 930 if (!show) {
931 oldColWidth1 = mListView->columnWidth(1); 931 oldColWidth1 = mListView->columnWidth(1);
932 oldColWidth3 = mListView->columnWidth(3); 932 oldColWidth3 = mListView->columnWidth(3);
933 mListView->setColumnWidth(1, 0); 933 mListView->setColumnWidth(1, 0);
934 mListView->setColumnWidth(3, 0); 934 mListView->setColumnWidth(3, 0);
935 } else { 935 } else {
936 mListView->setColumnWidth(1, oldColWidth1); 936 mListView->setColumnWidth(1, oldColWidth1);
937 mListView->setColumnWidth(3, oldColWidth3); 937 mListView->setColumnWidth(3, oldColWidth3);
938 } 938 }
939 mListView->repaint(); 939 mListView->repaint();
940} 940}
941 941
942void KOListView::printPreview(CalPrinter *calPrinter, const QDate &fd, 942void KOListView::printPreview(CalPrinter *calPrinter, const QDate &fd,
943 const QDate &td) 943 const QDate &td)
944{ 944{
945#ifndef KORG_NOPRINTER 945#ifndef KORG_NOPRINTER
946 calPrinter->preview(CalPrinter::Day, fd, td); 946 calPrinter->preview(CalPrinter::Day, fd, td);
947#endif 947#endif
948} 948}
949 949
950void KOListView::showDates() 950void KOListView::showDates()
951{ 951{
952 showDates(true); 952 showDates(true);
953} 953}
954 954
955void KOListView::hideDates() 955void KOListView::hideDates()
956{ 956{
957 showDates(false); 957 showDates(false);
958} 958}
959 959
960void KOListView::resetFocus() 960void KOListView::resetFocus()
961{ 961{
962 topLevelWidget()->setActiveWindow(); 962 topLevelWidget()->setActiveWindow();
963 topLevelWidget()->raise(); 963 topLevelWidget()->raise();
964 mListView->setFocus(); 964 mListView->setFocus();
965} 965}
966void KOListView::updateView() 966void KOListView::updateView()
967{ 967{
968 mListView->setFocus(); 968 mListView->setFocus();
969 if ( mListView->firstChild () ) { 969 if ( mListView->firstChild () ) {
970 mListView->setCurrentItem( mListView->firstChild () ); 970 mListView->setCurrentItem( mListView->firstChild () );
971 } 971 }
972 processSelectionChange( mListView->firstChild () ); 972 processSelectionChange( mListView->firstChild () );
973} 973}
974void KOListView::updateConfig() 974void KOListView::updateConfig()
975{ 975{
976 976
977 mListView->setFont ( KOPrefs::instance()->mListViewFont ); 977 mListView->setFont ( KOPrefs::instance()->mListViewFont );
978 updateView(); 978 updateView();
979 979
980} 980}
981void KOListView::setStartDate(const QDate &start) 981void KOListView::setStartDate(const QDate &start)
982{ 982{
983 mStartDate = start; 983 mStartDate = start;
984} 984}
985 985
986void KOListView::showDates(const QDate &start, const QDate &end) 986void KOListView::showDates(const QDate &start, const QDate &end)
987{ 987{
988 clear(); 988 clear();
989 mStartDate = start; 989 mStartDate = start;
990 QDate date = start; 990 QDate date = start;
991 while( date <= end ) { 991 while( date <= end ) {
992 addEvents(calendar()->events(date)); 992 addEvents(calendar()->events(date));
993 addTodos(calendar()->todos(date)); 993 addTodos(calendar()->todos(date));
994 addJournals( calendar()->journals4Date(date) ); 994 addJournals( calendar()->journals4Date(date) );
995 date = date.addDays( 1 ); 995 date = date.addDays( 1 );
996 } 996 }
997 //emit incidenceSelected( 0 ); 997 //emit incidenceSelected( 0 );
998 updateView(); 998 updateView();
999 999
1000} 1000}
1001 1001
1002void KOListView::addEvents(QPtrList<Event> eventList) 1002void KOListView::addEvents(QPtrList<Event> eventList)
1003{ 1003{
1004 1004
1005 Event *ev; 1005 Event *ev;
1006 for(ev = eventList.first(); ev; ev = eventList.next()) { 1006 for(ev = eventList.first(); ev; ev = eventList.next()) {
1007 addIncidence(ev); 1007 addIncidence(ev);
1008 } 1008 }
1009 if ( !mListView->currentItem() ){ 1009 if ( !mListView->currentItem() ){
1010 updateView(); 1010 updateView();
1011 } 1011 }
1012} 1012}
1013 1013
1014void KOListView::addTodos(QPtrList<Todo> eventList) 1014void KOListView::addTodos(QPtrList<Todo> eventList)
1015{ 1015{
1016 Todo *ev; 1016 Todo *ev;
1017 for(ev = eventList.first(); ev; ev = eventList.next()) { 1017 for(ev = eventList.first(); ev; ev = eventList.next()) {
1018 addIncidence(ev); 1018 addIncidence(ev);
1019 } 1019 }
1020 if ( !mListView->currentItem() ){ 1020 if ( !mListView->currentItem() ){
1021 updateView(); 1021 updateView();
1022 } 1022 }
1023} 1023}
1024void KOListView::addJournals(QPtrList<Journal> eventList) 1024void KOListView::addJournals(QPtrList<Journal> eventList)
1025{ 1025{
1026 Journal *ev; 1026 Journal *ev;
1027 for(ev = eventList.first(); ev; ev = eventList.next()) { 1027 for(ev = eventList.first(); ev; ev = eventList.next()) {
1028 addIncidence(ev); 1028 addIncidence(ev);
1029 } 1029 }
1030 if ( !mListView->currentItem() ){ 1030 if ( !mListView->currentItem() ){
1031 updateView(); 1031 updateView();
1032 } 1032 }
1033} 1033}
1034 1034
1035void KOListView::showCompletedTodos() 1035void KOListView::showCompletedTodos()
1036{ 1036{
1037 mForceShowCompletedTodos = true; 1037 mForceShowCompletedTodos = true;
1038} 1038}
1039void KOListView::addIncidence(Incidence *incidence) 1039void KOListView::addIncidence(Incidence *incidence)
1040{ 1040{
1041 if ( mUidDict.find( incidence->uid() ) ) return; 1041 if ( mUidDict.find( incidence->uid() ) ) return;
1042 1042
1043 // mListView->setFont ( KOPrefs::instance()->mListViewFont ); 1043 // mListView->setFont ( KOPrefs::instance()->mListViewFont );
1044 if ( incidence->typeID() == todoID ) { 1044 if ( incidence->typeID() == todoID ) {
1045 if ( ! mForceShowCompletedTodos ) { 1045 if ( ! mForceShowCompletedTodos ) {
1046 if ( !KOPrefs::instance()->mShowCompletedTodo && ((Todo*)incidence)->isCompleted() ) 1046 if ( !KOPrefs::instance()->mShowCompletedTodo && ((Todo*)incidence)->isCompleted() )
1047 return; 1047 return;
1048 } 1048 }
1049 } 1049 }
1050 mUidDict.insert( incidence->uid(), incidence ); 1050 mUidDict.insert( incidence->uid(), incidence );
1051 KOListViewItem *item = new KOListViewItem( incidence, mListView ); 1051 KOListViewItem *item = new KOListViewItem( incidence, mListView );
1052 ListItemVisitor v(item, mStartDate ); 1052 ListItemVisitor v(item, mStartDate );
1053 if (incidence->accept(v)) { 1053 if (incidence->accept(v)) {
1054 return; 1054 return;
1055 } 1055 }
1056 else delete item; 1056 else delete item;
1057} 1057}
1058 1058
1059void KOListView::showEvents(QPtrList<Event> eventList) 1059void KOListView::showEvents(QPtrList<Event> eventList)
1060{ 1060{
1061 clear(); 1061 clear();
1062 1062
1063 addEvents(eventList); 1063 addEvents(eventList);
1064 1064
1065 // After new creation of list view no events are selected. 1065 // After new creation of list view no events are selected.
1066 emit incidenceSelected( 0 ); 1066 emit incidenceSelected( 0 );
1067} 1067}
1068int KOListView::count() 1068int KOListView::count()
1069{ 1069{
1070 return mListView->childCount(); 1070 return mListView->childCount();
1071} 1071}
1072 1072
1073void KOListView::changeEventDisplay(Event *event, int action) 1073void KOListView::changeEventDisplay(Event *event, int action)
1074{ 1074{
1075 KOListViewItem *item; 1075 KOListViewItem *item;
1076 1076
1077 switch(action) { 1077 switch(action) {
1078 case KOGlobals::EVENTADDED: 1078 case KOGlobals::EVENTADDED:
1079 addIncidence( event ); 1079 addIncidence( event );
1080 break; 1080 break;
1081 case KOGlobals::EVENTEDITED: 1081 case KOGlobals::EVENTEDITED:
1082 item = getItemForEvent(event); 1082 item = getItemForEvent(event);
1083 if (item) { 1083 if (item) {
1084 ListItemVisitor v(item, mStartDate ); 1084 ListItemVisitor v(item, mStartDate );
1085 ((Incidence*)event)->accept(v); 1085 ((Incidence*)event)->accept(v);
1086 } 1086 }
1087 break; 1087 break;
1088 case KOGlobals::EVENTDELETED: 1088 case KOGlobals::EVENTDELETED:
1089 item = getItemForEvent(event); 1089 item = getItemForEvent(event);
1090 if (item) { 1090 if (item) {
1091 mUidDict.remove( event->uid() ); 1091 mUidDict.remove( event->uid() );
1092 delete item; 1092 delete item;
1093 } 1093 }
1094 break; 1094 break;
1095 default: 1095 default:
1096 ; 1096 ;
1097 } 1097 }
1098} 1098}
1099 1099
1100KOListViewItem *KOListView::getItemForEvent(Incidence *event) 1100KOListViewItem *KOListView::getItemForEvent(Incidence *event)
1101{ 1101{
1102 KOListViewItem *item = (KOListViewItem *)mListView->firstChild(); 1102 KOListViewItem *item = (KOListViewItem *)mListView->firstChild();
1103 while (item) { 1103 while (item) {
1104 if (item->data() == event) return item; 1104 if (item->data() == event) return item;
1105 item = (KOListViewItem *)item->nextSibling(); 1105 item = (KOListViewItem *)item->nextSibling();
1106 } 1106 }
1107 return 0; 1107 return 0;
1108} 1108}
1109 1109
1110void KOListView::defaultItemAction(QListViewItem *i) 1110void KOListView::defaultItemAction(QListViewItem *i)
1111{ 1111{
1112 KOListViewItem *item = static_cast<KOListViewItem *>( i ); 1112 KOListViewItem *item = static_cast<KOListViewItem *>( i );
1113 if ( item ) defaultAction( item->data() ); 1113 if ( item ) defaultAction( item->data() );
1114 1114
1115} 1115}
1116 1116
1117void KOListView::popupMenu(QListViewItem *item,const QPoint &,int) 1117void KOListView::popupMenu(QListViewItem *item,const QPoint &,int)
1118{ 1118{
1119 mActiveItem = (KOListViewItem *)item; 1119 mActiveItem = (KOListViewItem *)item;
1120 if (mActiveItem) { 1120 if (mActiveItem) {
1121 Incidence *incidence = mActiveItem->data(); 1121 Incidence *incidence = mActiveItem->data();
1122 mPopupMenu->enableDefault( !mListView->hasMultiSelection( item ) ); 1122 mPopupMenu->enableDefault( !mListView->hasMultiSelection( item ) );
1123 mPopupMenu->showIncidencePopup(incidence); 1123 mPopupMenu->showIncidencePopup(incidence);
1124 1124
1125 /* 1125 /*
1126 if ( incidence && incidence->type() == "Event" ) { 1126 if ( incidence && incidence->type() == "Event" ) {
1127 Event *event = static_cast<Event *>( incidence ); 1127 Event *event = static_cast<Event *>( incidence );
1128 mPopupMenu->showEventPopup(event); 1128 mPopupMenu->showEventPopup(event);
1129 } 1129 }
1130 */ 1130 */
1131 } 1131 }
1132} 1132}
1133 1133
1134void KOListView::readSettings(KConfig *config, QString setting) 1134void KOListView::readSettings(KConfig *config, QString setting)
1135{ 1135{
1136 // qDebug("KOListView::readSettings "); 1136 // qDebug("KOListView::readSettings ");
1137 mListView->restoreLayout(config,setting); 1137 mListView->restoreLayout(config,setting);
1138} 1138}
1139 1139
1140void KOListView::writeSettings(KConfig *config, QString setting) 1140void KOListView::writeSettings(KConfig *config, QString setting)
1141{ 1141{
1142 // qDebug("KOListView::writeSettings "); 1142 // qDebug("KOListView::writeSettings ");
1143 mListView->saveLayout(config, setting); 1143 mListView->saveLayout(config, setting);
1144} 1144}
1145 1145
1146void KOListView::processSelectionChange(QListViewItem *) 1146void KOListView::processSelectionChange(QListViewItem *)
1147{ 1147{
1148 1148
1149 KOListViewItem *item = 1149 KOListViewItem *item =
1150 static_cast<KOListViewItem *>( mListView->currentItem() ); 1150 static_cast<KOListViewItem *>( mListView->currentItem() );
1151 1151
1152 if ( !item ) { 1152 if ( !item ) {
1153 emit incidenceSelected( 0 ); 1153 emit incidenceSelected( 0 );
1154 } else { 1154 } else {
1155 emit incidenceSelected( item->data() ); 1155 emit incidenceSelected( item->data() );
1156 } 1156 }
1157} 1157}
1158 1158
1159void KOListView::clearSelection() 1159void KOListView::clearSelection()
1160{ 1160{
1161 mListView->selectAll( false ); 1161 mListView->selectAll( false );
1162} 1162}
1163void KOListView::allSelection() 1163void KOListView::allSelection()
1164{ 1164{
1165 mListView->selectAll( true ); 1165 mListView->selectAll( true );
1166} 1166}
1167 1167
1168void KOListView::clear() 1168void KOListView::clear()
1169{ 1169{
1170 mListView->clear(); 1170 mListView->clear();
1171 mUidDict.clear(); 1171 mUidDict.clear();
1172} 1172}
1173 1173
1174Incidence* KOListView::currentItem() 1174Incidence* KOListView::currentItem()
1175{ 1175{
1176 if ( mListView->currentItem() ) 1176 if ( mListView->currentItem() )
1177 return ((KOListViewItem*) mListView->currentItem())->data(); 1177 return ((KOListViewItem*) mListView->currentItem())->data();
1178 return 0; 1178 return 0;
1179} 1179}
1180void KOListView::keyPressEvent ( QKeyEvent *e) 1180void KOListView::keyPressEvent ( QKeyEvent *e)
1181{ 1181{
1182 1182
1183 if ( e->key() == Qt::Key_Delete || e->key() == Qt::Key_Backspace ) { 1183 if ( e->key() == Qt::Key_Delete || e->key() == Qt::Key_Backspace ) {
1184 deleteAll(); 1184 deleteAll();
1185 return; 1185 return;
1186 } 1186 }
1187 1187
1188 e->ignore(); 1188 e->ignore();
1189} 1189}
1190void KOListViewListView::keyPressEvent ( QKeyEvent *e) 1190void KOListViewListView::keyPressEvent ( QKeyEvent *e)
1191{ 1191{
1192 1192
1193 switch ( e->key() ) { 1193 switch ( e->key() ) {
1194 case Qt::Key_Down: 1194 case Qt::Key_Down:
1195 if ( e->state() == ShiftButton ) { 1195 if ( e->state() == ShiftButton ) {
1196 QListViewItem* cn = currentItem(); 1196 QListViewItem* cn = currentItem();
1197 if ( !cn ) 1197 if ( !cn )
1198 cn = firstChild(); 1198 cn = firstChild();
1199 if ( !cn ) 1199 if ( !cn )
1200 return; 1200 return;
1201 while ( cn->nextSibling() ) 1201 while ( cn->nextSibling() )
1202 cn = cn->nextSibling(); 1202 cn = cn->nextSibling();
1203 setCurrentItem ( cn ); 1203 setCurrentItem ( cn );
1204 ensureItemVisible ( cn ); 1204 ensureItemVisible ( cn );
1205 1205
1206 e->accept(); 1206 e->accept();
1207 return; 1207 return;
1208 } 1208 }
1209 if ( e->state() == ControlButton ) { 1209 if ( e->state() == ControlButton ) {
1210 int count = childCount (); 1210 int count = childCount ();
1211 int jump = count / 5; 1211 int jump = count / 5;
1212 QListViewItem* cn; 1212 QListViewItem* cn;
1213 cn = currentItem(); 1213 cn = currentItem();
1214 if ( ! cn ) 1214 if ( ! cn )
1215 return; 1215 return;
1216 if ( jump == 0 ) 1216 if ( jump == 0 )
1217 jump = 1; 1217 jump = 1;
1218 while ( jump && cn->nextSibling() ) { 1218 while ( jump && cn->nextSibling() ) {
1219 cn = cn->nextSibling(); 1219 cn = cn->nextSibling();
1220 --jump; 1220 --jump;
1221 } 1221 }
1222 setCurrentItem ( cn ); 1222 setCurrentItem ( cn );
1223 ensureItemVisible ( cn ); 1223 ensureItemVisible ( cn );
1224 1224
1225 } else 1225 } else
1226 QListView::keyPressEvent ( e ) ; 1226 QListView::keyPressEvent ( e ) ;
1227 e->accept(); 1227 e->accept();
1228 break; 1228 break;
1229 1229
1230 case Qt::Key_Up: 1230 case Qt::Key_Up:
1231 if ( e->state() == ShiftButton ) { 1231 if ( e->state() == ShiftButton ) {
1232 QListViewItem* cn = firstChild(); 1232 QListViewItem* cn = firstChild();
1233 if ( cn ) { 1233 if ( cn ) {
1234 setCurrentItem ( cn ); 1234 setCurrentItem ( cn );
1235 ensureItemVisible ( cn ); 1235 ensureItemVisible ( cn );
1236 } 1236 }
1237 e->accept(); 1237 e->accept();
1238 return; 1238 return;
1239 } 1239 }
1240 if ( e->state() == ControlButton ) { 1240 if ( e->state() == ControlButton ) {
1241 int count = childCount (); 1241 int count = childCount ();
1242 int jump = count / 5; 1242 int jump = count / 5;
1243 QListViewItem* cn; 1243 QListViewItem* cn;
1244 cn = currentItem(); 1244 cn = currentItem();
1245 if ( ! cn ) 1245 if ( ! cn )
1246 return; 1246 return;
1247 if ( jump == 0 ) 1247 if ( jump == 0 )
1248 jump = 1; 1248 jump = 1;
1249 while ( jump && cn->itemAbove ()) { 1249 while ( jump && cn->itemAbove ()) {
1250 cn = cn->itemAbove (); 1250 cn = cn->itemAbove ();
1251 --jump; 1251 --jump;
1252 } 1252 }
1253 setCurrentItem ( cn ); 1253 setCurrentItem ( cn );
1254 ensureItemVisible ( cn ); 1254 ensureItemVisible ( cn );
1255 } else 1255 } else
1256 QListView::keyPressEvent ( e ) ; 1256 QListView::keyPressEvent ( e ) ;
1257 e->accept(); 1257 e->accept();
1258 break; 1258 break;
1259 case Qt::Key_I: { 1259 case Qt::Key_I: {
1260 QListViewItem* cn; 1260 QListViewItem* cn;
1261 cn = currentItem(); 1261 cn = currentItem();
1262 if ( cn ) { 1262 if ( cn ) {
1263 KOListViewItem* ci = (KOListViewItem*)( cn ); 1263 KOListViewItem* ci = (KOListViewItem*)( cn );
1264 if ( ci ){ 1264 if ( ci ){
1265 //emit showIncidence( ci->data()); 1265 //emit showIncidence( ci->data());
1266 cn = cn->nextSibling(); 1266 cn = cn->nextSibling();
1267 if ( cn ) { 1267 if ( cn ) {
1268 setCurrentItem ( cn ); 1268 setCurrentItem ( cn );
1269 ensureItemVisible ( cn ); 1269 ensureItemVisible ( cn );
1270 } 1270 }
1271 emit showIncidence( ci->data()); 1271 emit showIncidence( ci->data());
1272 } 1272 }
1273 } 1273 }
1274 e->accept(); 1274 e->accept();
1275 } 1275 }
1276 break; 1276 break;
1277 case Qt::Key_Return: 1277 case Qt::Key_Return:
1278 case Qt::Key_Enter: 1278 case Qt::Key_Enter:
1279 { 1279 {
1280 QListViewItem* cn; 1280 QListViewItem* cn;
1281 cn = currentItem(); 1281 cn = currentItem();
1282 if ( cn ) { 1282 if ( cn ) {
1283 KOListViewItem* ci = (KOListViewItem*)( cn ); 1283 KOListViewItem* ci = (KOListViewItem*)( cn );
1284 if ( ci ){ 1284 if ( ci ){
1285 if ( e->state() == ShiftButton ) 1285 if ( e->state() == ShiftButton )
1286 ci->setSelected( false ); 1286 ci->setSelected( false );
1287 else 1287 else
1288 ci->setSelected( true ); 1288 ci->setSelected( true );
1289 cn = cn->nextSibling(); 1289 cn = cn->nextSibling();
1290 if ( cn ) { 1290 if ( cn ) {
1291 setCurrentItem ( cn ); 1291 setCurrentItem ( cn );
1292 ensureItemVisible ( cn ); 1292 ensureItemVisible ( cn );
1293 } 1293 }
1294 } 1294 }
1295 } 1295 }
1296 e->accept(); 1296 e->accept();
1297 } 1297 }
1298 break; 1298 break;
1299 default: 1299 default:
1300 e->ignore(); 1300 e->ignore();
1301 } 1301 }
1302} 1302}
1303KOListViewListView::KOListViewListView(KOListView * lv ) 1303KOListViewListView::KOListViewListView(KOListView * lv )
1304 : KListView( lv, "kolistlistview", false ) 1304 : KListView( lv, "kolistlistview", false )
1305{ 1305{
1306 mYMousePos = 0; 1306 mYMousePos = 0;
1307 mPopupTimer = new QTimer(this); 1307 mPopupTimer = new QTimer(this);
1308 connect(mPopupTimer , SIGNAL(timeout()), this, SLOT(popupMenu())); 1308 connect(mPopupTimer , SIGNAL(timeout()), this, SLOT(popupMenu()));
1309#ifndef DESKTOP_VERSION 1309#ifndef DESKTOP_VERSION
1310 //QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold ); 1310 //QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold );
1311#endif 1311#endif
1312 setSelectionMode( QListView::Multi ); 1312 setSelectionMode( QListView::Multi );
1313 setMultiSelection( true); 1313 setMultiSelection( true);
1314} 1314}
1315bool KOListViewListView::hasMultiSelection(QListViewItem* item) 1315bool KOListViewListView::hasMultiSelection(QListViewItem* item)
1316{ 1316{
1317 QListViewItem *qitem = firstChild (); 1317 QListViewItem *qitem = firstChild ();
1318 while ( qitem ) { 1318 while ( qitem ) {
1319 if ( qitem->isSelected() && item != qitem ) 1319 if ( qitem->isSelected() && item != qitem )
1320 return true; 1320 return true;
1321 qitem = qitem->nextSibling(); 1321 qitem = qitem->nextSibling();
1322 } 1322 }
1323 return false; 1323 return false;
1324} 1324}
1325void KOListViewListView::contentsMouseDoubleClickEvent(QMouseEvent *e) 1325void KOListViewListView::contentsMouseDoubleClickEvent(QMouseEvent *e)
1326{ 1326{
1327 if (!e) return; 1327 if (!e) return;
1328 QPoint vp = contentsToViewport(e->pos()); 1328 QPoint vp = contentsToViewport(e->pos());
1329 QListViewItem *item = itemAt(vp); 1329 QListViewItem *item = itemAt(vp);
1330 if (!item) { 1330 if (!item) {
1331 emit newEvent(); 1331 emit newEvent();
1332 return; 1332 return;
1333 } 1333 }
1334 KListView::contentsMouseDoubleClickEvent(e); 1334 KListView::contentsMouseDoubleClickEvent(e);
1335} 1335}
1336#if 0 1336#if 0
1337void KOListViewListView::contentsMousePressEvent(QMouseEvent *e) 1337void KOListViewListView::contentsMousePressEvent(QMouseEvent *e)
1338{ 1338{
1339 //qDebug("contentsMousePressEvent++++ "); 1339 //qDebug("contentsMousePressEvent++++ ");
1340 KListView::contentsMousePressEvent( e ); 1340 KListView::contentsMousePressEvent( e );
1341 if ( e->button() == RightButton ) { 1341 if ( e->button() == RightButton ) {
1342 QListViewItem* ci = currentItem(); 1342 QListViewItem* ci = currentItem();
1343 clearSelection () ; 1343 clearSelection () ;
1344 if ( ci ) 1344 if ( ci )
1345 ci->setSelected( true ); 1345 ci->setSelected( true );
1346 } 1346 }
1347} 1347}
1348void KOListViewListView::contentsMouseReleaseEvent(QMouseEvent *e) 1348void KOListViewListView::contentsMouseReleaseEvent(QMouseEvent *e)
1349{ 1349{
1350 KListView::contentsMouseReleaseEvent(e); 1350 KListView::contentsMouseReleaseEvent(e);
1351} 1351}
1352void KOListViewListView::contentsMouseMoveEvent(QMouseEvent *e) 1352void KOListViewListView::contentsMouseMoveEvent(QMouseEvent *e)
1353{ 1353{
1354 KListView::contentsMouseMoveEvent(e); 1354 KListView::contentsMouseMoveEvent(e);
1355} 1355}
1356#endif 1356#endif
1357void KOListViewListView::popupMenu() 1357void KOListViewListView::popupMenu()
1358{ 1358{
1359 mPopupTimer->stop(); 1359 mPopupTimer->stop();
1360 QMouseEvent* e = new QMouseEvent( QEvent::MouseButtonPress, mEventPos ,mEventGlobalPos, RightButton , RightButton ); 1360 QMouseEvent* e = new QMouseEvent( QEvent::MouseButtonPress, mEventPos ,mEventGlobalPos, RightButton , RightButton );
1361 QApplication::postEvent( this->viewport(), e ); 1361 QApplication::postEvent( this->viewport(), e );
1362 1362
1363} 1363}
1364void KOListViewListView::contentsMousePressEvent(QMouseEvent *e) 1364void KOListViewListView::contentsMousePressEvent(QMouseEvent *e)
1365{ 1365{
1366 //qDebug("contentsMousePressEvent++++ %d %d", e->pos().y(), e->globalPos().y()); 1366 //qDebug("contentsMousePressEvent++++ %d %d", e->pos().y(), e->globalPos().y());
1367 mYMousePos = mapToGlobal( (e->pos())).y(); 1367 mYMousePos = mapToGlobal( (e->pos())).y();
1368 if ( e->button() == LeftButton ) { 1368 if ( e->button() == LeftButton ) {
1369 mPopupTimer->start( 600 ); 1369 mPopupTimer->start( 600 );
1370 mEventPos = contentsToViewport(e->pos()); 1370 mEventPos = contentsToViewport(e->pos());
1371 mEventGlobalPos = e->globalPos(); 1371 mEventGlobalPos = e->globalPos();
1372 } 1372 }
1373 KListView::contentsMousePressEvent( e ); 1373 KListView::contentsMousePressEvent( e );
1374 if ( e->button() == RightButton ) { 1374 if ( e->button() == RightButton ) {
1375 QListViewItem* ci = currentItem(); 1375 QListViewItem* ci = currentItem();
1376 //clearSelection(); 1376 //clearSelection();
1377 if ( ci ) 1377 if ( ci )
1378 ci->setSelected( true ); 1378 ci->setSelected( true );
1379 } 1379 }
1380} 1380}
1381void KOListViewListView::contentsMouseReleaseEvent(QMouseEvent *e) 1381void KOListViewListView::contentsMouseReleaseEvent(QMouseEvent *e)
1382{ 1382{
1383 mPopupTimer->stop(); 1383 mPopupTimer->stop();
1384 KListView::contentsMouseReleaseEvent(e); 1384 KListView::contentsMouseReleaseEvent(e);
1385} 1385}
1386void KOListViewListView::contentsMouseMoveEvent(QMouseEvent *e) 1386void KOListViewListView::contentsMouseMoveEvent(QMouseEvent *e)
1387{ 1387{
1388 // qDebug("contentsMouseMoveEv....... "); 1388 // qDebug("contentsMouseMoveEv....... ");
1389 // qDebug("start: %d current %d ",mYMousePos , mapToGlobal( (e->pos())).y() ); 1389 // qDebug("start: %d current %d ",mYMousePos , mapToGlobal( (e->pos())).y() );
1390 int diff = mYMousePos - mapToGlobal( (e->pos())).y(); 1390 int diff = mYMousePos - mapToGlobal( (e->pos())).y();
1391 if ( diff < 0 ) diff = -diff; 1391 if ( diff < 0 ) diff = -diff;
1392 if ( diff > 15 ) 1392 if ( diff > 15 )
1393 mPopupTimer->stop(); 1393 mPopupTimer->stop();
1394 else { 1394 else {
1395 mEventPos = contentsToViewport(e->pos()); 1395 mEventPos = contentsToViewport(e->pos());
1396 mEventGlobalPos = e->globalPos(); 1396 mEventGlobalPos = e->globalPos();
1397 } 1397 }
1398 KListView::contentsMouseMoveEvent(e); 1398 KListView::contentsMouseMoveEvent(e);
1399} 1399}
1400 1400
1401#define protected public 1401#define protected public
1402#include <qheader.h> 1402#include <qheader.h>
1403#undef protected 1403#undef protected
1404void KOListViewListView::printList() 1404void KOListViewListView::printList()
1405{ 1405{
1406#ifdef DESKTOP_VERSION 1406#ifdef DESKTOP_VERSION
1407 KOPrintPrefs pp ( this ); 1407 KOPrintPrefs pp ( this );
1408 if (!pp.exec() ) 1408 if (!pp.exec() )
1409 return; 1409 return;
1410 int scaleval = pp.printMode() ; 1410 int scaleval = pp.printMode() ;
1411 1411
1412 QPrinter printer; 1412 QPrinter printer;
1413 if (!printer.setup() ) 1413 if (!printer.setup() )
1414 return; 1414 return;
1415 clearSelection (); 1415 clearSelection ();
1416 QPainter p; 1416 QPainter p;
1417 p.begin ( &printer ); 1417 p.begin ( &printer );
1418 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer ); 1418 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer );
1419 float dx, dy; 1419 float dx, dy;
1420 int wid = (m.width() * 9)/10; 1420 int wid = (m.width() * 9)/10;
1421 dx = (float) wid/(float)contentsWidth (); 1421 dx = (float) wid/(float)contentsWidth ();
1422 dy = (float)(m.height()) / (float)contentsHeight (); 1422 dy = (float)(m.height()) / (float)contentsHeight ();
1423 float scale; 1423 float scale;
1424 // scale to fit the width or height of the paper 1424 // scale to fit the width or height of the paper
1425 if ( dx < dy ) 1425 if ( dx < dy )
1426 scale = dx; 1426 scale = dx;
1427 else 1427 else
1428 scale = dy; 1428 scale = dy;
1429 1429
1430 p.translate( m.width()/10,m.width()/10 ); 1430 p.translate( m.width()/10,m.width()/10 );
1431 if ( scaleval == 2 || scaleval == 1 && scale < 1.0 ) { 1431 if ( scaleval == 2 || scaleval == 1 && scale < 1.0 ) {
1432 p.scale( scale, scale ); 1432 p.scale( scale, scale );
1433 } 1433 }
1434 1434
1435 int cou = header()->count(); 1435 int cou = header()->count();
1436 int iii; 1436 int iii;
1437 QRect rect ( 0,0,0, header()->height()); 1437 QRect rect ( 0,0,0, header()->height());
1438 for ( iii = 0; iii < cou; ++iii ) { 1438 for ( iii = 0; iii < cou; ++iii ) {
1439 rect.setLeft ( header()->sectionPos( iii ) ); 1439 rect.setLeft ( header()->sectionPos( iii ) );
1440 rect.setRight ( header()->sectionPos( iii ) + header()->sectionSize (iii)); 1440 rect.setRight ( header()->sectionPos( iii ) + header()->sectionSize (iii));
1441 header()->paintSection ( & p, header()->mapToIndex (iii), rect ); 1441 header()->paintSection ( & p, header()->mapToIndex (iii), rect );
1442 } 1442 }
1443 p.translate( 0, header()->height()); 1443 p.translate( 0, header()->height());
1444 drawContentsOffset ( &p, 0,0, 0,0, contentsWidth (), contentsHeight () ); 1444 drawContentsOffset ( &p, 0,0, 0,0, contentsWidth (), contentsHeight () );
1445 p.end(); 1445 p.end();
1446#endif 1446#endif
1447} 1447}
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp
index 498d9b0..eea9a4d 100644
--- a/korganizer/komonthview.cpp
+++ b/korganizer/komonthview.cpp
@@ -1,2324 +1,2326 @@
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 19
20#include <qpopupmenu.h> 20#include <qpopupmenu.h>
21#include <qfont.h> 21#include <qfont.h>
22#include <qfontmetrics.h> 22#include <qfontmetrics.h>
23#include <qkeycode.h> 23#include <qkeycode.h>
24#include <qhbox.h> 24#include <qhbox.h>
25#include <qvbox.h> 25#include <qvbox.h>
26#include <qwidgetstack.h> 26#include <qwidgetstack.h>
27#include <qpushbutton.h> 27#include <qpushbutton.h>
28#include <qtooltip.h> 28#include <qtooltip.h>
29#include <qpainter.h> 29#include <qpainter.h>
30#include <qtimer.h> 30#include <qtimer.h>
31#include <qwhatsthis.h> 31#include <qwhatsthis.h>
32#ifndef DESKTOP_VERSION 32#ifndef DESKTOP_VERSION
33#include <qpe/qpeapplication.h> 33#include <qpe/qpeapplication.h>
34#else 34#else
35#include <qapplication.h> 35#include <qapplication.h>
36#endif 36#endif
37 37
38#include <kdebug.h> 38#include <kdebug.h>
39#include <klocale.h> 39#include <klocale.h>
40#include <kglobal.h> 40#include <kglobal.h>
41#include <kconfig.h> 41#include <kconfig.h>
42#include <kiconloader.h> 42#include <kiconloader.h>
43 43
44#include <kcalendarsystem.h> 44#include <kcalendarsystem.h>
45 45
46#ifndef KORG_NOPRINTER 46#ifndef KORG_NOPRINTER
47#include "calprinter.h" 47#include "calprinter.h"
48#endif 48#endif
49#include "koprefs.h" 49#include "koprefs.h"
50#ifndef KORG_NOPLUGINS 50#ifndef KORG_NOPLUGINS
51#include "kocore.h" 51#include "kocore.h"
52#endif 52#endif
53#include "koglobals.h" 53#include "koglobals.h"
54#include <libkcal/kincidenceformatter.h> 54#include <libkcal/kincidenceformatter.h>
55 55
56#include "komonthview.h" 56#include "komonthview.h"
57 57
58#define PIXMAP_SIZE 5 58#define PIXMAP_SIZE 5
59#ifdef DESKTOP_VERSION 59#ifdef DESKTOP_VERSION
60QToolTipGroup *MonthViewCell::mToolTipGroup = 0; 60QToolTipGroup *MonthViewCell::mToolTipGroup = 0;
61#endif 61#endif
62class KNOWhatsThis :public QWhatsThis 62class KNOWhatsThis :public QWhatsThis
63{ 63{
64public: 64public:
65 KNOWhatsThis( KNoScrollListBox* sbox ) : QWhatsThis( sbox ), _wid( sbox) { }; 65 KNOWhatsThis( KNoScrollListBox* sbox ) : QWhatsThis( sbox ), _wid( sbox) { };
66 //~KNOWhatsThis( ) {qDebug("~KNOWhatsThis( ) "); }; 66 //~KNOWhatsThis( ) {qDebug("~KNOWhatsThis( ) "); };
67 67
68protected: 68protected:
69 virtual QString text( const QPoint& p) 69 virtual QString text( const QPoint& p)
70 { 70 {
71 return _wid->getWhatsThisText(p) ; 71 return _wid->getWhatsThisText(p) ;
72 }; 72 };
73private: 73private:
74 KNoScrollListBox* _wid; 74 KNoScrollListBox* _wid;
75 75
76}; 76};
77 77
78 78
79KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name) 79KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name)
80 : QListBox(parent, name, WRepaintNoErase) 80 : QListBox(parent, name, WRepaintNoErase)
81{ 81{
82#ifndef DESKTOP_VERSION 82#ifndef DESKTOP_VERSION
83 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 83 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
84#endif 84#endif
85 mWT = new KNOWhatsThis(this); 85 mWT = new KNOWhatsThis(this);
86 resetOnFocusIn = true; 86 resetOnFocusIn = true;
87 setVScrollBarMode(QScrollView::AlwaysOff); 87 setVScrollBarMode(QScrollView::AlwaysOff);
88 setHScrollBarMode(QScrollView::AlwaysOff); 88 setHScrollBarMode(QScrollView::AlwaysOff);
89} 89}
90KNoScrollListBox::~KNoScrollListBox() 90KNoScrollListBox::~KNoScrollListBox()
91{ 91{
92#if QT_VERSION >= 0x030000 92#if QT_VERSION >= 0x030000
93 93
94#else 94#else
95 delete mWT; 95 delete mWT;
96#endif 96#endif
97} 97}
98 98
99 99
100void KNoScrollListBox::focusInEvent ( QFocusEvent * e ) 100void KNoScrollListBox::focusInEvent ( QFocusEvent * e )
101{ 101{
102 QListBox::focusInEvent ( e ); 102 QListBox::focusInEvent ( e );
103 if ( count() ){ 103 if ( count() ){
104 int ci = currentItem(); 104 int ci = currentItem();
105 if ( ci < 0 ) ci = 0; 105 if ( ci < 0 ) ci = 0;
106 106
107 setCurrentItem( ci ); 107 setCurrentItem( ci );
108 setSelected ( ci, true ); 108 setSelected ( ci, true );
109 emit highlighted( item ( ci ) ); 109 emit highlighted( item ( ci ) );
110 110
111 resetOnFocusIn = true; 111 resetOnFocusIn = true;
112 112
113 if ( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) { 113 if ( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) {
114 QListBoxItem *fi = firstItem (); 114 QListBoxItem *fi = firstItem ();
115 if (fi ) { 115 if (fi ) {
116 int ihei = fi->height( this ); 116 int ihei = fi->height( this );
117 int hei = numRows () * ihei; 117 int hei = numRows () * ihei;
118 if ( hei < height() - horizontalScrollBar()->height () ) { 118 if ( hei < height() - horizontalScrollBar()->height () ) {
119 setVScrollBarMode(QScrollView::AlwaysOff); 119 setVScrollBarMode(QScrollView::AlwaysOff);
120 } 120 }
121 else 121 else
122 setVScrollBarMode(QScrollView::Auto); 122 setVScrollBarMode(QScrollView::Auto);
123 if ( ihei *3 > height() ) { 123 if ( ihei *3 > height() ) {
124 setHScrollBarMode(QScrollView::AlwaysOff); 124 setHScrollBarMode(QScrollView::AlwaysOff);
125 } 125 }
126 else { 126 else {
127 setHScrollBarMode(QScrollView::Auto); 127 setHScrollBarMode(QScrollView::Auto);
128 } 128 }
129 } else { 129 } else {
130 setVScrollBarMode(QScrollView::Auto); 130 setVScrollBarMode(QScrollView::Auto);
131 setHScrollBarMode(QScrollView::Auto); 131 setHScrollBarMode(QScrollView::Auto);
132 } 132 }
133 } 133 }
134 } 134 }
135} 135}
136void KNoScrollListBox::focusOutEvent ( QFocusEvent * e ) 136void KNoScrollListBox::focusOutEvent ( QFocusEvent * e )
137{ 137{
138 int i = currentItem (); 138 int i = currentItem ();
139 if ( i >= 0 ) { 139 if ( i >= 0 ) {
140 setSelected ( i, false ); 140 setSelected ( i, false );
141 } 141 }
142 QListBox::focusOutEvent ( e ); 142 QListBox::focusOutEvent ( e );
143 setVScrollBarMode(QScrollView::AlwaysOff); 143 setVScrollBarMode(QScrollView::AlwaysOff);
144 setHScrollBarMode(QScrollView::AlwaysOff); 144 setHScrollBarMode(QScrollView::AlwaysOff);
145 emit highlightIncidence( 0, (MonthViewCell*)this, 0 ); 145 emit highlightIncidence( 0, (MonthViewCell*)this, 0 );
146} 146}
147 147
148QString KNoScrollListBox::getWhatsThisText(QPoint p) 148QString KNoScrollListBox::getWhatsThisText(QPoint p)
149{ 149{
150 QListBoxItem* item = itemAt ( p ); 150 QListBoxItem* item = itemAt ( p );
151 if ( ! item ) { 151 if ( ! item ) {
152 return i18n("Click in the cell\nto add an event!"); 152 return i18n("Click in the cell\nto add an event!");
153 } 153 }
154 return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence(), 154 return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence(),
155 KOPrefs::instance()->mWTshowDetails, 155 KOPrefs::instance()->mWTshowDetails,
156 KOPrefs::instance()->mWTshowCreated, 156 KOPrefs::instance()->mWTshowCreated,
157 KOPrefs::instance()->mWTshowChanged); 157 KOPrefs::instance()->mWTshowChanged);
158} 158}
159void KNoScrollListBox::keyPressEvent(QKeyEvent *e) 159void KNoScrollListBox::keyPressEvent(QKeyEvent *e)
160{ 160{
161 //qDebug("KNoScrollListBox::keyPressEvent "); 161 //qDebug("KNoScrollListBox::keyPressEvent ");
162 switch(e->key()) { 162 switch(e->key()) {
163 case Key_Right: 163 case Key_Right:
164 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 164 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
165 { 165 {
166 e->ignore(); 166 e->ignore();
167 return; 167 return;
168 } 168 }
169 scrollBy(10,0); 169 scrollBy(10,0);
170 break; 170 break;
171 case Key_Left: 171 case Key_Left:
172 if (e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 172 if (e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
173 { 173 {
174 e->ignore(); 174 e->ignore();
175 return; 175 return;
176 } 176 }
177 scrollBy(-10,0); 177 scrollBy(-10,0);
178 break; 178 break;
179 case Key_Up: 179 case Key_Up:
180 if( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { 180 if( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) {
181 e->ignore(); 181 e->ignore();
182 break; 182 break;
183 } 183 }
184 if ( count() ) { 184 if ( count() ) {
185 if ( currentItem() == 0 ) { 185 if ( currentItem() == 0 ) {
186 emit prevCell(); 186 emit prevCell();
187 } else { 187 } else {
188 setCurrentItem((currentItem()+count()-1)%count()); 188 setCurrentItem((currentItem()+count()-1)%count());
189 if(!itemVisible(currentItem())) { 189 if(!itemVisible(currentItem())) {
190 if((unsigned int) currentItem() == (count()-1)) { 190 if((unsigned int) currentItem() == (count()-1)) {
191 setTopItem(currentItem()-numItemsVisible()+1); 191 setTopItem(currentItem()-numItemsVisible()+1);
192 } else { 192 } else {
193 setTopItem(topItem()-1); 193 setTopItem(topItem()-1);
194 } 194 }
195 } 195 }
196 } 196 }
197 } 197 }
198 break; 198 break;
199 case Key_Down: 199 case Key_Down:
200 if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { 200 if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) {
201 e->ignore(); 201 e->ignore();
202 break; 202 break;
203 } 203 }
204 if ( count () ) { 204 if ( count () ) {
205 if ( ((uint)currentItem()+1) == count () ) { 205 if ( ((uint)currentItem()+1) == count () ) {
206 emit nextCell(); 206 emit nextCell();
207 } else { 207 } else {
208 setCurrentItem((currentItem()+1)%count()); 208 setCurrentItem((currentItem()+1)%count());
209 if(!itemVisible(currentItem())) { 209 if(!itemVisible(currentItem())) {
210 if(currentItem() == 0) { 210 if(currentItem() == 0) {
211 setTopItem(0); 211 setTopItem(0);
212 } else { 212 } else {
213 setTopItem(topItem()+1); 213 setTopItem(topItem()+1);
214 } 214 }
215 } 215 }
216 } 216 }
217 } 217 }
218 break; 218 break;
219 case Key_I: 219 case Key_I:
220 QTimer::singleShot( 1, this, SLOT ( oneDown() ) ); 220 QTimer::singleShot( 1, this, SLOT ( oneDown() ) );
221 e->ignore(); 221 e->ignore();
222 break; 222 break;
223 case Key_Return: 223 case Key_Return:
224 case Key_Enter: 224 case Key_Enter:
225 { 225 {
226 if ( currentItem() >= 0 ) { 226 if ( currentItem() >= 0 ) {
227 emit doubleClicked( item( currentItem() ) ); 227 emit doubleClicked( item( currentItem() ) );
228 e->accept(); 228 e->accept();
229 } else { 229 } else {
230 e->ignore(); 230 e->ignore();
231 } 231 }
232 } 232 }
233 break; 233 break;
234 case Key_Shift: 234 case Key_Shift:
235 emit shiftDown(); 235 emit shiftDown();
236 break; 236 break;
237 default: 237 default:
238 e->ignore(); 238 e->ignore();
239 break; 239 break;
240 } 240 }
241} 241}
242 242
243void KNoScrollListBox::oneDown() 243void KNoScrollListBox::oneDown()
244{ 244{
245 if ( count () ) { 245 if ( count () ) {
246 if ( ((uint)currentItem()+1) == count () ) { 246 if ( ((uint)currentItem()+1) == count () ) {
247 emit nextCell(); 247 emit nextCell();
248 } else { 248 } else {
249 resetOnFocusIn = false; 249 resetOnFocusIn = false;
250 setCurrentItem((currentItem()+1)%count()); 250 setCurrentItem((currentItem()+1)%count());
251 if(!itemVisible(currentItem())) { 251 if(!itemVisible(currentItem())) {
252 if(currentItem() == 0) { 252 if(currentItem() == 0) {
253 setTopItem(0); 253 setTopItem(0);
254 } else { 254 } else {
255 setTopItem(topItem()+1); 255 setTopItem(topItem()+1);
256 } 256 }
257 } 257 }
258 } 258 }
259 } 259 }
260} 260}
261void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e) 261void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e)
262{ 262{
263 switch(e->key()) { 263 switch(e->key()) {
264 case Key_Shift: 264 case Key_Shift:
265 emit shiftUp(); 265 emit shiftUp();
266 break; 266 break;
267 default: 267 default:
268 break; 268 break;
269 } 269 }
270} 270}
271 271
272void KNoScrollListBox::mousePressEvent(QMouseEvent *e) 272void KNoScrollListBox::mousePressEvent(QMouseEvent *e)
273{ 273{
274 QListBox::mousePressEvent(e); 274 QListBox::mousePressEvent(e);
275 275
276 if(e->button() == RightButton) { 276 if(e->button() == RightButton) {
277 emit rightClick(); 277 emit rightClick();
278 } 278 }
279} 279}
280 280
281MonthViewItem::MonthViewItem( Incidence *incidence, const QString & s) 281MonthViewItem::MonthViewItem( Incidence *incidence, const QString & s)
282 : QListBoxItem() 282 : QListBoxItem()
283{ 283{
284 mblockRepaint = true; 284 mblockRepaint = true;
285 isWeekItem = KOPrefs::instance()->mMonthViewWeek; 285 isWeekItem = KOPrefs::instance()->mMonthViewWeek;
286 recycle( incidence, s ); 286 recycle( incidence, s );
287} 287}
288void MonthViewItem::recycle( Incidence *incidence, const QString & s) 288void MonthViewItem::recycle( Incidence *incidence, const QString & s)
289{ 289{
290 mDisplayHighlighted = false; 290 mDisplayHighlighted = false;
291 setText( s ); 291 setText( s );
292 mMultiday = 0; 292 mMultiday = 0;
293 mIncidence = incidence; 293 mIncidence = incidence;
294 mRecur = false; 294 mRecur = false;
295 mAlarm = false; 295 mAlarm = false;
296 mReply = false; 296 mReply = false;
297 mInfo = false; 297 mInfo = false;
298 mdayPos = 0; 298 mdayPos = 0;
299} 299}
300 300
301bool MonthViewItem::setHighlightedFalse() 301bool MonthViewItem::setHighlightedFalse()
302{ 302{
303 if ( !mDisplayHighlighted ) 303 if ( !mDisplayHighlighted )
304 return false; 304 return false;
305 mDisplayHighlighted = false; 305 mDisplayHighlighted = false;
306 return true; 306 return true;
307} 307}
308 308
309bool MonthViewItem::setHighlighted( Incidence * inc ) 309bool MonthViewItem::setHighlighted( Incidence * inc )
310{ 310{
311 if ( inc == mIncidence ) { 311 if ( inc == mIncidence ) {
312 if ( mDisplayHighlighted ) 312 if ( mDisplayHighlighted )
313 return false; 313 return false;
314 mDisplayHighlighted = true; 314 mDisplayHighlighted = true;
315 return true; 315 return true;
316 } else { 316 } else {
317 if ( !mDisplayHighlighted ) 317 if ( !mDisplayHighlighted )
318 return false; 318 return false;
319 mDisplayHighlighted = false; 319 mDisplayHighlighted = false;
320 return true; 320 return true;
321 } 321 }
322 return false; 322 return false;
323} 323}
324void MonthViewItem::paint(QPainter *p) 324void MonthViewItem::paint(QPainter *p)
325{ 325{
326 if ( mblockRepaint || !mIncidence ) { 326 if ( mblockRepaint || !mIncidence ) {
327 return; 327 return;
328 } 328 }
329#if QT_VERSION >= 0x030000 329#if QT_VERSION >= 0x030000
330 bool sel = isSelected(); 330 bool sel = isSelected();
331#else 331#else
332 bool sel = selected(); 332 bool sel = selected();
333#endif 333#endif
334 int heihei = height( listBox () ); 334 int heihei = height( listBox () );
335 int x = 1; 335 int x = 1;
336 if (KOPrefs::instance()->mMonthViewUsesCategoryColor || mDisplayHighlighted || sel ) 336 if (KOPrefs::instance()->mMonthViewUsesCategoryColor || mDisplayHighlighted || sel )
337 { 337 {
338 338
339 p->setBackgroundColor( palette().color( QPalette::Normal, \ 339 p->setBackgroundColor( palette().color( QPalette::Normal, \
340 sel ||mDisplayHighlighted ? QColorGroup::Highlight : QColorGroup::Background ) ); 340 sel ||mDisplayHighlighted ? QColorGroup::Highlight : QColorGroup::Background ) );
341 p->eraseRect( 0, 0, listBox()->maxItemWidth(), heihei ); 341 p->eraseRect( 0, 0, listBox()->maxItemWidth(), heihei );
342 } 342 }
343 343
344 //int y = 3;//(height() - mRecurPixmap.height()) /2; 344 //int y = 3;//(height() - mRecurPixmap.height()) /2;
345 int size = PIXMAP_SIZE; 345 int size = PIXMAP_SIZE;
346 if ( QApplication::desktop()->width() < 300 ) 346 if ( QApplication::desktop()->width() < 300 )
347 size = 3; 347 size = 3;
348 int y = (heihei - size -1 ) /2; 348 int y = (heihei - size -1 ) /2;
349 349
350 if ( mIncidence->calID() > 1 ) { 350 if ( mIncidence->calID() > 1 ) {
351 p->fillRect ( x, y-2,size,size+4, KOPrefs::instance()->defaultColor( mIncidence->calID() ) ); 351 p->fillRect ( x, y-2,size,size+4, KOPrefs::instance()->defaultColor( mIncidence->calID() ) );
352 p->drawRect ( x, y-2,size,size+4); 352 p->drawRect ( x, y-2,size,size+4);
353 x += size + 1; 353 x += size + 1;
354 } 354 }
355 if ( KOPrefs::instance()->mMonthShowIcons ) { 355 if ( KOPrefs::instance()->mMonthShowIcons ) {
356 if ( mInfo ) { 356 if ( mInfo ) {
357 p->fillRect ( x, y,size,size, Qt::darkGreen ); 357 p->fillRect ( x, y,size,size, Qt::darkGreen );
358 x += size + 1; 358 x += size + 1;
359 } 359 }
360 if ( mRecur ) { 360 if ( mRecur ) {
361 p->fillRect ( x, y,size,size, Qt::blue ); 361 p->fillRect ( x, y,size,size, Qt::blue );
362 x += size + 1; 362 x += size + 1;
363 } 363 }
364 if ( mAlarm ) { 364 if ( mAlarm ) {
365 p->fillRect ( x, y,size,size, Qt::red ); 365 p->fillRect ( x, y,size,size, Qt::red );
366 x += size + 1; 366 x += size + 1;
367 } 367 }
368 if ( mReply ) { 368 if ( mReply ) {
369 p->fillRect ( x, y,size,size, Qt::yellow ); 369 p->fillRect ( x, y,size,size, Qt::yellow );
370 x += size + 1; 370 x += size + 1;
371 } 371 }
372 } 372 }
373 373
374 374
375 375
376 376
377 if ( sel ) p->setPen( Qt::white ); 377 if ( sel ) p->setPen( Qt::white );
378 else p->setPen( palette().color( QPalette::Normal,QColorGroup::Foreground ) ); 378 else p->setPen( palette().color( QPalette::Normal,QColorGroup::Foreground ) );
379 379
380#if 0 380#if 0
381 p->setPen( palette().color( QPalette::Normal, sel ? \ 381 p->setPen( palette().color( QPalette::Normal, sel ? \
382 QColorGroup::HighlightedText : QColorGroup::Foreground ) ); 382 QColorGroup::HighlightedText : QColorGroup::Foreground ) );
383#endif 383#endif
384 QColor textColor = p->pen().color(); 384 QColor textColor = p->pen().color();
385 385
386 386
387 if ( mMultiday ) { 387 if ( mMultiday ) {
388 int yyy = y+(size/2); 388 int yyy = y+(size/2);
389 int sizeM = size+2; 389 int sizeM = size+2;
390 p->setBrush( QBrush( textColor ) ); 390 p->setBrush( QBrush( textColor ) );
391 p->drawLine ( x+1, yyy, x +sizeM +sizeM/2-1, yyy ) ; 391 p->drawLine ( x+1, yyy, x +sizeM +sizeM/2-1, yyy ) ;
392 if ( mMultiday == 2 || mMultiday == 3 ) { 392 if ( mMultiday == 2 || mMultiday == 3 ) {
393 QPointArray pa ( 3 ); 393 QPointArray pa ( 3 );
394 pa.setPoint (0, x, yyy ); 394 pa.setPoint (0, x, yyy );
395 pa.setPoint (1, x+sizeM/2, yyy+sizeM/2 ); 395 pa.setPoint (1, x+sizeM/2, yyy+sizeM/2 );
396 pa.setPoint (2, x+sizeM/2, yyy-sizeM/2 ); 396 pa.setPoint (2, x+sizeM/2, yyy-sizeM/2 );
397 p->drawPolygon( pa ); 397 p->drawPolygon( pa );
398 } 398 }
399 if ( mMultiday == 2 || mMultiday == 1 ) { 399 if ( mMultiday == 2 || mMultiday == 1 ) {
400 QPointArray pa ( 3 ); 400 QPointArray pa ( 3 );
401 pa.setPoint (0, x+sizeM +sizeM/2, yyy ); 401 pa.setPoint (0, x+sizeM +sizeM/2, yyy );
402 pa.setPoint (1, x+sizeM, yyy+sizeM/2 ); 402 pa.setPoint (1, x+sizeM, yyy+sizeM/2 );
403 pa.setPoint (2, x+sizeM, yyy-sizeM/2 ); 403 pa.setPoint (2, x+sizeM, yyy-sizeM/2 );
404 p->drawPolygon( pa ); 404 p->drawPolygon( pa );
405 } 405 }
406 if ( mMultiday == 1 ) { 406 if ( mMultiday == 1 ) {
407 // p->fillRect ( x, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); 407 // p->fillRect ( x, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) );
408 p->drawLine ( x+1, yyy-sizeM/2, x+1, yyy+sizeM/2 ); 408 p->drawLine ( x+1, yyy-sizeM/2, x+1, yyy+sizeM/2 );
409 } 409 }
410 if ( mMultiday == 3 ) { 410 if ( mMultiday == 3 ) {
411 // p->fillRect ( x+sizeM, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); 411 // p->fillRect ( x+sizeM, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) );
412 p->drawLine ( x+sizeM +sizeM/2-1, yyy-sizeM/2, x+sizeM +sizeM/2-1, yyy+sizeM/2 ); 412 p->drawLine ( x+sizeM +sizeM/2-1, yyy-sizeM/2, x+sizeM +sizeM/2-1, yyy+sizeM/2 );
413 413
414 } 414 }
415 x += sizeM/2 + 1; 415 x += sizeM/2 + 1;
416 x += sizeM + 1; 416 x += sizeM + 1;
417 } 417 }
418 418
419 if ( mIncidence->typeID() == todoID ){ 419 if ( mIncidence->typeID() == todoID ){
420 Todo* td = ( Todo* ) mIncidence; 420 Todo* td = ( Todo* ) mIncidence;
421 if ( td->isCompleted() ) { 421 if ( td->isCompleted() ) {
422 int half = size/2; 422 int half = size/2;
423 p->drawLine ( x, heihei/2, x +half , heihei/2 +half ) ; 423 p->drawLine ( x, heihei/2, x +half , heihei/2 +half ) ;
424 p->drawLine ( x +half , heihei/2 +half , x +half+half +2 , heihei/2 -2 ) ; 424 p->drawLine ( x +half , heihei/2 +half , x +half+half +2 , heihei/2 -2 ) ;
425 x += half+half + 4; 425 x += half+half + 4;
426 426
427 } else { 427 } else {
428 int val = td->percentComplete()/20; 428 int val = td->percentComplete()/20;
429 p->fillRect ( x+1, y-2, val ,size+4,textColor ); 429 p->fillRect ( x+1, y-2, val ,size+4,textColor );
430 p->drawRect ( x, y-2,7,size+4); 430 p->drawRect ( x, y-2,7,size+4);
431 x += size + 3; 431 x += size + 3;
432 } 432 }
433 } 433 }
434 QFontMetrics fm = p->fontMetrics(); 434 QFontMetrics fm = p->fontMetrics();
435 int yPos; 435 int yPos;
436 int pmheight = size; 436 int pmheight = size;
437 if( pmheight < fm.height() ) 437 if( pmheight < fm.height() )
438 yPos = fm.ascent() + fm.leading()/2; 438 yPos = fm.ascent() + fm.leading()/2;
439 else 439 else
440 yPos = pmheight/2 - fm.height()/2 + fm.ascent(); 440 yPos = pmheight/2 - fm.height()/2 + fm.ascent();
441 441
442 if ( KOPrefs::instance()->mMonthShowTimes || isWeekItem) { 442 if ( KOPrefs::instance()->mMonthShowTimes || isWeekItem) {
443 p->drawText( x, yPos, text() ); 443 p->drawText( x, yPos, text() );
444 if ( mIncidence->cancelled() ) { 444 if ( mIncidence->cancelled() ) {
445 int wid = fm.width( text() ); 445 int wid = fm.width( text() );
446 p->drawLine( x, heihei/2 ,x+wid, heihei/2 ); 446 p->drawLine( x, heihei/2 ,x+wid, heihei/2 );
447 } 447 }
448 } else { 448 } else {
449 QString pText = text(); 449 QString pText = text();
450 if( pText.mid(2,1) == ":" ) 450 if( pText.mid(2,1) == ":" )
451 pText = pText.mid( 6 ); 451 pText = pText.mid( 6 );
452 p->drawText( x, yPos, pText ); 452 p->drawText( x, yPos, pText );
453 if ( mIncidence->cancelled() ) { 453 if ( mIncidence->cancelled() ) {
454 int wid = fm.width( pText ); 454 int wid = fm.width( pText );
455 p->drawLine( x, heihei/2 ,x+wid, heihei/2 ); 455 p->drawLine( x, heihei/2 ,x+wid, heihei/2 );
456 } 456 }
457 } 457 }
458} 458}
459 459
460int MonthViewItem::height(const QListBox *lb) const 460int MonthViewItem::height(const QListBox *lb) const
461{ 461{
462 int ret = 10; 462 int ret = 10;
463 if ( lb ) 463 if ( lb )
464 ret = lb->fontMetrics().lineSpacing()+1; 464 ret = lb->fontMetrics().lineSpacing()+1;
465 return ret; 465 return ret;
466} 466}
467 467
468int MonthViewItem::width(const QListBox *lb) const 468int MonthViewItem::width(const QListBox *lb) const
469{ 469{
470 if( KOPrefs::instance()->mEnableMonthScroll || isWeekItem ) { 470 if( KOPrefs::instance()->mEnableMonthScroll || isWeekItem ) {
471 int size = PIXMAP_SIZE; 471 int size = PIXMAP_SIZE;
472 if ( QApplication::desktop()->width() < 300 ) 472 if ( QApplication::desktop()->width() < 300 )
473 size = 3; 473 size = 3;
474 int x = 1; 474 int x = 1;
475 if ( KOPrefs::instance()->mMonthShowIcons ) { 475 if ( KOPrefs::instance()->mMonthShowIcons ) {
476 if ( mInfo ) { 476 if ( mInfo ) {
477 x += size + 1; 477 x += size + 1;
478 } 478 }
479 if( mRecur ) { 479 if( mRecur ) {
480 x += size+1; 480 x += size+1;
481 } 481 }
482 if( mAlarm ) { 482 if( mAlarm ) {
483 x += size+1; 483 x += size+1;
484 } 484 }
485 if( mReply ) { 485 if( mReply ) {
486 x += size+1; 486 x += size+1;
487 } 487 }
488 } 488 }
489 if( mMultiday ) { 489 if( mMultiday ) {
490 x += size+1+2+size/2; 490 x += size+1+2+size/2;
491 } 491 }
492 return( x + lb->fontMetrics().width( text() ) + 1 ); 492 return( x + lb->fontMetrics().width( text() ) + 1 );
493 } 493 }
494 if ( ! lb ) 494 if ( ! lb )
495 return 10; 495 return 10;
496 return lb->width(); 496 return lb->width();
497} 497}
498 498
499 499
500MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par ) 500MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par )
501 : KNoScrollListBox( par ), 501 : KNoScrollListBox( par ),
502 mMonthView( parent ) 502 mMonthView( parent )
503{ 503{
504 //QVBoxLayout *topLayout = new QVBoxLayout( this ); 504 //QVBoxLayout *topLayout = new QVBoxLayout( this );
505 currentPalette = 0; 505 currentPalette = 0;
506 // mLabel = new QLabel( this );QPushButton 506 // mLabel = new QLabel( this );QPushButton
507 mLabel = new QPushButton( this ); 507 mLabel = new QPushButton( this );
508 //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain ); 508 //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain );
509 //mLabel->setLineWidth( 1 ); 509 //mLabel->setLineWidth( 1 );
510 //mLabel->setAlignment( AlignCenter ); 510 //mLabel->setAlignment( AlignCenter );
511 mLabel->setFlat( true ); 511 mLabel->setFlat( true );
512 mLabel->setFocusPolicy(NoFocus); 512 mLabel->setFocusPolicy(NoFocus);
513 //mItemList = new KNoScrollListBox( this ); 513 //mItemList = new KNoScrollListBox( this );
514 setMinimumSize( 10, 10 ); 514 setMinimumSize( 10, 10 );
515 setFrameStyle( QFrame::Panel | QFrame::Plain ); 515 setFrameStyle( QFrame::Panel | QFrame::Plain );
516 setLineWidth( 1 ); 516 setLineWidth( 1 );
517 //topLayout->addWidget( mItemList ); 517 //topLayout->addWidget( mItemList );
518 mLabel->raise(); 518 mLabel->raise();
519 // QColor( 0,0,255 ) QColor( 160,1600,255 ) 519 // QColor( 0,0,255 ) QColor( 160,1600,255 )
520 mStandardPalette = palette(); 520 mStandardPalette = palette();
521 mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) ); 521 mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) );
522 522
523 enableScrollBars( false ); 523 enableScrollBars( false );
524 updateConfig(); 524 updateConfig();
525 //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() )); 525 //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() ));
526 connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() )); 526 connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() ));
527 connect( this , SIGNAL( doubleClicked( QListBoxItem *) ), 527 connect( this , SIGNAL( doubleClicked( QListBoxItem *) ),
528 SLOT( defaultAction( QListBoxItem * ) ) ); 528 SLOT( defaultAction( QListBoxItem * ) ) );
529 connect( this, SIGNAL( rightButtonPressed( QListBoxItem *, 529 connect( this, SIGNAL( rightButtonPressed( QListBoxItem *,
530 const QPoint &) ), 530 const QPoint &) ),
531 SLOT( contextMenu( QListBoxItem * ) ) ); 531 SLOT( contextMenu( QListBoxItem * ) ) );
532 connect( this, SIGNAL( highlighted( QListBoxItem *) ), 532 connect( this, SIGNAL( highlighted( QListBoxItem *) ),
533 SLOT( selection( QListBoxItem * ) ) ); 533 SLOT( selection( QListBoxItem * ) ) );
534 534
535 /* 535 /*
536 connect( this, SIGNAL( clicked( QListBoxItem * ) ), 536 connect( this, SIGNAL( clicked( QListBoxItem * ) ),
537 SLOT( selection( QListBoxItem * ) ) ); 537 SLOT( selection( QListBoxItem * ) ) );
538 */ 538 */
539} 539}
540#ifdef DESKTOP_VERSION 540#ifdef DESKTOP_VERSION
541QToolTipGroup *MonthViewCell::toolTipGroup() 541QToolTipGroup *MonthViewCell::toolTipGroup()
542{ 542{
543 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); 543 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0);
544 return mToolTipGroup; 544 return mToolTipGroup;
545} 545}
546#endif 546#endif
547 547
548void MonthViewCell::setDate( const QDate &date ) 548void MonthViewCell::setDate( const QDate &date )
549{ 549{
550 // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl; 550 // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl;
551 mDate = date; 551 mDate = date;
552 552
553 553
554 554
555 //resizeEvent( 0 ); 555 //resizeEvent( 0 );
556} 556}
557 557
558QDate MonthViewCell::date() const 558QDate MonthViewCell::date() const
559{ 559{
560 return mDate; 560 return mDate;
561} 561}
562 562
563void MonthViewCell::setPrimary( bool primary ) 563void MonthViewCell::setPrimary( bool primary )
564{ 564{
565 mPrimary = primary; 565 mPrimary = primary;
566 //setMyPalette(); 566 //setMyPalette();
567} 567}
568void MonthViewCell::setMyPalette() 568void MonthViewCell::setMyPalette()
569{ 569{
570 570
571 if ( mHoliday) { 571 if ( mHoliday) {
572 if ( currentPalette == 1 ) return; 572 if ( currentPalette == 1 ) return;
573 mLabel->setPalette( QPalette ( mHolidayPalette.color( QPalette::Normal,QColorGroup::Base),mHolidayPalette.color(QPalette::Normal,QColorGroup::Base ) )); 573 mLabel->setPalette( QPalette ( mHolidayPalette.color( QPalette::Normal,QColorGroup::Base),mHolidayPalette.color(QPalette::Normal,QColorGroup::Base ) ));
574 setPalette( mHolidayPalette ); 574 setPalette( mHolidayPalette );
575 //mLabel->setPalette( mHolidayPalette ); 575 //mLabel->setPalette( mHolidayPalette );
576 currentPalette = 1; 576 currentPalette = 1;
577 577
578 } else { 578 } else {
579 if ( mPrimary ) { 579 if ( mPrimary ) {
580 if ( currentPalette == 2 ) return; 580 if ( currentPalette == 2 ) return;
581 mLabel->setPalette( QPalette ( mPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) )); 581 mLabel->setPalette( QPalette ( mPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) ));
582 //mLabel->setPalette( mPrimaryPalette ); 582 //mLabel->setPalette( mPrimaryPalette );
583 setPalette( mPrimaryPalette ); 583 setPalette( mPrimaryPalette );
584 currentPalette = 2; 584 currentPalette = 2;
585 585
586 } else { 586 } else {
587 if ( currentPalette == 3 ) return; 587 if ( currentPalette == 3 ) return;
588 setPalette( mNonPrimaryPalette ); 588 setPalette( mNonPrimaryPalette );
589 mLabel->setPalette( QPalette ( mNonPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mNonPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) )); 589 mLabel->setPalette( QPalette ( mNonPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mNonPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) ));
590 //mLabel->setPalette( mNonPrimaryPalette );; 590 //mLabel->setPalette( mNonPrimaryPalette );;
591 currentPalette = 3; 591 currentPalette = 3;
592 } 592 }
593 } 593 }
594 //QPalette pal = palette(); 594 //QPalette pal = palette();
595 595
596 //mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) )); 596 //mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) ));
597} 597}
598QPalette MonthViewCell::getPalette () 598QPalette MonthViewCell::getPalette ()
599{ 599{
600 if ( !KOPrefs::instance()->mMonthViewUsesDayColors ) 600 if ( !KOPrefs::instance()->mMonthViewUsesDayColors )
601 return mStandardPalette; 601 return mStandardPalette;
602 if ( mHoliday) { 602 if ( mHoliday) {
603 return mHolidayPalette ; 603 return mHolidayPalette ;
604 } else { 604 } else {
605 if ( mPrimary ) { 605 if ( mPrimary ) {
606 return mPrimaryPalette ; 606 return mPrimaryPalette ;
607 } 607 }
608 } 608 }
609 return mNonPrimaryPalette; 609 return mNonPrimaryPalette;
610} 610}
611bool MonthViewCell::isPrimary() const 611bool MonthViewCell::isPrimary() const
612{ 612{
613 return mPrimary; 613 return mPrimary;
614} 614}
615 615
616void MonthViewCell::setHoliday( bool holiday ) 616void MonthViewCell::setHoliday( bool holiday )
617{ 617{
618 mHoliday = holiday; 618 mHoliday = holiday;
619 //setMyPalette(); 619 //setMyPalette();
620} 620}
621 621
622void MonthViewCell::setHoliday( const QString &holiday ) 622void MonthViewCell::setHoliday( const QString &holiday )
623{ 623{
624 mHolidayString = holiday; 624 mHolidayString = holiday;
625 625
626 if ( !holiday.isEmpty() ) { 626 if ( !holiday.isEmpty() ) {
627 setHoliday( true ); 627 setHoliday( true );
628 } 628 }
629} 629}
630 630
631void MonthViewCell::startUpdateCell() 631void MonthViewCell::startUpdateCell()
632{ 632{
633 blockSignals( true ); 633 blockSignals( true );
634 mdayCount = 0; 634 mdayCount = 0;
635 setFocusPolicy(NoFocus); 635 setFocusPolicy(NoFocus);
636 if ( !mMonthView->isUpdatePossible() ) 636 if ( !mMonthView->isUpdatePossible() )
637 return; 637 return;
638 MonthViewItem *mitem = (MonthViewItem*) firstItem (); 638 MonthViewItem *mitem = (MonthViewItem*) firstItem ();
639 while ( mitem ) { 639 while ( mitem ) {
640 mitem->setBlockRepaint( true ); 640 mitem->setBlockRepaint( true );
641 mitem = (MonthViewItem *)mitem->next(); 641 mitem = (MonthViewItem *)mitem->next();
642 } 642 }
643 if ( mAvailItemList.count() > 20 ) { 643 if ( mAvailItemList.count() > 20 ) {
644 mAvailItemList.setAutoDelete( true ); 644 mAvailItemList.setAutoDelete( true );
645 mAvailItemList.clear(); 645 mAvailItemList.clear();
646 mAvailItemList.setAutoDelete( false ); 646 mAvailItemList.setAutoDelete( false );
647 clear(); 647 clear();
648 } 648 }
649 649
650 setPrimary( mDate.month()%2 ); 650 setPrimary( mDate.month()%2 );
651 setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays); 651 setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays);
652 if ( mDate == QDate::currentDate() ) { 652 if ( mDate == QDate::currentDate() ) {
653 setLineWidth( 3 ); 653 setLineWidth( 3 );
654 } else { 654 } else {
655 setLineWidth( 1 ); 655 setLineWidth( 1 );
656 } 656 }
657 MonthViewItem* CurrentAvailItem = (MonthViewItem*) firstItem (); 657 MonthViewItem* CurrentAvailItem = (MonthViewItem*) firstItem ();
658 //clear(); 658 //clear();
659 while ( CurrentAvailItem ) { 659 while ( CurrentAvailItem ) {
660 MonthViewItem *item = CurrentAvailItem; 660 MonthViewItem *item = CurrentAvailItem;
661 //item->setHighlightedFalse(); 661 //item->setHighlightedFalse();
662 item->recycle( 0, ""); 662 item->recycle( 0, "");
663 CurrentAvailItem = (MonthViewItem *)item->next(); 663 CurrentAvailItem = (MonthViewItem *)item->next();
664 mAvailItemList.append( item ); 664 mAvailItemList.append( item );
665 takeItem ( item ); 665 takeItem ( item );
666 } 666 }
667 667
668#ifdef DESKTOP_VERSION 668#ifdef DESKTOP_VERSION
669 QToolTip::remove(this); 669 QToolTip::remove(this);
670#endif 670#endif
671 mToolTip.clear(); 671 mToolTip.clear();
672 //qApp->processEvents(); 672 //qApp->processEvents();
673#if 0 673#if 0
674 if ( !mHolidayString.isEmpty() ) { 674 if ( !mHolidayString.isEmpty() ) {
675 MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString ); 675 MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString );
676 item->setPalette( mHolidayPalette ); 676 item->setPalette( mHolidayPalette );
677 insertItem( item ); 677 insertItem( item );
678 mToolTip.append ( mHolidayString ); 678 mToolTip.append ( mHolidayString );
679 } 679 }
680#endif 680#endif
681} 681}
682 682
683int MonthViewCell::insertEvent(Event *event) 683int MonthViewCell::insertEvent(Event *event)
684{ 684{
685 bool useToolTips = true; 685 bool useToolTips = true;
686#ifndef DESKTOP_VERSION 686#ifndef DESKTOP_VERSION
687 useToolTips = false; 687 useToolTips = false;
688#endif 688#endif
689 QString mToolTipText; 689 QString mToolTipText;
690 setFocusPolicy(WheelFocus); 690 setFocusPolicy(WheelFocus);
691 if ( !(event->doesRecur() == Recurrence::rNone) ) { 691 if ( !(event->doesRecur() == Recurrence::rNone) ) {
692 if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily ) 692 if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily )
693 return mdayCount; 693 return mdayCount;
694 else 694 else
695 if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly ) 695 if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly )
696 return mdayCount; 696 return mdayCount;
697 } 697 }
698 698
699 if ( event->isHoliday()) { 699 if ( event->isHoliday()) {
700 setHoliday( true ); 700 setHoliday( true );
701 if ( mDate.dayOfWeek() == 7 ) 701 if ( mDate.dayOfWeek() == 7 )
702 setLineWidth( 3 ); 702 setLineWidth( 3 );
703 } 703 }
704 QString text; 704 QString text;
705 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day 705 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day
706 if (event->isMultiDay()) { 706 if (event->isMultiDay()) {
707 QString prefix = "<->";multiday = 2; 707 QString prefix = "<->";multiday = 2;
708 QString time; 708 QString time;
709 if ( event->doesRecur() ) { 709 if ( event->doesRecur() ) {
710 if ( event->recursOn( mDate) ) { 710 if ( event->recursOn( mDate) ) {
711 prefix ="->" ;multiday = 1; 711 prefix ="->" ;multiday = 1;
712 } 712 }
713 else { 713 else {
714 int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); 714 int days = event->dtStart().date().daysTo ( event->dtEnd().date() );
715 if ( event->recursOn( mDate.addDays( -days)) ) { 715 if ( event->recursOn( mDate.addDays( -days)) ) {
716 prefix ="<-" ;multiday = 3; 716 prefix ="<-" ;multiday = 3;
717 } 717 }
718 } 718 }
719 719
720 } else { 720 } else {
721 if (mDate == event->dtStart().date()) { 721 if (mDate == event->dtStart().date()) {
722 prefix ="->" ;multiday = 1; 722 prefix ="->" ;multiday = 1;
723 } else if (mDate == event->dtEnd().date()) { 723 } else if (mDate == event->dtEnd().date()) {
724 prefix ="<-" ;multiday = 3; 724 prefix ="<-" ;multiday = 3;
725 } 725 }
726 } 726 }
727 if ( !event->doesFloat() ) { 727 if ( !event->doesFloat() ) {
728 if ( mDate == event->dtStart().date () ) 728 if ( mDate == event->dtStart().date () )
729 time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; 729 time = KGlobal::locale()->formatTime(event->dtStart().time())+" ";
730 else if ( mDate == event->dtEnd().date () ) 730 else if ( mDate == event->dtEnd().date () )
731 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; 731 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" ";
732 732
733 } 733 }
734 text = time + event->summary(); 734 text = time + event->summary();
735 if ( useToolTips ) 735 if ( useToolTips )
736 mToolTipText += prefix + text; 736 mToolTipText += prefix + text;
737 } else { 737 } else {
738 if (event->doesFloat()) { 738 if (event->doesFloat()) {
739 text = event->summary(); 739 text = event->summary();
740 if ( useToolTips ) 740 if ( useToolTips )
741 mToolTipText += text; 741 mToolTipText += text;
742 } 742 }
743 else { 743 else {
744 text = KGlobal::locale()->formatTime(event->dtStart().time()); 744 text = KGlobal::locale()->formatTime(event->dtStart().time());
745 text += " " + event->summary(); 745 text += " " + event->summary();
746 if ( useToolTips ) 746 if ( useToolTips )
747 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); 747 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary();
748 } 748 }
749 } 749 }
750 if ( useToolTips && ! event->location().isEmpty() ) { 750 if ( useToolTips && ! event->location().isEmpty() ) {
751 mToolTipText += " (" + event->location() +")"; 751 mToolTipText += " (" + event->location() +")";
752 } 752 }
753 MonthViewItem *item ; 753 MonthViewItem *item ;
754 754
755 if ( mAvailItemList.count() ) { 755 if ( mAvailItemList.count() ) {
756 item = mAvailItemList.first(); 756 item = mAvailItemList.first();
757 mAvailItemList.remove( item ); 757 mAvailItemList.remove( item );
758 item->recycle( event, text ); 758 item->recycle( event, text );
759 } else { 759 } else {
760 item = new MonthViewItem( event, text ); 760 item = new MonthViewItem( event, text );
761 } 761 }
762 762
763 QPalette pal; 763 QPalette pal;
764 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { 764 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) {
765 QStringList categories = event->categories(); 765 QStringList categories = event->categories();
766 QString cat = categories.first(); 766 QString cat = categories.first();
767 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { 767 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) {
768 pal = getPalette(); 768 pal = getPalette();
769 if (cat.isEmpty()) { 769 if (cat.isEmpty()) {
770 //pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); 770 //pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor);
771 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->defaultColor( event->calID() )); 771 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->defaultColor( event->calID() ));
772 } else { 772 } else {
773 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); 773 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat)));
774 } 774 }
775 775
776 } else { 776 } else {
777 if (cat.isEmpty()) { 777 if (cat.isEmpty()) {
778 //pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); 778 //pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor);
779 pal = QPalette( KOPrefs::instance()->defaultColor( event->calID() ), KOPrefs::instance()->defaultColor( event->calID() )); 779 pal = QPalette( KOPrefs::instance()->defaultColor( event->calID() ), KOPrefs::instance()->defaultColor( event->calID() ));
780 } else { 780 } else {
781 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); 781 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat)));
782 } 782 }
783 } 783 }
784 784
785 } else { 785 } else {
786 pal = mStandardPalette ; 786 pal = mStandardPalette ;
787 } 787 }
788 pal.setColor(QColorGroup::Highlight, KOPrefs::instance()->mHighlightColor); 788 pal.setColor(QColorGroup::Highlight, KOPrefs::instance()->mHighlightColor);
789 item->setPalette( pal ); 789 item->setPalette( pal );
790 item->setRecur( event->recurrence()->doesRecur() ); 790 item->setRecur( event->doesRecur() );
791 item->setAlarm( event->isAlarmEnabled() && multiday < 2 && event->alarmEnabled() ); 791 item->setAlarm( event->isAlarmEnabled() && multiday < 2 && event->alarmEnabled() );
792 item->setMoreInfo( event->description().length() > 0 ); 792 item->setMoreInfo( event->description().length() > 0 );
793#ifdef DESKTOP_VERSION 793#ifdef DESKTOP_VERSION
794 Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails, 794 Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails,
795 KOPrefs::instance()->email()); 795 KOPrefs::instance()->email());
796 if ( me != 0 ) { 796 if ( me != 0 ) {
797 if ( me->status() == Attendee::NeedsAction && me->RSVP()) 797 if ( me->status() == Attendee::NeedsAction && me->RSVP())
798 item->setReply(true && multiday < 2); 798 item->setReply(true && multiday < 2);
799 else 799 else
800 item->setReply(false); 800 item->setReply(false);
801 } else 801 } else
802 item->setReply(false); 802 item->setReply(false);
803#endif 803#endif
804 804
805 item->setMultiDay( multiday ); 805 item->setMultiDay( multiday );
806 if ( multiday ) { 806 if ( multiday ) {
807 insertItem( item ,mdayCount); 807 insertItem( item ,mdayCount);
808 ++mdayCount; 808 ++mdayCount;
809 } else { 809 } else {
810 uint i = mdayCount; 810 uint i = mdayCount;
811 uint pos = mdayCount; 811 uint pos = mdayCount;
812 uint itcount = count(); 812 uint itcount = count();
813 if ( itcount > 1000 ) { 813 if ( itcount > 1000 ) {
814 qDebug("KO: Bug in MonthViewCell::insertEvent %u ", itcount); 814 qDebug("KO: Bug in MonthViewCell::insertEvent %u ", itcount);
815 itcount = 0; 815 itcount = 0;
816 } 816 }
817 for ( i = pos; i < itcount;++i ) { 817 for ( i = pos; i < itcount;++i ) {
818 // qDebug("i %d mday %u count %d ",i,itcount,mdayCount ); 818 // qDebug("i %d mday %u count %d ",i,itcount,mdayCount );
819 QListBoxItem* it = this->item ( i ); 819 QListBoxItem* it = this->item ( i );
820 if ( it && text < it->text() ) { 820 if ( it && text < it->text() ) {
821 pos = i; 821 pos = i;
822 break; 822 break;
823 } 823 }
824 ++pos; 824 ++pos;
825 } 825 }
826 insertItem( item ,pos); 826 insertItem( item ,pos);
827 } 827 }
828 if ( useToolTips ) { 828 if ( useToolTips ) {
829 mToolTip.append( mToolTipText ); 829 mToolTip.append( mToolTipText );
830 } 830 }
831 return mdayCount; 831 return mdayCount;
832} 832}
833void MonthViewCell::insertTodo(Todo *todo) 833void MonthViewCell::insertTodo(Todo *todo)
834{ 834{
835 setFocusPolicy(WheelFocus); 835 setFocusPolicy(WheelFocus);
836 QString text; 836 QString text;
837 if (todo->hasDueDate()) { 837 if (todo->hasDueDate()) {
838 if (!todo->doesFloat()) { 838 if (!todo->doesFloat()) {
839 text += KGlobal::locale()->formatTime(todo->dtDue().time()); 839 text += KGlobal::locale()->formatTime(todo->dtDue().time());
840 text += " "; 840 text += " ";
841 } 841 }
842 } 842 }
843 text += todo->summary(); 843 text += todo->summary();
844 MonthViewItem *item ; 844 MonthViewItem *item ;
845 if ( mAvailItemList.count() ) { 845 if ( mAvailItemList.count() ) {
846 item = mAvailItemList.first(); 846 item = mAvailItemList.first();
847 mAvailItemList.remove( item ); 847 mAvailItemList.remove( item );
848 item->recycle( todo, text ); 848 item->recycle( todo, text );
849 } else { 849 } else {
850 item = new MonthViewItem( todo, text ); 850 item = new MonthViewItem( todo, text );
851 } 851 }
852 //MonthViewItem *item = new MonthViewItem( todo, mDate, text ); 852 //MonthViewItem *item = new MonthViewItem( todo, mDate, text );
853 //item->setPalette( mStandardPalette ); 853 //item->setPalette( mStandardPalette );
854 QPalette pal; 854 QPalette pal;
855 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { 855 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) {
856 QStringList categories = todo->categories(); 856 QStringList categories = todo->categories();
857 QString cat = categories.first(); 857 QString cat = categories.first();
858 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { 858 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) {
859 pal = getPalette(); 859 pal = getPalette();
860 if (cat.isEmpty()) { 860 if (cat.isEmpty()) {
861 //pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); 861 //pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor);
862 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->defaultColor( todo->calID() )); 862 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->defaultColor( todo->calID() ));
863 } else { 863 } else {
864 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); 864 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat)));
865 } 865 }
866 866
867 } else { 867 } else {
868 if (cat.isEmpty()) { 868 if (cat.isEmpty()) {
869 //pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); 869 //pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor);
870 pal = QPalette(KOPrefs::instance()->defaultColor( todo->calID() ), KOPrefs::instance()->defaultColor( todo->calID() )); 870 pal = QPalette(KOPrefs::instance()->defaultColor( todo->calID() ), KOPrefs::instance()->defaultColor( todo->calID() ));
871 } else { 871 } else {
872 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); 872 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat)));
873 } 873 }
874 } 874 }
875 875
876 } else { 876 } else {
877 pal = mStandardPalette ; 877 pal = mStandardPalette ;
878 } 878 }
879 pal.setColor(QColorGroup::Highlight, KOPrefs::instance()->mHighlightColor); 879 pal.setColor(QColorGroup::Highlight, KOPrefs::instance()->mHighlightColor);
880 item->setPalette( pal ); 880 item->setPalette( pal );
881 item->setRecur( todo->recurrence()->doesRecur() ); 881 item->setRecur( todo->doesRecur() );
882 item->setAlarm( todo->isAlarmEnabled() && todo->alarmEnabled() ); 882 item->setAlarm( todo->isAlarmEnabled() && todo->alarmEnabled() );
883 item->setMoreInfo( todo->description().length() > 0 ); 883 item->setMoreInfo( todo->description().length() > 0 );
884 insertItem( item , count()); 884 insertItem( item , count());
885#ifdef DESKTOP_VERSION 885#ifdef DESKTOP_VERSION
886 mToolTip.append( text ); 886 mToolTip.append( text );
887#endif 887#endif
888} 888}
889void MonthViewCell::repaintfinishUpdateCell() 889void MonthViewCell::repaintfinishUpdateCell()
890{ 890{
891 MonthViewItem *mitem = (MonthViewItem*) firstItem (); 891 MonthViewItem *mitem = (MonthViewItem*) firstItem ();
892 while ( mitem ) { 892 while ( mitem ) {
893 mitem->setBlockRepaint( false ); 893 mitem->setBlockRepaint( false );
894 updateItem ( mitem ); 894 updateItem ( mitem );
895 mitem = (MonthViewItem *)mitem->next(); 895 mitem = (MonthViewItem *)mitem->next();
896 } 896 }
897 blockSignals( false ); 897 blockSignals( false );
898} 898}
899void MonthViewCell::finishUpdateCell() 899void MonthViewCell::finishUpdateCell()
900{ 900{
901 901
902 902
903 903
904#ifdef DESKTOP_VERSION 904#ifdef DESKTOP_VERSION
905 if (mToolTip.count() > 0 ) { 905 if (mToolTip.count() > 0 ) {
906 mToolTip.sort(); 906 mToolTip.sort();
907 QToolTip::add(this,mToolTip.join("\n"),toolTipGroup(),""); 907 QToolTip::add(this,mToolTip.join("\n"),toolTipGroup(),"");
908 } 908 }
909#endif 909#endif
910 //sort(); 910 //sort();
911 //setMyPalette(); 911 //setMyPalette();
912 setMyPalette(); 912 setMyPalette();
913 913
914 resizeEvent( 0 ); 914 resizeEvent( 0 );
915 915
916} 916}
917void MonthViewCell::updateCell() 917void MonthViewCell::updateCell()
918{ 918{
919 if ( !mMonthView->isUpdatePossible() ) 919 if ( !mMonthView->isUpdatePossible() )
920 return; 920 return;
921 startUpdateCell(); 921 startUpdateCell();
922 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); 922 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
923 QPtrList<Event> events = mMonthView->calendar()->events( mDate, true ); 923 QPtrList<Event> events = mMonthView->calendar()->events( mDate, true );
924 Event *event; 924 Event *event;
925 for( event = events.first(); event; event = events.next() ) { // for event 925 for( event = events.first(); event; event = events.next() ) { // for event
926 insertEvent(event); 926 insertEvent(event);
927 } 927 }
928 // insert due todos 928 // insert due todos
929 QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate ); 929 QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate );
930 Todo *todo; 930 Todo *todo;
931 for(todo = todos.first(); todo; todo = todos.next()) { 931 for(todo = todos.first(); todo; todo = todos.next()) {
932 insertTodo( todo ); 932 insertTodo( todo );
933 } 933 }
934 finishUpdateCell(); 934 finishUpdateCell();
935 // if ( isVisible()) 935 // if ( isVisible())
936 //qApp->processEvents(); 936 //qApp->processEvents();
937} 937}
938 938
939void MonthViewCell::updateConfig( bool bigFont ) // = false 939void MonthViewCell::updateConfig( bool bigFont ) // = false
940{ 940{
941 941
942 if ( bigFont ) { 942 if ( bigFont ) {
943 QFont fo = KOPrefs::instance()->mMonthViewFont; 943 QFont fo = KOPrefs::instance()->mMonthViewFont;
944 int ps = fo.pointSize() + 2; 944 int ps = fo.pointSize() + 2;
945 if ( ps < 18 ) 945 if ( ps < 18 )
946 ps += 2; 946 ps += 2;
947 fo.setPointSize( ps ); 947 fo.setPointSize( ps );
948 setFont( fo ); 948 setFont( fo );
949 } else 949 } else
950 setFont( KOPrefs::instance()->mMonthViewFont ); 950 setFont( KOPrefs::instance()->mMonthViewFont );
951 951
952 QFontMetrics fm( font() ); 952 QFontMetrics fm( font() );
953 mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 ); 953 mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 );
954 mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 ); 954 mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 );
955 mHolidayPalette = mStandardPalette; 955 mHolidayPalette = mStandardPalette;
956 mPrimaryPalette = mStandardPalette; 956 mPrimaryPalette = mStandardPalette;
957 mNonPrimaryPalette = mStandardPalette; 957 mNonPrimaryPalette = mStandardPalette;
958 if ( KOPrefs::instance()->mMonthViewUsesDayColors ) { 958 if ( KOPrefs::instance()->mMonthViewUsesDayColors ) {
959 mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor ); 959 mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor );
960 mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor ); 960 mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor );
961 mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark()); 961 mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark());
962 mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark()); 962 mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark());
963 mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor); 963 mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor);
964 mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor); 964 mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor);
965 mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark()); 965 mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark());
966 mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor); 966 mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor);
967 mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor); 967 mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor);
968 } 968 }
969 //updateCell(); 969 //updateCell();
970} 970}
971 971
972void MonthViewCell::enableScrollBars( bool enabled ) 972void MonthViewCell::enableScrollBars( bool enabled )
973{ 973{
974 974
975 return; 975 return;
976 if ( enabled ) { 976 if ( enabled ) {
977 QListBoxItem *fi = firstItem (); 977 QListBoxItem *fi = firstItem ();
978 if (fi ) { 978 if (fi ) {
979 int ihei = fi->height( this ); 979 int ihei = fi->height( this );
980 int hei = numRows () * ihei; 980 int hei = numRows () * ihei;
981 if ( hei < height() - horizontalScrollBar()->height () ) { 981 if ( hei < height() - horizontalScrollBar()->height () ) {
982 setVScrollBarMode(QScrollView::AlwaysOff); 982 setVScrollBarMode(QScrollView::AlwaysOff);
983 } 983 }
984 else 984 else
985 setVScrollBarMode(QScrollView::Auto); 985 setVScrollBarMode(QScrollView::Auto);
986 if ( ihei *3 > height() ) { 986 if ( ihei *3 > height() ) {
987 setHScrollBarMode(QScrollView::AlwaysOff); 987 setHScrollBarMode(QScrollView::AlwaysOff);
988 } 988 }
989 else { 989 else {
990 setHScrollBarMode(QScrollView::Auto); 990 setHScrollBarMode(QScrollView::Auto);
991 } 991 }
992 } else { 992 } else {
993 setVScrollBarMode(QScrollView::Auto); 993 setVScrollBarMode(QScrollView::Auto);
994 setHScrollBarMode(QScrollView::Auto); 994 setHScrollBarMode(QScrollView::Auto);
995 } 995 }
996 } else { 996 } else {
997 setVScrollBarMode(QScrollView::AlwaysOff); 997 setVScrollBarMode(QScrollView::AlwaysOff);
998 setHScrollBarMode(QScrollView::AlwaysOff); 998 setHScrollBarMode(QScrollView::AlwaysOff);
999 } 999 }
1000} 1000}
1001 1001
1002Incidence *MonthViewCell::selectedIncidence() 1002Incidence *MonthViewCell::selectedIncidence()
1003{ 1003{
1004 int index = currentItem(); 1004 int index = currentItem();
1005 if ( index < 0 ) return 0; 1005 if ( index < 0 ) return 0;
1006 1006
1007 MonthViewItem *mitem = 1007 MonthViewItem *mitem =
1008 static_cast<MonthViewItem *>( item( index ) ); 1008 static_cast<MonthViewItem *>( item( index ) );
1009 1009
1010 if ( !mitem ) return 0; 1010 if ( !mitem ) return 0;
1011 1011
1012 return mitem->incidence(); 1012 return mitem->incidence();
1013} 1013}
1014 1014
1015QDate MonthViewCell::selectedIncidenceDate() 1015QDate MonthViewCell::selectedIncidenceDate()
1016{ 1016{
1017 QDate qd; 1017 QDate qd;
1018 int index = currentItem(); 1018 int index = currentItem();
1019 if ( index < 0 ) return qd; 1019 if ( index < 0 ) return qd;
1020 return mDate; 1020 return mDate;
1021} 1021}
1022 1022
1023void MonthViewCell::deselect() 1023void MonthViewCell::deselect()
1024{ 1024{
1025 clearSelection(); 1025 clearSelection();
1026 enableScrollBars( false ); 1026 enableScrollBars( false );
1027 // updateCell(); 1027 // updateCell();
1028} 1028}
1029void MonthViewCell::select() 1029void MonthViewCell::select()
1030{ 1030{
1031 ;// updateCell(); 1031 ;// updateCell();
1032} 1032}
1033 1033
1034void MonthViewCell::resizeEvent ( QResizeEvent * e ) 1034void MonthViewCell::resizeEvent ( QResizeEvent * e )
1035{ 1035{
1036 if ( !mMonthView->isUpdatePossible() ) 1036 if ( !mMonthView->isUpdatePossible() )
1037 return; 1037 return;
1038 //qDebug("++++++++++++++MonthViewCell::resizeEvent %d %d ", width(), height()); 1038 //qDebug("++++++++++++++MonthViewCell::resizeEvent %d %d ", width(), height());
1039 deselect(); 1039 deselect();
1040 mLabel->setMaximumHeight( height() - lineWidth()*2 ); 1040 mLabel->setMaximumHeight( height() - lineWidth()*2 );
1041 1041
1042 QString text; 1042 QString text;
1043 //mLabel->setText( text ); 1043 //mLabel->setText( text );
1044 bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog; 1044 bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog;
1045 if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) { 1045 if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) {
1046 text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " " + QString::number( mDate.day() ); 1046 text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " " + QString::number( mDate.day() );
1047 mLabel->resize( mLabelBigSize ); 1047 mLabel->resize( mLabelBigSize );
1048 } else { 1048 } else {
1049 mLabel->resize( mLabelSize ); 1049 mLabel->resize( mLabelSize );
1050 text = QString::number( mDate.day() ); 1050 text = QString::number( mDate.day() );
1051 } 1051 }
1052 mLabel->setText( text ); 1052 mLabel->setText( text );
1053 1053
1054 int size = height() - mLabel->height() - lineWidth()-1; 1054 int size = height() - mLabel->height() - lineWidth()-1;
1055 //qDebug("LW %d ", lineWidth()); 1055 //qDebug("LW %d ", lineWidth());
1056 if ( size > 0 ) 1056 if ( size > 0 )
1057 verticalScrollBar()->setMaximumHeight( size ); 1057 verticalScrollBar()->setMaximumHeight( size );
1058 size = width() - mLabel->width() -lineWidth()-1; 1058 size = width() - mLabel->width() -lineWidth()-1;
1059 if ( size > 0 ) 1059 if ( size > 0 )
1060 horizontalScrollBar()->setMaximumWidth( size ); 1060 horizontalScrollBar()->setMaximumWidth( size );
1061 mLabel->move( width()-lineWidth() - mLabel->width(), height()-lineWidth() - mLabel->height() ); 1061 mLabel->move( width()-lineWidth() - mLabel->width(), height()-lineWidth() - mLabel->height() );
1062 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); 1062 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
1063 // mItemList->resize ( width(), height () ); 1063 // mItemList->resize ( width(), height () );
1064 if ( e ) 1064 if ( e )
1065 KNoScrollListBox::resizeEvent ( e ); 1065 KNoScrollListBox::resizeEvent ( e );
1066} 1066}
1067 1067
1068void MonthViewCell::defaultAction( QListBoxItem *item ) 1068void MonthViewCell::defaultAction( QListBoxItem *item )
1069{ 1069{
1070 1070
1071 if ( !item ) { 1071 if ( !item ) {
1072 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 1072 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
1073 emit newEventSignal( dt ); 1073 emit newEventSignal( dt );
1074 return; 1074 return;
1075 } 1075 }
1076 1076
1077 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 1077 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
1078 Incidence *incidence = eventItem->incidence(); 1078 Incidence *incidence = eventItem->incidence();
1079 if ( incidence ) mMonthView->defaultAction( incidence ); 1079 if ( incidence ) mMonthView->defaultAction( incidence );
1080} 1080}
1081void MonthViewCell::showDay() 1081void MonthViewCell::showDay()
1082{ 1082{
1083 emit showDaySignal( date() ); 1083 emit showDaySignal( date() );
1084} 1084}
1085void MonthViewCell::newEvent() 1085void MonthViewCell::newEvent()
1086{ 1086{
1087 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 1087 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
1088 emit newEventSignal( dt ); 1088 emit newEventSignal( dt );
1089} 1089}
1090void MonthViewCell::cellClicked( QListBoxItem *item ) 1090void MonthViewCell::cellClicked( QListBoxItem *item )
1091{ 1091{
1092 mMonthView->setSelectedCell( this ); 1092 mMonthView->setSelectedCell( this );
1093 if ( item == 0 ) { 1093 if ( item == 0 ) {
1094 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 1094 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
1095 emit newEventSignal( dt ); 1095 emit newEventSignal( dt );
1096 return; 1096 return;
1097 } 1097 }
1098 1098
1099} 1099}
1100 1100
1101void MonthViewCell::contextMenu( QListBoxItem *item ) 1101void MonthViewCell::contextMenu( QListBoxItem *item )
1102{ 1102{
1103 mMonthView->setPopupCell( this ); 1103 mMonthView->setPopupCell( this );
1104 if ( !item ) { 1104 if ( !item ) {
1105 mMonthView->showContextMenu( 0 ); 1105 mMonthView->showContextMenu( 0 );
1106 return; 1106 return;
1107 } 1107 }
1108 //selection( item );
1109 //qApp->processEvents();
1108 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 1110 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
1109 Incidence *incidence = eventItem->incidence(); 1111 Incidence *incidence = eventItem->incidence();
1110 if ( incidence ) mMonthView->showContextMenu( incidence ); 1112 if ( incidence ) mMonthView->showContextMenu( incidence );
1111} 1113}
1112 1114
1113void MonthViewCell::selection( QListBoxItem *item ) 1115void MonthViewCell::selection( QListBoxItem *item )
1114{ 1116{
1115 if ( !item ) { 1117 if ( !item ) {
1116 emit highlightIncidence( 0 , this, 0 ); 1118 emit highlightIncidence( 0 , this, 0 );
1117 return; 1119 return;
1118 } 1120 }
1119 MonthViewItem * it = (static_cast<MonthViewItem *>( item )); 1121 MonthViewItem * it = (static_cast<MonthViewItem *>( item ));
1120 emit highlightIncidence( it->incidence(), this, it->multiDay() ); 1122 emit highlightIncidence( it->incidence(), this, it->multiDay() );
1121 mMonthView->setSelectedCell( this ); 1123 mMonthView->setSelectedCell( this );
1122} 1124}
1123 1125
1124void MonthViewCell::deHighLight() 1126void MonthViewCell::deHighLight()
1125{ 1127{
1126 MonthViewItem *mitem = (MonthViewItem*) firstItem (); 1128 MonthViewItem *mitem = (MonthViewItem*) firstItem ();
1127 while ( mitem ) { 1129 while ( mitem ) {
1128 if ( mitem->setHighlightedFalse() ) 1130 if ( mitem->setHighlightedFalse() )
1129 updateItem ( mitem ); 1131 updateItem ( mitem );
1130 mitem = (MonthViewItem *)mitem->next(); 1132 mitem = (MonthViewItem *)mitem->next();
1131 } 1133 }
1132} 1134}
1133// returns true if no inc found 1135// returns true if no inc found
1134bool MonthViewCell::doHighLight( Incidence * inc ) 1136bool MonthViewCell::doHighLight( Incidence * inc )
1135{ 1137{
1136 1138
1137 MonthViewItem *mitem = (MonthViewItem*) firstItem (); 1139 MonthViewItem *mitem = (MonthViewItem*) firstItem ();
1138 while ( mitem ) { 1140 while ( mitem ) {
1139 if ( mitem->incidence() == inc ) { 1141 if ( mitem->incidence() == inc ) {
1140 if ( mitem->setHighlighted( inc ) ) 1142 if ( mitem->setHighlighted( inc ) )
1141 updateItem ( mitem ); 1143 updateItem ( mitem );
1142 return false; 1144 return false;
1143 } 1145 }
1144 mitem = (MonthViewItem *)mitem->next(); 1146 mitem = (MonthViewItem *)mitem->next();
1145 } 1147 }
1146 return true; 1148 return true;
1147} 1149}
1148// ******************************************************************************* 1150// *******************************************************************************
1149// ******************************************************************************* 1151// *******************************************************************************
1150// ******************************************************************************* 1152// *******************************************************************************
1151 1153
1152 1154
1153KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) 1155KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name)
1154 : KOEventView( calendar, parent, name ), 1156 : KOEventView( calendar, parent, name ),
1155 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), 1157 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ),
1156 mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) 1158 mWidthLongDayLabel( 0 ), mSelectedCell( 0 )
1157{ 1159{
1158 mFlagKeyPressed = false; 1160 mFlagKeyPressed = false;
1159 mShortDayLabelsM = false; 1161 mShortDayLabelsM = false;
1160 mShortDayLabelsW = false; 1162 mShortDayLabelsW = false;
1161 skipResize = false; 1163 skipResize = false;
1162 clPending = true; 1164 clPending = true;
1163 mPopupCell = 0; 1165 mPopupCell = 0;
1164 mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" ); 1166 mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" );
1165 mWidStack = new QWidgetStack( this ); 1167 mWidStack = new QWidgetStack( this );
1166 QVBoxLayout* hb = new QVBoxLayout( this ); 1168 QVBoxLayout* hb = new QVBoxLayout( this );
1167 mMonthView = new QWidget( mWidStack ); 1169 mMonthView = new QWidget( mWidStack );
1168 mWeekView = new QWidget( mWidStack ); 1170 mWeekView = new QWidget( mWidStack );
1169#if QT_VERSION >= 0x030000 1171#if QT_VERSION >= 0x030000
1170 mWidStack->addWidget(mMonthView ); 1172 mWidStack->addWidget(mMonthView );
1171 mWidStack->addWidget(mWeekView ); 1173 mWidStack->addWidget(mWeekView );
1172#else 1174#else
1173 mWidStack->addWidget( mMonthView, 1 ); 1175 mWidStack->addWidget( mMonthView, 1 );
1174 mWidStack->addWidget( mWeekView , 1 ); 1176 mWidStack->addWidget( mWeekView , 1 );
1175#endif 1177#endif
1176 hb->addWidget( mNavigatorBar ); 1178 hb->addWidget( mNavigatorBar );
1177 hb->addWidget( mWidStack ); 1179 hb->addWidget( mWidStack );
1178 mShowWeekView = KOPrefs::instance()->mMonthViewWeek; 1180 mShowWeekView = KOPrefs::instance()->mMonthViewWeek;
1179 updatePossible = false; 1181 updatePossible = false;
1180 //updatePossible = true; 1182 //updatePossible = true;
1181 mCells.setAutoDelete( true ); 1183 mCells.setAutoDelete( true );
1182 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; 1184 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
1183 mDayLabels.resize( mDaysPerWeek ); 1185 mDayLabels.resize( mDaysPerWeek );
1184 mDayLabelsW.resize( mDaysPerWeek ); 1186 mDayLabelsW.resize( mDaysPerWeek );
1185 QFont bfont = font(); 1187 QFont bfont = font();
1186 if ( QApplication::desktop()->width() < 650 ) { 1188 if ( QApplication::desktop()->width() < 650 ) {
1187 bfont.setPointSize( bfont.pointSize() - 2 ); 1189 bfont.setPointSize( bfont.pointSize() - 2 );
1188 } 1190 }
1189 bfont.setBold( true ); 1191 bfont.setBold( true );
1190 int i; 1192 int i;
1191 1193
1192 for( i = 0; i < mDaysPerWeek; i++ ) { 1194 for( i = 0; i < mDaysPerWeek; i++ ) {
1193 QLabel *label = new QLabel( mMonthView ); 1195 QLabel *label = new QLabel( mMonthView );
1194 label->setFont(bfont); 1196 label->setFont(bfont);
1195 label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1197 label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1196 label->setLineWidth(1); 1198 label->setLineWidth(1);
1197 label->setAlignment(AlignCenter); 1199 label->setAlignment(AlignCenter);
1198 mDayLabels.insert( i, label ); 1200 mDayLabels.insert( i, label );
1199 label = new QLabel( mWeekView ); 1201 label = new QLabel( mWeekView );
1200 label->setFont(bfont); 1202 label->setFont(bfont);
1201 label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1203 label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1202 label->setLineWidth(1); 1204 label->setLineWidth(1);
1203 label->setAlignment(AlignCenter); 1205 label->setAlignment(AlignCenter);
1204 mDayLabelsW.insert( i, label ); 1206 mDayLabelsW.insert( i, label );
1205 } 1207 }
1206 1208
1207 bfont.setBold( false ); 1209 bfont.setBold( false );
1208 mWeekLabels.resize( mNumWeeks+1 ); 1210 mWeekLabels.resize( mNumWeeks+1 );
1209 mWeekLabelsW.resize( 2 ); 1211 mWeekLabelsW.resize( 2 );
1210 for( i = 0; i < mNumWeeks+1; i++ ) { 1212 for( i = 0; i < mNumWeeks+1; i++ ) {
1211 KOWeekButton *label = new KOWeekButton( mMonthView ); 1213 KOWeekButton *label = new KOWeekButton( mMonthView );
1212 label->setFocusPolicy(NoFocus); 1214 label->setFocusPolicy(NoFocus);
1213 label->setFont(bfont); 1215 label->setFont(bfont);
1214 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); 1216 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) );
1215 label->setFlat(true); 1217 label->setFlat(true);
1216 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); 1218 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed"));
1217 //label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1219 //label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1218 //label->setLineWidth(1); 1220 //label->setLineWidth(1);
1219 //label->setAlignment(AlignCenter); 1221 //label->setAlignment(AlignCenter);
1220 mWeekLabels.insert( i, label ); 1222 mWeekLabels.insert( i, label );
1221 } 1223 }
1222 mWeekLabels[mNumWeeks]->setText( i18n("W")); 1224 mWeekLabels[mNumWeeks]->setText( i18n("W"));
1223 mWeekLabels[mNumWeeks]->setFocusPolicy(WheelFocus); 1225 mWeekLabels[mNumWeeks]->setFocusPolicy(WheelFocus);
1224 QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number")); 1226 QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number"));
1225 1227
1226 for( i = 0; i < 1+1; i++ ) { 1228 for( i = 0; i < 1+1; i++ ) {
1227 KOWeekButton *label = new KOWeekButton( mWeekView ); 1229 KOWeekButton *label = new KOWeekButton( mWeekView );
1228 label->setFocusPolicy(NoFocus); 1230 label->setFocusPolicy(NoFocus);
1229 label->setFont(bfont); 1231 label->setFont(bfont);
1230 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); 1232 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) );
1231 label->setFlat(true); 1233 label->setFlat(true);
1232 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); 1234 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed"));
1233 //label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1235 //label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1234 //label->setLineWidth(1); 1236 //label->setLineWidth(1);
1235 //label->setAlignment(AlignCenter); 1237 //label->setAlignment(AlignCenter);
1236 mWeekLabelsW.insert( i, label ); 1238 mWeekLabelsW.insert( i, label );
1237 } 1239 }
1238 mWeekLabelsW[1]->setText( i18n("W")); 1240 mWeekLabelsW[1]->setText( i18n("W"));
1239 mWeekLabelsW[1]->setFocusPolicy(WheelFocus); 1241 mWeekLabelsW[1]->setFocusPolicy(WheelFocus);
1240 1242
1241 1243
1242 int row, col; 1244 int row, col;
1243 mCells.resize( mNumCells ); 1245 mCells.resize( mNumCells );
1244 for( row = 0; row < mNumWeeks; ++row ) { 1246 for( row = 0; row < mNumWeeks; ++row ) {
1245 for( col = 0; col < mDaysPerWeek; ++col ) { 1247 for( col = 0; col < mDaysPerWeek; ++col ) {
1246 MonthViewCell *cell = new MonthViewCell( this, mMonthView ); 1248 MonthViewCell *cell = new MonthViewCell( this, mMonthView );
1247 mCells.insert( row * mDaysPerWeek + col, cell ); 1249 mCells.insert( row * mDaysPerWeek + col, cell );
1248 1250
1249 connect( cell, SIGNAL( defaultAction( Incidence * ) ), 1251 connect( cell, SIGNAL( defaultAction( Incidence * ) ),
1250 SLOT( defaultAction( Incidence * ) ) ); 1252 SLOT( defaultAction( Incidence * ) ) );
1251 connect( cell, SIGNAL( newEventSignal( QDateTime ) ), 1253 connect( cell, SIGNAL( newEventSignal( QDateTime ) ),
1252 SIGNAL( newEventSignal( QDateTime ) ) ); 1254 SIGNAL( newEventSignal( QDateTime ) ) );
1253 connect( cell, SIGNAL( showDaySignal( QDate ) ), 1255 connect( cell, SIGNAL( showDaySignal( QDate ) ),
1254 SIGNAL( showDaySignal( QDate ) ) ); 1256 SIGNAL( showDaySignal( QDate ) ) );
1255 connect( cell, SIGNAL( nextCell() ), 1257 connect( cell, SIGNAL( nextCell() ),
1256 SLOT( nextCell() ) ); 1258 SLOT( nextCell() ) );
1257 connect( cell, SIGNAL( prevCell() ), 1259 connect( cell, SIGNAL( prevCell() ),
1258 SLOT( prevCell() ) ); 1260 SLOT( prevCell() ) );
1259 connect( cell, SIGNAL( highlightIncidence( Incidence * , MonthViewCell *, int ) ), 1261 connect( cell, SIGNAL( highlightIncidence( Incidence * , MonthViewCell *, int ) ),
1260 SLOT( incidenceHighlighted( Incidence *, MonthViewCell *, int ) )); 1262 SLOT( incidenceHighlighted( Incidence *, MonthViewCell *, int ) ));
1261 } 1263 }
1262 } 1264 }
1263 mCellsW.resize( mDaysPerWeek ); 1265 mCellsW.resize( mDaysPerWeek );
1264 for( col = 0; col < mDaysPerWeek; ++col ) { 1266 for( col = 0; col < mDaysPerWeek; ++col ) {
1265 MonthViewCell *cell = new MonthViewCell( this, mWeekView ); 1267 MonthViewCell *cell = new MonthViewCell( this, mWeekView );
1266 mCellsW.insert( col, cell ); 1268 mCellsW.insert( col, cell );
1267 1269
1268 connect( cell, SIGNAL( defaultAction( Incidence * ) ), 1270 connect( cell, SIGNAL( defaultAction( Incidence * ) ),
1269 SLOT( defaultAction( Incidence * ) ) ); 1271 SLOT( defaultAction( Incidence * ) ) );
1270 connect( cell, SIGNAL( newEventSignal( QDateTime ) ), 1272 connect( cell, SIGNAL( newEventSignal( QDateTime ) ),
1271 SIGNAL( newEventSignal( QDateTime ) ) ); 1273 SIGNAL( newEventSignal( QDateTime ) ) );
1272 connect( cell, SIGNAL( showDaySignal( QDate ) ), 1274 connect( cell, SIGNAL( showDaySignal( QDate ) ),
1273 SIGNAL( showDaySignal( QDate ) ) ); 1275 SIGNAL( showDaySignal( QDate ) ) );
1274 connect( cell, SIGNAL( nextCell() ), 1276 connect( cell, SIGNAL( nextCell() ),
1275 SLOT( nextCell() ) ); 1277 SLOT( nextCell() ) );
1276 connect( cell, SIGNAL( prevCell() ), 1278 connect( cell, SIGNAL( prevCell() ),
1277 SLOT( prevCell() ) ); 1279 SLOT( prevCell() ) );
1278 connect( cell, SIGNAL( highlightIncidence( Incidence * , MonthViewCell *, int ) ), 1280 connect( cell, SIGNAL( highlightIncidence( Incidence * , MonthViewCell *, int ) ),
1279 SLOT( incidenceHighlighted( Incidence *, MonthViewCell *, int ) )); 1281 SLOT( incidenceHighlighted( Incidence *, MonthViewCell *, int ) ));
1280 cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont ); 1282 cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont );
1281 } 1283 }
1282 1284
1283 //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) ); 1285 //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) );
1284 mContextMenu = eventPopup(); 1286 mContextMenu = eventPopup();
1285 mContextMenu->addAdditionalItem(QIconSet(QPixmap()), 1287 mContextMenu->addAdditionalItem(QIconSet(QPixmap()),
1286 i18n("New Event..."),this, 1288 i18n("New Event..."),this,
1287 SLOT(slotNewEvent()),false); 1289 SLOT(slotNewEvent()),false);
1288 mContextMenu->addAdditionalItem(QIconSet(QPixmap()), 1290 mContextMenu->addAdditionalItem(QIconSet(QPixmap()),
1289 i18n("New Todo..."),this, 1291 i18n("New Todo..."),this,
1290 SLOT(slotNewTodo()),false); 1292 SLOT(slotNewTodo()),false);
1291 mContextMenu->addAdditionalItem(QIconSet(QPixmap()), 1293 mContextMenu->addAdditionalItem(QIconSet(QPixmap()),
1292 i18n("Journal"),this, 1294 i18n("Journal"),this,
1293 SLOT(slotEditJournal()),false); 1295 SLOT(slotEditJournal()),false);
1294 1296
1295 connect (mContextMenu ,SIGNAL(categoryChanged( Incidence * )),this, 1297 connect (mContextMenu ,SIGNAL(categoryChanged( Incidence * )),this,
1296 SLOT( catChanged( Incidence * ) )); 1298 SLOT( catChanged( Incidence * ) ));
1297 1299
1298 1300
1299 QString pathString = ""; 1301 QString pathString = "";
1300 if ( !KOPrefs::instance()->mToolBarMiniIcons ) { 1302 if ( !KOPrefs::instance()->mToolBarMiniIcons ) {
1301 if ( QApplication::desktop()->width() < 480 ) 1303 if ( QApplication::desktop()->width() < 480 )
1302 pathString += "icons16/"; 1304 pathString += "icons16/";
1303 } else 1305 } else
1304 pathString += "iconsmini/"; 1306 pathString += "iconsmini/";
1305 mNewItemMenu = new QPopupMenu( this ); 1307 mNewItemMenu = new QPopupMenu( this );
1306 mNewItemMenu->insertItem( SmallIcon( pathString +"newevent" ), i18n("New Event..."),this, SLOT(slotNewEvent())); 1308 mNewItemMenu->insertItem( SmallIcon( pathString +"newevent" ), i18n("New Event..."),this, SLOT(slotNewEvent()));
1307 mNewItemMenu->insertItem( SmallIcon( pathString +"newtodo" ),i18n("New Todo..."),this,SLOT(slotNewTodo()),false); 1309 mNewItemMenu->insertItem( SmallIcon( pathString +"newtodo" ),i18n("New Todo..."),this,SLOT(slotNewTodo()),false);
1308 mNewItemMenu->insertItem( SmallIcon( pathString +"journal" ),i18n("Journal"),this,SLOT(slotEditJournal()),false); 1310 mNewItemMenu->insertItem( SmallIcon( pathString +"journal" ),i18n("Journal"),this,SLOT(slotEditJournal()),false);
1309 1311
1310 // updateConfig(); //useless here... 1312 // updateConfig(); //useless here...
1311 // ... but we need mWidthLongDayLabel computed 1313 // ... but we need mWidthLongDayLabel computed
1312 QFontMetrics fontmetric(mDayLabels[0]->font()); 1314 QFontMetrics fontmetric(mDayLabels[0]->font());
1313 mWidthLongDayLabel = 0; 1315 mWidthLongDayLabel = 0;
1314 for (int i = 0; i < 7; i++) { 1316 for (int i = 0; i < 7; i++) {
1315 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); 1317 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1));
1316 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; 1318 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
1317 } 1319 }
1318 1320
1319 //mWeekLabels[mNumWeeks]->setText( i18n("W")); 1321 //mWeekLabels[mNumWeeks]->setText( i18n("W"));
1320 1322
1321#if 0 1323#if 0
1322 if ( mShowWeekView ) 1324 if ( mShowWeekView )
1323 mWidStack->raiseWidget( mWeekView ); 1325 mWidStack->raiseWidget( mWeekView );
1324 else 1326 else
1325 mWidStack->raiseWidget( mMonthView ); 1327 mWidStack->raiseWidget( mMonthView );
1326#endif 1328#endif
1327 1329
1328 emit incidenceSelected( 0 ); 1330 emit incidenceSelected( 0 );
1329 1331
1330 mComputeLayoutTimer = new QTimer( this ); 1332 mComputeLayoutTimer = new QTimer( this );
1331 connect (mComputeLayoutTimer ,SIGNAL(timeout()), this, SLOT ( slotComputeLayout())); 1333 connect (mComputeLayoutTimer ,SIGNAL(timeout()), this, SLOT ( slotComputeLayout()));
1332 1334
1333 1335
1334#ifndef DESKTOP_VERSION 1336#ifndef DESKTOP_VERSION
1335 resize( QApplication::desktop()->size() ); 1337 resize( QApplication::desktop()->size() );
1336#else 1338#else
1337 resize(640, 480 ); 1339 resize(640, 480 );
1338 updatePossible = true; 1340 updatePossible = true;
1339#endif 1341#endif
1340 computeLayout(); 1342 computeLayout();
1341 1343
1342 if ( mShowWeekView ) 1344 if ( mShowWeekView )
1343 mWidStack->raiseWidget( mWeekView ); 1345 mWidStack->raiseWidget( mWeekView );
1344 else 1346 else
1345 mWidStack->raiseWidget( mMonthView ); 1347 mWidStack->raiseWidget( mMonthView );
1346} 1348}
1347 1349
1348KOMonthView::~KOMonthView() 1350KOMonthView::~KOMonthView()
1349{ 1351{
1350 delete mContextMenu; 1352 delete mContextMenu;
1351} 1353}
1352 1354
1353void KOMonthView::catChanged( Incidence * ) 1355void KOMonthView::catChanged( Incidence * )
1354{ 1356{
1355 updateView(); 1357 updateView();
1356} 1358}
1357void KOMonthView::incidenceHighlighted( Incidence * inc , MonthViewCell* mc, int mday ) 1359void KOMonthView::incidenceHighlighted( Incidence * inc , MonthViewCell* mc, int mday )
1358{ 1360{
1359 static Incidence * lastInc = 0; 1361 static Incidence * lastInc = 0;
1360 static MonthViewCell * lastCell = 0; 1362 static MonthViewCell * lastCell = 0;
1361 1363
1362 if ( lastInc == inc && lastCell == mc ) 1364 if ( lastInc == inc && lastCell == mc )
1363 return; 1365 return;
1364 lastInc = inc; 1366 lastInc = inc;
1365 lastCell = mc; 1367 lastCell = mc;
1366 //qDebug("KOMonthView::incidenceHighlighted %d %d %d", inc, mc, mday ); 1368 //qDebug("KOMonthView::incidenceHighlighted %d %d %d", inc, mc, mday );
1367 1369
1368 bool weekview = false; 1370 bool weekview = false;
1369 uint index = 0; 1371 uint index = 0;
1370 for (uint i = 0; i < mCellsW.count(); ++i) { 1372 for (uint i = 0; i < mCellsW.count(); ++i) {
1371 if ( mCellsW[i] == mc ) { 1373 if ( mCellsW[i] == mc ) {
1372 weekview = true; 1374 weekview = true;
1373 index = i; 1375 index = i;
1374 break; 1376 break;
1375 } 1377 }
1376 } 1378 }
1377 QPtrVector<MonthViewCell> *cells; 1379 QPtrVector<MonthViewCell> *cells;
1378 if ( weekview ) 1380 if ( weekview )
1379 cells = &mCellsW; 1381 cells = &mCellsW;
1380 else { 1382 else {
1381 for (uint i = 0; i < mCells.count(); ++i) { 1383 for (uint i = 0; i < mCells.count(); ++i) {
1382 if ( mCells[i] == mc ) { 1384 if ( mCells[i] == mc ) {
1383 index = i; 1385 index = i;
1384 break; 1386 break;
1385 } 1387 }
1386 } 1388 }
1387 cells = &mCells; 1389 cells = &mCells;
1388 } 1390 }
1389 for (uint i = 0; i < (*cells).count(); ++i) { 1391 for (uint i = 0; i < (*cells).count(); ++i) {
1390 (*cells)[i]->deHighLight(); 1392 (*cells)[i]->deHighLight();
1391 } 1393 }
1392 if ( ! inc ) 1394 if ( ! inc )
1393 return; 1395 return;
1394 1396
1395 uint count = (*cells).count(); 1397 uint count = (*cells).count();
1396 bool goLeft = (mday > 1 && index > 0); 1398 bool goLeft = (mday > 1 && index > 0);
1397 bool goRight = (mday < 3 && mday > 0 && index < count -1); 1399 bool goRight = (mday < 3 && mday > 0 && index < count -1);
1398 for (uint iii = 1; iii < count; ++iii) { 1400 for (uint iii = 1; iii < count; ++iii) {
1399 if ( goLeft ) { 1401 if ( goLeft ) {
1400 int left = index - iii; 1402 int left = index - iii;
1401 if ( left >= 0 ) { 1403 if ( left >= 0 ) {
1402 if ( (*cells)[(uint)left]->doHighLight(inc) ) 1404 if ( (*cells)[(uint)left]->doHighLight(inc) )
1403 goLeft = false; 1405 goLeft = false;
1404 } else 1406 } else
1405 goLeft = false; 1407 goLeft = false;
1406 } 1408 }
1407 if ( goRight ) { 1409 if ( goRight ) {
1408 uint right = index + iii; 1410 uint right = index + iii;
1409 if ( right < count ) { 1411 if ( right < count ) {
1410 if ( (*cells)[right]->doHighLight(inc) ) 1412 if ( (*cells)[right]->doHighLight(inc) )
1411 goRight = false; 1413 goRight = false;
1412 1414
1413 } else 1415 } else
1414 goRight = false; 1416 goRight = false;
1415 } 1417 }
1416 1418
1417 } 1419 }
1418#if 0 1420#if 0
1419 if ( mday > 1 && index > 0 ) 1421 if ( mday > 1 && index > 0 )
1420 for (int i = index-1; i >= 0; --i) { 1422 for (int i = index-1; i >= 0; --i) {
1421 //qDebug("index %d iii %d ", index, i); 1423 //qDebug("index %d iii %d ", index, i);
1422 if ( (*cells)[(uint)i]->doHighLight(inc) ) 1424 if ( (*cells)[(uint)i]->doHighLight(inc) )
1423 break; 1425 break;
1424 } 1426 }
1425 if ( mday < 3 && mday > 0 && index < (*cells).count()-1) 1427 if ( mday < 3 && mday > 0 && index < (*cells).count()-1)
1426 for (uint i = index+1; i < (*cells).count(); ++i) { 1428 for (uint i = index+1; i < (*cells).count(); ++i) {
1427 if ( (*cells)[i]->doHighLight(inc) ) 1429 if ( (*cells)[i]->doHighLight(inc) )
1428 break; 1430 break;
1429 } 1431 }
1430#endif 1432#endif
1431 1433
1432} 1434}
1433void KOMonthView::selectInternalWeekNum ( int n ) 1435void KOMonthView::selectInternalWeekNum ( int n )
1434{ 1436{
1435 switchView(); 1437 switchView();
1436 if ( !KOPrefs::instance()->mMonthViewWeek ) 1438 if ( !KOPrefs::instance()->mMonthViewWeek )
1437 emit selectMonth (); 1439 emit selectMonth ();
1438 else 1440 else
1439 emit selectWeekNum ( n ); 1441 emit selectWeekNum ( n );
1440} 1442}
1441 1443
1442int KOMonthView::currentWeek() 1444int KOMonthView::currentWeek()
1443{ 1445{
1444 if ( mShowWeekView ) 1446 if ( mShowWeekView )
1445 return mWeekLabelsW[0]->getWeekNum(); 1447 return mWeekLabelsW[0]->getWeekNum();
1446 return mWeekLabels[0]->getWeekNum(); 1448 return mWeekLabels[0]->getWeekNum();
1447} 1449}
1448void KOMonthView::switchView() 1450void KOMonthView::switchView()
1449{ 1451{
1450 if ( selectedCell( ) ) 1452 if ( selectedCell( ) )
1451 selectedCell()->deselect(); 1453 selectedCell()->deselect();
1452 mShowWeekView = !mShowWeekView; 1454 mShowWeekView = !mShowWeekView;
1453 KOPrefs::instance()->mMonthViewWeek = mShowWeekView; 1455 KOPrefs::instance()->mMonthViewWeek = mShowWeekView;
1454 if ( clPending ) { 1456 if ( clPending ) {
1455 computeLayout(); 1457 computeLayout();
1456 updateConfig(); 1458 updateConfig();
1457 } 1459 }
1458 if ( mShowWeekView ) 1460 if ( mShowWeekView )
1459 mWidStack->raiseWidget( mWeekView ); 1461 mWidStack->raiseWidget( mWeekView );
1460 else 1462 else
1461 mWidStack->raiseWidget( mMonthView ); 1463 mWidStack->raiseWidget( mMonthView );
1462 clPending = false; 1464 clPending = false;
1463} 1465}
1464 1466
1465int KOMonthView::maxDatesHint() 1467int KOMonthView::maxDatesHint()
1466{ 1468{
1467 return mNumCells; 1469 return mNumCells;
1468} 1470}
1469 1471
1470int KOMonthView::currentDateCount() 1472int KOMonthView::currentDateCount()
1471{ 1473{
1472 return mNumCells; 1474 return mNumCells;
1473} 1475}
1474 1476
1475QPtrList<Incidence> KOMonthView::selectedIncidences() 1477QPtrList<Incidence> KOMonthView::selectedIncidences()
1476{ 1478{
1477 QPtrList<Incidence> selected; 1479 QPtrList<Incidence> selected;
1478 1480
1479 if ( mSelectedCell ) { 1481 if ( mSelectedCell ) {
1480 Incidence *incidence = mSelectedCell->selectedIncidence(); 1482 Incidence *incidence = mSelectedCell->selectedIncidence();
1481 if ( incidence ) selected.append( incidence ); 1483 if ( incidence ) selected.append( incidence );
1482 } 1484 }
1483 1485
1484 return selected; 1486 return selected;
1485} 1487}
1486 1488
1487DateList KOMonthView::selectedDates() 1489DateList KOMonthView::selectedDates()
1488{ 1490{
1489 DateList selected; 1491 DateList selected;
1490 1492
1491 if ( mSelectedCell ) { 1493 if ( mSelectedCell ) {
1492 QDate qd = mSelectedCell->selectedIncidenceDate(); 1494 QDate qd = mSelectedCell->selectedIncidenceDate();
1493 if ( qd.isValid() ) selected.append( qd ); 1495 if ( qd.isValid() ) selected.append( qd );
1494 } 1496 }
1495 1497
1496 return selected; 1498 return selected;
1497} 1499}
1498#if 0 1500#if 0
1499void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd, 1501void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd,
1500 const QDate &td) 1502 const QDate &td)
1501{ 1503{
1502#ifndef KORG_NOPRINTER 1504#ifndef KORG_NOPRINTER
1503 calPrinter->preview(CalPrinter::Month, fd, td); 1505 calPrinter->preview(CalPrinter::Month, fd, td);
1504#endif 1506#endif
1505} 1507}
1506#endif 1508#endif
1507void KOMonthView::updateConfig() 1509void KOMonthView::updateConfig()
1508{ 1510{
1509 1511
1510 int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); 1512 int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday();
1511 1513
1512 if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) { 1514 if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) {
1513 mWeekStartsMonday = true; 1515 mWeekStartsMonday = true;
1514 } 1516 }
1515 QFontMetrics fontmetric(mDayLabels[0]->font()); 1517 QFontMetrics fontmetric(mDayLabels[0]->font());
1516 mWidthLongDayLabel = 0; 1518 mWidthLongDayLabel = 0;
1517 1519
1518 for (int i = 0; i < 7; i++) { 1520 for (int i = 0; i < 7; i++) {
1519 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); 1521 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1));
1520 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; 1522 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
1521 } 1523 }
1522 bool temp = mShowSatSunComp ; 1524 bool temp = mShowSatSunComp ;
1523 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; 1525 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
1524 if ( ! mShowWeekView ) { 1526 if ( ! mShowWeekView ) {
1525 if ( temp != KOPrefs::instance()->mMonthViewSatSunTog ) 1527 if ( temp != KOPrefs::instance()->mMonthViewSatSunTog )
1526 computeLayout(); 1528 computeLayout();
1527 } else 1529 } else
1528 doComputeLayoutWeek(); 1530 doComputeLayoutWeek();
1529 updateDayLabels(); 1531 updateDayLabels();
1530 //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks); 1532 //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks);
1531 //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks; 1533 //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks;
1532 //resizeEvent( 0 ); 1534 //resizeEvent( 0 );
1533 for (uint i = 0; i < mCells.count(); ++i) { 1535 for (uint i = 0; i < mCells.count(); ++i) {
1534 mCells[i]->updateConfig(); 1536 mCells[i]->updateConfig();
1535 } 1537 }
1536 1538
1537 for (uint i = 0; i < mCellsW.count(); ++i) { 1539 for (uint i = 0; i < mCellsW.count(); ++i) {
1538 mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont); 1540 mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont);
1539 } 1541 }
1540#ifdef DESKTOP_VERSION 1542#ifdef DESKTOP_VERSION
1541 MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips); 1543 MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips);
1542#endif 1544#endif
1543 updateView(); 1545 updateView();
1544} 1546}
1545 1547
1546void KOMonthView::updateDayLabels() 1548void KOMonthView::updateDayLabels()
1547{ 1549{
1548 1550
1549 QPtrVector<QLabel> *mDayLabelsT; 1551 QPtrVector<QLabel> *mDayLabelsT;
1550 1552
1551 mDayLabelsT = &mDayLabelsW; 1553 mDayLabelsT = &mDayLabelsW;
1552 for (int i = 0; i < 7; i++) { 1554 for (int i = 0; i < 7; i++) {
1553 { 1555 {
1554 bool show = mShortDayLabelsW; 1556 bool show = mShortDayLabelsW;
1555 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) 1557 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() )
1556 show = true; 1558 show = true;
1557 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); 1559 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show));
1558 } 1560 }
1559 } 1561 }
1560 mDayLabelsT = &mDayLabels; 1562 mDayLabelsT = &mDayLabels;
1561 for (int i = 0; i < 7; i++) { 1563 for (int i = 0; i < 7; i++) {
1562 if (KGlobal::locale()->weekStartsMonday() || KOPrefs::instance()->mMonthViewSatSunTog ) { 1564 if (KGlobal::locale()->weekStartsMonday() || KOPrefs::instance()->mMonthViewSatSunTog ) {
1563 bool show = mShortDayLabelsM; 1565 bool show = mShortDayLabelsM;
1564 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) 1566 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() )
1565 show = true; 1567 show = true;
1566 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); 1568 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show));
1567 } else { 1569 } else {
1568 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM)); 1570 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM));
1569 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM)); 1571 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM));
1570 1572
1571 } 1573 }
1572 } 1574 }
1573 1575
1574} 1576}
1575 1577
1576void KOMonthView::clearList() 1578void KOMonthView::clearList()
1577{ 1579{
1578 unsigned int i; 1580 unsigned int i;
1579 for( i = 0; i < mCells.size(); ++i ) { 1581 for( i = 0; i < mCells.size(); ++i ) {
1580 mCells[i]->clear(); 1582 mCells[i]->clear();
1581 } 1583 }
1582 for( i = 0; i < mCellsW.size(); ++i ) { 1584 for( i = 0; i < mCellsW.size(); ++i ) {
1583 mCellsW[i]->clear(); 1585 mCellsW[i]->clear();
1584 } 1586 }
1585} 1587}
1586void KOMonthView::showDates(const QDate &start, const QDate &) 1588void KOMonthView::showDates(const QDate &start, const QDate &)
1587{ 1589{
1588 // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl; 1590 // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl;
1589 1591
1590 QPtrVector<MonthViewCell> *cells; 1592 QPtrVector<MonthViewCell> *cells;
1591 QPtrVector<QLabel> *dayLabels; 1593 QPtrVector<QLabel> *dayLabels;
1592 QPtrVector<KOWeekButton> *weekLabels; 1594 QPtrVector<KOWeekButton> *weekLabels;
1593 uint weekNum = 6; 1595 uint weekNum = 6;
1594 mStartDate = start; 1596 mStartDate = start;
1595 if ( mShowWeekView ) { 1597 if ( mShowWeekView ) {
1596 weekNum = 1; 1598 weekNum = 1;
1597 cells = &mCellsW; 1599 cells = &mCellsW;
1598 dayLabels = &mDayLabelsW; 1600 dayLabels = &mDayLabelsW;
1599 weekLabels = &mWeekLabelsW; 1601 weekLabels = &mWeekLabelsW;
1600 if ( !KGlobal::locale()->weekStartsMonday() ) { 1602 if ( !KGlobal::locale()->weekStartsMonday() ) {
1601 mStartDate = mStartDate.addDays( 1 ); 1603 mStartDate = mStartDate.addDays( 1 );
1602 } 1604 }
1603 } else { 1605 } else {
1604 cells = &mCells; 1606 cells = &mCells;
1605 dayLabels = &mDayLabels; 1607 dayLabels = &mDayLabels;
1606 weekLabels = &mWeekLabels; 1608 weekLabels = &mWeekLabels;
1607 } 1609 }
1608 1610
1609 int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); 1611 int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday();
1610 1612
1611 if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) { 1613 if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) {
1612 mWeekStartsMonday = true; 1614 mWeekStartsMonday = true;
1613 } 1615 }
1614 int startWeekDay = mWeekStartsMonday ? 1 : 7; 1616 int startWeekDay = mWeekStartsMonday ? 1 : 7;
1615 1617
1616 while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) { 1618 while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) {
1617 mStartDate = mStartDate.addDays( -1 ); 1619 mStartDate = mStartDate.addDays( -1 );
1618 } 1620 }
1619 uint i; 1621 uint i;
1620 for( i = 0; i < (*cells).size(); ++i ) { 1622 for( i = 0; i < (*cells).size(); ++i ) {
1621 QDate date = mStartDate.addDays( i ); 1623 QDate date = mStartDate.addDays( i );
1622 (*cells)[i]->setDate( date ); 1624 (*cells)[i]->setDate( date );
1623 1625
1624#ifndef KORG_NOPLUGINS 1626#ifndef KORG_NOPLUGINS
1625 // add holiday, if present 1627 // add holiday, if present
1626 QString hstring(KOCore::self()->holiday(date)); 1628 QString hstring(KOCore::self()->holiday(date));
1627 (*cells)[i]->setHoliday( hstring ); 1629 (*cells)[i]->setHoliday( hstring );
1628#endif 1630#endif
1629 1631
1630 } 1632 }
1631 QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 ); 1633 QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 );
1632 for( i = 0; i < weekNum; ++i ) { 1634 for( i = 0; i < weekNum; ++i ) {
1633 int wno; 1635 int wno;
1634 // remember, according to ISO 8601, the first week of the year is the 1636 // remember, according to ISO 8601, the first week of the year is the
1635 // first week that contains a thursday. Thus we must subtract off 4, 1637 // first week that contains a thursday. Thus we must subtract off 4,
1636 // not just 1. 1638 // not just 1.
1637 int dayOfYear = date.dayOfYear(); 1639 int dayOfYear = date.dayOfYear();
1638 if (dayOfYear % 7 != 0) 1640 if (dayOfYear % 7 != 0)
1639 wno = dayOfYear / 7 + 1; 1641 wno = dayOfYear / 7 + 1;
1640 else 1642 else
1641 wno =dayOfYear / 7; 1643 wno =dayOfYear / 7;
1642 (*weekLabels)[i]->setWeekNum( wno ); 1644 (*weekLabels)[i]->setWeekNum( wno );
1643 date = date.addDays( 7 ); 1645 date = date.addDays( 7 );
1644 } 1646 }
1645 updateView(); 1647 updateView();
1646} 1648}
1647 1649
1648void KOMonthView::showEvents(QPtrList<Event>) 1650void KOMonthView::showEvents(QPtrList<Event>)
1649{ 1651{
1650 qDebug("KOMonthView::selectEvents is not implemented yet. "); 1652 qDebug("KOMonthView::selectEvents is not implemented yet. ");
1651} 1653}
1652 1654
1653void KOMonthView::changeEventDisplay(Event *, int) 1655void KOMonthView::changeEventDisplay(Event *, int)
1654{ 1656{
1655 // this should be re-written to be much more efficient, but this 1657 // this should be re-written to be much more efficient, but this
1656 // quick-and-dirty-hack gets the job done for right now. 1658 // quick-and-dirty-hack gets the job done for right now.
1657 //qDebug("KOMonthView::changeEventDisplay "); 1659 //qDebug("KOMonthView::changeEventDisplay ");
1658 updateView(); 1660 updateView();
1659} 1661}
1660 1662
1661void KOMonthView::updateView() 1663void KOMonthView::updateView()
1662{ 1664{
1663 1665
1664 if ( !updatePossible ) 1666 if ( !updatePossible )
1665 return; 1667 return;
1666 //qDebug("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU "); 1668 //qDebug("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU ");
1667 //QTime ti; 1669 //QTime ti;
1668 //ti.start(); 1670 //ti.start();
1669 clearSelection(); 1671 clearSelection();
1670 QPtrVector<MonthViewCell> *cells; 1672 QPtrVector<MonthViewCell> *cells;
1671 if ( mShowWeekView ) { 1673 if ( mShowWeekView ) {
1672 cells = &mCellsW; 1674 cells = &mCellsW;
1673 } else { 1675 } else {
1674 cells = &mCells; 1676 cells = &mCells;
1675 } 1677 }
1676#if 1 1678#if 1
1677 int i; 1679 int i;
1678 int timeSpan = (*cells).size()-1; 1680 int timeSpan = (*cells).size()-1;
1679 if ( KOPrefs::instance()->mMonthViewWeek ) 1681 if ( KOPrefs::instance()->mMonthViewWeek )
1680 timeSpan = 6; 1682 timeSpan = 6;
1681 for( i = 0; i < timeSpan + 1; ++i ) { 1683 for( i = 0; i < timeSpan + 1; ++i ) {
1682 (*cells)[i]->startUpdateCell(); 1684 (*cells)[i]->startUpdateCell();
1683 } 1685 }
1684 1686
1685 QPtrList<Event> events = calendar()->events(); 1687 QPtrList<Event> events = calendar()->events();
1686 Event *event; 1688 Event *event;
1687 QDateTime dt; 1689 QDateTime dt;
1688 QDate endDate = mStartDate.addDays( timeSpan ); 1690 QDate endDate = mStartDate.addDays( timeSpan );
1689 for( event = events.first(); event; event = events.next() ) { // for event 1691 for( event = events.first(); event; event = events.next() ) { // for event
1690 if ( event->doesRecur() ) { 1692 if ( event->doesRecur() ) {
1691 bool last; 1693 bool last;
1692 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); 1694 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last );
1693 QDateTime incidenceEnd; 1695 QDateTime incidenceEnd;
1694 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); 1696 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() );
1695 bool invalid = false; 1697 bool invalid = false;
1696 while( true ) { 1698 while( true ) {
1697 if ( incidenceStart.isValid() ) { 1699 if ( incidenceStart.isValid() ) {
1698 incidenceEnd = incidenceStart.addDays( eventlen ); 1700 incidenceEnd = incidenceStart.addDays( eventlen );
1699 int st = incidenceStart.date().daysTo( endDate ); 1701 int st = incidenceStart.date().daysTo( endDate );
1700 if ( st >= 0 ) { // start before timeend 1702 if ( st >= 0 ) { // start before timeend
1701 int end = mStartDate.daysTo( incidenceEnd.date() ); 1703 int end = mStartDate.daysTo( incidenceEnd.date() );
1702 if ( end >= 0 ) { // end after timestart --- got one! 1704 if ( end >= 0 ) { // end after timestart --- got one!
1703 //normalize 1705 //normalize
1704 st = timeSpan - st; 1706 st = timeSpan - st;
1705 if ( st < 0 ) st = 0; 1707 if ( st < 0 ) st = 0;
1706 if ( end > timeSpan ) end = timeSpan; 1708 if ( end > timeSpan ) end = timeSpan;
1707 int iii; 1709 int iii;
1708 //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); 1710 //qDebug("found %s %d %d ",event->summary().latin1(), st, end );
1709 for ( iii = st;iii<= end;++iii) 1711 for ( iii = st;iii<= end;++iii)
1710 (*cells)[iii]->insertEvent( event ); 1712 (*cells)[iii]->insertEvent( event );
1711 } 1713 }
1712 } 1714 }
1713 } else { 1715 } else {
1714 if ( invalid ) 1716 if ( invalid )
1715 break; 1717 break;
1716 invalid = true; 1718 invalid = true;
1717 //qDebug("invalid %s", event->summary().latin1()); 1719 //qDebug("invalid %s", event->summary().latin1());
1718 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; 1720 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );;
1719 } 1721 }
1720 if ( last ) 1722 if ( last )
1721 break; 1723 break;
1722 bool ok; 1724 bool ok;
1723 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); 1725 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok );
1724 if ( ! ok ) 1726 if ( ! ok )
1725 break; 1727 break;
1726 if ( incidenceStart.date() > endDate ) 1728 if ( incidenceStart.date() > endDate )
1727 break; 1729 break;
1728 } 1730 }
1729 } else { // no recur 1731 } else { // no recur
1730 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") ) 1732 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") )
1731 if ( event->uid().left(15) == QString("last-syncEvent-") ) 1733 if ( event->uid().left(15) == QString("last-syncEvent-") )
1732 continue; 1734 continue;
1733 int st = event->dtStart().date().daysTo( endDate ); 1735 int st = event->dtStart().date().daysTo( endDate );
1734 if ( st >= 0 ) { // start before timeend 1736 if ( st >= 0 ) { // start before timeend
1735 int end = mStartDate.daysTo( event->dtEnd().date() ); 1737 int end = mStartDate.daysTo( event->dtEnd().date() );
1736 if ( end >= 0 ) { // end after timestart --- got one! 1738 if ( end >= 0 ) { // end after timestart --- got one!
1737 //normalize 1739 //normalize
1738 st = timeSpan - st; 1740 st = timeSpan - st;
1739 if ( st < 0 ) st = 0; 1741 if ( st < 0 ) st = 0;
1740 if ( end > timeSpan ) end = timeSpan; 1742 if ( end > timeSpan ) end = timeSpan;
1741 int iii; 1743 int iii;
1742 for ( iii = st;iii<= end;++iii) 1744 for ( iii = st;iii<= end;++iii)
1743 (*cells)[iii]->insertEvent( event ); 1745 (*cells)[iii]->insertEvent( event );
1744 } 1746 }
1745 } 1747 }
1746 } 1748 }
1747 } 1749 }
1748 // insert due todos 1750 // insert due todos
1749 QPtrList<Todo> todos = calendar()->todos( ); 1751 QPtrList<Todo> todos = calendar()->todos( );
1750 Todo *todo; 1752 Todo *todo;
1751 for(todo = todos.first(); todo; todo = todos.next()) { 1753 for(todo = todos.first(); todo; todo = todos.next()) {
1752 //insertTodo( todo ); 1754 //insertTodo( todo );
1753 if ( todo->hasDueDate() ) { 1755 if ( todo->hasDueDate() ) {
1754 int day = mStartDate.daysTo( todo->dtDue().date() ); 1756 int day = mStartDate.daysTo( todo->dtDue().date() );
1755 if ( day >= 0 && day < timeSpan + 1) { 1757 if ( day >= 0 && day < timeSpan + 1) {
1756 (*cells)[day]->insertTodo( todo ); 1758 (*cells)[day]->insertTodo( todo );
1757 } 1759 }
1758 } 1760 }
1759 } 1761 }
1760 1762
1761 for( i = 0; i < timeSpan+1; ++i ) { 1763 for( i = 0; i < timeSpan+1; ++i ) {
1762 (*cells)[i]->finishUpdateCell(); 1764 (*cells)[i]->finishUpdateCell();
1763 } 1765 }
1764 processSelectionChange(); 1766 processSelectionChange();
1765 //qApp->processEvents(); 1767 //qApp->processEvents();
1766 for( i = 0; i < timeSpan+1; ++i ) { 1768 for( i = 0; i < timeSpan+1; ++i ) {
1767 //(*cells)[i]->repaintfinishUpdateCell(); 1769 //(*cells)[i]->repaintfinishUpdateCell();
1768 QTimer::singleShot( 0, (*cells)[i], SLOT ( repaintfinishUpdateCell() ) ); 1770 QTimer::singleShot( 0, (*cells)[i], SLOT ( repaintfinishUpdateCell() ) );
1769 } 1771 }
1770 setKeyBFocus(); 1772 setKeyBFocus();
1771#else 1773#else
1772 // old code 1774 // old code
1773 //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "); 1775 //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ");
1774 int i; 1776 int i;
1775 for( i = 0; i < (*cells).count(); ++i ) { 1777 for( i = 0; i < (*cells).count(); ++i ) {
1776 (*cells)[i]->updateCell(); 1778 (*cells)[i]->updateCell();
1777 } 1779 }
1778 1780
1779 //qDebug("KOMonthView::updateView() "); 1781 //qDebug("KOMonthView::updateView() ");
1780 processSelectionChange(); 1782 processSelectionChange();
1781 // qDebug("---------------------------------------------------------------------+ "); 1783 // qDebug("---------------------------------------------------------------------+ ");
1782 (*cells)[0]->setFocus(); 1784 (*cells)[0]->setFocus();
1783#endif 1785#endif
1784 1786
1785 //qDebug("update time %d ", ti.elapsed()); 1787 //qDebug("update time %d ", ti.elapsed());
1786} 1788}
1787 1789
1788void KOMonthView::setKeyBoardFocus() 1790void KOMonthView::setKeyBoardFocus()
1789{ 1791{
1790 //qDebug("KOMonthView::setKeyBoardFocus() "); 1792 //qDebug("KOMonthView::setKeyBoardFocus() ");
1791 bool shootAgain = false; 1793 bool shootAgain = false;
1792 if ( mShowWeekView ) { 1794 if ( mShowWeekView ) {
1793 shootAgain = !mWeekLabelsW[1]->hasFocus(); 1795 shootAgain = !mWeekLabelsW[1]->hasFocus();
1794 mWeekLabelsW[1]->setFocus(); 1796 mWeekLabelsW[1]->setFocus();
1795 } 1797 }
1796 else { 1798 else {
1797 shootAgain = !mWeekLabels[mNumWeeks]->hasFocus(); 1799 shootAgain = !mWeekLabels[mNumWeeks]->hasFocus();
1798 mWeekLabels[mNumWeeks]->setFocus(); 1800 mWeekLabels[mNumWeeks]->setFocus();
1799 } 1801 }
1800 --mKBFcounter; 1802 --mKBFcounter;
1801 if ( shootAgain && mKBFcounter > 0 ) { 1803 if ( shootAgain && mKBFcounter > 0 ) {
1802 QTimer::singleShot( 50, this, SLOT ( setKeyBoardFocus() ) ); 1804 QTimer::singleShot( 50, this, SLOT ( setKeyBoardFocus() ) );
1803 } 1805 }
1804} 1806}
1805void KOMonthView::setKeyBFocus() 1807void KOMonthView::setKeyBFocus()
1806{ 1808{
1807 //qDebug("KOMonthView::setKeyBFocus() "); 1809 //qDebug("KOMonthView::setKeyBFocus() ");
1808 mKBFcounter = 10; 1810 mKBFcounter = 10;
1809 QTimer::singleShot( 0, this, SLOT ( setKeyBoardFocus() ) ); 1811 QTimer::singleShot( 0, this, SLOT ( setKeyBoardFocus() ) );
1810} 1812}
1811void KOMonthView::resizeEvent(QResizeEvent * e) 1813void KOMonthView::resizeEvent(QResizeEvent * e)
1812{ 1814{
1813 //qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height()); 1815 //qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height());
1814 if ( isVisible() ) { 1816 if ( isVisible() ) {
1815 //qDebug("KOMonthView::isVisible "); 1817 //qDebug("KOMonthView::isVisible ");
1816 slotComputeLayout(); 1818 slotComputeLayout();
1817 } else 1819 } else
1818 mComputeLayoutTimer->start( 100 ); 1820 mComputeLayoutTimer->start( 100 );
1819 if ( e ) 1821 if ( e )
1820 KOEventView::resizeEvent( e ); 1822 KOEventView::resizeEvent( e );
1821} 1823}
1822 1824
1823void KOMonthView::slotComputeLayout() 1825void KOMonthView::slotComputeLayout()
1824{ 1826{
1825 mComputeLayoutTimer->stop(); 1827 mComputeLayoutTimer->stop();
1826 //qDebug("KOMonthView::Post - resizeEvent %d %d ", width(), height() ); 1828 //qDebug("KOMonthView::Post - resizeEvent %d %d ", width(), height() );
1827 computeLayout(); 1829 computeLayout();
1828 clPending = true; 1830 clPending = true;
1829 setKeyBFocus(); 1831 setKeyBFocus();
1830} 1832}
1831 1833
1832void KOMonthView::doComputeLayoutWeek() 1834void KOMonthView::doComputeLayoutWeek()
1833{ 1835{
1834 1836
1835 int daysToShow; 1837 int daysToShow;
1836 bool combinedSatSun = false; 1838 bool combinedSatSun = false;
1837 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { 1839 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) {
1838 daysToShow = 6; 1840 daysToShow = 6;
1839 combinedSatSun = true; 1841 combinedSatSun = true;
1840 } 1842 }
1841 int wid = width();//e 1843 int wid = width();//e
1842 int hei = height()-1-mNavigatorBar->height(); 1844 int hei = height()-1-mNavigatorBar->height();
1843#ifdef DESKTOP_VERSION 1845#ifdef DESKTOP_VERSION
1844 if ( !KOPrefs::instance()->mMonthViewWeekRowlayout ) { 1846 if ( !KOPrefs::instance()->mMonthViewWeekRowlayout ) {
1845 daysToShow = 2; 1847 daysToShow = 2;
1846 } else 1848 } else
1847#endif 1849#endif
1848 { 1850 {
1849 if ( wid < hei + 40 ) 1851 if ( wid < hei + 40 )
1850 daysToShow = 2; 1852 daysToShow = 2;
1851 else 1853 else
1852 daysToShow = 3; 1854 daysToShow = 3;
1853 } 1855 }
1854 bool landscape = (daysToShow == 3); 1856 bool landscape = (daysToShow == 3);
1855 mShowSatSunComp = true; 1857 mShowSatSunComp = true;
1856 combinedSatSun = true; 1858 combinedSatSun = true;
1857 1859
1858 //qDebug("KOMonthView::computeLayout() WWW ------------------------------------ "); 1860 //qDebug("KOMonthView::computeLayout() WWW ------------------------------------ ");
1859 QFontMetrics fm ( mWeekLabels[0]->font() ); 1861 QFontMetrics fm ( mWeekLabels[0]->font() );
1860 int weeklabelwid = fm.width( "888" ); 1862 int weeklabelwid = fm.width( "888" );
1861 wid -= weeklabelwid; 1863 wid -= weeklabelwid;
1862 1864
1863 int colWid = wid / daysToShow; 1865 int colWid = wid / daysToShow;
1864 int dayLabelHei = mDayLabelsW[0]->sizeHint().height(); 1866 int dayLabelHei = mDayLabelsW[0]->sizeHint().height();
1865 int cellHei = (hei - (5- daysToShow )*dayLabelHei) /(5- daysToShow ); 1867 int cellHei = (hei - (5- daysToShow )*dayLabelHei) /(5- daysToShow );
1866 int colModulo = wid % daysToShow; 1868 int colModulo = wid % daysToShow;
1867 int rowModulo = (hei- (5- daysToShow )*dayLabelHei) % daysToShow-1; 1869 int rowModulo = (hei- (5- daysToShow )*dayLabelHei) % daysToShow-1;
1868 //qDebug("rowmod %d ", rowModulo); 1870 //qDebug("rowmod %d ", rowModulo);
1869 int i; 1871 int i;
1870 int x,y,w,h; 1872 int x,y,w,h;
1871 x= 0; 1873 x= 0;
1872 y= 0; 1874 y= 0;
1873 w = colWid; 1875 w = colWid;
1874 h = dayLabelHei ; 1876 h = dayLabelHei ;
1875 for ( i = 0; i < 7; i++) { 1877 for ( i = 0; i < 7; i++) {
1876 if ( i && !( i % daysToShow) && i < 6) { 1878 if ( i && !( i % daysToShow) && i < 6) {
1877 y += hei/(5-daysToShow); 1879 y += hei/(5-daysToShow);
1878 x = 0; 1880 x = 0;
1879 w = colWid; 1881 w = colWid;
1880 } 1882 }
1881 if ( ((i) % daysToShow) >= daysToShow-colModulo ) { 1883 if ( ((i) % daysToShow) >= daysToShow-colModulo ) {
1882 ++w; 1884 ++w;
1883 } 1885 }
1884 int xC,yC,wC,hC; 1886 int xC,yC,wC,hC;
1885 if ( i >= 5 ) { 1887 if ( i >= 5 ) {
1886 int wi = width() - x - weeklabelwid; 1888 int wi = width() - x - weeklabelwid;
1887 if ( i == 5 ) { 1889 if ( i == 5 ) {
1888 xC = x+weeklabelwid; 1890 xC = x+weeklabelwid;
1889 yC = y; 1891 yC = y;
1890 wC = wi/2+wi%2; 1892 wC = wi/2+wi%2;
1891 hC = h; 1893 hC = h;
1892 } else { 1894 } else {
1893 xC = x+weeklabelwid; 1895 xC = x+weeklabelwid;
1894 yC = y; 1896 yC = y;
1895 wC = wi; 1897 wC = wi;
1896 hC = h; 1898 hC = h;
1897 } 1899 }
1898 x = x - w + wi - (wi/2 ); 1900 x = x - w + wi - (wi/2 );
1899 } 1901 }
1900 else { 1902 else {
1901 int wi = w; 1903 int wi = w;
1902 if ( !(( i+1) % daysToShow)) { 1904 if ( !(( i+1) % daysToShow)) {
1903 wi = width() - x - weeklabelwid; 1905 wi = width() - x - weeklabelwid;
1904 } 1906 }
1905 xC = x+weeklabelwid; 1907 xC = x+weeklabelwid;
1906 yC = y; 1908 yC = y;
1907 wC = wi; 1909 wC = wi;
1908 hC = h; 1910 hC = h;
1909 } 1911 }
1910 mDayLabelsW[mapWeekLayout(i,landscape)]->setGeometry( xC,yC,wC,hC); 1912 mDayLabelsW[mapWeekLayout(i,landscape)]->setGeometry( xC,yC,wC,hC);
1911 1913
1912 1914
1913 x += w; 1915 x += w;
1914 } 1916 }
1915 x= 0; 1917 x= 0;
1916 y= dayLabelHei; 1918 y= dayLabelHei;
1917 w = colWid; 1919 w = colWid;
1918 h = cellHei; 1920 h = cellHei;
1919 int max = 0; 1921 int max = 0;
1920 int w_count = mCellsW.count(); 1922 int w_count = mCellsW.count();
1921 for ( i = 0; i < w_count; ++i) { 1923 for ( i = 0; i < w_count; ++i) {
1922 if ( i > 6 ) { 1924 if ( i > 6 ) {
1923 mCellsW[i]->hide(); 1925 mCellsW[i]->hide();
1924 continue; 1926 continue;
1925 } 1927 }
1926 1928
1927 w = colWid; 1929 w = colWid;
1928 if ( ((i) % daysToShow) >= daysToShow-colModulo ) { 1930 if ( ((i) % daysToShow) >= daysToShow-colModulo ) {
1929 ++w; 1931 ++w;
1930 } 1932 }
1931 if ( i == (daysToShow-1-rowModulo)*7) 1933 if ( i == (daysToShow-1-rowModulo)*7)
1932 ++h; 1934 ++h;
1933 1935
1934 int xC,yC,wC,hC; 1936 int xC,yC,wC,hC;
1935 if ( i >= 5 ) { 1937 if ( i >= 5 ) {
1936 if ( i ==5 ) { 1938 if ( i ==5 ) {
1937 max = h/2; 1939 max = h/2;
1938 xC = x+weeklabelwid; 1940 xC = x+weeklabelwid;
1939 yC = y; 1941 yC = y;
1940 wC = w; 1942 wC = w;
1941 hC = max; 1943 hC = max;
1942 x -= w ;y += h/2; 1944 x -= w ;y += h/2;
1943 } else { 1945 } else {
1944 if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) { 1946 if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) {
1945 ++w; 1947 ++w;
1946 } 1948 }
1947 max = h-h/2; 1949 max = h-h/2;
1948 xC = x+weeklabelwid; 1950 xC = x+weeklabelwid;
1949 yC = y; 1951 yC = y;
1950 wC = w; 1952 wC = w;
1951 hC = max; 1953 hC = max;
1952 y -= h/2; 1954 y -= h/2;
1953 } 1955 }
1954 } else { 1956 } else {
1955 max = h; 1957 max = h;
1956 xC = x+weeklabelwid; 1958 xC = x+weeklabelwid;
1957 yC = y; 1959 yC = y;
1958 wC = w; 1960 wC = w;
1959 hC = h; 1961 hC = h;
1960 } 1962 }
1961 mCellsW[mapWeekLayout(i,landscape)]->setGeometry ( xC,yC,wC,hC ); 1963 mCellsW[mapWeekLayout(i,landscape)]->setGeometry ( xC,yC,wC,hC );
1962 1964
1963 1965
1964 x += w; 1966 x += w;
1965 if ( x + w/2 > wid ) { 1967 if ( x + w/2 > wid ) {
1966 x = 0; 1968 x = 0;
1967 y += h+dayLabelHei ; 1969 y += h+dayLabelHei ;
1968 } 1970 }
1969 //mCellsW[i]->dateLabel()->setMaximumHeight( max - mCellsW[i]->lineWidth()*2 ); 1971 //mCellsW[i]->dateLabel()->setMaximumHeight( max - mCellsW[i]->lineWidth()*2 );
1970 } 1972 }
1971 y= dayLabelHei; 1973 y= dayLabelHei;
1972 h = cellHei ; 1974 h = cellHei ;
1973 mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei); 1975 mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei);
1974 mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei); 1976 mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei);
1975 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); 1977 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height());
1976 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); 1978 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height());
1977 mShortDayLabelsW = mDayLabelsW[0]->width()-2 < mWidthLongDayLabel ; 1979 mShortDayLabelsW = mDayLabelsW[0]->width()-2 < mWidthLongDayLabel ;
1978 updateDayLabels(); 1980 updateDayLabels();
1979 //bool forceUpdate = !updatePossible; 1981 //bool forceUpdate = !updatePossible;
1980 updatePossible = true; 1982 updatePossible = true;
1981 //mWeekLabels[mNumWeeks]->setText( i18n("M")); 1983 //mWeekLabels[mNumWeeks]->setText( i18n("M"));
1982 //if ( forceUpdate ) 1984 //if ( forceUpdate )
1983 // updateView(); 1985 // updateView();
1984} 1986}
1985void KOMonthView::computeLayoutWeek() 1987void KOMonthView::computeLayoutWeek()
1986{ 1988{
1987 static int lastWid = 0; 1989 static int lastWid = 0;
1988 static int lastHei = 0; 1990 static int lastHei = 0;
1989 int tWid = topLevelWidget()->size().width(); 1991 int tWid = topLevelWidget()->size().width();
1990 int tHei = topLevelWidget()->size().height(); 1992 int tHei = topLevelWidget()->size().height();
1991 int wid = width();//e 1993 int wid = width();//e
1992 int hei = height()-1-mNavigatorBar->height(); 1994 int hei = height()-1-mNavigatorBar->height();
1993 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) 1995 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei )
1994 return; 1996 return;
1995 1997
1996 if ( lastWid == width() && lastHei == height() ) { 1998 if ( lastWid == width() && lastHei == height() ) {
1997 //qDebug("KOListWeekView::No compute layout needed "); 1999 //qDebug("KOListWeekView::No compute layout needed ");
1998 return; 2000 return;
1999 } 2001 }
2000 lastWid = width(); 2002 lastWid = width();
2001 lastHei = height(); 2003 lastHei = height();
2002 doComputeLayoutWeek(); 2004 doComputeLayoutWeek();
2003} 2005}
2004int KOMonthView::mapWeekLayout( int index, bool landscape ) 2006int KOMonthView::mapWeekLayout( int index, bool landscape )
2005{ 2007{
2006 if ( KOPrefs::instance()->mMonthViewWeekRowlayout ) 2008 if ( KOPrefs::instance()->mMonthViewWeekRowlayout )
2007 return index; 2009 return index;
2008 int diff = 0; 2010 int diff = 0;
2009 if ( !landscape ) diff = 1; 2011 if ( !landscape ) diff = 1;
2010 switch( index ) { 2012 switch( index ) {
2011 case 0: 2013 case 0:
2012 case 5: 2014 case 5:
2013 case 6: 2015 case 6:
2014 return index; 2016 return index;
2015 break; 2017 break;
2016 case 1: 2018 case 1:
2017 return 2+diff; 2019 return 2+diff;
2018 break; 2020 break;
2019 case 2: 2021 case 2:
2020 return 4-(3*diff); 2022 return 4-(3*diff);
2021 break; 2023 break;
2022 case 3: 2024 case 3:
2023 return 1+(3*diff); 2025 return 1+(3*diff);
2024 break; 2026 break;
2025 case 4: 2027 case 4:
2026 return 3-diff; 2028 return 3-diff;
2027 break; 2029 break;
2028 default: 2030 default:
2029 qDebug("KO: Error in mapping week layout "); 2031 qDebug("KO: Error in mapping week layout ");
2030 return index; 2032 return index;
2031 break; 2033 break;
2032 } 2034 }
2033 return index; 2035 return index;
2034} 2036}
2035void KOMonthView::computeLayout() 2037void KOMonthView::computeLayout()
2036{ 2038{
2037 2039
2038 2040
2039 static int lastWid = 0; 2041 static int lastWid = 0;
2040 static int lastHei = 0; 2042 static int lastHei = 0;
2041 2043
2042 if ( mShowWeekView ){ 2044 if ( mShowWeekView ){
2043 computeLayoutWeek(); 2045 computeLayoutWeek();
2044 return; 2046 return;
2045 } 2047 }
2046 int daysToShow = 7; 2048 int daysToShow = 7;
2047 bool combinedSatSun = false; 2049 bool combinedSatSun = false;
2048 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { 2050 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) {
2049 daysToShow = 6; 2051 daysToShow = 6;
2050 combinedSatSun = true; 2052 combinedSatSun = true;
2051 } 2053 }
2052 int tWid = topLevelWidget()->size().width(); 2054 int tWid = topLevelWidget()->size().width();
2053 int tHei = topLevelWidget()->size().height(); 2055 int tHei = topLevelWidget()->size().height();
2054 2056
2055 int wid = width();//e 2057 int wid = width();//e
2056 int hei = height()-1-mNavigatorBar->height(); 2058 int hei = height()-1-mNavigatorBar->height();
2057 2059
2058 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) { 2060 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) {
2059 return; 2061 return;
2060 } 2062 }
2061 if ( lastWid == width() && lastHei == height() ){ 2063 if ( lastWid == width() && lastHei == height() ){
2062 //qDebug("KOMonthview::No compute layout needed "); 2064 //qDebug("KOMonthview::No compute layout needed ");
2063 return; 2065 return;
2064 } 2066 }
2065 2067
2066 lastWid = width(); 2068 lastWid = width();
2067 lastHei = height(); 2069 lastHei = height();
2068 //qDebug("KOMonthView::computeLayout() MMM ------------------- "); 2070 //qDebug("KOMonthView::computeLayout() MMM ------------------- ");
2069 QFontMetrics fm ( mWeekLabels[0]->font() ); 2071 QFontMetrics fm ( mWeekLabels[0]->font() );
2070 int weeklabelwid = fm.width( "888" ); 2072 int weeklabelwid = fm.width( "888" );
2071 wid -= weeklabelwid; 2073 wid -= weeklabelwid;
2072 2074
2073 int colWid = wid / daysToShow; 2075 int colWid = wid / daysToShow;
2074 int dayLabelHei = mDayLabels[0]->sizeHint().height(); 2076 int dayLabelHei = mDayLabels[0]->sizeHint().height();
2075 int cellHei = (hei - dayLabelHei) /6; 2077 int cellHei = (hei - dayLabelHei) /6;
2076 int colModulo = wid % daysToShow; 2078 int colModulo = wid % daysToShow;
2077 int rowModulo = (hei- dayLabelHei) % 6; 2079 int rowModulo = (hei- dayLabelHei) % 6;
2078 //qDebug("rowmod %d ", rowModulo); 2080 //qDebug("rowmod %d ", rowModulo);
2079 int i; 2081 int i;
2080 int x,y,w,h; 2082 int x,y,w,h;
2081 x= 0; 2083 x= 0;
2082 y= 0; 2084 y= 0;
2083 w = colWid; 2085 w = colWid;
2084 h = dayLabelHei ; 2086 h = dayLabelHei ;
2085 for ( i = 0; i < 7; i++) { 2087 for ( i = 0; i < 7; i++) {
2086 if ( i == daysToShow-colModulo ) 2088 if ( i == daysToShow-colModulo )
2087 ++w; 2089 ++w;
2088 if ( combinedSatSun ) { 2090 if ( combinedSatSun ) {
2089 if ( i >= daysToShow-1 ) { 2091 if ( i >= daysToShow-1 ) {
2090 2092
2091 if ( i == 6 ) 2093 if ( i == 6 )
2092 mDayLabels[i]->setGeometry( x+weeklabelwid,y,width()-x-weeklabelwid,h); 2094 mDayLabels[i]->setGeometry( x+weeklabelwid,y,width()-x-weeklabelwid,h);
2093 else 2095 else
2094 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h); 2096 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h);
2095 x -= w/2 ; 2097 x -= w/2 ;
2096 } 2098 }
2097 else 2099 else
2098 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); 2100 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h);
2099 } else 2101 } else
2100 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); 2102 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h);
2101 x += w; 2103 x += w;
2102 } 2104 }
2103 x= 0; 2105 x= 0;
2104 y= dayLabelHei; 2106 y= dayLabelHei;
2105 w = colWid; 2107 w = colWid;
2106 h = cellHei ; 2108 h = cellHei ;
2107 int max = 0; 2109 int max = 0;
2108 int mc_count = mCells.count(); 2110 int mc_count = mCells.count();
2109 for ( i = 0; i < mc_count; ++i) { 2111 for ( i = 0; i < mc_count; ++i) {
2110 //qDebug("iii %d ", i); 2112 //qDebug("iii %d ", i);
2111 w = colWid; 2113 w = colWid;
2112 if ( ((i) % 7) >= 7-colModulo ) { 2114 if ( ((i) % 7) >= 7-colModulo ) {
2113 ++w; 2115 ++w;
2114 } 2116 }
2115 if ( i == (6-rowModulo)*7) 2117 if ( i == (6-rowModulo)*7)
2116 ++h; 2118 ++h;
2117 if ( combinedSatSun ) { 2119 if ( combinedSatSun ) {
2118 if ( (i)%7 >= daysToShow-1 ) { 2120 if ( (i)%7 >= daysToShow-1 ) {
2119 if ( (i)%7 == daysToShow-1 ) { 2121 if ( (i)%7 == daysToShow-1 ) {
2120 w = width()-x-weeklabelwid; 2122 w = width()-x-weeklabelwid;
2121 max = h/2; 2123 max = h/2;
2122 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max ); 2124 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max );
2123 x -= w ;y += h/2; 2125 x -= w ;y += h/2;
2124 } else { 2126 } else {
2125 w = width()-x-weeklabelwid; 2127 w = width()-x-weeklabelwid;
2126 max = h-h/2; 2128 max = h-h/2;
2127 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max ); 2129 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max );
2128 y -= h/2; 2130 y -= h/2;
2129 } 2131 }
2130 } else { 2132 } else {
2131 max = h; 2133 max = h;
2132 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); 2134 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h );
2133 } 2135 }
2134 2136
2135 } 2137 }
2136 else { 2138 else {
2137 max = h; 2139 max = h;
2138 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); 2140 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h );
2139 } 2141 }
2140 x += w; 2142 x += w;
2141 if ( x + w/2 > wid ) { 2143 if ( x + w/2 > wid ) {
2142 x = 0; 2144 x = 0;
2143 y += h; 2145 y += h;
2144 } 2146 }
2145 //mCells[i]->dateLabel()->setMaximumHeight( max- mCells[i]->lineWidth()*2 ); 2147 //mCells[i]->dateLabel()->setMaximumHeight( max- mCells[i]->lineWidth()*2 );
2146 } 2148 }
2147 y= dayLabelHei; 2149 y= dayLabelHei;
2148 h = cellHei ; 2150 h = cellHei ;
2149 for ( i = 0; i < 6; i++) { 2151 for ( i = 0; i < 6; i++) {
2150 if ( i == (6-rowModulo)) 2152 if ( i == (6-rowModulo))
2151 ++h; 2153 ++h;
2152 mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h); 2154 mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h);
2153 y += h; 2155 y += h;
2154 } 2156 }
2155 mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei); 2157 mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei);
2156 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); 2158 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height());
2157 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); 2159 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height());
2158 mShortDayLabelsM = mDayLabels[0]->width()-2 < mWidthLongDayLabel ; 2160 mShortDayLabelsM = mDayLabels[0]->width()-2 < mWidthLongDayLabel ;
2159 updateDayLabels(); 2161 updateDayLabels();
2160 //bool forceUpdate = !updatePossible; 2162 //bool forceUpdate = !updatePossible;
2161 updatePossible = true; 2163 updatePossible = true;
2162 //mWeekLabels[mNumWeeks]->setText( i18n("W")); 2164 //mWeekLabels[mNumWeeks]->setText( i18n("W"));
2163} 2165}
2164 2166
2165void KOMonthView::showContextMenu( Incidence *incidence ) 2167void KOMonthView::showContextMenu( Incidence *incidence )
2166{ 2168{
2167 if( incidence ) 2169 if( incidence )
2168 mContextMenu->showIncidencePopup(incidence); 2170 mContextMenu->showIncidencePopup(incidence);
2169 else { 2171 else {
2170 //qDebug("KOMonthView::showContextMenu "); 2172 //qDebug("KOMonthView::showContextMenu ");
2171 mNewItemMenu->popup(QCursor::pos()); 2173 mNewItemMenu->popup(QCursor::pos());
2172 } 2174 }
2173 /* 2175 /*
2174 if( incidence && incidence->typeID() == eventID ) { 2176 if( incidence && incidence->typeID() == eventID ) {
2175 Event *event = static_cast<Event *>(incidence); 2177 Event *event = static_cast<Event *>(incidence);
2176 mContextMenu->showEventPopup(event); 2178 mContextMenu->showEventPopup(event);
2177 } else { 2179 } else {
2178 kdDebug() << "MonthView::showContextMenu(): cast failed." << endl; 2180 kdDebug() << "MonthView::showContextMenu(): cast failed." << endl;
2179 } 2181 }
2180 */ 2182 */
2181} 2183}
2182MonthViewCell * KOMonthView::selectedCell( ) 2184MonthViewCell * KOMonthView::selectedCell( )
2183{ 2185{
2184 return mSelectedCell; 2186 return mSelectedCell;
2185} 2187}
2186void KOMonthView::setSelectedCell( MonthViewCell *cell ) 2188void KOMonthView::setSelectedCell( MonthViewCell *cell )
2187{ 2189{
2188 //qDebug("KOMonthView::setSelectedCell %d", cell); 2190 //qDebug("KOMonthView::setSelectedCell %d", cell);
2189 if ( mSelectedCell && mSelectedCell != cell ) { 2191 if ( mSelectedCell && mSelectedCell != cell ) {
2190 MonthViewCell * mvc = mSelectedCell; 2192 MonthViewCell * mvc = mSelectedCell;
2191 mSelectedCell = cell; 2193 mSelectedCell = cell;
2192 mvc->deselect(); 2194 mvc->deselect();
2193 } else 2195 } else
2194 mSelectedCell = cell; 2196 mSelectedCell = cell;
2195 // if ( mSelectedCell ) 2197 // if ( mSelectedCell )
2196 // mSelectedCell->select(); 2198 // mSelectedCell->select();
2197 if ( !mSelectedCell ) 2199 if ( !mSelectedCell )
2198 emit incidenceSelected( 0 ); 2200 emit incidenceSelected( 0 );
2199 else 2201 else
2200 emit incidenceSelected( mSelectedCell->selectedIncidence() ); 2202 emit incidenceSelected( mSelectedCell->selectedIncidence() );
2201} 2203}
2202 2204
2203void KOMonthView::processSelectionChange() 2205void KOMonthView::processSelectionChange()
2204{ 2206{
2205 QPtrList<Incidence> incidences = selectedIncidences(); 2207 QPtrList<Incidence> incidences = selectedIncidences();
2206 if (incidences.count() > 0) { 2208 if (incidences.count() > 0) {
2207 emit incidenceSelected( incidences.first() ); 2209 emit incidenceSelected( incidences.first() );
2208 } else { 2210 } else {
2209 emit incidenceSelected( 0 ); 2211 emit incidenceSelected( 0 );
2210 clearSelection(); 2212 clearSelection();
2211 } 2213 }
2212} 2214}
2213 2215
2214void KOMonthView::clearSelection() 2216void KOMonthView::clearSelection()
2215{ 2217{
2216 if ( mSelectedCell ) { 2218 if ( mSelectedCell ) {
2217 mSelectedCell->deselect(); 2219 mSelectedCell->deselect();
2218 mSelectedCell = 0; 2220 mSelectedCell = 0;
2219 } 2221 }
2220} 2222}
2221 2223
2222void KOMonthView::keyReleaseEvent ( QKeyEvent * e) 2224void KOMonthView::keyReleaseEvent ( QKeyEvent * e)
2223{ 2225{
2224 if ( !e->isAutoRepeat() ) { 2226 if ( !e->isAutoRepeat() ) {
2225 mFlagKeyPressed = false; 2227 mFlagKeyPressed = false;
2226 } 2228 }
2227} 2229}
2228 2230
2229void KOMonthView::keyPressEvent ( QKeyEvent * e ) 2231void KOMonthView::keyPressEvent ( QKeyEvent * e )
2230{ 2232{
2231 2233
2232 qApp->processEvents(); 2234 qApp->processEvents();
2233 if ( e->isAutoRepeat() && !mFlagKeyPressed ) { 2235 if ( e->isAutoRepeat() && !mFlagKeyPressed ) {
2234 //e->ignore(); 2236 //e->ignore();
2235 e->accept(); 2237 e->accept();
2236 return; 2238 return;
2237 } 2239 }
2238 if (! e->isAutoRepeat() ) 2240 if (! e->isAutoRepeat() )
2239 mFlagKeyPressed = true; 2241 mFlagKeyPressed = true;
2240 switch(e->key()) { 2242 switch(e->key()) {
2241 case Key_Up: 2243 case Key_Up:
2242 { 2244 {
2243 if ( mShowWeekView ) { 2245 if ( mShowWeekView ) {
2244 emit selectWeekNum ( currentWeek() - 1 ); 2246 emit selectWeekNum ( currentWeek() - 1 );
2245 } 2247 }
2246 else { 2248 else {
2247 emit prevMonth(); 2249 emit prevMonth();
2248 } 2250 }
2249 } 2251 }
2250 e->accept(); 2252 e->accept();
2251 break; 2253 break;
2252 case Key_Down: 2254 case Key_Down:
2253 { 2255 {
2254 if ( mShowWeekView ) { 2256 if ( mShowWeekView ) {
2255 emit selectWeekNum ( currentWeek() +1); 2257 emit selectWeekNum ( currentWeek() +1);
2256 } 2258 }
2257 else { 2259 else {
2258 emit nextMonth(); 2260 emit nextMonth();
2259 } 2261 }
2260 2262
2261 } 2263 }
2262 e->accept(); 2264 e->accept();
2263 break; 2265 break;
2264 case Key_Return: 2266 case Key_Return:
2265 case Key_Enter: 2267 case Key_Enter:
2266 { 2268 {
2267 selectInternalWeekNum ( currentWeek() ); 2269 selectInternalWeekNum ( currentWeek() );
2268 } 2270 }
2269 e->accept(); 2271 e->accept();
2270 break; 2272 break;
2271 case Key_D: 2273 case Key_D:
2272 if ( mSelectedCell ) { 2274 if ( mSelectedCell ) {
2273 mSelectedCell->showDay(); 2275 mSelectedCell->showDay();
2274 e->accept(); 2276 e->accept();
2275 } else { 2277 } else {
2276 e->ignore(); 2278 e->ignore();
2277 } 2279 }
2278 break; 2280 break;
2279 default: 2281 default:
2280 e->ignore(); 2282 e->ignore();
2281 break; 2283 break;
2282 } 2284 }
2283} 2285}
2284 2286
2285void KOMonthView::nextCell() 2287void KOMonthView::nextCell()
2286{ 2288{
2287 focusNextPrevChild ( true ); 2289 focusNextPrevChild ( true );
2288} 2290}
2289void KOMonthView::prevCell() 2291void KOMonthView::prevCell()
2290{ 2292{
2291 focusNextPrevChild ( false ); 2293 focusNextPrevChild ( false );
2292} 2294}
2293 2295
2294void KOMonthView::slotNewTodo() 2296void KOMonthView::slotNewTodo()
2295{ 2297{
2296 //qDebug("KOMonthView::slotNewTodo() "); 2298 //qDebug("KOMonthView::slotNewTodo() ");
2297 if ( mPopupCell ){ 2299 if ( mPopupCell ){
2298 QDateTime dt( mPopupCell->date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 2300 QDateTime dt( mPopupCell->date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
2299 emit newTodoSignal(dt,true); 2301 emit newTodoSignal(dt,true);
2300 } 2302 }
2301 mPopupCell = 0; 2303 mPopupCell = 0;
2302} 2304}
2303void KOMonthView::slotNewEvent() 2305void KOMonthView::slotNewEvent()
2304{ 2306{
2305 if ( mPopupCell ) { 2307 if ( mPopupCell ) {
2306 QDateTime dt( mPopupCell->date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 2308 QDateTime dt( mPopupCell->date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
2307 emit newEventSignal( dt ); 2309 emit newEventSignal( dt );
2308 } 2310 }
2309 //qDebug("KOMonthView::slotNewEvent() "); 2311 //qDebug("KOMonthView::slotNewEvent() ");
2310 mPopupCell = 0; 2312 mPopupCell = 0;
2311} 2313}
2312 2314
2313void KOMonthView::slotEditJournal() 2315void KOMonthView::slotEditJournal()
2314{ 2316{
2315 if ( mPopupCell ) 2317 if ( mPopupCell )
2316 emit showJournalSignal( 7, mPopupCell->date() ); 2318 emit showJournalSignal( 7, mPopupCell->date() );
2317 //qDebug("KOMonthView::slotEditJournal() "); 2319 //qDebug("KOMonthView::slotEditJournal() ");
2318 mPopupCell = 0; 2320 mPopupCell = 0;
2319} 2321}
2320 2322
2321void KOMonthView::setPopupCell( MonthViewCell * c) 2323void KOMonthView::setPopupCell( MonthViewCell * c)
2322{ 2324{
2323 mPopupCell = c; 2325 mPopupCell = c;
2324} 2326}
diff --git a/korganizer/kotodoeditor.cpp b/korganizer/kotodoeditor.cpp
index 100a81b..682f83b 100644
--- a/korganizer/kotodoeditor.cpp
+++ b/korganizer/kotodoeditor.cpp
@@ -1,453 +1,454 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 1997, 1998 Preston Brown 3 Copyright (c) 1997, 1998 Preston Brown
4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or 8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software 17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 19
20 As a special exception, permission is given to link this program 20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable, 21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution. 22 without including the source code for Qt in the source distribution.
23*/ 23*/
24 24
25#include <qtooltip.h> 25#include <qtooltip.h>
26#include <qframe.h> 26#include <qframe.h>
27#include <qpixmap.h> 27#include <qpixmap.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#include <qhbox.h> 29#include <qhbox.h>
30#include <qdir.h> 30#include <qdir.h>
31#include <qdatetime.h> 31#include <qdatetime.h>
32#include <qapplication.h> 32#include <qapplication.h>
33#include <qtabwidget.h> 33#include <qtabwidget.h>
34 34
35#include <kiconloader.h> 35#include <kiconloader.h>
36#include <klocale.h> 36#include <klocale.h>
37#include <kfiledialog.h> 37#include <kfiledialog.h>
38#include <kstandarddirs.h> 38#include <kstandarddirs.h>
39#include <kmessagebox.h> 39#include <kmessagebox.h>
40 40
41#include <libkdepim/categoryselectdialog.h> 41#include <libkdepim/categoryselectdialog.h>
42#include <libkcal/calendarlocal.h> 42#include <libkcal/calendarlocal.h>
43#include <libkcal/calendarresources.h> 43#include <libkcal/calendarresources.h>
44#include <libkcal/resourcecalendar.h> 44#include <libkcal/resourcecalendar.h>
45#include <libkcal/icalformat.h> 45#include <libkcal/icalformat.h>
46#include <kresources/resourceselectdialog.h> 46#include <kresources/resourceselectdialog.h>
47#include <libkdepim/kdateedit.h> 47#include <libkdepim/kdateedit.h>
48 48
49#include "koprefs.h" 49#include "koprefs.h"
50#include "kolocationbox.h" 50#include "kolocationbox.h"
51 51
52#include "kotodoeditor.h" 52#include "kotodoeditor.h"
53extern int globalFlagBlockAgenda; 53extern int globalFlagBlockAgenda;
54 54
55KOTodoEditor::KOTodoEditor( Calendar *calendar, QWidget *parent ) : 55KOTodoEditor::KOTodoEditor( Calendar *calendar, QWidget *parent ) :
56 KOIncidenceEditor( i18n("Edit To-Do"), calendar, parent ) 56 KOIncidenceEditor( i18n("Edit To-Do"), calendar, parent )
57{ 57{
58 mTodo = 0; 58 mTodo = 0;
59 mRelatedTodo = 0; 59 mRelatedTodo = 0;
60 findButton(User1)->hide(); 60 findButton(User1)->hide();
61 init(); 61 init();
62 if ( QApplication::desktop()->height() <= 240 ) 62 if ( QApplication::desktop()->height() <= 240 )
63 hideButtons(); 63 hideButtons();
64} 64}
65 65
66KOTodoEditor::~KOTodoEditor() 66KOTodoEditor::~KOTodoEditor()
67{ 67{
68 emit dialogClose( mTodo ); 68 emit dialogClose( mTodo );
69} 69}
70 70
71void KOTodoEditor::init() 71void KOTodoEditor::init()
72{ 72{
73 setupGeneral(); 73 setupGeneral();
74 setupAttendeesTab(); 74 setupAttendeesTab();
75 setupRecurrence(); 75 setupRecurrence();
76 connect(mGeneral,SIGNAL(datesChecked()),this ,SLOT(checkRecurrence())); 76 connect(mGeneral,SIGNAL(datesChecked()),this ,SLOT(checkRecurrence()));
77 mRecurrence->setDateTimeStr( i18n("<i>The recurrence is computed from the start datetime!</i>") ); 77 mRecurrence->setDateTimeStr( i18n("<i>The recurrence is computed from the start datetime!</i>") );
78 connect(mGeneral,SIGNAL(dateTimesChanged(QDateTime,QDateTime)), 78 connect(mGeneral,SIGNAL(dateTimesChanged(QDateTime,QDateTime)),
79 mRecurrence,SLOT(setDefaultsDates(QDateTime,QDateTime))); 79 mRecurrence,SLOT(setDefaultsDates(QDateTime,QDateTime)));
80} 80}
81void KOTodoEditor::setupRecurrence() 81void KOTodoEditor::setupRecurrence()
82{ 82{
83 QFrame *topFrame = addPage( i18n("Recurrence") ); 83 QFrame *topFrame = addPage( i18n("Recurrence") );
84 QBoxLayout *topLayout = new QVBoxLayout( topFrame ); 84 QBoxLayout *topLayout = new QVBoxLayout( topFrame );
85 85
86 mRecurrence = new KOEditorRecurrence( topFrame ); 86 mRecurrence = new KOEditorRecurrence( topFrame );
87 topLayout->addWidget( mRecurrence ); 87 topLayout->addWidget( mRecurrence );
88} 88}
89 89
90void KOTodoEditor::setCategories( QString s ) 90void KOTodoEditor::setCategories( QString s )
91{ 91{
92 mGeneral->setCategories(s); 92 mGeneral->setCategories(s);
93} 93}
94void KOTodoEditor::setSecrecy( int sec ) 94void KOTodoEditor::setSecrecy( int sec )
95{ 95{
96 mGeneral->setSecrecy( sec ); 96 mGeneral->setSecrecy( sec );
97} 97}
98void KOTodoEditor::reload() 98void KOTodoEditor::reload()
99{ 99{
100 if ( mTodo ) readTodo( mTodo ); 100 if ( mTodo ) readTodo( mTodo );
101} 101}
102 102
103void KOTodoEditor::setupGeneral() 103void KOTodoEditor::setupGeneral()
104{ 104{
105 mGeneral = new KOEditorGeneralTodo(this); 105 mGeneral = new KOEditorGeneralTodo(this);
106 connect ( mGeneral, SIGNAL ( allAccepted() ), this, SLOT ( slotOk () ) ); 106 connect ( mGeneral, SIGNAL ( allAccepted() ), this, SLOT ( slotOk () ) );
107 107
108 // connect(mGeneral,SIGNAL(openCategoryDialog()),mCategoryDialog,SLOT(show())); 108 // connect(mGeneral,SIGNAL(openCategoryDialog()),mCategoryDialog,SLOT(show()));
109 //connect(mCategoryDialog, SIGNAL(categoriesSelected(const QString &)), 109 //connect(mCategoryDialog, SIGNAL(categoriesSelected(const QString &)),
110 // mGeneral,SLOT(setCategories(const QString &))); 110 // mGeneral,SLOT(setCategories(const QString &)));
111 111
112 if (KOPrefs::instance()->mCompactDialogs) { 112 if (KOPrefs::instance()->mCompactDialogs) {
113 QFrame *topFrame = addPage(i18n("General")); 113 QFrame *topFrame = addPage(i18n("General"));
114 114
115 QBoxLayout *topLayout = new QVBoxLayout(topFrame); 115 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
116 if ( QApplication::desktop()->width() < 480 ) { 116 if ( QApplication::desktop()->width() < 480 ) {
117 topLayout->setMargin(marginHintSmall()); 117 topLayout->setMargin(marginHintSmall());
118 topLayout->setSpacing(spacingHintSmall()); 118 topLayout->setSpacing(spacingHintSmall());
119 } else { 119 } else {
120 topLayout->setMargin(marginHint()); 120 topLayout->setMargin(marginHint());
121 topLayout->setSpacing(spacingHint()); 121 topLayout->setSpacing(spacingHint());
122 } 122 }
123 topLayout->addStretch( 1 ); 123 topLayout->addStretch( 1 );
124 mGeneral->initHeader(topFrame,topLayout); 124 mGeneral->initHeader(topFrame,topLayout);
125 topLayout->addStretch( 1 ); 125 topLayout->addStretch( 1 );
126 mGeneral->initTime(topFrame,topLayout); 126 mGeneral->initTime(topFrame,topLayout);
127 topLayout->addStretch( 1 ); 127 topLayout->addStretch( 1 );
128 mGeneral->initAlarm(topFrame,topLayout); 128 mGeneral->initAlarm(topFrame,topLayout);
129 topLayout->addStretch( 1 ); 129 topLayout->addStretch( 1 );
130 mGeneral->enableAlarm( false ); 130 mGeneral->enableAlarm( false );
131 131
132 132
133 QBoxLayout *priorityLayout; 133 QBoxLayout *priorityLayout;
134 if ( QApplication::desktop()->width() < 500 ) 134 if ( QApplication::desktop()->width() < 500 )
135 priorityLayout = new QVBoxLayout( topLayout ); 135 priorityLayout = new QVBoxLayout( topLayout );
136 else 136 else
137 priorityLayout = new QHBoxLayout( topLayout ); 137 priorityLayout = new QHBoxLayout( topLayout );
138 QWidget* prioWidget = new QWidget (topFrame); 138 QWidget* prioWidget = new QWidget (topFrame);
139 priorityLayout->addWidget( prioWidget ); 139 priorityLayout->addWidget( prioWidget );
140 QHBoxLayout* priorityLayout2 = new QHBoxLayout( prioWidget); 140 QHBoxLayout* priorityLayout2 = new QHBoxLayout( prioWidget);
141 141
142 142
143 QIconSet icon; 143 QIconSet icon;
144 if ( QApplication::desktop()->width() < 321 ) 144 if ( QApplication::desktop()->width() < 321 )
145 icon = SmallIcon("fileimport16"); 145 icon = SmallIcon("fileimport16");
146 else 146 else
147 icon = SmallIcon("fileimport"); 147 icon = SmallIcon("fileimport");
148 QPushButton * loadTemplate = new QPushButton( prioWidget); 148 QPushButton * loadTemplate = new QPushButton( prioWidget);
149 loadTemplate->setIconSet (icon ) ; 149 loadTemplate->setIconSet (icon ) ;
150 int size = loadTemplate->sizeHint().height(); 150 int size = loadTemplate->sizeHint().height();
151 loadTemplate->setFixedSize( size, size ); 151 loadTemplate->setFixedSize( size, size );
152 if ( QApplication::desktop()->width() < 321 ) 152 if ( QApplication::desktop()->width() < 321 )
153 icon = SmallIcon("fileexport16"); 153 icon = SmallIcon("fileexport16");
154 else 154 else
155 icon = SmallIcon("fileexport"); 155 icon = SmallIcon("fileexport");
156 QPushButton * saveTemplate = new QPushButton( prioWidget); 156 QPushButton * saveTemplate = new QPushButton( prioWidget);
157 saveTemplate->setIconSet (icon ) ; 157 saveTemplate->setIconSet (icon ) ;
158 saveTemplate->setFixedSize( size, size ); 158 saveTemplate->setFixedSize( size, size );
159 159
160 priorityLayout2->addWidget(loadTemplate); 160 priorityLayout2->addWidget(loadTemplate);
161 priorityLayout2->addWidget(saveTemplate); 161 priorityLayout2->addWidget(saveTemplate);
162 mGeneral->initPriority(prioWidget,priorityLayout2); 162 mGeneral->initPriority(prioWidget,priorityLayout2);
163 mGeneral->initCategories( topFrame, priorityLayout ); 163 mGeneral->initCategories( topFrame, priorityLayout );
164 topLayout->addStretch(1); 164 topLayout->addStretch(1);
165 165
166 QFrame *topFrame2 = addPage(i18n("Details")); 166 QFrame *topFrame2 = addPage(i18n("Details"));
167 167
168 QBoxLayout *topLayout2 = new QVBoxLayout(topFrame2); 168 QBoxLayout *topLayout2 = new QVBoxLayout(topFrame2);
169 topLayout2->setMargin(marginHint()); 169 topLayout2->setMargin(marginHint());
170 topLayout2->setSpacing(spacingHint()); 170 topLayout2->setSpacing(spacingHint());
171 171
172 QHBoxLayout *completionLayout = new QHBoxLayout( topLayout2 ); 172 QHBoxLayout *completionLayout = new QHBoxLayout( topLayout2 );
173 mGeneral->initCompletion(topFrame2,completionLayout); 173 mGeneral->initCompletion(topFrame2,completionLayout);
174 174
175 175
176 mGeneral->initSecrecy( topFrame2, topLayout2 ); 176 mGeneral->initSecrecy( topFrame2, topLayout2 );
177 mGeneral->initDescription(topFrame2,topLayout2); 177 mGeneral->initDescription(topFrame2,topLayout2);
178 178
179 // QHBox * hb = new QHBox ( topFrame2 ); 179 // QHBox * hb = new QHBox ( topFrame2 );
180 // topLayout2->addWidget(hb); 180 // topLayout2->addWidget(hb);
181 // hb->setSpacing( 3 ); 181 // hb->setSpacing( 3 );
182 182
183 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); 183 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) );
184 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); 184 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) );
185 185
186 } else { 186 } else {
187 QFrame *topFrame = addPage(i18n("General")); 187 QFrame *topFrame = addPage(i18n("General"));
188 188
189 QBoxLayout *topLayout = new QVBoxLayout(topFrame); 189 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
190 topLayout->setSpacing(spacingHint()); 190 topLayout->setSpacing(spacingHint());
191 191
192 mGeneral->initHeader(topFrame,topLayout); 192 mGeneral->initHeader(topFrame,topLayout);
193 mGeneral->initTime(topFrame,topLayout); 193 mGeneral->initTime(topFrame,topLayout);
194 mGeneral->initStatus(topFrame,topLayout); 194 mGeneral->initStatus(topFrame,topLayout);
195 QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout); 195 QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout);
196 mGeneral->initAlarm(topFrame,alarmLineLayout); 196 mGeneral->initAlarm(topFrame,alarmLineLayout);
197 mGeneral->initDescription(topFrame,topLayout); 197 mGeneral->initDescription(topFrame,topLayout);
198 QBoxLayout *detailsLayout = new QHBoxLayout(topLayout); 198 QBoxLayout *detailsLayout = new QHBoxLayout(topLayout);
199 mGeneral->initCategories( topFrame, detailsLayout ); 199 mGeneral->initCategories( topFrame, detailsLayout );
200 mGeneral->initSecrecy( topFrame, detailsLayout ); 200 mGeneral->initSecrecy( topFrame, detailsLayout );
201 } 201 }
202 mGeneral->finishSetup(); 202 mGeneral->finishSetup();
203 203
204} 204}
205 205
206void KOTodoEditor::editTodo(Todo *todo, bool editDescription) 206void KOTodoEditor::editTodo(Todo *todo, bool editDescription)
207{ 207{
208 //init(); 208 //init();
209 209
210 mTodo = todo; 210 mTodo = todo;
211 readTodo(mTodo); 211 readTodo(mTodo);
212 if ( editDescription ) { 212 if ( editDescription ) {
213 showPage( 1 ); 213 showPage( 1 );
214 mGeneral->setFocusOn( 1 ); 214 mGeneral->setFocusOn( 1 );
215 } else { 215 } else {
216 showPage( 0 ); 216 showPage( 0 );
217 mGeneral->setFocusOn( 2 ); 217 mGeneral->setFocusOn( 2 );
218 } 218 }
219 checkRecurrence(); 219 checkRecurrence();
220} 220}
221 221
222void KOTodoEditor::newTodo(QDateTime due,Todo *relatedTodo,bool allDay) 222void KOTodoEditor::newTodo(QDateTime due,Todo *relatedTodo,bool allDay)
223{ 223{
224 //init(); 224 //init();
225 225
226 mTodo = 0; 226 mTodo = 0;
227 setDefaults(due,relatedTodo,allDay); 227 setDefaults(due,relatedTodo,allDay);
228} 228}
229 229
230void KOTodoEditor::loadDefaults() 230void KOTodoEditor::loadDefaults()
231{ 231{
232 setDefaults(QDateTime::currentDateTime().addDays(7),0,false); 232 setDefaults(QDateTime::currentDateTime().addDays(7),0,false);
233} 233}
234 234
235bool KOTodoEditor::processInput( bool emitTime ) 235bool KOTodoEditor::processInput( bool emitTime )
236{ 236{
237 if (!validateInput()) return false; 237 if (!validateInput()) return false;
238 238
239 Todo *todo = 0; 239 Todo *todo = 0;
240 240
241 if (mTodo) todo = mTodo; 241 if (mTodo) todo = mTodo;
242 else { 242 else {
243 todo = new Todo; 243 todo = new Todo;
244 todo->setOrganizer(KOPrefs::instance()->email()); 244 todo->setOrganizer(KOPrefs::instance()->email());
245 } 245 }
246 246
247 writeTodo(todo); 247 writeTodo(todo);
248 if ( emitTime ) { 248 if ( emitTime ) {
249 globalFlagBlockAgenda = 1; 249 globalFlagBlockAgenda = 1;
250 emit showAgendaView( false ); 250 emit showAgendaView( false );
251 if ( todo->hasDueDate() ) 251 if ( todo->hasDueDate() )
252 emit jumpToTime( todo->dtDue().date() ); 252 emit jumpToTime( todo->dtDue().date() );
253 globalFlagBlockAgenda = 2; 253 globalFlagBlockAgenda = 2;
254 } 254 }
255 if (mTodo) { 255 if (mTodo) {
256 todo->setRevision(todo->revision()+1); 256 todo->setRevision(todo->revision()+1);
257 emit todoChanged(todo); 257 emit todoChanged(todo);
258 } else { 258 } else {
259 mCalendar->addTodo(todo); 259 mCalendar->addTodo(todo);
260 mTodo = todo; 260 mTodo = todo;
261 emit todoAdded(todo); 261 emit todoAdded(todo);
262 } 262 }
263 263
264 return true; 264 return true;
265} 265}
266 266
267void KOTodoEditor::deleteTodo() 267void KOTodoEditor::deleteTodo()
268{ 268{
269 if (mTodo) { 269 if (mTodo) {
270 if (KOPrefs::instance()->mConfirm) { 270 if (KOPrefs::instance()->mConfirm) {
271 switch (msgItemDelete()) { 271 switch (msgItemDelete()) {
272 case KMessageBox::Continue: // OK 272 case KMessageBox::Continue: // OK
273 emit todoToBeDeleted(mTodo); 273 emit todoToBeDeleted(mTodo);
274 emit dialogClose(mTodo); 274 emit dialogClose(mTodo);
275 mCalendar->deleteTodo(mTodo); 275 mCalendar->deleteTodo(mTodo);
276 emit todoDeleted(); 276 emit todoDeleted();
277 reject(); 277 reject();
278 break; 278 break;
279 } 279 }
280 } 280 }
281 else { 281 else {
282 emit todoToBeDeleted(mTodo); 282 emit todoToBeDeleted(mTodo);
283 emit dialogClose(mTodo); 283 emit dialogClose(mTodo);
284 mCalendar->deleteTodo(mTodo); 284 mCalendar->deleteTodo(mTodo);
285 emit todoDeleted(); 285 emit todoDeleted();
286 reject(); 286 reject();
287 } 287 }
288 } else { 288 } else {
289 reject(); 289 reject();
290 } 290 }
291} 291}
292 292
293void KOTodoEditor::setDefaults(QDateTime due,Todo *relatedEvent,bool allDay) 293void KOTodoEditor::setDefaults(QDateTime due,Todo *relatedEvent,bool allDay)
294{ 294{
295 mRelatedTodo = relatedEvent; 295 mRelatedTodo = relatedEvent;
296 296
297 mGeneral->setDefaults(due,allDay); 297 mGeneral->setDefaults(due,allDay);
298 mDetails->setDefaults(); 298 mDetails->setDefaults();
299 showPage( 0 ); 299 showPage( 0 );
300 if ( mRelatedTodo ) { 300 if ( mRelatedTodo ) {
301 mGeneral->fillCalCombo(mRelatedTodo->calID() ); 301 mGeneral->fillCalCombo(mRelatedTodo->calID() );
302 mGeneral->setCategories (mRelatedTodo->categoriesStr ()); 302 mGeneral->setCategories (mRelatedTodo->categoriesStr ());
303 mGeneral->setSecrecy (mRelatedTodo->secrecy ()); 303 mGeneral->setSecrecy (mRelatedTodo->secrecy ());
304 if ( mRelatedTodo->priority() < 3 ) 304 if ( mRelatedTodo->priority() < 3 )
305 mGeneral->mPriorityCombo->setCurrentItem(mRelatedTodo->priority()-1); 305 mGeneral->mPriorityCombo->setCurrentItem(mRelatedTodo->priority()-1);
306 mGeneral->mSummaryEdit->lineEdit()->setText(mRelatedTodo->summary()+": "); 306 mGeneral->mSummaryEdit->lineEdit()->setText(mRelatedTodo->summary()+": ");
307 int len = mRelatedTodo->summary().length(); 307 int len = mRelatedTodo->summary().length();
308 mGeneral->mSummaryEdit->lineEdit()->setFocus(); 308 mGeneral->mSummaryEdit->lineEdit()->setFocus();
309 mGeneral->mSummaryEdit->lineEdit()->setCursorPosition ( len+2 ); 309 mGeneral->mSummaryEdit->lineEdit()->setCursorPosition ( len+2 );
310 mGeneral->mSummaryEdit->lineEdit()->setSelection ( 0, len+2 ); 310 mGeneral->mSummaryEdit->lineEdit()->setSelection ( 0, len+2 );
311 311
312 } else 312 } else
313 mGeneral->setFocusOn( 2 ); 313 mGeneral->setFocusOn( 2 );
314 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false ); 314 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false );
315 mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 )); 315 mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ));
316} 316}
317void KOTodoEditor::checkRecurrence() 317void KOTodoEditor::checkRecurrence()
318{ 318{
319 if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) { 319 if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) {
320 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), true ); 320 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), true );
321 321
322 if ( mTodo ) 322 if ( mTodo )
323 mRecurrence->readEvent( mTodo ); 323 mRecurrence->readEvent( mTodo );
324 else { 324 else {
325 bool time = mGeneral->mTimeButton->isChecked(); 325 bool time = mGeneral->mTimeButton->isChecked();
326 QDateTime from,to; 326 QDateTime from,to;
327 if ( time ) { 327 if ( time ) {
328 to = QDateTime( mGeneral->mDueDateEdit->date(), mGeneral->mDueTimeEdit->getTime() ) ; 328 to = QDateTime( mGeneral->mDueDateEdit->date(), mGeneral->mDueTimeEdit->getTime() ) ;
329 from = QDateTime( mGeneral->mStartDateEdit->date(),mGeneral->mStartTimeEdit->getTime( )) ; 329 from = QDateTime( mGeneral->mStartDateEdit->date(),mGeneral->mStartTimeEdit->getTime( )) ;
330 } else { 330 } else {
331 to = QDateTime( mGeneral->mDueDateEdit->date(), QTime( 0,0,0) ) ; 331 to = QDateTime( mGeneral->mDueDateEdit->date(), QTime( 0,0,0) ) ;
332 from = QDateTime( mGeneral->mStartDateEdit->date(),QTime( 0,0,0) ) ; 332 from = QDateTime( mGeneral->mStartDateEdit->date(),QTime( 0,0,0) ) ;
333 } 333 }
334 if ( to < from ) 334 if ( to < from )
335 to = from; 335 to = from;
336 mRecurrence->setDefaults(from,to); 336 mRecurrence->setDefaults(from,to);
337 } 337 }
338 } else { 338 } else {
339 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false ); 339 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false );
340 mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 )); 340 mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ));
341 } 341 }
342} 342}
343void KOTodoEditor::readTodo(Todo *todo) 343void KOTodoEditor::readTodo(Todo *todo)
344{ 344{
345 mGeneral->readTodo(todo); 345 mGeneral->readTodo(todo);
346 mDetails->readEvent(todo); 346 mDetails->readEvent(todo);
347 mRelatedTodo = 0;//todo->relatedTo(); 347 mRelatedTodo = 0;//todo->relatedTo();
348 // categories 348 // categories
349 // mCategoryDialog->setSelected(todo->categories()); 349 // mCategoryDialog->setSelected(todo->categories());
350 350
351 // We should handle read-only events here. 351 // We should handle read-only events here.
352} 352}
353 353
354void KOTodoEditor::writeTodo(Todo *event) 354void KOTodoEditor::writeTodo(Todo *event)
355{ 355{
356 bool maybeComputeRecurrenceTime = false; 356 bool maybeComputeRecurrenceTime = false;
357 if( event->hasRecurrenceID() && event->percentComplete() < 100) 357 if( event->hasRecurrenceID() && event->percentComplete() < 100)
358 maybeComputeRecurrenceTime = true; 358 maybeComputeRecurrenceTime = true;
359 event->setHasRecurrenceID( false ); 359 event->setHasRecurrenceID( false );
360 mGeneral->writeTodo(event); 360 mGeneral->writeTodo(event);
361 mDetails->writeEvent(event); 361 mDetails->writeEvent(event);
362 362
363 // set related event, i.e. parent to-do in this case. 363 // set related event, i.e. parent to-do in this case.
364 if (mRelatedTodo) { 364 if (mRelatedTodo) {
365 event->setRelatedTo(mRelatedTodo); 365 event->setRelatedTo(mRelatedTodo);
366 } 366 }
367 if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) { 367 if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) {
368 mRecurrence->writeEvent(event); 368 mRecurrence->writeEvent(event);
369 if ( event->doesRecur() ) { 369 if ( event->doesRecur() ) {
370 int addSec = -1 ; 370 int addSec = -1 ;
371 if ( maybeComputeRecurrenceTime && event->percentComplete() == 100 ) 371 if ( maybeComputeRecurrenceTime && event->percentComplete() == 100 )
372 addSec = 1; 372 addSec = 1;
373 event->setRecurrenceID( event->dtStart().addSecs( addSec ) ); 373 event->setRecurrenceID( event->dtStart().addSecs( addSec ) );
374 event->setRecurDates(); 374 event->setRecurDates();
375 } else { 375 } else {
376 event->setHasRecurrenceID( false ); 376 event->setHasRecurrenceID( false );
377 } 377 }
378 } else { 378 } else {
379 event->setHasRecurrenceID( false ); 379 event->setHasRecurrenceID( false );
380 event->recurrence()->unsetRecurs(); 380 if ( event->doesRecur() )
381 event->recurrence()->unsetRecurs();
381 } 382 }
382} 383}
383 384
384bool KOTodoEditor::validateInput() 385bool KOTodoEditor::validateInput()
385{ 386{
386 if (!mGeneral->validateInput()) return false; 387 if (!mGeneral->validateInput()) return false;
387 if (!mDetails->validateInput()) return false; 388 if (!mDetails->validateInput()) return false;
388 return true; 389 return true;
389} 390}
390 391
391int KOTodoEditor::msgItemDelete() 392int KOTodoEditor::msgItemDelete()
392{ 393{
393 return KMessageBox::warningContinueCancel(this, 394 return KMessageBox::warningContinueCancel(this,
394 i18n("This item will be permanently deleted."), 395 i18n("This item will be permanently deleted."),
395 i18n("KOrganizer Confirmation"),i18n("Delete")); 396 i18n("KOrganizer Confirmation"),i18n("Delete"));
396} 397}
397 398
398void KOTodoEditor::modified (int modification) 399void KOTodoEditor::modified (int modification)
399{ 400{
400 if (modification == KOGlobals::CATEGORY_MODIFIED || 401 if (modification == KOGlobals::CATEGORY_MODIFIED ||
401 KOGlobals::UNKNOWN_MODIFIED == modification ) 402 KOGlobals::UNKNOWN_MODIFIED == modification )
402 // mCategoryDialog->setSelected (mTodo->categories ()); 403 // mCategoryDialog->setSelected (mTodo->categories ());
403 mGeneral->modified (mTodo, modification); 404 mGeneral->modified (mTodo, modification);
404 405
405} 406}
406 407
407void KOTodoEditor::slotLoadTemplate() 408void KOTodoEditor::slotLoadTemplate()
408{ 409{
409 410
410 QString fileName =locateLocal( "templates", "todos" ); 411 QString fileName =locateLocal( "templates", "todos" );
411 QDir t_dir; 412 QDir t_dir;
412 if ( !t_dir.exists(fileName) ) 413 if ( !t_dir.exists(fileName) )
413 t_dir.mkdir ( fileName ); 414 t_dir.mkdir ( fileName );
414 fileName += "/todo"; 415 fileName += "/todo";
415 fileName = KFileDialog::getSaveFileName( fileName , "Load Todo template", this ); 416 fileName = KFileDialog::getSaveFileName( fileName , "Load Todo template", this );
416 if ( fileName.length() == 0 ) 417 if ( fileName.length() == 0 )
417 return; 418 return;
418 CalendarLocal cal; 419 CalendarLocal cal;
419 ICalFormat format; 420 ICalFormat format;
420 if ( !format.load( &cal, fileName ) ) { 421 if ( !format.load( &cal, fileName ) ) {
421 KMessageBox::error( this, i18n("Error loading template file\n '%1'.") 422 KMessageBox::error( this, i18n("Error loading template file\n '%1'.")
422 .arg( fileName ) ); 423 .arg( fileName ) );
423 return ; 424 return ;
424 } 425 }
425 QPtrList<Todo> todos = cal.todos(); 426 QPtrList<Todo> todos = cal.todos();
426 Todo * todo = todos.first(); 427 Todo * todo = todos.first();
427 if ( !todo ) { 428 if ( !todo ) {
428 KMessageBox::error( this, 429 KMessageBox::error( this,
429 i18n("Template does not\ncontain a valid Todo.")); 430 i18n("Template does not\ncontain a valid Todo."));
430 } else { 431 } else {
431 readTodo( todo ); 432 readTodo( todo );
432 } 433 }
433 434
434} 435}
435 436
436void KOTodoEditor::slotSaveTemplate() 437void KOTodoEditor::slotSaveTemplate()
437{ 438{
438 QString fileName =locateLocal( "templates", "todos" ); 439 QString fileName =locateLocal( "templates", "todos" );
439 QDir t_dir; 440 QDir t_dir;
440 if ( !t_dir.exists(fileName) ) 441 if ( !t_dir.exists(fileName) )
441 t_dir.mkdir ( fileName ); 442 t_dir.mkdir ( fileName );
442 fileName += "/todo"; 443 fileName += "/todo";
443 fileName = KFileDialog::getSaveFileName( fileName , "Save as Todo template", this ); 444 fileName = KFileDialog::getSaveFileName( fileName , "Save as Todo template", this );
444 if ( fileName.length() > 0 ) 445 if ( fileName.length() > 0 )
445 saveTemplate( fileName ); 446 saveTemplate( fileName );
446} 447}
447 448
448void KOTodoEditor::saveTemplate( const QString &templateName ) 449void KOTodoEditor::saveTemplate( const QString &templateName )
449{ 450{
450 Todo *todo = new Todo; 451 Todo *todo = new Todo;
451 writeTodo( todo ); 452 writeTodo( todo );
452 saveAsTemplate( todo, templateName ); 453 saveAsTemplate( todo, templateName );
453} 454}
diff --git a/korganizer/kowhatsnextview.cpp b/korganizer/kowhatsnextview.cpp
index fafcb58..f88403c 100644
--- a/korganizer/kowhatsnextview.cpp
+++ b/korganizer/kowhatsnextview.cpp
@@ -1,803 +1,803 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#include <qlayout.h> 20#include <qlayout.h>
21#include <qtextbrowser.h> 21#include <qtextbrowser.h>
22#include <qtextcodec.h> 22#include <qtextcodec.h>
23#include <qfileinfo.h> 23#include <qfileinfo.h>
24#include <qlabel.h> 24#include <qlabel.h>
25 25
26#include <qapplication.h> 26#include <qapplication.h>
27#ifdef DESKTOP_VERSION 27#ifdef DESKTOP_VERSION
28#include <qpaintdevicemetrics.h> 28#include <qpaintdevicemetrics.h>
29#endif 29#endif
30#include <kglobal.h> 30#include <kglobal.h>
31#include <klocale.h> 31#include <klocale.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <kiconloader.h> 33#include <kiconloader.h>
34#include <kmessagebox.h> 34#include <kmessagebox.h>
35 35
36#include <libkcal/calendar.h> 36#include <libkcal/calendar.h>
37 37
38#ifndef KORG_NOPRINTER 38#ifndef KORG_NOPRINTER
39#include "calprinter.h" 39#include "calprinter.h"
40#endif 40#endif
41#include "koglobals.h" 41#include "koglobals.h"
42#include "koprefs.h" 42#include "koprefs.h"
43#include "koeventviewerdialog.h" 43#include "koeventviewerdialog.h"
44#include "koeventviewer.h" 44#include "koeventviewer.h"
45#include <qstylesheet.h> 45#include <qstylesheet.h>
46#include "kowhatsnextview.h" 46#include "kowhatsnextview.h"
47using namespace KOrg; 47using namespace KOrg;
48 48
49void WhatsNextTextBrowser::setSource(const QString& n) 49void WhatsNextTextBrowser::setSource(const QString& n)
50{ 50{
51 51
52 if (n.startsWith("event:")) { 52 if (n.startsWith("event:")) {
53 emit showIncidence(n); 53 emit showIncidence(n);
54 return; 54 return;
55 } else if (n.startsWith("todo:")) { 55 } else if (n.startsWith("todo:")) {
56 emit showIncidence(n); 56 emit showIncidence(n);
57 return; 57 return;
58 } else { 58 } else {
59 QTextBrowser::setSource(n); 59 QTextBrowser::setSource(n);
60 } 60 }
61} 61}
62void WhatsNextTextBrowser::printMe() 62void WhatsNextTextBrowser::printMe()
63{ 63{
64#ifdef DESKTOP_VERSION 64#ifdef DESKTOP_VERSION
65 KOPrintPrefs pp ( this ); 65 KOPrintPrefs pp ( this );
66 if (!pp.exec() ) 66 if (!pp.exec() )
67 return; 67 return;
68 int scaleval = pp.printMode() ; 68 int scaleval = pp.printMode() ;
69 69
70 QPrinter printer; 70 QPrinter printer;
71 if (!printer.setup() ) 71 if (!printer.setup() )
72 return; 72 return;
73 QPainter p; 73 QPainter p;
74 p.begin ( &printer ); 74 p.begin ( &printer );
75 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer ); 75 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer );
76 float dx, dy; 76 float dx, dy;
77 int wid = (m.width() * 9)/10; 77 int wid = (m.width() * 9)/10;
78 dx = (float) wid/(float)contentsWidth (); 78 dx = (float) wid/(float)contentsWidth ();
79 dy = (float)(m.height()) / (float)contentsHeight (); 79 dy = (float)(m.height()) / (float)contentsHeight ();
80 float scale; 80 float scale;
81 // scale to fit the width or height of the paper 81 // scale to fit the width or height of the paper
82 if ( dx < dy ) 82 if ( dx < dy )
83 scale = dx; 83 scale = dx;
84 else 84 else
85 scale = dy; 85 scale = dy;
86 p.translate( m.width()/10,0 ); 86 p.translate( m.width()/10,0 );
87 if ( scaleval == 2 || scaleval == 1 && scale < 1.0 ) { 87 if ( scaleval == 2 || scaleval == 1 && scale < 1.0 ) {
88 p.scale( scale, scale ); 88 p.scale( scale, scale );
89 } 89 }
90 drawContents ( &p, 0,0, contentsWidth (), contentsHeight () ); 90 drawContents ( &p, 0,0, contentsWidth (), contentsHeight () );
91 p.end(); 91 p.end();
92#endif 92#endif
93} 93}
94 94
95KOWhatsNextView::KOWhatsNextView(Calendar *calendar, QWidget *parent, 95KOWhatsNextView::KOWhatsNextView(Calendar *calendar, QWidget *parent,
96 const char *name) 96 const char *name)
97 : KOrg::BaseView(calendar, parent, name) 97 : KOrg::BaseView(calendar, parent, name)
98{ 98{
99 // mDateLabel = 99 // mDateLabel =
100 // new QLabel(KGlobal::locale()->formatDate(QDate::currentDate()),this); 100 // new QLabel(KGlobal::locale()->formatDate(QDate::currentDate()),this);
101 // mDateLabel->setMargin(2); 101 // mDateLabel->setMargin(2);
102 // mDateLabel->setAlignment(AlignCenter); 102 // mDateLabel->setAlignment(AlignCenter);
103 setFont( KOPrefs::instance()->mWhatsNextFont ); 103 setFont( KOPrefs::instance()->mWhatsNextFont );
104 mView = new WhatsNextTextBrowser(this); 104 mView = new WhatsNextTextBrowser(this);
105 connect(mView,SIGNAL(showIncidence(const QString &)),SLOT(showIncidence(const QString &))); 105 connect(mView,SIGNAL(showIncidence(const QString &)),SLOT(showIncidence(const QString &)));
106 QStyleSheet* stsh = mView->styleSheet(); 106 QStyleSheet* stsh = mView->styleSheet();
107 QStyleSheetItem * style ; 107 QStyleSheetItem * style ;
108 style = stsh->item ("h2" ); 108 style = stsh->item ("h2" );
109 if ( style ) { 109 if ( style ) {
110 style->setMargin(QStyleSheetItem::MarginAll,0); 110 style->setMargin(QStyleSheetItem::MarginAll,0);
111 } 111 }
112 style = stsh->item ("h3" ); 112 style = stsh->item ("h3" );
113 if ( style ) { 113 if ( style ) {
114 style->setMargin(QStyleSheetItem::MarginAll,0); 114 style->setMargin(QStyleSheetItem::MarginAll,0);
115 } 115 }
116 mEventViewer = 0; 116 mEventViewer = 0;
117 117
118 QBoxLayout *topLayout = new QVBoxLayout(this); 118 QBoxLayout *topLayout = new QVBoxLayout(this);
119 // topLayout->addWidget(mDateLabel); 119 // topLayout->addWidget(mDateLabel);
120 topLayout->addWidget(mView); 120 topLayout->addWidget(mView);
121 mTimer = new QTimer( this ); 121 mTimer = new QTimer( this );
122 connect(mTimer,SIGNAL( timeout() ),this, SLOT(updateView())); 122 connect(mTimer,SIGNAL( timeout() ),this, SLOT(updateView()));
123 123
124 connect(mView->horizontalScrollBar (),SIGNAL( sliderReleased () ),this, SLOT(restartTimer())); 124 connect(mView->horizontalScrollBar (),SIGNAL( sliderReleased () ),this, SLOT(restartTimer()));
125 connect(mView->verticalScrollBar (),SIGNAL( sliderReleased () ),this, SLOT(restartTimer())); 125 connect(mView->verticalScrollBar (),SIGNAL( sliderReleased () ),this, SLOT(restartTimer()));
126} 126}
127 127
128KOWhatsNextView::~KOWhatsNextView() 128KOWhatsNextView::~KOWhatsNextView()
129{ 129{
130} 130}
131 131
132int KOWhatsNextView::maxDatesHint() 132int KOWhatsNextView::maxDatesHint()
133{ 133{
134 return 0; 134 return 0;
135} 135}
136 136
137int KOWhatsNextView::currentDateCount() 137int KOWhatsNextView::currentDateCount()
138{ 138{
139 return 0; 139 return 0;
140} 140}
141 141
142void KOWhatsNextView::clearList() 142void KOWhatsNextView::clearList()
143{ 143{
144 mTimer->stop(); 144 mTimer->stop();
145 mView->setText(" "); 145 mView->setText(" ");
146} 146}
147QPtrList<Incidence> KOWhatsNextView::selectedIncidences() 147QPtrList<Incidence> KOWhatsNextView::selectedIncidences()
148{ 148{
149 QPtrList<Incidence> eventList; 149 QPtrList<Incidence> eventList;
150 150
151 return eventList; 151 return eventList;
152} 152}
153 153
154void KOWhatsNextView::printMe() 154void KOWhatsNextView::printMe()
155{ 155{
156#ifdef DESKTOP_VERSION 156#ifdef DESKTOP_VERSION
157 mView->printMe(); 157 mView->printMe();
158#endif 158#endif
159} 159}
160void KOWhatsNextView::printPreview(CalPrinter *calPrinter, const QDate &fd, 160void KOWhatsNextView::printPreview(CalPrinter *calPrinter, const QDate &fd,
161 const QDate &td) 161 const QDate &td)
162{ 162{
163#ifndef KORG_NOPRINTER 163#ifndef KORG_NOPRINTER
164 calPrinter->preview(CalPrinter::Day, fd, td); 164 calPrinter->preview(CalPrinter::Day, fd, td);
165#endif 165#endif
166} 166}
167void KOWhatsNextView::updateConfig() 167void KOWhatsNextView::updateConfig()
168{ 168{
169 setFont( KOPrefs::instance()->mWhatsNextFont ); 169 setFont( KOPrefs::instance()->mWhatsNextFont );
170 updateView(); 170 updateView();
171 171
172} 172}
173void KOWhatsNextView::showEvent ( QShowEvent * e ) 173void KOWhatsNextView::showEvent ( QShowEvent * e )
174{ 174{
175 //qDebug("KOWhatsNextView::showEvent "); 175 //qDebug("KOWhatsNextView::showEvent ");
176 restartTimer(); 176 restartTimer();
177 QWidget::showEvent ( e ); 177 QWidget::showEvent ( e );
178} 178}
179void KOWhatsNextView::hideEvent ( QHideEvent * e) 179void KOWhatsNextView::hideEvent ( QHideEvent * e)
180{ 180{
181 //qDebug(" KOWhatsNextView::hideEvent"); 181 //qDebug(" KOWhatsNextView::hideEvent");
182 mTimer->stop(); 182 mTimer->stop();
183 QWidget::hideEvent ( e ); 183 QWidget::hideEvent ( e );
184} 184}
185void KOWhatsNextView::restartTimer() 185void KOWhatsNextView::restartTimer()
186{ 186{
187 //qDebug("KOWhatsNextView::restartTimer() "); 187 //qDebug("KOWhatsNextView::restartTimer() ");
188 mTimer->start( 300000 ); 188 mTimer->start( 300000 );
189 //mTimer->start( 5000 ); 189 //mTimer->start( 5000 );
190} 190}
191void KOWhatsNextView::updateView() 191void KOWhatsNextView::updateView()
192{ 192{
193 //qDebug("KOWhatsNextView::updateView() "); 193 //qDebug("KOWhatsNextView::updateView() ");
194 if ( mTimer->isActive() ) 194 if ( mTimer->isActive() )
195 restartTimer(); 195 restartTimer();
196 mCurrentMaxPrio = 5; 196 mCurrentMaxPrio = 5;
197 //qDebug("KOWhatsNextView::updateView() "); 197 //qDebug("KOWhatsNextView::updateView() ");
198 // mDateLabel->setText(KGlobal::locale()->formatDate(QDate::currentDate())); 198 // mDateLabel->setText(KGlobal::locale()->formatDate(QDate::currentDate()));
199 KIconLoader kil("korganizer"); 199 KIconLoader kil("korganizer");
200 QString ipath;// = new QString(); 200 QString ipath;// = new QString();
201 // kil.loadIcon("korganizer",KIcon::NoGroup,32,KIcon::DefaultState,&ipath); 201 // kil.loadIcon("korganizer",KIcon::NoGroup,32,KIcon::DefaultState,&ipath);
202 //<big><big><strong>" + date + "</strong></big></big>\n"; 202 //<big><big><strong>" + date + "</strong></big></big>\n";
203 mText = "<table width=\"100%\">\n"; 203 mText = "<table width=\"100%\">\n";
204 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>"; 204 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>";
205#ifdef DESKTOP_VERSION 205#ifdef DESKTOP_VERSION
206 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h1>"; 206 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h1>";
207#else 207#else
208 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h2>"; 208 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h2>";
209#endif 209#endif
210 // mText += "<img src=\""; 210 // mText += "<img src=\"";
211 // mText += ipath; 211 // mText += ipath;
212 // mText += "\">"; 212 // mText += "\">";
213 mEventDate = QDate::currentDate(); 213 mEventDate = QDate::currentDate();
214#ifdef DESKTOP_VERSION 214#ifdef DESKTOP_VERSION
215 mText += "<font color=\"#FFFFFF\"> <em>" + KGlobal::locale()->formatDate( mEventDate , false )+"</em></font></h1>"; 215 mText += "<font color=\"#FFFFFF\"> <em>" + KGlobal::locale()->formatDate( mEventDate , false )+"</em></font></h1>";
216#else 216#else
217 mText += "<font color=\"#FFFFFF\"> <em>" + KGlobal::locale()->formatDate( mEventDate , false )+"</em></font></h2>"; 217 mText += "<font color=\"#FFFFFF\"> <em>" + KGlobal::locale()->formatDate( mEventDate , false )+"</em></font></h2>";
218#endif 218#endif
219 mText += "</td></tr>\n<tr bgcolor=\"#EAF8FA\"><td>"; 219 mText += "</td></tr>\n<tr bgcolor=\"#EAF8FA\"><td>";
220 int iii; 220 int iii;
221 mTodos.clear(); 221 mTodos.clear();
222 QPtrList<Event> events; 222 QPtrList<Event> events;
223 QPtrList<Todo> todos = calendar()->todos(); 223 QPtrList<Todo> todos = calendar()->todos();
224 Todo * todo; 224 Todo * todo;
225 //mText += "<h2>" + i18n("Events: ") + "</h2>\n"; 225 //mText += "<h2>" + i18n("Events: ") + "</h2>\n";
226 int daysToShow = KOPrefs::instance()->mWhatsNextDays ; 226 int daysToShow = KOPrefs::instance()->mWhatsNextDays ;
227 bool itemAdded = false; 227 bool itemAdded = false;
228 for ( iii = 0; iii < daysToShow; ++iii ) { 228 for ( iii = 0; iii < daysToShow; ++iii ) {
229 QString date; 229 QString date;
230 itemAdded = false; 230 itemAdded = false;
231 events = calendar()->events( mEventDate, true ); 231 events = calendar()->events( mEventDate, true );
232 232
233 if ( iii == 0 ) { // today !!! 233 if ( iii == 0 ) { // today !!!
234 todo = todos.first(); 234 todo = todos.first();
235 while(todo) { 235 while(todo) {
236 if ( !todo->isCompleted() &&todo->hasDueDate() && todo->dtDue().date() < mEventDate ) { 236 if ( !todo->isCompleted() &&todo->hasDueDate() && todo->dtDue().date() < mEventDate ) {
237 if ( ! itemAdded ) { 237 if ( ! itemAdded ) {
238 appendDay ( iii, mEventDate ); 238 appendDay ( iii, mEventDate );
239 //itemAdded = true; 239 //itemAdded = true;
240 240
241 } //bool reply=false, bool notRed = true, bool appendTable = false); 241 } //bool reply=false, bool notRed = true, bool appendTable = false);
242 appendEvent(todo, false, false, !itemAdded ); 242 appendEvent(todo, false, false, !itemAdded );
243 itemAdded = true; 243 itemAdded = true;
244 } 244 }
245 todo = todos.next(); 245 todo = todos.next();
246 } 246 }
247 } 247 }
248 248
249 249
250 if (events.count() > 0) { 250 if (events.count() > 0) {
251 // mText += "<p></p>"; 251 // mText += "<p></p>";
252 // kil.loadIcon("month",KIcon::NoGroup,22,KIcon::DefaultState,&ipath); 252 // kil.loadIcon("month",KIcon::NoGroup,22,KIcon::DefaultState,&ipath);
253 // mText += "<h2>"; 253 // mText += "<h2>";
254 //mText += " <img src=\""; 254 //mText += " <img src=\"";
255 //mText += ipath; 255 //mText += ipath;
256 //mText += "\">"; 256 //mText += "\">";
257 if ( ! itemAdded ) { 257 if ( ! itemAdded ) {
258 appendDay ( iii, mEventDate ); 258 appendDay ( iii, mEventDate );
259 259
260 } 260 }
261 // for first day (iii == 0) 261 // for first day (iii == 0)
262 // we may have syncevents, or events in the past, which maybe should not be diaplayed 262 // we may have syncevents, or events in the past, which maybe should not be diaplayed
263 // for that reason we cannot append <table> in appendDay () for iii == 0 263 // for that reason we cannot append <table> in appendDay () for iii == 0
264 // we must append it in the first successful call of appendEvent() 264 // we must append it in the first successful call of appendEvent()
265 Event *ev = events.first(); 265 Event *ev = events.first();
266 while(ev) { 266 while(ev) {
267 //qDebug("+++++event append %s", ev->summary().latin1()); 267 //qDebug("+++++event append %s", ev->summary().latin1());
268 if ( true /*!ev->recurrence()->doesRecur() || ev->recursOn( mEventDate)*/) { 268 if ( true /*!ev->recurrence()->doesRecur() || ev->recursOn( mEventDate)*/) {
269 if ( appendEvent(ev, false , iii!= 0,!itemAdded ) ) 269 if ( appendEvent(ev, false , iii!= 0,!itemAdded ) )
270 itemAdded = true; 270 itemAdded = true;
271 } 271 }
272 ev = events.next(); 272 ev = events.next();
273 } 273 }
274 274
275 //mText += "</table>\n"; 275 //mText += "</table>\n";
276 } 276 }
277 277
278 todo = todos.first(); 278 todo = todos.first();
279 while(todo) { 279 while(todo) {
280 if ( !todo->isCompleted() &&todo->hasDueDate() && todo->dtDue().date() == mEventDate ) { 280 if ( !todo->isCompleted() &&todo->hasDueDate() && todo->dtDue().date() == mEventDate ) {
281 if ( ! itemAdded ) { 281 if ( ! itemAdded ) {
282 appendDay ( iii, mEventDate ); 282 appendDay ( iii, mEventDate );
283 //itemAdded = true; 283 //itemAdded = true;
284 } 284 }
285 appendEvent(todo, false , iii!= 0,!itemAdded); 285 appendEvent(todo, false , iii!= 0,!itemAdded);
286 itemAdded = true; 286 itemAdded = true;
287 } 287 }
288 todo = todos.next(); 288 todo = todos.next();
289 } 289 }
290 if ( !itemAdded && iii == 0 ) { 290 if ( !itemAdded && iii == 0 ) {
291 // appendDay ( iii, mEventDate ); 291 // appendDay ( iii, mEventDate );
292 //mText += "<table>"; 292 //mText += "<table>";
293 // mText += "<b><font color=\"#000080\"><em>"+i18n("No event, nothing to do.") +"</em></font></b>\n"; 293 // mText += "<b><font color=\"#000080\"><em>"+i18n("No event, nothing to do.") +"</em></font></b>\n";
294 mText += "<h3 align=\"center\"><font color=\"#008000\"><em>"+i18n("No event, nothing to do.") +"</em></font></h3>\n"; 294 mText += "<h3 align=\"center\"><font color=\"#008000\"><em>"+i18n("No event, nothing to do.") +"</em></font></h3>\n";
295 //mText +="</table>"; 295 //mText +="</table>";
296 } 296 }
297 if ( itemAdded ) 297 if ( itemAdded )
298 mText += "</table>\n"; 298 mText += "</table>\n";
299 mEventDate = mEventDate.addDays( 1 ); 299 mEventDate = mEventDate.addDays( 1 );
300 } 300 }
301 301
302 int topmostPrios = KOPrefs::instance()->mWhatsNextPrios; 302 int topmostPrios = KOPrefs::instance()->mWhatsNextPrios;
303 if (todos.count() > 0 && topmostPrios > 0 ) { 303 if (todos.count() > 0 && topmostPrios > 0 ) {
304 // kil.loadIcon("todo",KIcon::NoGroup,22,KIcon::DefaultState,&ipath); 304 // kil.loadIcon("todo",KIcon::NoGroup,22,KIcon::DefaultState,&ipath);
305 // mText += "<h2>"; 305 // mText += "<h2>";
306 //<img src=\""; 306 //<img src=\"";
307 // mText += ipath; 307 // mText += ipath;
308 // mText += "\">"; 308 // mText += "\">";
309 // mText += i18n("Overdue To-Do:") + "</h2>\n"; 309 // mText += i18n("Overdue To-Do:") + "</h2>\n";
310 310
311 //mText += "<ul>\n"; 311 //mText += "<ul>\n";
312 bool gotone = false; 312 bool gotone = false;
313 int priority = 1; 313 int priority = 1;
314 int priosFound = 0; 314 int priosFound = 0;
315#ifdef DESKTOP_VERSION 315#ifdef DESKTOP_VERSION
316 mText +="<p></p>"; 316 mText +="<p></p>";
317#endif 317#endif
318 318
319 mText +="<h2><em><font color=\"#000080\">" + i18n("Incomplete Todo:") + "</font></em></h2>\n"; 319 mText +="<h2><em><font color=\"#000080\">" + i18n("Incomplete Todo:") + "</font></em></h2>\n";
320 mText += "<ul>\n"; 320 mText += "<ul>\n";
321 while (!gotone && priority<6) { 321 while (!gotone && priority<6) {
322 todo = todos.first(); 322 todo = todos.first();
323 while(todo) { 323 while(todo) {
324 if (!todo->isCompleted() && (todo->priority() == priority) ) { 324 if (!todo->isCompleted() && (todo->priority() == priority) ) {
325 mCurrentMaxPrio = priority - priosFound + topmostPrios -1; 325 mCurrentMaxPrio = priority - priosFound + topmostPrios -1;
326 if ( appendTodo(todo) ) 326 if ( appendTodo(todo) )
327 gotone = true; 327 gotone = true;
328 } 328 }
329 todo = todos.next(); 329 todo = todos.next();
330 } 330 }
331 if ( gotone ) { 331 if ( gotone ) {
332 gotone = false; 332 gotone = false;
333 ++priosFound; 333 ++priosFound;
334 if ( priosFound == topmostPrios ) 334 if ( priosFound == topmostPrios )
335 break; 335 break;
336 } 336 }
337 priority++; 337 priority++;
338 // kdDebug() << "adding the todos..." << endl; 338 // kdDebug() << "adding the todos..." << endl;
339 } 339 }
340 mText += "</ul>\n"; 340 mText += "</ul>\n";
341 } 341 }
342 342
343 int replys = 0; 343 int replys = 0;
344 events = calendar()->events(QDate::currentDate(), QDate(2975,12,6)); 344 events = calendar()->events(QDate::currentDate(), QDate(2975,12,6));
345 if (events.count() > 0) { 345 if (events.count() > 0) {
346 Event *ev = events.first(); 346 Event *ev = events.first();
347 while(ev) { 347 while(ev) {
348 Attendee *me = ev->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 348 Attendee *me = ev->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
349 if (me!=0) { 349 if (me!=0) {
350 if (me->status()==Attendee::NeedsAction && me->RSVP()) { 350 if (me->status()==Attendee::NeedsAction && me->RSVP()) {
351 if (replys == 0) { 351 if (replys == 0) {
352 mText += "<p></p>"; 352 mText += "<p></p>";
353 // kil.loadIcon("reply",KIcon::NoGroup,22,KIcon::DefaultState,&ipath); 353 // kil.loadIcon("reply",KIcon::NoGroup,22,KIcon::DefaultState,&ipath);
354 //mText += "<h2>"; 354 //mText += "<h2>";
355 //<img src=\""; 355 //<img src=\"";
356 // mText += ipath; 356 // mText += ipath;
357 // mText += "\">"; 357 // mText += "\">";
358 //mText += i18n("Events and To-Dos that need a reply:") + "</h2>\n"; 358 //mText += i18n("Events and To-Dos that need a reply:") + "</h2>\n";
359 mText +="<h2><em><font color=\"#000080\">" + i18n("Events and To-Dos that need a reply:") + "</font></em></h2>\n"; 359 mText +="<h2><em><font color=\"#000080\">" + i18n("Events and To-Dos that need a reply:") + "</font></em></h2>\n";
360 mText += "<table>\n"; 360 mText += "<table>\n";
361 } 361 }
362 replys++; 362 replys++;
363 appendEvent(ev,true); 363 appendEvent(ev,true);
364 } 364 }
365 } 365 }
366 ev = events.next(); 366 ev = events.next();
367 } 367 }
368 } 368 }
369 todos = calendar()->todos(); 369 todos = calendar()->todos();
370 if (todos.count() > 0) { 370 if (todos.count() > 0) {
371 Todo *to = todos.first(); 371 Todo *to = todos.first();
372 while(to) { 372 while(to) {
373 if ( !to->isCompleted() ){ 373 if ( !to->isCompleted() ){
374 Attendee *me = to->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 374 Attendee *me = to->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
375 if (me!=0) { 375 if (me!=0) {
376 if (me->status()==Attendee::NeedsAction && me->RSVP()) { 376 if (me->status()==Attendee::NeedsAction && me->RSVP()) {
377 if (replys == 0) { 377 if (replys == 0) {
378 mText +="<h2><em><font color=\"#000080\">" + i18n("Events and To-Dos that need a reply:") + "</font></em></h2>\n"; 378 mText +="<h2><em><font color=\"#000080\">" + i18n("Events and To-Dos that need a reply:") + "</font></em></h2>\n";
379 mText += "<table>\n"; 379 mText += "<table>\n";
380 } 380 }
381 replys++; 381 replys++;
382 appendEvent(to, true); 382 appendEvent(to, true);
383 } 383 }
384 } 384 }
385 } 385 }
386 to = todos.next(); 386 to = todos.next();
387 } 387 }
388 } 388 }
389 if (replys > 0 ) mText += "</table>\n"; 389 if (replys > 0 ) mText += "</table>\n";
390 390
391 391
392 mText += "</td></tr>\n</table>\n"; 392 mText += "</td></tr>\n</table>\n";
393 393
394 mView->setText(mText); 394 mView->setText(mText);
395 mView->setFocus(); 395 mView->setFocus();
396 396
397 // QPixmap bPix = SmallIcon( "back" ); 397 // QPixmap bPix = SmallIcon( "back" );
398 // qDebug("xxxxxxxxxxxxxxxxxxxxx "); 398 // qDebug("xxxxxxxxxxxxxxxxxxxxx ");
399 // QWidget* test = new QWidget(); 399 // QWidget* test = new QWidget();
400 // test->setBackgroundMode(FixedPixmap ); 400 // test->setBackgroundMode(FixedPixmap );
401 // test->setBackgroundPixmap ( bPix ); 401 // test->setBackgroundPixmap ( bPix );
402 // test->resize( 300, 400 ); 402 // test->resize( 300, 400 );
403 // test->show(); 403 // test->show();
404 // mView->setBackgroundMode(FixedPixmap ); 404 // mView->setBackgroundMode(FixedPixmap );
405 // mView->setBackgroundPixmap ( bPix ); 405 // mView->setBackgroundPixmap ( bPix );
406 // qDebug("%s ",mText.latin1()); 406 // qDebug("%s ",mText.latin1());
407} 407}
408 408
409void KOWhatsNextView::appendDay( int i, QDate eventDate ) 409void KOWhatsNextView::appendDay( int i, QDate eventDate )
410{ 410{
411 QString date; 411 QString date;
412 QString day = KGlobal::locale()->formatDate( eventDate , KOPrefs::instance()->mShortDateInViewer); 412 QString day = KGlobal::locale()->formatDate( eventDate , KOPrefs::instance()->mShortDateInViewer);
413 if ( ! KOPrefs::instance()->mShortDateInViewer && QApplication::desktop()->width() < 320 ) { 413 if ( ! KOPrefs::instance()->mShortDateInViewer && QApplication::desktop()->width() < 320 ) {
414 if ( i == 0 ) { 414 if ( i == 0 ) {
415 //mText += "<table>\n"; 415 //mText += "<table>\n";
416 return;//date = "<em><font color=\"#008000\"><em>" + day+"</font></em>"; 416 return;//date = "<em><font color=\"#008000\"><em>" + day+"</font></em>";
417 } 417 }
418 else if ( i == 1 ) 418 else if ( i == 1 )
419 date = "<em><font color=\"#000080\">" + day + "</font></em>" ; 419 date = "<em><font color=\"#000080\">" + day + "</font></em>" ;
420 else date = "<em><font color=\"#000080\">" + day + "</font></em>"; 420 else date = "<em><font color=\"#000080\">" + day + "</font></em>";
421 mText += "<h2>" + date + "</h2>\n"; 421 mText += "<h2>" + date + "</h2>\n";
422 //mText += "<big><big><strong>" + date + "</strong></big></big>\n"; 422 //mText += "<big><big><strong>" + date + "</strong></big></big>\n";
423 mText += "<table>\n"; 423 mText += "<table>\n";
424 424
425 425
426 426
427 } else { 427 } else {
428 if ( i == 0 ) { 428 if ( i == 0 ) {
429 //mText += "<table>\n"; 429 //mText += "<table>\n";
430 return;// date = "<font color=\"#008000\"><em>" +i18n("Today: ") +"</em>" + day+"</font>"; 430 return;// date = "<font color=\"#008000\"><em>" +i18n("Today: ") +"</em>" + day+"</font>";
431 } 431 }
432 432
433#ifdef DESKTOP_VERSION 433#ifdef DESKTOP_VERSION
434 else if ( i == 1 ) { 434 else if ( i == 1 ) {
435 date = "<h2><em><font color=\"#000080\">" + i18n("Tomorrow: ") + day +"</font></em></h2>" ; 435 date = "<h2><em><font color=\"#000080\">" + i18n("Tomorrow: ") + day +"</font></em></h2>" ;
436 } 436 }
437 else date = "<h2><em><font color=\"#000080\">" + i18n("In %1 days: ").arg( i ) +day + "</font></em></h2>"; 437 else date = "<h2><em><font color=\"#000080\">" + i18n("In %1 days: ").arg( i ) +day + "</font></em></h2>";
438#else 438#else
439 else if ( i == 1 ) { 439 else if ( i == 1 ) {
440 date = "<em><font color=\"#000080\">" + i18n("Tomorrow: ") + day +"</font></em>" ; 440 date = "<em><font color=\"#000080\">" + i18n("Tomorrow: ") + day +"</font></em>" ;
441 } 441 }
442 else date = "<em><font color=\"#000080\">" + i18n("In %1 days: ").arg( i ) +day + "</font></em>"; 442 else date = "<em><font color=\"#000080\">" + i18n("In %1 days: ").arg( i ) +day + "</font></em>";
443 443
444#endif 444#endif
445 mText += "<h2>" + date + "</h2>\n"; 445 mText += "<h2>" + date + "</h2>\n";
446 //mText += "<big><big><strong>" + date + "</strong></big></big>\n"; 446 //mText += "<big><big><strong>" + date + "</strong></big></big>\n";
447 mText += "<table>\n"; 447 mText += "<table>\n";
448 } 448 }
449} 449}
450 450
451 451
452void KOWhatsNextView::showDates(const QDate &, const QDate &) 452void KOWhatsNextView::showDates(const QDate &, const QDate &)
453{ 453{
454 updateView(); 454 updateView();
455} 455}
456 456
457void KOWhatsNextView::showEvents(QPtrList<Event>) 457void KOWhatsNextView::showEvents(QPtrList<Event>)
458{ 458{
459} 459}
460 460
461void KOWhatsNextView::changeEventDisplay(Event *, int action) 461void KOWhatsNextView::changeEventDisplay(Event *, int action)
462{ 462{
463 switch(action) { 463 switch(action) {
464 case KOGlobals::EVENTADDED: 464 case KOGlobals::EVENTADDED:
465 updateView(); 465 updateView();
466 break; 466 break;
467 case KOGlobals::EVENTEDITED: 467 case KOGlobals::EVENTEDITED:
468 updateView(); 468 updateView();
469 break; 469 break;
470 case KOGlobals::EVENTDELETED: 470 case KOGlobals::EVENTDELETED:
471 updateView(); 471 updateView();
472 break; 472 break;
473 default: 473 default:
474 updateView(); 474 updateView();
475 kdDebug() << "KOWhatsNextView::changeEventDisplay(): Illegal action " << action << endl; 475 kdDebug() << "KOWhatsNextView::changeEventDisplay(): Illegal action " << action << endl;
476 } 476 }
477} 477}
478 478
479bool KOWhatsNextView::appendEvent(Incidence *ev, bool reply, bool notRed, bool appendTable ) 479bool KOWhatsNextView::appendEvent(Incidence *ev, bool reply, bool notRed, bool appendTable )
480{ 480{
481 if ( !KOPrefs::instance()->mShowSyncEvents && ev->uid().left(15) == QString("last-syncEvent-") ) 481 if ( !KOPrefs::instance()->mShowSyncEvents && ev->uid().left(15) == QString("last-syncEvent-") )
482 return false; 482 return false;
483 QDateTime cdt = QDateTime::currentDateTime(); 483 QDateTime cdt = QDateTime::currentDateTime();
484 QDateTime noc; 484 QDateTime noc;
485 QString tempText; 485 QString tempText;
486 if ( appendTable && !notRed ) { 486 if ( appendTable && !notRed ) {
487 tempText = "<table>"; 487 tempText = "<table>";
488 } 488 }
489 bool ok = true; 489 bool ok = true;
490 if ( reply ) { 490 if ( reply ) {
491 noc = ev->getNextOccurence( cdt, &ok ); 491 noc = ev->getNextOccurence( cdt, &ok );
492 if (! ok && ev->typeID() == eventID) 492 if (! ok && ev->typeID() == eventID)
493 return false; 493 return false;
494 } 494 }
495 bool bDay = false; 495 bool bDay = false;
496 if ( ev->isBirthday() || ev->isAnniversary() ) 496 if ( ev->isBirthday() || ev->isAnniversary() )
497 bDay = true; 497 bDay = true;
498 tempText += "<tr><td><b>"; 498 tempText += "<tr><td><b>";
499 if (ev->typeID() == eventID ) { 499 if (ev->typeID() == eventID ) {
500 if (reply) { 500 if (reply) {
501 if (!ev->doesFloat()) 501 if (!ev->doesFloat())
502 tempText += KGlobal::locale()->formatDateTime( noc , KOPrefs::instance()->mShortDateInViewer) +": "; 502 tempText += KGlobal::locale()->formatDateTime( noc , KOPrefs::instance()->mShortDateInViewer) +": ";
503 else 503 else
504 tempText += KGlobal::locale()->formatDate( noc.date() , KOPrefs::instance()->mShortDateInViewer) +": "; 504 tempText += KGlobal::locale()->formatDate( noc.date() , KOPrefs::instance()->mShortDateInViewer) +": ";
505 505
506 } else { 506 } else {
507 if (!ev->doesFloat()) { 507 if (!ev->doesFloat()) {
508 Event *event = static_cast<Event *>(ev); 508 Event *event = static_cast<Event *>(ev);
509 QDateTime st,end; 509 QDateTime st,end;
510 if ( event->recurrence()->doesRecur() ) { 510 if ( event->doesRecur() ) {
511 QDate recDate= mEventDate; 511 QDate recDate= mEventDate;
512 int days = event->dtStart().date().daysTo (event->dtEnd().date() ); 512 int days = event->dtStart().date().daysTo (event->dtEnd().date() );
513 while ( ! event->recursOn( recDate ) ) { 513 while ( ! event->recursOn( recDate ) ) {
514 recDate = recDate.addDays( -1 ); 514 recDate = recDate.addDays( -1 );
515 515
516 } 516 }
517 st = QDateTime ( recDate, event->dtStart().time() ); 517 st = QDateTime ( recDate, event->dtStart().time() );
518 end = QDateTime ( recDate.addDays( days ), event->dtEnd().time() ); 518 end = QDateTime ( recDate.addDays( days ), event->dtEnd().time() );
519 } 519 }
520 else { 520 else {
521 st = event->dtStart(); 521 st = event->dtStart();
522 end = event->dtEnd(); 522 end = event->dtEnd();
523 } 523 }
524 524
525 525
526 QString dateText; 526 QString dateText;
527 // qDebug("%s %s %s %s ", mEventDate.toString().latin1(),event->summary().latin1(), st .toString().latin1(),end.toString().latin1() ); 527 // qDebug("%s %s %s %s ", mEventDate.toString().latin1(),event->summary().latin1(), st .toString().latin1(),end.toString().latin1() );
528 if ( st.date() < mEventDate ) 528 if ( st.date() < mEventDate )
529 dateText = "++:++-"; 529 dateText = "++:++-";
530 else 530 else
531 dateText = event->dtStartTimeStr() + "-"; 531 dateText = event->dtStartTimeStr() + "-";
532 if ( KOPrefs::instance()->mWhatsNextTime2Lines ) 532 if ( KOPrefs::instance()->mWhatsNextTime2Lines )
533 dateText += " "; 533 dateText += " ";
534 if ( end.date() > mEventDate ) 534 if ( end.date() > mEventDate )
535 dateText += "++:++"; 535 dateText += "++:++";
536 else 536 else
537 dateText += event->dtEndTimeStr(); 537 dateText += event->dtEndTimeStr();
538 if ( notRed ) 538 if ( notRed )
539 tempText += dateText; 539 tempText += dateText;
540 else { 540 else {
541 if ( end < cdt ) { 541 if ( end < cdt ) {
542 if ( !KOPrefs::instance()->mWNViewShowsPast ) 542 if ( !KOPrefs::instance()->mWNViewShowsPast )
543 return false; 543 return false;
544 tempText += "<font color=\"#F00000\">" + dateText + "</font>"; 544 tempText += "<font color=\"#F00000\">" + dateText + "</font>";
545 } 545 }
546 else if ( st < cdt ) 546 else if ( st < cdt )
547 tempText += "<font color=\"#008000\">" + dateText + "</font>"; 547 tempText += "<font color=\"#008000\">" + dateText + "</font>";
548 else 548 else
549 tempText += dateText; 549 tempText += dateText;
550 550
551 } 551 }
552 552
553 } else { 553 } else {
554 if ( bDay ) { 554 if ( bDay ) {
555 555
556 if ( ev->isBirthday()) 556 if ( ev->isBirthday())
557 tempText += "<font color=\"#00B000\">" + i18n("Birthday") +":</font>"; 557 tempText += "<font color=\"#00B000\">" + i18n("Birthday") +":</font>";
558 else 558 else
559 tempText += "<font color=\"#00B0000\">" + i18n("Anniversary")+":</font>"; 559 tempText += "<font color=\"#00B0000\">" + i18n("Anniversary")+":</font>";
560 } else { 560 } else {
561 if ( ((Event*)ev)->isMultiDay() ) { 561 if ( ((Event*)ev)->isMultiDay() ) {
562 QString dfs = KGlobal::locale()->dateFormatShort(); 562 QString dfs = KGlobal::locale()->dateFormatShort();
563 KGlobal::locale()->setDateFormatShort("%d.%b"); 563 KGlobal::locale()->setDateFormatShort("%d.%b");
564 tempText +=KGlobal::locale()->formatDate(((Event*)ev)->dtStart().date(), true, KLocale::Userdefined) + "-"; 564 tempText +=KGlobal::locale()->formatDate(((Event*)ev)->dtStart().date(), true, KLocale::Userdefined) + "-";
565 if ( KOPrefs::instance()->mWhatsNextTime2Lines ) 565 if ( KOPrefs::instance()->mWhatsNextTime2Lines )
566 tempText += " "; 566 tempText += " ";
567 tempText +=KGlobal::locale()->formatDate(((Event*)ev)->dtEnd().date(), true, KLocale::Userdefined); 567 tempText +=KGlobal::locale()->formatDate(((Event*)ev)->dtEnd().date(), true, KLocale::Userdefined);
568 KGlobal::locale()->setDateFormatShort(dfs); 568 KGlobal::locale()->setDateFormatShort(dfs);
569 } else { 569 } else {
570 tempText += " " ;//i18n("Allday:"); 570 tempText += " " ;//i18n("Allday:");
571 } 571 }
572 } 572 }
573 573
574 } 574 }
575 } 575 }
576 } else { 576 } else {
577 mTodos.append( ev ); 577 mTodos.append( ev );
578 tempText += i18n("ToDo:"); 578 tempText += i18n("ToDo:");
579 if ( KOPrefs::instance()->mWhatsNextTime2Lines ) 579 if ( KOPrefs::instance()->mWhatsNextTime2Lines )
580 tempText += " "; 580 tempText += " ";
581 if (reply) { 581 if (reply) {
582 tempText += " "; 582 tempText += " ";
583 if ( noc != cdt ) { 583 if ( noc != cdt ) {
584 tempText += KGlobal::locale()->formatDate( noc.date() , KOPrefs::instance()->mShortDateInViewer) +": "; 584 tempText += KGlobal::locale()->formatDate( noc.date() , KOPrefs::instance()->mShortDateInViewer) +": ";
585 } 585 }
586 } else { 586 } else {
587 if ( ((Todo*)ev)->dtDue().date() < QDate::currentDate() ) { 587 if ( ((Todo*)ev)->dtDue().date() < QDate::currentDate() ) {
588 // tempText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>"; 588 // tempText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>";
589 QString dfs = KGlobal::locale()->dateFormatShort(); 589 QString dfs = KGlobal::locale()->dateFormatShort();
590 KGlobal::locale()->setDateFormatShort("%d.%b"); 590 KGlobal::locale()->setDateFormatShort("%d.%b");
591 tempText +="<font color=\"#F00000\">" + KGlobal::locale()->formatDate(((Todo*)ev)->dtDue().date(), true, KLocale::Userdefined) + "</font>"; 591 tempText +="<font color=\"#F00000\">" + KGlobal::locale()->formatDate(((Todo*)ev)->dtDue().date(), true, KLocale::Userdefined) + "</font>";
592 KGlobal::locale()->setDateFormatShort(dfs); 592 KGlobal::locale()->setDateFormatShort(dfs);
593 } else { 593 } else {
594 if (!ev->doesFloat() ) 594 if (!ev->doesFloat() )
595 if( ( (Todo*)ev)->dtDue() < cdt ) { 595 if( ( (Todo*)ev)->dtDue() < cdt ) {
596 tempText +="<font color=\"#F00000\">" + ((Todo*)ev)->dtDueTimeStr() + "</font>"; 596 tempText +="<font color=\"#F00000\">" + ((Todo*)ev)->dtDueTimeStr() + "</font>";
597 597
598 598
599 } else 599 } else
600 tempText +=((Todo*)ev)->dtDueTimeStr(); 600 tempText +=((Todo*)ev)->dtDueTimeStr();
601 mTodos.append( ev ); 601 mTodos.append( ev );
602 } 602 }
603 } 603 }
604 } 604 }
605 tempText += "</b></td><td>"; 605 tempText += "</b></td><td>";
606 bool needClose = false; 606 bool needClose = false;
607 if ( ev->cancelled() ) { 607 if ( ev->cancelled() ) {
608 tempText += "<font color=\"#F00000\">[c"; 608 tempText += "<font color=\"#F00000\">[c";
609 needClose =true; 609 needClose =true;
610 610
611 } 611 }
612 if ( ev->isAlarmEnabled() && ev->alarmEnabled()) { 612 if ( ev->isAlarmEnabled() && ev->alarmEnabled()) {
613 if ( !needClose) 613 if ( !needClose)
614 tempText +="["; 614 tempText +="[";
615 tempText += "a"; 615 tempText += "a";
616 needClose =true; 616 needClose =true;
617 617
618 } 618 }
619 if ( ev->description().length() > 0 ) { 619 if ( ev->description().length() > 0 ) {
620 if ( !needClose) 620 if ( !needClose)
621 tempText +="["; 621 tempText +="[";
622 tempText += "i"; 622 tempText += "i";
623 needClose =true; 623 needClose =true;
624 } 624 }
625 if ( ev->recurrence()->doesRecur() ) { 625 if ( ev->doesRecur() ) {
626 if ( !needClose) 626 if ( !needClose)
627 tempText +="["; 627 tempText +="[";
628 tempText += "r"; 628 tempText += "r";
629 needClose =true; 629 needClose =true;
630 } 630 }
631 if ( needClose ) { 631 if ( needClose ) {
632 tempText += "] "; 632 tempText += "] ";
633 } 633 }
634 if ( ev->cancelled() ) 634 if ( ev->cancelled() )
635 tempText += "</font>"; 635 tempText += "</font>";
636 tempText += "<a "; 636 tempText += "<a ";
637 if (ev->typeID() == eventID ) tempText += "href=\"event:"; 637 if (ev->typeID() == eventID ) tempText += "href=\"event:";
638 if (ev->typeID() == todoID ) tempText += "href=\"todo:"; 638 if (ev->typeID() == todoID ) tempText += "href=\"todo:";
639 tempText += ev->uid() + "\">"; 639 tempText += ev->uid() + "\">";
640 if ( ev->summary().length() > 0 ) 640 if ( ev->summary().length() > 0 )
641 tempText += ev->summary(); 641 tempText += ev->summary();
642 else 642 else
643 tempText += i18n("-no summary-"); 643 tempText += i18n("-no summary-");
644 if ( bDay ) { 644 if ( bDay ) {
645 noc = ev->getNextOccurence( cdt.addDays(-1), &ok ); 645 noc = ev->getNextOccurence( cdt.addDays(-1), &ok );
646 if ( ok ) { 646 if ( ok ) {
647 int years = 0; 647 int years = 0;
648 if ( ev->typeID() == todoID ) { 648 if ( ev->typeID() == todoID ) {
649 years = noc.date().year() -((Todo*)ev)->dtDue().date().year(); 649 years = noc.date().year() -((Todo*)ev)->dtDue().date().year();
650 } else 650 } else
651 years = noc.date().year() - ev->dtStart().date().year(); 651 years = noc.date().year() - ev->dtStart().date().year();
652 tempText += i18n(" (%1 y.)"). arg( years ); 652 tempText += i18n(" (%1 y.)"). arg( years );
653 } 653 }
654 } 654 }
655 655
656 tempText += "</a>"; 656 tempText += "</a>";
657 if ( KOPrefs::instance()->mWNViewShowLocation ) 657 if ( KOPrefs::instance()->mWNViewShowLocation )
658 if ( !ev->location().isEmpty() ) 658 if ( !ev->location().isEmpty() )
659 tempText += " ("+ev->location() +")"; 659 tempText += " ("+ev->location() +")";
660 if ( ev->relatedTo() && KOPrefs::instance()->mWNViewShowsParents) 660 if ( ev->relatedTo() && KOPrefs::instance()->mWNViewShowsParents)
661 tempText += " ["+ev->relatedTo()->summary() +"]"; 661 tempText += " ["+ev->relatedTo()->summary() +"]";
662 tempText += "</td></tr>\n"; 662 tempText += "</td></tr>\n";
663 mText += tempText; 663 mText += tempText;
664 return true; 664 return true;
665} 665}
666 666
667bool KOWhatsNextView::appendTodo(Incidence *ev, QString ind , bool isSub ) 667bool KOWhatsNextView::appendTodo(Incidence *ev, QString ind , bool isSub )
668{ 668{
669 if ( mTodos.find( ev ) != mTodos.end() ) return false; 669 if ( mTodos.find( ev ) != mTodos.end() ) return false;
670 670
671 mTodos.append( ev ); 671 mTodos.append( ev );
672 if ( !isSub ) 672 if ( !isSub )
673 mText += "<p>"; 673 mText += "<p>";
674 else 674 else
675 mText += "<li>"; 675 mText += "<li>";
676 mText += "[" +QString::number(ev->priority()) + "/" + QString::number(((Todo*)ev)->percentComplete())+"%] "; 676 mText += "[" +QString::number(ev->priority()) + "/" + QString::number(((Todo*)ev)->percentComplete())+"%] ";
677 677
678 678
679 mText += ind; 679 mText += ind;
680 bool needClose = false; 680 bool needClose = false;
681 if ( ev->cancelled() ) { 681 if ( ev->cancelled() ) {
682 mText += "<font color=\"#F00000\">[c"; 682 mText += "<font color=\"#F00000\">[c";
683 needClose =true; 683 needClose =true;
684 684
685 } 685 }
686 if ( ev->isAlarmEnabled() && ev->alarmEnabled() ) { 686 if ( ev->isAlarmEnabled() && ev->alarmEnabled() ) {
687 if ( !needClose) 687 if ( !needClose)
688 mText +="["; 688 mText +="[";
689 mText += "a"; 689 mText += "a";
690 needClose =true; 690 needClose =true;
691 691
692 } 692 }
693 693
694 if ( ev->description().length() > 0 ) { 694 if ( ev->description().length() > 0 ) {
695 if ( !needClose) 695 if ( !needClose)
696 mText +="["; 696 mText +="[";
697 mText += "i"; 697 mText += "i";
698 needClose =true; 698 needClose =true;
699 } 699 }
700 if ( ev->doesRecur() ) { 700 if ( ev->doesRecur() ) {
701 if ( !needClose) 701 if ( !needClose)
702 mText +="["; 702 mText +="[";
703 mText += "r"; 703 mText += "r";
704 needClose =true; 704 needClose =true;
705 } 705 }
706 // if ( ev->recurrence()->doesRecur() ) { 706 // if ( ev->recurrence()->doesRecur() ) {
707 // if ( !needClose) 707 // if ( !needClose)
708 // mText +="("; 708 // mText +="(";
709 // mText += "r"; 709 // mText += "r";
710 // needClose =true; 710 // needClose =true;
711 // } 711 // }
712 if ( needClose ) 712 if ( needClose )
713 mText += "] "; 713 mText += "] ";
714 if ( ev->cancelled() ) 714 if ( ev->cancelled() )
715 mText += "</font>"; 715 mText += "</font>";
716 mText += "<a href=\"todo:" + ev->uid() + "\">"; 716 mText += "<a href=\"todo:" + ev->uid() + "\">";
717 if ( ev->summary().length() > 0 ) 717 if ( ev->summary().length() > 0 )
718 mText += ev->summary(); 718 mText += ev->summary();
719 else 719 else
720 mText += i18n("-no summary-"); 720 mText += i18n("-no summary-");
721 mText += "</a>"; 721 mText += "</a>";
722 if ( ((Todo*)ev)->hasDueDate () ) { 722 if ( ((Todo*)ev)->hasDueDate () ) {
723 QString year = ""; 723 QString year = "";
724 int ye = ((Todo*)ev)->dtDue().date().year(); 724 int ye = ((Todo*)ev)->dtDue().date().year();
725 if ( QDateTime::currentDateTime().date().year() != ye ) 725 if ( QDateTime::currentDateTime().date().year() != ye )
726 year = QString::number( ye ); 726 year = QString::number( ye );
727 QString dfs = KGlobal::locale()->dateFormatShort(); 727 QString dfs = KGlobal::locale()->dateFormatShort();
728 KGlobal::locale()->setDateFormatShort("%d.%b"); 728 KGlobal::locale()->setDateFormatShort("%d.%b");
729 mText +="<font color=\"#00A000\"> [" + KGlobal::locale()->formatDate(((Todo*)ev)->dtDue().date(), true, KLocale::Userdefined) + "."+ year +"]</font>"; 729 mText +="<font color=\"#00A000\"> [" + KGlobal::locale()->formatDate(((Todo*)ev)->dtDue().date(), true, KLocale::Userdefined) + "."+ year +"]</font>";
730 KGlobal::locale()->setDateFormatShort(dfs); 730 KGlobal::locale()->setDateFormatShort(dfs);
731 } 731 }
732 if ( KOPrefs::instance()->mWNViewShowLocation ) 732 if ( KOPrefs::instance()->mWNViewShowLocation )
733 if ( !ev->location().isEmpty() ) 733 if ( !ev->location().isEmpty() )
734 mText += " ("+ev->location() +")"; 734 mText += " ("+ev->location() +")";
735 if ( !isSub ) { 735 if ( !isSub ) {
736 if ( ((Todo*)ev)->relatedTo()&& KOPrefs::instance()->mWNViewShowsParents) 736 if ( ((Todo*)ev)->relatedTo()&& KOPrefs::instance()->mWNViewShowsParents)
737 mText += " ["+ev->relatedTo()->summary() +"]"; 737 mText += " ["+ev->relatedTo()->summary() +"]";
738 mText += "</p>\n"; 738 mText += "</p>\n";
739 } 739 }
740 else { 740 else {
741 ind += "-"; 741 ind += "-";
742 mText += "</li>\n"; 742 mText += "</li>\n";
743 } 743 }
744 QPtrList<Incidence> Relations = ev->relations(); 744 QPtrList<Incidence> Relations = ev->relations();
745 Incidence *to; 745 Incidence *to;
746 for (to=Relations.first();to;to=Relations.next()) { 746 for (to=Relations.first();to;to=Relations.next()) {
747 if (!((Todo*)to)->isCompleted() && ((Todo*)to)->priority() <= mCurrentMaxPrio ) 747 if (!((Todo*)to)->isCompleted() && ((Todo*)to)->priority() <= mCurrentMaxPrio )
748 appendTodo( to, ind , true ); 748 appendTodo( to, ind , true );
749 } 749 }
750 750
751 return true; 751 return true;
752} 752}
753 753
754/* 754/*
755 void KOWhatsNextView::createEventViewer() 755 void KOWhatsNextView::createEventViewer()
756 { 756 {
757 if (!mEventViewer) { 757 if (!mEventViewer) {
758 758
759 mEventViewer = new KOEventViewerDialog(this); 759 mEventViewer = new KOEventViewerDialog(this);
760 } 760 }
761 } 761 }
762*/ 762*/
763void KOWhatsNextView::setEventViewer(KOEventViewerDialog* v ) 763void KOWhatsNextView::setEventViewer(KOEventViewerDialog* v )
764{ 764{
765 mEventViewer = v; 765 mEventViewer = v;
766} 766}
767 767
768// TODO: Create this function in CalendarView and remove it from here 768// TODO: Create this function in CalendarView and remove it from here
769void KOWhatsNextView::showIncidence(const QString &uid) 769void KOWhatsNextView::showIncidence(const QString &uid)
770{ 770{
771 771
772 if ( !mEventViewer ) { 772 if ( !mEventViewer ) {
773 qDebug("KOWhatsNextView::showIncidence::sorry, no event viewer set "); 773 qDebug("KOWhatsNextView::showIncidence::sorry, no event viewer set ");
774 return; 774 return;
775 } 775 }
776 //kdDebug() << "KOWhatsNextView::showIncidence(): " << uid << endl; 776 //kdDebug() << "KOWhatsNextView::showIncidence(): " << uid << endl;
777 //qDebug("KOWhatsNextView::showIncidence %s ", uid.latin1()); 777 //qDebug("KOWhatsNextView::showIncidence %s ", uid.latin1());
778 if (uid.startsWith("event:")) { 778 if (uid.startsWith("event:")) {
779#ifdef DESKTOP_VERSION 779#ifdef DESKTOP_VERSION
780 Event *event = calendar()->event(uid.mid(8)); 780 Event *event = calendar()->event(uid.mid(8));
781#else 781#else
782 Event *event = calendar()->event(uid.mid(6)); 782 Event *event = calendar()->event(uid.mid(6));
783#endif 783#endif
784 //qDebug("event %d uid %s ", event, uid.mid(6).latin1()); 784 //qDebug("event %d uid %s ", event, uid.mid(6).latin1());
785 if (!event) return; 785 if (!event) return;
786 //createEventViewer(); 786 //createEventViewer();
787 mEventViewer->setEvent(event); 787 mEventViewer->setEvent(event);
788 } else if (uid.startsWith("todo:")) { 788 } else if (uid.startsWith("todo:")) {
789#ifdef DESKTOP_VERSION 789#ifdef DESKTOP_VERSION
790 Todo *todo = calendar()->todo(uid.mid(7)); 790 Todo *todo = calendar()->todo(uid.mid(7));
791#else 791#else
792 Todo *todo = calendar()->todo(uid.mid(5)); 792 Todo *todo = calendar()->todo(uid.mid(5));
793#endif 793#endif
794 if (!todo) return; 794 if (!todo) return;
795 //createEventViewer(); 795 //createEventViewer();
796 mEventViewer->setTodo(todo); 796 mEventViewer->setTodo(todo);
797 } else { 797 } else {
798 return; 798 return;
799 799
800 } 800 }
801 mEventViewer->showMe(); 801 mEventViewer->showMe();
802 mEventViewer->raise(); 802 mEventViewer->raise();
803} 803}