-rw-r--r-- | korganizer/komonthview.cpp | 6 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 1 | ||||
-rw-r--r-- | libkcal/icalformat.cpp | 17 | ||||
-rw-r--r-- | libkcal/icalformat.h | 3 | ||||
-rw-r--r-- | libkcal/todo.cpp | 7 |
5 files changed, 24 insertions, 10 deletions
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp index eea9a4d..4aeb20c 100644 --- a/korganizer/komonthview.cpp +++ b/korganizer/komonthview.cpp | |||
@@ -1,2326 +1,2330 @@ | |||
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 |
60 | QToolTipGroup *MonthViewCell::mToolTipGroup = 0; | 60 | QToolTipGroup *MonthViewCell::mToolTipGroup = 0; |
61 | #endif | 61 | #endif |
62 | class KNOWhatsThis :public QWhatsThis | 62 | class KNOWhatsThis :public QWhatsThis |
63 | { | 63 | { |
64 | public: | 64 | public: |
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 | ||
68 | protected: | 68 | protected: |
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 | }; |
73 | private: | 73 | private: |
74 | KNoScrollListBox* _wid; | 74 | KNoScrollListBox* _wid; |
75 | 75 | ||
76 | }; | 76 | }; |
77 | 77 | ||
78 | 78 | ||
79 | KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name) | 79 | KNoScrollListBox::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 | } |
90 | KNoScrollListBox::~KNoScrollListBox() | 90 | KNoScrollListBox::~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 | ||
100 | void KNoScrollListBox::focusInEvent ( QFocusEvent * e ) | 100 | void 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 | } |
136 | void KNoScrollListBox::focusOutEvent ( QFocusEvent * e ) | 136 | void 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 | ||
148 | QString KNoScrollListBox::getWhatsThisText(QPoint p) | 148 | QString 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 | } |
159 | void KNoScrollListBox::keyPressEvent(QKeyEvent *e) | 159 | void 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 | ||
243 | void KNoScrollListBox::oneDown() | 243 | void 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 | } |
261 | void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e) | 261 | void 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 | ||
272 | void KNoScrollListBox::mousePressEvent(QMouseEvent *e) | 272 | void 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 | ||
281 | MonthViewItem::MonthViewItem( Incidence *incidence, const QString & s) | 281 | MonthViewItem::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 | } |
288 | void MonthViewItem::recycle( Incidence *incidence, const QString & s) | 288 | void 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 | ||
301 | bool MonthViewItem::setHighlightedFalse() | 301 | bool 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 | ||
309 | bool MonthViewItem::setHighlighted( Incidence * inc ) | 309 | bool 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 | } |
324 | void MonthViewItem::paint(QPainter *p) | 324 | void 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 | ||
460 | int MonthViewItem::height(const QListBox *lb) const | 460 | int 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 | ||
468 | int MonthViewItem::width(const QListBox *lb) const | 468 | int 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 | ||
500 | MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par ) | 500 | MonthViewCell::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 |
541 | QToolTipGroup *MonthViewCell::toolTipGroup() | 541 | QToolTipGroup *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 | ||
548 | void MonthViewCell::setDate( const QDate &date ) | 548 | void 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 | ||
558 | QDate MonthViewCell::date() const | 558 | QDate MonthViewCell::date() const |
559 | { | 559 | { |
560 | return mDate; | 560 | return mDate; |
561 | } | 561 | } |
562 | 562 | ||
563 | void MonthViewCell::setPrimary( bool primary ) | 563 | void MonthViewCell::setPrimary( bool primary ) |
564 | { | 564 | { |
565 | mPrimary = primary; | 565 | mPrimary = primary; |
566 | //setMyPalette(); | 566 | //setMyPalette(); |
567 | } | 567 | } |
568 | void MonthViewCell::setMyPalette() | 568 | void 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 | } |
598 | QPalette MonthViewCell::getPalette () | 598 | QPalette 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 | } |
611 | bool MonthViewCell::isPrimary() const | 611 | bool MonthViewCell::isPrimary() const |
612 | { | 612 | { |
613 | return mPrimary; | 613 | return mPrimary; |
614 | } | 614 | } |
615 | 615 | ||
616 | void MonthViewCell::setHoliday( bool holiday ) | 616 | void MonthViewCell::setHoliday( bool holiday ) |
617 | { | 617 | { |
618 | mHoliday = holiday; | 618 | mHoliday = holiday; |
619 | //setMyPalette(); | 619 | //setMyPalette(); |
620 | } | 620 | } |
621 | 621 | ||
622 | void MonthViewCell::setHoliday( const QString &holiday ) | 622 | void 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 | ||
631 | void MonthViewCell::startUpdateCell() | 631 | void 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 | ||
683 | int MonthViewCell::insertEvent(Event *event) | 683 | int 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->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 | } |
833 | void MonthViewCell::insertTodo(Todo *todo) | 833 | void 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->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 | } |
889 | void MonthViewCell::repaintfinishUpdateCell() | 889 | void 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 | } |
899 | void MonthViewCell::finishUpdateCell() | 899 | void 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 | } |
917 | void MonthViewCell::updateCell() | 917 | void 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 | ||
939 | void MonthViewCell::updateConfig( bool bigFont ) // = false | 939 | void 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 | ||
972 | void MonthViewCell::enableScrollBars( bool enabled ) | 972 | void 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 | ||
1002 | Incidence *MonthViewCell::selectedIncidence() | 1002 | Incidence *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 | ||
1015 | QDate MonthViewCell::selectedIncidenceDate() | 1015 | QDate 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 | ||
1023 | void MonthViewCell::deselect() | 1023 | void MonthViewCell::deselect() |
1024 | { | 1024 | { |
1025 | clearSelection(); | 1025 | clearSelection(); |
1026 | enableScrollBars( false ); | 1026 | enableScrollBars( false ); |
1027 | // updateCell(); | 1027 | // updateCell(); |
1028 | } | 1028 | } |
1029 | void MonthViewCell::select() | 1029 | void MonthViewCell::select() |
1030 | { | 1030 | { |
1031 | ;// updateCell(); | 1031 | ;// updateCell(); |
1032 | } | 1032 | } |
1033 | 1033 | ||
1034 | void MonthViewCell::resizeEvent ( QResizeEvent * e ) | 1034 | void 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 | ||
1068 | void MonthViewCell::defaultAction( QListBoxItem *item ) | 1068 | void 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 | } |
1081 | void MonthViewCell::showDay() | 1081 | void MonthViewCell::showDay() |
1082 | { | 1082 | { |
1083 | emit showDaySignal( date() ); | 1083 | emit showDaySignal( date() ); |
1084 | } | 1084 | } |
1085 | void MonthViewCell::newEvent() | 1085 | void 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 | } |
1090 | void MonthViewCell::cellClicked( QListBoxItem *item ) | 1090 | void 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 | ||
1101 | void MonthViewCell::contextMenu( QListBoxItem *item ) | 1101 | void 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 ); | 1108 | //selection( item ); |
1109 | //qApp->processEvents(); | 1109 | //qApp->processEvents(); |
1110 | MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); | 1110 | MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); |
1111 | Incidence *incidence = eventItem->incidence(); | 1111 | Incidence *incidence = eventItem->incidence(); |
1112 | if ( incidence ) mMonthView->showContextMenu( incidence ); | 1112 | if ( incidence ) { |
1113 | mMonthView->showContextMenu( incidence ); | ||
1114 | selection( item ); | ||
1115 | doHighLight( incidence ); | ||
1116 | } | ||
1113 | } | 1117 | } |
1114 | 1118 | ||
1115 | void MonthViewCell::selection( QListBoxItem *item ) | 1119 | void MonthViewCell::selection( QListBoxItem *item ) |
1116 | { | 1120 | { |
1117 | if ( !item ) { | 1121 | if ( !item ) { |
1118 | emit highlightIncidence( 0 , this, 0 ); | 1122 | emit highlightIncidence( 0 , this, 0 ); |
1119 | return; | 1123 | return; |
1120 | } | 1124 | } |
1121 | MonthViewItem * it = (static_cast<MonthViewItem *>( item )); | 1125 | MonthViewItem * it = (static_cast<MonthViewItem *>( item )); |
1122 | emit highlightIncidence( it->incidence(), this, it->multiDay() ); | 1126 | emit highlightIncidence( it->incidence(), this, it->multiDay() ); |
1123 | mMonthView->setSelectedCell( this ); | 1127 | mMonthView->setSelectedCell( this ); |
1124 | } | 1128 | } |
1125 | 1129 | ||
1126 | void MonthViewCell::deHighLight() | 1130 | void MonthViewCell::deHighLight() |
1127 | { | 1131 | { |
1128 | MonthViewItem *mitem = (MonthViewItem*) firstItem (); | 1132 | MonthViewItem *mitem = (MonthViewItem*) firstItem (); |
1129 | while ( mitem ) { | 1133 | while ( mitem ) { |
1130 | if ( mitem->setHighlightedFalse() ) | 1134 | if ( mitem->setHighlightedFalse() ) |
1131 | updateItem ( mitem ); | 1135 | updateItem ( mitem ); |
1132 | mitem = (MonthViewItem *)mitem->next(); | 1136 | mitem = (MonthViewItem *)mitem->next(); |
1133 | } | 1137 | } |
1134 | } | 1138 | } |
1135 | // returns true if no inc found | 1139 | // returns true if no inc found |
1136 | bool MonthViewCell::doHighLight( Incidence * inc ) | 1140 | bool MonthViewCell::doHighLight( Incidence * inc ) |
1137 | { | 1141 | { |
1138 | 1142 | ||
1139 | MonthViewItem *mitem = (MonthViewItem*) firstItem (); | 1143 | MonthViewItem *mitem = (MonthViewItem*) firstItem (); |
1140 | while ( mitem ) { | 1144 | while ( mitem ) { |
1141 | if ( mitem->incidence() == inc ) { | 1145 | if ( mitem->incidence() == inc ) { |
1142 | if ( mitem->setHighlighted( inc ) ) | 1146 | if ( mitem->setHighlighted( inc ) ) |
1143 | updateItem ( mitem ); | 1147 | updateItem ( mitem ); |
1144 | return false; | 1148 | return false; |
1145 | } | 1149 | } |
1146 | mitem = (MonthViewItem *)mitem->next(); | 1150 | mitem = (MonthViewItem *)mitem->next(); |
1147 | } | 1151 | } |
1148 | return true; | 1152 | return true; |
1149 | } | 1153 | } |
1150 | // ******************************************************************************* | 1154 | // ******************************************************************************* |
1151 | // ******************************************************************************* | 1155 | // ******************************************************************************* |
1152 | // ******************************************************************************* | 1156 | // ******************************************************************************* |
1153 | 1157 | ||
1154 | 1158 | ||
1155 | KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) | 1159 | KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) |
1156 | : KOEventView( calendar, parent, name ), | 1160 | : KOEventView( calendar, parent, name ), |
1157 | mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), | 1161 | mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), |
1158 | mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) | 1162 | mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) |
1159 | { | 1163 | { |
1160 | mFlagKeyPressed = false; | 1164 | mFlagKeyPressed = false; |
1161 | mShortDayLabelsM = false; | 1165 | mShortDayLabelsM = false; |
1162 | mShortDayLabelsW = false; | 1166 | mShortDayLabelsW = false; |
1163 | skipResize = false; | 1167 | skipResize = false; |
1164 | clPending = true; | 1168 | clPending = true; |
1165 | mPopupCell = 0; | 1169 | mPopupCell = 0; |
1166 | mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" ); | 1170 | mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" ); |
1167 | mWidStack = new QWidgetStack( this ); | 1171 | mWidStack = new QWidgetStack( this ); |
1168 | QVBoxLayout* hb = new QVBoxLayout( this ); | 1172 | QVBoxLayout* hb = new QVBoxLayout( this ); |
1169 | mMonthView = new QWidget( mWidStack ); | 1173 | mMonthView = new QWidget( mWidStack ); |
1170 | mWeekView = new QWidget( mWidStack ); | 1174 | mWeekView = new QWidget( mWidStack ); |
1171 | #if QT_VERSION >= 0x030000 | 1175 | #if QT_VERSION >= 0x030000 |
1172 | mWidStack->addWidget(mMonthView ); | 1176 | mWidStack->addWidget(mMonthView ); |
1173 | mWidStack->addWidget(mWeekView ); | 1177 | mWidStack->addWidget(mWeekView ); |
1174 | #else | 1178 | #else |
1175 | mWidStack->addWidget( mMonthView, 1 ); | 1179 | mWidStack->addWidget( mMonthView, 1 ); |
1176 | mWidStack->addWidget( mWeekView , 1 ); | 1180 | mWidStack->addWidget( mWeekView , 1 ); |
1177 | #endif | 1181 | #endif |
1178 | hb->addWidget( mNavigatorBar ); | 1182 | hb->addWidget( mNavigatorBar ); |
1179 | hb->addWidget( mWidStack ); | 1183 | hb->addWidget( mWidStack ); |
1180 | mShowWeekView = KOPrefs::instance()->mMonthViewWeek; | 1184 | mShowWeekView = KOPrefs::instance()->mMonthViewWeek; |
1181 | updatePossible = false; | 1185 | updatePossible = false; |
1182 | //updatePossible = true; | 1186 | //updatePossible = true; |
1183 | mCells.setAutoDelete( true ); | 1187 | mCells.setAutoDelete( true ); |
1184 | mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; | 1188 | mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; |
1185 | mDayLabels.resize( mDaysPerWeek ); | 1189 | mDayLabels.resize( mDaysPerWeek ); |
1186 | mDayLabelsW.resize( mDaysPerWeek ); | 1190 | mDayLabelsW.resize( mDaysPerWeek ); |
1187 | QFont bfont = font(); | 1191 | QFont bfont = font(); |
1188 | if ( QApplication::desktop()->width() < 650 ) { | 1192 | if ( QApplication::desktop()->width() < 650 ) { |
1189 | bfont.setPointSize( bfont.pointSize() - 2 ); | 1193 | bfont.setPointSize( bfont.pointSize() - 2 ); |
1190 | } | 1194 | } |
1191 | bfont.setBold( true ); | 1195 | bfont.setBold( true ); |
1192 | int i; | 1196 | int i; |
1193 | 1197 | ||
1194 | for( i = 0; i < mDaysPerWeek; i++ ) { | 1198 | for( i = 0; i < mDaysPerWeek; i++ ) { |
1195 | QLabel *label = new QLabel( mMonthView ); | 1199 | QLabel *label = new QLabel( mMonthView ); |
1196 | label->setFont(bfont); | 1200 | label->setFont(bfont); |
1197 | label->setFrameStyle(QFrame::Panel|QFrame::Raised); | 1201 | label->setFrameStyle(QFrame::Panel|QFrame::Raised); |
1198 | label->setLineWidth(1); | 1202 | label->setLineWidth(1); |
1199 | label->setAlignment(AlignCenter); | 1203 | label->setAlignment(AlignCenter); |
1200 | mDayLabels.insert( i, label ); | 1204 | mDayLabels.insert( i, label ); |
1201 | label = new QLabel( mWeekView ); | 1205 | label = new QLabel( mWeekView ); |
1202 | label->setFont(bfont); | 1206 | label->setFont(bfont); |
1203 | label->setFrameStyle(QFrame::Panel|QFrame::Raised); | 1207 | label->setFrameStyle(QFrame::Panel|QFrame::Raised); |
1204 | label->setLineWidth(1); | 1208 | label->setLineWidth(1); |
1205 | label->setAlignment(AlignCenter); | 1209 | label->setAlignment(AlignCenter); |
1206 | mDayLabelsW.insert( i, label ); | 1210 | mDayLabelsW.insert( i, label ); |
1207 | } | 1211 | } |
1208 | 1212 | ||
1209 | bfont.setBold( false ); | 1213 | bfont.setBold( false ); |
1210 | mWeekLabels.resize( mNumWeeks+1 ); | 1214 | mWeekLabels.resize( mNumWeeks+1 ); |
1211 | mWeekLabelsW.resize( 2 ); | 1215 | mWeekLabelsW.resize( 2 ); |
1212 | for( i = 0; i < mNumWeeks+1; i++ ) { | 1216 | for( i = 0; i < mNumWeeks+1; i++ ) { |
1213 | KOWeekButton *label = new KOWeekButton( mMonthView ); | 1217 | KOWeekButton *label = new KOWeekButton( mMonthView ); |
1214 | label->setFocusPolicy(NoFocus); | 1218 | label->setFocusPolicy(NoFocus); |
1215 | label->setFont(bfont); | 1219 | label->setFont(bfont); |
1216 | connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); | 1220 | connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); |
1217 | label->setFlat(true); | 1221 | label->setFlat(true); |
1218 | QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); | 1222 | QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); |
1219 | //label->setFrameStyle(QFrame::Panel|QFrame::Raised); | 1223 | //label->setFrameStyle(QFrame::Panel|QFrame::Raised); |
1220 | //label->setLineWidth(1); | 1224 | //label->setLineWidth(1); |
1221 | //label->setAlignment(AlignCenter); | 1225 | //label->setAlignment(AlignCenter); |
1222 | mWeekLabels.insert( i, label ); | 1226 | mWeekLabels.insert( i, label ); |
1223 | } | 1227 | } |
1224 | mWeekLabels[mNumWeeks]->setText( i18n("W")); | 1228 | mWeekLabels[mNumWeeks]->setText( i18n("W")); |
1225 | mWeekLabels[mNumWeeks]->setFocusPolicy(WheelFocus); | 1229 | mWeekLabels[mNumWeeks]->setFocusPolicy(WheelFocus); |
1226 | QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number")); | 1230 | QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number")); |
1227 | 1231 | ||
1228 | for( i = 0; i < 1+1; i++ ) { | 1232 | for( i = 0; i < 1+1; i++ ) { |
1229 | KOWeekButton *label = new KOWeekButton( mWeekView ); | 1233 | KOWeekButton *label = new KOWeekButton( mWeekView ); |
1230 | label->setFocusPolicy(NoFocus); | 1234 | label->setFocusPolicy(NoFocus); |
1231 | label->setFont(bfont); | 1235 | label->setFont(bfont); |
1232 | connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); | 1236 | connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); |
1233 | label->setFlat(true); | 1237 | label->setFlat(true); |
1234 | QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); | 1238 | QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); |
1235 | //label->setFrameStyle(QFrame::Panel|QFrame::Raised); | 1239 | //label->setFrameStyle(QFrame::Panel|QFrame::Raised); |
1236 | //label->setLineWidth(1); | 1240 | //label->setLineWidth(1); |
1237 | //label->setAlignment(AlignCenter); | 1241 | //label->setAlignment(AlignCenter); |
1238 | mWeekLabelsW.insert( i, label ); | 1242 | mWeekLabelsW.insert( i, label ); |
1239 | } | 1243 | } |
1240 | mWeekLabelsW[1]->setText( i18n("W")); | 1244 | mWeekLabelsW[1]->setText( i18n("W")); |
1241 | mWeekLabelsW[1]->setFocusPolicy(WheelFocus); | 1245 | mWeekLabelsW[1]->setFocusPolicy(WheelFocus); |
1242 | 1246 | ||
1243 | 1247 | ||
1244 | int row, col; | 1248 | int row, col; |
1245 | mCells.resize( mNumCells ); | 1249 | mCells.resize( mNumCells ); |
1246 | for( row = 0; row < mNumWeeks; ++row ) { | 1250 | for( row = 0; row < mNumWeeks; ++row ) { |
1247 | for( col = 0; col < mDaysPerWeek; ++col ) { | 1251 | for( col = 0; col < mDaysPerWeek; ++col ) { |
1248 | MonthViewCell *cell = new MonthViewCell( this, mMonthView ); | 1252 | MonthViewCell *cell = new MonthViewCell( this, mMonthView ); |
1249 | mCells.insert( row * mDaysPerWeek + col, cell ); | 1253 | mCells.insert( row * mDaysPerWeek + col, cell ); |
1250 | 1254 | ||
1251 | connect( cell, SIGNAL( defaultAction( Incidence * ) ), | 1255 | connect( cell, SIGNAL( defaultAction( Incidence * ) ), |
1252 | SLOT( defaultAction( Incidence * ) ) ); | 1256 | SLOT( defaultAction( Incidence * ) ) ); |
1253 | connect( cell, SIGNAL( newEventSignal( QDateTime ) ), | 1257 | connect( cell, SIGNAL( newEventSignal( QDateTime ) ), |
1254 | SIGNAL( newEventSignal( QDateTime ) ) ); | 1258 | SIGNAL( newEventSignal( QDateTime ) ) ); |
1255 | connect( cell, SIGNAL( showDaySignal( QDate ) ), | 1259 | connect( cell, SIGNAL( showDaySignal( QDate ) ), |
1256 | SIGNAL( showDaySignal( QDate ) ) ); | 1260 | SIGNAL( showDaySignal( QDate ) ) ); |
1257 | connect( cell, SIGNAL( nextCell() ), | 1261 | connect( cell, SIGNAL( nextCell() ), |
1258 | SLOT( nextCell() ) ); | 1262 | SLOT( nextCell() ) ); |
1259 | connect( cell, SIGNAL( prevCell() ), | 1263 | connect( cell, SIGNAL( prevCell() ), |
1260 | SLOT( prevCell() ) ); | 1264 | SLOT( prevCell() ) ); |
1261 | connect( cell, SIGNAL( highlightIncidence( Incidence * , MonthViewCell *, int ) ), | 1265 | connect( cell, SIGNAL( highlightIncidence( Incidence * , MonthViewCell *, int ) ), |
1262 | SLOT( incidenceHighlighted( Incidence *, MonthViewCell *, int ) )); | 1266 | SLOT( incidenceHighlighted( Incidence *, MonthViewCell *, int ) )); |
1263 | } | 1267 | } |
1264 | } | 1268 | } |
1265 | mCellsW.resize( mDaysPerWeek ); | 1269 | mCellsW.resize( mDaysPerWeek ); |
1266 | for( col = 0; col < mDaysPerWeek; ++col ) { | 1270 | for( col = 0; col < mDaysPerWeek; ++col ) { |
1267 | MonthViewCell *cell = new MonthViewCell( this, mWeekView ); | 1271 | MonthViewCell *cell = new MonthViewCell( this, mWeekView ); |
1268 | mCellsW.insert( col, cell ); | 1272 | mCellsW.insert( col, cell ); |
1269 | 1273 | ||
1270 | connect( cell, SIGNAL( defaultAction( Incidence * ) ), | 1274 | connect( cell, SIGNAL( defaultAction( Incidence * ) ), |
1271 | SLOT( defaultAction( Incidence * ) ) ); | 1275 | SLOT( defaultAction( Incidence * ) ) ); |
1272 | connect( cell, SIGNAL( newEventSignal( QDateTime ) ), | 1276 | connect( cell, SIGNAL( newEventSignal( QDateTime ) ), |
1273 | SIGNAL( newEventSignal( QDateTime ) ) ); | 1277 | SIGNAL( newEventSignal( QDateTime ) ) ); |
1274 | connect( cell, SIGNAL( showDaySignal( QDate ) ), | 1278 | connect( cell, SIGNAL( showDaySignal( QDate ) ), |
1275 | SIGNAL( showDaySignal( QDate ) ) ); | 1279 | SIGNAL( showDaySignal( QDate ) ) ); |
1276 | connect( cell, SIGNAL( nextCell() ), | 1280 | connect( cell, SIGNAL( nextCell() ), |
1277 | SLOT( nextCell() ) ); | 1281 | SLOT( nextCell() ) ); |
1278 | connect( cell, SIGNAL( prevCell() ), | 1282 | connect( cell, SIGNAL( prevCell() ), |
1279 | SLOT( prevCell() ) ); | 1283 | SLOT( prevCell() ) ); |
1280 | connect( cell, SIGNAL( highlightIncidence( Incidence * , MonthViewCell *, int ) ), | 1284 | connect( cell, SIGNAL( highlightIncidence( Incidence * , MonthViewCell *, int ) ), |
1281 | SLOT( incidenceHighlighted( Incidence *, MonthViewCell *, int ) )); | 1285 | SLOT( incidenceHighlighted( Incidence *, MonthViewCell *, int ) )); |
1282 | cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont ); | 1286 | cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont ); |
1283 | } | 1287 | } |
1284 | 1288 | ||
1285 | //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) ); | 1289 | //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) ); |
1286 | mContextMenu = eventPopup(); | 1290 | mContextMenu = eventPopup(); |
1287 | mContextMenu->addAdditionalItem(QIconSet(QPixmap()), | 1291 | mContextMenu->addAdditionalItem(QIconSet(QPixmap()), |
1288 | i18n("New Event..."),this, | 1292 | i18n("New Event..."),this, |
1289 | SLOT(slotNewEvent()),false); | 1293 | SLOT(slotNewEvent()),false); |
1290 | mContextMenu->addAdditionalItem(QIconSet(QPixmap()), | 1294 | mContextMenu->addAdditionalItem(QIconSet(QPixmap()), |
1291 | i18n("New Todo..."),this, | 1295 | i18n("New Todo..."),this, |
1292 | SLOT(slotNewTodo()),false); | 1296 | SLOT(slotNewTodo()),false); |
1293 | mContextMenu->addAdditionalItem(QIconSet(QPixmap()), | 1297 | mContextMenu->addAdditionalItem(QIconSet(QPixmap()), |
1294 | i18n("Journal"),this, | 1298 | i18n("Journal"),this, |
1295 | SLOT(slotEditJournal()),false); | 1299 | SLOT(slotEditJournal()),false); |
1296 | 1300 | ||
1297 | connect (mContextMenu ,SIGNAL(categoryChanged( Incidence * )),this, | 1301 | connect (mContextMenu ,SIGNAL(categoryChanged( Incidence * )),this, |
1298 | SLOT( catChanged( Incidence * ) )); | 1302 | SLOT( catChanged( Incidence * ) )); |
1299 | 1303 | ||
1300 | 1304 | ||
1301 | QString pathString = ""; | 1305 | QString pathString = ""; |
1302 | if ( !KOPrefs::instance()->mToolBarMiniIcons ) { | 1306 | if ( !KOPrefs::instance()->mToolBarMiniIcons ) { |
1303 | if ( QApplication::desktop()->width() < 480 ) | 1307 | if ( QApplication::desktop()->width() < 480 ) |
1304 | pathString += "icons16/"; | 1308 | pathString += "icons16/"; |
1305 | } else | 1309 | } else |
1306 | pathString += "iconsmini/"; | 1310 | pathString += "iconsmini/"; |
1307 | mNewItemMenu = new QPopupMenu( this ); | 1311 | mNewItemMenu = new QPopupMenu( this ); |
1308 | mNewItemMenu->insertItem( SmallIcon( pathString +"newevent" ), i18n("New Event..."),this, SLOT(slotNewEvent())); | 1312 | mNewItemMenu->insertItem( SmallIcon( pathString +"newevent" ), i18n("New Event..."),this, SLOT(slotNewEvent())); |
1309 | mNewItemMenu->insertItem( SmallIcon( pathString +"newtodo" ),i18n("New Todo..."),this,SLOT(slotNewTodo()),false); | 1313 | mNewItemMenu->insertItem( SmallIcon( pathString +"newtodo" ),i18n("New Todo..."),this,SLOT(slotNewTodo()),false); |
1310 | mNewItemMenu->insertItem( SmallIcon( pathString +"journal" ),i18n("Journal"),this,SLOT(slotEditJournal()),false); | 1314 | mNewItemMenu->insertItem( SmallIcon( pathString +"journal" ),i18n("Journal"),this,SLOT(slotEditJournal()),false); |
1311 | 1315 | ||
1312 | // updateConfig(); //useless here... | 1316 | // updateConfig(); //useless here... |
1313 | // ... but we need mWidthLongDayLabel computed | 1317 | // ... but we need mWidthLongDayLabel computed |
1314 | QFontMetrics fontmetric(mDayLabels[0]->font()); | 1318 | QFontMetrics fontmetric(mDayLabels[0]->font()); |
1315 | mWidthLongDayLabel = 0; | 1319 | mWidthLongDayLabel = 0; |
1316 | for (int i = 0; i < 7; i++) { | 1320 | for (int i = 0; i < 7; i++) { |
1317 | int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); | 1321 | int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); |
1318 | if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; | 1322 | if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; |
1319 | } | 1323 | } |
1320 | 1324 | ||
1321 | //mWeekLabels[mNumWeeks]->setText( i18n("W")); | 1325 | //mWeekLabels[mNumWeeks]->setText( i18n("W")); |
1322 | 1326 | ||
1323 | #if 0 | 1327 | #if 0 |
1324 | if ( mShowWeekView ) | 1328 | if ( mShowWeekView ) |
1325 | mWidStack->raiseWidget( mWeekView ); | 1329 | mWidStack->raiseWidget( mWeekView ); |
1326 | else | 1330 | else |
1327 | mWidStack->raiseWidget( mMonthView ); | 1331 | mWidStack->raiseWidget( mMonthView ); |
1328 | #endif | 1332 | #endif |
1329 | 1333 | ||
1330 | emit incidenceSelected( 0 ); | 1334 | emit incidenceSelected( 0 ); |
1331 | 1335 | ||
1332 | mComputeLayoutTimer = new QTimer( this ); | 1336 | mComputeLayoutTimer = new QTimer( this ); |
1333 | connect (mComputeLayoutTimer ,SIGNAL(timeout()), this, SLOT ( slotComputeLayout())); | 1337 | connect (mComputeLayoutTimer ,SIGNAL(timeout()), this, SLOT ( slotComputeLayout())); |
1334 | 1338 | ||
1335 | 1339 | ||
1336 | #ifndef DESKTOP_VERSION | 1340 | #ifndef DESKTOP_VERSION |
1337 | resize( QApplication::desktop()->size() ); | 1341 | resize( QApplication::desktop()->size() ); |
1338 | #else | 1342 | #else |
1339 | resize(640, 480 ); | 1343 | resize(640, 480 ); |
1340 | updatePossible = true; | 1344 | updatePossible = true; |
1341 | #endif | 1345 | #endif |
1342 | computeLayout(); | 1346 | computeLayout(); |
1343 | 1347 | ||
1344 | if ( mShowWeekView ) | 1348 | if ( mShowWeekView ) |
1345 | mWidStack->raiseWidget( mWeekView ); | 1349 | mWidStack->raiseWidget( mWeekView ); |
1346 | else | 1350 | else |
1347 | mWidStack->raiseWidget( mMonthView ); | 1351 | mWidStack->raiseWidget( mMonthView ); |
1348 | } | 1352 | } |
1349 | 1353 | ||
1350 | KOMonthView::~KOMonthView() | 1354 | KOMonthView::~KOMonthView() |
1351 | { | 1355 | { |
1352 | delete mContextMenu; | 1356 | delete mContextMenu; |
1353 | } | 1357 | } |
1354 | 1358 | ||
1355 | void KOMonthView::catChanged( Incidence * ) | 1359 | void KOMonthView::catChanged( Incidence * ) |
1356 | { | 1360 | { |
1357 | updateView(); | 1361 | updateView(); |
1358 | } | 1362 | } |
1359 | void KOMonthView::incidenceHighlighted( Incidence * inc , MonthViewCell* mc, int mday ) | 1363 | void KOMonthView::incidenceHighlighted( Incidence * inc , MonthViewCell* mc, int mday ) |
1360 | { | 1364 | { |
1361 | static Incidence * lastInc = 0; | 1365 | static Incidence * lastInc = 0; |
1362 | static MonthViewCell * lastCell = 0; | 1366 | static MonthViewCell * lastCell = 0; |
1363 | 1367 | ||
1364 | if ( lastInc == inc && lastCell == mc ) | 1368 | if ( lastInc == inc && lastCell == mc ) |
1365 | return; | 1369 | return; |
1366 | lastInc = inc; | 1370 | lastInc = inc; |
1367 | lastCell = mc; | 1371 | lastCell = mc; |
1368 | //qDebug("KOMonthView::incidenceHighlighted %d %d %d", inc, mc, mday ); | 1372 | //qDebug("KOMonthView::incidenceHighlighted %d %d %d", inc, mc, mday ); |
1369 | 1373 | ||
1370 | bool weekview = false; | 1374 | bool weekview = false; |
1371 | uint index = 0; | 1375 | uint index = 0; |
1372 | for (uint i = 0; i < mCellsW.count(); ++i) { | 1376 | for (uint i = 0; i < mCellsW.count(); ++i) { |
1373 | if ( mCellsW[i] == mc ) { | 1377 | if ( mCellsW[i] == mc ) { |
1374 | weekview = true; | 1378 | weekview = true; |
1375 | index = i; | 1379 | index = i; |
1376 | break; | 1380 | break; |
1377 | } | 1381 | } |
1378 | } | 1382 | } |
1379 | QPtrVector<MonthViewCell> *cells; | 1383 | QPtrVector<MonthViewCell> *cells; |
1380 | if ( weekview ) | 1384 | if ( weekview ) |
1381 | cells = &mCellsW; | 1385 | cells = &mCellsW; |
1382 | else { | 1386 | else { |
1383 | for (uint i = 0; i < mCells.count(); ++i) { | 1387 | for (uint i = 0; i < mCells.count(); ++i) { |
1384 | if ( mCells[i] == mc ) { | 1388 | if ( mCells[i] == mc ) { |
1385 | index = i; | 1389 | index = i; |
1386 | break; | 1390 | break; |
1387 | } | 1391 | } |
1388 | } | 1392 | } |
1389 | cells = &mCells; | 1393 | cells = &mCells; |
1390 | } | 1394 | } |
1391 | for (uint i = 0; i < (*cells).count(); ++i) { | 1395 | for (uint i = 0; i < (*cells).count(); ++i) { |
1392 | (*cells)[i]->deHighLight(); | 1396 | (*cells)[i]->deHighLight(); |
1393 | } | 1397 | } |
1394 | if ( ! inc ) | 1398 | if ( ! inc ) |
1395 | return; | 1399 | return; |
1396 | 1400 | ||
1397 | uint count = (*cells).count(); | 1401 | uint count = (*cells).count(); |
1398 | bool goLeft = (mday > 1 && index > 0); | 1402 | bool goLeft = (mday > 1 && index > 0); |
1399 | bool goRight = (mday < 3 && mday > 0 && index < count -1); | 1403 | bool goRight = (mday < 3 && mday > 0 && index < count -1); |
1400 | for (uint iii = 1; iii < count; ++iii) { | 1404 | for (uint iii = 1; iii < count; ++iii) { |
1401 | if ( goLeft ) { | 1405 | if ( goLeft ) { |
1402 | int left = index - iii; | 1406 | int left = index - iii; |
1403 | if ( left >= 0 ) { | 1407 | if ( left >= 0 ) { |
1404 | if ( (*cells)[(uint)left]->doHighLight(inc) ) | 1408 | if ( (*cells)[(uint)left]->doHighLight(inc) ) |
1405 | goLeft = false; | 1409 | goLeft = false; |
1406 | } else | 1410 | } else |
1407 | goLeft = false; | 1411 | goLeft = false; |
1408 | } | 1412 | } |
1409 | if ( goRight ) { | 1413 | if ( goRight ) { |
1410 | uint right = index + iii; | 1414 | uint right = index + iii; |
1411 | if ( right < count ) { | 1415 | if ( right < count ) { |
1412 | if ( (*cells)[right]->doHighLight(inc) ) | 1416 | if ( (*cells)[right]->doHighLight(inc) ) |
1413 | goRight = false; | 1417 | goRight = false; |
1414 | 1418 | ||
1415 | } else | 1419 | } else |
1416 | goRight = false; | 1420 | goRight = false; |
1417 | } | 1421 | } |
1418 | 1422 | ||
1419 | } | 1423 | } |
1420 | #if 0 | 1424 | #if 0 |
1421 | if ( mday > 1 && index > 0 ) | 1425 | if ( mday > 1 && index > 0 ) |
1422 | for (int i = index-1; i >= 0; --i) { | 1426 | for (int i = index-1; i >= 0; --i) { |
1423 | //qDebug("index %d iii %d ", index, i); | 1427 | //qDebug("index %d iii %d ", index, i); |
1424 | if ( (*cells)[(uint)i]->doHighLight(inc) ) | 1428 | if ( (*cells)[(uint)i]->doHighLight(inc) ) |
1425 | break; | 1429 | break; |
1426 | } | 1430 | } |
1427 | if ( mday < 3 && mday > 0 && index < (*cells).count()-1) | 1431 | if ( mday < 3 && mday > 0 && index < (*cells).count()-1) |
1428 | for (uint i = index+1; i < (*cells).count(); ++i) { | 1432 | for (uint i = index+1; i < (*cells).count(); ++i) { |
1429 | if ( (*cells)[i]->doHighLight(inc) ) | 1433 | if ( (*cells)[i]->doHighLight(inc) ) |
1430 | break; | 1434 | break; |
1431 | } | 1435 | } |
1432 | #endif | 1436 | #endif |
1433 | 1437 | ||
1434 | } | 1438 | } |
1435 | void KOMonthView::selectInternalWeekNum ( int n ) | 1439 | void KOMonthView::selectInternalWeekNum ( int n ) |
1436 | { | 1440 | { |
1437 | switchView(); | 1441 | switchView(); |
1438 | if ( !KOPrefs::instance()->mMonthViewWeek ) | 1442 | if ( !KOPrefs::instance()->mMonthViewWeek ) |
1439 | emit selectMonth (); | 1443 | emit selectMonth (); |
1440 | else | 1444 | else |
1441 | emit selectWeekNum ( n ); | 1445 | emit selectWeekNum ( n ); |
1442 | } | 1446 | } |
1443 | 1447 | ||
1444 | int KOMonthView::currentWeek() | 1448 | int KOMonthView::currentWeek() |
1445 | { | 1449 | { |
1446 | if ( mShowWeekView ) | 1450 | if ( mShowWeekView ) |
1447 | return mWeekLabelsW[0]->getWeekNum(); | 1451 | return mWeekLabelsW[0]->getWeekNum(); |
1448 | return mWeekLabels[0]->getWeekNum(); | 1452 | return mWeekLabels[0]->getWeekNum(); |
1449 | } | 1453 | } |
1450 | void KOMonthView::switchView() | 1454 | void KOMonthView::switchView() |
1451 | { | 1455 | { |
1452 | if ( selectedCell( ) ) | 1456 | if ( selectedCell( ) ) |
1453 | selectedCell()->deselect(); | 1457 | selectedCell()->deselect(); |
1454 | mShowWeekView = !mShowWeekView; | 1458 | mShowWeekView = !mShowWeekView; |
1455 | KOPrefs::instance()->mMonthViewWeek = mShowWeekView; | 1459 | KOPrefs::instance()->mMonthViewWeek = mShowWeekView; |
1456 | if ( clPending ) { | 1460 | if ( clPending ) { |
1457 | computeLayout(); | 1461 | computeLayout(); |
1458 | updateConfig(); | 1462 | updateConfig(); |
1459 | } | 1463 | } |
1460 | if ( mShowWeekView ) | 1464 | if ( mShowWeekView ) |
1461 | mWidStack->raiseWidget( mWeekView ); | 1465 | mWidStack->raiseWidget( mWeekView ); |
1462 | else | 1466 | else |
1463 | mWidStack->raiseWidget( mMonthView ); | 1467 | mWidStack->raiseWidget( mMonthView ); |
1464 | clPending = false; | 1468 | clPending = false; |
1465 | } | 1469 | } |
1466 | 1470 | ||
1467 | int KOMonthView::maxDatesHint() | 1471 | int KOMonthView::maxDatesHint() |
1468 | { | 1472 | { |
1469 | return mNumCells; | 1473 | return mNumCells; |
1470 | } | 1474 | } |
1471 | 1475 | ||
1472 | int KOMonthView::currentDateCount() | 1476 | int KOMonthView::currentDateCount() |
1473 | { | 1477 | { |
1474 | return mNumCells; | 1478 | return mNumCells; |
1475 | } | 1479 | } |
1476 | 1480 | ||
1477 | QPtrList<Incidence> KOMonthView::selectedIncidences() | 1481 | QPtrList<Incidence> KOMonthView::selectedIncidences() |
1478 | { | 1482 | { |
1479 | QPtrList<Incidence> selected; | 1483 | QPtrList<Incidence> selected; |
1480 | 1484 | ||
1481 | if ( mSelectedCell ) { | 1485 | if ( mSelectedCell ) { |
1482 | Incidence *incidence = mSelectedCell->selectedIncidence(); | 1486 | Incidence *incidence = mSelectedCell->selectedIncidence(); |
1483 | if ( incidence ) selected.append( incidence ); | 1487 | if ( incidence ) selected.append( incidence ); |
1484 | } | 1488 | } |
1485 | 1489 | ||
1486 | return selected; | 1490 | return selected; |
1487 | } | 1491 | } |
1488 | 1492 | ||
1489 | DateList KOMonthView::selectedDates() | 1493 | DateList KOMonthView::selectedDates() |
1490 | { | 1494 | { |
1491 | DateList selected; | 1495 | DateList selected; |
1492 | 1496 | ||
1493 | if ( mSelectedCell ) { | 1497 | if ( mSelectedCell ) { |
1494 | QDate qd = mSelectedCell->selectedIncidenceDate(); | 1498 | QDate qd = mSelectedCell->selectedIncidenceDate(); |
1495 | if ( qd.isValid() ) selected.append( qd ); | 1499 | if ( qd.isValid() ) selected.append( qd ); |
1496 | } | 1500 | } |
1497 | 1501 | ||
1498 | return selected; | 1502 | return selected; |
1499 | } | 1503 | } |
1500 | #if 0 | 1504 | #if 0 |
1501 | void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd, | 1505 | void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd, |
1502 | const QDate &td) | 1506 | const QDate &td) |
1503 | { | 1507 | { |
1504 | #ifndef KORG_NOPRINTER | 1508 | #ifndef KORG_NOPRINTER |
1505 | calPrinter->preview(CalPrinter::Month, fd, td); | 1509 | calPrinter->preview(CalPrinter::Month, fd, td); |
1506 | #endif | 1510 | #endif |
1507 | } | 1511 | } |
1508 | #endif | 1512 | #endif |
1509 | void KOMonthView::updateConfig() | 1513 | void KOMonthView::updateConfig() |
1510 | { | 1514 | { |
1511 | 1515 | ||
1512 | int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); | 1516 | int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); |
1513 | 1517 | ||
1514 | if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) { | 1518 | if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) { |
1515 | mWeekStartsMonday = true; | 1519 | mWeekStartsMonday = true; |
1516 | } | 1520 | } |
1517 | QFontMetrics fontmetric(mDayLabels[0]->font()); | 1521 | QFontMetrics fontmetric(mDayLabels[0]->font()); |
1518 | mWidthLongDayLabel = 0; | 1522 | mWidthLongDayLabel = 0; |
1519 | 1523 | ||
1520 | for (int i = 0; i < 7; i++) { | 1524 | for (int i = 0; i < 7; i++) { |
1521 | int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); | 1525 | int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); |
1522 | if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; | 1526 | if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; |
1523 | } | 1527 | } |
1524 | bool temp = mShowSatSunComp ; | 1528 | bool temp = mShowSatSunComp ; |
1525 | mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; | 1529 | mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; |
1526 | if ( ! mShowWeekView ) { | 1530 | if ( ! mShowWeekView ) { |
1527 | if ( temp != KOPrefs::instance()->mMonthViewSatSunTog ) | 1531 | if ( temp != KOPrefs::instance()->mMonthViewSatSunTog ) |
1528 | computeLayout(); | 1532 | computeLayout(); |
1529 | } else | 1533 | } else |
1530 | doComputeLayoutWeek(); | 1534 | doComputeLayoutWeek(); |
1531 | updateDayLabels(); | 1535 | updateDayLabels(); |
1532 | //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks); | 1536 | //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks); |
1533 | //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks; | 1537 | //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks; |
1534 | //resizeEvent( 0 ); | 1538 | //resizeEvent( 0 ); |
1535 | for (uint i = 0; i < mCells.count(); ++i) { | 1539 | for (uint i = 0; i < mCells.count(); ++i) { |
1536 | mCells[i]->updateConfig(); | 1540 | mCells[i]->updateConfig(); |
1537 | } | 1541 | } |
1538 | 1542 | ||
1539 | for (uint i = 0; i < mCellsW.count(); ++i) { | 1543 | for (uint i = 0; i < mCellsW.count(); ++i) { |
1540 | mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont); | 1544 | mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont); |
1541 | } | 1545 | } |
1542 | #ifdef DESKTOP_VERSION | 1546 | #ifdef DESKTOP_VERSION |
1543 | MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips); | 1547 | MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips); |
1544 | #endif | 1548 | #endif |
1545 | updateView(); | 1549 | updateView(); |
1546 | } | 1550 | } |
1547 | 1551 | ||
1548 | void KOMonthView::updateDayLabels() | 1552 | void KOMonthView::updateDayLabels() |
1549 | { | 1553 | { |
1550 | 1554 | ||
1551 | QPtrVector<QLabel> *mDayLabelsT; | 1555 | QPtrVector<QLabel> *mDayLabelsT; |
1552 | 1556 | ||
1553 | mDayLabelsT = &mDayLabelsW; | 1557 | mDayLabelsT = &mDayLabelsW; |
1554 | for (int i = 0; i < 7; i++) { | 1558 | for (int i = 0; i < 7; i++) { |
1555 | { | 1559 | { |
1556 | bool show = mShortDayLabelsW; | 1560 | bool show = mShortDayLabelsW; |
1557 | if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) | 1561 | if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) |
1558 | show = true; | 1562 | show = true; |
1559 | (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); | 1563 | (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); |
1560 | } | 1564 | } |
1561 | } | 1565 | } |
1562 | mDayLabelsT = &mDayLabels; | 1566 | mDayLabelsT = &mDayLabels; |
1563 | for (int i = 0; i < 7; i++) { | 1567 | for (int i = 0; i < 7; i++) { |
1564 | if (KGlobal::locale()->weekStartsMonday() || KOPrefs::instance()->mMonthViewSatSunTog ) { | 1568 | if (KGlobal::locale()->weekStartsMonday() || KOPrefs::instance()->mMonthViewSatSunTog ) { |
1565 | bool show = mShortDayLabelsM; | 1569 | bool show = mShortDayLabelsM; |
1566 | if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) | 1570 | if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) |
1567 | show = true; | 1571 | show = true; |
1568 | (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); | 1572 | (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); |
1569 | } else { | 1573 | } else { |
1570 | if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM)); | 1574 | if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM)); |
1571 | else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM)); | 1575 | else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM)); |
1572 | 1576 | ||
1573 | } | 1577 | } |
1574 | } | 1578 | } |
1575 | 1579 | ||
1576 | } | 1580 | } |
1577 | 1581 | ||
1578 | void KOMonthView::clearList() | 1582 | void KOMonthView::clearList() |
1579 | { | 1583 | { |
1580 | unsigned int i; | 1584 | unsigned int i; |
1581 | for( i = 0; i < mCells.size(); ++i ) { | 1585 | for( i = 0; i < mCells.size(); ++i ) { |
1582 | mCells[i]->clear(); | 1586 | mCells[i]->clear(); |
1583 | } | 1587 | } |
1584 | for( i = 0; i < mCellsW.size(); ++i ) { | 1588 | for( i = 0; i < mCellsW.size(); ++i ) { |
1585 | mCellsW[i]->clear(); | 1589 | mCellsW[i]->clear(); |
1586 | } | 1590 | } |
1587 | } | 1591 | } |
1588 | void KOMonthView::showDates(const QDate &start, const QDate &) | 1592 | void KOMonthView::showDates(const QDate &start, const QDate &) |
1589 | { | 1593 | { |
1590 | // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl; | 1594 | // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl; |
1591 | 1595 | ||
1592 | QPtrVector<MonthViewCell> *cells; | 1596 | QPtrVector<MonthViewCell> *cells; |
1593 | QPtrVector<QLabel> *dayLabels; | 1597 | QPtrVector<QLabel> *dayLabels; |
1594 | QPtrVector<KOWeekButton> *weekLabels; | 1598 | QPtrVector<KOWeekButton> *weekLabels; |
1595 | uint weekNum = 6; | 1599 | uint weekNum = 6; |
1596 | mStartDate = start; | 1600 | mStartDate = start; |
1597 | if ( mShowWeekView ) { | 1601 | if ( mShowWeekView ) { |
1598 | weekNum = 1; | 1602 | weekNum = 1; |
1599 | cells = &mCellsW; | 1603 | cells = &mCellsW; |
1600 | dayLabels = &mDayLabelsW; | 1604 | dayLabels = &mDayLabelsW; |
1601 | weekLabels = &mWeekLabelsW; | 1605 | weekLabels = &mWeekLabelsW; |
1602 | if ( !KGlobal::locale()->weekStartsMonday() ) { | 1606 | if ( !KGlobal::locale()->weekStartsMonday() ) { |
1603 | mStartDate = mStartDate.addDays( 1 ); | 1607 | mStartDate = mStartDate.addDays( 1 ); |
1604 | } | 1608 | } |
1605 | } else { | 1609 | } else { |
1606 | cells = &mCells; | 1610 | cells = &mCells; |
1607 | dayLabels = &mDayLabels; | 1611 | dayLabels = &mDayLabels; |
1608 | weekLabels = &mWeekLabels; | 1612 | weekLabels = &mWeekLabels; |
1609 | } | 1613 | } |
1610 | 1614 | ||
1611 | int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); | 1615 | int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); |
1612 | 1616 | ||
1613 | if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) { | 1617 | if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) { |
1614 | mWeekStartsMonday = true; | 1618 | mWeekStartsMonday = true; |
1615 | } | 1619 | } |
1616 | int startWeekDay = mWeekStartsMonday ? 1 : 7; | 1620 | int startWeekDay = mWeekStartsMonday ? 1 : 7; |
1617 | 1621 | ||
1618 | while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) { | 1622 | while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) { |
1619 | mStartDate = mStartDate.addDays( -1 ); | 1623 | mStartDate = mStartDate.addDays( -1 ); |
1620 | } | 1624 | } |
1621 | uint i; | 1625 | uint i; |
1622 | for( i = 0; i < (*cells).size(); ++i ) { | 1626 | for( i = 0; i < (*cells).size(); ++i ) { |
1623 | QDate date = mStartDate.addDays( i ); | 1627 | QDate date = mStartDate.addDays( i ); |
1624 | (*cells)[i]->setDate( date ); | 1628 | (*cells)[i]->setDate( date ); |
1625 | 1629 | ||
1626 | #ifndef KORG_NOPLUGINS | 1630 | #ifndef KORG_NOPLUGINS |
1627 | // add holiday, if present | 1631 | // add holiday, if present |
1628 | QString hstring(KOCore::self()->holiday(date)); | 1632 | QString hstring(KOCore::self()->holiday(date)); |
1629 | (*cells)[i]->setHoliday( hstring ); | 1633 | (*cells)[i]->setHoliday( hstring ); |
1630 | #endif | 1634 | #endif |
1631 | 1635 | ||
1632 | } | 1636 | } |
1633 | QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 ); | 1637 | QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 ); |
1634 | for( i = 0; i < weekNum; ++i ) { | 1638 | for( i = 0; i < weekNum; ++i ) { |
1635 | int wno; | 1639 | int wno; |
1636 | // remember, according to ISO 8601, the first week of the year is the | 1640 | // remember, according to ISO 8601, the first week of the year is the |
1637 | // first week that contains a thursday. Thus we must subtract off 4, | 1641 | // first week that contains a thursday. Thus we must subtract off 4, |
1638 | // not just 1. | 1642 | // not just 1. |
1639 | int dayOfYear = date.dayOfYear(); | 1643 | int dayOfYear = date.dayOfYear(); |
1640 | if (dayOfYear % 7 != 0) | 1644 | if (dayOfYear % 7 != 0) |
1641 | wno = dayOfYear / 7 + 1; | 1645 | wno = dayOfYear / 7 + 1; |
1642 | else | 1646 | else |
1643 | wno =dayOfYear / 7; | 1647 | wno =dayOfYear / 7; |
1644 | (*weekLabels)[i]->setWeekNum( wno ); | 1648 | (*weekLabels)[i]->setWeekNum( wno ); |
1645 | date = date.addDays( 7 ); | 1649 | date = date.addDays( 7 ); |
1646 | } | 1650 | } |
1647 | updateView(); | 1651 | updateView(); |
1648 | } | 1652 | } |
1649 | 1653 | ||
1650 | void KOMonthView::showEvents(QPtrList<Event>) | 1654 | void KOMonthView::showEvents(QPtrList<Event>) |
1651 | { | 1655 | { |
1652 | qDebug("KOMonthView::selectEvents is not implemented yet. "); | 1656 | qDebug("KOMonthView::selectEvents is not implemented yet. "); |
1653 | } | 1657 | } |
1654 | 1658 | ||
1655 | void KOMonthView::changeEventDisplay(Event *, int) | 1659 | void KOMonthView::changeEventDisplay(Event *, int) |
1656 | { | 1660 | { |
1657 | // this should be re-written to be much more efficient, but this | 1661 | // this should be re-written to be much more efficient, but this |
1658 | // quick-and-dirty-hack gets the job done for right now. | 1662 | // quick-and-dirty-hack gets the job done for right now. |
1659 | //qDebug("KOMonthView::changeEventDisplay "); | 1663 | //qDebug("KOMonthView::changeEventDisplay "); |
1660 | updateView(); | 1664 | updateView(); |
1661 | } | 1665 | } |
1662 | 1666 | ||
1663 | void KOMonthView::updateView() | 1667 | void KOMonthView::updateView() |
1664 | { | 1668 | { |
1665 | 1669 | ||
1666 | if ( !updatePossible ) | 1670 | if ( !updatePossible ) |
1667 | return; | 1671 | return; |
1668 | //qDebug("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU "); | 1672 | //qDebug("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU "); |
1669 | //QTime ti; | 1673 | //QTime ti; |
1670 | //ti.start(); | 1674 | //ti.start(); |
1671 | clearSelection(); | 1675 | clearSelection(); |
1672 | QPtrVector<MonthViewCell> *cells; | 1676 | QPtrVector<MonthViewCell> *cells; |
1673 | if ( mShowWeekView ) { | 1677 | if ( mShowWeekView ) { |
1674 | cells = &mCellsW; | 1678 | cells = &mCellsW; |
1675 | } else { | 1679 | } else { |
1676 | cells = &mCells; | 1680 | cells = &mCells; |
1677 | } | 1681 | } |
1678 | #if 1 | 1682 | #if 1 |
1679 | int i; | 1683 | int i; |
1680 | int timeSpan = (*cells).size()-1; | 1684 | int timeSpan = (*cells).size()-1; |
1681 | if ( KOPrefs::instance()->mMonthViewWeek ) | 1685 | if ( KOPrefs::instance()->mMonthViewWeek ) |
1682 | timeSpan = 6; | 1686 | timeSpan = 6; |
1683 | for( i = 0; i < timeSpan + 1; ++i ) { | 1687 | for( i = 0; i < timeSpan + 1; ++i ) { |
1684 | (*cells)[i]->startUpdateCell(); | 1688 | (*cells)[i]->startUpdateCell(); |
1685 | } | 1689 | } |
1686 | 1690 | ||
1687 | QPtrList<Event> events = calendar()->events(); | 1691 | QPtrList<Event> events = calendar()->events(); |
1688 | Event *event; | 1692 | Event *event; |
1689 | QDateTime dt; | 1693 | QDateTime dt; |
1690 | QDate endDate = mStartDate.addDays( timeSpan ); | 1694 | QDate endDate = mStartDate.addDays( timeSpan ); |
1691 | for( event = events.first(); event; event = events.next() ) { // for event | 1695 | for( event = events.first(); event; event = events.next() ) { // for event |
1692 | if ( event->doesRecur() ) { | 1696 | if ( event->doesRecur() ) { |
1693 | bool last; | 1697 | bool last; |
1694 | QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); | 1698 | QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); |
1695 | QDateTime incidenceEnd; | 1699 | QDateTime incidenceEnd; |
1696 | int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); | 1700 | int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); |
1697 | bool invalid = false; | 1701 | bool invalid = false; |
1698 | while( true ) { | 1702 | while( true ) { |
1699 | if ( incidenceStart.isValid() ) { | 1703 | if ( incidenceStart.isValid() ) { |
1700 | incidenceEnd = incidenceStart.addDays( eventlen ); | 1704 | incidenceEnd = incidenceStart.addDays( eventlen ); |
1701 | int st = incidenceStart.date().daysTo( endDate ); | 1705 | int st = incidenceStart.date().daysTo( endDate ); |
1702 | if ( st >= 0 ) { // start before timeend | 1706 | if ( st >= 0 ) { // start before timeend |
1703 | int end = mStartDate.daysTo( incidenceEnd.date() ); | 1707 | int end = mStartDate.daysTo( incidenceEnd.date() ); |
1704 | if ( end >= 0 ) { // end after timestart --- got one! | 1708 | if ( end >= 0 ) { // end after timestart --- got one! |
1705 | //normalize | 1709 | //normalize |
1706 | st = timeSpan - st; | 1710 | st = timeSpan - st; |
1707 | if ( st < 0 ) st = 0; | 1711 | if ( st < 0 ) st = 0; |
1708 | if ( end > timeSpan ) end = timeSpan; | 1712 | if ( end > timeSpan ) end = timeSpan; |
1709 | int iii; | 1713 | int iii; |
1710 | //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); | 1714 | //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); |
1711 | for ( iii = st;iii<= end;++iii) | 1715 | for ( iii = st;iii<= end;++iii) |
1712 | (*cells)[iii]->insertEvent( event ); | 1716 | (*cells)[iii]->insertEvent( event ); |
1713 | } | 1717 | } |
1714 | } | 1718 | } |
1715 | } else { | 1719 | } else { |
1716 | if ( invalid ) | 1720 | if ( invalid ) |
1717 | break; | 1721 | break; |
1718 | invalid = true; | 1722 | invalid = true; |
1719 | //qDebug("invalid %s", event->summary().latin1()); | 1723 | //qDebug("invalid %s", event->summary().latin1()); |
1720 | incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; | 1724 | incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; |
1721 | } | 1725 | } |
1722 | if ( last ) | 1726 | if ( last ) |
1723 | break; | 1727 | break; |
1724 | bool ok; | 1728 | bool ok; |
1725 | incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); | 1729 | incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); |
1726 | if ( ! ok ) | 1730 | if ( ! ok ) |
1727 | break; | 1731 | break; |
1728 | if ( incidenceStart.date() > endDate ) | 1732 | if ( incidenceStart.date() > endDate ) |
1729 | break; | 1733 | break; |
1730 | } | 1734 | } |
1731 | } else { // no recur | 1735 | } else { // no recur |
1732 | if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") ) | 1736 | if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") ) |
1733 | if ( event->uid().left(15) == QString("last-syncEvent-") ) | 1737 | if ( event->uid().left(15) == QString("last-syncEvent-") ) |
1734 | continue; | 1738 | continue; |
1735 | int st = event->dtStart().date().daysTo( endDate ); | 1739 | int st = event->dtStart().date().daysTo( endDate ); |
1736 | if ( st >= 0 ) { // start before timeend | 1740 | if ( st >= 0 ) { // start before timeend |
1737 | int end = mStartDate.daysTo( event->dtEnd().date() ); | 1741 | int end = mStartDate.daysTo( event->dtEnd().date() ); |
1738 | if ( end >= 0 ) { // end after timestart --- got one! | 1742 | if ( end >= 0 ) { // end after timestart --- got one! |
1739 | //normalize | 1743 | //normalize |
1740 | st = timeSpan - st; | 1744 | st = timeSpan - st; |
1741 | if ( st < 0 ) st = 0; | 1745 | if ( st < 0 ) st = 0; |
1742 | if ( end > timeSpan ) end = timeSpan; | 1746 | if ( end > timeSpan ) end = timeSpan; |
1743 | int iii; | 1747 | int iii; |
1744 | for ( iii = st;iii<= end;++iii) | 1748 | for ( iii = st;iii<= end;++iii) |
1745 | (*cells)[iii]->insertEvent( event ); | 1749 | (*cells)[iii]->insertEvent( event ); |
1746 | } | 1750 | } |
1747 | } | 1751 | } |
1748 | } | 1752 | } |
1749 | } | 1753 | } |
1750 | // insert due todos | 1754 | // insert due todos |
1751 | QPtrList<Todo> todos = calendar()->todos( ); | 1755 | QPtrList<Todo> todos = calendar()->todos( ); |
1752 | Todo *todo; | 1756 | Todo *todo; |
1753 | for(todo = todos.first(); todo; todo = todos.next()) { | 1757 | for(todo = todos.first(); todo; todo = todos.next()) { |
1754 | //insertTodo( todo ); | 1758 | //insertTodo( todo ); |
1755 | if ( todo->hasDueDate() ) { | 1759 | if ( todo->hasDueDate() ) { |
1756 | int day = mStartDate.daysTo( todo->dtDue().date() ); | 1760 | int day = mStartDate.daysTo( todo->dtDue().date() ); |
1757 | if ( day >= 0 && day < timeSpan + 1) { | 1761 | if ( day >= 0 && day < timeSpan + 1) { |
1758 | (*cells)[day]->insertTodo( todo ); | 1762 | (*cells)[day]->insertTodo( todo ); |
1759 | } | 1763 | } |
1760 | } | 1764 | } |
1761 | } | 1765 | } |
1762 | 1766 | ||
1763 | for( i = 0; i < timeSpan+1; ++i ) { | 1767 | for( i = 0; i < timeSpan+1; ++i ) { |
1764 | (*cells)[i]->finishUpdateCell(); | 1768 | (*cells)[i]->finishUpdateCell(); |
1765 | } | 1769 | } |
1766 | processSelectionChange(); | 1770 | processSelectionChange(); |
1767 | //qApp->processEvents(); | 1771 | //qApp->processEvents(); |
1768 | for( i = 0; i < timeSpan+1; ++i ) { | 1772 | for( i = 0; i < timeSpan+1; ++i ) { |
1769 | //(*cells)[i]->repaintfinishUpdateCell(); | 1773 | //(*cells)[i]->repaintfinishUpdateCell(); |
1770 | QTimer::singleShot( 0, (*cells)[i], SLOT ( repaintfinishUpdateCell() ) ); | 1774 | QTimer::singleShot( 0, (*cells)[i], SLOT ( repaintfinishUpdateCell() ) ); |
1771 | } | 1775 | } |
1772 | setKeyBFocus(); | 1776 | setKeyBFocus(); |
1773 | #else | 1777 | #else |
1774 | // old code | 1778 | // old code |
1775 | //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "); | 1779 | //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "); |
1776 | int i; | 1780 | int i; |
1777 | for( i = 0; i < (*cells).count(); ++i ) { | 1781 | for( i = 0; i < (*cells).count(); ++i ) { |
1778 | (*cells)[i]->updateCell(); | 1782 | (*cells)[i]->updateCell(); |
1779 | } | 1783 | } |
1780 | 1784 | ||
1781 | //qDebug("KOMonthView::updateView() "); | 1785 | //qDebug("KOMonthView::updateView() "); |
1782 | processSelectionChange(); | 1786 | processSelectionChange(); |
1783 | // qDebug("---------------------------------------------------------------------+ "); | 1787 | // qDebug("---------------------------------------------------------------------+ "); |
1784 | (*cells)[0]->setFocus(); | 1788 | (*cells)[0]->setFocus(); |
1785 | #endif | 1789 | #endif |
1786 | 1790 | ||
1787 | //qDebug("update time %d ", ti.elapsed()); | 1791 | //qDebug("update time %d ", ti.elapsed()); |
1788 | } | 1792 | } |
1789 | 1793 | ||
1790 | void KOMonthView::setKeyBoardFocus() | 1794 | void KOMonthView::setKeyBoardFocus() |
1791 | { | 1795 | { |
1792 | //qDebug("KOMonthView::setKeyBoardFocus() "); | 1796 | //qDebug("KOMonthView::setKeyBoardFocus() "); |
1793 | bool shootAgain = false; | 1797 | bool shootAgain = false; |
1794 | if ( mShowWeekView ) { | 1798 | if ( mShowWeekView ) { |
1795 | shootAgain = !mWeekLabelsW[1]->hasFocus(); | 1799 | shootAgain = !mWeekLabelsW[1]->hasFocus(); |
1796 | mWeekLabelsW[1]->setFocus(); | 1800 | mWeekLabelsW[1]->setFocus(); |
1797 | } | 1801 | } |
1798 | else { | 1802 | else { |
1799 | shootAgain = !mWeekLabels[mNumWeeks]->hasFocus(); | 1803 | shootAgain = !mWeekLabels[mNumWeeks]->hasFocus(); |
1800 | mWeekLabels[mNumWeeks]->setFocus(); | 1804 | mWeekLabels[mNumWeeks]->setFocus(); |
1801 | } | 1805 | } |
1802 | --mKBFcounter; | 1806 | --mKBFcounter; |
1803 | if ( shootAgain && mKBFcounter > 0 ) { | 1807 | if ( shootAgain && mKBFcounter > 0 ) { |
1804 | QTimer::singleShot( 50, this, SLOT ( setKeyBoardFocus() ) ); | 1808 | QTimer::singleShot( 50, this, SLOT ( setKeyBoardFocus() ) ); |
1805 | } | 1809 | } |
1806 | } | 1810 | } |
1807 | void KOMonthView::setKeyBFocus() | 1811 | void KOMonthView::setKeyBFocus() |
1808 | { | 1812 | { |
1809 | //qDebug("KOMonthView::setKeyBFocus() "); | 1813 | //qDebug("KOMonthView::setKeyBFocus() "); |
1810 | mKBFcounter = 10; | 1814 | mKBFcounter = 10; |
1811 | QTimer::singleShot( 0, this, SLOT ( setKeyBoardFocus() ) ); | 1815 | QTimer::singleShot( 0, this, SLOT ( setKeyBoardFocus() ) ); |
1812 | } | 1816 | } |
1813 | void KOMonthView::resizeEvent(QResizeEvent * e) | 1817 | void KOMonthView::resizeEvent(QResizeEvent * e) |
1814 | { | 1818 | { |
1815 | //qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height()); | 1819 | //qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height()); |
1816 | if ( isVisible() ) { | 1820 | if ( isVisible() ) { |
1817 | //qDebug("KOMonthView::isVisible "); | 1821 | //qDebug("KOMonthView::isVisible "); |
1818 | slotComputeLayout(); | 1822 | slotComputeLayout(); |
1819 | } else | 1823 | } else |
1820 | mComputeLayoutTimer->start( 100 ); | 1824 | mComputeLayoutTimer->start( 100 ); |
1821 | if ( e ) | 1825 | if ( e ) |
1822 | KOEventView::resizeEvent( e ); | 1826 | KOEventView::resizeEvent( e ); |
1823 | } | 1827 | } |
1824 | 1828 | ||
1825 | void KOMonthView::slotComputeLayout() | 1829 | void KOMonthView::slotComputeLayout() |
1826 | { | 1830 | { |
1827 | mComputeLayoutTimer->stop(); | 1831 | mComputeLayoutTimer->stop(); |
1828 | //qDebug("KOMonthView::Post - resizeEvent %d %d ", width(), height() ); | 1832 | //qDebug("KOMonthView::Post - resizeEvent %d %d ", width(), height() ); |
1829 | computeLayout(); | 1833 | computeLayout(); |
1830 | clPending = true; | 1834 | clPending = true; |
1831 | setKeyBFocus(); | 1835 | setKeyBFocus(); |
1832 | } | 1836 | } |
1833 | 1837 | ||
1834 | void KOMonthView::doComputeLayoutWeek() | 1838 | void KOMonthView::doComputeLayoutWeek() |
1835 | { | 1839 | { |
1836 | 1840 | ||
1837 | int daysToShow; | 1841 | int daysToShow; |
1838 | bool combinedSatSun = false; | 1842 | bool combinedSatSun = false; |
1839 | if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { | 1843 | if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { |
1840 | daysToShow = 6; | 1844 | daysToShow = 6; |
1841 | combinedSatSun = true; | 1845 | combinedSatSun = true; |
1842 | } | 1846 | } |
1843 | int wid = width();//e | 1847 | int wid = width();//e |
1844 | int hei = height()-1-mNavigatorBar->height(); | 1848 | int hei = height()-1-mNavigatorBar->height(); |
1845 | #ifdef DESKTOP_VERSION | 1849 | #ifdef DESKTOP_VERSION |
1846 | if ( !KOPrefs::instance()->mMonthViewWeekRowlayout ) { | 1850 | if ( !KOPrefs::instance()->mMonthViewWeekRowlayout ) { |
1847 | daysToShow = 2; | 1851 | daysToShow = 2; |
1848 | } else | 1852 | } else |
1849 | #endif | 1853 | #endif |
1850 | { | 1854 | { |
1851 | if ( wid < hei + 40 ) | 1855 | if ( wid < hei + 40 ) |
1852 | daysToShow = 2; | 1856 | daysToShow = 2; |
1853 | else | 1857 | else |
1854 | daysToShow = 3; | 1858 | daysToShow = 3; |
1855 | } | 1859 | } |
1856 | bool landscape = (daysToShow == 3); | 1860 | bool landscape = (daysToShow == 3); |
1857 | mShowSatSunComp = true; | 1861 | mShowSatSunComp = true; |
1858 | combinedSatSun = true; | 1862 | combinedSatSun = true; |
1859 | 1863 | ||
1860 | //qDebug("KOMonthView::computeLayout() WWW ------------------------------------ "); | 1864 | //qDebug("KOMonthView::computeLayout() WWW ------------------------------------ "); |
1861 | QFontMetrics fm ( mWeekLabels[0]->font() ); | 1865 | QFontMetrics fm ( mWeekLabels[0]->font() ); |
1862 | int weeklabelwid = fm.width( "888" ); | 1866 | int weeklabelwid = fm.width( "888" ); |
1863 | wid -= weeklabelwid; | 1867 | wid -= weeklabelwid; |
1864 | 1868 | ||
1865 | int colWid = wid / daysToShow; | 1869 | int colWid = wid / daysToShow; |
1866 | int dayLabelHei = mDayLabelsW[0]->sizeHint().height(); | 1870 | int dayLabelHei = mDayLabelsW[0]->sizeHint().height(); |
1867 | int cellHei = (hei - (5- daysToShow )*dayLabelHei) /(5- daysToShow ); | 1871 | int cellHei = (hei - (5- daysToShow )*dayLabelHei) /(5- daysToShow ); |
1868 | int colModulo = wid % daysToShow; | 1872 | int colModulo = wid % daysToShow; |
1869 | int rowModulo = (hei- (5- daysToShow )*dayLabelHei) % daysToShow-1; | 1873 | int rowModulo = (hei- (5- daysToShow )*dayLabelHei) % daysToShow-1; |
1870 | //qDebug("rowmod %d ", rowModulo); | 1874 | //qDebug("rowmod %d ", rowModulo); |
1871 | int i; | 1875 | int i; |
1872 | int x,y,w,h; | 1876 | int x,y,w,h; |
1873 | x= 0; | 1877 | x= 0; |
1874 | y= 0; | 1878 | y= 0; |
1875 | w = colWid; | 1879 | w = colWid; |
1876 | h = dayLabelHei ; | 1880 | h = dayLabelHei ; |
1877 | for ( i = 0; i < 7; i++) { | 1881 | for ( i = 0; i < 7; i++) { |
1878 | if ( i && !( i % daysToShow) && i < 6) { | 1882 | if ( i && !( i % daysToShow) && i < 6) { |
1879 | y += hei/(5-daysToShow); | 1883 | y += hei/(5-daysToShow); |
1880 | x = 0; | 1884 | x = 0; |
1881 | w = colWid; | 1885 | w = colWid; |
1882 | } | 1886 | } |
1883 | if ( ((i) % daysToShow) >= daysToShow-colModulo ) { | 1887 | if ( ((i) % daysToShow) >= daysToShow-colModulo ) { |
1884 | ++w; | 1888 | ++w; |
1885 | } | 1889 | } |
1886 | int xC,yC,wC,hC; | 1890 | int xC,yC,wC,hC; |
1887 | if ( i >= 5 ) { | 1891 | if ( i >= 5 ) { |
1888 | int wi = width() - x - weeklabelwid; | 1892 | int wi = width() - x - weeklabelwid; |
1889 | if ( i == 5 ) { | 1893 | if ( i == 5 ) { |
1890 | xC = x+weeklabelwid; | 1894 | xC = x+weeklabelwid; |
1891 | yC = y; | 1895 | yC = y; |
1892 | wC = wi/2+wi%2; | 1896 | wC = wi/2+wi%2; |
1893 | hC = h; | 1897 | hC = h; |
1894 | } else { | 1898 | } else { |
1895 | xC = x+weeklabelwid; | 1899 | xC = x+weeklabelwid; |
1896 | yC = y; | 1900 | yC = y; |
1897 | wC = wi; | 1901 | wC = wi; |
1898 | hC = h; | 1902 | hC = h; |
1899 | } | 1903 | } |
1900 | x = x - w + wi - (wi/2 ); | 1904 | x = x - w + wi - (wi/2 ); |
1901 | } | 1905 | } |
1902 | else { | 1906 | else { |
1903 | int wi = w; | 1907 | int wi = w; |
1904 | if ( !(( i+1) % daysToShow)) { | 1908 | if ( !(( i+1) % daysToShow)) { |
1905 | wi = width() - x - weeklabelwid; | 1909 | wi = width() - x - weeklabelwid; |
1906 | } | 1910 | } |
1907 | xC = x+weeklabelwid; | 1911 | xC = x+weeklabelwid; |
1908 | yC = y; | 1912 | yC = y; |
1909 | wC = wi; | 1913 | wC = wi; |
1910 | hC = h; | 1914 | hC = h; |
1911 | } | 1915 | } |
1912 | mDayLabelsW[mapWeekLayout(i,landscape)]->setGeometry( xC,yC,wC,hC); | 1916 | mDayLabelsW[mapWeekLayout(i,landscape)]->setGeometry( xC,yC,wC,hC); |
1913 | 1917 | ||
1914 | 1918 | ||
1915 | x += w; | 1919 | x += w; |
1916 | } | 1920 | } |
1917 | x= 0; | 1921 | x= 0; |
1918 | y= dayLabelHei; | 1922 | y= dayLabelHei; |
1919 | w = colWid; | 1923 | w = colWid; |
1920 | h = cellHei; | 1924 | h = cellHei; |
1921 | int max = 0; | 1925 | int max = 0; |
1922 | int w_count = mCellsW.count(); | 1926 | int w_count = mCellsW.count(); |
1923 | for ( i = 0; i < w_count; ++i) { | 1927 | for ( i = 0; i < w_count; ++i) { |
1924 | if ( i > 6 ) { | 1928 | if ( i > 6 ) { |
1925 | mCellsW[i]->hide(); | 1929 | mCellsW[i]->hide(); |
1926 | continue; | 1930 | continue; |
1927 | } | 1931 | } |
1928 | 1932 | ||
1929 | w = colWid; | 1933 | w = colWid; |
1930 | if ( ((i) % daysToShow) >= daysToShow-colModulo ) { | 1934 | if ( ((i) % daysToShow) >= daysToShow-colModulo ) { |
1931 | ++w; | 1935 | ++w; |
1932 | } | 1936 | } |
1933 | if ( i == (daysToShow-1-rowModulo)*7) | 1937 | if ( i == (daysToShow-1-rowModulo)*7) |
1934 | ++h; | 1938 | ++h; |
1935 | 1939 | ||
1936 | int xC,yC,wC,hC; | 1940 | int xC,yC,wC,hC; |
1937 | if ( i >= 5 ) { | 1941 | if ( i >= 5 ) { |
1938 | if ( i ==5 ) { | 1942 | if ( i ==5 ) { |
1939 | max = h/2; | 1943 | max = h/2; |
1940 | xC = x+weeklabelwid; | 1944 | xC = x+weeklabelwid; |
1941 | yC = y; | 1945 | yC = y; |
1942 | wC = w; | 1946 | wC = w; |
1943 | hC = max; | 1947 | hC = max; |
1944 | x -= w ;y += h/2; | 1948 | x -= w ;y += h/2; |
1945 | } else { | 1949 | } else { |
1946 | if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) { | 1950 | if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) { |
1947 | ++w; | 1951 | ++w; |
1948 | } | 1952 | } |
1949 | max = h-h/2; | 1953 | max = h-h/2; |
1950 | xC = x+weeklabelwid; | 1954 | xC = x+weeklabelwid; |
1951 | yC = y; | 1955 | yC = y; |
1952 | wC = w; | 1956 | wC = w; |
1953 | hC = max; | 1957 | hC = max; |
1954 | y -= h/2; | 1958 | y -= h/2; |
1955 | } | 1959 | } |
1956 | } else { | 1960 | } else { |
1957 | max = h; | 1961 | max = h; |
1958 | xC = x+weeklabelwid; | 1962 | xC = x+weeklabelwid; |
1959 | yC = y; | 1963 | yC = y; |
1960 | wC = w; | 1964 | wC = w; |
1961 | hC = h; | 1965 | hC = h; |
1962 | } | 1966 | } |
1963 | mCellsW[mapWeekLayout(i,landscape)]->setGeometry ( xC,yC,wC,hC ); | 1967 | mCellsW[mapWeekLayout(i,landscape)]->setGeometry ( xC,yC,wC,hC ); |
1964 | 1968 | ||
1965 | 1969 | ||
1966 | x += w; | 1970 | x += w; |
1967 | if ( x + w/2 > wid ) { | 1971 | if ( x + w/2 > wid ) { |
1968 | x = 0; | 1972 | x = 0; |
1969 | y += h+dayLabelHei ; | 1973 | y += h+dayLabelHei ; |
1970 | } | 1974 | } |
1971 | //mCellsW[i]->dateLabel()->setMaximumHeight( max - mCellsW[i]->lineWidth()*2 ); | 1975 | //mCellsW[i]->dateLabel()->setMaximumHeight( max - mCellsW[i]->lineWidth()*2 ); |
1972 | } | 1976 | } |
1973 | y= dayLabelHei; | 1977 | y= dayLabelHei; |
1974 | h = cellHei ; | 1978 | h = cellHei ; |
1975 | mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei); | 1979 | mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei); |
1976 | mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei); | 1980 | mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei); |
1977 | // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); | 1981 | // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); |
1978 | //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); | 1982 | //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); |
1979 | mShortDayLabelsW = mDayLabelsW[0]->width()-2 < mWidthLongDayLabel ; | 1983 | mShortDayLabelsW = mDayLabelsW[0]->width()-2 < mWidthLongDayLabel ; |
1980 | updateDayLabels(); | 1984 | updateDayLabels(); |
1981 | //bool forceUpdate = !updatePossible; | 1985 | //bool forceUpdate = !updatePossible; |
1982 | updatePossible = true; | 1986 | updatePossible = true; |
1983 | //mWeekLabels[mNumWeeks]->setText( i18n("M")); | 1987 | //mWeekLabels[mNumWeeks]->setText( i18n("M")); |
1984 | //if ( forceUpdate ) | 1988 | //if ( forceUpdate ) |
1985 | // updateView(); | 1989 | // updateView(); |
1986 | } | 1990 | } |
1987 | void KOMonthView::computeLayoutWeek() | 1991 | void KOMonthView::computeLayoutWeek() |
1988 | { | 1992 | { |
1989 | static int lastWid = 0; | 1993 | static int lastWid = 0; |
1990 | static int lastHei = 0; | 1994 | static int lastHei = 0; |
1991 | int tWid = topLevelWidget()->size().width(); | 1995 | int tWid = topLevelWidget()->size().width(); |
1992 | int tHei = topLevelWidget()->size().height(); | 1996 | int tHei = topLevelWidget()->size().height(); |
1993 | int wid = width();//e | 1997 | int wid = width();//e |
1994 | int hei = height()-1-mNavigatorBar->height(); | 1998 | int hei = height()-1-mNavigatorBar->height(); |
1995 | if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) | 1999 | if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) |
1996 | return; | 2000 | return; |
1997 | 2001 | ||
1998 | if ( lastWid == width() && lastHei == height() ) { | 2002 | if ( lastWid == width() && lastHei == height() ) { |
1999 | //qDebug("KOListWeekView::No compute layout needed "); | 2003 | //qDebug("KOListWeekView::No compute layout needed "); |
2000 | return; | 2004 | return; |
2001 | } | 2005 | } |
2002 | lastWid = width(); | 2006 | lastWid = width(); |
2003 | lastHei = height(); | 2007 | lastHei = height(); |
2004 | doComputeLayoutWeek(); | 2008 | doComputeLayoutWeek(); |
2005 | } | 2009 | } |
2006 | int KOMonthView::mapWeekLayout( int index, bool landscape ) | 2010 | int KOMonthView::mapWeekLayout( int index, bool landscape ) |
2007 | { | 2011 | { |
2008 | if ( KOPrefs::instance()->mMonthViewWeekRowlayout ) | 2012 | if ( KOPrefs::instance()->mMonthViewWeekRowlayout ) |
2009 | return index; | 2013 | return index; |
2010 | int diff = 0; | 2014 | int diff = 0; |
2011 | if ( !landscape ) diff = 1; | 2015 | if ( !landscape ) diff = 1; |
2012 | switch( index ) { | 2016 | switch( index ) { |
2013 | case 0: | 2017 | case 0: |
2014 | case 5: | 2018 | case 5: |
2015 | case 6: | 2019 | case 6: |
2016 | return index; | 2020 | return index; |
2017 | break; | 2021 | break; |
2018 | case 1: | 2022 | case 1: |
2019 | return 2+diff; | 2023 | return 2+diff; |
2020 | break; | 2024 | break; |
2021 | case 2: | 2025 | case 2: |
2022 | return 4-(3*diff); | 2026 | return 4-(3*diff); |
2023 | break; | 2027 | break; |
2024 | case 3: | 2028 | case 3: |
2025 | return 1+(3*diff); | 2029 | return 1+(3*diff); |
2026 | break; | 2030 | break; |
2027 | case 4: | 2031 | case 4: |
2028 | return 3-diff; | 2032 | return 3-diff; |
2029 | break; | 2033 | break; |
2030 | default: | 2034 | default: |
2031 | qDebug("KO: Error in mapping week layout "); | 2035 | qDebug("KO: Error in mapping week layout "); |
2032 | return index; | 2036 | return index; |
2033 | break; | 2037 | break; |
2034 | } | 2038 | } |
2035 | return index; | 2039 | return index; |
2036 | } | 2040 | } |
2037 | void KOMonthView::computeLayout() | 2041 | void KOMonthView::computeLayout() |
2038 | { | 2042 | { |
2039 | 2043 | ||
2040 | 2044 | ||
2041 | static int lastWid = 0; | 2045 | static int lastWid = 0; |
2042 | static int lastHei = 0; | 2046 | static int lastHei = 0; |
2043 | 2047 | ||
2044 | if ( mShowWeekView ){ | 2048 | if ( mShowWeekView ){ |
2045 | computeLayoutWeek(); | 2049 | computeLayoutWeek(); |
2046 | return; | 2050 | return; |
2047 | } | 2051 | } |
2048 | int daysToShow = 7; | 2052 | int daysToShow = 7; |
2049 | bool combinedSatSun = false; | 2053 | bool combinedSatSun = false; |
2050 | if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { | 2054 | if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { |
2051 | daysToShow = 6; | 2055 | daysToShow = 6; |
2052 | combinedSatSun = true; | 2056 | combinedSatSun = true; |
2053 | } | 2057 | } |
2054 | int tWid = topLevelWidget()->size().width(); | 2058 | int tWid = topLevelWidget()->size().width(); |
2055 | int tHei = topLevelWidget()->size().height(); | 2059 | int tHei = topLevelWidget()->size().height(); |
2056 | 2060 | ||
2057 | int wid = width();//e | 2061 | int wid = width();//e |
2058 | int hei = height()-1-mNavigatorBar->height(); | 2062 | int hei = height()-1-mNavigatorBar->height(); |
2059 | 2063 | ||
2060 | if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) { | 2064 | if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) { |
2061 | return; | 2065 | return; |
2062 | } | 2066 | } |
2063 | if ( lastWid == width() && lastHei == height() ){ | 2067 | if ( lastWid == width() && lastHei == height() ){ |
2064 | //qDebug("KOMonthview::No compute layout needed "); | 2068 | //qDebug("KOMonthview::No compute layout needed "); |
2065 | return; | 2069 | return; |
2066 | } | 2070 | } |
2067 | 2071 | ||
2068 | lastWid = width(); | 2072 | lastWid = width(); |
2069 | lastHei = height(); | 2073 | lastHei = height(); |
2070 | //qDebug("KOMonthView::computeLayout() MMM ------------------- "); | 2074 | //qDebug("KOMonthView::computeLayout() MMM ------------------- "); |
2071 | QFontMetrics fm ( mWeekLabels[0]->font() ); | 2075 | QFontMetrics fm ( mWeekLabels[0]->font() ); |
2072 | int weeklabelwid = fm.width( "888" ); | 2076 | int weeklabelwid = fm.width( "888" ); |
2073 | wid -= weeklabelwid; | 2077 | wid -= weeklabelwid; |
2074 | 2078 | ||
2075 | int colWid = wid / daysToShow; | 2079 | int colWid = wid / daysToShow; |
2076 | int dayLabelHei = mDayLabels[0]->sizeHint().height(); | 2080 | int dayLabelHei = mDayLabels[0]->sizeHint().height(); |
2077 | int cellHei = (hei - dayLabelHei) /6; | 2081 | int cellHei = (hei - dayLabelHei) /6; |
2078 | int colModulo = wid % daysToShow; | 2082 | int colModulo = wid % daysToShow; |
2079 | int rowModulo = (hei- dayLabelHei) % 6; | 2083 | int rowModulo = (hei- dayLabelHei) % 6; |
2080 | //qDebug("rowmod %d ", rowModulo); | 2084 | //qDebug("rowmod %d ", rowModulo); |
2081 | int i; | 2085 | int i; |
2082 | int x,y,w,h; | 2086 | int x,y,w,h; |
2083 | x= 0; | 2087 | x= 0; |
2084 | y= 0; | 2088 | y= 0; |
2085 | w = colWid; | 2089 | w = colWid; |
2086 | h = dayLabelHei ; | 2090 | h = dayLabelHei ; |
2087 | for ( i = 0; i < 7; i++) { | 2091 | for ( i = 0; i < 7; i++) { |
2088 | if ( i == daysToShow-colModulo ) | 2092 | if ( i == daysToShow-colModulo ) |
2089 | ++w; | 2093 | ++w; |
2090 | if ( combinedSatSun ) { | 2094 | if ( combinedSatSun ) { |
2091 | if ( i >= daysToShow-1 ) { | 2095 | if ( i >= daysToShow-1 ) { |
2092 | 2096 | ||
2093 | if ( i == 6 ) | 2097 | if ( i == 6 ) |
2094 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,width()-x-weeklabelwid,h); | 2098 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,width()-x-weeklabelwid,h); |
2095 | else | 2099 | else |
2096 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h); | 2100 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h); |
2097 | x -= w/2 ; | 2101 | x -= w/2 ; |
2098 | } | 2102 | } |
2099 | else | 2103 | else |
2100 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); | 2104 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); |
2101 | } else | 2105 | } else |
2102 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); | 2106 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); |
2103 | x += w; | 2107 | x += w; |
2104 | } | 2108 | } |
2105 | x= 0; | 2109 | x= 0; |
2106 | y= dayLabelHei; | 2110 | y= dayLabelHei; |
2107 | w = colWid; | 2111 | w = colWid; |
2108 | h = cellHei ; | 2112 | h = cellHei ; |
2109 | int max = 0; | 2113 | int max = 0; |
2110 | int mc_count = mCells.count(); | 2114 | int mc_count = mCells.count(); |
2111 | for ( i = 0; i < mc_count; ++i) { | 2115 | for ( i = 0; i < mc_count; ++i) { |
2112 | //qDebug("iii %d ", i); | 2116 | //qDebug("iii %d ", i); |
2113 | w = colWid; | 2117 | w = colWid; |
2114 | if ( ((i) % 7) >= 7-colModulo ) { | 2118 | if ( ((i) % 7) >= 7-colModulo ) { |
2115 | ++w; | 2119 | ++w; |
2116 | } | 2120 | } |
2117 | if ( i == (6-rowModulo)*7) | 2121 | if ( i == (6-rowModulo)*7) |
2118 | ++h; | 2122 | ++h; |
2119 | if ( combinedSatSun ) { | 2123 | if ( combinedSatSun ) { |
2120 | if ( (i)%7 >= daysToShow-1 ) { | 2124 | if ( (i)%7 >= daysToShow-1 ) { |
2121 | if ( (i)%7 == daysToShow-1 ) { | 2125 | if ( (i)%7 == daysToShow-1 ) { |
2122 | w = width()-x-weeklabelwid; | 2126 | w = width()-x-weeklabelwid; |
2123 | max = h/2; | 2127 | max = h/2; |
2124 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,max ); | 2128 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,max ); |
2125 | x -= w ;y += h/2; | 2129 | x -= w ;y += h/2; |
2126 | } else { | 2130 | } else { |
2127 | w = width()-x-weeklabelwid; | 2131 | w = width()-x-weeklabelwid; |
2128 | max = h-h/2; | 2132 | max = h-h/2; |
2129 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,max ); | 2133 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,max ); |
2130 | y -= h/2; | 2134 | y -= h/2; |
2131 | } | 2135 | } |
2132 | } else { | 2136 | } else { |
2133 | max = h; | 2137 | max = h; |
2134 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); | 2138 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); |
2135 | } | 2139 | } |
2136 | 2140 | ||
2137 | } | 2141 | } |
2138 | else { | 2142 | else { |
2139 | max = h; | 2143 | max = h; |
2140 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); | 2144 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); |
2141 | } | 2145 | } |
2142 | x += w; | 2146 | x += w; |
2143 | if ( x + w/2 > wid ) { | 2147 | if ( x + w/2 > wid ) { |
2144 | x = 0; | 2148 | x = 0; |
2145 | y += h; | 2149 | y += h; |
2146 | } | 2150 | } |
2147 | //mCells[i]->dateLabel()->setMaximumHeight( max- mCells[i]->lineWidth()*2 ); | 2151 | //mCells[i]->dateLabel()->setMaximumHeight( max- mCells[i]->lineWidth()*2 ); |
2148 | } | 2152 | } |
2149 | y= dayLabelHei; | 2153 | y= dayLabelHei; |
2150 | h = cellHei ; | 2154 | h = cellHei ; |
2151 | for ( i = 0; i < 6; i++) { | 2155 | for ( i = 0; i < 6; i++) { |
2152 | if ( i == (6-rowModulo)) | 2156 | if ( i == (6-rowModulo)) |
2153 | ++h; | 2157 | ++h; |
2154 | mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h); | 2158 | mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h); |
2155 | y += h; | 2159 | y += h; |
2156 | } | 2160 | } |
2157 | mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei); | 2161 | mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei); |
2158 | // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); | 2162 | // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); |
2159 | //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); | 2163 | //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); |
2160 | mShortDayLabelsM = mDayLabels[0]->width()-2 < mWidthLongDayLabel ; | 2164 | mShortDayLabelsM = mDayLabels[0]->width()-2 < mWidthLongDayLabel ; |
2161 | updateDayLabels(); | 2165 | updateDayLabels(); |
2162 | //bool forceUpdate = !updatePossible; | 2166 | //bool forceUpdate = !updatePossible; |
2163 | updatePossible = true; | 2167 | updatePossible = true; |
2164 | //mWeekLabels[mNumWeeks]->setText( i18n("W")); | 2168 | //mWeekLabels[mNumWeeks]->setText( i18n("W")); |
2165 | } | 2169 | } |
2166 | 2170 | ||
2167 | void KOMonthView::showContextMenu( Incidence *incidence ) | 2171 | void KOMonthView::showContextMenu( Incidence *incidence ) |
2168 | { | 2172 | { |
2169 | if( incidence ) | 2173 | if( incidence ) |
2170 | mContextMenu->showIncidencePopup(incidence); | 2174 | mContextMenu->showIncidencePopup(incidence); |
2171 | else { | 2175 | else { |
2172 | //qDebug("KOMonthView::showContextMenu "); | 2176 | //qDebug("KOMonthView::showContextMenu "); |
2173 | mNewItemMenu->popup(QCursor::pos()); | 2177 | mNewItemMenu->popup(QCursor::pos()); |
2174 | } | 2178 | } |
2175 | /* | 2179 | /* |
2176 | if( incidence && incidence->typeID() == eventID ) { | 2180 | if( incidence && incidence->typeID() == eventID ) { |
2177 | Event *event = static_cast<Event *>(incidence); | 2181 | Event *event = static_cast<Event *>(incidence); |
2178 | mContextMenu->showEventPopup(event); | 2182 | mContextMenu->showEventPopup(event); |
2179 | } else { | 2183 | } else { |
2180 | kdDebug() << "MonthView::showContextMenu(): cast failed." << endl; | 2184 | kdDebug() << "MonthView::showContextMenu(): cast failed." << endl; |
2181 | } | 2185 | } |
2182 | */ | 2186 | */ |
2183 | } | 2187 | } |
2184 | MonthViewCell * KOMonthView::selectedCell( ) | 2188 | MonthViewCell * KOMonthView::selectedCell( ) |
2185 | { | 2189 | { |
2186 | return mSelectedCell; | 2190 | return mSelectedCell; |
2187 | } | 2191 | } |
2188 | void KOMonthView::setSelectedCell( MonthViewCell *cell ) | 2192 | void KOMonthView::setSelectedCell( MonthViewCell *cell ) |
2189 | { | 2193 | { |
2190 | //qDebug("KOMonthView::setSelectedCell %d", cell); | 2194 | //qDebug("KOMonthView::setSelectedCell %d", cell); |
2191 | if ( mSelectedCell && mSelectedCell != cell ) { | 2195 | if ( mSelectedCell && mSelectedCell != cell ) { |
2192 | MonthViewCell * mvc = mSelectedCell; | 2196 | MonthViewCell * mvc = mSelectedCell; |
2193 | mSelectedCell = cell; | 2197 | mSelectedCell = cell; |
2194 | mvc->deselect(); | 2198 | mvc->deselect(); |
2195 | } else | 2199 | } else |
2196 | mSelectedCell = cell; | 2200 | mSelectedCell = cell; |
2197 | // if ( mSelectedCell ) | 2201 | // if ( mSelectedCell ) |
2198 | // mSelectedCell->select(); | 2202 | // mSelectedCell->select(); |
2199 | if ( !mSelectedCell ) | 2203 | if ( !mSelectedCell ) |
2200 | emit incidenceSelected( 0 ); | 2204 | emit incidenceSelected( 0 ); |
2201 | else | 2205 | else |
2202 | emit incidenceSelected( mSelectedCell->selectedIncidence() ); | 2206 | emit incidenceSelected( mSelectedCell->selectedIncidence() ); |
2203 | } | 2207 | } |
2204 | 2208 | ||
2205 | void KOMonthView::processSelectionChange() | 2209 | void KOMonthView::processSelectionChange() |
2206 | { | 2210 | { |
2207 | QPtrList<Incidence> incidences = selectedIncidences(); | 2211 | QPtrList<Incidence> incidences = selectedIncidences(); |
2208 | if (incidences.count() > 0) { | 2212 | if (incidences.count() > 0) { |
2209 | emit incidenceSelected( incidences.first() ); | 2213 | emit incidenceSelected( incidences.first() ); |
2210 | } else { | 2214 | } else { |
2211 | emit incidenceSelected( 0 ); | 2215 | emit incidenceSelected( 0 ); |
2212 | clearSelection(); | 2216 | clearSelection(); |
2213 | } | 2217 | } |
2214 | } | 2218 | } |
2215 | 2219 | ||
2216 | void KOMonthView::clearSelection() | 2220 | void KOMonthView::clearSelection() |
2217 | { | 2221 | { |
2218 | if ( mSelectedCell ) { | 2222 | if ( mSelectedCell ) { |
2219 | mSelectedCell->deselect(); | 2223 | mSelectedCell->deselect(); |
2220 | mSelectedCell = 0; | 2224 | mSelectedCell = 0; |
2221 | } | 2225 | } |
2222 | } | 2226 | } |
2223 | 2227 | ||
2224 | void KOMonthView::keyReleaseEvent ( QKeyEvent * e) | 2228 | void KOMonthView::keyReleaseEvent ( QKeyEvent * e) |
2225 | { | 2229 | { |
2226 | if ( !e->isAutoRepeat() ) { | 2230 | if ( !e->isAutoRepeat() ) { |
2227 | mFlagKeyPressed = false; | 2231 | mFlagKeyPressed = false; |
2228 | } | 2232 | } |
2229 | } | 2233 | } |
2230 | 2234 | ||
2231 | void KOMonthView::keyPressEvent ( QKeyEvent * e ) | 2235 | void KOMonthView::keyPressEvent ( QKeyEvent * e ) |
2232 | { | 2236 | { |
2233 | 2237 | ||
2234 | qApp->processEvents(); | 2238 | qApp->processEvents(); |
2235 | if ( e->isAutoRepeat() && !mFlagKeyPressed ) { | 2239 | if ( e->isAutoRepeat() && !mFlagKeyPressed ) { |
2236 | //e->ignore(); | 2240 | //e->ignore(); |
2237 | e->accept(); | 2241 | e->accept(); |
2238 | return; | 2242 | return; |
2239 | } | 2243 | } |
2240 | if (! e->isAutoRepeat() ) | 2244 | if (! e->isAutoRepeat() ) |
2241 | mFlagKeyPressed = true; | 2245 | mFlagKeyPressed = true; |
2242 | switch(e->key()) { | 2246 | switch(e->key()) { |
2243 | case Key_Up: | 2247 | case Key_Up: |
2244 | { | 2248 | { |
2245 | if ( mShowWeekView ) { | 2249 | if ( mShowWeekView ) { |
2246 | emit selectWeekNum ( currentWeek() - 1 ); | 2250 | emit selectWeekNum ( currentWeek() - 1 ); |
2247 | } | 2251 | } |
2248 | else { | 2252 | else { |
2249 | emit prevMonth(); | 2253 | emit prevMonth(); |
2250 | } | 2254 | } |
2251 | } | 2255 | } |
2252 | e->accept(); | 2256 | e->accept(); |
2253 | break; | 2257 | break; |
2254 | case Key_Down: | 2258 | case Key_Down: |
2255 | { | 2259 | { |
2256 | if ( mShowWeekView ) { | 2260 | if ( mShowWeekView ) { |
2257 | emit selectWeekNum ( currentWeek() +1); | 2261 | emit selectWeekNum ( currentWeek() +1); |
2258 | } | 2262 | } |
2259 | else { | 2263 | else { |
2260 | emit nextMonth(); | 2264 | emit nextMonth(); |
2261 | } | 2265 | } |
2262 | 2266 | ||
2263 | } | 2267 | } |
2264 | e->accept(); | 2268 | e->accept(); |
2265 | break; | 2269 | break; |
2266 | case Key_Return: | 2270 | case Key_Return: |
2267 | case Key_Enter: | 2271 | case Key_Enter: |
2268 | { | 2272 | { |
2269 | selectInternalWeekNum ( currentWeek() ); | 2273 | selectInternalWeekNum ( currentWeek() ); |
2270 | } | 2274 | } |
2271 | e->accept(); | 2275 | e->accept(); |
2272 | break; | 2276 | break; |
2273 | case Key_D: | 2277 | case Key_D: |
2274 | if ( mSelectedCell ) { | 2278 | if ( mSelectedCell ) { |
2275 | mSelectedCell->showDay(); | 2279 | mSelectedCell->showDay(); |
2276 | e->accept(); | 2280 | e->accept(); |
2277 | } else { | 2281 | } else { |
2278 | e->ignore(); | 2282 | e->ignore(); |
2279 | } | 2283 | } |
2280 | break; | 2284 | break; |
2281 | default: | 2285 | default: |
2282 | e->ignore(); | 2286 | e->ignore(); |
2283 | break; | 2287 | break; |
2284 | } | 2288 | } |
2285 | } | 2289 | } |
2286 | 2290 | ||
2287 | void KOMonthView::nextCell() | 2291 | void KOMonthView::nextCell() |
2288 | { | 2292 | { |
2289 | focusNextPrevChild ( true ); | 2293 | focusNextPrevChild ( true ); |
2290 | } | 2294 | } |
2291 | void KOMonthView::prevCell() | 2295 | void KOMonthView::prevCell() |
2292 | { | 2296 | { |
2293 | focusNextPrevChild ( false ); | 2297 | focusNextPrevChild ( false ); |
2294 | } | 2298 | } |
2295 | 2299 | ||
2296 | void KOMonthView::slotNewTodo() | 2300 | void KOMonthView::slotNewTodo() |
2297 | { | 2301 | { |
2298 | //qDebug("KOMonthView::slotNewTodo() "); | 2302 | //qDebug("KOMonthView::slotNewTodo() "); |
2299 | if ( mPopupCell ){ | 2303 | if ( mPopupCell ){ |
2300 | QDateTime dt( mPopupCell->date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); | 2304 | QDateTime dt( mPopupCell->date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); |
2301 | emit newTodoSignal(dt,true); | 2305 | emit newTodoSignal(dt,true); |
2302 | } | 2306 | } |
2303 | mPopupCell = 0; | 2307 | mPopupCell = 0; |
2304 | } | 2308 | } |
2305 | void KOMonthView::slotNewEvent() | 2309 | void KOMonthView::slotNewEvent() |
2306 | { | 2310 | { |
2307 | if ( mPopupCell ) { | 2311 | if ( mPopupCell ) { |
2308 | QDateTime dt( mPopupCell->date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); | 2312 | QDateTime dt( mPopupCell->date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); |
2309 | emit newEventSignal( dt ); | 2313 | emit newEventSignal( dt ); |
2310 | } | 2314 | } |
2311 | //qDebug("KOMonthView::slotNewEvent() "); | 2315 | //qDebug("KOMonthView::slotNewEvent() "); |
2312 | mPopupCell = 0; | 2316 | mPopupCell = 0; |
2313 | } | 2317 | } |
2314 | 2318 | ||
2315 | void KOMonthView::slotEditJournal() | 2319 | void KOMonthView::slotEditJournal() |
2316 | { | 2320 | { |
2317 | if ( mPopupCell ) | 2321 | if ( mPopupCell ) |
2318 | emit showJournalSignal( 7, mPopupCell->date() ); | 2322 | emit showJournalSignal( 7, mPopupCell->date() ); |
2319 | //qDebug("KOMonthView::slotEditJournal() "); | 2323 | //qDebug("KOMonthView::slotEditJournal() "); |
2320 | mPopupCell = 0; | 2324 | mPopupCell = 0; |
2321 | } | 2325 | } |
2322 | 2326 | ||
2323 | void KOMonthView::setPopupCell( MonthViewCell * c) | 2327 | void KOMonthView::setPopupCell( MonthViewCell * c) |
2324 | { | 2328 | { |
2325 | mPopupCell = c; | 2329 | mPopupCell = c; |
2326 | } | 2330 | } |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index e37a7ad..eef8327 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,1024 +1,1025 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <qdatetime.h> | 23 | #include <qdatetime.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | 26 | ||
27 | #include <kdebug.h> | 27 | #include <kdebug.h> |
28 | #include <kconfig.h> | 28 | #include <kconfig.h> |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | #include <klocale.h> | 30 | #include <klocale.h> |
31 | 31 | ||
32 | #include "vcaldrag.h" | 32 | #include "vcaldrag.h" |
33 | #include "vcalformat.h" | 33 | #include "vcalformat.h" |
34 | #include "icalformat.h" | 34 | #include "icalformat.h" |
35 | #include "exceptions.h" | 35 | #include "exceptions.h" |
36 | #include "incidence.h" | 36 | #include "incidence.h" |
37 | #include "journal.h" | 37 | #include "journal.h" |
38 | #include "filestorage.h" | 38 | #include "filestorage.h" |
39 | #include "calfilter.h" | 39 | #include "calfilter.h" |
40 | 40 | ||
41 | #include "calendarlocal.h" | 41 | #include "calendarlocal.h" |
42 | 42 | ||
43 | // #ifndef DESKTOP_VERSION | 43 | // #ifndef DESKTOP_VERSION |
44 | // #include <qtopia/alarmserver.h> | 44 | // #include <qtopia/alarmserver.h> |
45 | // #endif | 45 | // #endif |
46 | using namespace KCal; | 46 | using namespace KCal; |
47 | 47 | ||
48 | CalendarLocal::CalendarLocal() | 48 | CalendarLocal::CalendarLocal() |
49 | : Calendar() | 49 | : Calendar() |
50 | { | 50 | { |
51 | init(); | 51 | init(); |
52 | } | 52 | } |
53 | 53 | ||
54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) | 54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) |
55 | : Calendar(timeZoneId) | 55 | : Calendar(timeZoneId) |
56 | { | 56 | { |
57 | init(); | 57 | init(); |
58 | } | 58 | } |
59 | 59 | ||
60 | void CalendarLocal::init() | 60 | void CalendarLocal::init() |
61 | { | 61 | { |
62 | mNextAlarmIncidence = 0; | 62 | mNextAlarmIncidence = 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | CalendarLocal::~CalendarLocal() | 66 | CalendarLocal::~CalendarLocal() |
67 | { | 67 | { |
68 | registerObserver( 0 ); | ||
68 | if ( mDeleteIncidencesOnClose ) | 69 | if ( mDeleteIncidencesOnClose ) |
69 | close(); | 70 | close(); |
70 | } | 71 | } |
71 | bool CalendarLocal::mergeCalendarFile( QString name ) | 72 | bool CalendarLocal::mergeCalendarFile( QString name ) |
72 | { | 73 | { |
73 | CalendarLocal calendar( timeZoneId() ); | 74 | CalendarLocal calendar( timeZoneId() ); |
74 | calendar.setDefaultCalendar( 1 ); | 75 | calendar.setDefaultCalendar( 1 ); |
75 | if ( calendar.load( name ) ) { | 76 | if ( calendar.load( name ) ) { |
76 | mergeCalendar( &calendar ); | 77 | mergeCalendar( &calendar ); |
77 | return true; | 78 | return true; |
78 | } | 79 | } |
79 | return false; | 80 | return false; |
80 | } | 81 | } |
81 | 82 | ||
82 | Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates) | 83 | Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates) |
83 | { | 84 | { |
84 | Todo *todo;; | 85 | Todo *todo;; |
85 | Incidence *retVal = 0; | 86 | Incidence *retVal = 0; |
86 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 87 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
87 | if ( todo->uid() == uid ) { | 88 | if ( todo->uid() == uid ) { |
88 | if ( doNotCheckDuplicates ) return todo; | 89 | if ( doNotCheckDuplicates ) return todo; |
89 | if ( retVal ) { | 90 | if ( retVal ) { |
90 | if ( retVal->calID() > todo->calID() ) { | 91 | if ( retVal->calID() > todo->calID() ) { |
91 | retVal = todo; | 92 | retVal = todo; |
92 | } | 93 | } |
93 | } else { | 94 | } else { |
94 | retVal = todo; | 95 | retVal = todo; |
95 | } | 96 | } |
96 | } | 97 | } |
97 | } | 98 | } |
98 | if ( retVal ) return retVal; | 99 | if ( retVal ) return retVal; |
99 | Event *event; | 100 | Event *event; |
100 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 101 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
101 | if ( event->uid() == uid ) { | 102 | if ( event->uid() == uid ) { |
102 | if ( doNotCheckDuplicates ) return event; | 103 | if ( doNotCheckDuplicates ) return event; |
103 | if ( retVal ) { | 104 | if ( retVal ) { |
104 | if ( retVal->calID() > event->calID() ) { | 105 | if ( retVal->calID() > event->calID() ) { |
105 | retVal = event; | 106 | retVal = event; |
106 | } | 107 | } |
107 | } else { | 108 | } else { |
108 | retVal = event; | 109 | retVal = event; |
109 | } | 110 | } |
110 | } | 111 | } |
111 | } | 112 | } |
112 | if ( retVal ) return retVal; | 113 | if ( retVal ) return retVal; |
113 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 114 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
114 | if ( it->uid() == uid ) { | 115 | if ( it->uid() == uid ) { |
115 | if ( doNotCheckDuplicates ) return it; | 116 | if ( doNotCheckDuplicates ) return it; |
116 | if ( retVal ) { | 117 | if ( retVal ) { |
117 | if ( retVal->calID() > it->calID() ) { | 118 | if ( retVal->calID() > it->calID() ) { |
118 | retVal = it; | 119 | retVal = it; |
119 | } | 120 | } |
120 | } else { | 121 | } else { |
121 | retVal = it; | 122 | retVal = it; |
122 | } | 123 | } |
123 | } | 124 | } |
124 | return retVal; | 125 | return retVal; |
125 | } | 126 | } |
126 | 127 | ||
127 | bool CalendarLocal::mergeCalendar( Calendar* remote ) | 128 | bool CalendarLocal::mergeCalendar( Calendar* remote ) |
128 | { | 129 | { |
129 | // 1 look for raw inc in local | 130 | // 1 look for raw inc in local |
130 | // if inc not in remote, delete in local | 131 | // if inc not in remote, delete in local |
131 | // 2 look for raw inc in remote | 132 | // 2 look for raw inc in remote |
132 | // if inc in local, replace it | 133 | // if inc in local, replace it |
133 | // if not in local, add it to default calendar | 134 | // if not in local, add it to default calendar |
134 | QPtrList<Incidence> localInc = rawIncidences(); | 135 | QPtrList<Incidence> localInc = rawIncidences(); |
135 | Incidence* inL = localInc.first(); | 136 | Incidence* inL = localInc.first(); |
136 | while ( inL ) { | 137 | while ( inL ) { |
137 | if ( ! inL->isReadOnly () ) | 138 | if ( ! inL->isReadOnly () ) |
138 | if ( !remote->incidenceForUid( inL->uid(), true )) | 139 | if ( !remote->incidenceForUid( inL->uid(), true )) |
139 | deleteIncidence( inL ); | 140 | deleteIncidence( inL ); |
140 | inL = localInc.next(); | 141 | inL = localInc.next(); |
141 | } | 142 | } |
142 | QPtrList<Incidence> er = remote->rawIncidences(); | 143 | QPtrList<Incidence> er = remote->rawIncidences(); |
143 | Incidence* inR = er.first(); | 144 | Incidence* inR = er.first(); |
144 | while ( inR ) { | 145 | while ( inR ) { |
145 | inL = incidenceForUid( inR->uid(),false ); | 146 | inL = incidenceForUid( inR->uid(),false ); |
146 | if ( inL ) { | 147 | if ( inL ) { |
147 | if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { | 148 | if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { |
148 | int calID = inL->calID(); | 149 | int calID = inL->calID(); |
149 | deleteIncidence( inL ); | 150 | deleteIncidence( inL ); |
150 | inL = inR->clone(); | 151 | inL = inR->clone(); |
151 | inL->setCalID( calID ); | 152 | inL->setCalID( calID ); |
152 | addIncidence( inL ); | 153 | addIncidence( inL ); |
153 | } | 154 | } |
154 | } else { | 155 | } else { |
155 | inL = inR->clone(); | 156 | inL = inR->clone(); |
156 | inL->setCalID( 0 );// add to default cal | 157 | inL->setCalID( 0 );// add to default cal |
157 | addIncidence( inL ); | 158 | addIncidence( inL ); |
158 | } | 159 | } |
159 | inR = er.next(); | 160 | inR = er.next(); |
160 | } | 161 | } |
161 | return true; | 162 | return true; |
162 | } | 163 | } |
163 | 164 | ||
164 | 165 | ||
165 | bool CalendarLocal::addCalendarFile( QString name, int id ) | 166 | bool CalendarLocal::addCalendarFile( QString name, int id ) |
166 | { | 167 | { |
167 | CalendarLocal calendar( timeZoneId() ); | 168 | CalendarLocal calendar( timeZoneId() ); |
168 | calendar.setDefaultCalendar( id ); | 169 | calendar.setDefaultCalendar( id ); |
169 | if ( calendar.load( name ) ) { | 170 | if ( calendar.load( name ) ) { |
170 | addCalendar( &calendar ); | 171 | addCalendar( &calendar ); |
171 | return true; | 172 | return true; |
172 | } | 173 | } |
173 | return false; | 174 | return false; |
174 | } | 175 | } |
175 | void CalendarLocal::setSyncEventsReadOnly() | 176 | void CalendarLocal::setSyncEventsReadOnly() |
176 | { | 177 | { |
177 | Event * ev; | 178 | Event * ev; |
178 | ev = mEventList.first(); | 179 | ev = mEventList.first(); |
179 | while ( ev ) { | 180 | while ( ev ) { |
180 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | 181 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) |
181 | ev->setReadOnly( true ); | 182 | ev->setReadOnly( true ); |
182 | ev = mEventList.next(); | 183 | ev = mEventList.next(); |
183 | } | 184 | } |
184 | } | 185 | } |
185 | void CalendarLocal::addCalendar( Calendar* cal ) | 186 | void CalendarLocal::addCalendar( Calendar* cal ) |
186 | { | 187 | { |
187 | cal->setDontDeleteIncidencesOnClose(); | 188 | cal->setDontDeleteIncidencesOnClose(); |
188 | { | 189 | { |
189 | QPtrList<Event> EventList = cal->rawEvents(); | 190 | QPtrList<Event> EventList = cal->rawEvents(); |
190 | Event * ev = EventList.first(); | 191 | Event * ev = EventList.first(); |
191 | while ( ev ) { | 192 | while ( ev ) { |
192 | ev->unRegisterObserver( cal ); | 193 | ev->unRegisterObserver( cal ); |
193 | ev->registerObserver( this ); | 194 | ev->registerObserver( this ); |
194 | mEventList.append( ev ); | 195 | mEventList.append( ev ); |
195 | ev = EventList.next(); | 196 | ev = EventList.next(); |
196 | } | 197 | } |
197 | } | 198 | } |
198 | { | 199 | { |
199 | 200 | ||
200 | QPtrList<Todo> TodoList = cal->rawTodos(); | 201 | QPtrList<Todo> TodoList = cal->rawTodos(); |
201 | Todo * ev = TodoList.first(); | 202 | Todo * ev = TodoList.first(); |
202 | while ( ev ) { | 203 | while ( ev ) { |
203 | QString rel = ev->relatedToUid(); | 204 | QString rel = ev->relatedToUid(); |
204 | if ( !rel.isEmpty() ){ | 205 | if ( !rel.isEmpty() ){ |
205 | ev->setRelatedTo ( 0 ); | 206 | ev->setRelatedTo ( 0 ); |
206 | ev->setRelatedToUid( rel ); | 207 | ev->setRelatedToUid( rel ); |
207 | } | 208 | } |
208 | ev = TodoList.next(); | 209 | ev = TodoList.next(); |
209 | } | 210 | } |
210 | //TodoList = cal->rawTodos(); | 211 | //TodoList = cal->rawTodos(); |
211 | ev = TodoList.first(); | 212 | ev = TodoList.first(); |
212 | while ( ev ) { | 213 | while ( ev ) { |
213 | ev->unRegisterObserver( cal ); | 214 | ev->unRegisterObserver( cal ); |
214 | ev->registerObserver( this ); | 215 | ev->registerObserver( this ); |
215 | mTodoList.append( ev ); | 216 | mTodoList.append( ev ); |
216 | setupRelations( ev ); | 217 | setupRelations( ev ); |
217 | ev = TodoList.next(); | 218 | ev = TodoList.next(); |
218 | } | 219 | } |
219 | } | 220 | } |
220 | { | 221 | { |
221 | QPtrList<Journal> JournalList = cal->journals(); | 222 | QPtrList<Journal> JournalList = cal->journals(); |
222 | Journal * ev = JournalList.first(); | 223 | Journal * ev = JournalList.first(); |
223 | while ( ev ) { | 224 | while ( ev ) { |
224 | ev->unRegisterObserver( cal ); | 225 | ev->unRegisterObserver( cal ); |
225 | ev->registerObserver( this ); | 226 | ev->registerObserver( this ); |
226 | mJournalList.append( ev ); | 227 | mJournalList.append( ev ); |
227 | ev = JournalList.next(); | 228 | ev = JournalList.next(); |
228 | } | 229 | } |
229 | } | 230 | } |
230 | setModified( true ); | 231 | setModified( true ); |
231 | } | 232 | } |
232 | bool CalendarLocal::load( const QString &fileName ) | 233 | bool CalendarLocal::load( const QString &fileName ) |
233 | { | 234 | { |
234 | FileStorage storage( this, fileName ); | 235 | FileStorage storage( this, fileName ); |
235 | return storage.load(); | 236 | return storage.load(); |
236 | } | 237 | } |
237 | 238 | ||
238 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 239 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
239 | { | 240 | { |
240 | FileStorage storage( this, fileName, format ); | 241 | FileStorage storage( this, fileName, format ); |
241 | return storage.save(); | 242 | return storage.save(); |
242 | } | 243 | } |
243 | 244 | ||
244 | void CalendarLocal::stopAllTodos() | 245 | void CalendarLocal::stopAllTodos() |
245 | { | 246 | { |
246 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 247 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
247 | it->setRunning( false ); | 248 | it->setRunning( false ); |
248 | 249 | ||
249 | } | 250 | } |
250 | void CalendarLocal::close() | 251 | void CalendarLocal::close() |
251 | { | 252 | { |
252 | 253 | ||
253 | Todo * i; | 254 | Todo * i; |
254 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 255 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
255 | 256 | ||
256 | mEventList.setAutoDelete( true ); | 257 | mEventList.setAutoDelete( true ); |
257 | mTodoList.setAutoDelete( true ); | 258 | mTodoList.setAutoDelete( true ); |
258 | mJournalList.setAutoDelete( false ); | 259 | mJournalList.setAutoDelete( false ); |
259 | 260 | ||
260 | mEventList.clear(); | 261 | mEventList.clear(); |
261 | mTodoList.clear(); | 262 | mTodoList.clear(); |
262 | mJournalList.clear(); | 263 | mJournalList.clear(); |
263 | 264 | ||
264 | mEventList.setAutoDelete( false ); | 265 | mEventList.setAutoDelete( false ); |
265 | mTodoList.setAutoDelete( false ); | 266 | mTodoList.setAutoDelete( false ); |
266 | mJournalList.setAutoDelete( false ); | 267 | mJournalList.setAutoDelete( false ); |
267 | 268 | ||
268 | setModified( false ); | 269 | setModified( false ); |
269 | } | 270 | } |
270 | 271 | ||
271 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 272 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
272 | { | 273 | { |
273 | QString cat; | 274 | QString cat; |
274 | bool isBirthday = true; | 275 | bool isBirthday = true; |
275 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 276 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
276 | isBirthday = false; | 277 | isBirthday = false; |
277 | cat = i18n( "Anniversary" ); | 278 | cat = i18n( "Anniversary" ); |
278 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 279 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
279 | isBirthday = true; | 280 | isBirthday = true; |
280 | cat = i18n( "Birthday" ); | 281 | cat = i18n( "Birthday" ); |
281 | } else { | 282 | } else { |
282 | qDebug("addAnniversaryNoDup called without fitting category! "); | 283 | qDebug("addAnniversaryNoDup called without fitting category! "); |
283 | return false; | 284 | return false; |
284 | } | 285 | } |
285 | Event * eve; | 286 | Event * eve; |
286 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 287 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
287 | if ( !(eve->categories().contains( cat ) )) | 288 | if ( !(eve->categories().contains( cat ) )) |
288 | continue; | 289 | continue; |
289 | // now we have an event with fitting category | 290 | // now we have an event with fitting category |
290 | if ( eve->dtStart().date() != event->dtStart().date() ) | 291 | if ( eve->dtStart().date() != event->dtStart().date() ) |
291 | continue; | 292 | continue; |
292 | // now we have an event with fitting category+date | 293 | // now we have an event with fitting category+date |
293 | if ( eve->summary() != event->summary() ) | 294 | if ( eve->summary() != event->summary() ) |
294 | continue; | 295 | continue; |
295 | // now we have an event with fitting category+date+summary | 296 | // now we have an event with fitting category+date+summary |
296 | return false; | 297 | return false; |
297 | } | 298 | } |
298 | return addEvent( event ); | 299 | return addEvent( event ); |
299 | 300 | ||
300 | } | 301 | } |
301 | bool CalendarLocal::addEventNoDup( Event *event ) | 302 | bool CalendarLocal::addEventNoDup( Event *event ) |
302 | { | 303 | { |
303 | Event * eve; | 304 | Event * eve; |
304 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 305 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
305 | if ( *eve == *event ) { | 306 | if ( *eve == *event ) { |
306 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 307 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
307 | return false; | 308 | return false; |
308 | } | 309 | } |
309 | } | 310 | } |
310 | return addEvent( event ); | 311 | return addEvent( event ); |
311 | } | 312 | } |
312 | 313 | ||
313 | bool CalendarLocal::addEvent( Event *event ) | 314 | bool CalendarLocal::addEvent( Event *event ) |
314 | { | 315 | { |
315 | insertEvent( event ); | 316 | insertEvent( event ); |
316 | 317 | ||
317 | event->registerObserver( this ); | 318 | event->registerObserver( this ); |
318 | 319 | ||
319 | setModified( true ); | 320 | setModified( true ); |
320 | if ( event->calID() == 0 ) | 321 | if ( event->calID() == 0 ) |
321 | event->setCalID( mDefaultCalendar ); | 322 | event->setCalID( mDefaultCalendar ); |
322 | event->setCalEnabled( true ); | 323 | event->setCalEnabled( true ); |
323 | 324 | ||
324 | return true; | 325 | return true; |
325 | } | 326 | } |
326 | 327 | ||
327 | void CalendarLocal::deleteEvent( Event *event ) | 328 | void CalendarLocal::deleteEvent( Event *event ) |
328 | { | 329 | { |
329 | if ( mUndoIncidence ) delete mUndoIncidence; | 330 | if ( mUndoIncidence ) delete mUndoIncidence; |
330 | mUndoIncidence = event->clone(); | 331 | mUndoIncidence = event->clone(); |
331 | if ( mEventList.removeRef( event ) ) { | 332 | if ( mEventList.removeRef( event ) ) { |
332 | setModified( true ); | 333 | setModified( true ); |
333 | } | 334 | } |
334 | } | 335 | } |
335 | 336 | ||
336 | 337 | ||
337 | Event *CalendarLocal::event( const QString &uid ) | 338 | Event *CalendarLocal::event( const QString &uid ) |
338 | { | 339 | { |
339 | Event *event; | 340 | Event *event; |
340 | Event *retVal = 0; | 341 | Event *retVal = 0; |
341 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 342 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
342 | if ( event->calEnabled() && event->uid() == uid ) { | 343 | if ( event->calEnabled() && event->uid() == uid ) { |
343 | if ( retVal ) { | 344 | if ( retVal ) { |
344 | if ( retVal->calID() > event->calID() ) { | 345 | if ( retVal->calID() > event->calID() ) { |
345 | retVal = event; | 346 | retVal = event; |
346 | } | 347 | } |
347 | } else { | 348 | } else { |
348 | retVal = event; | 349 | retVal = event; |
349 | } | 350 | } |
350 | } | 351 | } |
351 | } | 352 | } |
352 | return retVal; | 353 | return retVal; |
353 | } | 354 | } |
354 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 355 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
355 | { | 356 | { |
356 | Todo * eve; | 357 | Todo * eve; |
357 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 358 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
358 | if ( *eve == *todo ) { | 359 | if ( *eve == *todo ) { |
359 | //qDebug("duplicate todo found! not inserted! "); | 360 | //qDebug("duplicate todo found! not inserted! "); |
360 | return false; | 361 | return false; |
361 | } | 362 | } |
362 | } | 363 | } |
363 | return addTodo( todo ); | 364 | return addTodo( todo ); |
364 | } | 365 | } |
365 | bool CalendarLocal::addTodo( Todo *todo ) | 366 | bool CalendarLocal::addTodo( Todo *todo ) |
366 | { | 367 | { |
367 | mTodoList.append( todo ); | 368 | mTodoList.append( todo ); |
368 | 369 | ||
369 | todo->registerObserver( this ); | 370 | todo->registerObserver( this ); |
370 | 371 | ||
371 | // Set up subtask relations | 372 | // Set up subtask relations |
372 | setupRelations( todo ); | 373 | setupRelations( todo ); |
373 | 374 | ||
374 | setModified( true ); | 375 | setModified( true ); |
375 | if ( todo->calID() == 0 ) | 376 | if ( todo->calID() == 0 ) |
376 | todo->setCalID( mDefaultCalendar ); | 377 | todo->setCalID( mDefaultCalendar ); |
377 | todo->setCalEnabled( true ); | 378 | todo->setCalEnabled( true ); |
378 | return true; | 379 | return true; |
379 | } | 380 | } |
380 | 381 | ||
381 | void CalendarLocal::deleteTodo( Todo *todo ) | 382 | void CalendarLocal::deleteTodo( Todo *todo ) |
382 | { | 383 | { |
383 | // Handle orphaned children | 384 | // Handle orphaned children |
384 | if ( mUndoIncidence ) delete mUndoIncidence; | 385 | if ( mUndoIncidence ) delete mUndoIncidence; |
385 | removeRelations( todo ); | 386 | removeRelations( todo ); |
386 | mUndoIncidence = todo->clone(); | 387 | mUndoIncidence = todo->clone(); |
387 | 388 | ||
388 | if ( mTodoList.removeRef( todo ) ) { | 389 | if ( mTodoList.removeRef( todo ) ) { |
389 | setModified( true ); | 390 | setModified( true ); |
390 | } | 391 | } |
391 | } | 392 | } |
392 | 393 | ||
393 | QPtrList<Todo> CalendarLocal::rawTodos() | 394 | QPtrList<Todo> CalendarLocal::rawTodos() |
394 | { | 395 | { |
395 | QPtrList<Todo> el; | 396 | QPtrList<Todo> el; |
396 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 397 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
397 | if ( it->calEnabled() ) el.append( it ); | 398 | if ( it->calEnabled() ) el.append( it ); |
398 | return el; | 399 | return el; |
399 | } | 400 | } |
400 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 401 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
401 | { | 402 | { |
402 | Todo *todo; | 403 | Todo *todo; |
403 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 404 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
404 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 405 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
405 | } | 406 | } |
406 | 407 | ||
407 | return 0; | 408 | return 0; |
408 | } | 409 | } |
409 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 410 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
410 | { | 411 | { |
411 | QPtrList<Incidence> all = rawIncidences() ; | 412 | QPtrList<Incidence> all = rawIncidences() ; |
412 | Incidence *inc; | 413 | Incidence *inc; |
413 | for ( inc = all.first(); inc; inc = all.next() ) { | 414 | for ( inc = all.first(); inc; inc = all.next() ) { |
414 | inc->removeID( syncProfile ); | 415 | inc->removeID( syncProfile ); |
415 | } | 416 | } |
416 | if ( syncProfile.isEmpty() ) { | 417 | if ( syncProfile.isEmpty() ) { |
417 | QPtrList<Event> el; | 418 | QPtrList<Event> el; |
418 | Event *todo; | 419 | Event *todo; |
419 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 420 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
420 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 421 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
421 | el.append( todo ); | 422 | el.append( todo ); |
422 | } | 423 | } |
423 | for ( todo = el.first(); todo; todo = el.next() ) { | 424 | for ( todo = el.first(); todo; todo = el.next() ) { |
424 | deleteIncidence ( todo ); | 425 | deleteIncidence ( todo ); |
425 | } | 426 | } |
426 | } else { | 427 | } else { |
427 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 428 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
428 | if ( lse ) | 429 | if ( lse ) |
429 | deleteIncidence ( lse ); | 430 | deleteIncidence ( lse ); |
430 | } | 431 | } |
431 | } | 432 | } |
432 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 433 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
433 | { | 434 | { |
434 | QPtrList<Event> el; | 435 | QPtrList<Event> el; |
435 | Event *todo; | 436 | Event *todo; |
436 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 437 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
437 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 438 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
438 | if ( todo->summary().left(3) == "E: " ) | 439 | if ( todo->summary().left(3) == "E: " ) |
439 | el.append( todo ); | 440 | el.append( todo ); |
440 | } | 441 | } |
441 | 442 | ||
442 | return el; | 443 | return el; |
443 | 444 | ||
444 | } | 445 | } |
445 | Event *CalendarLocal::event( QString syncProf, QString id ) | 446 | Event *CalendarLocal::event( QString syncProf, QString id ) |
446 | { | 447 | { |
447 | Event *todo; | 448 | Event *todo; |
448 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 449 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
449 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 450 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
450 | } | 451 | } |
451 | 452 | ||
452 | return 0; | 453 | return 0; |
453 | } | 454 | } |
454 | Todo *CalendarLocal::todo( const QString &uid ) | 455 | Todo *CalendarLocal::todo( const QString &uid ) |
455 | { | 456 | { |
456 | Todo *todo;; | 457 | Todo *todo;; |
457 | Todo *retVal = 0; | 458 | Todo *retVal = 0; |
458 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 459 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
459 | if ( todo->calEnabled() && todo->uid() == uid ) { | 460 | if ( todo->calEnabled() && todo->uid() == uid ) { |
460 | if ( retVal ) { | 461 | if ( retVal ) { |
461 | if ( retVal->calID() > todo->calID() ) { | 462 | if ( retVal->calID() > todo->calID() ) { |
462 | retVal = todo; | 463 | retVal = todo; |
463 | } | 464 | } |
464 | } else { | 465 | } else { |
465 | retVal = todo; | 466 | retVal = todo; |
466 | } | 467 | } |
467 | } | 468 | } |
468 | } | 469 | } |
469 | return retVal; | 470 | return retVal; |
470 | } | 471 | } |
471 | QString CalendarLocal::nextSummary() const | 472 | QString CalendarLocal::nextSummary() const |
472 | { | 473 | { |
473 | return mNextSummary; | 474 | return mNextSummary; |
474 | } | 475 | } |
475 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 476 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
476 | { | 477 | { |
477 | return mNextAlarmEventDateTime; | 478 | return mNextAlarmEventDateTime; |
478 | } | 479 | } |
479 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 480 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
480 | { | 481 | { |
481 | //mNextAlarmIncidence | 482 | //mNextAlarmIncidence |
482 | //mNextAlarmDateTime | 483 | //mNextAlarmDateTime |
483 | //return mNextSummary; | 484 | //return mNextSummary; |
484 | //return mNextAlarmEventDateTime; | 485 | //return mNextAlarmEventDateTime; |
485 | bool newNextAlarm = false; | 486 | bool newNextAlarm = false; |
486 | bool computeNextAlarm = false; | 487 | bool computeNextAlarm = false; |
487 | bool ok; | 488 | bool ok; |
488 | int offset; | 489 | int offset; |
489 | QDateTime nextA; | 490 | QDateTime nextA; |
490 | // QString nextSum; | 491 | // QString nextSum; |
491 | //QDateTime nextEvent; | 492 | //QDateTime nextEvent; |
492 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 493 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
493 | computeNextAlarm = true; | 494 | computeNextAlarm = true; |
494 | } else { | 495 | } else { |
495 | if ( ! deleted ) { | 496 | if ( ! deleted ) { |
496 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 497 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
497 | if ( ok ) { | 498 | if ( ok ) { |
498 | if ( nextA < mNextAlarmDateTime ) { | 499 | if ( nextA < mNextAlarmDateTime ) { |
499 | deRegisterAlarm(); | 500 | deRegisterAlarm(); |
500 | mNextAlarmDateTime = nextA; | 501 | mNextAlarmDateTime = nextA; |
501 | mNextSummary = incidence->summary(); | 502 | mNextSummary = incidence->summary(); |
502 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 503 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
503 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 504 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
504 | newNextAlarm = true; | 505 | newNextAlarm = true; |
505 | mNextAlarmIncidence = incidence; | 506 | mNextAlarmIncidence = incidence; |
506 | } else { | 507 | } else { |
507 | if ( incidence == mNextAlarmIncidence ) { | 508 | if ( incidence == mNextAlarmIncidence ) { |
508 | computeNextAlarm = true; | 509 | computeNextAlarm = true; |
509 | } | 510 | } |
510 | } | 511 | } |
511 | } else { | 512 | } else { |
512 | if ( mNextAlarmIncidence == incidence ) { | 513 | if ( mNextAlarmIncidence == incidence ) { |
513 | computeNextAlarm = true; | 514 | computeNextAlarm = true; |
514 | } | 515 | } |
515 | } | 516 | } |
516 | } else { // deleted | 517 | } else { // deleted |
517 | if ( incidence == mNextAlarmIncidence ) { | 518 | if ( incidence == mNextAlarmIncidence ) { |
518 | computeNextAlarm = true; | 519 | computeNextAlarm = true; |
519 | } | 520 | } |
520 | } | 521 | } |
521 | } | 522 | } |
522 | if ( computeNextAlarm ) { | 523 | if ( computeNextAlarm ) { |
523 | deRegisterAlarm(); | 524 | deRegisterAlarm(); |
524 | nextA = nextAlarm( 1000 ); | 525 | nextA = nextAlarm( 1000 ); |
525 | if (! mNextAlarmIncidence ) { | 526 | if (! mNextAlarmIncidence ) { |
526 | return; | 527 | return; |
527 | } | 528 | } |
528 | newNextAlarm = true; | 529 | newNextAlarm = true; |
529 | } | 530 | } |
530 | if ( newNextAlarm ) | 531 | if ( newNextAlarm ) |
531 | registerAlarm(); | 532 | registerAlarm(); |
532 | } | 533 | } |
533 | QString CalendarLocal:: getAlarmNotification() | 534 | QString CalendarLocal:: getAlarmNotification() |
534 | { | 535 | { |
535 | QString ret; | 536 | QString ret; |
536 | // this should not happen | 537 | // this should not happen |
537 | if (! mNextAlarmIncidence ) | 538 | if (! mNextAlarmIncidence ) |
538 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 539 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
539 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 540 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
540 | if ( alarm->type() == Alarm::Procedure ) { | 541 | if ( alarm->type() == Alarm::Procedure ) { |
541 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 542 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
542 | } else { | 543 | } else { |
543 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 544 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
544 | } | 545 | } |
545 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 546 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
546 | if ( mNextSummary.length() > 25 ) | 547 | if ( mNextSummary.length() > 25 ) |
547 | ret += "\n" + mNextSummary.mid(25, 25 ); | 548 | ret += "\n" + mNextSummary.mid(25, 25 ); |
548 | ret+= "\n"+mNextAlarmEventDateTimeString; | 549 | ret+= "\n"+mNextAlarmEventDateTimeString; |
549 | return ret; | 550 | return ret; |
550 | } | 551 | } |
551 | void CalendarLocal::registerAlarm() | 552 | void CalendarLocal::registerAlarm() |
552 | { | 553 | { |
553 | mLastAlarmNotificationString = getAlarmNotification(); | 554 | mLastAlarmNotificationString = getAlarmNotification(); |
554 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 555 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
555 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 556 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
556 | // #ifndef DESKTOP_VERSION | 557 | // #ifndef DESKTOP_VERSION |
557 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 558 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
558 | // #endif | 559 | // #endif |
559 | } | 560 | } |
560 | void CalendarLocal::deRegisterAlarm() | 561 | void CalendarLocal::deRegisterAlarm() |
561 | { | 562 | { |
562 | if ( mLastAlarmNotificationString.isNull() ) | 563 | if ( mLastAlarmNotificationString.isNull() ) |
563 | return; | 564 | return; |
564 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 565 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
565 | 566 | ||
566 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 567 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
567 | mNextAlarmEventDateTime = QDateTime(); | 568 | mNextAlarmEventDateTime = QDateTime(); |
568 | // #ifndef DESKTOP_VERSION | 569 | // #ifndef DESKTOP_VERSION |
569 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 570 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
570 | // #endif | 571 | // #endif |
571 | } | 572 | } |
572 | 573 | ||
573 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 574 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
574 | { | 575 | { |
575 | QPtrList<Todo> todos; | 576 | QPtrList<Todo> todos; |
576 | 577 | ||
577 | Todo *todo; | 578 | Todo *todo; |
578 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 579 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
579 | if ( !todo->calEnabled() ) continue; | 580 | if ( !todo->calEnabled() ) continue; |
580 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 581 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
581 | todos.append( todo ); | 582 | todos.append( todo ); |
582 | } | 583 | } |
583 | } | 584 | } |
584 | 585 | ||
585 | filter()->apply( &todos ); | 586 | filter()->apply( &todos ); |
586 | return todos; | 587 | return todos; |
587 | } | 588 | } |
588 | void CalendarLocal::reInitAlarmSettings() | 589 | void CalendarLocal::reInitAlarmSettings() |
589 | { | 590 | { |
590 | if ( !mNextAlarmIncidence ) { | 591 | if ( !mNextAlarmIncidence ) { |
591 | nextAlarm( 1000 ); | 592 | nextAlarm( 1000 ); |
592 | } | 593 | } |
593 | deRegisterAlarm(); | 594 | deRegisterAlarm(); |
594 | mNextAlarmIncidence = 0; | 595 | mNextAlarmIncidence = 0; |
595 | checkAlarmForIncidence( 0, false ); | 596 | checkAlarmForIncidence( 0, false ); |
596 | 597 | ||
597 | } | 598 | } |
598 | 599 | ||
599 | 600 | ||
600 | 601 | ||
601 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 602 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
602 | { | 603 | { |
603 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 604 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
604 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 605 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
605 | QDateTime next; | 606 | QDateTime next; |
606 | Event *e; | 607 | Event *e; |
607 | bool ok; | 608 | bool ok; |
608 | bool found = false; | 609 | bool found = false; |
609 | int offset; | 610 | int offset; |
610 | mNextAlarmIncidence = 0; | 611 | mNextAlarmIncidence = 0; |
611 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 612 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
612 | if ( !e->calEnabled() ) continue; | 613 | if ( !e->calEnabled() ) continue; |
613 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 614 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
614 | if ( ok ) { | 615 | if ( ok ) { |
615 | if ( next < nextA ) { | 616 | if ( next < nextA ) { |
616 | nextA = next; | 617 | nextA = next; |
617 | found = true; | 618 | found = true; |
618 | mNextSummary = e->summary(); | 619 | mNextSummary = e->summary(); |
619 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 620 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
620 | mNextAlarmIncidence = (Incidence *) e; | 621 | mNextAlarmIncidence = (Incidence *) e; |
621 | } | 622 | } |
622 | } | 623 | } |
623 | } | 624 | } |
624 | Todo *t; | 625 | Todo *t; |
625 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 626 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
626 | if ( !t->calEnabled() ) continue; | 627 | if ( !t->calEnabled() ) continue; |
627 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 628 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
628 | if ( ok ) { | 629 | if ( ok ) { |
629 | if ( next < nextA ) { | 630 | if ( next < nextA ) { |
630 | nextA = next; | 631 | nextA = next; |
631 | found = true; | 632 | found = true; |
632 | mNextSummary = t->summary(); | 633 | mNextSummary = t->summary(); |
633 | mNextAlarmEventDateTime = next.addSecs(offset ); | 634 | mNextAlarmEventDateTime = next.addSecs(offset ); |
634 | mNextAlarmIncidence = (Incidence *) t; | 635 | mNextAlarmIncidence = (Incidence *) t; |
635 | } | 636 | } |
636 | } | 637 | } |
637 | } | 638 | } |
638 | if ( mNextAlarmIncidence ) { | 639 | if ( mNextAlarmIncidence ) { |
639 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 640 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
640 | mNextAlarmDateTime = nextA; | 641 | mNextAlarmDateTime = nextA; |
641 | } | 642 | } |
642 | return nextA; | 643 | return nextA; |
643 | } | 644 | } |
644 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 645 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
645 | { | 646 | { |
646 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 647 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
647 | } | 648 | } |
648 | 649 | ||
649 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 650 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
650 | { | 651 | { |
651 | 652 | ||
652 | Alarm::List alarms; | 653 | Alarm::List alarms; |
653 | 654 | ||
654 | Event *e; | 655 | Event *e; |
655 | 656 | ||
656 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 657 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
657 | if ( !e->calEnabled() ) continue; | 658 | if ( !e->calEnabled() ) continue; |
658 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 659 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
659 | else appendAlarms( alarms, e, from, to ); | 660 | else appendAlarms( alarms, e, from, to ); |
660 | } | 661 | } |
661 | 662 | ||
662 | Todo *t; | 663 | Todo *t; |
663 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 664 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
664 | if ( !t->calEnabled() ) continue; | 665 | if ( !t->calEnabled() ) continue; |
665 | appendAlarms( alarms, t, from, to ); | 666 | appendAlarms( alarms, t, from, to ); |
666 | } | 667 | } |
667 | 668 | ||
668 | return alarms; | 669 | return alarms; |
669 | } | 670 | } |
670 | 671 | ||
671 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 672 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
672 | const QDateTime &from, const QDateTime &to ) | 673 | const QDateTime &from, const QDateTime &to ) |
673 | { | 674 | { |
674 | QPtrList<Alarm> alarmList = incidence->alarms(); | 675 | QPtrList<Alarm> alarmList = incidence->alarms(); |
675 | Alarm *alarm; | 676 | Alarm *alarm; |
676 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 677 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
677 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 678 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
678 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 679 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
679 | if ( alarm->enabled() ) { | 680 | if ( alarm->enabled() ) { |
680 | if ( alarm->time() >= from && alarm->time() <= to ) { | 681 | if ( alarm->time() >= from && alarm->time() <= to ) { |
681 | alarms.append( alarm ); | 682 | alarms.append( alarm ); |
682 | } | 683 | } |
683 | } | 684 | } |
684 | } | 685 | } |
685 | } | 686 | } |
686 | 687 | ||
687 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | 688 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, |
688 | Incidence *incidence, | 689 | Incidence *incidence, |
689 | const QDateTime &from, | 690 | const QDateTime &from, |
690 | const QDateTime &to ) | 691 | const QDateTime &to ) |
691 | { | 692 | { |
692 | 693 | ||
693 | QPtrList<Alarm> alarmList = incidence->alarms(); | 694 | QPtrList<Alarm> alarmList = incidence->alarms(); |
694 | Alarm *alarm; | 695 | Alarm *alarm; |
695 | QDateTime qdt; | 696 | QDateTime qdt; |
696 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 697 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
697 | if (incidence->recursOn(from.date())) { | 698 | if (incidence->recursOn(from.date())) { |
698 | qdt.setTime(alarm->time().time()); | 699 | qdt.setTime(alarm->time().time()); |
699 | qdt.setDate(from.date()); | 700 | qdt.setDate(from.date()); |
700 | } | 701 | } |
701 | else qdt = alarm->time(); | 702 | else qdt = alarm->time(); |
702 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); | 703 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); |
703 | if ( alarm->enabled() ) { | 704 | if ( alarm->enabled() ) { |
704 | if ( qdt >= from && qdt <= to ) { | 705 | if ( qdt >= from && qdt <= to ) { |
705 | alarms.append( alarm ); | 706 | alarms.append( alarm ); |
706 | } | 707 | } |
707 | } | 708 | } |
708 | } | 709 | } |
709 | } | 710 | } |
710 | 711 | ||
711 | 712 | ||
712 | /****************************** PROTECTED METHODS ****************************/ | 713 | /****************************** PROTECTED METHODS ****************************/ |
713 | 714 | ||
714 | // after changes are made to an event, this should be called. | 715 | // after changes are made to an event, this should be called. |
715 | void CalendarLocal::update( IncidenceBase *incidence ) | 716 | void CalendarLocal::update( IncidenceBase *incidence ) |
716 | { | 717 | { |
717 | incidence->setSyncStatus( Event::SYNCMOD ); | 718 | incidence->setSyncStatus( Event::SYNCMOD ); |
718 | incidence->setLastModified( QDateTime::currentDateTime() ); | 719 | incidence->setLastModified( QDateTime::currentDateTime() ); |
719 | // we should probably update the revision number here, | 720 | // we should probably update the revision number here, |
720 | // or internally in the Event itself when certain things change. | 721 | // or internally in the Event itself when certain things change. |
721 | // need to verify with ical documentation. | 722 | // need to verify with ical documentation. |
722 | 723 | ||
723 | setModified( true ); | 724 | setModified( true ); |
724 | } | 725 | } |
725 | 726 | ||
726 | void CalendarLocal::insertEvent( Event *event ) | 727 | void CalendarLocal::insertEvent( Event *event ) |
727 | { | 728 | { |
728 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 729 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
729 | } | 730 | } |
730 | 731 | ||
731 | 732 | ||
732 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 733 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
733 | { | 734 | { |
734 | QPtrList<Event> eventList; | 735 | QPtrList<Event> eventList; |
735 | 736 | ||
736 | Event *event; | 737 | Event *event; |
737 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 738 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
738 | if ( !event->calEnabled() ) continue; | 739 | if ( !event->calEnabled() ) continue; |
739 | if ( event->doesRecur() ) { | 740 | if ( event->doesRecur() ) { |
740 | if ( event->isMultiDay() ) { | 741 | if ( event->isMultiDay() ) { |
741 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 742 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
742 | int i; | 743 | int i; |
743 | for ( i = 0; i <= extraDays; i++ ) { | 744 | for ( i = 0; i <= extraDays; i++ ) { |
744 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 745 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
745 | eventList.append( event ); | 746 | eventList.append( event ); |
746 | break; | 747 | break; |
747 | } | 748 | } |
748 | } | 749 | } |
749 | } else { | 750 | } else { |
750 | if ( event->recursOn( qd ) ) | 751 | if ( event->recursOn( qd ) ) |
751 | eventList.append( event ); | 752 | eventList.append( event ); |
752 | } | 753 | } |
753 | } else { | 754 | } else { |
754 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 755 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
755 | eventList.append( event ); | 756 | eventList.append( event ); |
756 | } | 757 | } |
757 | } | 758 | } |
758 | } | 759 | } |
759 | 760 | ||
760 | if ( !sorted ) { | 761 | if ( !sorted ) { |
761 | return eventList; | 762 | return eventList; |
762 | } | 763 | } |
763 | 764 | ||
764 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 765 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
765 | // now, we have to sort it based on dtStart.time() | 766 | // now, we have to sort it based on dtStart.time() |
766 | QPtrList<Event> eventListSorted; | 767 | QPtrList<Event> eventListSorted; |
767 | Event *sortEvent; | 768 | Event *sortEvent; |
768 | for ( event = eventList.first(); event; event = eventList.next() ) { | 769 | for ( event = eventList.first(); event; event = eventList.next() ) { |
769 | sortEvent = eventListSorted.first(); | 770 | sortEvent = eventListSorted.first(); |
770 | int i = 0; | 771 | int i = 0; |
771 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 772 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
772 | { | 773 | { |
773 | i++; | 774 | i++; |
774 | sortEvent = eventListSorted.next(); | 775 | sortEvent = eventListSorted.next(); |
775 | } | 776 | } |
776 | eventListSorted.insert( i, event ); | 777 | eventListSorted.insert( i, event ); |
777 | } | 778 | } |
778 | return eventListSorted; | 779 | return eventListSorted; |
779 | } | 780 | } |
780 | 781 | ||
781 | 782 | ||
782 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 783 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
783 | bool inclusive ) | 784 | bool inclusive ) |
784 | { | 785 | { |
785 | Event *event = 0; | 786 | Event *event = 0; |
786 | 787 | ||
787 | QPtrList<Event> eventList; | 788 | QPtrList<Event> eventList; |
788 | 789 | ||
789 | // Get non-recurring events | 790 | // Get non-recurring events |
790 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 791 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
791 | if ( !event->calEnabled() ) continue; | 792 | if ( !event->calEnabled() ) continue; |
792 | if ( event->doesRecur() ) { | 793 | if ( event->doesRecur() ) { |
793 | QDate rStart = event->dtStart().date(); | 794 | QDate rStart = event->dtStart().date(); |
794 | bool found = false; | 795 | bool found = false; |
795 | if ( inclusive ) { | 796 | if ( inclusive ) { |
796 | if ( rStart >= start && rStart <= end ) { | 797 | if ( rStart >= start && rStart <= end ) { |
797 | // Start date of event is in range. Now check for end date. | 798 | // Start date of event is in range. Now check for end date. |
798 | // if duration is negative, event recurs forever, so do not include it. | 799 | // if duration is negative, event recurs forever, so do not include it. |
799 | if ( event->recurrence()->duration() == 0 ) { // End date set | 800 | if ( event->recurrence()->duration() == 0 ) { // End date set |
800 | QDate rEnd = event->recurrence()->endDate(); | 801 | QDate rEnd = event->recurrence()->endDate(); |
801 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 802 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
802 | found = true; | 803 | found = true; |
803 | } | 804 | } |
804 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 805 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
805 | // TODO: Calculate end date from duration. Should be done in Event | 806 | // TODO: Calculate end date from duration. Should be done in Event |
806 | // For now exclude all events with a duration. | 807 | // For now exclude all events with a duration. |
807 | } | 808 | } |
808 | } | 809 | } |
809 | } else { | 810 | } else { |
810 | bool founOne; | 811 | bool founOne; |
811 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 812 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
812 | if ( founOne ) { | 813 | if ( founOne ) { |
813 | if ( next <= end ) { | 814 | if ( next <= end ) { |
814 | found = true; | 815 | found = true; |
815 | } | 816 | } |
816 | } | 817 | } |
817 | 818 | ||
818 | /* | 819 | /* |
819 | // crap !!! | 820 | // crap !!! |
820 | if ( rStart <= end ) { // Start date not after range | 821 | if ( rStart <= end ) { // Start date not after range |
821 | if ( rStart >= start ) { // Start date within range | 822 | if ( rStart >= start ) { // Start date within range |
822 | found = true; | 823 | found = true; |
823 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 824 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
824 | found = true; | 825 | found = true; |
825 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 826 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
826 | QDate rEnd = event->recurrence()->endDate(); | 827 | QDate rEnd = event->recurrence()->endDate(); |
827 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 828 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
828 | found = true; | 829 | found = true; |
829 | } | 830 | } |
830 | } else { // Duration set | 831 | } else { // Duration set |
831 | // TODO: Calculate end date from duration. Should be done in Event | 832 | // TODO: Calculate end date from duration. Should be done in Event |
832 | // For now include all events with a duration. | 833 | // For now include all events with a duration. |
833 | found = true; | 834 | found = true; |
834 | } | 835 | } |
835 | } | 836 | } |
836 | */ | 837 | */ |
837 | 838 | ||
838 | } | 839 | } |
839 | 840 | ||
840 | if ( found ) eventList.append( event ); | 841 | if ( found ) eventList.append( event ); |
841 | } else { | 842 | } else { |
842 | QDate s = event->dtStart().date(); | 843 | QDate s = event->dtStart().date(); |
843 | QDate e = event->dtEnd().date(); | 844 | QDate e = event->dtEnd().date(); |
844 | 845 | ||
845 | if ( inclusive ) { | 846 | if ( inclusive ) { |
846 | if ( s >= start && e <= end ) { | 847 | if ( s >= start && e <= end ) { |
847 | eventList.append( event ); | 848 | eventList.append( event ); |
848 | } | 849 | } |
849 | } else { | 850 | } else { |
850 | if ( ( e >= start && s <= end ) ) { | 851 | if ( ( e >= start && s <= end ) ) { |
851 | eventList.append( event ); | 852 | eventList.append( event ); |
852 | } | 853 | } |
853 | } | 854 | } |
854 | } | 855 | } |
855 | } | 856 | } |
856 | 857 | ||
857 | return eventList; | 858 | return eventList; |
858 | } | 859 | } |
859 | 860 | ||
860 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 861 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
861 | { | 862 | { |
862 | return rawEventsForDate( qdt.date() ); | 863 | return rawEventsForDate( qdt.date() ); |
863 | } | 864 | } |
864 | 865 | ||
865 | QPtrList<Event> CalendarLocal::rawEvents() | 866 | QPtrList<Event> CalendarLocal::rawEvents() |
866 | { | 867 | { |
867 | QPtrList<Event> el; | 868 | QPtrList<Event> el; |
868 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 869 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
869 | if ( it->calEnabled() ) el.append( it ); | 870 | if ( it->calEnabled() ) el.append( it ); |
870 | return el; | 871 | return el; |
871 | } | 872 | } |
872 | 873 | ||
873 | bool CalendarLocal::addJournal(Journal *journal) | 874 | bool CalendarLocal::addJournal(Journal *journal) |
874 | { | 875 | { |
875 | mJournalList.append(journal); | 876 | mJournalList.append(journal); |
876 | 877 | ||
877 | journal->registerObserver( this ); | 878 | journal->registerObserver( this ); |
878 | 879 | ||
879 | setModified( true ); | 880 | setModified( true ); |
880 | if ( journal->calID() == 0 ) | 881 | if ( journal->calID() == 0 ) |
881 | journal->setCalID( mDefaultCalendar ); | 882 | journal->setCalID( mDefaultCalendar ); |
882 | journal->setCalEnabled( true ); | 883 | journal->setCalEnabled( true ); |
883 | return true; | 884 | return true; |
884 | } | 885 | } |
885 | 886 | ||
886 | void CalendarLocal::deleteJournal( Journal *journal ) | 887 | void CalendarLocal::deleteJournal( Journal *journal ) |
887 | { | 888 | { |
888 | if ( mUndoIncidence ) delete mUndoIncidence; | 889 | if ( mUndoIncidence ) delete mUndoIncidence; |
889 | mUndoIncidence = journal->clone(); | 890 | mUndoIncidence = journal->clone(); |
890 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); | 891 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); |
891 | if ( mJournalList.removeRef(journal) ) { | 892 | if ( mJournalList.removeRef(journal) ) { |
892 | setModified( true ); | 893 | setModified( true ); |
893 | } | 894 | } |
894 | } | 895 | } |
895 | 896 | ||
896 | QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) | 897 | QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) |
897 | { | 898 | { |
898 | QPtrList<Journal> el; | 899 | QPtrList<Journal> el; |
899 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 900 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
900 | if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); | 901 | if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); |
901 | return el; | 902 | return el; |
902 | } | 903 | } |
903 | Journal *CalendarLocal::journal( const QDate &date ) | 904 | Journal *CalendarLocal::journal( const QDate &date ) |
904 | { | 905 | { |
905 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 906 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
906 | 907 | ||
907 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 908 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
908 | if ( it->calEnabled() && it->dtStart().date() == date ) | 909 | if ( it->calEnabled() && it->dtStart().date() == date ) |
909 | return it; | 910 | return it; |
910 | 911 | ||
911 | return 0; | 912 | return 0; |
912 | } | 913 | } |
913 | 914 | ||
914 | Journal *CalendarLocal::journal( const QString &uid ) | 915 | Journal *CalendarLocal::journal( const QString &uid ) |
915 | { | 916 | { |
916 | Journal * retVal = 0; | 917 | Journal * retVal = 0; |
917 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 918 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
918 | if ( it->calEnabled() && it->uid() == uid ) { | 919 | if ( it->calEnabled() && it->uid() == uid ) { |
919 | if ( retVal ) { | 920 | if ( retVal ) { |
920 | if ( retVal->calID() > it->calID() ) { | 921 | if ( retVal->calID() > it->calID() ) { |
921 | retVal = it; | 922 | retVal = it; |
922 | } | 923 | } |
923 | } else { | 924 | } else { |
924 | retVal = it; | 925 | retVal = it; |
925 | } | 926 | } |
926 | } | 927 | } |
927 | return retVal; | 928 | return retVal; |
928 | } | 929 | } |
929 | 930 | ||
930 | QPtrList<Journal> CalendarLocal::journals() | 931 | QPtrList<Journal> CalendarLocal::journals() |
931 | { | 932 | { |
932 | QPtrList<Journal> el; | 933 | QPtrList<Journal> el; |
933 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 934 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
934 | if ( it->calEnabled() ) el.append( it ); | 935 | if ( it->calEnabled() ) el.append( it ); |
935 | return el; | 936 | return el; |
936 | } | 937 | } |
937 | void CalendarLocal::setCalendarRemove( int id ) | 938 | void CalendarLocal::setCalendarRemove( int id ) |
938 | { | 939 | { |
939 | 940 | ||
940 | { | 941 | { |
941 | QPtrList<Event> EventList = mEventList; | 942 | QPtrList<Event> EventList = mEventList; |
942 | Event * ev = EventList.first(); | 943 | Event * ev = EventList.first(); |
943 | while ( ev ) { | 944 | while ( ev ) { |
944 | if ( ev->calID() == id ) | 945 | if ( ev->calID() == id ) |
945 | deleteEvent( ev ); | 946 | deleteEvent( ev ); |
946 | ev = EventList.next(); | 947 | ev = EventList.next(); |
947 | } | 948 | } |
948 | } | 949 | } |
949 | { | 950 | { |
950 | 951 | ||
951 | QPtrList<Todo> TodoList = mTodoList; | 952 | QPtrList<Todo> TodoList = mTodoList; |
952 | Todo * ev = TodoList.first(); | 953 | Todo * ev = TodoList.first(); |
953 | while ( ev ) { | 954 | while ( ev ) { |
954 | if ( ev->calID() == id ) | 955 | if ( ev->calID() == id ) |
955 | deleteTodo( ev ); | 956 | deleteTodo( ev ); |
956 | ev = TodoList.next(); | 957 | ev = TodoList.next(); |
957 | } | 958 | } |
958 | } | 959 | } |
959 | { | 960 | { |
960 | QPtrList<Journal> JournalList = mJournalList; | 961 | QPtrList<Journal> JournalList = mJournalList; |
961 | Journal * ev = JournalList.first(); | 962 | Journal * ev = JournalList.first(); |
962 | while ( ev ) { | 963 | while ( ev ) { |
963 | if ( ev->calID() == id ) | 964 | if ( ev->calID() == id ) |
964 | deleteJournal( ev ); | 965 | deleteJournal( ev ); |
965 | ev = JournalList.next(); | 966 | ev = JournalList.next(); |
966 | } | 967 | } |
967 | } | 968 | } |
968 | 969 | ||
969 | if ( mUndoIncidence ) delete mUndoIncidence; | 970 | if ( mUndoIncidence ) delete mUndoIncidence; |
970 | mUndoIncidence = 0; | 971 | mUndoIncidence = 0; |
971 | 972 | ||
972 | } | 973 | } |
973 | 974 | ||
974 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) | 975 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) |
975 | { | 976 | { |
976 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 977 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
977 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 978 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
978 | 979 | ||
979 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 980 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
980 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 981 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
981 | 982 | ||
982 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 983 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
983 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 984 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
984 | 985 | ||
985 | } | 986 | } |
986 | 987 | ||
987 | void CalendarLocal::setReadOnly( int id, bool enable ) | 988 | void CalendarLocal::setReadOnly( int id, bool enable ) |
988 | { | 989 | { |
989 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 990 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
990 | if ( it->calID() == id ) it->setReadOnly( enable ); | 991 | if ( it->calID() == id ) it->setReadOnly( enable ); |
991 | 992 | ||
992 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 993 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
993 | if ( it->calID() == id ) it->setReadOnly( enable ); | 994 | if ( it->calID() == id ) it->setReadOnly( enable ); |
994 | 995 | ||
995 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 996 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
996 | if ( it->calID() == id ) it->setReadOnly( enable ); | 997 | if ( it->calID() == id ) it->setReadOnly( enable ); |
997 | 998 | ||
998 | } | 999 | } |
999 | 1000 | ||
1000 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) | 1001 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) |
1001 | { | 1002 | { |
1002 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1003 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1003 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 1004 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
1004 | 1005 | ||
1005 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1006 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1006 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 1007 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
1007 | 1008 | ||
1008 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1009 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1009 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 1010 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
1010 | reInitAlarmSettings(); | 1011 | reInitAlarmSettings(); |
1011 | 1012 | ||
1012 | } | 1013 | } |
1013 | void CalendarLocal::setDefaultCalendarEnabledOnly() | 1014 | void CalendarLocal::setDefaultCalendarEnabledOnly() |
1014 | { | 1015 | { |
1015 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1016 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1016 | it->setCalEnabled( it->calID() == mDefaultCalendar ); | 1017 | it->setCalEnabled( it->calID() == mDefaultCalendar ); |
1017 | 1018 | ||
1018 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1019 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1019 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 1020 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
1020 | 1021 | ||
1021 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1022 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1022 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 1023 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
1023 | 1024 | ||
1024 | } | 1025 | } |
diff --git a/libkcal/icalformat.cpp b/libkcal/icalformat.cpp index 5877406..6f3a799 100644 --- a/libkcal/icalformat.cpp +++ b/libkcal/icalformat.cpp | |||
@@ -1,462 +1,469 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library 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 GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <qdatetime.h> | 21 | #include <qdatetime.h> |
22 | #include <qstring.h> | 22 | #include <qstring.h> |
23 | #include <qptrlist.h> | 23 | #include <qptrlist.h> |
24 | #include <qregexp.h> | 24 | #include <qregexp.h> |
25 | #include <qclipboard.h> | 25 | #include <qclipboard.h> |
26 | #include <qfile.h> | 26 | #include <qfile.h> |
27 | #include <qtextstream.h> | 27 | #include <qtextstream.h> |
28 | #include <qtextcodec.h> | 28 | #include <qtextcodec.h> |
29 | #include <stdlib.h> | 29 | #include <stdlib.h> |
30 | 30 | ||
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 | 34 | ||
35 | extern "C" { | 35 | extern "C" { |
36 | #include <ical.h> | 36 | #include <ical.h> |
37 | #include <icalss.h> | 37 | #include <icalss.h> |
38 | #include <icalparser.h> | 38 | #include <icalparser.h> |
39 | #include <icalrestriction.h> | 39 | #include <icalrestriction.h> |
40 | } | 40 | } |
41 | 41 | ||
42 | #include "calendar.h" | 42 | #include "calendar.h" |
43 | #include "calendarlocal.h" | 43 | #include "calendarlocal.h" |
44 | #include "journal.h" | 44 | #include "journal.h" |
45 | 45 | ||
46 | #include "icalformat.h" | 46 | #include "icalformat.h" |
47 | #include "icalformatimpl.h" | 47 | #include "icalformatimpl.h" |
48 | 48 | ||
49 | #define _ICAL_VERSION "2.0" | 49 | #define _ICAL_VERSION "2.0" |
50 | 50 | ||
51 | using namespace KCal; | 51 | using namespace KCal; |
52 | 52 | ||
53 | ICalFormat::ICalFormat( ) | 53 | ICalFormat::ICalFormat( bool pe ) |
54 | { | 54 | { |
55 | mProcessEvents = pe; | ||
55 | mImpl = new ICalFormatImpl( this ); | 56 | mImpl = new ICalFormatImpl( this ); |
56 | tzOffsetMin = 0; | 57 | tzOffsetMin = 0; |
57 | //qDebug("new ICalFormat() "); | 58 | //qDebug("new ICalFormat() "); |
58 | } | 59 | } |
59 | 60 | ||
60 | ICalFormat::~ICalFormat() | 61 | ICalFormat::~ICalFormat() |
61 | { | 62 | { |
62 | delete mImpl; | 63 | delete mImpl; |
63 | //qDebug("delete ICalFormat "); | 64 | //qDebug("delete ICalFormat "); |
64 | } | 65 | } |
65 | 66 | ||
66 | bool ICalFormat::load( Calendar *calendar, const QString &fileName) | 67 | bool ICalFormat::load( Calendar *calendar, const QString &fileName) |
67 | { | 68 | { |
68 | 69 | ||
69 | clearException(); | 70 | clearException(); |
70 | 71 | ||
71 | QFile file( fileName ); | 72 | QFile file( fileName ); |
72 | if (!file.open( IO_ReadOnly ) ) { | 73 | if (!file.open( IO_ReadOnly ) ) { |
73 | setException(new ErrorFormat(ErrorFormat::LoadError)); | 74 | setException(new ErrorFormat(ErrorFormat::LoadError)); |
74 | return false; | 75 | return false; |
75 | } | 76 | } |
76 | QTextStream ts( &file ); | 77 | QTextStream ts( &file ); |
77 | QString text; | 78 | QString text; |
78 | 79 | ||
79 | ts.setEncoding( QTextStream::Latin1 ); | 80 | ts.setEncoding( QTextStream::Latin1 ); |
80 | text = ts.read(); | 81 | text = ts.read(); |
81 | file.close(); | 82 | file.close(); |
82 | 83 | ||
83 | return fromString( calendar, text ); | 84 | return fromString( calendar, text ); |
84 | } | 85 | } |
85 | 86 | ||
86 | //#include <qdatetime.h> | 87 | //#include <qdatetime.h> |
87 | bool ICalFormat::save( Calendar *calendar, const QString &fileName ) | 88 | bool ICalFormat::save( Calendar *calendar, const QString &fileName ) |
88 | { | 89 | { |
89 | //kdDebug(5800) << "ICalFormat::save(): " << fileName << endl; | 90 | //kdDebug(5800) << "ICalFormat::save(): " << fileName << endl; |
90 | //qDebug("ICalFormat::save "); | 91 | //qDebug("ICalFormat::save "); |
91 | clearException(); | 92 | clearException(); |
92 | QString text = toString( calendar ); | 93 | QString text = toString( calendar ); |
93 | //return false; | 94 | //return false; |
94 | // qDebug("to string takes ms: %d ",is.elapsed() ); | 95 | // qDebug("to string takes ms: %d ",is.elapsed() ); |
95 | if ( text.isNull() ) return false; | 96 | if ( text.isNull() ) return false; |
96 | 97 | ||
97 | // TODO: write backup file | 98 | // TODO: write backup file |
98 | //is.restart(); | 99 | //is.restart(); |
99 | QFile file( fileName ); | 100 | QFile file( fileName ); |
100 | if (!file.open( IO_WriteOnly ) ) { | 101 | if (!file.open( IO_WriteOnly ) ) { |
101 | setException(new ErrorFormat(ErrorFormat::SaveError, | 102 | setException(new ErrorFormat(ErrorFormat::SaveError, |
102 | i18n("Could not open file '%1'").arg(fileName))); | 103 | i18n("Could not open file '%1'").arg(fileName))); |
103 | return false; | 104 | return false; |
104 | } | 105 | } |
105 | QTextStream ts( &file ); | 106 | QTextStream ts( &file ); |
106 | 107 | ||
107 | ts.setEncoding( QTextStream::Latin1 ); | 108 | ts.setEncoding( QTextStream::Latin1 ); |
108 | ts << text; | 109 | ts << text; |
109 | file.close(); | 110 | file.close(); |
110 | //qDebug("saving file takes ms: %d ", is.elapsed() ); | 111 | //qDebug("saving file takes ms: %d ", is.elapsed() ); |
111 | return true; | 112 | return true; |
112 | } | 113 | } |
113 | 114 | ||
114 | bool ICalFormat::fromString( Calendar *cal, const QString &text ) | 115 | bool ICalFormat::fromString( Calendar *cal, const QString &text ) |
115 | { | 116 | { |
116 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); | 117 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); |
117 | // qDebug("ICalFormat::fromString tz: %s ", cal->timeZoneId().latin1()); | 118 | // qDebug("ICalFormat::fromString tz: %s ", cal->timeZoneId().latin1()); |
118 | // Get first VCALENDAR component. | 119 | // Get first VCALENDAR component. |
119 | // TODO: Handle more than one VCALENDAR or non-VCALENDAR top components | 120 | // TODO: Handle more than one VCALENDAR or non-VCALENDAR top components |
120 | icalcomponent *calendar; | 121 | icalcomponent *calendar; |
121 | 122 | ||
122 | //calendar = icalcomponent_new_from_string( text.local8Bit().data()); | 123 | //calendar = icalcomponent_new_from_string( text.local8Bit().data()); |
123 | // good calendar = icalcomponent_new_from_string( text.utf8().data()); | 124 | // good calendar = icalcomponent_new_from_string( text.utf8().data()); |
124 | calendar = icalcomponent_new_from_string( (char*)text.latin1()); | 125 | calendar = icalcomponent_new_from_string( (char*)text.latin1()); |
125 | if (!calendar) { | 126 | if (!calendar) { |
126 | setException(new ErrorFormat(ErrorFormat::ParseErrorIcal)); | 127 | setException(new ErrorFormat(ErrorFormat::ParseErrorIcal)); |
127 | return false; | 128 | return false; |
128 | } | 129 | } |
129 | 130 | ||
130 | bool success = true; | 131 | bool success = true; |
131 | 132 | ||
132 | if (icalcomponent_isa(calendar) != ICAL_VCALENDAR_COMPONENT) { | 133 | if (icalcomponent_isa(calendar) != ICAL_VCALENDAR_COMPONENT) { |
133 | setException(new ErrorFormat(ErrorFormat::NoCalendar)); | 134 | setException(new ErrorFormat(ErrorFormat::NoCalendar)); |
134 | success = false; | 135 | success = false; |
135 | } else { | 136 | } else { |
136 | // put all objects into their proper places | 137 | // put all objects into their proper places |
137 | if ( !mImpl->populate( cal, calendar ) ) { | 138 | if ( !mImpl->populate( cal, calendar ) ) { |
138 | if ( !exception() ) { | 139 | if ( !exception() ) { |
139 | setException(new ErrorFormat(ErrorFormat::ParseErrorKcal)); | 140 | setException(new ErrorFormat(ErrorFormat::ParseErrorKcal)); |
140 | } | 141 | } |
141 | success = false; | 142 | success = false; |
142 | } else | 143 | } else |
143 | mLoadedProductId = mImpl->loadedProductId(); | 144 | mLoadedProductId = mImpl->loadedProductId(); |
144 | } | 145 | } |
145 | 146 | ||
146 | icalcomponent_free( calendar ); | 147 | icalcomponent_free( calendar ); |
147 | icalmemory_free_ring(); | 148 | icalmemory_free_ring(); |
148 | 149 | ||
149 | return success; | 150 | return success; |
150 | } | 151 | } |
151 | 152 | ||
152 | Incidence *ICalFormat::fromString( const QString &text ) | 153 | Incidence *ICalFormat::fromString( const QString &text ) |
153 | { | 154 | { |
154 | CalendarLocal cal( mTimeZoneId ); | 155 | CalendarLocal cal( mTimeZoneId ); |
155 | fromString(&cal, text); | 156 | fromString(&cal, text); |
156 | 157 | ||
157 | Incidence *ical = 0; | 158 | Incidence *ical = 0; |
158 | QPtrList<Event> elist = cal.events(); | 159 | QPtrList<Event> elist = cal.events(); |
159 | if ( elist.count() > 0 ) { | 160 | if ( elist.count() > 0 ) { |
160 | ical = elist.first(); | 161 | ical = elist.first(); |
161 | } else { | 162 | } else { |
162 | QPtrList<Todo> tlist = cal.todos(); | 163 | QPtrList<Todo> tlist = cal.todos(); |
163 | if ( tlist.count() > 0 ) { | 164 | if ( tlist.count() > 0 ) { |
164 | ical = tlist.first(); | 165 | ical = tlist.first(); |
165 | } else { | 166 | } else { |
166 | QPtrList<Journal> jlist = cal.journals(); | 167 | QPtrList<Journal> jlist = cal.journals(); |
167 | if ( jlist.count() > 0 ) { | 168 | if ( jlist.count() > 0 ) { |
168 | ical = jlist.first(); | 169 | ical = jlist.first(); |
169 | } | 170 | } |
170 | } | 171 | } |
171 | } | 172 | } |
172 | return ical; | 173 | return ical; |
173 | } | 174 | } |
174 | #include <qapp.h> | 175 | #include <qapp.h> |
175 | 176 | ||
176 | QString ICalFormat::toString( Calendar *cal ) | 177 | QString ICalFormat::toString( Calendar *cal ) |
177 | { | 178 | { |
178 | 179 | ||
179 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); | 180 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); |
180 | 181 | ||
181 | icalcomponent *calendar = mImpl->createCalendarComponent(cal); | 182 | icalcomponent *calendar = mImpl->createCalendarComponent(cal); |
182 | 183 | ||
183 | icalcomponent *component; | 184 | icalcomponent *component; |
184 | 185 | ||
185 | // todos | 186 | // todos |
186 | QPtrList<Todo> todoList = cal->rawTodos(); | 187 | QPtrList<Todo> todoList = cal->rawTodos(); |
187 | QPtrListIterator<Todo> qlt(todoList); | 188 | QPtrListIterator<Todo> qlt(todoList); |
188 | for (; qlt.current(); ++qlt) { | 189 | for (; qlt.current(); ++qlt) { |
189 | component = mImpl->writeTodo(qlt.current()); | 190 | component = mImpl->writeTodo(qlt.current()); |
190 | icalcomponent_add_component(calendar,component); | 191 | icalcomponent_add_component(calendar,component); |
191 | //qDebug(" todos "); | 192 | //qDebug(" todos "); |
192 | qApp->processEvents(); | 193 | if ( mProcessEvents ) { |
194 | //qDebug("mProcessEvents "); | ||
195 | qApp->processEvents(); | ||
196 | } | ||
193 | } | 197 | } |
194 | // events | 198 | // events |
195 | QPtrList<Event> events = cal->rawEvents(); | 199 | QPtrList<Event> events = cal->rawEvents(); |
196 | Event *ev; | 200 | Event *ev; |
197 | for(ev=events.first();ev;ev=events.next()) { | 201 | for(ev=events.first();ev;ev=events.next()) { |
198 | component = mImpl->writeEvent(ev); | 202 | component = mImpl->writeEvent(ev); |
199 | icalcomponent_add_component(calendar,component); | 203 | icalcomponent_add_component(calendar,component); |
200 | //qDebug("events "); | 204 | //qDebug("events "); |
201 | qApp->processEvents(); | 205 | if ( mProcessEvents ) |
206 | qApp->processEvents(); | ||
202 | } | 207 | } |
203 | 208 | ||
204 | // journals | 209 | // journals |
205 | QPtrList<Journal> journals = cal->journals(); | 210 | QPtrList<Journal> journals = cal->journals(); |
206 | Journal *j; | 211 | Journal *j; |
207 | for(j=journals.first();j;j=journals.next()) { | 212 | for(j=journals.first();j;j=journals.next()) { |
208 | component = mImpl->writeJournal(j); | 213 | component = mImpl->writeJournal(j); |
209 | icalcomponent_add_component(calendar,component); | 214 | icalcomponent_add_component(calendar,component); |
210 | //qDebug("journals "); | 215 | //qDebug("journals "); |
211 | qApp->processEvents(); | 216 | if ( mProcessEvents ) |
217 | qApp->processEvents(); | ||
212 | } | 218 | } |
213 | const char *text; | 219 | const char *text; |
214 | QString ret =""; | 220 | QString ret =""; |
215 | text = icalcomponent_as_ical_string( calendar ); | 221 | text = icalcomponent_as_ical_string( calendar ); |
216 | qApp->processEvents(); | 222 | if ( mProcessEvents ) |
223 | qApp->processEvents(); | ||
217 | 224 | ||
218 | // text = "BEGIN:VCALENDAR\nPRODID\n :-//K Desktop Environment//NONSGML libkcal 3.1//EN\nVERSION\n :2.0\nBEGIN:VEVENT\nDTSTAMP\n :20031231T213514Z\nORGANIZER\n :MAILTO:lutz@putz.de\nCREATED\n :20031231T213513Z\nUID\n :libkcal-1295166342.120\nSEQUENCE\n :0\nLAST-MODIFIED\n :20031231T213513Z\nSUMMARY\n :test1\nCLASS\n :PUBLIC\nPRIORITY\n :3\nDTSTART\n :20040101T090000Z\nDTEND\n :20040101T110000Z\nTRANSP\n :OPAQUE\nEND:VEVENT\nEND:VCALENDAR\n"; | 225 | // text = "BEGIN:VCALENDAR\nPRODID\n :-//K Desktop Environment//NONSGML libkcal 3.1//EN\nVERSION\n :2.0\nBEGIN:VEVENT\nDTSTAMP\n :20031231T213514Z\nORGANIZER\n :MAILTO:lutz@putz.de\nCREATED\n :20031231T213513Z\nUID\n :libkcal-1295166342.120\nSEQUENCE\n :0\nLAST-MODIFIED\n :20031231T213513Z\nSUMMARY\n :test1\nCLASS\n :PUBLIC\nPRIORITY\n :3\nDTSTART\n :20040101T090000Z\nDTEND\n :20040101T110000Z\nTRANSP\n :OPAQUE\nEND:VEVENT\nEND:VCALENDAR\n"; |
219 | 226 | ||
220 | 227 | ||
221 | if ( text ) { | 228 | if ( text ) { |
222 | ret = QString ( text ); | 229 | ret = QString ( text ); |
223 | } | 230 | } |
224 | icalcomponent_free( calendar ); | 231 | icalcomponent_free( calendar ); |
225 | 232 | ||
226 | if (!text) { | 233 | if (!text) { |
227 | setException(new ErrorFormat(ErrorFormat::SaveError, | 234 | setException(new ErrorFormat(ErrorFormat::SaveError, |
228 | i18n("libical error"))); | 235 | i18n("libical error"))); |
229 | icalmemory_free_ring(); | 236 | icalmemory_free_ring(); |
230 | return QString::null; | 237 | return QString::null; |
231 | } | 238 | } |
232 | icalmemory_free_ring(); | 239 | icalmemory_free_ring(); |
233 | return ret; | 240 | return ret; |
234 | } | 241 | } |
235 | 242 | ||
236 | QString ICalFormat::toICalString( Incidence *incidence ) | 243 | QString ICalFormat::toICalString( Incidence *incidence ) |
237 | { | 244 | { |
238 | CalendarLocal cal( mTimeZoneId ); | 245 | CalendarLocal cal( mTimeZoneId ); |
239 | cal.addIncidence( incidence->clone() ); | 246 | cal.addIncidence( incidence->clone() ); |
240 | return toString( &cal ); | 247 | return toString( &cal ); |
241 | } | 248 | } |
242 | 249 | ||
243 | QString ICalFormat::toString( Incidence *incidence ) | 250 | QString ICalFormat::toString( Incidence *incidence ) |
244 | { | 251 | { |
245 | icalcomponent *component; | 252 | icalcomponent *component; |
246 | 253 | ||
247 | component = mImpl->writeIncidence( incidence ); | 254 | component = mImpl->writeIncidence( incidence ); |
248 | 255 | ||
249 | const char *text = icalcomponent_as_ical_string( component ); | 256 | const char *text = icalcomponent_as_ical_string( component ); |
250 | 257 | ||
251 | icalcomponent_free( component ); | 258 | icalcomponent_free( component ); |
252 | 259 | ||
253 | return QString::fromLocal8Bit( text ); | 260 | return QString::fromLocal8Bit( text ); |
254 | } | 261 | } |
255 | 262 | ||
256 | QString ICalFormat::toString( Recurrence *recurrence ) | 263 | QString ICalFormat::toString( Recurrence *recurrence ) |
257 | { | 264 | { |
258 | icalproperty *property; | 265 | icalproperty *property; |
259 | property = mImpl->writeRecurrenceRule( recurrence ); | 266 | property = mImpl->writeRecurrenceRule( recurrence ); |
260 | const char *text = icalproperty_as_ical_string( property ); | 267 | const char *text = icalproperty_as_ical_string( property ); |
261 | icalproperty_free( property ); | 268 | icalproperty_free( property ); |
262 | return QString::fromLocal8Bit( text ); | 269 | return QString::fromLocal8Bit( text ); |
263 | } | 270 | } |
264 | /* | 271 | /* |
265 | bool ICalFormat::fromString( Recurrence * recurrence, const QString& rrule ) | 272 | bool ICalFormat::fromString( Recurrence * recurrence, const QString& rrule ) |
266 | { | 273 | { |
267 | bool success = true; | 274 | bool success = true; |
268 | icalerror_clear_errno(); | 275 | icalerror_clear_errno(); |
269 | struct icalrecurrencetype recur = icalrecurrencetype_from_string( rrule ); | 276 | struct icalrecurrencetype recur = icalrecurrencetype_from_string( rrule ); |
270 | if ( icalerrno != ICAL_NO_ERROR ) { | 277 | if ( icalerrno != ICAL_NO_ERROR ) { |
271 | kdDebug() << "Recurrence parsing error: " << icalerror_strerror( icalerrno ) << endl; | 278 | kdDebug() << "Recurrence parsing error: " << icalerror_strerror( icalerrno ) << endl; |
272 | success = false; | 279 | success = false; |
273 | } | 280 | } |
274 | 281 | ||
275 | if ( success ) { | 282 | if ( success ) { |
276 | mImpl->readRecurrence( recur, recurrence ); | 283 | mImpl->readRecurrence( recur, recurrence ); |
277 | } | 284 | } |
278 | 285 | ||
279 | return success; | 286 | return success; |
280 | } | 287 | } |
281 | */ | 288 | */ |
282 | 289 | ||
283 | QString ICalFormat::createScheduleMessage(IncidenceBase *incidence, | 290 | QString ICalFormat::createScheduleMessage(IncidenceBase *incidence, |
284 | Scheduler::Method method) | 291 | Scheduler::Method method) |
285 | { | 292 | { |
286 | icalcomponent *message = mImpl->createScheduleComponent(incidence,method); | 293 | icalcomponent *message = mImpl->createScheduleComponent(incidence,method); |
287 | 294 | ||
288 | QString messageText = icalcomponent_as_ical_string(message); | 295 | QString messageText = icalcomponent_as_ical_string(message); |
289 | 296 | ||
290 | 297 | ||
291 | 298 | ||
292 | return messageText; | 299 | return messageText; |
293 | } | 300 | } |
294 | 301 | ||
295 | ScheduleMessage *ICalFormat::parseScheduleMessage( Calendar *cal, | 302 | ScheduleMessage *ICalFormat::parseScheduleMessage( Calendar *cal, |
296 | const QString &messageText ) | 303 | const QString &messageText ) |
297 | { | 304 | { |
298 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); | 305 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); |
299 | clearException(); | 306 | clearException(); |
300 | 307 | ||
301 | if (messageText.isEmpty()) return 0; | 308 | if (messageText.isEmpty()) return 0; |
302 | 309 | ||
303 | icalcomponent *message; | 310 | icalcomponent *message; |
304 | message = icalparser_parse_string(messageText.local8Bit()); | 311 | message = icalparser_parse_string(messageText.local8Bit()); |
305 | 312 | ||
306 | if (!message) return 0; | 313 | if (!message) return 0; |
307 | 314 | ||
308 | icalproperty *m = icalcomponent_get_first_property(message, | 315 | icalproperty *m = icalcomponent_get_first_property(message, |
309 | ICAL_METHOD_PROPERTY); | 316 | ICAL_METHOD_PROPERTY); |
310 | 317 | ||
311 | if (!m) return 0; | 318 | if (!m) return 0; |
312 | 319 | ||
313 | icalcomponent *c; | 320 | icalcomponent *c; |
314 | 321 | ||
315 | IncidenceBase *incidence = 0; | 322 | IncidenceBase *incidence = 0; |
316 | c = icalcomponent_get_first_component(message,ICAL_VEVENT_COMPONENT); | 323 | c = icalcomponent_get_first_component(message,ICAL_VEVENT_COMPONENT); |
317 | if (c) { | 324 | if (c) { |
318 | incidence = mImpl->readEvent(c); | 325 | incidence = mImpl->readEvent(c); |
319 | } | 326 | } |
320 | 327 | ||
321 | if (!incidence) { | 328 | if (!incidence) { |
322 | c = icalcomponent_get_first_component(message,ICAL_VTODO_COMPONENT); | 329 | c = icalcomponent_get_first_component(message,ICAL_VTODO_COMPONENT); |
323 | if (c) { | 330 | if (c) { |
324 | incidence = mImpl->readTodo(c); | 331 | incidence = mImpl->readTodo(c); |
325 | } | 332 | } |
326 | } | 333 | } |
327 | 334 | ||
328 | if (!incidence) { | 335 | if (!incidence) { |
329 | c = icalcomponent_get_first_component(message,ICAL_VFREEBUSY_COMPONENT); | 336 | c = icalcomponent_get_first_component(message,ICAL_VFREEBUSY_COMPONENT); |
330 | if (c) { | 337 | if (c) { |
331 | incidence = mImpl->readFreeBusy(c); | 338 | incidence = mImpl->readFreeBusy(c); |
332 | } | 339 | } |
333 | } | 340 | } |
334 | 341 | ||
335 | if (!incidence) { | 342 | if (!incidence) { |
336 | kdDebug() << "ICalFormat:parseScheduleMessage: object is not a freebusy, event or todo" << endl; | 343 | kdDebug() << "ICalFormat:parseScheduleMessage: object is not a freebusy, event or todo" << endl; |
337 | return 0; | 344 | return 0; |
338 | } | 345 | } |
339 | 346 | ||
340 | kdDebug(5800) << "ICalFormat::parseScheduleMessage() getting method..." << endl; | 347 | kdDebug(5800) << "ICalFormat::parseScheduleMessage() getting method..." << endl; |
341 | 348 | ||
342 | icalproperty_method icalmethod = icalproperty_get_method(m); | 349 | icalproperty_method icalmethod = icalproperty_get_method(m); |
343 | Scheduler::Method method; | 350 | Scheduler::Method method; |
344 | 351 | ||
345 | switch (icalmethod) { | 352 | switch (icalmethod) { |
346 | case ICAL_METHOD_PUBLISH: | 353 | case ICAL_METHOD_PUBLISH: |
347 | method = Scheduler::Publish; | 354 | method = Scheduler::Publish; |
348 | break; | 355 | break; |
349 | case ICAL_METHOD_REQUEST: | 356 | case ICAL_METHOD_REQUEST: |
350 | method = Scheduler::Request; | 357 | method = Scheduler::Request; |
351 | break; | 358 | break; |
352 | case ICAL_METHOD_REFRESH: | 359 | case ICAL_METHOD_REFRESH: |
353 | method = Scheduler::Refresh; | 360 | method = Scheduler::Refresh; |
354 | break; | 361 | break; |
355 | case ICAL_METHOD_CANCEL: | 362 | case ICAL_METHOD_CANCEL: |
356 | method = Scheduler::Cancel; | 363 | method = Scheduler::Cancel; |
357 | break; | 364 | break; |
358 | case ICAL_METHOD_ADD: | 365 | case ICAL_METHOD_ADD: |
359 | method = Scheduler::Add; | 366 | method = Scheduler::Add; |
360 | break; | 367 | break; |
361 | case ICAL_METHOD_REPLY: | 368 | case ICAL_METHOD_REPLY: |
362 | method = Scheduler::Reply; | 369 | method = Scheduler::Reply; |
363 | break; | 370 | break; |
364 | case ICAL_METHOD_COUNTER: | 371 | case ICAL_METHOD_COUNTER: |
365 | method = Scheduler::Counter; | 372 | method = Scheduler::Counter; |
366 | break; | 373 | break; |
367 | case ICAL_METHOD_DECLINECOUNTER: | 374 | case ICAL_METHOD_DECLINECOUNTER: |
368 | method = Scheduler::Declinecounter; | 375 | method = Scheduler::Declinecounter; |
369 | break; | 376 | break; |
370 | default: | 377 | default: |
371 | method = Scheduler::NoMethod; | 378 | method = Scheduler::NoMethod; |
372 | kdDebug(5800) << "ICalFormat::parseScheduleMessage(): Unknow method" << endl; | 379 | kdDebug(5800) << "ICalFormat::parseScheduleMessage(): Unknow method" << endl; |
373 | break; | 380 | break; |
374 | } | 381 | } |
375 | 382 | ||
376 | 383 | ||
377 | if (!icalrestriction_check(message)) { | 384 | if (!icalrestriction_check(message)) { |
378 | setException(new ErrorFormat(ErrorFormat::Restriction, | 385 | setException(new ErrorFormat(ErrorFormat::Restriction, |
379 | Scheduler::translatedMethodName(method) + ": " + | 386 | Scheduler::translatedMethodName(method) + ": " + |
380 | mImpl->extractErrorProperty(c))); | 387 | mImpl->extractErrorProperty(c))); |
381 | return 0; | 388 | return 0; |
382 | } | 389 | } |
383 | 390 | ||
384 | icalcomponent *calendarComponent = mImpl->createCalendarComponent(cal); | 391 | icalcomponent *calendarComponent = mImpl->createCalendarComponent(cal); |
385 | 392 | ||
386 | Incidence *existingIncidence = cal->event(incidence->uid()); | 393 | Incidence *existingIncidence = cal->event(incidence->uid()); |
387 | if (existingIncidence) { | 394 | if (existingIncidence) { |
388 | // TODO: check, if cast is required, or if it can be done by virtual funcs. | 395 | // TODO: check, if cast is required, or if it can be done by virtual funcs. |
389 | if (existingIncidence->typeID() == todoID ) { | 396 | if (existingIncidence->typeID() == todoID ) { |
390 | Todo *todo = static_cast<Todo *>(existingIncidence); | 397 | Todo *todo = static_cast<Todo *>(existingIncidence); |
391 | icalcomponent_add_component(calendarComponent, | 398 | icalcomponent_add_component(calendarComponent, |
392 | mImpl->writeTodo(todo)); | 399 | mImpl->writeTodo(todo)); |
393 | } | 400 | } |
394 | if (existingIncidence->typeID() == eventID ) { | 401 | if (existingIncidence->typeID() == eventID ) { |
395 | Event *event = static_cast<Event *>(existingIncidence); | 402 | Event *event = static_cast<Event *>(existingIncidence); |
396 | icalcomponent_add_component(calendarComponent, | 403 | icalcomponent_add_component(calendarComponent, |
397 | mImpl->writeEvent(event)); | 404 | mImpl->writeEvent(event)); |
398 | } | 405 | } |
399 | } else { | 406 | } else { |
400 | calendarComponent = 0; | 407 | calendarComponent = 0; |
401 | } | 408 | } |
402 | qDebug("icalclassify commented out "); | 409 | qDebug("icalclassify commented out "); |
403 | ScheduleMessage::Status status; | 410 | ScheduleMessage::Status status; |
404 | #if 0 | 411 | #if 0 |
405 | 412 | ||
406 | icalclass result = icalclassify(message,calendarComponent,(char *)""); | 413 | icalclass result = icalclassify(message,calendarComponent,(char *)""); |
407 | 414 | ||
408 | 415 | ||
409 | 416 | ||
410 | switch (result) { | 417 | switch (result) { |
411 | case ICAL_PUBLISH_NEW_CLASS: | 418 | case ICAL_PUBLISH_NEW_CLASS: |
412 | status = ScheduleMessage::PublishNew; | 419 | status = ScheduleMessage::PublishNew; |
413 | break; | 420 | break; |
414 | case ICAL_OBSOLETE_CLASS: | 421 | case ICAL_OBSOLETE_CLASS: |
415 | status = ScheduleMessage::Obsolete; | 422 | status = ScheduleMessage::Obsolete; |
416 | break; | 423 | break; |
417 | case ICAL_REQUEST_NEW_CLASS: | 424 | case ICAL_REQUEST_NEW_CLASS: |
418 | status = ScheduleMessage::RequestNew; | 425 | status = ScheduleMessage::RequestNew; |
419 | break; | 426 | break; |
420 | case ICAL_REQUEST_UPDATE_CLASS: | 427 | case ICAL_REQUEST_UPDATE_CLASS: |
421 | status = ScheduleMessage::RequestUpdate; | 428 | status = ScheduleMessage::RequestUpdate; |
422 | break; | 429 | break; |
423 | case ICAL_UNKNOWN_CLASS: | 430 | case ICAL_UNKNOWN_CLASS: |
424 | default: | 431 | default: |
425 | status = ScheduleMessage::Unknown; | 432 | status = ScheduleMessage::Unknown; |
426 | break; | 433 | break; |
427 | } | 434 | } |
428 | #endif | 435 | #endif |
429 | status = ScheduleMessage::RequestUpdate; | 436 | status = ScheduleMessage::RequestUpdate; |
430 | return new ScheduleMessage(incidence,method,status); | 437 | return new ScheduleMessage(incidence,method,status); |
431 | } | 438 | } |
432 | 439 | ||
433 | void ICalFormat::setTimeZone( const QString &id, bool utc ) | 440 | void ICalFormat::setTimeZone( const QString &id, bool utc ) |
434 | { | 441 | { |
435 | 442 | ||
436 | 443 | ||
437 | mTimeZoneId = id; | 444 | mTimeZoneId = id; |
438 | mUtc = utc; | 445 | mUtc = utc; |
439 | 446 | ||
440 | tzOffsetMin = KGlobal::locale()->timezoneOffset(mTimeZoneId); | 447 | tzOffsetMin = KGlobal::locale()->timezoneOffset(mTimeZoneId); |
441 | 448 | ||
442 | //qDebug("ICalFormat::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), tzOffsetMin); | 449 | //qDebug("ICalFormat::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), tzOffsetMin); |
443 | } | 450 | } |
444 | 451 | ||
445 | QString ICalFormat::timeZoneId() const | 452 | QString ICalFormat::timeZoneId() const |
446 | { | 453 | { |
447 | return mTimeZoneId; | 454 | return mTimeZoneId; |
448 | } | 455 | } |
449 | 456 | ||
450 | bool ICalFormat::utc() const | 457 | bool ICalFormat::utc() const |
451 | { | 458 | { |
452 | return mUtc; | 459 | return mUtc; |
453 | } | 460 | } |
454 | int ICalFormat::timeOffset() | 461 | int ICalFormat::timeOffset() |
455 | { | 462 | { |
456 | return tzOffsetMin; | 463 | return tzOffsetMin; |
457 | } | 464 | } |
458 | const char *ICalFormat::tzString() | 465 | const char *ICalFormat::tzString() |
459 | { | 466 | { |
460 | const char* ret = (const char* ) mTzString; | 467 | const char* ret = (const char* ) mTzString; |
461 | return ret; | 468 | return ret; |
462 | } | 469 | } |
diff --git a/libkcal/icalformat.h b/libkcal/icalformat.h index 485ab6e..a770dbb 100644 --- a/libkcal/icalformat.h +++ b/libkcal/icalformat.h | |||
@@ -1,115 +1,116 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library 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 GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | #ifndef ICALFORMAT_H | 20 | #ifndef ICALFORMAT_H |
21 | #define ICALFORMAT_H | 21 | #define ICALFORMAT_H |
22 | 22 | ||
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | 24 | ||
25 | #include "scheduler.h" | 25 | #include "scheduler.h" |
26 | 26 | ||
27 | #include "calformat.h" | 27 | #include "calformat.h" |
28 | 28 | ||
29 | namespace KCal { | 29 | namespace KCal { |
30 | 30 | ||
31 | class ICalFormatImpl; | 31 | class ICalFormatImpl; |
32 | 32 | ||
33 | /** | 33 | /** |
34 | This class implements the iCalendar format. It provides methods for | 34 | This class implements the iCalendar format. It provides methods for |
35 | loading/saving/converting iCalendar format data into the internal KOrganizer | 35 | loading/saving/converting iCalendar format data into the internal KOrganizer |
36 | representation as Calendar and Events. | 36 | representation as Calendar and Events. |
37 | 37 | ||
38 | @short iCalendar format implementation | 38 | @short iCalendar format implementation |
39 | */ | 39 | */ |
40 | class ICalFormat : public CalFormat { | 40 | class ICalFormat : public CalFormat { |
41 | public: | 41 | public: |
42 | /** Create new iCalendar format. */ | 42 | /** Create new iCalendar format. */ |
43 | ICalFormat( ); | 43 | ICalFormat( bool pe = true); |
44 | virtual ~ICalFormat(); | 44 | virtual ~ICalFormat(); |
45 | 45 | ||
46 | /** | 46 | /** |
47 | Loads a calendar on disk in iCalendar format into calendar. | 47 | Loads a calendar on disk in iCalendar format into calendar. |
48 | Returns true if successful, else returns false. Provides more error | 48 | Returns true if successful, else returns false. Provides more error |
49 | information by exception(). | 49 | information by exception(). |
50 | @param calendar Calendar object to be filled. | 50 | @param calendar Calendar object to be filled. |
51 | @param fileName The name of the calendar file on disk. | 51 | @param fileName The name of the calendar file on disk. |
52 | */ | 52 | */ |
53 | bool load( Calendar *, const QString &fileName ); | 53 | bool load( Calendar *, const QString &fileName ); |
54 | /** | 54 | /** |
55 | Writes out the calendar to disk in iCalendar format. Returns true if | 55 | Writes out the calendar to disk in iCalendar format. Returns true if |
56 | successful and false on error. | 56 | successful and false on error. |
57 | 57 | ||
58 | @param calendar The Calendar object to be written. | 58 | @param calendar The Calendar object to be written. |
59 | @param fileName The name of the calendar file on disk. | 59 | @param fileName The name of the calendar file on disk. |
60 | */ | 60 | */ |
61 | bool save( Calendar *, const QString &fileName ); | 61 | bool save( Calendar *, const QString &fileName ); |
62 | 62 | ||
63 | /** | 63 | /** |
64 | Parse string and populate calendar with that information. | 64 | Parse string and populate calendar with that information. |
65 | */ | 65 | */ |
66 | bool fromString( Calendar *, const QString & ); | 66 | bool fromString( Calendar *, const QString & ); |
67 | /** | 67 | /** |
68 | Parse string and return first ical component. | 68 | Parse string and return first ical component. |
69 | */ | 69 | */ |
70 | Incidence *fromString( const QString & ); | 70 | Incidence *fromString( const QString & ); |
71 | /** | 71 | /** |
72 | Return calendar information as string. | 72 | Return calendar information as string. |
73 | */ | 73 | */ |
74 | QString toString( Calendar * ); | 74 | QString toString( Calendar * ); |
75 | /** | 75 | /** |
76 | Return incidence as full iCalendar formatted text. | 76 | Return incidence as full iCalendar formatted text. |
77 | */ | 77 | */ |
78 | QString toICalString( Incidence * ); | 78 | QString toICalString( Incidence * ); |
79 | /** | 79 | /** |
80 | Return incidence as iCalendar formatted text. | 80 | Return incidence as iCalendar formatted text. |
81 | */ | 81 | */ |
82 | QString toString( Incidence * ); | 82 | QString toString( Incidence * ); |
83 | /** | 83 | /** |
84 | Return recurrence as iCalendar formatted text. | 84 | Return recurrence as iCalendar formatted text. |
85 | */ | 85 | */ |
86 | QString toString( Recurrence * ); | 86 | QString toString( Recurrence * ); |
87 | /** | 87 | /** |
88 | Parse string and fill recurrence object with | 88 | Parse string and fill recurrence object with |
89 | that information | 89 | that information |
90 | */ | 90 | */ |
91 | //bool fromString ( Recurrence *, const QString& ); | 91 | //bool fromString ( Recurrence *, const QString& ); |
92 | 92 | ||
93 | /** Create a scheduling message for event \a e using method \m */ | 93 | /** Create a scheduling message for event \a e using method \m */ |
94 | QString createScheduleMessage(IncidenceBase *e,Scheduler::Method m); | 94 | QString createScheduleMessage(IncidenceBase *e,Scheduler::Method m); |
95 | /** Parse scheduling message provided as string \s */ | 95 | /** Parse scheduling message provided as string \s */ |
96 | ScheduleMessage *parseScheduleMessage( Calendar *, const QString &s); | 96 | ScheduleMessage *parseScheduleMessage( Calendar *, const QString &s); |
97 | 97 | ||
98 | /** Set id of used time zone and whether this time zone is UTC or not. */ | 98 | /** Set id of used time zone and whether this time zone is UTC or not. */ |
99 | void setTimeZone( const QString &id, bool utc ); | 99 | void setTimeZone( const QString &id, bool utc ); |
100 | QString timeZoneId() const; | 100 | QString timeZoneId() const; |
101 | int timeOffset(); | 101 | int timeOffset(); |
102 | const char * tzString(); | 102 | const char * tzString(); |
103 | bool utc() const; | 103 | bool utc() const; |
104 | 104 | ||
105 | private: | 105 | private: |
106 | bool mProcessEvents; | ||
106 | ICalFormatImpl *mImpl; | 107 | ICalFormatImpl *mImpl; |
107 | QString mTimeZoneId; | 108 | QString mTimeZoneId; |
108 | QCString mTzString; | 109 | QCString mTzString; |
109 | int tzOffsetMin; | 110 | int tzOffsetMin; |
110 | bool mUtc; | 111 | bool mUtc; |
111 | }; | 112 | }; |
112 | 113 | ||
113 | } | 114 | } |
114 | 115 | ||
115 | #endif | 116 | #endif |
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 4ada2d8..7bf756a 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp | |||
@@ -1,615 +1,616 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library 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 GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <kglobal.h> | 21 | #include <kglobal.h> |
22 | #include <kglobalsettings.h> | 22 | #include <kglobalsettings.h> |
23 | #include <klocale.h> | 23 | #include <klocale.h> |
24 | #include <kdebug.h> | 24 | #include <kdebug.h> |
25 | #include <qregexp.h> | 25 | #include <qregexp.h> |
26 | #include <qfileinfo.h> | 26 | #include <qfileinfo.h> |
27 | 27 | ||
28 | #include "calendarlocal.h" | 28 | #include "calendarlocal.h" |
29 | #include "icalformat.h" | 29 | #include "icalformat.h" |
30 | #include "todo.h" | 30 | #include "todo.h" |
31 | 31 | ||
32 | using namespace KCal; | 32 | using namespace KCal; |
33 | 33 | ||
34 | Todo::Todo(): QObject(), Incidence() | 34 | Todo::Todo(): QObject(), Incidence() |
35 | { | 35 | { |
36 | // mStatus = TENTATIVE; | 36 | // mStatus = TENTATIVE; |
37 | 37 | ||
38 | mHasDueDate = false; | 38 | mHasDueDate = false; |
39 | setHasStartDate( false ); | 39 | setHasStartDate( false ); |
40 | mCompleted = getEvenTime(QDateTime::currentDateTime()); | 40 | mCompleted = getEvenTime(QDateTime::currentDateTime()); |
41 | mHasCompletedDate = false; | 41 | mHasCompletedDate = false; |
42 | mPercentComplete = 0; | 42 | mPercentComplete = 0; |
43 | mRunning = false; | 43 | mRunning = false; |
44 | mRunSaveTimer = 0; | 44 | mRunSaveTimer = 0; |
45 | } | 45 | } |
46 | 46 | ||
47 | Todo::Todo(const Todo &t) : QObject(),Incidence(t) | 47 | Todo::Todo(const Todo &t) : QObject(),Incidence(t) |
48 | { | 48 | { |
49 | mDtDue = t.mDtDue; | 49 | mDtDue = t.mDtDue; |
50 | mHasDueDate = t.mHasDueDate; | 50 | mHasDueDate = t.mHasDueDate; |
51 | mCompleted = t.mCompleted; | 51 | mCompleted = t.mCompleted; |
52 | mHasCompletedDate = t.mHasCompletedDate; | 52 | mHasCompletedDate = t.mHasCompletedDate; |
53 | mPercentComplete = t.mPercentComplete; | 53 | mPercentComplete = t.mPercentComplete; |
54 | mRunning = false; | 54 | mRunning = false; |
55 | mRunSaveTimer = 0; | 55 | mRunSaveTimer = 0; |
56 | } | 56 | } |
57 | 57 | ||
58 | Todo::~Todo() | 58 | Todo::~Todo() |
59 | { | 59 | { |
60 | setRunning( false ); | 60 | setRunning( false ); |
61 | //qDebug("Todo::~Todo() "); | 61 | //qDebug("Todo::~Todo() "); |
62 | } | 62 | } |
63 | 63 | ||
64 | void Todo::setRunningFalse( QString s ) | 64 | void Todo::setRunningFalse( QString s ) |
65 | { | 65 | { |
66 | if ( ! mRunning ) | 66 | if ( ! mRunning ) |
67 | return; | 67 | return; |
68 | mRunning = false; | 68 | mRunning = false; |
69 | mRunSaveTimer->stop(); | 69 | if ( mRunSaveTimer ) |
70 | mRunSaveTimer->stop(); | ||
70 | saveRunningInfoToFile( s ); | 71 | saveRunningInfoToFile( s ); |
71 | } | 72 | } |
72 | void Todo::stopRunning() | 73 | void Todo::stopRunning() |
73 | { | 74 | { |
74 | if ( !mRunning ) | 75 | if ( !mRunning ) |
75 | return; | 76 | return; |
76 | if ( mRunSaveTimer ) | 77 | if ( mRunSaveTimer ) |
77 | mRunSaveTimer->stop(); | 78 | mRunSaveTimer->stop(); |
78 | mRunning = false; | 79 | mRunning = false; |
79 | } | 80 | } |
80 | void Todo::setRunning( bool run ) | 81 | void Todo::setRunning( bool run ) |
81 | { | 82 | { |
82 | if ( run == mRunning ) | 83 | if ( run == mRunning ) |
83 | return; | 84 | return; |
84 | //qDebug("Todo::setRunning %d ", run); | 85 | //qDebug("Todo::setRunning %d ", run); |
85 | if ( !mRunSaveTimer ) { | 86 | if ( !mRunSaveTimer ) { |
86 | mRunSaveTimer = new QTimer ( this ); | 87 | mRunSaveTimer = new QTimer ( this ); |
87 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); | 88 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); |
88 | } | 89 | } |
89 | mRunning = run; | 90 | mRunning = run; |
90 | if ( mRunning ) { | 91 | if ( mRunning ) { |
91 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min | 92 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min |
92 | mRunStart = QDateTime::currentDateTime(); | 93 | mRunStart = QDateTime::currentDateTime(); |
93 | } else { | 94 | } else { |
94 | mRunSaveTimer->stop(); | 95 | mRunSaveTimer->stop(); |
95 | saveRunningInfoToFile(); | 96 | saveRunningInfoToFile(); |
96 | } | 97 | } |
97 | } | 98 | } |
98 | void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) | 99 | void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) |
99 | { | 100 | { |
100 | if ( !mRunning) return; | 101 | if ( !mRunning) return; |
101 | mRunning = false; | 102 | mRunning = false; |
102 | mRunStart = start; | 103 | mRunStart = start; |
103 | mRunEnd = end; | 104 | mRunEnd = end; |
104 | saveRunningInfoToFile( comment ); | 105 | saveRunningInfoToFile( comment ); |
105 | } | 106 | } |
106 | void Todo::saveRunningInfoToFile() | 107 | void Todo::saveRunningInfoToFile() |
107 | { | 108 | { |
108 | mRunEnd = QDateTime::currentDateTime(); | 109 | mRunEnd = QDateTime::currentDateTime(); |
109 | saveRunningInfoToFile( QString::null ); | 110 | saveRunningInfoToFile( QString::null ); |
110 | } | 111 | } |
111 | void Todo::saveRunningInfoToFile( QString comment ) | 112 | void Todo::saveRunningInfoToFile( QString comment ) |
112 | { | 113 | { |
113 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); | 114 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); |
114 | if ( mRunStart.secsTo ( mRunEnd) < 15 ) { | 115 | if ( mRunStart.secsTo ( mRunEnd) < 15 ) { |
115 | qDebug("Running time < 15 seconds. Skipped. "); | 116 | qDebug("Running time < 15 seconds. Skipped. "); |
116 | return; | 117 | return; |
117 | } | 118 | } |
118 | QString dir = KGlobalSettings::timeTrackerDir(); | 119 | QString dir = KGlobalSettings::timeTrackerDir(); |
119 | //qDebug("%s ", dir.latin1()); | 120 | //qDebug("%s ", dir.latin1()); |
120 | QString file = "%1%2%3-%4%5%6-"; | 121 | QString file = "%1%2%3-%4%5%6-"; |
121 | file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 ); | 122 | file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 ); |
122 | file.replace ( QRegExp (" "), "0" ); | 123 | file.replace ( QRegExp (" "), "0" ); |
123 | file += uid(); | 124 | file += uid(); |
124 | //qDebug("File %s ",file.latin1() ); | 125 | //qDebug("File %s ",file.latin1() ); |
125 | CalendarLocal cal; | 126 | CalendarLocal cal; |
126 | cal.setLocalTime(); | 127 | cal.setLocalTime(); |
127 | Todo * to = (Todo*) clone(); | 128 | Todo * to = (Todo*) clone(); |
128 | to->setFloats( false ); | 129 | to->setFloats( false ); |
129 | to->setDtStart( mRunStart ); | 130 | to->setDtStart( mRunStart ); |
130 | to->setHasStartDate( true ); | 131 | to->setHasStartDate( true ); |
131 | to->setDtDue( mRunEnd ); | 132 | to->setDtDue( mRunEnd ); |
132 | to->setHasDueDate( true ); | 133 | to->setHasDueDate( true ); |
133 | to->setUid( file ); | 134 | to->setUid( file ); |
134 | if ( !comment.isEmpty() ) { | 135 | if ( !comment.isEmpty() ) { |
135 | QString des = to->description(); | 136 | QString des = to->description(); |
136 | if ( des.isEmpty () ) | 137 | if ( des.isEmpty () ) |
137 | to->setDescription( "TT-Note: " + comment ); | 138 | to->setDescription( "TT-Note: " + comment ); |
138 | else | 139 | else |
139 | to->setDescription( "TT-Note: " + comment +"\n" + des ); | 140 | to->setDescription( "TT-Note: " + comment +"\n" + des ); |
140 | } | 141 | } |
141 | cal.addIncidence( to ); | 142 | cal.addIncidence( to ); |
142 | ICalFormat format; | 143 | ICalFormat format( false ); |
143 | file = dir +"/" +file +".ics"; | 144 | file = dir +"/" +file +".ics"; |
144 | format.save( &cal, file ); | 145 | format.save( &cal, file ); |
145 | saveParents(); | 146 | saveParents(); |
146 | 147 | ||
147 | } | 148 | } |
148 | void Todo::saveParents() | 149 | void Todo::saveParents() |
149 | { | 150 | { |
150 | if (!relatedTo() ) | 151 | if (!relatedTo() ) |
151 | return; | 152 | return; |
152 | Incidence * inc = relatedTo(); | 153 | Incidence * inc = relatedTo(); |
153 | if ( inc->typeID() != todoID ) | 154 | if ( inc->typeID() != todoID ) |
154 | return; | 155 | return; |
155 | Todo* to = (Todo*)inc; | 156 | Todo* to = (Todo*)inc; |
156 | bool saveTodo = false; | 157 | bool saveTodo = false; |
157 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; | 158 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; |
158 | QFileInfo fi ( file ); | 159 | QFileInfo fi ( file ); |
159 | if ( fi.exists() ) { | 160 | if ( fi.exists() ) { |
160 | if ( fi.lastModified () < to->lastModified ()) | 161 | if ( fi.lastModified () < to->lastModified ()) |
161 | saveTodo = true; | 162 | saveTodo = true; |
162 | } else { | 163 | } else { |
163 | saveTodo = true; | 164 | saveTodo = true; |
164 | } | 165 | } |
165 | if ( saveTodo ) { | 166 | if ( saveTodo ) { |
166 | CalendarLocal cal; | 167 | CalendarLocal cal; |
167 | cal.setLocalTime(); | 168 | cal.setLocalTime(); |
168 | Todo * par = (Todo *) to->clone(); | 169 | Todo * par = (Todo *) to->clone(); |
169 | cal.addIncidence( par ); | 170 | cal.addIncidence( par ); |
170 | ICalFormat format; | 171 | ICalFormat format( false ); |
171 | format.save( &cal, file ); | 172 | format.save( &cal, file ); |
172 | } | 173 | } |
173 | to->saveParents(); | 174 | to->saveParents(); |
174 | } | 175 | } |
175 | 176 | ||
176 | int Todo::runTime() | 177 | int Todo::runTime() |
177 | { | 178 | { |
178 | if ( !mRunning ) | 179 | if ( !mRunning ) |
179 | return 0; | 180 | return 0; |
180 | return mRunStart.secsTo( QDateTime::currentDateTime() ); | 181 | return mRunStart.secsTo( QDateTime::currentDateTime() ); |
181 | } | 182 | } |
182 | bool Todo::hasRunningSub() | 183 | bool Todo::hasRunningSub() |
183 | { | 184 | { |
184 | if ( mRunning ) | 185 | if ( mRunning ) |
185 | return true; | 186 | return true; |
186 | Incidence *aTodo; | 187 | Incidence *aTodo; |
187 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 188 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
188 | if ( ((Todo*)aTodo)->hasRunningSub() ) | 189 | if ( ((Todo*)aTodo)->hasRunningSub() ) |
189 | return true; | 190 | return true; |
190 | } | 191 | } |
191 | return false; | 192 | return false; |
192 | } | 193 | } |
193 | Incidence *Todo::clone() | 194 | Incidence *Todo::clone() |
194 | { | 195 | { |
195 | return new Todo(*this); | 196 | return new Todo(*this); |
196 | } | 197 | } |
197 | 198 | ||
198 | bool Todo::contains ( Todo* from ) | 199 | bool Todo::contains ( Todo* from ) |
199 | { | 200 | { |
200 | 201 | ||
201 | if ( !from->summary().isEmpty() ) | 202 | if ( !from->summary().isEmpty() ) |
202 | if ( !summary().startsWith( from->summary() )) | 203 | if ( !summary().startsWith( from->summary() )) |
203 | return false; | 204 | return false; |
204 | if ( from->hasStartDate() ) { | 205 | if ( from->hasStartDate() ) { |
205 | if ( !hasStartDate() ) | 206 | if ( !hasStartDate() ) |
206 | return false; | 207 | return false; |
207 | if ( from->dtStart() != dtStart()) | 208 | if ( from->dtStart() != dtStart()) |
208 | return false; | 209 | return false; |
209 | } | 210 | } |
210 | if ( from->hasDueDate() ){ | 211 | if ( from->hasDueDate() ){ |
211 | if ( !hasDueDate() ) | 212 | if ( !hasDueDate() ) |
212 | return false; | 213 | return false; |
213 | if ( from->dtDue() != dtDue()) | 214 | if ( from->dtDue() != dtDue()) |
214 | return false; | 215 | return false; |
215 | } | 216 | } |
216 | if ( !from->location().isEmpty() ) | 217 | if ( !from->location().isEmpty() ) |
217 | if ( !location().startsWith( from->location() ) ) | 218 | if ( !location().startsWith( from->location() ) ) |
218 | return false; | 219 | return false; |
219 | if ( !from->description().isEmpty() ) | 220 | if ( !from->description().isEmpty() ) |
220 | if ( !description().startsWith( from->description() )) | 221 | if ( !description().startsWith( from->description() )) |
221 | return false; | 222 | return false; |
222 | if ( from->alarms().count() ) { | 223 | if ( from->alarms().count() ) { |
223 | Alarm *a = from->alarms().first(); | 224 | Alarm *a = from->alarms().first(); |
224 | if ( a->enabled() ){ | 225 | if ( a->enabled() ){ |
225 | if ( !alarms().count() ) | 226 | if ( !alarms().count() ) |
226 | return false; | 227 | return false; |
227 | Alarm *b = alarms().first(); | 228 | Alarm *b = alarms().first(); |
228 | if( ! b->enabled() ) | 229 | if( ! b->enabled() ) |
229 | return false; | 230 | return false; |
230 | if ( ! (a->offset() == b->offset() )) | 231 | if ( ! (a->offset() == b->offset() )) |
231 | return false; | 232 | return false; |
232 | } | 233 | } |
233 | } | 234 | } |
234 | 235 | ||
235 | QStringList cat = categories(); | 236 | QStringList cat = categories(); |
236 | QStringList catFrom = from->categories(); | 237 | QStringList catFrom = from->categories(); |
237 | QString nCat; | 238 | QString nCat; |
238 | unsigned int iii; | 239 | unsigned int iii; |
239 | for ( iii = 0; iii < catFrom.count();++iii ) { | 240 | for ( iii = 0; iii < catFrom.count();++iii ) { |
240 | nCat = catFrom[iii]; | 241 | nCat = catFrom[iii]; |
241 | if ( !nCat.isEmpty() ) | 242 | if ( !nCat.isEmpty() ) |
242 | if ( !cat.contains( nCat )) { | 243 | if ( !cat.contains( nCat )) { |
243 | return false; | 244 | return false; |
244 | } | 245 | } |
245 | } | 246 | } |
246 | if ( from->isCompleted() ) { | 247 | if ( from->isCompleted() ) { |
247 | if ( !isCompleted() ) | 248 | if ( !isCompleted() ) |
248 | return false; | 249 | return false; |
249 | } | 250 | } |
250 | if( priority() != from->priority() ) | 251 | if( priority() != from->priority() ) |
251 | return false; | 252 | return false; |
252 | 253 | ||
253 | 254 | ||
254 | return true; | 255 | return true; |
255 | 256 | ||
256 | } | 257 | } |
257 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) | 258 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) |
258 | { | 259 | { |
259 | 260 | ||
260 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); | 261 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); |
261 | if ( ! ret ) | 262 | if ( ! ret ) |
262 | return false; | 263 | return false; |
263 | if ( t1.hasDueDate() == t2.hasDueDate() ) { | 264 | if ( t1.hasDueDate() == t2.hasDueDate() ) { |
264 | if ( t1.hasDueDate() ) { | 265 | if ( t1.hasDueDate() ) { |
265 | if ( t1.doesFloat() == t2.doesFloat() ) { | 266 | if ( t1.doesFloat() == t2.doesFloat() ) { |
266 | if ( t1.doesFloat() ) { | 267 | if ( t1.doesFloat() ) { |
267 | if ( t1.dtDue().date() != t2.dtDue().date() ) | 268 | if ( t1.dtDue().date() != t2.dtDue().date() ) |
268 | return false; | 269 | return false; |
269 | } else | 270 | } else |
270 | if ( t1.dtDue() != t2.dtDue() ) | 271 | if ( t1.dtDue() != t2.dtDue() ) |
271 | return false; | 272 | return false; |
272 | } else | 273 | } else |
273 | return false;// float != | 274 | return false;// float != |
274 | } | 275 | } |
275 | 276 | ||
276 | } else | 277 | } else |
277 | return false; | 278 | return false; |
278 | if ( t1.percentComplete() != t2.percentComplete() ) | 279 | if ( t1.percentComplete() != t2.percentComplete() ) |
279 | return false; | 280 | return false; |
280 | if ( t1.isCompleted() ) { | 281 | if ( t1.isCompleted() ) { |
281 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { | 282 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { |
282 | if ( t1.hasCompletedDate() ) { | 283 | if ( t1.hasCompletedDate() ) { |
283 | if ( t1.completed() != t2.completed() ) | 284 | if ( t1.completed() != t2.completed() ) |
284 | return false; | 285 | return false; |
285 | } | 286 | } |
286 | 287 | ||
287 | } else | 288 | } else |
288 | return false; | 289 | return false; |
289 | } | 290 | } |
290 | return true; | 291 | return true; |
291 | 292 | ||
292 | } | 293 | } |
293 | 294 | ||
294 | void Todo::setDtDue(const QDateTime &dtDue) | 295 | void Todo::setDtDue(const QDateTime &dtDue) |
295 | { | 296 | { |
296 | //int diffsecs = mDtDue.secsTo(dtDue); | 297 | //int diffsecs = mDtDue.secsTo(dtDue); |
297 | 298 | ||
298 | /*if (mReadOnly) return; | 299 | /*if (mReadOnly) return; |
299 | const QPtrList<Alarm>& alarms = alarms(); | 300 | const QPtrList<Alarm>& alarms = alarms(); |
300 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { | 301 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { |
301 | if (alarm->enabled()) { | 302 | if (alarm->enabled()) { |
302 | alarm->setTime(alarm->time().addSecs(diffsecs)); | 303 | alarm->setTime(alarm->time().addSecs(diffsecs)); |
303 | } | 304 | } |
304 | }*/ | 305 | }*/ |
305 | mDtDue = getEvenTime(dtDue); | 306 | mDtDue = getEvenTime(dtDue); |
306 | 307 | ||
307 | //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; | 308 | //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; |
308 | 309 | ||
309 | /*const QPtrList<Alarm>& alarms = alarms(); | 310 | /*const QPtrList<Alarm>& alarms = alarms(); |
310 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) | 311 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) |
311 | alarm->setAlarmStart(mDtDue);*/ | 312 | alarm->setAlarmStart(mDtDue);*/ |
312 | updated(); | 313 | updated(); |
313 | } | 314 | } |
314 | 315 | ||
315 | QDateTime Todo::dtDue() const | 316 | QDateTime Todo::dtDue() const |
316 | { | 317 | { |
317 | return mDtDue; | 318 | return mDtDue; |
318 | } | 319 | } |
319 | 320 | ||
320 | QString Todo::dtDueTimeStr() const | 321 | QString Todo::dtDueTimeStr() const |
321 | { | 322 | { |
322 | return KGlobal::locale()->formatTime(mDtDue.time()); | 323 | return KGlobal::locale()->formatTime(mDtDue.time()); |
323 | } | 324 | } |
324 | 325 | ||
325 | QString Todo::dtDueDateStr(bool shortfmt) const | 326 | QString Todo::dtDueDateStr(bool shortfmt) const |
326 | { | 327 | { |
327 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); | 328 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); |
328 | } | 329 | } |
329 | 330 | ||
330 | QString Todo::dtDueStr(bool shortfmt) const | 331 | QString Todo::dtDueStr(bool shortfmt) const |
331 | { | 332 | { |
332 | if ( doesFloat() ) | 333 | if ( doesFloat() ) |
333 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); | 334 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); |
334 | return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); | 335 | return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); |
335 | } | 336 | } |
336 | // retval 0 : no found | 337 | // retval 0 : no found |
337 | // 1 : due for date found | 338 | // 1 : due for date found |
338 | // 2 : overdue for date found | 339 | // 2 : overdue for date found |
339 | int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) | 340 | int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) |
340 | { | 341 | { |
341 | int retval = 0; | 342 | int retval = 0; |
342 | if ( isCompleted() ) | 343 | if ( isCompleted() ) |
343 | return 0; | 344 | return 0; |
344 | if ( hasDueDate() ) { | 345 | if ( hasDueDate() ) { |
345 | if ( dtDue().date() < date ) | 346 | if ( dtDue().date() < date ) |
346 | return 2; | 347 | return 2; |
347 | // we do not return, because we may find an overdue sub todo | 348 | // we do not return, because we may find an overdue sub todo |
348 | if ( dtDue().date() == date ) | 349 | if ( dtDue().date() == date ) |
349 | retval = 1; | 350 | retval = 1; |
350 | } | 351 | } |
351 | if ( checkSubtodos ) { | 352 | if ( checkSubtodos ) { |
352 | Incidence *aTodo; | 353 | Incidence *aTodo; |
353 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 354 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
354 | int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); | 355 | int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); |
355 | if ( ret == 2 ) | 356 | if ( ret == 2 ) |
356 | return 2; | 357 | return 2; |
357 | if ( ret == 1) | 358 | if ( ret == 1) |
358 | retval = 1; | 359 | retval = 1; |
359 | } | 360 | } |
360 | } | 361 | } |
361 | return retval; | 362 | return retval; |
362 | } | 363 | } |
363 | int Todo::hasDueSubTodo( bool checkSubtodos ) //= true | 364 | int Todo::hasDueSubTodo( bool checkSubtodos ) //= true |
364 | { | 365 | { |
365 | return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); | 366 | return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); |
366 | } | 367 | } |
367 | bool Todo::hasDueDate() const | 368 | bool Todo::hasDueDate() const |
368 | { | 369 | { |
369 | return mHasDueDate; | 370 | return mHasDueDate; |
370 | } | 371 | } |
371 | 372 | ||
372 | void Todo::setHasDueDate(bool f) | 373 | void Todo::setHasDueDate(bool f) |
373 | { | 374 | { |
374 | if (mReadOnly) return; | 375 | if (mReadOnly) return; |
375 | mHasDueDate = f; | 376 | mHasDueDate = f; |
376 | updated(); | 377 | updated(); |
377 | } | 378 | } |
378 | 379 | ||
379 | 380 | ||
380 | #if 0 | 381 | #if 0 |
381 | void Todo::setStatus(const QString &statStr) | 382 | void Todo::setStatus(const QString &statStr) |
382 | { | 383 | { |
383 | if (mReadOnly) return; | 384 | if (mReadOnly) return; |
384 | QString ss(statStr.upper()); | 385 | QString ss(statStr.upper()); |
385 | 386 | ||
386 | if (ss == "X-ACTION") | 387 | if (ss == "X-ACTION") |
387 | mStatus = NEEDS_ACTION; | 388 | mStatus = NEEDS_ACTION; |
388 | else if (ss == "NEEDS ACTION") | 389 | else if (ss == "NEEDS ACTION") |
389 | mStatus = NEEDS_ACTION; | 390 | mStatus = NEEDS_ACTION; |
390 | else if (ss == "ACCEPTED") | 391 | else if (ss == "ACCEPTED") |
391 | mStatus = ACCEPTED; | 392 | mStatus = ACCEPTED; |
392 | else if (ss == "SENT") | 393 | else if (ss == "SENT") |
393 | mStatus = SENT; | 394 | mStatus = SENT; |
394 | else if (ss == "TENTATIVE") | 395 | else if (ss == "TENTATIVE") |
395 | mStatus = TENTATIVE; | 396 | mStatus = TENTATIVE; |
396 | else if (ss == "CONFIRMED") | 397 | else if (ss == "CONFIRMED") |
397 | mStatus = CONFIRMED; | 398 | mStatus = CONFIRMED; |
398 | else if (ss == "DECLINED") | 399 | else if (ss == "DECLINED") |
399 | mStatus = DECLINED; | 400 | mStatus = DECLINED; |
400 | else if (ss == "COMPLETED") | 401 | else if (ss == "COMPLETED") |
401 | mStatus = COMPLETED; | 402 | mStatus = COMPLETED; |
402 | else if (ss == "DELEGATED") | 403 | else if (ss == "DELEGATED") |
403 | mStatus = DELEGATED; | 404 | mStatus = DELEGATED; |
404 | 405 | ||
405 | updated(); | 406 | updated(); |
406 | } | 407 | } |
407 | 408 | ||
408 | void Todo::setStatus(int status) | 409 | void Todo::setStatus(int status) |
409 | { | 410 | { |
410 | if (mReadOnly) return; | 411 | if (mReadOnly) return; |
411 | mStatus = status; | 412 | mStatus = status; |
412 | updated(); | 413 | updated(); |
413 | } | 414 | } |
414 | 415 | ||
415 | int Todo::status() const | 416 | int Todo::status() const |
416 | { | 417 | { |
417 | return mStatus; | 418 | return mStatus; |
418 | } | 419 | } |
419 | 420 | ||
420 | QString Todo::statusStr() const | 421 | QString Todo::statusStr() const |
421 | { | 422 | { |
422 | switch(mStatus) { | 423 | switch(mStatus) { |
423 | case NEEDS_ACTION: | 424 | case NEEDS_ACTION: |
424 | return QString("NEEDS ACTION"); | 425 | return QString("NEEDS ACTION"); |
425 | break; | 426 | break; |
426 | case ACCEPTED: | 427 | case ACCEPTED: |
427 | return QString("ACCEPTED"); | 428 | return QString("ACCEPTED"); |
428 | break; | 429 | break; |
429 | case SENT: | 430 | case SENT: |
430 | return QString("SENT"); | 431 | return QString("SENT"); |
431 | break; | 432 | break; |
432 | case TENTATIVE: | 433 | case TENTATIVE: |
433 | return QString("TENTATIVE"); | 434 | return QString("TENTATIVE"); |
434 | break; | 435 | break; |
435 | case CONFIRMED: | 436 | case CONFIRMED: |
436 | return QString("CONFIRMED"); | 437 | return QString("CONFIRMED"); |
437 | break; | 438 | break; |
438 | case DECLINED: | 439 | case DECLINED: |
439 | return QString("DECLINED"); | 440 | return QString("DECLINED"); |
440 | break; | 441 | break; |
441 | case COMPLETED: | 442 | case COMPLETED: |
442 | return QString("COMPLETED"); | 443 | return QString("COMPLETED"); |
443 | break; | 444 | break; |
444 | case DELEGATED: | 445 | case DELEGATED: |
445 | return QString("DELEGATED"); | 446 | return QString("DELEGATED"); |
446 | break; | 447 | break; |
447 | } | 448 | } |
448 | return QString(""); | 449 | return QString(""); |
449 | } | 450 | } |
450 | #endif | 451 | #endif |
451 | 452 | ||
452 | bool Todo::isCompleted() const | 453 | bool Todo::isCompleted() const |
453 | { | 454 | { |
454 | if (mPercentComplete == 100) { | 455 | if (mPercentComplete == 100) { |
455 | return true; | 456 | return true; |
456 | } | 457 | } |
457 | else return false; | 458 | else return false; |
458 | } | 459 | } |
459 | 460 | ||
460 | void Todo::setCompleted(bool completed) | 461 | void Todo::setCompleted(bool completed) |
461 | { | 462 | { |
462 | if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { | 463 | if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { |
463 | if ( !setRecurDates() ) | 464 | if ( !setRecurDates() ) |
464 | completed = false; | 465 | completed = false; |
465 | } | 466 | } |
466 | if (completed) mPercentComplete = 100; | 467 | if (completed) mPercentComplete = 100; |
467 | else { | 468 | else { |
468 | mPercentComplete = 0; | 469 | mPercentComplete = 0; |
469 | mHasCompletedDate = false; | 470 | mHasCompletedDate = false; |
470 | } | 471 | } |
471 | updated(); | 472 | updated(); |
472 | } | 473 | } |
473 | 474 | ||
474 | QDateTime Todo::completed() const | 475 | QDateTime Todo::completed() const |
475 | { | 476 | { |
476 | return mCompleted; | 477 | return mCompleted; |
477 | } | 478 | } |
478 | 479 | ||
479 | QString Todo::completedStr( bool shortF ) const | 480 | QString Todo::completedStr( bool shortF ) const |
480 | { | 481 | { |
481 | return KGlobal::locale()->formatDateTime(mCompleted, shortF); | 482 | return KGlobal::locale()->formatDateTime(mCompleted, shortF); |
482 | } | 483 | } |
483 | 484 | ||
484 | void Todo::setCompleted(const QDateTime &completed) | 485 | void Todo::setCompleted(const QDateTime &completed) |
485 | { | 486 | { |
486 | //qDebug("Todo::setCompleted "); | 487 | //qDebug("Todo::setCompleted "); |
487 | if ( mHasCompletedDate ) { | 488 | if ( mHasCompletedDate ) { |
488 | // qDebug("has completed data - return "); | 489 | // qDebug("has completed data - return "); |
489 | return; | 490 | return; |
490 | } | 491 | } |
491 | mHasCompletedDate = true; | 492 | mHasCompletedDate = true; |
492 | mPercentComplete = 100; | 493 | mPercentComplete = 100; |
493 | mCompleted = getEvenTime(completed); | 494 | mCompleted = getEvenTime(completed); |
494 | updated(); | 495 | updated(); |
495 | } | 496 | } |
496 | 497 | ||
497 | bool Todo::hasCompletedDate() const | 498 | bool Todo::hasCompletedDate() const |
498 | { | 499 | { |
499 | return mHasCompletedDate; | 500 | return mHasCompletedDate; |
500 | } | 501 | } |
501 | 502 | ||
502 | int Todo::percentComplete() const | 503 | int Todo::percentComplete() const |
503 | { | 504 | { |
504 | return mPercentComplete; | 505 | return mPercentComplete; |
505 | } | 506 | } |
506 | bool Todo::setRecurDates() | 507 | bool Todo::setRecurDates() |
507 | { | 508 | { |
508 | if ( !mHasRecurrenceID ) | 509 | if ( !mHasRecurrenceID ) |
509 | return true; | 510 | return true; |
510 | int secs = mDtStart.secsTo( dtDue() ); | 511 | int secs = mDtStart.secsTo( dtDue() ); |
511 | bool ok; | 512 | bool ok; |
512 | qDebug("T:setRecurDates() "); | 513 | qDebug("T:setRecurDates() "); |
513 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); | 514 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); |
514 | QDateTime next = getNextOccurence( mRecurrenceID, &ok ); | 515 | QDateTime next = getNextOccurence( mRecurrenceID, &ok ); |
515 | if ( ok ) { | 516 | if ( ok ) { |
516 | mRecurrenceID = next; | 517 | mRecurrenceID = next; |
517 | mDtStart = next; | 518 | mDtStart = next; |
518 | setDtDue( next.addSecs( secs ) ); | 519 | setDtDue( next.addSecs( secs ) ); |
519 | if ( QDateTime::currentDateTime() > next) | 520 | if ( QDateTime::currentDateTime() > next) |
520 | return false; | 521 | return false; |
521 | } else { | 522 | } else { |
522 | setHasRecurrenceID( false ); | 523 | setHasRecurrenceID( false ); |
523 | recurrence()->unsetRecurs(); | 524 | recurrence()->unsetRecurs(); |
524 | } | 525 | } |
525 | return true; | 526 | return true; |
526 | } | 527 | } |
527 | void Todo::setPercentComplete(int v) | 528 | void Todo::setPercentComplete(int v) |
528 | { | 529 | { |
529 | if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { | 530 | if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { |
530 | if ( !setRecurDates() ) | 531 | if ( !setRecurDates() ) |
531 | v = 0; | 532 | v = 0; |
532 | } | 533 | } |
533 | mPercentComplete = v; | 534 | mPercentComplete = v; |
534 | if ( v != 100 ) | 535 | if ( v != 100 ) |
535 | mHasCompletedDate = false; | 536 | mHasCompletedDate = false; |
536 | updated(); | 537 | updated(); |
537 | } | 538 | } |
538 | QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const | 539 | QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const |
539 | { | 540 | { |
540 | *ok = false; | 541 | *ok = false; |
541 | if ( ! hasDueDate() || cancelled() || !alarmEnabled() ) { | 542 | if ( ! hasDueDate() || cancelled() || !alarmEnabled() ) { |
542 | return QDateTime (); | 543 | return QDateTime (); |
543 | } | 544 | } |
544 | // if the recurring todo is set to complete and requested time < start time of todo | 545 | // if the recurring todo is set to complete and requested time < start time of todo |
545 | // we want to get the alarm. | 546 | // we want to get the alarm. |
546 | bool iscompleted = isCompleted(); | 547 | bool iscompleted = isCompleted(); |
547 | if ( iscompleted && doesRecur() ) { | 548 | if ( iscompleted && doesRecur() ) { |
548 | Todo * to = (Todo*) this; | 549 | Todo * to = (Todo*) this; |
549 | to->checkSetCompletedFalse(); | 550 | to->checkSetCompletedFalse(); |
550 | iscompleted = isCompleted(); | 551 | iscompleted = isCompleted(); |
551 | if ( hasStartDate() && start_dt < dtStart() ){ | 552 | if ( hasStartDate() && start_dt < dtStart() ){ |
552 | iscompleted = false; | 553 | iscompleted = false; |
553 | } | 554 | } |
554 | } | 555 | } |
555 | if ( iscompleted ) { | 556 | if ( iscompleted ) { |
556 | return QDateTime (); | 557 | return QDateTime (); |
557 | } | 558 | } |
558 | QDateTime incidenceStart; | 559 | QDateTime incidenceStart; |
559 | incidenceStart = dtDue(); | 560 | incidenceStart = dtDue(); |
560 | bool enabled = false; | 561 | bool enabled = false; |
561 | Alarm* alarm; | 562 | Alarm* alarm; |
562 | int off = 0; | 563 | int off = 0; |
563 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; | 564 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; |
564 | // if ( QDateTime::currentDateTime() > incidenceStart ){ | 565 | // if ( QDateTime::currentDateTime() > incidenceStart ){ |
565 | // *ok = false; | 566 | // *ok = false; |
566 | // return incidenceStart; | 567 | // return incidenceStart; |
567 | // } | 568 | // } |
568 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 569 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
569 | if (alarm->enabled()) { | 570 | if (alarm->enabled()) { |
570 | if ( alarm->hasTime () ) { | 571 | if ( alarm->hasTime () ) { |
571 | if ( alarm->time() < alarmStart ) { | 572 | if ( alarm->time() < alarmStart ) { |
572 | alarmStart = alarm->time(); | 573 | alarmStart = alarm->time(); |
573 | enabled = true; | 574 | enabled = true; |
574 | off = alarmStart.secsTo( incidenceStart ); | 575 | off = alarmStart.secsTo( incidenceStart ); |
575 | } | 576 | } |
576 | 577 | ||
577 | } else { | 578 | } else { |
578 | int secs = alarm->startOffset().asSeconds(); | 579 | int secs = alarm->startOffset().asSeconds(); |
579 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { | 580 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { |
580 | alarmStart = incidenceStart.addSecs( secs ); | 581 | alarmStart = incidenceStart.addSecs( secs ); |
581 | enabled = true; | 582 | enabled = true; |
582 | off = -secs; | 583 | off = -secs; |
583 | } | 584 | } |
584 | } | 585 | } |
585 | } | 586 | } |
586 | } | 587 | } |
587 | if ( enabled ) { | 588 | if ( enabled ) { |
588 | if ( alarmStart > start_dt ) { | 589 | if ( alarmStart > start_dt ) { |
589 | *ok = true; | 590 | *ok = true; |
590 | * offset = off; | 591 | * offset = off; |
591 | return alarmStart; | 592 | return alarmStart; |
592 | } | 593 | } |
593 | } | 594 | } |
594 | *ok = false; | 595 | *ok = false; |
595 | return QDateTime (); | 596 | return QDateTime (); |
596 | 597 | ||
597 | } | 598 | } |
598 | 599 | ||
599 | void Todo::checkSetCompletedFalse() | 600 | void Todo::checkSetCompletedFalse() |
600 | { | 601 | { |
601 | if ( !mHasRecurrenceID ) { | 602 | if ( !mHasRecurrenceID ) { |
602 | qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); | 603 | qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); |
603 | return; | 604 | return; |
604 | } | 605 | } |
605 | // qDebug("Todo::checkSetCompletedFalse()"); | 606 | // qDebug("Todo::checkSetCompletedFalse()"); |
606 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); | 607 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); |
607 | if ( mPercentComplete == 100 ) { | 608 | if ( mPercentComplete == 100 ) { |
608 | QDateTime dt = QDateTime::currentDateTime(); | 609 | QDateTime dt = QDateTime::currentDateTime(); |
609 | if ( dt > mDtStart && dt > mRecurrenceID ) { | 610 | if ( dt > mDtStart && dt > mRecurrenceID ) { |
610 | qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); | 611 | qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); |
611 | setCompleted( false ); | 612 | setCompleted( false ); |
612 | qDebug("Todo::checkSetCompletedFalse "); | 613 | qDebug("Todo::checkSetCompletedFalse "); |
613 | } | 614 | } |
614 | } | 615 | } |
615 | } | 616 | } |