Diffstat (limited to 'core/pim/datebook/datebook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/datebook/datebook.cpp | 380 |
1 files changed, 169 insertions, 211 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp index 829f8f8..4fbcb10 100644 --- a/core/pim/datebook/datebook.cpp +++ b/core/pim/datebook/datebook.cpp @@ -72,8 +72,2 @@ -#define DAY 1 -#define WEEK 2 -#define WEEKLST 4 -#define MONTH 3 - - DateBook::DateBook( QWidget *parent, const char *, WFlags f ) @@ -168,3 +162,3 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f ) - a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 ); + a = new QAction( tr( "Edit..." ), QString::null, 0, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); @@ -172,37 +166,12 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f ) - QPopupMenu *default_view = new QPopupMenu(this); - settings->insertItem( tr( "Default View" ),default_view ); - default_view->setCheckable(TRUE); - - Config config("DateBook"); - config.setGroup("Main"); - int current=config.readNumEntry("defaultview", DAY); - - QActionGroup *ag = new QActionGroup(this); - a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true ); - if (current==DAY) a->setOn(true), viewDay(); - ag->insert(a); - a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true ); - if (current==WEEK) a->setOn(true), /*viewWeek(),*/ needEvilHack = true; - ag->insert(a); - a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true ); - if (current==WEEKLST) a->setOn(true), viewWeekLst(); - ag->insert(a); - a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true ); - if (current==MONTH) a->setOn(true), viewMonth(); - ag->insert(a); - - ag->addTo(default_view); - connect(ag, SIGNAL( selected ( QAction * ) ), - this, SLOT( newDefaultView(QAction *) ) - ); - - connect( qApp, SIGNAL(clockChanged(bool)), - this, SLOT(changeClock(bool)) ); - connect( qApp, SIGNAL(weekChanged(bool)), - this, SLOT(changeWeek(bool)) ); + if(defaultView==DAY) viewDay(); + if(defaultView==WEEK) needEvilHack=true; // viewWeek(); + if(defaultView==WEEKLST) viewWeekLst(); + if(defaultView==MONTH) viewMonth(); + + 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&)) ); + connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), this, SLOT(appMessage(const QCString&, const QByteArray&)) ); #endif @@ -213,7 +182,5 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f ) QCopChannel *channel = new QCopChannel( "QPE/System", this ); - connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), - this, SLOT(receive(const QCString&, const QByteArray&)) ); + 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&)) ); + connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); qDebug("olle\n"); @@ -269,7 +236,10 @@ void DateBook::slotSettings() { - DateBookSettings frmSettings( ampm, this ); - frmSettings.setStartTime( startTime ); - frmSettings.setAlarmPreset( aPreset, presetTime ); - frmSettings.setJumpToCurTime( bJumpToCurTime ); - frmSettings.setRowStyle( rowStyle ); + DateBookSettings frmSettings( ampm, this ); + frmSettings.setStartTime( startTime ); + frmSettings.setAlarmPreset( aPreset, presetTime ); + frmSettings.setJumpToCurTime( bJumpToCurTime ); + frmSettings.setRowStyle( rowStyle ); + frmSettings.comboDefaultView->setCurrentItem(defaultView-1); + frmSettings.comboWeekListView->setCurrentItem(weeklistviewconfig); + #if defined (Q_WS_QWS) || defined(_WS_QWS_) @@ -285,2 +255,4 @@ void DateBook::slotSettings() rowStyle = frmSettings.rowStyle(); + defaultView=frmSettings.comboDefaultView->currentItem()+1; + weeklistviewconfig=frmSettings.comboWeekListView->currentItem(); @@ -302,2 +274,4 @@ void DateBook::slotSettings() weekView->redraw(); + else if ( views->visibleWidget() == weekLstView ) + weekLstView->redraw(); } @@ -385,2 +359,3 @@ void DateBook::view(int v, const QDate &d) { void DateBook::viewDefault(const QDate &d) { +/* Config config("DateBook"); @@ -390,2 +365,4 @@ void DateBook::viewDefault(const QDate &d) { view(current,d); +*/ + view(defaultView,d); } @@ -610,10 +587,7 @@ void DateBook::loadSettings() { - { - Config config( "qpe" ); - config.setGroup("Time"); - ampm = config.readBoolEntry( "AMPM", TRUE ); - onMonday = config.readBoolEntry( "MONDAY" ); - } + Config qpeconfig( "qpe" ); + qpeconfig.setGroup("Time"); + ampm = qpeconfig.readBoolEntry( "AMPM", TRUE ); + onMonday = qpeconfig.readBoolEntry( "MONDAY" ); - { Config config("DateBook"); @@ -625,3 +599,4 @@ void DateBook::loadSettings() rowStyle = config.readNumEntry("rowstyle"); - } + defaultView = config.readNumEntry("defaultview",DAY); + weeklistviewconfig = config.readNumEntry("weeklistviewconfig",NORMAL); } @@ -630,22 +605,12 @@ void DateBook::saveSettings() { - Config config( "qpe" ); - Config configDB( "DateBook" ); - configDB.setGroup( "Main" ); - configDB.writeEntry("startviewtime",startTime); - configDB.writeEntry("alarmpreset",aPreset); - configDB.writeEntry("presettime",presetTime); - configDB.writeEntry("jumptocurtime", bJumpToCurTime); - configDB.writeEntry("rowstyle", rowStyle); -} - -void DateBook::newDefaultView(QAction *a) { - int val=DAY; - if (a->text() == "Day") val=DAY; - if (a->text() == "Week") val=WEEK; - if (a->text() == "WeekLst") val=WEEKLST; - if (a->text() == "Month") val=MONTH; - - Config configDB( "DateBook" ); - configDB.setGroup( "Main" ); - configDB.writeEntry("defaultview",val); + Config config( "qpe" ); + Config configDB( "DateBook" ); + configDB.setGroup( "Main" ); + configDB.writeEntry("startviewtime",startTime); + configDB.writeEntry("alarmpreset",aPreset); + configDB.writeEntry("presettime",presetTime); + configDB.writeEntry("jumptocurtime", bJumpToCurTime); + configDB.writeEntry("rowstyle", rowStyle); + configDB.writeEntry("defaultview",defaultView); + configDB.writeEntry("weeklistviewconfig",weeklistviewconfig); } @@ -654,85 +619,81 @@ void DateBook::appMessage(const QCString& msg, const QByteArray& data) { - bool needShow = FALSE; - if ( msg == "alarm(QDateTime,int)" ) { - QDataStream ds(data,IO_ReadOnly); - QDateTime when; int warn; - ds >> when >> warn; - - // check to make it's okay to continue, - // this is the case that the time was set ahead, and - // we are forced given a stale alarm... - QDateTime current = QDateTime::currentDateTime(); - if ( current.time().hour() != when.time().hour() - && current.time().minute() != when.time().minute() ) - return; - - QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); - if ( list.count() > 0 ) { - QString msg; - bool bSound = FALSE; - int stopTimer = 0; - bool found = FALSE; - for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); - it!=list.end(); ++it ) { - if ( (*it).event().hasAlarm() ) { - found = TRUE; - msg += "<CENTER><B>" + (*it).description() + "</B>" - + "<BR>" + (*it).location() + "<BR>" - + TimeString::dateString((*it).event().start(),ampm) - + (warn - ? tr(" (in " + QString::number(warn) - + tr(" minutes)")) - : QString("")) - + "<BR>" - + (*it).notes() + "</CENTER>"; - if ( (*it).event().alarmSound() != Event::Silent ) { - bSound = TRUE; - } - } - } - if ( found ) { - if ( bSound ) { - Sound::soundAlarm(); - alarmCounter = 0; - stopTimer = startTimer( 5000 ); - } - - QDialog dlg( this, 0, TRUE ); - QVBoxLayout *vb = new QVBoxLayout( &dlg ); - QScrollView *view = new QScrollView( &dlg, "scrollView"); - view->setResizePolicy( QScrollView::AutoOneFit ); - vb->addWidget( view ); - QLabel *lblMsg = new QLabel( msg, &dlg ); - view->addChild( lblMsg ); - QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); - connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); - vb->addWidget( cmdOk ); + bool needShow = FALSE; + if ( msg == "alarm(QDateTime,int)" ) { + QDataStream ds(data,IO_ReadOnly); + QDateTime when; int warn; + ds >> when >> warn; + + // check to make it's okay to continue, + // this is the case that the time was set ahead, and + // we are forced given a stale alarm... + QDateTime current = QDateTime::currentDateTime(); + if ( current.time().hour() != when.time().hour() && current.time().minute() != when.time().minute() ) + return; + + QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); + if ( list.count() > 0 ) { + QString msg; + bool bSound = FALSE; + int stopTimer = 0; + bool found = FALSE; + for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); it!=list.end(); ++it ) { + if ( (*it).event().hasAlarm() ) { + found = TRUE; + msg += "<CENTER><B>" + (*it).description() + "</B>" + + "<BR>" + (*it).location() + "<BR>" + + TimeString::dateString((*it).event().start(),ampm) + + (warn + ? tr(" (in " + QString::number(warn) + + tr(" minutes)")) + : QString("")) + + "<BR>" + + (*it).notes() + "</CENTER>"; + if ( (*it).event().alarmSound() != Event::Silent ) { + bSound = TRUE; + } + } + } + if ( found ) { + if ( bSound ) { + Sound::soundAlarm(); + alarmCounter = 0; + stopTimer = startTimer( 5000 ); + } + QDialog dlg( this, 0, TRUE ); + QVBoxLayout *vb = new QVBoxLayout( &dlg ); + QScrollView *view = new QScrollView( &dlg, "scrollView"); + view->setResizePolicy( QScrollView::AutoOneFit ); + vb->addWidget( view ); + QLabel *lblMsg = new QLabel( msg, &dlg ); + view->addChild( lblMsg ); + QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); + connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); + vb->addWidget( cmdOk ); #if defined(Q_WS_QWS) || defined(_WS_QWS_) - dlg.showMaximized(); + dlg.showMaximized(); #endif - needShow = dlg.exec(); - - if ( bSound ) - killTimer( stopTimer ); - } - } - } else if ( msg == "nextView()" ) { - if ( !qApp-> activeWindow ( )) { - needShow = TRUE; - } - else { - QWidget* cur = views->visibleWidget(); - if ( cur ) { - if ( cur == dayView ) - viewWeek(); - else if ( cur == weekView ) - viewWeekLst(); - else if ( cur == weekLstView ) - viewMonth(); - else if ( cur == monthView ) - viewDay(); - needShow = TRUE; - } - } + needShow = dlg.exec(); + + if ( bSound ) + killTimer( stopTimer ); + } + } + } else if ( msg == "nextView()" ) { + if ( !qApp-> activeWindow ( )) { + needShow = TRUE; + } else { + QWidget* cur = views->visibleWidget(); + if ( cur ) { + if ( cur == dayView ) + viewWeek(); + else if ( cur == weekView ) + viewWeekLst(); + else if ( cur == weekLstView ) + viewMonth(); + else if ( cur == monthView ) + viewDay(); + needShow = TRUE; + } + } } @@ -740,10 +701,10 @@ void DateBook::appMessage(const QCString& msg, const QByteArray& data) #if defined(Q_WS_QWS) || defined(_WS_QWS_) - showMaximized(); + showMaximized(); #else - show(); + show(); #endif - raise(); - QPEApplication::setKeepRunning(); - setActiveWindow(); - } + raise(); + QPEApplication::setKeepRunning(); + setActiveWindow(); + } } @@ -752,10 +713,7 @@ void DateBook::reload() { - db->reload(); - if ( dayAction->isOn() ) - viewDay(); - else if ( weekAction->isOn() ) - viewWeek(); - else if ( monthAction->isOn() ) - viewMonth(); - syncing = FALSE; + db->reload(); + if ( dayAction->isOn() ) viewDay(); + else if ( weekAction->isOn() ) viewWeek(); + else if ( monthAction->isOn() ) viewMonth(); + syncing = FALSE; } @@ -764,4 +722,4 @@ void DateBook::flush() { - syncing = TRUE; - db->save(); + syncing = TRUE; + db->save(); } @@ -770,8 +728,8 @@ void DateBook::timerEvent( QTimerEvent *e ) { - if ( alarmCounter < 10 ) { - alarmCounter++; - Sound::soundAlarm(); - } - else - killTimer( e->timerId() ); + if ( alarmCounter < 10 ) { + alarmCounter++; + Sound::soundAlarm(); + } else { + killTimer( e->timerId() ); + } } @@ -780,7 +738,7 @@ void DateBook::changeClock( bool newClock ) { - ampm = newClock; - // repaint the affected objects... - if (dayView) dayView->redraw(); - if (weekView) weekView->redraw(); - if (weekLstView) weekLstView->redraw(); + ampm = newClock; + // repaint the affected objects... + if (dayView) dayView->redraw(); + if (weekView) weekView->redraw(); + if (weekLstView) weekLstView->redraw(); } @@ -789,5 +747,5 @@ void DateBook::changeWeek( bool m ) { - /* no need to redraw, each widget catches. Do need to - store though for widgets we haven't made yet */ - onMonday = m; + /* no need to redraw, each widget catches. Do need to + store though for widgets we haven't made yet */ + onMonday = m; } @@ -796,4 +754,4 @@ void DateBook::slotToday() { - // we need to view today using default view - viewDefault(QDate::currentDate()); + // we need to view today using default view + view(defaultView,QDate::currentDate()); } @@ -802,25 +760,25 @@ void DateBook::closeEvent( QCloseEvent *e ) { - if(syncing) { - /* no need to save, did that at flush */ - e->accept(); - return; - } + if(syncing) { + /* no need to save, did that at flush */ + e->accept(); + return; + } - // save settings will generate it's own error messages, no - // need to do checking ourselves. - saveSettings(); - if ( db->save() ) - e->accept(); - else { - if ( QMessageBox::critical( this, tr( "Out of space" ), - tr("Calendar was unable to save\n" - "your changes.\n" - "Free up some space and try again.\n" - "\nQuit anyway?"), - QMessageBox::Yes|QMessageBox::Escape, - QMessageBox::No|QMessageBox::Default ) - != QMessageBox::No ) - e->accept(); - else - e->ignore(); + // save settings will generate it's own error messages, no + // need to do checking ourselves. + saveSettings(); + if ( db->save() ) { + e->accept(); + } else { + if ( QMessageBox::critical( this, tr( "Out of space" ), + tr("Calendar was unable to save\n" + "your changes.\n" + "Free up some space and try again.\n" + "\nQuit anyway?"), + QMessageBox::Yes|QMessageBox::Escape, + QMessageBox::No|QMessageBox::Default ) + != QMessageBox::No ) + e->accept(); + else + e->ignore(); } |