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 | |||
@@ -216,34 +216,34 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f ) | |||
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() ) |
@@ -271,38 +271,42 @@ void DateBook::slotSettings() | |||
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) |
@@ -346,41 +350,41 @@ QDate DateBook::currentDate() | |||
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); |
@@ -509,67 +513,68 @@ void DateBook::addEvent( const Event &e ) | |||
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 ) ), |