author | zautrix <zautrix> | 2005-01-31 16:29:05 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-01-31 16:29:05 (UTC) |
commit | ec037c4616342c1b3976c55db98b775f48e0d455 (patch) (unidiff) | |
tree | 9d568c8f6ad6005f822c12644596b7a553837c7f | |
parent | 5d52c81be9b43887c13f8534a04164d3b44b821f (diff) | |
download | kdepimpi-ec037c4616342c1b3976c55db98b775f48e0d455.zip kdepimpi-ec037c4616342c1b3976c55db98b775f48e0d455.tar.gz kdepimpi-ec037c4616342c1b3976c55db98b775f48e0d455.tar.bz2 |
fix
-rw-r--r-- | korganizer/komonthview.cpp | 165 | ||||
-rw-r--r-- | korganizer/komonthview.h | 5 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 1 | ||||
-rw-r--r-- | libkcal/incidence.cpp | 3 |
4 files changed, 146 insertions, 28 deletions
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp index 770a42b..6646b98 100644 --- a/korganizer/komonthview.cpp +++ b/korganizer/komonthview.cpp | |||
@@ -1,1156 +1,1269 @@ | |||
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 <qpushbutton.h> | 26 | #include <qpushbutton.h> |
27 | #include <qtooltip.h> | 27 | #include <qtooltip.h> |
28 | #include <qpainter.h> | 28 | #include <qpainter.h> |
29 | #include <qwhatsthis.h> | 29 | #include <qwhatsthis.h> |
30 | #ifndef DESKTOP_VERSION | 30 | #ifndef DESKTOP_VERSION |
31 | #include <qpe/qpeapplication.h> | 31 | #include <qpe/qpeapplication.h> |
32 | #else | 32 | #else |
33 | #include <qapplication.h> | 33 | #include <qapplication.h> |
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | #include <kdebug.h> | 36 | #include <kdebug.h> |
37 | #include <klocale.h> | 37 | #include <klocale.h> |
38 | #include <kglobal.h> | 38 | #include <kglobal.h> |
39 | #include <kconfig.h> | 39 | #include <kconfig.h> |
40 | #include <kiconloader.h> | 40 | #include <kiconloader.h> |
41 | 41 | ||
42 | #include <kcalendarsystem.h> | 42 | #include <kcalendarsystem.h> |
43 | 43 | ||
44 | #ifndef KORG_NOPRINTER | 44 | #ifndef KORG_NOPRINTER |
45 | #include "calprinter.h" | 45 | #include "calprinter.h" |
46 | #endif | 46 | #endif |
47 | #include "koprefs.h" | 47 | #include "koprefs.h" |
48 | #ifndef KORG_NOPLUGINS | 48 | #ifndef KORG_NOPLUGINS |
49 | #include "kocore.h" | 49 | #include "kocore.h" |
50 | #endif | 50 | #endif |
51 | #include "koglobals.h" | 51 | #include "koglobals.h" |
52 | #include <libkcal/kincidenceformatter.h> | 52 | #include <libkcal/kincidenceformatter.h> |
53 | 53 | ||
54 | #include "komonthview.h" | 54 | #include "komonthview.h" |
55 | 55 | ||
56 | #define PIXMAP_SIZE 5 | 56 | #define PIXMAP_SIZE 5 |
57 | #ifdef DESKTOP_VERSION | 57 | #ifdef DESKTOP_VERSION |
58 | QToolTipGroup *MonthViewCell::mToolTipGroup = 0; | 58 | QToolTipGroup *MonthViewCell::mToolTipGroup = 0; |
59 | #endif | 59 | #endif |
60 | class KNOWhatsThis :public QWhatsThis | 60 | class KNOWhatsThis :public QWhatsThis |
61 | { | 61 | { |
62 | public: | 62 | public: |
63 | KNOWhatsThis( KNoScrollListBox* sbox ) : QWhatsThis( sbox ), _wid( sbox) { }; | 63 | KNOWhatsThis( KNoScrollListBox* sbox ) : QWhatsThis( sbox ), _wid( sbox) { }; |
64 | //~KNOWhatsThis( ) {qDebug("~KNOWhatsThis( ) "); }; | 64 | //~KNOWhatsThis( ) {qDebug("~KNOWhatsThis( ) "); }; |
65 | 65 | ||
66 | protected: | 66 | protected: |
67 | virtual QString text( const QPoint& p) | 67 | virtual QString text( const QPoint& p) |
68 | { | 68 | { |
69 | return _wid->getWhatsThisText(p) ; | 69 | return _wid->getWhatsThisText(p) ; |
70 | }; | 70 | }; |
71 | private: | 71 | private: |
72 | KNoScrollListBox* _wid; | 72 | KNoScrollListBox* _wid; |
73 | 73 | ||
74 | }; | 74 | }; |
75 | 75 | ||
76 | 76 | ||
77 | KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name) | 77 | KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name) |
78 | : QListBox(parent, name, WRepaintNoErase) | 78 | : QListBox(parent, name, WRepaintNoErase) |
79 | { | 79 | { |
80 | #ifndef DESKTOP_VERSION | 80 | #ifndef DESKTOP_VERSION |
81 | QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); | 81 | QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); |
82 | #endif | 82 | #endif |
83 | mWT = new KNOWhatsThis(this); | 83 | mWT = new KNOWhatsThis(this); |
84 | } | 84 | } |
85 | KNoScrollListBox::~KNoScrollListBox() | 85 | KNoScrollListBox::~KNoScrollListBox() |
86 | { | 86 | { |
87 | 87 | ||
88 | } | 88 | } |
89 | QString KNoScrollListBox::getWhatsThisText(QPoint p) | 89 | QString KNoScrollListBox::getWhatsThisText(QPoint p) |
90 | { | 90 | { |
91 | QListBoxItem* item = itemAt ( p ); | 91 | QListBoxItem* item = itemAt ( p ); |
92 | if ( ! item ) { | 92 | if ( ! item ) { |
93 | return i18n("Click in the cell\nto add an event!"); | 93 | return i18n("Click in the cell\nto add an event!"); |
94 | } | 94 | } |
95 | return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence()); | 95 | return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence()); |
96 | } | 96 | } |
97 | void KNoScrollListBox::keyPressEvent(QKeyEvent *e) | 97 | void KNoScrollListBox::keyPressEvent(QKeyEvent *e) |
98 | { | 98 | { |
99 | 99 | ||
100 | switch(e->key()) { | 100 | switch(e->key()) { |
101 | case Key_Right: | 101 | case Key_Right: |
102 | // if ( e->state() == Qt::ControlButton ) | 102 | // if ( e->state() == Qt::ControlButton ) |
103 | { | 103 | { |
104 | e->ignore(); | 104 | e->ignore(); |
105 | return; | 105 | return; |
106 | } | 106 | } |
107 | scrollBy(4,0); | 107 | scrollBy(4,0); |
108 | break; | 108 | break; |
109 | case Key_Left: | 109 | case Key_Left: |
110 | // if ( e->state() == Qt::ControlButton ) | 110 | // if ( e->state() == Qt::ControlButton ) |
111 | { | 111 | { |
112 | e->ignore(); | 112 | e->ignore(); |
113 | return; | 113 | return; |
114 | } | 114 | } |
115 | scrollBy(-4,0); | 115 | scrollBy(-4,0); |
116 | break; | 116 | break; |
117 | case Key_Up: | 117 | case Key_Up: |
118 | if(count() < 2) { | 118 | if(count() < 2) { |
119 | e->ignore(); | 119 | e->ignore(); |
120 | break; | 120 | break; |
121 | } | 121 | } |
122 | setCurrentItem((currentItem()+count()-1)%count()); | 122 | setCurrentItem((currentItem()+count()-1)%count()); |
123 | if(!itemVisible(currentItem())) { | 123 | if(!itemVisible(currentItem())) { |
124 | if((unsigned int) currentItem() == (count()-1)) { | 124 | if((unsigned int) currentItem() == (count()-1)) { |
125 | setTopItem(currentItem()-numItemsVisible()+1); | 125 | setTopItem(currentItem()-numItemsVisible()+1); |
126 | } else { | 126 | } else { |
127 | setTopItem(topItem()-1); | 127 | setTopItem(topItem()-1); |
128 | } | 128 | } |
129 | } | 129 | } |
130 | break; | 130 | break; |
131 | case Key_Down: | 131 | case Key_Down: |
132 | if(count() < 2) { | 132 | if(count() < 2) { |
133 | e->ignore(); | 133 | e->ignore(); |
134 | break; | 134 | break; |
135 | } | 135 | } |
136 | setCurrentItem((currentItem()+1)%count()); | 136 | setCurrentItem((currentItem()+1)%count()); |
137 | if(!itemVisible(currentItem())) { | 137 | if(!itemVisible(currentItem())) { |
138 | if(currentItem() == 0) { | 138 | if(currentItem() == 0) { |
139 | setTopItem(0); | 139 | setTopItem(0); |
140 | } else { | 140 | } else { |
141 | setTopItem(topItem()+1); | 141 | setTopItem(topItem()+1); |
142 | } | 142 | } |
143 | } | 143 | } |
144 | break; | 144 | break; |
145 | case Key_Shift: | 145 | case Key_Shift: |
146 | emit shiftDown(); | 146 | emit shiftDown(); |
147 | break; | 147 | break; |
148 | default: | 148 | default: |
149 | e->ignore(); | 149 | e->ignore(); |
150 | break; | 150 | break; |
151 | } | 151 | } |
152 | } | 152 | } |
153 | 153 | ||
154 | void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e) | 154 | void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e) |
155 | { | 155 | { |
156 | switch(e->key()) { | 156 | switch(e->key()) { |
157 | case Key_Shift: | 157 | case Key_Shift: |
158 | emit shiftUp(); | 158 | emit shiftUp(); |
159 | break; | 159 | break; |
160 | default: | 160 | default: |
161 | break; | 161 | break; |
162 | } | 162 | } |
163 | } | 163 | } |
164 | 164 | ||
165 | void KNoScrollListBox::mousePressEvent(QMouseEvent *e) | 165 | void KNoScrollListBox::mousePressEvent(QMouseEvent *e) |
166 | { | 166 | { |
167 | QListBox::mousePressEvent(e); | 167 | QListBox::mousePressEvent(e); |
168 | 168 | ||
169 | if(e->button() == RightButton) { | 169 | if(e->button() == RightButton) { |
170 | emit rightClick(); | 170 | emit rightClick(); |
171 | } | 171 | } |
172 | } | 172 | } |
173 | 173 | ||
174 | MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s) | 174 | MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s) |
175 | : QListBoxItem() | 175 | : QListBoxItem() |
176 | { | 176 | { |
177 | setText( s ); | 177 | setText( s ); |
178 | 178 | ||
179 | mIncidence = incidence; | 179 | mIncidence = incidence; |
180 | mDate = qd; | 180 | mDate = qd; |
181 | // QWhatsThis::add(this,KIncidenceFormatter::instance()->getFormattedText( mIncidence )); | 181 | // QWhatsThis::add(this,KIncidenceFormatter::instance()->getFormattedText( mIncidence )); |
182 | mRecur = false; | 182 | mRecur = false; |
183 | mAlarm = false; | 183 | mAlarm = false; |
184 | mReply = false; | 184 | mReply = false; |
185 | mInfo = false; | 185 | mInfo = false; |
186 | } | 186 | } |
187 | 187 | ||
188 | void MonthViewItem::paint(QPainter *p) | 188 | void MonthViewItem::paint(QPainter *p) |
189 | { | 189 | { |
190 | #if QT_VERSION >= 0x030000 | 190 | #if QT_VERSION >= 0x030000 |
191 | bool sel = isSelected(); | 191 | bool sel = isSelected(); |
192 | #else | 192 | #else |
193 | bool sel = selected(); | 193 | bool sel = selected(); |
194 | #endif | 194 | #endif |
195 | 195 | ||
196 | 196 | ||
197 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) | 197 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) |
198 | { | 198 | { |
199 | p->setBackgroundColor( palette().color( QPalette::Normal, \ | 199 | p->setBackgroundColor( palette().color( QPalette::Normal, \ |
200 | sel ? QColorGroup::Highlight : QColorGroup::Background ) ); | 200 | sel ? QColorGroup::Highlight : QColorGroup::Background ) ); |
201 | p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) ); | 201 | p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) ); |
202 | } | 202 | } |
203 | int x = 1; | 203 | int x = 1; |
204 | int y = 3;//(height() - mRecurPixmap.height()) /2; | 204 | int y = 3;//(height() - mRecurPixmap.height()) /2; |
205 | int size = PIXMAP_SIZE; | 205 | int size = PIXMAP_SIZE; |
206 | if ( QApplication::desktop()->width() < 300 ) | 206 | if ( QApplication::desktop()->width() < 300 ) |
207 | size = 3; | 207 | size = 3; |
208 | if ( KOPrefs::instance()->mMonthShowIcons ) { | 208 | if ( KOPrefs::instance()->mMonthShowIcons ) { |
209 | if ( mInfo ) { | 209 | if ( mInfo ) { |
210 | p->fillRect ( x, y,size,size, Qt::darkGreen ); | 210 | p->fillRect ( x, y,size,size, Qt::darkGreen ); |
211 | x += size + 1; | 211 | x += size + 1; |
212 | } | 212 | } |
213 | if ( mRecur ) { | 213 | if ( mRecur ) { |
214 | p->fillRect ( x, y,size,size, Qt::blue ); | 214 | p->fillRect ( x, y,size,size, Qt::blue ); |
215 | x += size + 1; | 215 | x += size + 1; |
216 | } | 216 | } |
217 | if ( mAlarm ) { | 217 | if ( mAlarm ) { |
218 | p->fillRect ( x, y,size,size, Qt::red ); | 218 | p->fillRect ( x, y,size,size, Qt::red ); |
219 | x += size + 1; | 219 | x += size + 1; |
220 | } | 220 | } |
221 | if ( mReply ) { | 221 | if ( mReply ) { |
222 | p->fillRect ( x, y,size,size, Qt::yellow ); | 222 | p->fillRect ( x, y,size,size, Qt::yellow ); |
223 | x += size + 1; | 223 | x += size + 1; |
224 | } | 224 | } |
225 | } | 225 | } |
226 | QFontMetrics fm = p->fontMetrics(); | 226 | QFontMetrics fm = p->fontMetrics(); |
227 | int yPos; | 227 | int yPos; |
228 | int pmheight = size; | 228 | int pmheight = size; |
229 | if( pmheight < fm.height() ) | 229 | if( pmheight < fm.height() ) |
230 | yPos = fm.ascent() + fm.leading()/2; | 230 | yPos = fm.ascent() + fm.leading()/2; |
231 | else | 231 | else |
232 | yPos = pmheight/2 - fm.height()/2 + fm.ascent(); | 232 | yPos = pmheight/2 - fm.height()/2 + fm.ascent(); |
233 | p->setPen( palette().color( QPalette::Normal, sel ? \ | 233 | p->setPen( palette().color( QPalette::Normal, sel ? \ |
234 | QColorGroup::HighlightedText : QColorGroup::Foreground ) ); | 234 | QColorGroup::HighlightedText : QColorGroup::Foreground ) ); |
235 | p->drawText( x, yPos, text() ); | 235 | p->drawText( x, yPos, text() ); |
236 | if ( mIncidence->cancelled() ) { | 236 | if ( mIncidence->cancelled() ) { |
237 | int wid = fm.width( text() ); | 237 | int wid = fm.width( text() ); |
238 | p->drawLine( x, yPos- fm.height()/2+2,x+wid, yPos- fm.height()/2 +2); | 238 | p->drawLine( x, yPos- fm.height()/2+2,x+wid, yPos- fm.height()/2 +2); |
239 | } | 239 | } |
240 | 240 | ||
241 | } | 241 | } |
242 | 242 | ||
243 | int MonthViewItem::height(const QListBox *lb) const | 243 | int MonthViewItem::height(const QListBox *lb) const |
244 | { | 244 | { |
245 | return lb->fontMetrics().lineSpacing()+1; | 245 | return lb->fontMetrics().lineSpacing()+1; |
246 | } | 246 | } |
247 | 247 | ||
248 | int MonthViewItem::width(const QListBox *lb) const | 248 | int MonthViewItem::width(const QListBox *lb) const |
249 | { | 249 | { |
250 | int size = PIXMAP_SIZE; | 250 | int size = PIXMAP_SIZE; |
251 | if ( QApplication::desktop()->width() < 300 ) | 251 | if ( QApplication::desktop()->width() < 300 ) |
252 | size = 3; | 252 | size = 3; |
253 | int x = 1; | 253 | int x = 1; |
254 | if ( mInfo ) { | 254 | if ( mInfo ) { |
255 | x += size + 1; | 255 | x += size + 1; |
256 | } | 256 | } |
257 | if( mRecur ) { | 257 | if( mRecur ) { |
258 | x += size+1; | 258 | x += size+1; |
259 | } | 259 | } |
260 | if( mAlarm ) { | 260 | if( mAlarm ) { |
261 | x += size+1; | 261 | x += size+1; |
262 | } | 262 | } |
263 | if( mReply ) { | 263 | if( mReply ) { |
264 | x += size+1; | 264 | x += size+1; |
265 | } | 265 | } |
266 | 266 | ||
267 | return( x + lb->fontMetrics().width( text() ) + 1 ); | 267 | return( x + lb->fontMetrics().width( text() ) + 1 ); |
268 | } | 268 | } |
269 | 269 | ||
270 | 270 | ||
271 | MonthViewCell::MonthViewCell( KOMonthView *parent) | 271 | MonthViewCell::MonthViewCell( KOMonthView *parent) |
272 | : QWidget( parent ), | 272 | : QWidget( parent ), |
273 | mMonthView( parent ) | 273 | mMonthView( parent ) |
274 | { | 274 | { |
275 | 275 | ||
276 | QVBoxLayout *topLayout = new QVBoxLayout( this ); | 276 | QVBoxLayout *topLayout = new QVBoxLayout( this ); |
277 | 277 | ||
278 | // mLabel = new QLabel( this );QPushButton | 278 | // mLabel = new QLabel( this );QPushButton |
279 | mLabel = new QPushButton( this ); | 279 | mLabel = new QPushButton( this ); |
280 | //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain ); | 280 | //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain ); |
281 | //mLabel->setLineWidth( 1 ); | 281 | //mLabel->setLineWidth( 1 ); |
282 | //mLabel->setAlignment( AlignCenter ); | 282 | //mLabel->setAlignment( AlignCenter ); |
283 | mLabel->setFlat( true ); | 283 | mLabel->setFlat( true ); |
284 | mItemList = new KNoScrollListBox( this ); | 284 | mItemList = new KNoScrollListBox( this ); |
285 | mItemList->setMinimumSize( 10, 10 ); | 285 | mItemList->setMinimumSize( 10, 10 ); |
286 | mItemList->setFrameStyle( QFrame::Panel | QFrame::Plain ); | 286 | mItemList->setFrameStyle( QFrame::Panel | QFrame::Plain ); |
287 | mItemList->setLineWidth( 1 ); | 287 | mItemList->setLineWidth( 1 ); |
288 | topLayout->addWidget( mItemList ); | 288 | topLayout->addWidget( mItemList ); |
289 | mLabel->raise(); | 289 | mLabel->raise(); |
290 | // QColor( 0,0,255 ) QColor( 160,1600,255 ) | 290 | // QColor( 0,0,255 ) QColor( 160,1600,255 ) |
291 | mStandardPalette = palette(); | 291 | mStandardPalette = palette(); |
292 | mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) ); | 292 | mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) ); |
293 | 293 | ||
294 | enableScrollBars( false ); | 294 | enableScrollBars( false ); |
295 | updateConfig(); | 295 | updateConfig(); |
296 | //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() )); | 296 | //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() )); |
297 | connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() )); | 297 | connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() )); |
298 | connect( mItemList, SIGNAL( doubleClicked( QListBoxItem *) ), | 298 | connect( mItemList, SIGNAL( doubleClicked( QListBoxItem *) ), |
299 | SLOT( defaultAction( QListBoxItem * ) ) ); | 299 | SLOT( defaultAction( QListBoxItem * ) ) ); |
300 | connect( mItemList, SIGNAL( rightButtonPressed( QListBoxItem *, | 300 | connect( mItemList, SIGNAL( rightButtonPressed( QListBoxItem *, |
301 | const QPoint &) ), | 301 | const QPoint &) ), |
302 | SLOT( contextMenu( QListBoxItem * ) ) ); | 302 | SLOT( contextMenu( QListBoxItem * ) ) ); |
303 | connect( mItemList, SIGNAL( highlighted( QListBoxItem *) ), | 303 | connect( mItemList, SIGNAL( highlighted( QListBoxItem *) ), |
304 | SLOT( selection( QListBoxItem * ) ) ); | 304 | SLOT( selection( QListBoxItem * ) ) ); |
305 | connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), | 305 | connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), |
306 | SLOT( cellClicked( QListBoxItem * ) ) ); | 306 | SLOT( cellClicked( QListBoxItem * ) ) ); |
307 | connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), | 307 | connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), |
308 | SLOT( selection( QListBoxItem * ) ) ); | 308 | SLOT( selection( QListBoxItem * ) ) ); |
309 | } | 309 | } |
310 | #ifdef DESKTOP_VERSION | 310 | #ifdef DESKTOP_VERSION |
311 | QToolTipGroup *MonthViewCell::toolTipGroup() | 311 | QToolTipGroup *MonthViewCell::toolTipGroup() |
312 | { | 312 | { |
313 | if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); | 313 | if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); |
314 | return mToolTipGroup; | 314 | return mToolTipGroup; |
315 | } | 315 | } |
316 | #endif | 316 | #endif |
317 | 317 | ||
318 | void MonthViewCell::setDate( const QDate &date ) | 318 | void MonthViewCell::setDate( const QDate &date ) |
319 | { | 319 | { |
320 | // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl; | 320 | // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl; |
321 | mDate = date; | 321 | mDate = date; |
322 | 322 | ||
323 | 323 | ||
324 | 324 | ||
325 | //resizeEvent( 0 ); | 325 | //resizeEvent( 0 ); |
326 | } | 326 | } |
327 | 327 | ||
328 | QDate MonthViewCell::date() const | 328 | QDate MonthViewCell::date() const |
329 | { | 329 | { |
330 | return mDate; | 330 | return mDate; |
331 | } | 331 | } |
332 | 332 | ||
333 | void MonthViewCell::setPrimary( bool primary ) | 333 | void MonthViewCell::setPrimary( bool primary ) |
334 | { | 334 | { |
335 | mPrimary = primary; | 335 | mPrimary = primary; |
336 | //setMyPalette(); | 336 | //setMyPalette(); |
337 | } | 337 | } |
338 | void MonthViewCell::setMyPalette() | 338 | void MonthViewCell::setMyPalette() |
339 | { | 339 | { |
340 | 340 | ||
341 | if ( mHoliday) { | 341 | if ( mHoliday) { |
342 | setPalette( mHolidayPalette ); | 342 | setPalette( mHolidayPalette ); |
343 | } else { | 343 | } else { |
344 | if ( mPrimary ) { | 344 | if ( mPrimary ) { |
345 | setPalette( mPrimaryPalette ); | 345 | setPalette( mPrimaryPalette ); |
346 | } else { | 346 | } else { |
347 | setPalette( mNonPrimaryPalette ); | 347 | setPalette( mNonPrimaryPalette ); |
348 | } | 348 | } |
349 | } | 349 | } |
350 | QPalette pal = palette(); | 350 | QPalette pal = palette(); |
351 | 351 | ||
352 | mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) )); | 352 | mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) )); |
353 | } | 353 | } |
354 | QPalette MonthViewCell::getPalette () | 354 | QPalette MonthViewCell::getPalette () |
355 | { | 355 | { |
356 | if ( !KOPrefs::instance()->mMonthViewUsesDayColors ) | 356 | if ( !KOPrefs::instance()->mMonthViewUsesDayColors ) |
357 | return mStandardPalette; | 357 | return mStandardPalette; |
358 | if ( mHoliday) { | 358 | if ( mHoliday) { |
359 | return mHolidayPalette ; | 359 | return mHolidayPalette ; |
360 | } else { | 360 | } else { |
361 | if ( mPrimary ) { | 361 | if ( mPrimary ) { |
362 | return mPrimaryPalette ; | 362 | return mPrimaryPalette ; |
363 | } | 363 | } |
364 | } | 364 | } |
365 | return mNonPrimaryPalette; | 365 | return mNonPrimaryPalette; |
366 | } | 366 | } |
367 | bool MonthViewCell::isPrimary() const | 367 | bool MonthViewCell::isPrimary() const |
368 | { | 368 | { |
369 | return mPrimary; | 369 | return mPrimary; |
370 | } | 370 | } |
371 | 371 | ||
372 | void MonthViewCell::setHoliday( bool holiday ) | 372 | void MonthViewCell::setHoliday( bool holiday ) |
373 | { | 373 | { |
374 | mHoliday = holiday; | 374 | mHoliday = holiday; |
375 | //setMyPalette(); | 375 | //setMyPalette(); |
376 | } | 376 | } |
377 | 377 | ||
378 | void MonthViewCell::setHoliday( const QString &holiday ) | 378 | void MonthViewCell::setHoliday( const QString &holiday ) |
379 | { | 379 | { |
380 | mHolidayString = holiday; | 380 | mHolidayString = holiday; |
381 | 381 | ||
382 | if ( !holiday.isEmpty() ) { | 382 | if ( !holiday.isEmpty() ) { |
383 | setHoliday( true ); | 383 | setHoliday( true ); |
384 | } | 384 | } |
385 | } | 385 | } |
386 | void MonthViewCell::keyPressEvent ( QKeyEvent * e ) | 386 | void MonthViewCell::keyPressEvent ( QKeyEvent * e ) |
387 | { | 387 | { |
388 | 388 | ||
389 | e->ignore(); | 389 | e->ignore(); |
390 | 390 | ||
391 | } | 391 | } |
392 | void MonthViewCell::clear() | 392 | void MonthViewCell::clear() |
393 | { | 393 | { |
394 | mItemList->clear(); | 394 | mItemList->clear(); |
395 | QApplication::removePostedEvents ( mItemList ); | 395 | QApplication::removePostedEvents ( mItemList ); |
396 | QApplication::removePostedEvents ( mLabel ); | 396 | QApplication::removePostedEvents ( mLabel ); |
397 | QApplication::removePostedEvents ( this ); | 397 | QApplication::removePostedEvents ( this ); |
398 | } | 398 | } |
399 | void MonthViewCell::updateCell() | 399 | |
400 | void MonthViewCell::startUpdateCell() | ||
400 | { | 401 | { |
402 | |||
401 | if ( !mMonthView->isUpdatePossible() ) | 403 | if ( !mMonthView->isUpdatePossible() ) |
402 | return; | 404 | return; |
403 | /* | 405 | /* |
404 | if ( !isVisible() ){ | 406 | if ( !isVisible() ){ |
405 | return; | 407 | return; |
406 | } | 408 | } |
407 | */ | 409 | */ |
408 | // qDebug("MonthViewCell::updateCell() "); | 410 | // qDebug("MonthViewCell::updateCell() "); |
409 | setPrimary( mDate.month()%2 ); | 411 | setPrimary( mDate.month()%2 ); |
410 | setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays); | 412 | setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays); |
411 | if ( mDate == QDate::currentDate() ) { | 413 | if ( mDate == QDate::currentDate() ) { |
412 | mItemList->setLineWidth( 3 ); | 414 | mItemList->setLineWidth( 3 ); |
413 | } else { | 415 | } else { |
414 | mItemList->setLineWidth( 1 ); | 416 | mItemList->setLineWidth( 1 ); |
415 | } | 417 | } |
416 | mItemList->clear(); | 418 | mItemList->clear(); |
417 | 419 | ||
418 | #ifdef DESKTOP_VERSION | 420 | #ifdef DESKTOP_VERSION |
419 | QToolTip::remove(this); | 421 | QToolTip::remove(this); |
420 | #endif | 422 | #endif |
421 | QString tipText(""); | 423 | mToolTip = ""; |
422 | //qApp->processEvents(); | 424 | //qApp->processEvents(); |
423 | if ( !mHolidayString.isEmpty() ) { | 425 | if ( !mHolidayString.isEmpty() ) { |
424 | MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString ); | 426 | MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString ); |
425 | item->setPalette( mHolidayPalette ); | 427 | item->setPalette( mHolidayPalette ); |
426 | mItemList->insertItem( item ); | 428 | mItemList->insertItem( item ); |
427 | tipText += mHolidayString+"\n"; | 429 | mToolTip += mHolidayString+"\n"; |
428 | } | 430 | } |
429 | //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); | 431 | } |
430 | QPtrList<Event> events = mMonthView->calendar()->events( mDate, true ); | ||
431 | Event *event; | ||
432 | for( event = events.first(); event; event = events.next() ) { // for event | ||
433 | 432 | ||
433 | void MonthViewCell::insertEvent(Event *event) | ||
434 | { | ||
434 | if ( !(event->doesRecur() == Recurrence::rNone) ) { | 435 | if ( !(event->doesRecur() == Recurrence::rNone) ) { |
435 | if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily ) | 436 | if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily ) |
436 | continue; | 437 | return; |
437 | else | 438 | else |
438 | if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly ) | 439 | if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly ) |
439 | continue; | 440 | return; |
440 | } | 441 | } |
441 | 442 | ||
442 | if ( event->categories().contains("Holiday") || | 443 | if ( event->categories().contains("Holiday") || |
443 | event->categories().contains(i18n("Holiday"))) { | 444 | event->categories().contains(i18n("Holiday"))) { |
444 | setHoliday( true ); | 445 | setHoliday( true ); |
445 | if ( mDate.dayOfWeek() == 7 ) | 446 | if ( mDate.dayOfWeek() == 7 ) |
446 | mItemList->setLineWidth( 3 ); | 447 | mItemList->setLineWidth( 3 ); |
447 | } | 448 | } |
448 | QString text; | 449 | QString text; |
449 | if (event->isMultiDay()) { | 450 | if (event->isMultiDay()) { |
450 | QString prefix = "<->"; | 451 | QString prefix = "<->"; |
451 | if ( event->doesRecur() ) { | 452 | if ( event->doesRecur() ) { |
452 | if ( event->recursOn( mDate) ) | 453 | if ( event->recursOn( mDate) ) |
453 | prefix ="->" ; | 454 | prefix ="->" ; |
454 | else { | 455 | else { |
455 | int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); | 456 | int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); |
456 | if ( event->recursOn( mDate.addDays( -days)) ) | 457 | if ( event->recursOn( mDate.addDays( -days)) ) |
457 | prefix ="<-" ; | 458 | prefix ="<-" ; |
458 | } | 459 | } |
459 | 460 | ||
460 | } else { | 461 | } else { |
461 | if (mDate == event->dtStart().date()) { | 462 | if (mDate == event->dtStart().date()) { |
462 | prefix ="->" ; | 463 | prefix ="->" ; |
463 | } else if (mDate == event->dtEnd().date()) { | 464 | } else if (mDate == event->dtEnd().date()) { |
464 | prefix ="<-" ; | 465 | prefix ="<-" ; |
465 | } | 466 | } |
466 | } | 467 | } |
467 | text = prefix + event->summary(); | 468 | text = prefix + event->summary(); |
468 | tipText += text; | 469 | mToolTip += text; |
469 | } else { | 470 | } else { |
470 | if (event->doesFloat()) { | 471 | if (event->doesFloat()) { |
471 | text = event->summary(); | 472 | text = event->summary(); |
472 | tipText += text; | 473 | mToolTip += text; |
473 | } | 474 | } |
474 | else { | 475 | else { |
475 | text = KGlobal::locale()->formatTime(event->dtStart().time()); | 476 | text = KGlobal::locale()->formatTime(event->dtStart().time()); |
476 | text += " " + event->summary(); | 477 | text += " " + event->summary(); |
477 | tipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); | 478 | mToolTip += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); |
478 | } | 479 | } |
479 | } | 480 | } |
480 | 481 | ||
481 | MonthViewItem *item = new MonthViewItem( event, mDate, text ); | 482 | MonthViewItem *item = new MonthViewItem( event, mDate, text ); |
482 | QPalette pal; | 483 | QPalette pal; |
483 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { | 484 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { |
484 | QStringList categories = event->categories(); | 485 | QStringList categories = event->categories(); |
485 | QString cat = categories.first(); | 486 | QString cat = categories.first(); |
486 | if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { | 487 | if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { |
487 | pal = getPalette(); | 488 | pal = getPalette(); |
488 | if (cat.isEmpty()) { | 489 | if (cat.isEmpty()) { |
489 | pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); | 490 | pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); |
490 | } else { | 491 | } else { |
491 | pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); | 492 | pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); |
492 | } | 493 | } |
493 | 494 | ||
494 | } else { | 495 | } else { |
495 | if (cat.isEmpty()) { | 496 | if (cat.isEmpty()) { |
496 | pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); | 497 | pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); |
497 | } else { | 498 | } else { |
498 | pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); | 499 | pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); |
499 | } | 500 | } |
500 | } | 501 | } |
501 | 502 | ||
502 | } else { | 503 | } else { |
503 | pal = mStandardPalette ; | 504 | pal = mStandardPalette ; |
504 | } | 505 | } |
505 | item->setPalette( pal ); | 506 | item->setPalette( pal ); |
506 | item->setRecur( event->recurrence()->doesRecur() ); | 507 | item->setRecur( event->recurrence()->doesRecur() ); |
507 | item->setAlarm( event->isAlarmEnabled() ); | 508 | item->setAlarm( event->isAlarmEnabled() ); |
508 | item->setMoreInfo( event->description().length() > 0 ); | 509 | item->setMoreInfo( event->description().length() > 0 ); |
509 | #ifdef DESKTOP_VERSION | 510 | #ifdef DESKTOP_VERSION |
510 | Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails, | 511 | Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails, |
511 | KOPrefs::instance()->email()); | 512 | KOPrefs::instance()->email()); |
512 | if ( me != 0 ) { | 513 | if ( me != 0 ) { |
513 | if ( me->status() == Attendee::NeedsAction && me->RSVP()) | 514 | if ( me->status() == Attendee::NeedsAction && me->RSVP()) |
514 | item->setReply(true); | 515 | item->setReply(true); |
515 | else | 516 | else |
516 | item->setReply(false); | 517 | item->setReply(false); |
517 | } else | 518 | } else |
518 | item->setReply(false); | 519 | item->setReply(false); |
519 | #endif | 520 | #endif |
520 | mItemList->insertItem( item ); | 521 | mItemList->insertItem( item ); |
521 | tipText += "\n"; | 522 | mToolTip += "\n"; |
522 | 523 | } | |
523 | } | 524 | void MonthViewCell::insertTodo(Todo *todo) |
524 | 525 | { | |
525 | // insert due todos | 526 | QString text; |
526 | QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate ); | ||
527 | Todo *todo; | ||
528 | for(todo = todos.first(); todo; todo = todos.next()) { | ||
529 | QString text; | ||
530 | if (todo->hasDueDate()) { | 527 | if (todo->hasDueDate()) { |
531 | if (!todo->doesFloat()) { | 528 | if (!todo->doesFloat()) { |
532 | text += KGlobal::locale()->formatTime(todo->dtDue().time()); | 529 | text += KGlobal::locale()->formatTime(todo->dtDue().time()); |
533 | text += " "; | 530 | text += " "; |
534 | } | 531 | } |
535 | } | 532 | } |
536 | text += i18n("To-Do: %1").arg(todo->summary()); | 533 | text += i18n("To-Do: %1").arg(todo->summary()); |
537 | 534 | ||
538 | MonthViewItem *item = new MonthViewItem( todo, mDate, text ); | 535 | MonthViewItem *item = new MonthViewItem( todo, mDate, text ); |
539 | //item->setPalette( mStandardPalette ); | 536 | //item->setPalette( mStandardPalette ); |
540 | QPalette pal; | 537 | QPalette pal; |
541 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { | 538 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { |
542 | QStringList categories = todo->categories(); | 539 | QStringList categories = todo->categories(); |
543 | QString cat = categories.first(); | 540 | QString cat = categories.first(); |
544 | if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { | 541 | if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { |
545 | pal = getPalette(); | 542 | pal = getPalette(); |
546 | if (cat.isEmpty()) { | 543 | if (cat.isEmpty()) { |
547 | pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); | 544 | pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); |
548 | } else { | 545 | } else { |
549 | pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); | 546 | pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); |
550 | } | 547 | } |
551 | 548 | ||
552 | } else { | 549 | } else { |
553 | if (cat.isEmpty()) { | 550 | if (cat.isEmpty()) { |
554 | pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); | 551 | pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); |
555 | } else { | 552 | } else { |
556 | pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); | 553 | pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); |
557 | } | 554 | } |
558 | } | 555 | } |
559 | 556 | ||
560 | } else { | 557 | } else { |
561 | pal = mStandardPalette ; | 558 | pal = mStandardPalette ; |
562 | } | 559 | } |
563 | item->setPalette( pal ); | 560 | item->setPalette( pal ); |
564 | mItemList->insertItem( item ); | 561 | mItemList->insertItem( item ); |
565 | tipText += text+"\n"; | 562 | mToolTip += text+"\n"; |
566 | } | 563 | } |
564 | void MonthViewCell::finishUpdateCell() | ||
565 | { | ||
567 | #ifdef DESKTOP_VERSION | 566 | #ifdef DESKTOP_VERSION |
568 | if (tipText != "") | 567 | if (mToolTip != "") |
569 | QToolTip::add(this,tipText,toolTipGroup(),""); | 568 | QToolTip::add(this,mToolTip,toolTipGroup(),""); |
570 | #endif | 569 | #endif |
571 | 570 | ||
572 | //setMyPalette(); | 571 | //setMyPalette(); |
573 | setMyPalette(); | 572 | setMyPalette(); |
574 | QString text; | 573 | QString text; |
575 | bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog; | 574 | bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog; |
576 | if ( KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) { | 575 | if ( KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) { |
577 | text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " "; | 576 | text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " "; |
578 | mLabel->resize( mLabelBigSize ); | 577 | mLabel->resize( mLabelBigSize ); |
579 | text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); | 578 | text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); |
580 | } else { | 579 | } else { |
581 | mLabel->resize( mLabelSize ); | 580 | mLabel->resize( mLabelSize ); |
582 | text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); | 581 | text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); |
583 | } | 582 | } |
584 | 583 | ||
585 | mLabel->setText( text ); | 584 | mLabel->setText( text ); |
586 | resizeEvent( 0 ); | 585 | resizeEvent( 0 ); |
586 | } | ||
587 | void MonthViewCell::updateCell() | ||
588 | { | ||
589 | if ( !mMonthView->isUpdatePossible() ) | ||
590 | return; | ||
591 | startUpdateCell(); | ||
592 | //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); | ||
593 | QPtrList<Event> events = mMonthView->calendar()->events( mDate, true ); | ||
594 | Event *event; | ||
595 | for( event = events.first(); event; event = events.next() ) { // for event | ||
596 | insertEvent(event); | ||
597 | } | ||
598 | // insert due todos | ||
599 | QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate ); | ||
600 | Todo *todo; | ||
601 | for(todo = todos.first(); todo; todo = todos.next()) { | ||
602 | insertTodo( todo ); | ||
603 | } | ||
604 | finishUpdateCell(); | ||
587 | // if ( isVisible()) | 605 | // if ( isVisible()) |
588 | //qApp->processEvents(); | 606 | //qApp->processEvents(); |
589 | } | 607 | } |
590 | 608 | ||
591 | void MonthViewCell::updateConfig() | 609 | void MonthViewCell::updateConfig() |
592 | { | 610 | { |
593 | 611 | qDebug("MonthViewCell::updateConfig() "); | |
594 | setFont( KOPrefs::instance()->mMonthViewFont ); | 612 | setFont( KOPrefs::instance()->mMonthViewFont ); |
595 | 613 | ||
596 | QFontMetrics fm( font() ); | 614 | QFontMetrics fm( font() ); |
597 | mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 ); | 615 | mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 ); |
598 | mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 ); | 616 | mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 ); |
599 | mHolidayPalette = mStandardPalette; | 617 | mHolidayPalette = mStandardPalette; |
600 | mPrimaryPalette = mStandardPalette; | 618 | mPrimaryPalette = mStandardPalette; |
601 | mNonPrimaryPalette = mStandardPalette; | 619 | mNonPrimaryPalette = mStandardPalette; |
602 | if ( KOPrefs::instance()->mMonthViewUsesDayColors ) { | 620 | if ( KOPrefs::instance()->mMonthViewUsesDayColors ) { |
603 | mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor ); | 621 | mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor ); |
604 | mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor ); | 622 | mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor ); |
605 | mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark()); | 623 | mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark()); |
606 | mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark()); | 624 | mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark()); |
607 | mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor); | 625 | mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor); |
608 | mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor); | 626 | mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor); |
609 | mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark()); | 627 | mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark()); |
610 | mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor); | 628 | mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor); |
611 | mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor); | 629 | mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor); |
612 | } | 630 | } |
613 | updateCell(); | 631 | updateCell(); |
614 | } | 632 | } |
615 | 633 | ||
616 | void MonthViewCell::enableScrollBars( bool enabled ) | 634 | void MonthViewCell::enableScrollBars( bool enabled ) |
617 | { | 635 | { |
618 | if ( enabled ) { | 636 | if ( enabled ) { |
619 | mItemList->setVScrollBarMode(QScrollView::Auto); | 637 | mItemList->setVScrollBarMode(QScrollView::Auto); |
620 | mItemList->setHScrollBarMode(QScrollView::Auto); | 638 | mItemList->setHScrollBarMode(QScrollView::Auto); |
621 | } else { | 639 | } else { |
622 | mItemList->setVScrollBarMode(QScrollView::AlwaysOff); | 640 | mItemList->setVScrollBarMode(QScrollView::AlwaysOff); |
623 | mItemList->setHScrollBarMode(QScrollView::AlwaysOff); | 641 | mItemList->setHScrollBarMode(QScrollView::AlwaysOff); |
624 | } | 642 | } |
625 | } | 643 | } |
626 | 644 | ||
627 | Incidence *MonthViewCell::selectedIncidence() | 645 | Incidence *MonthViewCell::selectedIncidence() |
628 | { | 646 | { |
629 | int index = mItemList->currentItem(); | 647 | int index = mItemList->currentItem(); |
630 | if ( index < 0 ) return 0; | 648 | if ( index < 0 ) return 0; |
631 | 649 | ||
632 | MonthViewItem *item = | 650 | MonthViewItem *item = |
633 | static_cast<MonthViewItem *>( mItemList->item( index ) ); | 651 | static_cast<MonthViewItem *>( mItemList->item( index ) ); |
634 | 652 | ||
635 | if ( !item ) return 0; | 653 | if ( !item ) return 0; |
636 | 654 | ||
637 | return item->incidence(); | 655 | return item->incidence(); |
638 | } | 656 | } |
639 | 657 | ||
640 | QDate MonthViewCell::selectedIncidenceDate() | 658 | QDate MonthViewCell::selectedIncidenceDate() |
641 | { | 659 | { |
642 | QDate qd; | 660 | QDate qd; |
643 | int index = mItemList->currentItem(); | 661 | int index = mItemList->currentItem(); |
644 | if ( index < 0 ) return qd; | 662 | if ( index < 0 ) return qd; |
645 | 663 | ||
646 | MonthViewItem *item = | 664 | MonthViewItem *item = |
647 | static_cast<MonthViewItem *>( mItemList->item( index ) ); | 665 | static_cast<MonthViewItem *>( mItemList->item( index ) ); |
648 | 666 | ||
649 | if ( !item ) return qd; | 667 | if ( !item ) return qd; |
650 | 668 | ||
651 | return item->incidenceDate(); | 669 | return item->incidenceDate(); |
652 | } | 670 | } |
653 | 671 | ||
654 | void MonthViewCell::deselect() | 672 | void MonthViewCell::deselect() |
655 | { | 673 | { |
656 | mItemList->clearSelection(); | 674 | mItemList->clearSelection(); |
657 | enableScrollBars( false ); | 675 | enableScrollBars( false ); |
658 | // updateCell(); | 676 | // updateCell(); |
659 | } | 677 | } |
660 | void MonthViewCell::select() | 678 | void MonthViewCell::select() |
661 | { | 679 | { |
662 | ;// updateCell(); | 680 | ;// updateCell(); |
663 | } | 681 | } |
664 | 682 | ||
665 | void MonthViewCell::resizeEvent ( QResizeEvent * ) | 683 | void MonthViewCell::resizeEvent ( QResizeEvent * ) |
666 | { | 684 | { |
667 | if ( !mMonthView->isUpdatePossible() ) | 685 | if ( !mMonthView->isUpdatePossible() ) |
668 | return; | 686 | return; |
669 | #ifndef DESKTOP_VERSION | 687 | #ifndef DESKTOP_VERSION |
670 | if ( !isVisible() ){ | 688 | if ( !isVisible() ){ |
671 | return; | 689 | return; |
672 | } | 690 | } |
673 | #endif | 691 | #endif |
674 | int size = height() - mLabel->height(); | 692 | int size = height() - mLabel->height(); |
675 | if ( size > 0 ) | 693 | if ( size > 0 ) |
676 | mItemList->verticalScrollBar()->setMaximumHeight( size ); | 694 | mItemList->verticalScrollBar()->setMaximumHeight( size ); |
677 | size = width() - mLabel->width(); | 695 | size = width() - mLabel->width(); |
678 | if ( size > 0 ) | 696 | if ( size > 0 ) |
679 | mItemList->horizontalScrollBar()->setMaximumWidth( size ); | 697 | mItemList->horizontalScrollBar()->setMaximumWidth( size ); |
680 | mLabel->move( width()-mItemList->lineWidth() - mLabel->width(), height()-mItemList->lineWidth() - mLabel->height() ); | 698 | mLabel->move( width()-mItemList->lineWidth() - mLabel->width(), height()-mItemList->lineWidth() - mLabel->height() ); |
681 | //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); | 699 | //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); |
682 | } | 700 | } |
683 | 701 | ||
684 | void MonthViewCell::defaultAction( QListBoxItem *item ) | 702 | void MonthViewCell::defaultAction( QListBoxItem *item ) |
685 | { | 703 | { |
686 | if ( !item ) return; | 704 | if ( !item ) return; |
687 | 705 | ||
688 | MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); | 706 | MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); |
689 | Incidence *incidence = eventItem->incidence(); | 707 | Incidence *incidence = eventItem->incidence(); |
690 | if ( incidence ) mMonthView->defaultAction( incidence ); | 708 | if ( incidence ) mMonthView->defaultAction( incidence ); |
691 | } | 709 | } |
692 | void MonthViewCell::showDay() | 710 | void MonthViewCell::showDay() |
693 | { | 711 | { |
694 | emit showDaySignal( date() ); | 712 | emit showDaySignal( date() ); |
695 | } | 713 | } |
696 | void MonthViewCell::newEvent() | 714 | void MonthViewCell::newEvent() |
697 | { | 715 | { |
698 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); | 716 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); |
699 | emit newEventSignal( dt ); | 717 | emit newEventSignal( dt ); |
700 | } | 718 | } |
701 | void MonthViewCell::cellClicked( QListBoxItem *item ) | 719 | void MonthViewCell::cellClicked( QListBoxItem *item ) |
702 | { | 720 | { |
703 | static QListBoxItem * lastClicked = 0; | 721 | static QListBoxItem * lastClicked = 0; |
704 | if ( item == 0 ) { | 722 | if ( item == 0 ) { |
705 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); | 723 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); |
706 | emit newEventSignal( dt ); | 724 | emit newEventSignal( dt ); |
707 | return; | 725 | return; |
708 | } | 726 | } |
709 | /* | 727 | /* |
710 | if ( lastClicked ) | 728 | if ( lastClicked ) |
711 | if ( ! item ) { | 729 | if ( ! item ) { |
712 | if ( lastClicked->listBox() != item->listBox() ) | 730 | if ( lastClicked->listBox() != item->listBox() ) |
713 | lastClicked->listBox()->clearSelection(); | 731 | lastClicked->listBox()->clearSelection(); |
714 | } | 732 | } |
715 | */ | 733 | */ |
716 | 734 | ||
717 | mMonthView->setSelectedCell( this ); | 735 | mMonthView->setSelectedCell( this ); |
718 | if( KOPrefs::instance()->mEnableMonthScroll ) enableScrollBars( true ); | 736 | if( KOPrefs::instance()->mEnableMonthScroll ) enableScrollBars( true ); |
719 | select(); | 737 | select(); |
720 | } | 738 | } |
721 | 739 | ||
722 | void MonthViewCell::contextMenu( QListBoxItem *item ) | 740 | void MonthViewCell::contextMenu( QListBoxItem *item ) |
723 | { | 741 | { |
724 | if ( !item ) return; | 742 | if ( !item ) return; |
725 | 743 | ||
726 | MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); | 744 | MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); |
727 | Incidence *incidence = eventItem->incidence(); | 745 | Incidence *incidence = eventItem->incidence(); |
728 | if ( incidence ) mMonthView->showContextMenu( incidence ); | 746 | if ( incidence ) mMonthView->showContextMenu( incidence ); |
729 | } | 747 | } |
730 | 748 | ||
731 | void MonthViewCell::selection( QListBoxItem *item ) | 749 | void MonthViewCell::selection( QListBoxItem *item ) |
732 | { | 750 | { |
733 | if ( !item ) return; | 751 | if ( !item ) return; |
734 | 752 | ||
735 | mMonthView->setSelectedCell( this ); | 753 | mMonthView->setSelectedCell( this ); |
736 | } | 754 | } |
737 | 755 | ||
738 | 756 | ||
739 | // ******************************************************************************* | 757 | // ******************************************************************************* |
740 | // ******************************************************************************* | 758 | // ******************************************************************************* |
741 | // ******************************************************************************* | 759 | // ******************************************************************************* |
742 | 760 | ||
743 | 761 | ||
744 | KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) | 762 | KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) |
745 | : KOEventView( calendar, parent, name ), | 763 | : KOEventView( calendar, parent, name ), |
746 | mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), | 764 | mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), |
747 | mShortDayLabels( false ), mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) | 765 | mShortDayLabels( false ), mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) |
748 | { | 766 | { |
749 | 767 | ||
750 | updatePossible = false; | 768 | updatePossible = false; |
751 | mCells.setAutoDelete( true ); | 769 | mCells.setAutoDelete( true ); |
752 | mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; | 770 | mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; |
753 | // mDayLayout = new QGridLayout( this ); | 771 | // mDayLayout = new QGridLayout( this ); |
754 | // create the day of the week labels (Sun, Mon, etc) and add them to | 772 | // create the day of the week labels (Sun, Mon, etc) and add them to |
755 | // the layout. | 773 | // the layout. |
756 | mDayLabels.resize( mDaysPerWeek ); | 774 | mDayLabels.resize( mDaysPerWeek ); |
757 | QFont bfont = font(); | 775 | QFont bfont = font(); |
758 | if ( QApplication::desktop()->width() < 650 ) { | 776 | if ( QApplication::desktop()->width() < 650 ) { |
759 | bfont.setPointSize( bfont.pointSize() - 2 ); | 777 | bfont.setPointSize( bfont.pointSize() - 2 ); |
760 | } | 778 | } |
761 | bfont.setBold( true ); | 779 | bfont.setBold( true ); |
762 | int i; | 780 | int i; |
763 | 781 | ||
764 | for( i = 0; i < mDaysPerWeek; i++ ) { | 782 | for( i = 0; i < mDaysPerWeek; i++ ) { |
765 | QLabel *label = new QLabel( this ); | 783 | QLabel *label = new QLabel( this ); |
766 | label->setFont(bfont); | 784 | label->setFont(bfont); |
767 | label->setFrameStyle(QFrame::Panel|QFrame::Raised); | 785 | label->setFrameStyle(QFrame::Panel|QFrame::Raised); |
768 | label->setLineWidth(1); | 786 | label->setLineWidth(1); |
769 | label->setAlignment(AlignCenter); | 787 | label->setAlignment(AlignCenter); |
770 | mDayLabels.insert( i, label ); | 788 | mDayLabels.insert( i, label ); |
771 | } | 789 | } |
772 | 790 | ||
773 | bfont.setBold( false ); | 791 | bfont.setBold( false ); |
774 | mWeekLabels.resize( mNumWeeks+1 ); | 792 | mWeekLabels.resize( mNumWeeks+1 ); |
775 | for( i = 0; i < mNumWeeks+1; i++ ) { | 793 | for( i = 0; i < mNumWeeks+1; i++ ) { |
776 | KOWeekButton *label = new KOWeekButton( this ); | 794 | KOWeekButton *label = new KOWeekButton( this ); |
777 | label->setFont(bfont); | 795 | label->setFont(bfont); |
778 | connect( label, SIGNAL( selectWeekNum ( int )),this, SIGNAL( selectWeekNum ( int )) ); | 796 | connect( label, SIGNAL( selectWeekNum ( int )),this, SIGNAL( selectWeekNum ( int )) ); |
779 | label->setFlat(true); | 797 | label->setFlat(true); |
780 | QWhatsThis::add(label,i18n("Click on the week number to\nshow week in agenda view")); | 798 | QWhatsThis::add(label,i18n("Click on the week number to\nshow week in agenda view")); |
781 | //label->setFrameStyle(QFrame::Panel|QFrame::Raised); | 799 | //label->setFrameStyle(QFrame::Panel|QFrame::Raised); |
782 | //label->setLineWidth(1); | 800 | //label->setLineWidth(1); |
783 | //label->setAlignment(AlignCenter); | 801 | //label->setAlignment(AlignCenter); |
784 | mWeekLabels.insert( i, label ); | 802 | mWeekLabels.insert( i, label ); |
785 | } | 803 | } |
786 | mWeekLabels[mNumWeeks]->setText( i18n("W")); | 804 | mWeekLabels[mNumWeeks]->setText( i18n("W")); |
787 | int row, col; | 805 | int row, col; |
788 | mCells.resize( mNumCells ); | 806 | mCells.resize( mNumCells ); |
789 | for( row = 0; row < mNumWeeks; ++row ) { | 807 | for( row = 0; row < mNumWeeks; ++row ) { |
790 | for( col = 0; col < mDaysPerWeek; ++col ) { | 808 | for( col = 0; col < mDaysPerWeek; ++col ) { |
791 | MonthViewCell *cell = new MonthViewCell( this ); | 809 | MonthViewCell *cell = new MonthViewCell( this ); |
792 | mCells.insert( row * mDaysPerWeek + col, cell ); | 810 | mCells.insert( row * mDaysPerWeek + col, cell ); |
793 | 811 | ||
794 | connect( cell, SIGNAL( defaultAction( Incidence * ) ), | 812 | connect( cell, SIGNAL( defaultAction( Incidence * ) ), |
795 | SLOT( defaultAction( Incidence * ) ) ); | 813 | SLOT( defaultAction( Incidence * ) ) ); |
796 | connect( cell, SIGNAL( newEventSignal( QDateTime ) ), | 814 | connect( cell, SIGNAL( newEventSignal( QDateTime ) ), |
797 | SIGNAL( newEventSignal( QDateTime ) ) ); | 815 | SIGNAL( newEventSignal( QDateTime ) ) ); |
798 | connect( cell, SIGNAL( showDaySignal( QDate ) ), | 816 | connect( cell, SIGNAL( showDaySignal( QDate ) ), |
799 | SIGNAL( showDaySignal( QDate ) ) ); | 817 | SIGNAL( showDaySignal( QDate ) ) ); |
800 | } | 818 | } |
801 | } | 819 | } |
802 | 820 | ||
803 | mContextMenu = eventPopup(); | 821 | mContextMenu = eventPopup(); |
804 | // updateConfig(); //useless here | 822 | // updateConfig(); //useless here |
805 | 823 | ||
806 | emit incidenceSelected( 0 ); | 824 | emit incidenceSelected( 0 ); |
807 | } | 825 | } |
808 | 826 | ||
809 | KOMonthView::~KOMonthView() | 827 | KOMonthView::~KOMonthView() |
810 | { | 828 | { |
811 | delete mContextMenu; | 829 | delete mContextMenu; |
812 | } | 830 | } |
813 | 831 | ||
814 | int KOMonthView::maxDatesHint() | 832 | int KOMonthView::maxDatesHint() |
815 | { | 833 | { |
816 | return mNumCells; | 834 | return mNumCells; |
817 | } | 835 | } |
818 | 836 | ||
819 | int KOMonthView::currentDateCount() | 837 | int KOMonthView::currentDateCount() |
820 | { | 838 | { |
821 | return mNumCells; | 839 | return mNumCells; |
822 | } | 840 | } |
823 | 841 | ||
824 | QPtrList<Incidence> KOMonthView::selectedIncidences() | 842 | QPtrList<Incidence> KOMonthView::selectedIncidences() |
825 | { | 843 | { |
826 | QPtrList<Incidence> selected; | 844 | QPtrList<Incidence> selected; |
827 | 845 | ||
828 | if ( mSelectedCell ) { | 846 | if ( mSelectedCell ) { |
829 | Incidence *incidence = mSelectedCell->selectedIncidence(); | 847 | Incidence *incidence = mSelectedCell->selectedIncidence(); |
830 | if ( incidence ) selected.append( incidence ); | 848 | if ( incidence ) selected.append( incidence ); |
831 | } | 849 | } |
832 | 850 | ||
833 | return selected; | 851 | return selected; |
834 | } | 852 | } |
835 | 853 | ||
836 | DateList KOMonthView::selectedDates() | 854 | DateList KOMonthView::selectedDates() |
837 | { | 855 | { |
838 | DateList selected; | 856 | DateList selected; |
839 | 857 | ||
840 | if ( mSelectedCell ) { | 858 | if ( mSelectedCell ) { |
841 | QDate qd = mSelectedCell->selectedIncidenceDate(); | 859 | QDate qd = mSelectedCell->selectedIncidenceDate(); |
842 | if ( qd.isValid() ) selected.append( qd ); | 860 | if ( qd.isValid() ) selected.append( qd ); |
843 | } | 861 | } |
844 | 862 | ||
845 | return selected; | 863 | return selected; |
846 | } | 864 | } |
847 | 865 | ||
848 | void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd, | 866 | void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd, |
849 | const QDate &td) | 867 | const QDate &td) |
850 | { | 868 | { |
851 | #ifndef KORG_NOPRINTER | 869 | #ifndef KORG_NOPRINTER |
852 | calPrinter->preview(CalPrinter::Month, fd, td); | 870 | calPrinter->preview(CalPrinter::Month, fd, td); |
853 | #endif | 871 | #endif |
854 | } | 872 | } |
855 | 873 | ||
856 | void KOMonthView::updateConfig() | 874 | void KOMonthView::updateConfig() |
857 | { | 875 | { |
858 | 876 | ||
859 | mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); | 877 | mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); |
860 | 878 | ||
861 | QFontMetrics fontmetric(mDayLabels[0]->font()); | 879 | QFontMetrics fontmetric(mDayLabels[0]->font()); |
862 | mWidthLongDayLabel = 0; | 880 | mWidthLongDayLabel = 0; |
863 | 881 | ||
864 | for (int i = 0; i < 7; i++) { | 882 | for (int i = 0; i < 7; i++) { |
865 | int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); | 883 | int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); |
866 | if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; | 884 | if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; |
867 | } | 885 | } |
868 | bool temp = mShowSatSunComp ; | 886 | bool temp = mShowSatSunComp ; |
869 | mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; | 887 | mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; |
870 | if ( temp != KOPrefs::instance()->mMonthViewSatSunTog ) | 888 | if ( temp != KOPrefs::instance()->mMonthViewSatSunTog ) |
871 | computeLayout(); | 889 | computeLayout(); |
872 | updateDayLabels(); | 890 | updateDayLabels(); |
873 | //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks); | 891 | //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks); |
874 | int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks; | 892 | int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks; |
875 | //resizeEvent( 0 ); | 893 | //resizeEvent( 0 ); |
876 | for (uint i = 0; i < mCells.count(); ++i) { | 894 | for (uint i = 0; i < mCells.count(); ++i) { |
877 | mCells[i]->updateConfig(); | 895 | mCells[i]->updateConfig(); |
878 | } | 896 | } |
879 | #ifdef DESKTOP_VERSION | 897 | #ifdef DESKTOP_VERSION |
880 | MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips); | 898 | MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips); |
881 | #endif | 899 | #endif |
882 | } | 900 | } |
883 | 901 | ||
884 | void KOMonthView::updateDayLabels() | 902 | void KOMonthView::updateDayLabels() |
885 | { | 903 | { |
886 | 904 | ||
887 | for (int i = 0; i < 7; i++) { | 905 | for (int i = 0; i < 7; i++) { |
888 | if (mWeekStartsMonday) { | 906 | if (mWeekStartsMonday) { |
889 | bool show = mShortDayLabels; | 907 | bool show = mShortDayLabels; |
890 | if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > mDayLabels[i]->width() ) | 908 | if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > mDayLabels[i]->width() ) |
891 | show = true; | 909 | show = true; |
892 | mDayLabels[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); | 910 | mDayLabels[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); |
893 | } else { | 911 | } else { |
894 | if (i==0) mDayLabels[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabels)); | 912 | if (i==0) mDayLabels[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabels)); |
895 | else mDayLabels[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabels)); | 913 | else mDayLabels[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabels)); |
896 | 914 | ||
897 | } | 915 | } |
898 | } | 916 | } |
899 | } | 917 | } |
900 | 918 | ||
901 | void KOMonthView::showDates(const QDate &start, const QDate &) | 919 | void KOMonthView::showDates(const QDate &start, const QDate &) |
902 | { | 920 | { |
903 | // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl; | 921 | // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl; |
904 | 922 | ||
905 | 923 | ||
906 | mStartDate = start; | 924 | mStartDate = start; |
907 | 925 | ||
908 | int startWeekDay = mWeekStartsMonday ? 1 : 7; | 926 | int startWeekDay = mWeekStartsMonday ? 1 : 7; |
909 | 927 | ||
910 | while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) { | 928 | while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) { |
911 | mStartDate = mStartDate.addDays( -1 ); | 929 | mStartDate = mStartDate.addDays( -1 ); |
912 | } | 930 | } |
913 | 931 | ||
914 | bool primary = false; | 932 | bool primary = false; |
915 | uint i; | 933 | uint i; |
916 | for( i = 0; i < mCells.size(); ++i ) { | 934 | for( i = 0; i < mCells.size(); ++i ) { |
917 | QDate date = mStartDate.addDays( i ); | 935 | QDate date = mStartDate.addDays( i ); |
918 | mCells[i]->setDate( date ); | 936 | mCells[i]->setDate( date ); |
919 | 937 | ||
920 | #ifndef KORG_NOPLUGINS | 938 | #ifndef KORG_NOPLUGINS |
921 | // add holiday, if present | 939 | // add holiday, if present |
922 | QString hstring(KOCore::self()->holiday(date)); | 940 | QString hstring(KOCore::self()->holiday(date)); |
923 | mCells[i]->setHoliday( hstring ); | 941 | mCells[i]->setHoliday( hstring ); |
924 | #endif | 942 | #endif |
925 | 943 | ||
926 | } | 944 | } |
927 | QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 ); | 945 | QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 ); |
928 | for( i = 0; i < 6; ++i ) { | 946 | for( i = 0; i < 6; ++i ) { |
929 | int wno; | 947 | int wno; |
930 | // remember, according to ISO 8601, the first week of the year is the | 948 | // remember, according to ISO 8601, the first week of the year is the |
931 | // first week that contains a thursday. Thus we must subtract off 4, | 949 | // first week that contains a thursday. Thus we must subtract off 4, |
932 | // not just 1. | 950 | // not just 1. |
933 | int dayOfYear = date.dayOfYear(); | 951 | int dayOfYear = date.dayOfYear(); |
934 | if (dayOfYear % 7 != 0) | 952 | if (dayOfYear % 7 != 0) |
935 | wno = dayOfYear / 7 + 1; | 953 | wno = dayOfYear / 7 + 1; |
936 | else | 954 | else |
937 | wno =dayOfYear / 7; | 955 | wno =dayOfYear / 7; |
938 | mWeekLabels[i]->setWeekNum( wno ); | 956 | mWeekLabels[i]->setWeekNum( wno ); |
939 | date = date.addDays( 7 ); | 957 | date = date.addDays( 7 ); |
940 | } | 958 | } |
941 | updateView(); | 959 | updateView(); |
942 | } | 960 | } |
943 | 961 | ||
944 | void KOMonthView::showEvents(QPtrList<Event>) | 962 | void KOMonthView::showEvents(QPtrList<Event>) |
945 | { | 963 | { |
946 | qDebug("KOMonthView::selectEvents is not implemented yet. "); | 964 | qDebug("KOMonthView::selectEvents is not implemented yet. "); |
947 | } | 965 | } |
948 | 966 | ||
949 | void KOMonthView::changeEventDisplay(Event *, int) | 967 | void KOMonthView::changeEventDisplay(Event *, int) |
950 | { | 968 | { |
951 | // this should be re-written to be much more efficient, but this | 969 | // this should be re-written to be much more efficient, but this |
952 | // quick-and-dirty-hack gets the job done for right now. | 970 | // quick-and-dirty-hack gets the job done for right now. |
953 | updateView(); | 971 | updateView(); |
954 | } | 972 | } |
955 | 973 | ||
956 | void KOMonthView::updateView() | 974 | void KOMonthView::updateView() |
957 | { | 975 | { |
958 | 976 | ||
959 | if ( !updatePossible ) | 977 | if ( !updatePossible ) |
960 | return; | 978 | return; |
979 | QTime ti; | ||
980 | ti.start(); | ||
981 | #if 1 | ||
982 | int i; | ||
983 | for( i = 0; i < mCells.count(); ++i ) { | ||
984 | mCells[i]->startUpdateCell(); | ||
985 | } | ||
986 | |||
987 | QPtrList<Event> events = calendar()->events(); | ||
988 | Event *event; | ||
989 | QDateTime dt; | ||
990 | bool ok; | ||
991 | int timeSpan = mCells.size()-1; | ||
992 | QDate endDate = mStartDate.addDays( timeSpan ); | ||
993 | for( event = events.first(); event; event = events.next() ) { // for event | ||
994 | if ( event->doesRecur() ) { | ||
995 | bool last; | ||
996 | QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); | ||
997 | QDateTime incidenceEnd; | ||
998 | int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); | ||
999 | bool invalid = false; | ||
1000 | while( true ) { | ||
1001 | if ( incidenceStart.isValid() ) { | ||
1002 | incidenceEnd = incidenceStart.addDays( eventlen ); | ||
1003 | int st = incidenceStart.date().daysTo( endDate ); | ||
1004 | if ( st >= 0 ) { // start before timeend | ||
1005 | int end = mStartDate.daysTo( incidenceEnd.date() ); | ||
1006 | if ( end >= 0 ) { // end after timestart --- got one! | ||
1007 | //normalize | ||
1008 | st = timeSpan - st; | ||
1009 | if ( st < 0 ) st = 0; | ||
1010 | if ( end > timeSpan ) end = timeSpan; | ||
1011 | int iii; | ||
1012 | //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); | ||
1013 | for ( iii = st;iii<= end;++iii) | ||
1014 | mCells[iii]->insertEvent( event ); | ||
1015 | } | ||
1016 | } | ||
1017 | } else { | ||
1018 | if ( invalid ) | ||
1019 | break; | ||
1020 | invalid = true; | ||
1021 | //qDebug("invalid %s", event->summary().latin1()); | ||
1022 | incidenceStart = QDateTime( mStartDate ); | ||
1023 | } | ||
1024 | if ( last ) | ||
1025 | break; | ||
1026 | bool ok; | ||
1027 | incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); | ||
1028 | if ( ! ok ) | ||
1029 | break; | ||
1030 | if ( incidenceStart.date() > endDate ) | ||
1031 | break; | ||
1032 | } | ||
1033 | } else { // no recur | ||
1034 | int st = event->dtStart().date().daysTo( endDate ); | ||
1035 | if ( st >= 0 ) { // start before timeend | ||
1036 | int end = mStartDate.daysTo( event->dtEnd().date() ); | ||
1037 | if ( end >= 0 ) { // end after timestart --- got one! | ||
1038 | //normalize | ||
1039 | st = timeSpan - st; | ||
1040 | if ( st < 0 ) st = 0; | ||
1041 | if ( end > timeSpan ) end = timeSpan; | ||
1042 | int iii; | ||
1043 | for ( iii = st;iii<= end;++iii) | ||
1044 | mCells[iii]->insertEvent( event ); | ||
1045 | } | ||
1046 | } | ||
1047 | } | ||
1048 | } | ||
1049 | // insert due todos | ||
1050 | QPtrList<Todo> todos = calendar()->todos( ); | ||
1051 | Todo *todo; | ||
1052 | for(todo = todos.first(); todo; todo = todos.next()) { | ||
1053 | //insertTodo( todo ); | ||
1054 | if ( todo->hasDueDate() ) { | ||
1055 | int day = mStartDate.daysTo( todo->dtDue().date() ); | ||
1056 | if ( day >= 0 && day < mCells.size() ) { | ||
1057 | mCells[day]->insertTodo( todo ); | ||
1058 | } | ||
1059 | } | ||
1060 | } | ||
1061 | |||
1062 | for( i = 0; i < mCells.count(); ++i ) { | ||
1063 | mCells[i]->finishUpdateCell(); | ||
1064 | } | ||
1065 | processSelectionChange(); | ||
1066 | mCells[0]->setFocus(); | ||
1067 | |||
1068 | |||
1069 | #else | ||
1070 | // old code | ||
961 | //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "); | 1071 | //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "); |
962 | int i; | 1072 | int i; |
963 | for( i = 0; i < mCells.count(); ++i ) { | 1073 | for( i = 0; i < mCells.count(); ++i ) { |
964 | mCells[i]->updateCell(); | 1074 | mCells[i]->updateCell(); |
965 | } | 1075 | } |
966 | 1076 | ||
967 | //qDebug("KOMonthView::updateView() "); | 1077 | //qDebug("KOMonthView::updateView() "); |
968 | processSelectionChange(); | 1078 | processSelectionChange(); |
969 | // qDebug("---------------------------------------------------------------------+ "); | 1079 | // qDebug("---------------------------------------------------------------------+ "); |
970 | mCells[0]->setFocus(); | 1080 | mCells[0]->setFocus(); |
1081 | #endif | ||
1082 | |||
1083 | qDebug("update time %d ", ti.elapsed()); | ||
971 | } | 1084 | } |
972 | 1085 | ||
973 | void KOMonthView::resizeEvent(QResizeEvent * e) | 1086 | void KOMonthView::resizeEvent(QResizeEvent * e) |
974 | { | 1087 | { |
975 | computeLayout(); | 1088 | computeLayout(); |
976 | mCells[0]->setFocus(); | 1089 | mCells[0]->setFocus(); |
977 | } | 1090 | } |
978 | void KOMonthView::computeLayout() | 1091 | void KOMonthView::computeLayout() |
979 | { | 1092 | { |
980 | // select the appropriate heading string size. E.g. "Wednesday" or "Wed". | 1093 | // select the appropriate heading string size. E.g. "Wednesday" or "Wed". |
981 | // note this only changes the text if the requested size crosses the | 1094 | // note this only changes the text if the requested size crosses the |
982 | // threshold between big enough to support the full name and not big | 1095 | // threshold between big enough to support the full name and not big |
983 | // enough. | 1096 | // enough. |
984 | 1097 | ||
985 | int daysToShow = 7; | 1098 | int daysToShow = 7; |
986 | bool combinedSatSun = false; | 1099 | bool combinedSatSun = false; |
987 | if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { | 1100 | if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { |
988 | daysToShow = 6; | 1101 | daysToShow = 6; |
989 | combinedSatSun = true; | 1102 | combinedSatSun = true; |
990 | } | 1103 | } |
991 | int tWid = topLevelWidget()->size().width(); | 1104 | int tWid = topLevelWidget()->size().width(); |
992 | int tHei = topLevelWidget()->size().height(); | 1105 | int tHei = topLevelWidget()->size().height(); |
993 | 1106 | ||
994 | int wid = size().width();//e | 1107 | int wid = size().width();//e |
995 | int hei = size().height()-1; | 1108 | int hei = size().height()-1; |
996 | 1109 | ||
997 | if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) | 1110 | if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) |
998 | return; | 1111 | return; |
999 | //qDebug("KOMonthView::computeLayout()------------------------------------ "); | 1112 | //qDebug("KOMonthView::computeLayout()------------------------------------ "); |
1000 | QFontMetrics fm ( mWeekLabels[0]->font() ); | 1113 | QFontMetrics fm ( mWeekLabels[0]->font() ); |
1001 | int weeklabelwid = fm.width( "888" ); | 1114 | int weeklabelwid = fm.width( "888" ); |
1002 | wid -= weeklabelwid; | 1115 | wid -= weeklabelwid; |
1003 | 1116 | ||
1004 | int colWid = wid / daysToShow; | 1117 | int colWid = wid / daysToShow; |
1005 | int lastCol = wid - ( colWid*6 ); | 1118 | int lastCol = wid - ( colWid*6 ); |
1006 | int dayLabelHei = mDayLabels[0]->sizeHint().height(); | 1119 | int dayLabelHei = mDayLabels[0]->sizeHint().height(); |
1007 | int cellHei = (hei - dayLabelHei) /6; | 1120 | int cellHei = (hei - dayLabelHei) /6; |
1008 | int colModulo = wid % daysToShow; | 1121 | int colModulo = wid % daysToShow; |
1009 | int rowModulo = (hei- dayLabelHei) % 6; | 1122 | int rowModulo = (hei- dayLabelHei) % 6; |
1010 | //qDebug("rowmod %d ", rowModulo); | 1123 | //qDebug("rowmod %d ", rowModulo); |
1011 | int i; | 1124 | int i; |
1012 | int x,y,w,h; | 1125 | int x,y,w,h; |
1013 | x= 0; | 1126 | x= 0; |
1014 | y= 0; | 1127 | y= 0; |
1015 | w = colWid; | 1128 | w = colWid; |
1016 | h = dayLabelHei ; | 1129 | h = dayLabelHei ; |
1017 | for ( i = 0; i < 7; i++) { | 1130 | for ( i = 0; i < 7; i++) { |
1018 | if ( i == daysToShow-colModulo ) | 1131 | if ( i == daysToShow-colModulo ) |
1019 | ++w; | 1132 | ++w; |
1020 | if ( combinedSatSun ) { | 1133 | if ( combinedSatSun ) { |
1021 | if ( i >= daysToShow-1 ) { | 1134 | if ( i >= daysToShow-1 ) { |
1022 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h); | 1135 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h); |
1023 | x -= w/2 ; | 1136 | x -= w/2 ; |
1024 | } | 1137 | } |
1025 | else | 1138 | else |
1026 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); | 1139 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); |
1027 | } else | 1140 | } else |
1028 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); | 1141 | mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); |
1029 | x += w; | 1142 | x += w; |
1030 | } | 1143 | } |
1031 | x= 0; | 1144 | x= 0; |
1032 | y= dayLabelHei; | 1145 | y= dayLabelHei; |
1033 | w = colWid; | 1146 | w = colWid; |
1034 | h = cellHei ; | 1147 | h = cellHei ; |
1035 | for ( i = 0; i < mCells.count(); ++i) { | 1148 | for ( i = 0; i < mCells.count(); ++i) { |
1036 | 1149 | ||
1037 | w = colWid; | 1150 | w = colWid; |
1038 | if ( ((i) % 7) >= 7-colModulo ) { | 1151 | if ( ((i) % 7) >= 7-colModulo ) { |
1039 | ++w; | 1152 | ++w; |
1040 | } | 1153 | } |
1041 | if ( i == (6-rowModulo)*7) | 1154 | if ( i == (6-rowModulo)*7) |
1042 | ++h; | 1155 | ++h; |
1043 | if ( combinedSatSun ) { | 1156 | if ( combinedSatSun ) { |
1044 | if ( (i)%7 >= daysToShow-1 ) { | 1157 | if ( (i)%7 >= daysToShow-1 ) { |
1045 | if ( (i)%7 == daysToShow-1 ) { | 1158 | if ( (i)%7 == daysToShow-1 ) { |
1046 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h/2 ); | 1159 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h/2 ); |
1047 | x -= w ;y += h/2; | 1160 | x -= w ;y += h/2; |
1048 | } else { | 1161 | } else { |
1049 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h-h/2 ); | 1162 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h-h/2 ); |
1050 | y -= h/2; | 1163 | y -= h/2; |
1051 | } | 1164 | } |
1052 | } else | 1165 | } else |
1053 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); | 1166 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); |
1054 | 1167 | ||
1055 | } | 1168 | } |
1056 | else | 1169 | else |
1057 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); | 1170 | mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); |
1058 | x += w; | 1171 | x += w; |
1059 | if ( x + w/2 > wid ) { | 1172 | if ( x + w/2 > wid ) { |
1060 | x = 0; | 1173 | x = 0; |
1061 | y += h; | 1174 | y += h; |
1062 | } | 1175 | } |
1063 | } | 1176 | } |
1064 | y= dayLabelHei; | 1177 | y= dayLabelHei; |
1065 | h = cellHei ; | 1178 | h = cellHei ; |
1066 | for ( i = 0; i < 6; i++) { | 1179 | for ( i = 0; i < 6; i++) { |
1067 | if ( i == (6-rowModulo)) | 1180 | if ( i == (6-rowModulo)) |
1068 | ++h; | 1181 | ++h; |
1069 | mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h); | 1182 | mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h); |
1070 | y += h; | 1183 | y += h; |
1071 | } | 1184 | } |
1072 | mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei); | 1185 | mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei); |
1073 | // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); | 1186 | // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); |
1074 | //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); | 1187 | //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); |
1075 | mShortDayLabels = mDayLabels[0]->width() < mWidthLongDayLabel ; | 1188 | mShortDayLabels = mDayLabels[0]->width() < mWidthLongDayLabel ; |
1076 | updateDayLabels(); | 1189 | updateDayLabels(); |
1077 | bool forceUpdate = !updatePossible; | 1190 | bool forceUpdate = !updatePossible; |
1078 | updatePossible = true; | 1191 | updatePossible = true; |
1079 | if ( forceUpdate ) | 1192 | if ( forceUpdate ) |
1080 | updateView(); | 1193 | updateView(); |
1081 | } | 1194 | } |
1082 | 1195 | ||
1083 | void KOMonthView::showContextMenu( Incidence *incidence ) | 1196 | void KOMonthView::showContextMenu( Incidence *incidence ) |
1084 | { | 1197 | { |
1085 | mContextMenu->showIncidencePopup(incidence); | 1198 | mContextMenu->showIncidencePopup(incidence); |
1086 | /* | 1199 | /* |
1087 | if( incidence && incidence->type() == "Event" ) { | 1200 | if( incidence && incidence->type() == "Event" ) { |
1088 | Event *event = static_cast<Event *>(incidence); | 1201 | Event *event = static_cast<Event *>(incidence); |
1089 | mContextMenu->showEventPopup(event); | 1202 | mContextMenu->showEventPopup(event); |
1090 | } else { | 1203 | } else { |
1091 | kdDebug() << "MonthView::showContextMenu(): cast failed." << endl; | 1204 | kdDebug() << "MonthView::showContextMenu(): cast failed." << endl; |
1092 | } | 1205 | } |
1093 | */ | 1206 | */ |
1094 | } | 1207 | } |
1095 | MonthViewCell * KOMonthView::selectedCell( ) | 1208 | MonthViewCell * KOMonthView::selectedCell( ) |
1096 | { | 1209 | { |
1097 | return mSelectedCell; | 1210 | return mSelectedCell; |
1098 | } | 1211 | } |
1099 | void KOMonthView::setSelectedCell( MonthViewCell *cell ) | 1212 | void KOMonthView::setSelectedCell( MonthViewCell *cell ) |
1100 | { | 1213 | { |
1101 | // qDebug("KOMonthView::setSelectedCell "); | 1214 | // qDebug("KOMonthView::setSelectedCell "); |
1102 | if ( mSelectedCell && mSelectedCell != cell ) { | 1215 | if ( mSelectedCell && mSelectedCell != cell ) { |
1103 | MonthViewCell * mvc = mSelectedCell; | 1216 | MonthViewCell * mvc = mSelectedCell; |
1104 | mSelectedCell = cell; | 1217 | mSelectedCell = cell; |
1105 | mvc->deselect(); | 1218 | mvc->deselect(); |
1106 | } else | 1219 | } else |
1107 | mSelectedCell = cell; | 1220 | mSelectedCell = cell; |
1108 | // if ( mSelectedCell ) | 1221 | // if ( mSelectedCell ) |
1109 | // mSelectedCell->select(); | 1222 | // mSelectedCell->select(); |
1110 | if ( !mSelectedCell ) | 1223 | if ( !mSelectedCell ) |
1111 | emit incidenceSelected( 0 ); | 1224 | emit incidenceSelected( 0 ); |
1112 | else | 1225 | else |
1113 | emit incidenceSelected( mSelectedCell->selectedIncidence() ); | 1226 | emit incidenceSelected( mSelectedCell->selectedIncidence() ); |
1114 | } | 1227 | } |
1115 | 1228 | ||
1116 | void KOMonthView::processSelectionChange() | 1229 | void KOMonthView::processSelectionChange() |
1117 | { | 1230 | { |
1118 | QPtrList<Incidence> incidences = selectedIncidences(); | 1231 | QPtrList<Incidence> incidences = selectedIncidences(); |
1119 | if (incidences.count() > 0) { | 1232 | if (incidences.count() > 0) { |
1120 | emit incidenceSelected( incidences.first() ); | 1233 | emit incidenceSelected( incidences.first() ); |
1121 | } else { | 1234 | } else { |
1122 | emit incidenceSelected( 0 ); | 1235 | emit incidenceSelected( 0 ); |
1123 | } | 1236 | } |
1124 | } | 1237 | } |
1125 | 1238 | ||
1126 | void KOMonthView::clearSelection() | 1239 | void KOMonthView::clearSelection() |
1127 | { | 1240 | { |
1128 | if ( mSelectedCell ) { | 1241 | if ( mSelectedCell ) { |
1129 | mSelectedCell->deselect(); | 1242 | mSelectedCell->deselect(); |
1130 | mSelectedCell = 0; | 1243 | mSelectedCell = 0; |
1131 | } | 1244 | } |
1132 | } | 1245 | } |
1133 | void KOMonthView::keyPressEvent ( QKeyEvent * e ) | 1246 | void KOMonthView::keyPressEvent ( QKeyEvent * e ) |
1134 | { | 1247 | { |
1135 | //qDebug("KOMonthView::keyPressEvent "); | 1248 | //qDebug("KOMonthView::keyPressEvent "); |
1136 | switch(e->key()) { | 1249 | switch(e->key()) { |
1137 | case Key_Up: | 1250 | case Key_Up: |
1138 | { | 1251 | { |
1139 | emit prevMonth(); | 1252 | emit prevMonth(); |
1140 | mCells[0]->setFocus(); | 1253 | mCells[0]->setFocus(); |
1141 | } | 1254 | } |
1142 | e->accept(); | 1255 | e->accept(); |
1143 | break; | 1256 | break; |
1144 | case Key_Down: | 1257 | case Key_Down: |
1145 | { | 1258 | { |
1146 | emit nextMonth(); | 1259 | emit nextMonth(); |
1147 | mCells[0]->setFocus(); | 1260 | mCells[0]->setFocus(); |
1148 | 1261 | ||
1149 | } | 1262 | } |
1150 | e->accept(); | 1263 | e->accept(); |
1151 | break; | 1264 | break; |
1152 | default: | 1265 | default: |
1153 | e->ignore(); | 1266 | e->ignore(); |
1154 | break; | 1267 | break; |
1155 | } | 1268 | } |
1156 | } | 1269 | } |
diff --git a/korganizer/komonthview.h b/korganizer/komonthview.h index 50903b3..b84065e 100644 --- a/korganizer/komonthview.h +++ b/korganizer/komonthview.h | |||
@@ -1,274 +1,279 @@ | |||
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 | #ifndef _KOMONTHVIEW_H | 20 | #ifndef _KOMONTHVIEW_H |
21 | #define _KOMONTHVIEW_H | 21 | #define _KOMONTHVIEW_H |
22 | 22 | ||
23 | #include <qlabel.h> | 23 | #include <qlabel.h> |
24 | #include <qframe.h> | 24 | #include <qframe.h> |
25 | #include <qdatetime.h> | 25 | #include <qdatetime.h> |
26 | #include <qlistbox.h> | 26 | #include <qlistbox.h> |
27 | #include <qpoint.h> | 27 | #include <qpoint.h> |
28 | #include <qlayout.h> | 28 | #include <qlayout.h> |
29 | #include <qintdict.h> | 29 | #include <qintdict.h> |
30 | #include <qpushbutton.h> | 30 | #include <qpushbutton.h> |
31 | #include <qvaluelist.h> | 31 | #include <qvaluelist.h> |
32 | #include <qptrvector.h> | 32 | #include <qptrvector.h> |
33 | 33 | ||
34 | #include <libkcal/calendar.h> | 34 | #include <libkcal/calendar.h> |
35 | #include <libkcal/event.h> | 35 | #include <libkcal/event.h> |
36 | 36 | ||
37 | #include "koeventview.h" | 37 | #include "koeventview.h" |
38 | 38 | ||
39 | #ifdef DESKTOP_VERSION | 39 | #ifdef DESKTOP_VERSION |
40 | class QToolTipGroup; | 40 | class QToolTipGroup; |
41 | #endif | 41 | #endif |
42 | 42 | ||
43 | class KNOWhatsThis; | 43 | class KNOWhatsThis; |
44 | class KOWeekButton : public QPushButton | 44 | class KOWeekButton : public QPushButton |
45 | { | 45 | { |
46 | Q_OBJECT | 46 | Q_OBJECT |
47 | public: | 47 | public: |
48 | KOWeekButton( QWidget *parent=0, const char *name=0 ) : | 48 | KOWeekButton( QWidget *parent=0, const char *name=0 ) : |
49 | QPushButton( parent, name) | 49 | QPushButton( parent, name) |
50 | { | 50 | { |
51 | connect( this, SIGNAL( clicked() ), | 51 | connect( this, SIGNAL( clicked() ), |
52 | SLOT( bottonClicked() )); | 52 | SLOT( bottonClicked() )); |
53 | mNumber = -1; | 53 | mNumber = -1; |
54 | } | 54 | } |
55 | void setWeekNum ( int num ) {mNumber = num; setText( QString::number ( num ));} | 55 | void setWeekNum ( int num ) {mNumber = num; setText( QString::number ( num ));} |
56 | signals: | 56 | signals: |
57 | void selectWeekNum ( int ); | 57 | void selectWeekNum ( int ); |
58 | private: | 58 | private: |
59 | int mNumber; | 59 | int mNumber; |
60 | private slots : | 60 | private slots : |
61 | void bottonClicked() { if ( mNumber > 0 ) emit selectWeekNum ( mNumber ); } | 61 | void bottonClicked() { if ( mNumber > 0 ) emit selectWeekNum ( mNumber ); } |
62 | }; | 62 | }; |
63 | 63 | ||
64 | class KNoScrollListBox: public QListBox | 64 | class KNoScrollListBox: public QListBox |
65 | { | 65 | { |
66 | Q_OBJECT | 66 | Q_OBJECT |
67 | public: | 67 | public: |
68 | KNoScrollListBox(QWidget *parent=0, const char *name=0); | 68 | KNoScrollListBox(QWidget *parent=0, const char *name=0); |
69 | ~KNoScrollListBox(); | 69 | ~KNoScrollListBox(); |
70 | QString getWhatsThisText(QPoint p) ; | 70 | QString getWhatsThisText(QPoint p) ; |
71 | 71 | ||
72 | signals: | 72 | signals: |
73 | void shiftDown(); | 73 | void shiftDown(); |
74 | void shiftUp(); | 74 | void shiftUp(); |
75 | void rightClick(); | 75 | void rightClick(); |
76 | 76 | ||
77 | protected slots: | 77 | protected slots: |
78 | void keyPressEvent(QKeyEvent *); | 78 | void keyPressEvent(QKeyEvent *); |
79 | void keyReleaseEvent(QKeyEvent *); | 79 | void keyReleaseEvent(QKeyEvent *); |
80 | void mousePressEvent(QMouseEvent *); | 80 | void mousePressEvent(QMouseEvent *); |
81 | 81 | ||
82 | private: | 82 | private: |
83 | KNOWhatsThis * mWT; | 83 | KNOWhatsThis * mWT; |
84 | }; | 84 | }; |
85 | 85 | ||
86 | 86 | ||
87 | class MonthViewItem: public QListBoxItem | 87 | class MonthViewItem: public QListBoxItem |
88 | { | 88 | { |
89 | public: | 89 | public: |
90 | MonthViewItem( Incidence *, QDate qd, const QString & title ); | 90 | MonthViewItem( Incidence *, QDate qd, const QString & title ); |
91 | 91 | ||
92 | void setRecur(bool on) { mRecur = on; } | 92 | void setRecur(bool on) { mRecur = on; } |
93 | void setAlarm(bool on) { mAlarm = on; } | 93 | void setAlarm(bool on) { mAlarm = on; } |
94 | void setReply(bool on) { mReply = on; } | 94 | void setReply(bool on) { mReply = on; } |
95 | void setMoreInfo(bool on) { mInfo = on; } | 95 | void setMoreInfo(bool on) { mInfo = on; } |
96 | 96 | ||
97 | 97 | ||
98 | void setPalette(const QPalette &p) { mPalette = p; } | 98 | void setPalette(const QPalette &p) { mPalette = p; } |
99 | QPalette palette() const { return mPalette; } | 99 | QPalette palette() const { return mPalette; } |
100 | 100 | ||
101 | Incidence *incidence() const { return mIncidence; } | 101 | Incidence *incidence() const { return mIncidence; } |
102 | QDate incidenceDate() { return mDate; } | 102 | QDate incidenceDate() { return mDate; } |
103 | 103 | ||
104 | protected: | 104 | protected: |
105 | virtual void paint(QPainter *); | 105 | virtual void paint(QPainter *); |
106 | virtual int height(const QListBox *) const; | 106 | virtual int height(const QListBox *) const; |
107 | virtual int width(const QListBox *) const; | 107 | virtual int width(const QListBox *) const; |
108 | 108 | ||
109 | private: | 109 | private: |
110 | bool mRecur; | 110 | bool mRecur; |
111 | bool mAlarm; | 111 | bool mAlarm; |
112 | bool mReply; | 112 | bool mReply; |
113 | bool mInfo; | 113 | bool mInfo; |
114 | 114 | ||
115 | QPalette mPalette; | 115 | QPalette mPalette; |
116 | QDate mDate; | 116 | QDate mDate; |
117 | 117 | ||
118 | Incidence *mIncidence; | 118 | Incidence *mIncidence; |
119 | }; | 119 | }; |
120 | 120 | ||
121 | 121 | ||
122 | class KOMonthView; | 122 | class KOMonthView; |
123 | 123 | ||
124 | class MonthViewCell : public QWidget | 124 | class MonthViewCell : public QWidget |
125 | { | 125 | { |
126 | Q_OBJECT | 126 | Q_OBJECT |
127 | public: | 127 | public: |
128 | MonthViewCell( KOMonthView * ); | 128 | MonthViewCell( KOMonthView * ); |
129 | 129 | ||
130 | void setDate( const QDate & ); | 130 | void setDate( const QDate & ); |
131 | QDate date() const; | 131 | QDate date() const; |
132 | 132 | ||
133 | void setPrimary( bool ); | 133 | void setPrimary( bool ); |
134 | bool isPrimary() const; | 134 | bool isPrimary() const; |
135 | 135 | ||
136 | void setHoliday( bool ); | 136 | void setHoliday( bool ); |
137 | void setHoliday( const QString & ); | 137 | void setHoliday( const QString & ); |
138 | 138 | ||
139 | void updateCell(); | 139 | void updateCell(); |
140 | void startUpdateCell(); | ||
141 | void finishUpdateCell(); | ||
142 | void insertEvent(Event *); | ||
143 | void insertTodo(Todo *); | ||
140 | 144 | ||
141 | void updateConfig(); | 145 | void updateConfig(); |
142 | 146 | ||
143 | void enableScrollBars( bool ); | 147 | void enableScrollBars( bool ); |
144 | 148 | ||
145 | Incidence *selectedIncidence(); | 149 | Incidence *selectedIncidence(); |
146 | QDate selectedIncidenceDate(); | 150 | QDate selectedIncidenceDate(); |
147 | 151 | ||
148 | void deselect(); | 152 | void deselect(); |
149 | void select(); | 153 | void select(); |
150 | void clear(); | 154 | void clear(); |
151 | 155 | ||
152 | #ifdef DESKTOP_VERSION | 156 | #ifdef DESKTOP_VERSION |
153 | static QToolTipGroup *toolTipGroup(); | 157 | static QToolTipGroup *toolTipGroup(); |
154 | #endif | 158 | #endif |
155 | signals: | 159 | signals: |
156 | void defaultAction( Incidence * ); | 160 | void defaultAction( Incidence * ); |
157 | void newEventSignal( QDateTime ); | 161 | void newEventSignal( QDateTime ); |
158 | void showDaySignal( QDate ); | 162 | void showDaySignal( QDate ); |
159 | 163 | ||
160 | protected: | 164 | protected: |
165 | QString mToolTip; | ||
161 | void resizeEvent( QResizeEvent * ); | 166 | void resizeEvent( QResizeEvent * ); |
162 | 167 | ||
163 | protected slots: | 168 | protected slots: |
164 | void defaultAction( QListBoxItem * ); | 169 | void defaultAction( QListBoxItem * ); |
165 | void contextMenu( QListBoxItem * ); | 170 | void contextMenu( QListBoxItem * ); |
166 | void selection( QListBoxItem * ); | 171 | void selection( QListBoxItem * ); |
167 | void cellClicked( QListBoxItem * ); | 172 | void cellClicked( QListBoxItem * ); |
168 | void newEvent(); | 173 | void newEvent(); |
169 | void showDay(); | 174 | void showDay(); |
170 | 175 | ||
171 | private: | 176 | private: |
172 | KOMonthView *mMonthView; | 177 | KOMonthView *mMonthView; |
173 | 178 | ||
174 | QDate mDate; | 179 | QDate mDate; |
175 | bool mPrimary; | 180 | bool mPrimary; |
176 | bool mHoliday; | 181 | bool mHoliday; |
177 | QString mHolidayString; | 182 | QString mHolidayString; |
178 | 183 | ||
179 | //QLabel *mLabel; | 184 | //QLabel *mLabel; |
180 | QPushButton *mLabel; | 185 | QPushButton *mLabel; |
181 | QListBox *mItemList; | 186 | QListBox *mItemList; |
182 | #ifdef DESKTOP_VERSION | 187 | #ifdef DESKTOP_VERSION |
183 | static QToolTipGroup *mToolTipGroup; | 188 | static QToolTipGroup *mToolTipGroup; |
184 | #endif | 189 | #endif |
185 | QSize mLabelSize; | 190 | QSize mLabelSize; |
186 | QSize mLabelBigSize; | 191 | QSize mLabelBigSize; |
187 | QPalette mHolidayPalette; | 192 | QPalette mHolidayPalette; |
188 | QPalette mStandardPalette; | 193 | QPalette mStandardPalette; |
189 | QPalette mPrimaryPalette; | 194 | QPalette mPrimaryPalette; |
190 | QPalette mNonPrimaryPalette; | 195 | QPalette mNonPrimaryPalette; |
191 | void setMyPalette(); | 196 | void setMyPalette(); |
192 | QPalette getPalette (); | 197 | QPalette getPalette (); |
193 | void keyPressEvent ( QKeyEvent * ) ; | 198 | void keyPressEvent ( QKeyEvent * ) ; |
194 | 199 | ||
195 | }; | 200 | }; |
196 | 201 | ||
197 | 202 | ||
198 | class KOMonthView: public KOEventView | 203 | class KOMonthView: public KOEventView |
199 | { | 204 | { |
200 | Q_OBJECT | 205 | Q_OBJECT |
201 | public: | 206 | public: |
202 | KOMonthView(Calendar *cal, QWidget *parent = 0, const char *name = 0 ); | 207 | KOMonthView(Calendar *cal, QWidget *parent = 0, const char *name = 0 ); |
203 | ~KOMonthView(); | 208 | ~KOMonthView(); |
204 | 209 | ||
205 | /** Returns maximum number of days supported by the komonthview */ | 210 | /** Returns maximum number of days supported by the komonthview */ |
206 | virtual int maxDatesHint(); | 211 | virtual int maxDatesHint(); |
207 | 212 | ||
208 | /** Returns number of currently shown dates. */ | 213 | /** Returns number of currently shown dates. */ |
209 | virtual int currentDateCount(); | 214 | virtual int currentDateCount(); |
210 | 215 | ||
211 | /** returns the currently selected events */ | 216 | /** returns the currently selected events */ |
212 | virtual QPtrList<Incidence> selectedIncidences(); | 217 | virtual QPtrList<Incidence> selectedIncidences(); |
213 | 218 | ||
214 | /** returns dates of the currently selected events */ | 219 | /** returns dates of the currently selected events */ |
215 | virtual DateList selectedDates(); | 220 | virtual DateList selectedDates(); |
216 | 221 | ||
217 | virtual void printPreview(CalPrinter *calPrinter, | 222 | virtual void printPreview(CalPrinter *calPrinter, |
218 | const QDate &, const QDate &); | 223 | const QDate &, const QDate &); |
219 | bool isMonthView() { return true; } | 224 | bool isMonthView() { return true; } |
220 | bool isUpdatePossible() { return updatePossible; } | 225 | bool isUpdatePossible() { return updatePossible; } |
221 | 226 | ||
222 | MonthViewCell * selectedCell(); | 227 | MonthViewCell * selectedCell(); |
223 | public slots: | 228 | public slots: |
224 | virtual void updateView(); | 229 | virtual void updateView(); |
225 | virtual void updateConfig(); | 230 | virtual void updateConfig(); |
226 | virtual void showDates(const QDate &start, const QDate &end); | 231 | virtual void showDates(const QDate &start, const QDate &end); |
227 | virtual void showEvents(QPtrList<Event> eventList); | 232 | virtual void showEvents(QPtrList<Event> eventList); |
228 | 233 | ||
229 | void changeEventDisplay(Event *, int); | 234 | void changeEventDisplay(Event *, int); |
230 | 235 | ||
231 | void clearSelection(); | 236 | void clearSelection(); |
232 | 237 | ||
233 | void showContextMenu( Incidence * ); | 238 | void showContextMenu( Incidence * ); |
234 | 239 | ||
235 | void setSelectedCell( MonthViewCell * ); | 240 | void setSelectedCell( MonthViewCell * ); |
236 | 241 | ||
237 | protected slots: | 242 | protected slots: |
238 | void processSelectionChange(); | 243 | void processSelectionChange(); |
239 | signals: | 244 | signals: |
240 | void nextMonth(); | 245 | void nextMonth(); |
241 | void prevMonth(); | 246 | void prevMonth(); |
242 | void selectWeekNum ( int ); | 247 | void selectWeekNum ( int ); |
243 | void showDaySignal( QDate ); | 248 | void showDaySignal( QDate ); |
244 | protected: | 249 | protected: |
245 | void resizeEvent(QResizeEvent *); | 250 | void resizeEvent(QResizeEvent *); |
246 | void viewChanged(); | 251 | void viewChanged(); |
247 | void updateDayLabels(); | 252 | void updateDayLabels(); |
248 | 253 | ||
249 | private: | 254 | private: |
250 | bool updatePossible; | 255 | bool updatePossible; |
251 | int mDaysPerWeek; | 256 | int mDaysPerWeek; |
252 | int mNumWeeks; | 257 | int mNumWeeks; |
253 | int mNumCells; | 258 | int mNumCells; |
254 | bool mWeekStartsMonday; | 259 | bool mWeekStartsMonday; |
255 | bool mShowSatSunComp; | 260 | bool mShowSatSunComp; |
256 | void computeLayout(); | 261 | void computeLayout(); |
257 | 262 | ||
258 | QPtrVector<MonthViewCell> mCells; | 263 | QPtrVector<MonthViewCell> mCells; |
259 | QPtrVector<QLabel> mDayLabels; | 264 | QPtrVector<QLabel> mDayLabels; |
260 | QPtrVector<KOWeekButton> mWeekLabels; | 265 | QPtrVector<KOWeekButton> mWeekLabels; |
261 | 266 | ||
262 | bool mShortDayLabels; | 267 | bool mShortDayLabels; |
263 | int mWidthLongDayLabel; | 268 | int mWidthLongDayLabel; |
264 | 269 | ||
265 | QDate mStartDate; | 270 | QDate mStartDate; |
266 | 271 | ||
267 | MonthViewCell *mSelectedCell; | 272 | MonthViewCell *mSelectedCell; |
268 | 273 | ||
269 | KOEventPopupMenu *mContextMenu; | 274 | KOEventPopupMenu *mContextMenu; |
270 | void keyPressEvent ( QKeyEvent * ) ; | 275 | void keyPressEvent ( QKeyEvent * ) ; |
271 | 276 | ||
272 | }; | 277 | }; |
273 | 278 | ||
274 | #endif | 279 | #endif |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 0eba6a9..e75154b 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,724 +1,725 @@ | |||
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 | close(); | 68 | close(); |
69 | } | 69 | } |
70 | 70 | ||
71 | bool CalendarLocal::load( const QString &fileName ) | 71 | bool CalendarLocal::load( const QString &fileName ) |
72 | { | 72 | { |
73 | FileStorage storage( this, fileName ); | 73 | FileStorage storage( this, fileName ); |
74 | return storage.load(); | 74 | return storage.load(); |
75 | } | 75 | } |
76 | 76 | ||
77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
78 | { | 78 | { |
79 | FileStorage storage( this, fileName, format ); | 79 | FileStorage storage( this, fileName, format ); |
80 | return storage.save(); | 80 | return storage.save(); |
81 | } | 81 | } |
82 | 82 | ||
83 | void CalendarLocal::close() | 83 | void CalendarLocal::close() |
84 | { | 84 | { |
85 | mEventList.setAutoDelete( true ); | 85 | mEventList.setAutoDelete( true ); |
86 | mTodoList.setAutoDelete( true ); | 86 | mTodoList.setAutoDelete( true ); |
87 | mJournalList.setAutoDelete( false ); | 87 | mJournalList.setAutoDelete( false ); |
88 | 88 | ||
89 | mEventList.clear(); | 89 | mEventList.clear(); |
90 | mTodoList.clear(); | 90 | mTodoList.clear(); |
91 | mJournalList.clear(); | 91 | mJournalList.clear(); |
92 | 92 | ||
93 | mEventList.setAutoDelete( false ); | 93 | mEventList.setAutoDelete( false ); |
94 | mTodoList.setAutoDelete( false ); | 94 | mTodoList.setAutoDelete( false ); |
95 | mJournalList.setAutoDelete( false ); | 95 | mJournalList.setAutoDelete( false ); |
96 | 96 | ||
97 | setModified( false ); | 97 | setModified( false ); |
98 | } | 98 | } |
99 | 99 | ||
100 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 100 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
101 | { | 101 | { |
102 | QString cat; | 102 | QString cat; |
103 | bool isBirthday = true; | 103 | bool isBirthday = true; |
104 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 104 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
105 | isBirthday = false; | 105 | isBirthday = false; |
106 | cat = i18n( "Anniversary" ); | 106 | cat = i18n( "Anniversary" ); |
107 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 107 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
108 | isBirthday = true; | 108 | isBirthday = true; |
109 | cat = i18n( "Birthday" ); | 109 | cat = i18n( "Birthday" ); |
110 | } else { | 110 | } else { |
111 | qDebug("addAnniversaryNoDup called without fitting category! "); | 111 | qDebug("addAnniversaryNoDup called without fitting category! "); |
112 | return false; | 112 | return false; |
113 | } | 113 | } |
114 | Event * eve; | 114 | Event * eve; |
115 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 115 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
116 | if ( !(eve->categories().contains( cat ) )) | 116 | if ( !(eve->categories().contains( cat ) )) |
117 | continue; | 117 | continue; |
118 | // now we have an event with fitting category | 118 | // now we have an event with fitting category |
119 | if ( eve->dtStart().date() != event->dtStart().date() ) | 119 | if ( eve->dtStart().date() != event->dtStart().date() ) |
120 | continue; | 120 | continue; |
121 | // now we have an event with fitting category+date | 121 | // now we have an event with fitting category+date |
122 | if ( eve->summary() != event->summary() ) | 122 | if ( eve->summary() != event->summary() ) |
123 | continue; | 123 | continue; |
124 | // now we have an event with fitting category+date+summary | 124 | // now we have an event with fitting category+date+summary |
125 | return false; | 125 | return false; |
126 | } | 126 | } |
127 | return addEvent( event ); | 127 | return addEvent( event ); |
128 | 128 | ||
129 | } | 129 | } |
130 | bool CalendarLocal::addEventNoDup( Event *event ) | 130 | bool CalendarLocal::addEventNoDup( Event *event ) |
131 | { | 131 | { |
132 | Event * eve; | 132 | Event * eve; |
133 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 133 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
134 | if ( *eve == *event ) { | 134 | if ( *eve == *event ) { |
135 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 135 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
136 | return false; | 136 | return false; |
137 | } | 137 | } |
138 | } | 138 | } |
139 | return addEvent( event ); | 139 | return addEvent( event ); |
140 | } | 140 | } |
141 | 141 | ||
142 | bool CalendarLocal::addEvent( Event *event ) | 142 | bool CalendarLocal::addEvent( Event *event ) |
143 | { | 143 | { |
144 | insertEvent( event ); | 144 | insertEvent( event ); |
145 | 145 | ||
146 | event->registerObserver( this ); | 146 | event->registerObserver( this ); |
147 | 147 | ||
148 | setModified( true ); | 148 | setModified( true ); |
149 | 149 | ||
150 | return true; | 150 | return true; |
151 | } | 151 | } |
152 | 152 | ||
153 | void CalendarLocal::deleteEvent( Event *event ) | 153 | void CalendarLocal::deleteEvent( Event *event ) |
154 | { | 154 | { |
155 | if ( mUndoIncidence ) delete mUndoIncidence; | 155 | if ( mUndoIncidence ) delete mUndoIncidence; |
156 | mUndoIncidence = event->clone(); | 156 | mUndoIncidence = event->clone(); |
157 | if ( mEventList.removeRef( event ) ) { | 157 | if ( mEventList.removeRef( event ) ) { |
158 | setModified( true ); | 158 | setModified( true ); |
159 | } | 159 | } |
160 | } | 160 | } |
161 | 161 | ||
162 | 162 | ||
163 | Event *CalendarLocal::event( const QString &uid ) | 163 | Event *CalendarLocal::event( const QString &uid ) |
164 | { | 164 | { |
165 | 165 | ||
166 | Event *event; | 166 | Event *event; |
167 | 167 | ||
168 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 168 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
169 | if ( event->uid() == uid ) { | 169 | if ( event->uid() == uid ) { |
170 | return event; | 170 | return event; |
171 | } | 171 | } |
172 | } | 172 | } |
173 | 173 | ||
174 | return 0; | 174 | return 0; |
175 | } | 175 | } |
176 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 176 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
177 | { | 177 | { |
178 | Todo * eve; | 178 | Todo * eve; |
179 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 179 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
180 | if ( *eve == *todo ) { | 180 | if ( *eve == *todo ) { |
181 | //qDebug("duplicate todo found! not inserted! "); | 181 | //qDebug("duplicate todo found! not inserted! "); |
182 | return false; | 182 | return false; |
183 | } | 183 | } |
184 | } | 184 | } |
185 | return addTodo( todo ); | 185 | return addTodo( todo ); |
186 | } | 186 | } |
187 | bool CalendarLocal::addTodo( Todo *todo ) | 187 | bool CalendarLocal::addTodo( Todo *todo ) |
188 | { | 188 | { |
189 | mTodoList.append( todo ); | 189 | mTodoList.append( todo ); |
190 | 190 | ||
191 | todo->registerObserver( this ); | 191 | todo->registerObserver( this ); |
192 | 192 | ||
193 | // Set up subtask relations | 193 | // Set up subtask relations |
194 | setupRelations( todo ); | 194 | setupRelations( todo ); |
195 | 195 | ||
196 | setModified( true ); | 196 | setModified( true ); |
197 | 197 | ||
198 | return true; | 198 | return true; |
199 | } | 199 | } |
200 | 200 | ||
201 | void CalendarLocal::deleteTodo( Todo *todo ) | 201 | void CalendarLocal::deleteTodo( Todo *todo ) |
202 | { | 202 | { |
203 | // Handle orphaned children | 203 | // Handle orphaned children |
204 | if ( mUndoIncidence ) delete mUndoIncidence; | 204 | if ( mUndoIncidence ) delete mUndoIncidence; |
205 | removeRelations( todo ); | 205 | removeRelations( todo ); |
206 | mUndoIncidence = todo->clone(); | 206 | mUndoIncidence = todo->clone(); |
207 | 207 | ||
208 | if ( mTodoList.removeRef( todo ) ) { | 208 | if ( mTodoList.removeRef( todo ) ) { |
209 | setModified( true ); | 209 | setModified( true ); |
210 | } | 210 | } |
211 | } | 211 | } |
212 | 212 | ||
213 | QPtrList<Todo> CalendarLocal::rawTodos() | 213 | QPtrList<Todo> CalendarLocal::rawTodos() |
214 | { | 214 | { |
215 | return mTodoList; | 215 | return mTodoList; |
216 | } | 216 | } |
217 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 217 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
218 | { | 218 | { |
219 | Todo *todo; | 219 | Todo *todo; |
220 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 220 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
221 | if ( todo->getID( syncProf ) == id ) return todo; | 221 | if ( todo->getID( syncProf ) == id ) return todo; |
222 | } | 222 | } |
223 | 223 | ||
224 | return 0; | 224 | return 0; |
225 | } | 225 | } |
226 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 226 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
227 | { | 227 | { |
228 | QPtrList<Incidence> all = rawIncidences() ; | 228 | QPtrList<Incidence> all = rawIncidences() ; |
229 | Incidence *inc; | 229 | Incidence *inc; |
230 | for ( inc = all.first(); inc; inc = all.next() ) { | 230 | for ( inc = all.first(); inc; inc = all.next() ) { |
231 | inc->removeID( syncProfile ); | 231 | inc->removeID( syncProfile ); |
232 | } | 232 | } |
233 | if ( syncProfile.isEmpty() ) { | 233 | if ( syncProfile.isEmpty() ) { |
234 | QPtrList<Event> el; | 234 | QPtrList<Event> el; |
235 | Event *todo; | 235 | Event *todo; |
236 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 236 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
237 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 237 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
238 | el.append( todo ); | 238 | el.append( todo ); |
239 | } | 239 | } |
240 | for ( todo = el.first(); todo; todo = el.next() ) { | 240 | for ( todo = el.first(); todo; todo = el.next() ) { |
241 | deleteIncidence ( todo ); | 241 | deleteIncidence ( todo ); |
242 | } | 242 | } |
243 | } else { | 243 | } else { |
244 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 244 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
245 | deleteIncidence ( lse ); | 245 | deleteIncidence ( lse ); |
246 | } | 246 | } |
247 | } | 247 | } |
248 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 248 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
249 | { | 249 | { |
250 | QPtrList<Event> el; | 250 | QPtrList<Event> el; |
251 | Event *todo; | 251 | Event *todo; |
252 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 252 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
253 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 253 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
254 | if ( todo->summary().left(3) == "E: " ) | 254 | if ( todo->summary().left(3) == "E: " ) |
255 | el.append( todo ); | 255 | el.append( todo ); |
256 | } | 256 | } |
257 | 257 | ||
258 | return el; | 258 | return el; |
259 | 259 | ||
260 | } | 260 | } |
261 | Event *CalendarLocal::event( QString syncProf, QString id ) | 261 | Event *CalendarLocal::event( QString syncProf, QString id ) |
262 | { | 262 | { |
263 | Event *todo; | 263 | Event *todo; |
264 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 264 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
265 | if ( todo->getID( syncProf ) == id ) return todo; | 265 | if ( todo->getID( syncProf ) == id ) return todo; |
266 | } | 266 | } |
267 | 267 | ||
268 | return 0; | 268 | return 0; |
269 | } | 269 | } |
270 | Todo *CalendarLocal::todo( const QString &uid ) | 270 | Todo *CalendarLocal::todo( const QString &uid ) |
271 | { | 271 | { |
272 | Todo *todo; | 272 | Todo *todo; |
273 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 273 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
274 | if ( todo->uid() == uid ) return todo; | 274 | if ( todo->uid() == uid ) return todo; |
275 | } | 275 | } |
276 | 276 | ||
277 | return 0; | 277 | return 0; |
278 | } | 278 | } |
279 | QString CalendarLocal::nextSummary() const | 279 | QString CalendarLocal::nextSummary() const |
280 | { | 280 | { |
281 | return mNextSummary; | 281 | return mNextSummary; |
282 | } | 282 | } |
283 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 283 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
284 | { | 284 | { |
285 | return mNextAlarmEventDateTime; | 285 | return mNextAlarmEventDateTime; |
286 | } | 286 | } |
287 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 287 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
288 | { | 288 | { |
289 | //mNextAlarmIncidence | 289 | //mNextAlarmIncidence |
290 | //mNextAlarmDateTime | 290 | //mNextAlarmDateTime |
291 | //return mNextSummary; | 291 | //return mNextSummary; |
292 | //return mNextAlarmEventDateTime; | 292 | //return mNextAlarmEventDateTime; |
293 | bool newNextAlarm = false; | 293 | bool newNextAlarm = false; |
294 | bool computeNextAlarm = false; | 294 | bool computeNextAlarm = false; |
295 | bool ok; | 295 | bool ok; |
296 | int offset; | 296 | int offset; |
297 | QDateTime nextA; | 297 | QDateTime nextA; |
298 | // QString nextSum; | 298 | // QString nextSum; |
299 | //QDateTime nextEvent; | 299 | //QDateTime nextEvent; |
300 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 300 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
301 | computeNextAlarm = true; | 301 | computeNextAlarm = true; |
302 | } else { | 302 | } else { |
303 | if ( ! deleted ) { | 303 | if ( ! deleted ) { |
304 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; | 304 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; |
305 | if ( ok ) { | 305 | if ( ok ) { |
306 | if ( nextA < mNextAlarmDateTime ) { | 306 | if ( nextA < mNextAlarmDateTime ) { |
307 | deRegisterAlarm(); | 307 | deRegisterAlarm(); |
308 | mNextAlarmDateTime = nextA; | 308 | mNextAlarmDateTime = nextA; |
309 | mNextSummary = incidence->summary(); | 309 | mNextSummary = incidence->summary(); |
310 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 310 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
311 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 311 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
312 | newNextAlarm = true; | 312 | newNextAlarm = true; |
313 | mNextAlarmIncidence = incidence; | 313 | mNextAlarmIncidence = incidence; |
314 | } else { | 314 | } else { |
315 | if ( incidence == mNextAlarmIncidence ) { | 315 | if ( incidence == mNextAlarmIncidence ) { |
316 | computeNextAlarm = true; | 316 | computeNextAlarm = true; |
317 | } | 317 | } |
318 | } | 318 | } |
319 | } else { | 319 | } else { |
320 | if ( mNextAlarmIncidence == incidence ) { | 320 | if ( mNextAlarmIncidence == incidence ) { |
321 | computeNextAlarm = true; | 321 | computeNextAlarm = true; |
322 | } | 322 | } |
323 | } | 323 | } |
324 | } else { // deleted | 324 | } else { // deleted |
325 | if ( incidence == mNextAlarmIncidence ) { | 325 | if ( incidence == mNextAlarmIncidence ) { |
326 | computeNextAlarm = true; | 326 | computeNextAlarm = true; |
327 | } | 327 | } |
328 | } | 328 | } |
329 | } | 329 | } |
330 | if ( computeNextAlarm ) { | 330 | if ( computeNextAlarm ) { |
331 | deRegisterAlarm(); | 331 | deRegisterAlarm(); |
332 | nextA = nextAlarm( 1000 ); | 332 | nextA = nextAlarm( 1000 ); |
333 | if (! mNextAlarmIncidence ) { | 333 | if (! mNextAlarmIncidence ) { |
334 | return; | 334 | return; |
335 | } | 335 | } |
336 | newNextAlarm = true; | 336 | newNextAlarm = true; |
337 | } | 337 | } |
338 | if ( newNextAlarm ) | 338 | if ( newNextAlarm ) |
339 | registerAlarm(); | 339 | registerAlarm(); |
340 | } | 340 | } |
341 | QString CalendarLocal:: getAlarmNotification() | 341 | QString CalendarLocal:: getAlarmNotification() |
342 | { | 342 | { |
343 | QString ret; | 343 | QString ret; |
344 | // this should not happen | 344 | // this should not happen |
345 | if (! mNextAlarmIncidence ) | 345 | if (! mNextAlarmIncidence ) |
346 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 346 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
347 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 347 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
348 | if ( alarm->type() == Alarm::Procedure ) { | 348 | if ( alarm->type() == Alarm::Procedure ) { |
349 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 349 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
350 | } else { | 350 | } else { |
351 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 351 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
352 | } | 352 | } |
353 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 353 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
354 | if ( mNextSummary.length() > 25 ) | 354 | if ( mNextSummary.length() > 25 ) |
355 | ret += "\n" + mNextSummary.mid(25, 25 ); | 355 | ret += "\n" + mNextSummary.mid(25, 25 ); |
356 | ret+= "\n"+mNextAlarmEventDateTimeString; | 356 | ret+= "\n"+mNextAlarmEventDateTimeString; |
357 | return ret; | 357 | return ret; |
358 | } | 358 | } |
359 | void CalendarLocal::registerAlarm() | 359 | void CalendarLocal::registerAlarm() |
360 | { | 360 | { |
361 | mLastAlarmNotificationString = getAlarmNotification(); | 361 | mLastAlarmNotificationString = getAlarmNotification(); |
362 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 362 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
363 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 363 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
364 | // #ifndef DESKTOP_VERSION | 364 | // #ifndef DESKTOP_VERSION |
365 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 365 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
366 | // #endif | 366 | // #endif |
367 | } | 367 | } |
368 | void CalendarLocal::deRegisterAlarm() | 368 | void CalendarLocal::deRegisterAlarm() |
369 | { | 369 | { |
370 | if ( mLastAlarmNotificationString.isNull() ) | 370 | if ( mLastAlarmNotificationString.isNull() ) |
371 | return; | 371 | return; |
372 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 372 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
373 | 373 | ||
374 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 374 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
375 | // #ifndef DESKTOP_VERSION | 375 | // #ifndef DESKTOP_VERSION |
376 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 376 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
377 | // #endif | 377 | // #endif |
378 | } | 378 | } |
379 | 379 | ||
380 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 380 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
381 | { | 381 | { |
382 | QPtrList<Todo> todos; | 382 | QPtrList<Todo> todos; |
383 | 383 | ||
384 | Todo *todo; | 384 | Todo *todo; |
385 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 385 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
386 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 386 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
387 | todos.append( todo ); | 387 | todos.append( todo ); |
388 | } | 388 | } |
389 | } | 389 | } |
390 | 390 | ||
391 | filter()->apply( &todos ); | 391 | filter()->apply( &todos ); |
392 | return todos; | 392 | return todos; |
393 | } | 393 | } |
394 | void CalendarLocal::reInitAlarmSettings() | 394 | void CalendarLocal::reInitAlarmSettings() |
395 | { | 395 | { |
396 | if ( !mNextAlarmIncidence ) { | 396 | if ( !mNextAlarmIncidence ) { |
397 | nextAlarm( 1000 ); | 397 | nextAlarm( 1000 ); |
398 | } | 398 | } |
399 | deRegisterAlarm(); | 399 | deRegisterAlarm(); |
400 | mNextAlarmIncidence = 0; | 400 | mNextAlarmIncidence = 0; |
401 | checkAlarmForIncidence( 0, false ); | 401 | checkAlarmForIncidence( 0, false ); |
402 | 402 | ||
403 | } | 403 | } |
404 | 404 | ||
405 | 405 | ||
406 | 406 | ||
407 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 407 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
408 | { | 408 | { |
409 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 409 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
410 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 410 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
411 | QDateTime next; | 411 | QDateTime next; |
412 | Event *e; | 412 | Event *e; |
413 | bool ok; | 413 | bool ok; |
414 | bool found = false; | 414 | bool found = false; |
415 | int offset; | 415 | int offset; |
416 | mNextAlarmIncidence = 0; | 416 | mNextAlarmIncidence = 0; |
417 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 417 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
418 | next = e->getNextAlarmDateTime(& ok, &offset ) ; | 418 | next = e->getNextAlarmDateTime(& ok, &offset ) ; |
419 | if ( ok ) { | 419 | if ( ok ) { |
420 | if ( next < nextA ) { | 420 | if ( next < nextA ) { |
421 | nextA = next; | 421 | nextA = next; |
422 | found = true; | 422 | found = true; |
423 | mNextSummary = e->summary(); | 423 | mNextSummary = e->summary(); |
424 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 424 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
425 | mNextAlarmIncidence = (Incidence *) e; | 425 | mNextAlarmIncidence = (Incidence *) e; |
426 | } | 426 | } |
427 | } | 427 | } |
428 | } | 428 | } |
429 | Todo *t; | 429 | Todo *t; |
430 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 430 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
431 | next = t->getNextAlarmDateTime(& ok, &offset ) ; | 431 | next = t->getNextAlarmDateTime(& ok, &offset ) ; |
432 | if ( ok ) { | 432 | if ( ok ) { |
433 | if ( next < nextA ) { | 433 | if ( next < nextA ) { |
434 | nextA = next; | 434 | nextA = next; |
435 | found = true; | 435 | found = true; |
436 | mNextSummary = t->summary(); | 436 | mNextSummary = t->summary(); |
437 | mNextAlarmEventDateTime = next.addSecs(offset ); | 437 | mNextAlarmEventDateTime = next.addSecs(offset ); |
438 | mNextAlarmIncidence = (Incidence *) t; | 438 | mNextAlarmIncidence = (Incidence *) t; |
439 | } | 439 | } |
440 | } | 440 | } |
441 | } | 441 | } |
442 | if ( mNextAlarmIncidence ) { | 442 | if ( mNextAlarmIncidence ) { |
443 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 443 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
444 | mNextAlarmDateTime = nextA; | 444 | mNextAlarmDateTime = nextA; |
445 | } | 445 | } |
446 | return nextA; | 446 | return nextA; |
447 | } | 447 | } |
448 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 448 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
449 | { | 449 | { |
450 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 450 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
451 | } | 451 | } |
452 | 452 | ||
453 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 453 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
454 | { | 454 | { |
455 | kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " | 455 | kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " |
456 | << to.toString() << ")\n"; | 456 | << to.toString() << ")\n"; |
457 | 457 | ||
458 | Alarm::List alarms; | 458 | Alarm::List alarms; |
459 | 459 | ||
460 | Event *e; | 460 | Event *e; |
461 | 461 | ||
462 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 462 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
463 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 463 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
464 | else appendAlarms( alarms, e, from, to ); | 464 | else appendAlarms( alarms, e, from, to ); |
465 | } | 465 | } |
466 | 466 | ||
467 | Todo *t; | 467 | Todo *t; |
468 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 468 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
469 | appendAlarms( alarms, t, from, to ); | 469 | appendAlarms( alarms, t, from, to ); |
470 | } | 470 | } |
471 | 471 | ||
472 | return alarms; | 472 | return alarms; |
473 | } | 473 | } |
474 | 474 | ||
475 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 475 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
476 | const QDateTime &from, const QDateTime &to ) | 476 | const QDateTime &from, const QDateTime &to ) |
477 | { | 477 | { |
478 | QPtrList<Alarm> alarmList = incidence->alarms(); | 478 | QPtrList<Alarm> alarmList = incidence->alarms(); |
479 | Alarm *alarm; | 479 | Alarm *alarm; |
480 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 480 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
481 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 481 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
482 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 482 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
483 | if ( alarm->enabled() ) { | 483 | if ( alarm->enabled() ) { |
484 | if ( alarm->time() >= from && alarm->time() <= to ) { | 484 | if ( alarm->time() >= from && alarm->time() <= to ) { |
485 | kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() | 485 | kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() |
486 | << "': " << alarm->time().toString() << endl; | 486 | << "': " << alarm->time().toString() << endl; |
487 | alarms.append( alarm ); | 487 | alarms.append( alarm ); |
488 | } | 488 | } |
489 | } | 489 | } |
490 | } | 490 | } |
491 | } | 491 | } |
492 | 492 | ||
493 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | 493 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, |
494 | Incidence *incidence, | 494 | Incidence *incidence, |
495 | const QDateTime &from, | 495 | const QDateTime &from, |
496 | const QDateTime &to ) | 496 | const QDateTime &to ) |
497 | { | 497 | { |
498 | 498 | ||
499 | QPtrList<Alarm> alarmList = incidence->alarms(); | 499 | QPtrList<Alarm> alarmList = incidence->alarms(); |
500 | Alarm *alarm; | 500 | Alarm *alarm; |
501 | QDateTime qdt; | 501 | QDateTime qdt; |
502 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 502 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
503 | if (incidence->recursOn(from.date())) { | 503 | if (incidence->recursOn(from.date())) { |
504 | qdt.setTime(alarm->time().time()); | 504 | qdt.setTime(alarm->time().time()); |
505 | qdt.setDate(from.date()); | 505 | qdt.setDate(from.date()); |
506 | } | 506 | } |
507 | else qdt = alarm->time(); | 507 | else qdt = alarm->time(); |
508 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); | 508 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); |
509 | if ( alarm->enabled() ) { | 509 | if ( alarm->enabled() ) { |
510 | if ( qdt >= from && qdt <= to ) { | 510 | if ( qdt >= from && qdt <= to ) { |
511 | alarms.append( alarm ); | 511 | alarms.append( alarm ); |
512 | } | 512 | } |
513 | } | 513 | } |
514 | } | 514 | } |
515 | } | 515 | } |
516 | 516 | ||
517 | 517 | ||
518 | /****************************** PROTECTED METHODS ****************************/ | 518 | /****************************** PROTECTED METHODS ****************************/ |
519 | 519 | ||
520 | // after changes are made to an event, this should be called. | 520 | // after changes are made to an event, this should be called. |
521 | void CalendarLocal::update( IncidenceBase *incidence ) | 521 | void CalendarLocal::update( IncidenceBase *incidence ) |
522 | { | 522 | { |
523 | incidence->setSyncStatus( Event::SYNCMOD ); | 523 | incidence->setSyncStatus( Event::SYNCMOD ); |
524 | incidence->setLastModified( QDateTime::currentDateTime() ); | 524 | incidence->setLastModified( QDateTime::currentDateTime() ); |
525 | // we should probably update the revision number here, | 525 | // we should probably update the revision number here, |
526 | // or internally in the Event itself when certain things change. | 526 | // or internally in the Event itself when certain things change. |
527 | // need to verify with ical documentation. | 527 | // need to verify with ical documentation. |
528 | 528 | ||
529 | setModified( true ); | 529 | setModified( true ); |
530 | } | 530 | } |
531 | 531 | ||
532 | void CalendarLocal::insertEvent( Event *event ) | 532 | void CalendarLocal::insertEvent( Event *event ) |
533 | { | 533 | { |
534 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 534 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
535 | } | 535 | } |
536 | 536 | ||
537 | 537 | ||
538 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 538 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
539 | { | 539 | { |
540 | QPtrList<Event> eventList; | 540 | QPtrList<Event> eventList; |
541 | 541 | ||
542 | Event *event; | 542 | Event *event; |
543 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 543 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
544 | if ( event->doesRecur() ) { | 544 | if ( event->doesRecur() ) { |
545 | if ( event->isMultiDay() ) { | 545 | if ( event->isMultiDay() ) { |
546 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 546 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
547 | int i; | 547 | int i; |
548 | for ( i = 0; i <= extraDays; i++ ) { | 548 | for ( i = 0; i <= extraDays; i++ ) { |
549 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 549 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
550 | eventList.append( event ); | 550 | eventList.append( event ); |
551 | break; | 551 | break; |
552 | } | 552 | } |
553 | } | 553 | } |
554 | } else { | 554 | } else { |
555 | if ( event->recursOn( qd ) ) | 555 | if ( event->recursOn( qd ) ) |
556 | eventList.append( event ); | 556 | eventList.append( event ); |
557 | } | 557 | } |
558 | } else { | 558 | } else { |
559 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 559 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
560 | eventList.append( event ); | 560 | eventList.append( event ); |
561 | } | 561 | } |
562 | } | 562 | } |
563 | } | 563 | } |
564 | 564 | ||
565 | if ( !sorted ) { | 565 | if ( !sorted ) { |
566 | return eventList; | 566 | return eventList; |
567 | } | 567 | } |
568 | 568 | ||
569 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 569 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
570 | // now, we have to sort it based on dtStart.time() | 570 | // now, we have to sort it based on dtStart.time() |
571 | QPtrList<Event> eventListSorted; | 571 | QPtrList<Event> eventListSorted; |
572 | Event *sortEvent; | 572 | Event *sortEvent; |
573 | for ( event = eventList.first(); event; event = eventList.next() ) { | 573 | for ( event = eventList.first(); event; event = eventList.next() ) { |
574 | sortEvent = eventListSorted.first(); | 574 | sortEvent = eventListSorted.first(); |
575 | int i = 0; | 575 | int i = 0; |
576 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 576 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
577 | { | 577 | { |
578 | i++; | 578 | i++; |
579 | sortEvent = eventListSorted.next(); | 579 | sortEvent = eventListSorted.next(); |
580 | } | 580 | } |
581 | eventListSorted.insert( i, event ); | 581 | eventListSorted.insert( i, event ); |
582 | } | 582 | } |
583 | return eventListSorted; | 583 | return eventListSorted; |
584 | } | 584 | } |
585 | 585 | ||
586 | 586 | ||
587 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 587 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
588 | bool inclusive ) | 588 | bool inclusive ) |
589 | { | 589 | { |
590 | qDebug("CalendarLocal::rawEvents called "); | ||
590 | Event *event = 0; | 591 | Event *event = 0; |
591 | 592 | ||
592 | QPtrList<Event> eventList; | 593 | QPtrList<Event> eventList; |
593 | 594 | ||
594 | // Get non-recurring events | 595 | // Get non-recurring events |
595 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 596 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
596 | if ( event->doesRecur() ) { | 597 | if ( event->doesRecur() ) { |
597 | QDate rStart = event->dtStart().date(); | 598 | QDate rStart = event->dtStart().date(); |
598 | bool found = false; | 599 | bool found = false; |
599 | if ( inclusive ) { | 600 | if ( inclusive ) { |
600 | if ( rStart >= start && rStart <= end ) { | 601 | if ( rStart >= start && rStart <= end ) { |
601 | // Start date of event is in range. Now check for end date. | 602 | // Start date of event is in range. Now check for end date. |
602 | // if duration is negative, event recurs forever, so do not include it. | 603 | // if duration is negative, event recurs forever, so do not include it. |
603 | if ( event->recurrence()->duration() == 0 ) { // End date set | 604 | if ( event->recurrence()->duration() == 0 ) { // End date set |
604 | QDate rEnd = event->recurrence()->endDate(); | 605 | QDate rEnd = event->recurrence()->endDate(); |
605 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 606 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
606 | found = true; | 607 | found = true; |
607 | } | 608 | } |
608 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 609 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
609 | // TODO: Calculate end date from duration. Should be done in Event | 610 | // TODO: Calculate end date from duration. Should be done in Event |
610 | // For now exclude all events with a duration. | 611 | // For now exclude all events with a duration. |
611 | } | 612 | } |
612 | } | 613 | } |
613 | } else { | 614 | } else { |
614 | bool founOne; | 615 | bool founOne; |
615 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 616 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
616 | if ( founOne ) { | 617 | if ( founOne ) { |
617 | if ( next <= end ) { | 618 | if ( next <= end ) { |
618 | found = true; | 619 | found = true; |
619 | } | 620 | } |
620 | } | 621 | } |
621 | 622 | ||
622 | /* | 623 | /* |
623 | // crap !!! | 624 | // crap !!! |
624 | if ( rStart <= end ) { // Start date not after range | 625 | if ( rStart <= end ) { // Start date not after range |
625 | if ( rStart >= start ) { // Start date within range | 626 | if ( rStart >= start ) { // Start date within range |
626 | found = true; | 627 | found = true; |
627 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 628 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
628 | found = true; | 629 | found = true; |
629 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 630 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
630 | QDate rEnd = event->recurrence()->endDate(); | 631 | QDate rEnd = event->recurrence()->endDate(); |
631 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 632 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
632 | found = true; | 633 | found = true; |
633 | } | 634 | } |
634 | } else { // Duration set | 635 | } else { // Duration set |
635 | // TODO: Calculate end date from duration. Should be done in Event | 636 | // TODO: Calculate end date from duration. Should be done in Event |
636 | // For now include all events with a duration. | 637 | // For now include all events with a duration. |
637 | found = true; | 638 | found = true; |
638 | } | 639 | } |
639 | } | 640 | } |
640 | */ | 641 | */ |
641 | 642 | ||
642 | } | 643 | } |
643 | 644 | ||
644 | if ( found ) eventList.append( event ); | 645 | if ( found ) eventList.append( event ); |
645 | } else { | 646 | } else { |
646 | QDate s = event->dtStart().date(); | 647 | QDate s = event->dtStart().date(); |
647 | QDate e = event->dtEnd().date(); | 648 | QDate e = event->dtEnd().date(); |
648 | 649 | ||
649 | if ( inclusive ) { | 650 | if ( inclusive ) { |
650 | if ( s >= start && e <= end ) { | 651 | if ( s >= start && e <= end ) { |
651 | eventList.append( event ); | 652 | eventList.append( event ); |
652 | } | 653 | } |
653 | } else { | 654 | } else { |
654 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { | 655 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { |
655 | eventList.append( event ); | 656 | eventList.append( event ); |
656 | } | 657 | } |
657 | } | 658 | } |
658 | } | 659 | } |
659 | } | 660 | } |
660 | 661 | ||
661 | return eventList; | 662 | return eventList; |
662 | } | 663 | } |
663 | 664 | ||
664 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 665 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
665 | { | 666 | { |
666 | return rawEventsForDate( qdt.date() ); | 667 | return rawEventsForDate( qdt.date() ); |
667 | } | 668 | } |
668 | 669 | ||
669 | QPtrList<Event> CalendarLocal::rawEvents() | 670 | QPtrList<Event> CalendarLocal::rawEvents() |
670 | { | 671 | { |
671 | return mEventList; | 672 | return mEventList; |
672 | } | 673 | } |
673 | 674 | ||
674 | bool CalendarLocal::addJournal(Journal *journal) | 675 | bool CalendarLocal::addJournal(Journal *journal) |
675 | { | 676 | { |
676 | if ( journal->dtStart().isValid()) | 677 | if ( journal->dtStart().isValid()) |
677 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; | 678 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; |
678 | else | 679 | else |
679 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; | 680 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; |
680 | 681 | ||
681 | mJournalList.append(journal); | 682 | mJournalList.append(journal); |
682 | 683 | ||
683 | journal->registerObserver( this ); | 684 | journal->registerObserver( this ); |
684 | 685 | ||
685 | setModified( true ); | 686 | setModified( true ); |
686 | 687 | ||
687 | return true; | 688 | return true; |
688 | } | 689 | } |
689 | 690 | ||
690 | void CalendarLocal::deleteJournal( Journal *journal ) | 691 | void CalendarLocal::deleteJournal( Journal *journal ) |
691 | { | 692 | { |
692 | if ( mUndoIncidence ) delete mUndoIncidence; | 693 | if ( mUndoIncidence ) delete mUndoIncidence; |
693 | mUndoIncidence = journal->clone(); | 694 | mUndoIncidence = journal->clone(); |
694 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); | 695 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); |
695 | if ( mJournalList.removeRef(journal) ) { | 696 | if ( mJournalList.removeRef(journal) ) { |
696 | setModified( true ); | 697 | setModified( true ); |
697 | } | 698 | } |
698 | } | 699 | } |
699 | 700 | ||
700 | Journal *CalendarLocal::journal( const QDate &date ) | 701 | Journal *CalendarLocal::journal( const QDate &date ) |
701 | { | 702 | { |
702 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 703 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
703 | 704 | ||
704 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 705 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
705 | if ( it->dtStart().date() == date ) | 706 | if ( it->dtStart().date() == date ) |
706 | return it; | 707 | return it; |
707 | 708 | ||
708 | return 0; | 709 | return 0; |
709 | } | 710 | } |
710 | 711 | ||
711 | Journal *CalendarLocal::journal( const QString &uid ) | 712 | Journal *CalendarLocal::journal( const QString &uid ) |
712 | { | 713 | { |
713 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 714 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
714 | if ( it->uid() == uid ) | 715 | if ( it->uid() == uid ) |
715 | return it; | 716 | return it; |
716 | 717 | ||
717 | return 0; | 718 | return 0; |
718 | } | 719 | } |
719 | 720 | ||
720 | QPtrList<Journal> CalendarLocal::journals() | 721 | QPtrList<Journal> CalendarLocal::journals() |
721 | { | 722 | { |
722 | return mJournalList; | 723 | return mJournalList; |
723 | } | 724 | } |
724 | 725 | ||
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index 28402ae..f9e1e9e 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp | |||
@@ -1,617 +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 <klocale.h> | 22 | #include <klocale.h> |
23 | #include <kdebug.h> | 23 | #include <kdebug.h> |
24 | 24 | ||
25 | #include "calformat.h" | 25 | #include "calformat.h" |
26 | 26 | ||
27 | #include "incidence.h" | 27 | #include "incidence.h" |
28 | #include "todo.h" | 28 | #include "todo.h" |
29 | 29 | ||
30 | using namespace KCal; | 30 | using namespace KCal; |
31 | 31 | ||
32 | Incidence::Incidence() : | 32 | Incidence::Incidence() : |
33 | IncidenceBase(), | 33 | IncidenceBase(), |
34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) | 34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) |
35 | { | 35 | { |
36 | mRecurrence = new Recurrence(this); | 36 | mRecurrence = new Recurrence(this); |
37 | mCancelled = false; | 37 | mCancelled = false; |
38 | recreate(); | 38 | recreate(); |
39 | mHasStartDate = true; | 39 | mHasStartDate = true; |
40 | mAlarms.setAutoDelete(true); | 40 | mAlarms.setAutoDelete(true); |
41 | mAttachments.setAutoDelete(true); | 41 | mAttachments.setAutoDelete(true); |
42 | } | 42 | } |
43 | 43 | ||
44 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) | 44 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) |
45 | { | 45 | { |
46 | // TODO: reenable attributes currently commented out. | 46 | // TODO: reenable attributes currently commented out. |
47 | mRevision = i.mRevision; | 47 | mRevision = i.mRevision; |
48 | mCreated = i.mCreated; | 48 | mCreated = i.mCreated; |
49 | mDescription = i.mDescription; | 49 | mDescription = i.mDescription; |
50 | mSummary = i.mSummary; | 50 | mSummary = i.mSummary; |
51 | mCategories = i.mCategories; | 51 | mCategories = i.mCategories; |
52 | // Incidence *mRelatedTo; Incidence *mRelatedTo; | 52 | // Incidence *mRelatedTo; Incidence *mRelatedTo; |
53 | mRelatedTo = 0; | 53 | mRelatedTo = 0; |
54 | mRelatedToUid = i.mRelatedToUid; | 54 | mRelatedToUid = i.mRelatedToUid; |
55 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; | 55 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; |
56 | mExDates = i.mExDates; | 56 | mExDates = i.mExDates; |
57 | mAttachments = i.mAttachments; | 57 | mAttachments = i.mAttachments; |
58 | mResources = i.mResources; | 58 | mResources = i.mResources; |
59 | mSecrecy = i.mSecrecy; | 59 | mSecrecy = i.mSecrecy; |
60 | mPriority = i.mPriority; | 60 | mPriority = i.mPriority; |
61 | mLocation = i.mLocation; | 61 | mLocation = i.mLocation; |
62 | mCancelled = i.mCancelled; | 62 | mCancelled = i.mCancelled; |
63 | mHasStartDate = i.mHasStartDate; | 63 | mHasStartDate = i.mHasStartDate; |
64 | QPtrListIterator<Alarm> it( i.mAlarms ); | 64 | QPtrListIterator<Alarm> it( i.mAlarms ); |
65 | const Alarm *a; | 65 | const Alarm *a; |
66 | while( (a = it.current()) ) { | 66 | while( (a = it.current()) ) { |
67 | Alarm *b = new Alarm( *a ); | 67 | Alarm *b = new Alarm( *a ); |
68 | b->setParent( this ); | 68 | b->setParent( this ); |
69 | mAlarms.append( b ); | 69 | mAlarms.append( b ); |
70 | 70 | ||
71 | ++it; | 71 | ++it; |
72 | } | 72 | } |
73 | mAlarms.setAutoDelete(true); | 73 | mAlarms.setAutoDelete(true); |
74 | 74 | ||
75 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); | 75 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); |
76 | } | 76 | } |
77 | 77 | ||
78 | Incidence::~Incidence() | 78 | Incidence::~Incidence() |
79 | { | 79 | { |
80 | 80 | ||
81 | Incidence *ev; | 81 | Incidence *ev; |
82 | QPtrList<Incidence> Relations = relations(); | 82 | QPtrList<Incidence> Relations = relations(); |
83 | for (ev=Relations.first();ev;ev=Relations.next()) { | 83 | for (ev=Relations.first();ev;ev=Relations.next()) { |
84 | if (ev->relatedTo() == this) ev->setRelatedTo(0); | 84 | if (ev->relatedTo() == this) ev->setRelatedTo(0); |
85 | } | 85 | } |
86 | if (relatedTo()) relatedTo()->removeRelation(this); | 86 | if (relatedTo()) relatedTo()->removeRelation(this); |
87 | delete mRecurrence; | 87 | delete mRecurrence; |
88 | 88 | ||
89 | } | 89 | } |
90 | 90 | ||
91 | bool Incidence::cancelled() const | 91 | bool Incidence::cancelled() const |
92 | { | 92 | { |
93 | return mCancelled; | 93 | return mCancelled; |
94 | } | 94 | } |
95 | void Incidence::setCancelled( bool b ) | 95 | void Incidence::setCancelled( bool b ) |
96 | { | 96 | { |
97 | mCancelled = b; | 97 | mCancelled = b; |
98 | updated(); | 98 | updated(); |
99 | } | 99 | } |
100 | bool Incidence::hasStartDate() const | 100 | bool Incidence::hasStartDate() const |
101 | { | 101 | { |
102 | return mHasStartDate; | 102 | return mHasStartDate; |
103 | } | 103 | } |
104 | 104 | ||
105 | void Incidence::setHasStartDate(bool f) | 105 | void Incidence::setHasStartDate(bool f) |
106 | { | 106 | { |
107 | if (mReadOnly) return; | 107 | if (mReadOnly) return; |
108 | mHasStartDate = f; | 108 | mHasStartDate = f; |
109 | updated(); | 109 | updated(); |
110 | } | 110 | } |
111 | 111 | ||
112 | // A string comparison that considers that null and empty are the same | 112 | // A string comparison that considers that null and empty are the same |
113 | static bool stringCompare( const QString& s1, const QString& s2 ) | 113 | static bool stringCompare( const QString& s1, const QString& s2 ) |
114 | { | 114 | { |
115 | if ( s1.isEmpty() && s2.isEmpty() ) | 115 | if ( s1.isEmpty() && s2.isEmpty() ) |
116 | return true; | 116 | return true; |
117 | return s1 == s2; | 117 | return s1 == s2; |
118 | } | 118 | } |
119 | 119 | ||
120 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) | 120 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) |
121 | { | 121 | { |
122 | 122 | ||
123 | if( i1.alarms().count() != i2.alarms().count() ) { | 123 | if( i1.alarms().count() != i2.alarms().count() ) { |
124 | return false; // no need to check further | 124 | return false; // no need to check further |
125 | } | 125 | } |
126 | if ( i1.alarms().count() > 0 ) { | 126 | if ( i1.alarms().count() > 0 ) { |
127 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) | 127 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) |
128 | { | 128 | { |
129 | qDebug("alarm not equal "); | 129 | qDebug("alarm not equal "); |
130 | return false; | 130 | return false; |
131 | } | 131 | } |
132 | } | 132 | } |
133 | #if 0 | 133 | #if 0 |
134 | QPtrListIterator<Alarm> a1( i1.alarms() ); | 134 | QPtrListIterator<Alarm> a1( i1.alarms() ); |
135 | QPtrListIterator<Alarm> a2( i2.alarms() ); | 135 | QPtrListIterator<Alarm> a2( i2.alarms() ); |
136 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { | 136 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { |
137 | if( *a1.current() == *a2.current() ) { | 137 | if( *a1.current() == *a2.current() ) { |
138 | continue; | 138 | continue; |
139 | } | 139 | } |
140 | else { | 140 | else { |
141 | return false; | 141 | return false; |
142 | } | 142 | } |
143 | } | 143 | } |
144 | #endif | 144 | #endif |
145 | 145 | ||
146 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) | 146 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) |
147 | return false; | 147 | return false; |
148 | if ( i1.hasStartDate() == i2.hasStartDate() ) { | 148 | if ( i1.hasStartDate() == i2.hasStartDate() ) { |
149 | if ( i1.hasStartDate() ) { | 149 | if ( i1.hasStartDate() ) { |
150 | if ( i1.dtStart() != i2.dtStart() ) | 150 | if ( i1.dtStart() != i2.dtStart() ) |
151 | return false; | 151 | return false; |
152 | } | 152 | } |
153 | } else { | 153 | } else { |
154 | return false; | 154 | return false; |
155 | } | 155 | } |
156 | if (!( *i1.recurrence() == *i2.recurrence()) ) { | 156 | if (!( *i1.recurrence() == *i2.recurrence()) ) { |
157 | qDebug("recurrence is NOT equal "); | 157 | qDebug("recurrence is NOT equal "); |
158 | return false; | 158 | return false; |
159 | } | 159 | } |
160 | return | 160 | return |
161 | // i1.created() == i2.created() && | 161 | // i1.created() == i2.created() && |
162 | stringCompare( i1.description(), i2.description() ) && | 162 | stringCompare( i1.description(), i2.description() ) && |
163 | stringCompare( i1.summary(), i2.summary() ) && | 163 | stringCompare( i1.summary(), i2.summary() ) && |
164 | i1.categories() == i2.categories() && | 164 | i1.categories() == i2.categories() && |
165 | // no need to compare mRelatedTo | 165 | // no need to compare mRelatedTo |
166 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && | 166 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && |
167 | // i1.relations() == i2.relations() && | 167 | // i1.relations() == i2.relations() && |
168 | i1.exDates() == i2.exDates() && | 168 | i1.exDates() == i2.exDates() && |
169 | i1.attachments() == i2.attachments() && | 169 | i1.attachments() == i2.attachments() && |
170 | i1.resources() == i2.resources() && | 170 | i1.resources() == i2.resources() && |
171 | i1.secrecy() == i2.secrecy() && | 171 | i1.secrecy() == i2.secrecy() && |
172 | i1.priority() == i2.priority() && | 172 | i1.priority() == i2.priority() && |
173 | stringCompare( i1.location(), i2.location() ); | 173 | stringCompare( i1.location(), i2.location() ); |
174 | } | 174 | } |
175 | 175 | ||
176 | Incidence* Incidence::recreateCloneException( QDate d ) | 176 | Incidence* Incidence::recreateCloneException( QDate d ) |
177 | { | 177 | { |
178 | Incidence* newInc = clone(); | 178 | Incidence* newInc = clone(); |
179 | newInc->recreate(); | 179 | newInc->recreate(); |
180 | if ( doesRecur() ) { | 180 | if ( doesRecur() ) { |
181 | addExDate( d ); | 181 | addExDate( d ); |
182 | newInc->recurrence()->unsetRecurs(); | 182 | newInc->recurrence()->unsetRecurs(); |
183 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); | 183 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); |
184 | QTime tim = dtStart().time(); | 184 | QTime tim = dtStart().time(); |
185 | newInc->setDtStart( QDateTime(d, tim) ); | 185 | newInc->setDtStart( QDateTime(d, tim) ); |
186 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); | 186 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); |
187 | } | 187 | } |
188 | return newInc; | 188 | return newInc; |
189 | } | 189 | } |
190 | 190 | ||
191 | void Incidence::recreate() | 191 | void Incidence::recreate() |
192 | { | 192 | { |
193 | setCreated(QDateTime::currentDateTime()); | 193 | setCreated(QDateTime::currentDateTime()); |
194 | 194 | ||
195 | setUid(CalFormat::createUniqueId()); | 195 | setUid(CalFormat::createUniqueId()); |
196 | 196 | ||
197 | setRevision(0); | 197 | setRevision(0); |
198 | setIDStr( ":" ); | 198 | setIDStr( ":" ); |
199 | setLastModified(QDateTime::currentDateTime()); | 199 | setLastModified(QDateTime::currentDateTime()); |
200 | } | 200 | } |
201 | 201 | ||
202 | void Incidence::setReadOnly( bool readOnly ) | 202 | void Incidence::setReadOnly( bool readOnly ) |
203 | { | 203 | { |
204 | IncidenceBase::setReadOnly( readOnly ); | 204 | IncidenceBase::setReadOnly( readOnly ); |
205 | recurrence()->setRecurReadOnly( readOnly); | 205 | recurrence()->setRecurReadOnly( readOnly); |
206 | } | 206 | } |
207 | 207 | ||
208 | void Incidence::setCreated(QDateTime created) | 208 | void Incidence::setCreated(QDateTime created) |
209 | { | 209 | { |
210 | if (mReadOnly) return; | 210 | if (mReadOnly) return; |
211 | mCreated = getEvenTime(created); | 211 | mCreated = getEvenTime(created); |
212 | } | 212 | } |
213 | 213 | ||
214 | QDateTime Incidence::created() const | 214 | QDateTime Incidence::created() const |
215 | { | 215 | { |
216 | return mCreated; | 216 | return mCreated; |
217 | } | 217 | } |
218 | 218 | ||
219 | void Incidence::setRevision(int rev) | 219 | void Incidence::setRevision(int rev) |
220 | { | 220 | { |
221 | if (mReadOnly) return; | 221 | if (mReadOnly) return; |
222 | mRevision = rev; | 222 | mRevision = rev; |
223 | 223 | ||
224 | updated(); | 224 | updated(); |
225 | } | 225 | } |
226 | 226 | ||
227 | int Incidence::revision() const | 227 | int Incidence::revision() const |
228 | { | 228 | { |
229 | return mRevision; | 229 | return mRevision; |
230 | } | 230 | } |
231 | 231 | ||
232 | void Incidence::setDtStart(const QDateTime &dtStart) | 232 | void Incidence::setDtStart(const QDateTime &dtStart) |
233 | { | 233 | { |
234 | 234 | ||
235 | QDateTime dt = getEvenTime(dtStart); | 235 | QDateTime dt = getEvenTime(dtStart); |
236 | recurrence()->setRecurStart( dt); | 236 | recurrence()->setRecurStart( dt); |
237 | IncidenceBase::setDtStart( dt ); | 237 | IncidenceBase::setDtStart( dt ); |
238 | } | 238 | } |
239 | 239 | ||
240 | void Incidence::setDescription(const QString &description) | 240 | void Incidence::setDescription(const QString &description) |
241 | { | 241 | { |
242 | if (mReadOnly) return; | 242 | if (mReadOnly) return; |
243 | mDescription = description; | 243 | mDescription = description; |
244 | updated(); | 244 | updated(); |
245 | } | 245 | } |
246 | 246 | ||
247 | QString Incidence::description() const | 247 | QString Incidence::description() const |
248 | { | 248 | { |
249 | return mDescription; | 249 | return mDescription; |
250 | } | 250 | } |
251 | 251 | ||
252 | 252 | ||
253 | void Incidence::setSummary(const QString &summary) | 253 | void Incidence::setSummary(const QString &summary) |
254 | { | 254 | { |
255 | if (mReadOnly) return; | 255 | if (mReadOnly) return; |
256 | mSummary = summary; | 256 | mSummary = summary; |
257 | updated(); | 257 | updated(); |
258 | } | 258 | } |
259 | 259 | ||
260 | QString Incidence::summary() const | 260 | QString Incidence::summary() const |
261 | { | 261 | { |
262 | return mSummary; | 262 | return mSummary; |
263 | } | 263 | } |
264 | 264 | ||
265 | void Incidence::setCategories(const QStringList &categories) | 265 | void Incidence::setCategories(const QStringList &categories) |
266 | { | 266 | { |
267 | if (mReadOnly) return; | 267 | if (mReadOnly) return; |
268 | mCategories = categories; | 268 | mCategories = categories; |
269 | updated(); | 269 | updated(); |
270 | } | 270 | } |
271 | 271 | ||
272 | // TODO: remove setCategories(QString) function | 272 | // TODO: remove setCategories(QString) function |
273 | void Incidence::setCategories(const QString &catStr) | 273 | void Incidence::setCategories(const QString &catStr) |
274 | { | 274 | { |
275 | if (mReadOnly) return; | 275 | if (mReadOnly) return; |
276 | mCategories.clear(); | 276 | mCategories.clear(); |
277 | 277 | ||
278 | if (catStr.isEmpty()) return; | 278 | if (catStr.isEmpty()) return; |
279 | 279 | ||
280 | mCategories = QStringList::split(",",catStr); | 280 | mCategories = QStringList::split(",",catStr); |
281 | 281 | ||
282 | QStringList::Iterator it; | 282 | QStringList::Iterator it; |
283 | for(it = mCategories.begin();it != mCategories.end(); ++it) { | 283 | for(it = mCategories.begin();it != mCategories.end(); ++it) { |
284 | *it = (*it).stripWhiteSpace(); | 284 | *it = (*it).stripWhiteSpace(); |
285 | } | 285 | } |
286 | 286 | ||
287 | updated(); | 287 | updated(); |
288 | } | 288 | } |
289 | 289 | ||
290 | QStringList Incidence::categories() const | 290 | QStringList Incidence::categories() const |
291 | { | 291 | { |
292 | return mCategories; | 292 | return mCategories; |
293 | } | 293 | } |
294 | 294 | ||
295 | QString Incidence::categoriesStr() | 295 | QString Incidence::categoriesStr() |
296 | { | 296 | { |
297 | return mCategories.join(","); | 297 | return mCategories.join(","); |
298 | } | 298 | } |
299 | 299 | ||
300 | void Incidence::setRelatedToUid(const QString &relatedToUid) | 300 | void Incidence::setRelatedToUid(const QString &relatedToUid) |
301 | { | 301 | { |
302 | if (mReadOnly) return; | 302 | if (mReadOnly) return; |
303 | mRelatedToUid = relatedToUid; | 303 | mRelatedToUid = relatedToUid; |
304 | } | 304 | } |
305 | 305 | ||
306 | QString Incidence::relatedToUid() const | 306 | QString Incidence::relatedToUid() const |
307 | { | 307 | { |
308 | return mRelatedToUid; | 308 | return mRelatedToUid; |
309 | } | 309 | } |
310 | 310 | ||
311 | void Incidence::setRelatedTo(Incidence *relatedTo) | 311 | void Incidence::setRelatedTo(Incidence *relatedTo) |
312 | { | 312 | { |
313 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); | 313 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); |
314 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); | 314 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); |
315 | if (mReadOnly || mRelatedTo == relatedTo) return; | 315 | if (mReadOnly || mRelatedTo == relatedTo) return; |
316 | if(mRelatedTo) { | 316 | if(mRelatedTo) { |
317 | // updated(); | 317 | // updated(); |
318 | mRelatedTo->removeRelation(this); | 318 | mRelatedTo->removeRelation(this); |
319 | } | 319 | } |
320 | mRelatedTo = relatedTo; | 320 | mRelatedTo = relatedTo; |
321 | if (mRelatedTo) mRelatedTo->addRelation(this); | 321 | if (mRelatedTo) mRelatedTo->addRelation(this); |
322 | } | 322 | } |
323 | 323 | ||
324 | Incidence *Incidence::relatedTo() const | 324 | Incidence *Incidence::relatedTo() const |
325 | { | 325 | { |
326 | return mRelatedTo; | 326 | return mRelatedTo; |
327 | } | 327 | } |
328 | 328 | ||
329 | QPtrList<Incidence> Incidence::relations() const | 329 | QPtrList<Incidence> Incidence::relations() const |
330 | { | 330 | { |
331 | return mRelations; | 331 | return mRelations; |
332 | } | 332 | } |
333 | 333 | ||
334 | void Incidence::addRelation(Incidence *event) | 334 | void Incidence::addRelation(Incidence *event) |
335 | { | 335 | { |
336 | if( mRelations.findRef( event ) == -1 ) { | 336 | if( mRelations.findRef( event ) == -1 ) { |
337 | mRelations.append(event); | 337 | mRelations.append(event); |
338 | //updated(); | 338 | //updated(); |
339 | } | 339 | } |
340 | } | 340 | } |
341 | 341 | ||
342 | void Incidence::removeRelation(Incidence *event) | 342 | void Incidence::removeRelation(Incidence *event) |
343 | { | 343 | { |
344 | 344 | ||
345 | mRelations.removeRef(event); | 345 | mRelations.removeRef(event); |
346 | 346 | ||
347 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); | 347 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); |
348 | } | 348 | } |
349 | 349 | ||
350 | bool Incidence::recursOn(const QDate &qd) const | 350 | bool Incidence::recursOn(const QDate &qd) const |
351 | { | 351 | { |
352 | if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; | 352 | if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; |
353 | else return false; | 353 | else return false; |
354 | } | 354 | } |
355 | 355 | ||
356 | void Incidence::setExDates(const DateList &exDates) | 356 | void Incidence::setExDates(const DateList &exDates) |
357 | { | 357 | { |
358 | if (mReadOnly) return; | 358 | if (mReadOnly) return; |
359 | mExDates = exDates; | 359 | mExDates = exDates; |
360 | 360 | ||
361 | recurrence()->setRecurExDatesCount(mExDates.count()); | 361 | recurrence()->setRecurExDatesCount(mExDates.count()); |
362 | 362 | ||
363 | updated(); | 363 | updated(); |
364 | } | 364 | } |
365 | 365 | ||
366 | void Incidence::addExDate(const QDate &date) | 366 | void Incidence::addExDate(const QDate &date) |
367 | { | 367 | { |
368 | if (mReadOnly) return; | 368 | if (mReadOnly) return; |
369 | mExDates.append(date); | 369 | mExDates.append(date); |
370 | 370 | ||
371 | recurrence()->setRecurExDatesCount(mExDates.count()); | 371 | recurrence()->setRecurExDatesCount(mExDates.count()); |
372 | 372 | ||
373 | updated(); | 373 | updated(); |
374 | } | 374 | } |
375 | 375 | ||
376 | DateList Incidence::exDates() const | 376 | DateList Incidence::exDates() const |
377 | { | 377 | { |
378 | return mExDates; | 378 | return mExDates; |
379 | } | 379 | } |
380 | 380 | ||
381 | bool Incidence::isException(const QDate &date) const | 381 | bool Incidence::isException(const QDate &date) const |
382 | { | 382 | { |
383 | DateList::ConstIterator it; | 383 | DateList::ConstIterator it; |
384 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { | 384 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { |
385 | if ( (*it) == date ) { | 385 | if ( (*it) == date ) { |
386 | return true; | 386 | return true; |
387 | } | 387 | } |
388 | } | 388 | } |
389 | 389 | ||
390 | return false; | 390 | return false; |
391 | } | 391 | } |
392 | 392 | ||
393 | void Incidence::addAttachment(Attachment *attachment) | 393 | void Incidence::addAttachment(Attachment *attachment) |
394 | { | 394 | { |
395 | if (mReadOnly || !attachment) return; | 395 | if (mReadOnly || !attachment) return; |
396 | mAttachments.append(attachment); | 396 | mAttachments.append(attachment); |
397 | updated(); | 397 | updated(); |
398 | } | 398 | } |
399 | 399 | ||
400 | void Incidence::deleteAttachment(Attachment *attachment) | 400 | void Incidence::deleteAttachment(Attachment *attachment) |
401 | { | 401 | { |
402 | mAttachments.removeRef(attachment); | 402 | mAttachments.removeRef(attachment); |
403 | } | 403 | } |
404 | 404 | ||
405 | void Incidence::deleteAttachments(const QString& mime) | 405 | void Incidence::deleteAttachments(const QString& mime) |
406 | { | 406 | { |
407 | Attachment *at = mAttachments.first(); | 407 | Attachment *at = mAttachments.first(); |
408 | while (at) { | 408 | while (at) { |
409 | if (at->mimeType() == mime) | 409 | if (at->mimeType() == mime) |
410 | mAttachments.remove(); | 410 | mAttachments.remove(); |
411 | else | 411 | else |
412 | at = mAttachments.next(); | 412 | at = mAttachments.next(); |
413 | } | 413 | } |
414 | } | 414 | } |
415 | 415 | ||
416 | QPtrList<Attachment> Incidence::attachments() const | 416 | QPtrList<Attachment> Incidence::attachments() const |
417 | { | 417 | { |
418 | return mAttachments; | 418 | return mAttachments; |
419 | } | 419 | } |
420 | 420 | ||
421 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const | 421 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const |
422 | { | 422 | { |
423 | QPtrList<Attachment> attachments; | 423 | QPtrList<Attachment> attachments; |
424 | QPtrListIterator<Attachment> it( mAttachments ); | 424 | QPtrListIterator<Attachment> it( mAttachments ); |
425 | Attachment *at; | 425 | Attachment *at; |
426 | while ( (at = it.current()) ) { | 426 | while ( (at = it.current()) ) { |
427 | if (at->mimeType() == mime) | 427 | if (at->mimeType() == mime) |
428 | attachments.append(at); | 428 | attachments.append(at); |
429 | ++it; | 429 | ++it; |
430 | } | 430 | } |
431 | 431 | ||
432 | return attachments; | 432 | return attachments; |
433 | } | 433 | } |
434 | 434 | ||
435 | void Incidence::setResources(const QStringList &resources) | 435 | void Incidence::setResources(const QStringList &resources) |
436 | { | 436 | { |
437 | if (mReadOnly) return; | 437 | if (mReadOnly) return; |
438 | mResources = resources; | 438 | mResources = resources; |
439 | updated(); | 439 | updated(); |
440 | } | 440 | } |
441 | 441 | ||
442 | QStringList Incidence::resources() const | 442 | QStringList Incidence::resources() const |
443 | { | 443 | { |
444 | return mResources; | 444 | return mResources; |
445 | } | 445 | } |
446 | 446 | ||
447 | 447 | ||
448 | void Incidence::setPriority(int priority) | 448 | void Incidence::setPriority(int priority) |
449 | { | 449 | { |
450 | if (mReadOnly) return; | 450 | if (mReadOnly) return; |
451 | mPriority = priority; | 451 | mPriority = priority; |
452 | updated(); | 452 | updated(); |
453 | } | 453 | } |
454 | 454 | ||
455 | int Incidence::priority() const | 455 | int Incidence::priority() const |
456 | { | 456 | { |
457 | return mPriority; | 457 | return mPriority; |
458 | } | 458 | } |
459 | 459 | ||
460 | void Incidence::setSecrecy(int sec) | 460 | void Incidence::setSecrecy(int sec) |
461 | { | 461 | { |
462 | if (mReadOnly) return; | 462 | if (mReadOnly) return; |
463 | mSecrecy = sec; | 463 | mSecrecy = sec; |
464 | updated(); | 464 | updated(); |
465 | } | 465 | } |
466 | 466 | ||
467 | int Incidence::secrecy() const | 467 | int Incidence::secrecy() const |
468 | { | 468 | { |
469 | return mSecrecy; | 469 | return mSecrecy; |
470 | } | 470 | } |
471 | 471 | ||
472 | QString Incidence::secrecyStr() const | 472 | QString Incidence::secrecyStr() const |
473 | { | 473 | { |
474 | return secrecyName(mSecrecy); | 474 | return secrecyName(mSecrecy); |
475 | } | 475 | } |
476 | 476 | ||
477 | QString Incidence::secrecyName(int secrecy) | 477 | QString Incidence::secrecyName(int secrecy) |
478 | { | 478 | { |
479 | switch (secrecy) { | 479 | switch (secrecy) { |
480 | case SecrecyPublic: | 480 | case SecrecyPublic: |
481 | return i18n("Public"); | 481 | return i18n("Public"); |
482 | break; | 482 | break; |
483 | case SecrecyPrivate: | 483 | case SecrecyPrivate: |
484 | return i18n("Private"); | 484 | return i18n("Private"); |
485 | break; | 485 | break; |
486 | case SecrecyConfidential: | 486 | case SecrecyConfidential: |
487 | return i18n("Confidential"); | 487 | return i18n("Confidential"); |
488 | break; | 488 | break; |
489 | default: | 489 | default: |
490 | return i18n("Undefined"); | 490 | return i18n("Undefined"); |
491 | break; | 491 | break; |
492 | } | 492 | } |
493 | } | 493 | } |
494 | 494 | ||
495 | QStringList Incidence::secrecyList() | 495 | QStringList Incidence::secrecyList() |
496 | { | 496 | { |
497 | QStringList list; | 497 | QStringList list; |
498 | list << secrecyName(SecrecyPublic); | 498 | list << secrecyName(SecrecyPublic); |
499 | list << secrecyName(SecrecyPrivate); | 499 | list << secrecyName(SecrecyPrivate); |
500 | list << secrecyName(SecrecyConfidential); | 500 | list << secrecyName(SecrecyConfidential); |
501 | 501 | ||
502 | return list; | 502 | return list; |
503 | } | 503 | } |
504 | 504 | ||
505 | 505 | ||
506 | QPtrList<Alarm> Incidence::alarms() const | 506 | QPtrList<Alarm> Incidence::alarms() const |
507 | { | 507 | { |
508 | return mAlarms; | 508 | return mAlarms; |
509 | } | 509 | } |
510 | 510 | ||
511 | Alarm* Incidence::newAlarm() | 511 | Alarm* Incidence::newAlarm() |
512 | { | 512 | { |
513 | Alarm* alarm = new Alarm(this); | 513 | Alarm* alarm = new Alarm(this); |
514 | mAlarms.append(alarm); | 514 | mAlarms.append(alarm); |
515 | // updated(); | 515 | // updated(); |
516 | return alarm; | 516 | return alarm; |
517 | } | 517 | } |
518 | 518 | ||
519 | void Incidence::addAlarm(Alarm *alarm) | 519 | void Incidence::addAlarm(Alarm *alarm) |
520 | { | 520 | { |
521 | mAlarms.append(alarm); | 521 | mAlarms.append(alarm); |
522 | updated(); | 522 | updated(); |
523 | } | 523 | } |
524 | 524 | ||
525 | void Incidence::removeAlarm(Alarm *alarm) | 525 | void Incidence::removeAlarm(Alarm *alarm) |
526 | { | 526 | { |
527 | mAlarms.removeRef(alarm); | 527 | mAlarms.removeRef(alarm); |
528 | updated(); | 528 | updated(); |
529 | } | 529 | } |
530 | 530 | ||
531 | void Incidence::clearAlarms() | 531 | void Incidence::clearAlarms() |
532 | { | 532 | { |
533 | mAlarms.clear(); | 533 | mAlarms.clear(); |
534 | updated(); | 534 | updated(); |
535 | } | 535 | } |
536 | 536 | ||
537 | bool Incidence::isAlarmEnabled() const | 537 | bool Incidence::isAlarmEnabled() const |
538 | { | 538 | { |
539 | Alarm* alarm; | 539 | Alarm* alarm; |
540 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 540 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
541 | if (alarm->enabled()) | 541 | if (alarm->enabled()) |
542 | return true; | 542 | return true; |
543 | } | 543 | } |
544 | return false; | 544 | return false; |
545 | } | 545 | } |
546 | 546 | ||
547 | Recurrence *Incidence::recurrence() const | 547 | Recurrence *Incidence::recurrence() const |
548 | { | 548 | { |
549 | return mRecurrence; | 549 | return mRecurrence; |
550 | } | 550 | } |
551 | void Incidence::setRecurrence( Recurrence * r) | 551 | void Incidence::setRecurrence( Recurrence * r) |
552 | { | 552 | { |
553 | delete mRecurrence; | 553 | delete mRecurrence; |
554 | mRecurrence = r; | 554 | mRecurrence = r; |
555 | } | 555 | } |
556 | 556 | ||
557 | void Incidence::setLocation(const QString &location) | 557 | void Incidence::setLocation(const QString &location) |
558 | { | 558 | { |
559 | if (mReadOnly) return; | 559 | if (mReadOnly) return; |
560 | mLocation = location; | 560 | mLocation = location; |
561 | updated(); | 561 | updated(); |
562 | } | 562 | } |
563 | 563 | ||
564 | QString Incidence::location() const | 564 | QString Incidence::location() const |
565 | { | 565 | { |
566 | return mLocation; | 566 | return mLocation; |
567 | } | 567 | } |
568 | 568 | ||
569 | ushort Incidence::doesRecur() const | 569 | ushort Incidence::doesRecur() const |
570 | { | 570 | { |
571 | if ( mRecurrence ) return mRecurrence->doesRecur(); | 571 | if ( mRecurrence ) return mRecurrence->doesRecur(); |
572 | else return Recurrence::rNone; | 572 | else return Recurrence::rNone; |
573 | } | 573 | } |
574 | 574 | ||
575 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const | 575 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const |
576 | { | 576 | { |
577 | QDateTime incidenceStart = dt; | 577 | QDateTime incidenceStart = dt; |
578 | *ok = false; | 578 | *ok = false; |
579 | if ( doesRecur() ) { | 579 | if ( doesRecur() ) { |
580 | bool last; | 580 | bool last; |
581 | recurrence()->getPreviousDateTime( incidenceStart , &last ); | 581 | recurrence()->getPreviousDateTime( incidenceStart , &last ); |
582 | int count = 0; | 582 | int count = 0; |
583 | if ( !last ) { | 583 | if ( !last ) { |
584 | while ( !last ) { | 584 | while ( !last ) { |
585 | ++count; | 585 | ++count; |
586 | incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); | 586 | incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); |
587 | if ( recursOn( incidenceStart.date() ) ) { | 587 | if ( recursOn( incidenceStart.date() ) ) { |
588 | last = true; // exit while llop | 588 | last = true; // exit while llop |
589 | } else { | 589 | } else { |
590 | if ( last ) { // no alarm on last recurrence | 590 | if ( last ) { // no alarm on last recurrence |
591 | return QDateTime (); | 591 | return QDateTime (); |
592 | } | 592 | } |
593 | int year = incidenceStart.date().year(); | 593 | int year = incidenceStart.date().year(); |
594 | // workaround for bug in recurrence | 594 | // workaround for bug in recurrence |
595 | if ( count == 100 || year < 1980 || year > 5000 ) { | 595 | if ( count == 100 || year < 1000 || year > 5000 ) { |
596 | return QDateTime (); | 596 | return QDateTime (); |
597 | } | 597 | } |
598 | incidenceStart = incidenceStart.addSecs( 1 ); | 598 | incidenceStart = incidenceStart.addSecs( 1 ); |
599 | } | 599 | } |
600 | } | 600 | } |
601 | } else { | 601 | } else { |
602 | return QDateTime (); | 602 | return QDateTime (); |
603 | } | 603 | } |
604 | } else { | 604 | } else { |
605 | if ( hasStartDate () ) { | 605 | if ( hasStartDate () ) { |
606 | incidenceStart = dtStart(); | 606 | incidenceStart = dtStart(); |
607 | } | 607 | } |
608 | if ( type() =="Todo" ) { | 608 | if ( type() =="Todo" ) { |
609 | if ( ((Todo*)this)->hasDueDate() ) | 609 | if ( ((Todo*)this)->hasDueDate() ) |
610 | incidenceStart = ((Todo*)this)->dtDue(); | 610 | incidenceStart = ((Todo*)this)->dtDue(); |
611 | |||
612 | } | 611 | } |
613 | } | 612 | } |
614 | if ( incidenceStart > dt ) | 613 | if ( incidenceStart > dt ) |
615 | *ok = true; | 614 | *ok = true; |
616 | return incidenceStart; | 615 | return incidenceStart; |
617 | } | 616 | } |