-rw-r--r-- | core/pim/datebook/datebook.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp index 7dcf156..db2058b 100644 --- a/core/pim/datebook/datebook.cpp +++ b/core/pim/datebook/datebook.cpp @@ -619,385 +619,390 @@ void DateBook::appMessage(const QCString& msg, const QByteArray& data) // 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(); #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; } } } if ( needShow ) { #if defined(Q_WS_QWS) || defined(_WS_QWS_) showMaximized(); #else show(); #endif raise(); QPEApplication::setKeepRunning(); setActiveWindow(); } } void DateBook::reload() { db->reload(); if ( dayAction->isOn() ) viewDay(); else if ( weekAction->isOn() ) viewWeek(); else if ( monthAction->isOn() ) viewMonth(); syncing = FALSE; } void DateBook::flush() { syncing = TRUE; db->save(); } void DateBook::timerEvent( QTimerEvent *e ) { if ( alarmCounter < 10 ) { alarmCounter++; Sound::soundAlarm(); } else killTimer( e->timerId() ); } void DateBook::changeClock( bool newClock ) { ampm = newClock; // repaint the affected objects... if (dayView) dayView->redraw(); if (weekView) weekView->redraw(); if (weekLstView) weekLstView->redraw(); } 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; } void DateBook::slotToday() { // we need to view today using default view viewDefault(QDate::currentDate()); } void DateBook::closeEvent( QCloseEvent *e ) { 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(); } } // Entering directly from the "keyboard" void DateBook::slotNewEventFromKey( const QString &str ) { if (syncing) { QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); return; } // We get to here from a key pressed in the Day View // So we can assume some things. We want the string // passed in to be part of the description. QDateTime start, end; if ( views->visibleWidget() == dayView ) { dayView->selectedDates( start, end ); } else if ( views->visibleWidget() == monthView ) { QDate d = monthView->selectedDate(); start = end = d; start.setTime( QTime( 10, 0 ) ); end.setTime( QTime( 12, 0 ) ); } else if ( views->visibleWidget() == weekView ) { QDate d = weekView->date(); start = end = d; start.setTime( QTime( 10, 0 ) ); end.setTime( QTime( 12, 0 ) ); - } + } else if ( views->visibleWidget() == weekLstView ) { + QDate d = weekLstView->date(); + start = end = d; + start.setTime( QTime( 10, 0 ) ); + end.setTime( QTime( 12, 0 ) ); + } slotNewEntry(start, end, str); } void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str) { // argh! This really needs to be encapsulated in a class // or function. QDialog newDlg( this, 0, TRUE ); newDlg.setCaption( DateEntryBase::tr("New Event") ); DateEntry *e; QVBoxLayout *vb = new QVBoxLayout( &newDlg ); QScrollView *sv = new QScrollView( &newDlg ); sv->setResizePolicy( QScrollView::AutoOneFit ); sv->setFrameStyle( QFrame::NoFrame ); sv->setHScrollBarMode( QScrollView::AlwaysOff ); vb->addWidget( sv ); Event ev; ev.setDescription( str ); // When the new gui comes in, change this... ev.setLocation( tr("(Unknown)") ); ev.setStart( start ); ev.setEnd( end ); e = new DateEntry( onMonday, ev, ampm, &newDlg ); e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); sv->addChild( e ); #if defined(Q_WS_QWS) || defined(_WS_QWS_) newDlg.showMaximized(); #endif while (newDlg.exec()) { ev = e->event(); ev.assignUid(); QString error = checkEvent( ev ); if ( !error.isNull() ) { if ( QMessageBox::warning( this, tr("Error!"), error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) continue; } db->addEvent( ev ); emit newEvent(); break; } } void DateBook::setDocument( const QString &filename ) { if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; QValueList<Event> tl = Event::readVCalendar( filename ); for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { db->addEvent( *it ); } } static const char * beamfile = "/tmp/obex/event.vcs"; void DateBook::beamEvent( const Event &e ) { qDebug("trying to beamn"); unlink( beamfile ); // delete if exists mkdir("/tmp/obex/", 0755); Event::writeVCalendar( beamfile, e ); Ir *ir = new Ir( this ); connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); QString description = e.description(); ir->send( beamfile, description, "text/x-vCalendar" ); } void DateBook::beamDone( Ir *ir ) { delete ir; unlink( beamfile ); } void DateBook::slotFind() { // move it to the day view... viewDay(); FindDialog frmFind( "Calendar", this ); frmFind.setUseDate( true ); frmFind.setDate( currentDate() ); QObject::connect( &frmFind, SIGNAL(signalFindClicked(const QString&, const QDate&, bool, bool, int)), this, SLOT(slotDoFind(const QString&, const QDate&, bool, bool, int)) ); QObject::connect( this, SIGNAL(signalNotFound()), &frmFind, SLOT(slotNotFound()) ); QObject::connect( this, SIGNAL(signalWrapAround()), &frmFind, SLOT(slotWrapAround()) ); frmFind.exec(); inSearch = false; } bool catComp( QArray<int> cats, int category ) { bool returnMe; int i, count; count = int(cats.count()); returnMe = false; if ( (category == -1 && count == 0) || category == -2 ) returnMe = true; else { for ( i = 0; i < count; i++ ) { if ( category == cats[i] ) { returnMe = true; break; } } } return returnMe; } void DateBook::slotDoFind( const QString& txt, const QDate &dt, bool caseSensitive, bool /*backwards*/, int category ) { QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), next; QRegExp r( txt ); r.setCaseSensitive( caseSensitive ); static Event rev, nonrev; if ( !inSearch ) { rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); nonrev.setStart( rev.start() ); inSearch = true; } static QDate searchDate = dt; static bool wrapAround = true; bool candidtate; candidtate = false; QValueList<Event> repeats = db->getRawRepeats(); // find the candidate for the first repeat that matches... QValueListConstIterator<Event> it; QDate start = dt; for ( it = repeats.begin(); it != repeats.end(); ++it ) { if ( catComp( (*it).categories(), category ) ) { while ( nextOccurance( *it, start, next ) ) { if ( next < dtEnd ) { if ( (*it).match( r ) && !(next <= rev.start()) ) { rev = *it; dtEnd = next; rev.setStart( next ); candidtate = true; wrapAround = true; start = dt; break; } else start = next.date().addDays( 1 ); } } } } // now the for first non repeat... QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); qHeapSort( nonRepeats.begin(), nonRepeats.end() ); for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { if ( catComp( (*it).categories(), category ) ) { if ( (*it).start() < dtEnd ) { if ( (*it).match( r ) && !(*it <= nonrev) ) { nonrev = *it; dtEnd = nonrev.start(); candidtate = true; wrapAround = true; break; } } } } if ( candidtate ) { dayView->setStartViewTime( dtEnd.time().hour() ); dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), dtEnd.date().day() ); } else { if ( wrapAround ) { emit signalWrapAround(); rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); nonrev.setStart( rev.start() ); |