author | umopapisdn <umopapisdn> | 2003-04-12 01:19:53 (UTC) |
---|---|---|
committer | umopapisdn <umopapisdn> | 2003-04-12 01:19:53 (UTC) |
commit | 212aef7fd20182fe926644af2ab10a4b49549440 (patch) (side-by-side diff) | |
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 @@ -200,125 +200,129 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f ) connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) ); connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(changeWeek(bool)) ); #if defined(Q_WS_QWS) && !defined(QT_NO_COP) connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), this, SLOT(appMessage(const QCString&, const QByteArray&)) ); #endif // listen on QPE/System #if defined(Q_WS_QWS) #if !defined(QT_NO_COP) QCopChannel *channel = new QCopChannel( "QPE/System", this ); connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); channel = new QCopChannel( "QPE/Datebook", this ); connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); qDebug("olle\n"); #endif #endif qDebug("done t=%d", t.elapsed() ); - + /* * Here is a problem description: * When Weekview is the default view * a DateBookWeekView get's created * redraw() get's called. So what? * Remember that we're still in the c'tor * and no final layout has happened? Ok * now all Events get arranged. Their x * position get's determined by a QHeader * position. But the QHeader isn't layouted or * at the right position. redraw() is a slot * so we'll call it then via a singleShot * from view() */ - if( needEvilHack ){ - QTimer::singleShot( 500, this, SLOT(viewWeek()) ); - } + if( needEvilHack ){ + QTimer::singleShot( 500, this, SLOT(viewWeek()) ); + } } void DateBook::receive( const QCString &msg, const QByteArray &data ) { QDataStream stream( data, IO_ReadOnly ); if ( msg == "timeChange(QString)" ) { // update active view! if ( dayAction->isOn() ) viewDay(); else if ( weekAction->isOn() ) viewWeek(); else if ( monthAction->isOn() ) viewMonth(); } else if (msg == "editEvent(int)") { int uid; stream >> uid; Event e=db->eventByUID(uid); editEvent(e); } } DateBook::~DateBook() { } void DateBook::slotSettings() { DateBookSettings frmSettings( ampm, this ); frmSettings.setStartTime( startTime ); frmSettings.setAlarmPreset( aPreset, presetTime ); frmSettings.setJumpToCurTime( bJumpToCurTime ); frmSettings.setRowStyle( rowStyle ); #if defined (Q_WS_QWS) || defined(_WS_QWS_) frmSettings.showMaximized(); #endif - if ( frmSettings.exec() ) { - aPreset = frmSettings.alarmPreset(); - presetTime = frmSettings.presetTime(); - startTime = frmSettings.startTime(); - bJumpToCurTime = frmSettings.jumpToCurTime(); - rowStyle = frmSettings.rowStyle(); - if ( dayView ) - dayView->setStartViewTime( startTime ); - dayView->setJumpToCurTime( bJumpToCurTime ); - dayView->setRowStyle( rowStyle ); - if ( weekView ) - weekView->setStartViewTime( startTime ); - saveSettings(); - - // make the change obvious - if ( views->visibleWidget() ) { - if ( views->visibleWidget() == dayView ) - dayView->redraw(); - else if ( views->visibleWidget() == weekView ) - weekView->redraw(); + if ( frmSettings.exec() ) { + + aPreset = frmSettings.alarmPreset(); + presetTime = frmSettings.presetTime(); + startTime = frmSettings.startTime(); + bJumpToCurTime = frmSettings.jumpToCurTime(); + rowStyle = frmSettings.rowStyle(); + + if ( dayView ) { + dayView->setStartViewTime( startTime ); + dayView->setJumpToCurTime( bJumpToCurTime ); + dayView->setRowStyle( rowStyle ); + } + if ( weekView ) { + weekView->setStartViewTime( startTime ); + } + saveSettings(); + + // make the change obvious + if ( views->visibleWidget() ) { + if ( views->visibleWidget() == dayView ) + dayView->redraw(); + else if ( views->visibleWidget() == weekView ) + weekView->redraw(); + } } - } } void DateBook::fileNew() { slotNewEventFromKey(""); } QString DateBook::checkEvent(const Event &e) { /* check if overlaps with itself */ bool checkFailed = FALSE; /* check the next 12 repeats. should catch most problems */ QDate current_date = e.start().date(); Event previous = e; for(int i = 0; i < 12; i++) { QDateTime next; if (!nextOccurance(previous, current_date.addDays(1), next)) { break; // no more repeats } if(next < previous.end()) { checkFailed = TRUE; break; @@ -330,73 +334,73 @@ QString DateBook::checkEvent(const Event &e) return tr("Event duration is potentially longer\n" "than interval between repeats."); return QString::null; } QDate DateBook::currentDate() { QDate d = QDate::currentDate(); if ( dayView && views->visibleWidget() == dayView ) { d = dayView->date(); } else if ( weekView && views->visibleWidget() == weekView ) { d = weekView->date(); } else if ( weekLstView && views->visibleWidget() == weekLstView ) { d = weekLstView->date(); } else if ( monthView && views->visibleWidget() == monthView ) { d = monthView->selectedDate(); } return d; } void DateBook::view(int v, const QDate &d) { - if (v==DAY) { - initDay(); - dayAction->setOn( TRUE ); - dayView->setDate( d ); - views->raiseWidget( dayView ); - dayView->redraw(); - } else if (v==WEEK) { - initWeek(); - weekAction->setOn( TRUE ); - weekView->setDate( d ); - views->raiseWidget( weekView ); - weekView->redraw(); - } else if (v==WEEKLST) { - initWeekLst(); - weekLstAction->setOn( TRUE ); - weekLstView->setDate(d); - views->raiseWidget( weekLstView ); - weekLstView->redraw(); - } else if (v==MONTH) { - initMonth(); - monthAction->setOn( TRUE ); - monthView->setDate( d.year(), d.month(), d.day() ); - views->raiseWidget( monthView ); - monthView->redraw(); - } + if (v==DAY) { + initDay(); + dayAction->setOn( TRUE ); + dayView->setDate( d ); + views->raiseWidget( dayView ); + dayView->redraw(); + } else if (v==WEEK) { + initWeek(); + weekAction->setOn( TRUE ); + weekView->setDate( d ); + views->raiseWidget( weekView ); + weekView->redraw(); + } else if (v==WEEKLST) { + initWeekLst(); + weekLstAction->setOn( TRUE ); + weekLstView->setDate(d); + views->raiseWidget( weekLstView ); + weekLstView->redraw(); + } else if (v==MONTH) { + initMonth(); + monthAction->setOn( TRUE ); + monthView->setDate( d.year(), d.month(), d.day() ); + views->raiseWidget( monthView ); + monthView->redraw(); + } } void DateBook::viewDefault(const QDate &d) { Config config("DateBook"); config.setGroup("Main"); int current=config.readNumEntry("defaultview", DAY); view(current,d); } void DateBook::viewDay() { view(DAY,currentDate()); } void DateBook::viewWeek() { view(WEEK,currentDate()); } void DateBook::viewWeekLst() { view(WEEKLST,currentDate()); } void DateBook::viewMonth() { view(MONTH,currentDate()); @@ -493,99 +497,100 @@ void DateBook::removeEvent( const Event &e ) if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) return; db->removeEvent( e ); if ( views->visibleWidget() == dayView && dayView ) dayView->redraw(); } void DateBook::addEvent( const Event &e ) { QDate d = e.start().date(); initDay(); dayView->setDate( d ); } void DateBook::showDay( int year, int month, int day ) { QDate d(year, month, day); view(DAY,d); } void DateBook::initDay() { - if ( !dayView ) { - dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); - views->addWidget( dayView, DAY ); - dayView->setStartViewTime( startTime ); - dayView->setJumpToCurTime( bJumpToCurTime ); - dayView->setRowStyle( rowStyle ); - connect( this, SIGNAL( newEvent() ), - dayView, SLOT( redraw() ) ); - connect( dayView, SIGNAL( newEvent() ), - this, SLOT( fileNew() ) ); - connect( dayView, SIGNAL( removeEvent( const Event & ) ), - this, SLOT( removeEvent( const Event & ) ) ); - connect( dayView, SIGNAL( editEvent( const Event & ) ), - this, SLOT( editEvent( const Event & ) ) ); - connect( dayView, SIGNAL( duplicateEvent( const Event & ) ), - this, SLOT( duplicateEvent( const Event & ) ) ); - connect( dayView, SIGNAL( beamEvent( const Event & ) ), - this, SLOT( beamEvent( const Event & ) ) ); - connect( dayView, SIGNAL(sigNewEvent(const QString &)), - this, SLOT(slotNewEventFromKey(const QString &)) ); + if ( !dayView ) { + dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); + views->addWidget( dayView, DAY ); + dayView->setStartViewTime( startTime ); + dayView->setJumpToCurTime( bJumpToCurTime ); + dayView->setRowStyle( rowStyle ); + connect( this, SIGNAL( newEvent() ), + dayView, SLOT( redraw() ) ); + connect( dayView, SIGNAL( newEvent() ), + this, SLOT( fileNew() ) ); + connect( dayView, SIGNAL( removeEvent( const Event & ) ), + this, SLOT( removeEvent( const Event & ) ) ); + connect( dayView, SIGNAL( editEvent( const Event & ) ), + this, SLOT( editEvent( const Event & ) ) ); + connect( dayView, SIGNAL( duplicateEvent( const Event & ) ), + this, SLOT( duplicateEvent( const Event & ) ) ); + connect( dayView, SIGNAL( beamEvent( const Event & ) ), + this, SLOT( beamEvent( const Event & ) ) ); + connect( dayView, SIGNAL(sigNewEvent(const QString &)), + this, SLOT(slotNewEventFromKey(const QString &)) ); } } void DateBook::initWeek() { - if ( !weekView ) { - weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); - weekView->setStartViewTime( startTime ); - views->addWidget( weekView, WEEK ); - connect( weekView, SIGNAL( showDate( int, int, int ) ), - this, SLOT( showDay( int, int, int ) ) ); - connect( this, SIGNAL( newEvent() ), - weekView, SLOT( redraw() ) ); - } - //But also get it right: the year that we display can be different - //from the year of the current date. So, first find the year - //number of the current week. - - int yearNumber, totWeeks; - calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); + if ( !weekView ) { + weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); + weekView->setStartViewTime( startTime ); + views->addWidget( weekView, WEEK ); + connect( weekView, SIGNAL( showDate( int, int, int ) ), + this, SLOT( showDay( int, int, int ) ) ); + connect( this, SIGNAL( newEvent() ), + weekView, SLOT( redraw() ) ); + } - QDate d = QDate( yearNumber, 12, 31 ); - calcWeek( d, totWeeks, yearNumber, onMonday ); + //But also get it right: the year that we display can be different + //from the year of the current date. So, first find the year + //number of the current week. + int yearNumber, totWeeks; + calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); - while ( totWeeks == 1 ) { - d = d.addDays( -1 ); + QDate d = QDate( yearNumber, 12, 31 ); calcWeek( d, totWeeks, yearNumber, onMonday ); - } - if ( totWeeks != weekView->totalWeeks() ) - weekView->setTotalWeeks( totWeeks ); + + while ( totWeeks == 1 ) { + d = d.addDays( -1 ); + calcWeek( d, totWeeks, yearNumber, onMonday ); + } + if ( totWeeks != weekView->totalWeeks() ) + weekView->setTotalWeeks( totWeeks ); } + void DateBook::initWeekLst() { if ( !weekLstView ) { weekLstView = new DateBookWeekLst( ampm, onMonday, db, views, "weeklst view" ); views->addWidget( weekLstView, WEEKLST ); //weekLstView->setStartViewTime( startTime ); connect( weekLstView, SIGNAL( showDate( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) ); connect( weekLstView, SIGNAL( addEvent( const QDateTime &, const QDateTime &, const QString & , const QString &) ), this, SLOT( slotNewEntry( const QDateTime &, const QDateTime &, const QString & , const QString &) ) ); connect( this, SIGNAL( newEvent() ), weekLstView, SLOT( redraw() ) ); connect( weekLstView, SIGNAL( editEvent( const Event & ) ), this, SLOT( editEvent( const Event & ) ) ); } } void DateBook::initMonth() |