author | umopapisdn <umopapisdn> | 2003-04-12 01:19:53 (UTC) |
---|---|---|
committer | umopapisdn <umopapisdn> | 2003-04-12 01:19:53 (UTC) |
commit | 212aef7fd20182fe926644af2ab10a4b49549440 (patch) (unidiff) | |
tree | 9e8fb96b40037b31cb2eed411c7a51f35d819ddc | |
parent | 79fcbf52d267aa3eb839de35f15992bf5e18f8eb (diff) | |
download | opie-212aef7fd20182fe926644af2ab10a4b49549440.zip opie-212aef7fd20182fe926644af2ab10a4b49549440.tar.gz opie-212aef7fd20182fe926644af2ab10a4b49549440.tar.bz2 |
Bugfix: Datebook shouldn't crash if we modify prefences when dayview isn't initialized. :)
-rw-r--r-- | core/pim/datebook/datebook.cpp | 189 |
1 files changed, 97 insertions, 92 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp index 1bc82a5..829f8f8 100644 --- a/core/pim/datebook/datebook.cpp +++ b/core/pim/datebook/datebook.cpp | |||
@@ -160,283 +160,287 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f ) | |||
160 | a->addTo( sub_bar ); | 160 | a->addTo( sub_bar ); |
161 | a->addTo( view ); | 161 | a->addTo( view ); |
162 | a->setToggleAction( TRUE ); | 162 | a->setToggleAction( TRUE ); |
163 | monthAction = a; | 163 | monthAction = a; |
164 | 164 | ||
165 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 ); | 165 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 ); |
166 | connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); | 166 | connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); |
167 | a->addTo( sub_bar ); | 167 | a->addTo( sub_bar ); |
168 | 168 | ||
169 | a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 ); | 169 | a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 ); |
170 | connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); | 170 | connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); |
171 | a->addTo( settings ); | 171 | a->addTo( settings ); |
172 | 172 | ||
173 | QPopupMenu *default_view = new QPopupMenu(this); | 173 | QPopupMenu *default_view = new QPopupMenu(this); |
174 | settings->insertItem( tr( "Default View" ),default_view ); | 174 | settings->insertItem( tr( "Default View" ),default_view ); |
175 | default_view->setCheckable(TRUE); | 175 | default_view->setCheckable(TRUE); |
176 | 176 | ||
177 | Config config("DateBook"); | 177 | Config config("DateBook"); |
178 | config.setGroup("Main"); | 178 | config.setGroup("Main"); |
179 | int current=config.readNumEntry("defaultview", DAY); | 179 | int current=config.readNumEntry("defaultview", DAY); |
180 | 180 | ||
181 | QActionGroup *ag = new QActionGroup(this); | 181 | QActionGroup *ag = new QActionGroup(this); |
182 | a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true ); | 182 | a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true ); |
183 | if (current==DAY) a->setOn(true), viewDay(); | 183 | if (current==DAY) a->setOn(true), viewDay(); |
184 | ag->insert(a); | 184 | ag->insert(a); |
185 | a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true ); | 185 | a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true ); |
186 | if (current==WEEK) a->setOn(true), /*viewWeek(),*/ needEvilHack = true; | 186 | if (current==WEEK) a->setOn(true), /*viewWeek(),*/ needEvilHack = true; |
187 | ag->insert(a); | 187 | ag->insert(a); |
188 | a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true ); | 188 | a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true ); |
189 | if (current==WEEKLST) a->setOn(true), viewWeekLst(); | 189 | if (current==WEEKLST) a->setOn(true), viewWeekLst(); |
190 | ag->insert(a); | 190 | ag->insert(a); |
191 | a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true ); | 191 | a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true ); |
192 | if (current==MONTH) a->setOn(true), viewMonth(); | 192 | if (current==MONTH) a->setOn(true), viewMonth(); |
193 | ag->insert(a); | 193 | ag->insert(a); |
194 | 194 | ||
195 | ag->addTo(default_view); | 195 | ag->addTo(default_view); |
196 | connect(ag, SIGNAL( selected ( QAction * ) ), | 196 | connect(ag, SIGNAL( selected ( QAction * ) ), |
197 | this, SLOT( newDefaultView(QAction *) ) | 197 | this, SLOT( newDefaultView(QAction *) ) |
198 | ); | 198 | ); |
199 | 199 | ||
200 | connect( qApp, SIGNAL(clockChanged(bool)), | 200 | connect( qApp, SIGNAL(clockChanged(bool)), |
201 | this, SLOT(changeClock(bool)) ); | 201 | this, SLOT(changeClock(bool)) ); |
202 | connect( qApp, SIGNAL(weekChanged(bool)), | 202 | connect( qApp, SIGNAL(weekChanged(bool)), |
203 | this, SLOT(changeWeek(bool)) ); | 203 | this, SLOT(changeWeek(bool)) ); |
204 | 204 | ||
205 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 205 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
206 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), | 206 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), |
207 | this, SLOT(appMessage(const QCString&, const QByteArray&)) ); | 207 | this, SLOT(appMessage(const QCString&, const QByteArray&)) ); |
208 | #endif | 208 | #endif |
209 | 209 | ||
210 | // listen on QPE/System | 210 | // listen on QPE/System |
211 | #if defined(Q_WS_QWS) | 211 | #if defined(Q_WS_QWS) |
212 | #if !defined(QT_NO_COP) | 212 | #if !defined(QT_NO_COP) |
213 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); | 213 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); |
214 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 214 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
215 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 215 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
216 | channel = new QCopChannel( "QPE/Datebook", this ); | 216 | channel = new QCopChannel( "QPE/Datebook", this ); |
217 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 217 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
218 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 218 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
219 | qDebug("olle\n"); | 219 | qDebug("olle\n"); |
220 | #endif | 220 | #endif |
221 | #endif | 221 | #endif |
222 | 222 | ||
223 | qDebug("done t=%d", t.elapsed() ); | 223 | qDebug("done t=%d", t.elapsed() ); |
224 | 224 | ||
225 | /* | 225 | /* |
226 | * Here is a problem description: | 226 | * Here is a problem description: |
227 | * When Weekview is the default view | 227 | * When Weekview is the default view |
228 | * a DateBookWeekView get's created | 228 | * a DateBookWeekView get's created |
229 | * redraw() get's called. So what? | 229 | * redraw() get's called. So what? |
230 | * Remember that we're still in the c'tor | 230 | * Remember that we're still in the c'tor |
231 | * and no final layout has happened? Ok | 231 | * and no final layout has happened? Ok |
232 | * now all Events get arranged. Their x | 232 | * now all Events get arranged. Their x |
233 | * position get's determined by a QHeader | 233 | * position get's determined by a QHeader |
234 | * position. But the QHeader isn't layouted or | 234 | * position. But the QHeader isn't layouted or |
235 | * at the right position. redraw() is a slot | 235 | * at the right position. redraw() is a slot |
236 | * so we'll call it then via a singleShot | 236 | * so we'll call it then via a singleShot |
237 | * from view() | 237 | * from view() |
238 | */ | 238 | */ |
239 | if( needEvilHack ){ | 239 | if( needEvilHack ){ |
240 | QTimer::singleShot( 500, this, SLOT(viewWeek()) ); | 240 | QTimer::singleShot( 500, this, SLOT(viewWeek()) ); |
241 | } | 241 | } |
242 | } | 242 | } |
243 | 243 | ||
244 | void DateBook::receive( const QCString &msg, const QByteArray &data ) | 244 | void DateBook::receive( const QCString &msg, const QByteArray &data ) |
245 | { | 245 | { |
246 | QDataStream stream( data, IO_ReadOnly ); | 246 | QDataStream stream( data, IO_ReadOnly ); |
247 | if ( msg == "timeChange(QString)" ) { | 247 | if ( msg == "timeChange(QString)" ) { |
248 | // update active view! | 248 | // update active view! |
249 | if ( dayAction->isOn() ) | 249 | if ( dayAction->isOn() ) |
250 | viewDay(); | 250 | viewDay(); |
251 | else if ( weekAction->isOn() ) | 251 | else if ( weekAction->isOn() ) |
252 | viewWeek(); | 252 | viewWeek(); |
253 | else if ( monthAction->isOn() ) | 253 | else if ( monthAction->isOn() ) |
254 | viewMonth(); | 254 | viewMonth(); |
255 | } | 255 | } |
256 | else if (msg == "editEvent(int)") { | 256 | else if (msg == "editEvent(int)") { |
257 | int uid; | 257 | int uid; |
258 | stream >> uid; | 258 | stream >> uid; |
259 | Event e=db->eventByUID(uid); | 259 | Event e=db->eventByUID(uid); |
260 | editEvent(e); | 260 | editEvent(e); |
261 | } | 261 | } |
262 | } | 262 | } |
263 | 263 | ||
264 | DateBook::~DateBook() | 264 | DateBook::~DateBook() |
265 | { | 265 | { |
266 | } | 266 | } |
267 | 267 | ||
268 | void DateBook::slotSettings() | 268 | void DateBook::slotSettings() |
269 | { | 269 | { |
270 | DateBookSettings frmSettings( ampm, this ); | 270 | DateBookSettings frmSettings( ampm, this ); |
271 | frmSettings.setStartTime( startTime ); | 271 | frmSettings.setStartTime( startTime ); |
272 | frmSettings.setAlarmPreset( aPreset, presetTime ); | 272 | frmSettings.setAlarmPreset( aPreset, presetTime ); |
273 | frmSettings.setJumpToCurTime( bJumpToCurTime ); | 273 | frmSettings.setJumpToCurTime( bJumpToCurTime ); |
274 | frmSettings.setRowStyle( rowStyle ); | 274 | frmSettings.setRowStyle( rowStyle ); |
275 | #if defined (Q_WS_QWS) || defined(_WS_QWS_) | 275 | #if defined (Q_WS_QWS) || defined(_WS_QWS_) |
276 | frmSettings.showMaximized(); | 276 | frmSettings.showMaximized(); |
277 | #endif | 277 | #endif |
278 | 278 | ||
279 | if ( frmSettings.exec() ) { | 279 | if ( frmSettings.exec() ) { |
280 | aPreset = frmSettings.alarmPreset(); | 280 | |
281 | presetTime = frmSettings.presetTime(); | 281 | aPreset = frmSettings.alarmPreset(); |
282 | startTime = frmSettings.startTime(); | 282 | presetTime = frmSettings.presetTime(); |
283 | bJumpToCurTime = frmSettings.jumpToCurTime(); | 283 | startTime = frmSettings.startTime(); |
284 | rowStyle = frmSettings.rowStyle(); | 284 | bJumpToCurTime = frmSettings.jumpToCurTime(); |
285 | if ( dayView ) | 285 | rowStyle = frmSettings.rowStyle(); |
286 | dayView->setStartViewTime( startTime ); | 286 | |
287 | dayView->setJumpToCurTime( bJumpToCurTime ); | 287 | if ( dayView ) { |
288 | dayView->setRowStyle( rowStyle ); | 288 | dayView->setStartViewTime( startTime ); |
289 | if ( weekView ) | 289 | dayView->setJumpToCurTime( bJumpToCurTime ); |
290 | weekView->setStartViewTime( startTime ); | 290 | dayView->setRowStyle( rowStyle ); |
291 | saveSettings(); | 291 | } |
292 | 292 | if ( weekView ) { | |
293 | // make the change obvious | 293 | weekView->setStartViewTime( startTime ); |
294 | if ( views->visibleWidget() ) { | 294 | } |
295 | if ( views->visibleWidget() == dayView ) | 295 | saveSettings(); |
296 | dayView->redraw(); | 296 | |
297 | else if ( views->visibleWidget() == weekView ) | 297 | // make the change obvious |
298 | weekView->redraw(); | 298 | if ( views->visibleWidget() ) { |
299 | if ( views->visibleWidget() == dayView ) | ||
300 | dayView->redraw(); | ||
301 | else if ( views->visibleWidget() == weekView ) | ||
302 | weekView->redraw(); | ||
303 | } | ||
299 | } | 304 | } |
300 | } | ||
301 | } | 305 | } |
302 | 306 | ||
303 | void DateBook::fileNew() | 307 | void DateBook::fileNew() |
304 | { | 308 | { |
305 | slotNewEventFromKey(""); | 309 | slotNewEventFromKey(""); |
306 | } | 310 | } |
307 | 311 | ||
308 | QString DateBook::checkEvent(const Event &e) | 312 | QString DateBook::checkEvent(const Event &e) |
309 | { | 313 | { |
310 | /* check if overlaps with itself */ | 314 | /* check if overlaps with itself */ |
311 | bool checkFailed = FALSE; | 315 | bool checkFailed = FALSE; |
312 | 316 | ||
313 | /* check the next 12 repeats. should catch most problems */ | 317 | /* check the next 12 repeats. should catch most problems */ |
314 | QDate current_date = e.start().date(); | 318 | QDate current_date = e.start().date(); |
315 | Event previous = e; | 319 | Event previous = e; |
316 | for(int i = 0; i < 12; i++) | 320 | for(int i = 0; i < 12; i++) |
317 | { | 321 | { |
318 | QDateTime next; | 322 | QDateTime next; |
319 | if (!nextOccurance(previous, current_date.addDays(1), next)) { | 323 | if (!nextOccurance(previous, current_date.addDays(1), next)) { |
320 | break; // no more repeats | 324 | break; // no more repeats |
321 | } | 325 | } |
322 | if(next < previous.end()) { | 326 | if(next < previous.end()) { |
323 | checkFailed = TRUE; | 327 | checkFailed = TRUE; |
324 | break; | 328 | break; |
325 | } | 329 | } |
326 | current_date = next.date(); | 330 | current_date = next.date(); |
327 | } | 331 | } |
328 | 332 | ||
329 | if(checkFailed) | 333 | if(checkFailed) |
330 | return tr("Event duration is potentially longer\n" | 334 | return tr("Event duration is potentially longer\n" |
331 | "than interval between repeats."); | 335 | "than interval between repeats."); |
332 | 336 | ||
333 | return QString::null; | 337 | return QString::null; |
334 | } | 338 | } |
335 | 339 | ||
336 | QDate DateBook::currentDate() | 340 | QDate DateBook::currentDate() |
337 | { | 341 | { |
338 | QDate d = QDate::currentDate(); | 342 | QDate d = QDate::currentDate(); |
339 | 343 | ||
340 | if ( dayView && views->visibleWidget() == dayView ) { | 344 | if ( dayView && views->visibleWidget() == dayView ) { |
341 | d = dayView->date(); | 345 | d = dayView->date(); |
342 | } else if ( weekView && views->visibleWidget() == weekView ) { | 346 | } else if ( weekView && views->visibleWidget() == weekView ) { |
343 | d = weekView->date(); | 347 | d = weekView->date(); |
344 | } else if ( weekLstView && views->visibleWidget() == weekLstView ) { | 348 | } else if ( weekLstView && views->visibleWidget() == weekLstView ) { |
345 | d = weekLstView->date(); | 349 | d = weekLstView->date(); |
346 | } else if ( monthView && views->visibleWidget() == monthView ) { | 350 | } else if ( monthView && views->visibleWidget() == monthView ) { |
347 | d = monthView->selectedDate(); | 351 | d = monthView->selectedDate(); |
348 | } | 352 | } |
349 | 353 | ||
350 | return d; | 354 | return d; |
351 | } | 355 | } |
352 | 356 | ||
353 | void DateBook::view(int v, const QDate &d) { | 357 | void DateBook::view(int v, const QDate &d) { |
354 | if (v==DAY) { | 358 | if (v==DAY) { |
355 | initDay(); | 359 | initDay(); |
356 | dayAction->setOn( TRUE ); | 360 | dayAction->setOn( TRUE ); |
357 | dayView->setDate( d ); | 361 | dayView->setDate( d ); |
358 | views->raiseWidget( dayView ); | 362 | views->raiseWidget( dayView ); |
359 | dayView->redraw(); | 363 | dayView->redraw(); |
360 | } else if (v==WEEK) { | 364 | } else if (v==WEEK) { |
361 | initWeek(); | 365 | initWeek(); |
362 | weekAction->setOn( TRUE ); | 366 | weekAction->setOn( TRUE ); |
363 | weekView->setDate( d ); | 367 | weekView->setDate( d ); |
364 | views->raiseWidget( weekView ); | 368 | views->raiseWidget( weekView ); |
365 | weekView->redraw(); | 369 | weekView->redraw(); |
366 | } else if (v==WEEKLST) { | 370 | } else if (v==WEEKLST) { |
367 | initWeekLst(); | 371 | initWeekLst(); |
368 | weekLstAction->setOn( TRUE ); | 372 | weekLstAction->setOn( TRUE ); |
369 | weekLstView->setDate(d); | 373 | weekLstView->setDate(d); |
370 | views->raiseWidget( weekLstView ); | 374 | views->raiseWidget( weekLstView ); |
371 | weekLstView->redraw(); | 375 | weekLstView->redraw(); |
372 | } else if (v==MONTH) { | 376 | } else if (v==MONTH) { |
373 | initMonth(); | 377 | initMonth(); |
374 | monthAction->setOn( TRUE ); | 378 | monthAction->setOn( TRUE ); |
375 | monthView->setDate( d.year(), d.month(), d.day() ); | 379 | monthView->setDate( d.year(), d.month(), d.day() ); |
376 | views->raiseWidget( monthView ); | 380 | views->raiseWidget( monthView ); |
377 | monthView->redraw(); | 381 | monthView->redraw(); |
378 | } | 382 | } |
379 | } | 383 | } |
380 | 384 | ||
381 | void DateBook::viewDefault(const QDate &d) { | 385 | void DateBook::viewDefault(const QDate &d) { |
382 | Config config("DateBook"); | 386 | Config config("DateBook"); |
383 | config.setGroup("Main"); | 387 | config.setGroup("Main"); |
384 | int current=config.readNumEntry("defaultview", DAY); | 388 | int current=config.readNumEntry("defaultview", DAY); |
385 | 389 | ||
386 | view(current,d); | 390 | view(current,d); |
387 | } | 391 | } |
388 | 392 | ||
389 | void DateBook::viewDay() { | 393 | void DateBook::viewDay() { |
390 | view(DAY,currentDate()); | 394 | view(DAY,currentDate()); |
391 | } | 395 | } |
392 | 396 | ||
393 | void DateBook::viewWeek() { | 397 | void DateBook::viewWeek() { |
394 | view(WEEK,currentDate()); | 398 | view(WEEK,currentDate()); |
395 | } | 399 | } |
396 | 400 | ||
397 | void DateBook::viewWeekLst() { | 401 | void DateBook::viewWeekLst() { |
398 | view(WEEKLST,currentDate()); | 402 | view(WEEKLST,currentDate()); |
399 | } | 403 | } |
400 | 404 | ||
401 | void DateBook::viewMonth() { | 405 | void DateBook::viewMonth() { |
402 | view(MONTH,currentDate()); | 406 | view(MONTH,currentDate()); |
403 | } | 407 | } |
404 | 408 | ||
405 | void DateBook::duplicateEvent( const Event &e ) | 409 | void DateBook::duplicateEvent( const Event &e ) |
406 | { | 410 | { |
407 | qWarning("Hmmm..."); | 411 | qWarning("Hmmm..."); |
408 | // Alot of code duplication, as this is almost like editEvent(); | 412 | // Alot of code duplication, as this is almost like editEvent(); |
409 | if (syncing) { | 413 | if (syncing) { |
410 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); | 414 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); |
411 | return; | 415 | return; |
412 | } | 416 | } |
413 | 417 | ||
414 | Event dupevent(e);// Make a duplicate. | 418 | Event dupevent(e);// Make a duplicate. |
415 | 419 | ||
416 | // workaround added for text input. | 420 | // workaround added for text input. |
417 | QDialog editDlg( this, 0, TRUE ); | 421 | QDialog editDlg( this, 0, TRUE ); |
418 | DateEntry *entry; | 422 | DateEntry *entry; |
419 | editDlg.setCaption( tr("Duplicate Event") ); | 423 | editDlg.setCaption( tr("Duplicate Event") ); |
420 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); | 424 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); |
421 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); | 425 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); |
422 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 426 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
423 | // KLUDGE!!! | 427 | // KLUDGE!!! |
424 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); | 428 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); |
425 | vb->addWidget( sv ); | 429 | vb->addWidget( sv ); |
426 | entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" ); | 430 | entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" ); |
427 | entry->timezone->setEnabled( FALSE ); | 431 | entry->timezone->setEnabled( FALSE ); |
428 | sv->addChild( entry ); | 432 | sv->addChild( entry ); |
429 | 433 | ||
430 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 434 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
431 | editDlg.showMaximized(); | 435 | editDlg.showMaximized(); |
432 | #endif | 436 | #endif |
433 | while (editDlg.exec() ) { | 437 | while (editDlg.exec() ) { |
434 | Event newEv = entry->event(); | 438 | Event newEv = entry->event(); |
435 | QString error = checkEvent(newEv); | 439 | QString error = checkEvent(newEv); |
436 | if (!error.isNull()) { | 440 | if (!error.isNull()) { |
437 | if (QMessageBox::warning(this, "error box", error, "Fix it", "Continue", 0, 0, 1) == 0) | 441 | if (QMessageBox::warning(this, "error box", error, "Fix it", "Continue", 0, 0, 1) == 0) |
438 | continue; | 442 | continue; |
439 | } | 443 | } |
440 | db->addEvent(newEv); | 444 | db->addEvent(newEv); |
441 | emit newEvent(); | 445 | emit newEvent(); |
442 | break; | 446 | break; |
@@ -453,179 +457,180 @@ void DateBook::editEvent( const Event &e ) | |||
453 | // workaround added for text input. | 457 | // workaround added for text input. |
454 | QDialog editDlg( this, 0, TRUE ); | 458 | QDialog editDlg( this, 0, TRUE ); |
455 | DateEntry *entry; | 459 | DateEntry *entry; |
456 | editDlg.setCaption( tr("Edit Event") ); | 460 | editDlg.setCaption( tr("Edit Event") ); |
457 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); | 461 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); |
458 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); | 462 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); |
459 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 463 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
460 | // KLUDGE!!! | 464 | // KLUDGE!!! |
461 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); | 465 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); |
462 | vb->addWidget( sv ); | 466 | vb->addWidget( sv ); |
463 | entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); | 467 | entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); |
464 | entry->timezone->setEnabled( FALSE ); | 468 | entry->timezone->setEnabled( FALSE ); |
465 | sv->addChild( entry ); | 469 | sv->addChild( entry ); |
466 | 470 | ||
467 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 471 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
468 | editDlg.showMaximized(); | 472 | editDlg.showMaximized(); |
469 | #endif | 473 | #endif |
470 | while (editDlg.exec() ) { | 474 | while (editDlg.exec() ) { |
471 | Event newEv = entry->event(); | 475 | Event newEv = entry->event(); |
472 | if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) | 476 | if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) |
473 | break; | 477 | break; |
474 | newEv.setUid(e.uid()); // FIXME: Hack not to clear uid | 478 | newEv.setUid(e.uid()); // FIXME: Hack not to clear uid |
475 | QString error = checkEvent(newEv); | 479 | QString error = checkEvent(newEv); |
476 | if (!error.isNull()) { | 480 | if (!error.isNull()) { |
477 | if (QMessageBox::warning(this, "error box", error, "Fix it", "Continue", 0, 0, 1) == 0) continue; | 481 | if (QMessageBox::warning(this, "error box", error, "Fix it", "Continue", 0, 0, 1) == 0) continue; |
478 | } | 482 | } |
479 | db->editEvent(e, newEv); | 483 | db->editEvent(e, newEv); |
480 | emit newEvent(); | 484 | emit newEvent(); |
481 | break; | 485 | break; |
482 | } | 486 | } |
483 | } | 487 | } |
484 | 488 | ||
485 | void DateBook::removeEvent( const Event &e ) | 489 | void DateBook::removeEvent( const Event &e ) |
486 | { | 490 | { |
487 | if (syncing) { | 491 | if (syncing) { |
488 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); | 492 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); |
489 | return; | 493 | return; |
490 | } | 494 | } |
491 | 495 | ||
492 | QString strName = e.description(); | 496 | QString strName = e.description(); |
493 | 497 | ||
494 | if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) | 498 | if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) |
495 | return; | 499 | return; |
496 | 500 | ||
497 | db->removeEvent( e ); | 501 | db->removeEvent( e ); |
498 | if ( views->visibleWidget() == dayView && dayView ) | 502 | if ( views->visibleWidget() == dayView && dayView ) |
499 | dayView->redraw(); | 503 | dayView->redraw(); |
500 | } | 504 | } |
501 | 505 | ||
502 | void DateBook::addEvent( const Event &e ) | 506 | void DateBook::addEvent( const Event &e ) |
503 | { | 507 | { |
504 | QDate d = e.start().date(); | 508 | QDate d = e.start().date(); |
505 | initDay(); | 509 | initDay(); |
506 | dayView->setDate( d ); | 510 | dayView->setDate( d ); |
507 | } | 511 | } |
508 | 512 | ||
509 | void DateBook::showDay( int year, int month, int day ) | 513 | void DateBook::showDay( int year, int month, int day ) |
510 | { | 514 | { |
511 | QDate d(year, month, day); | 515 | QDate d(year, month, day); |
512 | view(DAY,d); | 516 | view(DAY,d); |
513 | } | 517 | } |
514 | 518 | ||
515 | void DateBook::initDay() | 519 | void DateBook::initDay() |
516 | { | 520 | { |
517 | if ( !dayView ) { | 521 | if ( !dayView ) { |
518 | dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); | 522 | dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); |
519 | views->addWidget( dayView, DAY ); | 523 | views->addWidget( dayView, DAY ); |
520 | dayView->setStartViewTime( startTime ); | 524 | dayView->setStartViewTime( startTime ); |
521 | dayView->setJumpToCurTime( bJumpToCurTime ); | 525 | dayView->setJumpToCurTime( bJumpToCurTime ); |
522 | dayView->setRowStyle( rowStyle ); | 526 | dayView->setRowStyle( rowStyle ); |
523 | connect( this, SIGNAL( newEvent() ), | 527 | connect( this, SIGNAL( newEvent() ), |
524 | dayView, SLOT( redraw() ) ); | 528 | dayView, SLOT( redraw() ) ); |
525 | connect( dayView, SIGNAL( newEvent() ), | 529 | connect( dayView, SIGNAL( newEvent() ), |
526 | this, SLOT( fileNew() ) ); | 530 | this, SLOT( fileNew() ) ); |
527 | connect( dayView, SIGNAL( removeEvent( const Event & ) ), | 531 | connect( dayView, SIGNAL( removeEvent( const Event & ) ), |
528 | this, SLOT( removeEvent( const Event & ) ) ); | 532 | this, SLOT( removeEvent( const Event & ) ) ); |
529 | connect( dayView, SIGNAL( editEvent( const Event & ) ), | 533 | connect( dayView, SIGNAL( editEvent( const Event & ) ), |
530 | this, SLOT( editEvent( const Event & ) ) ); | 534 | this, SLOT( editEvent( const Event & ) ) ); |
531 | connect( dayView, SIGNAL( duplicateEvent( const Event & ) ), | 535 | connect( dayView, SIGNAL( duplicateEvent( const Event & ) ), |
532 | this, SLOT( duplicateEvent( const Event & ) ) ); | 536 | this, SLOT( duplicateEvent( const Event & ) ) ); |
533 | connect( dayView, SIGNAL( beamEvent( const Event & ) ), | 537 | connect( dayView, SIGNAL( beamEvent( const Event & ) ), |
534 | this, SLOT( beamEvent( const Event & ) ) ); | 538 | this, SLOT( beamEvent( const Event & ) ) ); |
535 | connect( dayView, SIGNAL(sigNewEvent(const QString &)), | 539 | connect( dayView, SIGNAL(sigNewEvent(const QString &)), |
536 | this, SLOT(slotNewEventFromKey(const QString &)) ); | 540 | this, SLOT(slotNewEventFromKey(const QString &)) ); |
537 | } | 541 | } |
538 | } | 542 | } |
539 | 543 | ||
540 | void DateBook::initWeek() | 544 | void DateBook::initWeek() |
541 | { | 545 | { |
542 | if ( !weekView ) { | 546 | if ( !weekView ) { |
543 | weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); | 547 | weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); |
544 | weekView->setStartViewTime( startTime ); | 548 | weekView->setStartViewTime( startTime ); |
545 | views->addWidget( weekView, WEEK ); | 549 | views->addWidget( weekView, WEEK ); |
546 | connect( weekView, SIGNAL( showDate( int, int, int ) ), | 550 | connect( weekView, SIGNAL( showDate( int, int, int ) ), |
547 | this, SLOT( showDay( int, int, int ) ) ); | 551 | this, SLOT( showDay( int, int, int ) ) ); |
548 | connect( this, SIGNAL( newEvent() ), | 552 | connect( this, SIGNAL( newEvent() ), |
549 | weekView, SLOT( redraw() ) ); | 553 | weekView, SLOT( redraw() ) ); |
550 | } | 554 | } |
551 | //But also get it right: the year that we display can be different | ||
552 | //from the year of the current date. So, first find the year | ||
553 | //number of the current week. | ||
554 | |||
555 | int yearNumber, totWeeks; | ||
556 | calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); | ||
557 | 555 | ||
558 | QDate d = QDate( yearNumber, 12, 31 ); | 556 | //But also get it right: the year that we display can be different |
559 | calcWeek( d, totWeeks, yearNumber, onMonday ); | 557 | //from the year of the current date. So, first find the year |
558 | //number of the current week. | ||
559 | int yearNumber, totWeeks; | ||
560 | calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); | ||
560 | 561 | ||
561 | while ( totWeeks == 1 ) { | 562 | QDate d = QDate( yearNumber, 12, 31 ); |
562 | d = d.addDays( -1 ); | ||
563 | calcWeek( d, totWeeks, yearNumber, onMonday ); | 563 | calcWeek( d, totWeeks, yearNumber, onMonday ); |
564 | } | 564 | |
565 | if ( totWeeks != weekView->totalWeeks() ) | 565 | while ( totWeeks == 1 ) { |
566 | weekView->setTotalWeeks( totWeeks ); | 566 | d = d.addDays( -1 ); |
567 | calcWeek( d, totWeeks, yearNumber, onMonday ); | ||
568 | } | ||
569 | if ( totWeeks != weekView->totalWeeks() ) | ||
570 | weekView->setTotalWeeks( totWeeks ); | ||
567 | } | 571 | } |
572 | |||
568 | void DateBook::initWeekLst() { | 573 | void DateBook::initWeekLst() { |
569 | if ( !weekLstView ) { | 574 | if ( !weekLstView ) { |
570 | weekLstView = new DateBookWeekLst( ampm, onMonday, db, | 575 | weekLstView = new DateBookWeekLst( ampm, onMonday, db, |
571 | views, "weeklst view" ); | 576 | views, "weeklst view" ); |
572 | views->addWidget( weekLstView, WEEKLST ); | 577 | views->addWidget( weekLstView, WEEKLST ); |
573 | 578 | ||
574 | //weekLstView->setStartViewTime( startTime ); | 579 | //weekLstView->setStartViewTime( startTime ); |
575 | connect( weekLstView, SIGNAL( showDate( int, int, int ) ), | 580 | connect( weekLstView, SIGNAL( showDate( int, int, int ) ), |
576 | this, SLOT( showDay( int, int, int ) ) ); | 581 | this, SLOT( showDay( int, int, int ) ) ); |
577 | connect( weekLstView, SIGNAL( addEvent( const QDateTime &, | 582 | connect( weekLstView, SIGNAL( addEvent( const QDateTime &, |
578 | const QDateTime &, | 583 | const QDateTime &, |
579 | const QString & , const QString &) ), | 584 | const QString & , const QString &) ), |
580 | this, SLOT( slotNewEntry( const QDateTime &, | 585 | this, SLOT( slotNewEntry( const QDateTime &, |
581 | const QDateTime &, | 586 | const QDateTime &, |
582 | const QString & , const QString &) ) ); | 587 | const QString & , const QString &) ) ); |
583 | connect( this, SIGNAL( newEvent() ), | 588 | connect( this, SIGNAL( newEvent() ), |
584 | weekLstView, SLOT( redraw() ) ); | 589 | weekLstView, SLOT( redraw() ) ); |
585 | connect( weekLstView, SIGNAL( editEvent( const Event & ) ), | 590 | connect( weekLstView, SIGNAL( editEvent( const Event & ) ), |
586 | this, SLOT( editEvent( const Event & ) ) ); | 591 | this, SLOT( editEvent( const Event & ) ) ); |
587 | } | 592 | } |
588 | } | 593 | } |
589 | 594 | ||
590 | 595 | ||
591 | void DateBook::initMonth() | 596 | void DateBook::initMonth() |
592 | { | 597 | { |
593 | if ( !monthView ) { | 598 | if ( !monthView ) { |
594 | monthView = new DateBookMonth( views, "month view", FALSE, db ); | 599 | monthView = new DateBookMonth( views, "month view", FALSE, db ); |
595 | views->addWidget( monthView, MONTH ); | 600 | views->addWidget( monthView, MONTH ); |
596 | connect( monthView, SIGNAL( dateClicked( int, int, int ) ), | 601 | connect( monthView, SIGNAL( dateClicked( int, int, int ) ), |
597 | this, SLOT( showDay( int, int, int ) ) ); | 602 | this, SLOT( showDay( int, int, int ) ) ); |
598 | connect( this, SIGNAL( newEvent() ), | 603 | connect( this, SIGNAL( newEvent() ), |
599 | monthView, SLOT( redraw() ) ); | 604 | monthView, SLOT( redraw() ) ); |
600 | qApp->processEvents(); | 605 | qApp->processEvents(); |
601 | } | 606 | } |
602 | } | 607 | } |
603 | 608 | ||
604 | void DateBook::loadSettings() | 609 | void DateBook::loadSettings() |
605 | { | 610 | { |
606 | { | 611 | { |
607 | Config config( "qpe" ); | 612 | Config config( "qpe" ); |
608 | config.setGroup("Time"); | 613 | config.setGroup("Time"); |
609 | ampm = config.readBoolEntry( "AMPM", TRUE ); | 614 | ampm = config.readBoolEntry( "AMPM", TRUE ); |
610 | onMonday = config.readBoolEntry( "MONDAY" ); | 615 | onMonday = config.readBoolEntry( "MONDAY" ); |
611 | } | 616 | } |
612 | 617 | ||
613 | { | 618 | { |
614 | Config config("DateBook"); | 619 | Config config("DateBook"); |
615 | config.setGroup("Main"); | 620 | config.setGroup("Main"); |
616 | startTime = config.readNumEntry("startviewtime", 8); | 621 | startTime = config.readNumEntry("startviewtime", 8); |
617 | aPreset = config.readBoolEntry("alarmpreset"); | 622 | aPreset = config.readBoolEntry("alarmpreset"); |
618 | presetTime = config.readNumEntry("presettime"); | 623 | presetTime = config.readNumEntry("presettime"); |
619 | bJumpToCurTime = config.readBoolEntry("jumptocurtime"); | 624 | bJumpToCurTime = config.readBoolEntry("jumptocurtime"); |
620 | rowStyle = config.readNumEntry("rowstyle"); | 625 | rowStyle = config.readNumEntry("rowstyle"); |
621 | } | 626 | } |
622 | } | 627 | } |
623 | 628 | ||
624 | void DateBook::saveSettings() | 629 | void DateBook::saveSettings() |
625 | { | 630 | { |
626 | Config config( "qpe" ); | 631 | Config config( "qpe" ); |
627 | Config configDB( "DateBook" ); | 632 | Config configDB( "DateBook" ); |
628 | configDB.setGroup( "Main" ); | 633 | configDB.setGroup( "Main" ); |
629 | configDB.writeEntry("startviewtime",startTime); | 634 | configDB.writeEntry("startviewtime",startTime); |
630 | configDB.writeEntry("alarmpreset",aPreset); | 635 | configDB.writeEntry("alarmpreset",aPreset); |
631 | configDB.writeEntry("presettime",presetTime); | 636 | configDB.writeEntry("presettime",presetTime); |