📄 datebook.cpp
字号:
diter = futureExceptions.remove( diter ); } else { diter++; pastExceptions.remove( d ); // some of these would have been added by processing the children if ( processedDates.contains( d ) == 0 ) ((PrEvent&)e).addException( d ); } } break; } } else { e = ev.event(); asException = FALSE; } EntryDialog editDlg( onMonday, e, parentWidget->isVisible() ? parentWidget : 0, "edit-event", TRUE ); if ( preview ) editDlg.showSummary(); // workaround added for text input. if (e.isException())#ifdef QTOPIA_PHONE editDlg.setCaption( tr("Edit Exception") );#else editDlg.setCaption( tr("Edit Event Exception") );#endif else editDlg.setCaption( tr("Edit Event") ); // connect the qApp stuff. connect( qApp, SIGNAL(weekChanged(bool)), &editDlg, SLOT(setWeekStartsMonday(bool)) );#ifdef QTOPIA_DESKTOP connect( editDlg.entryDetails()->comboCategory, SIGNAL( editCategoriesClicked(QWidget*) ), SLOT( editCategories(QWidget*) ) ); editDlg.resize(500, 300);#endif //entry->timezone->setEnabled(FALSE); while (QPEApplication::execDialog(&editDlg) ) { PimEvent newEv = editDlg.event(); QString error = checkEvent(newEv); if (!error.isNull()) { if (QMessageBox::warning(parentWidget, "Error", error, "Fix it", "Continue", 0, 0, 1) == 0) continue; } QUuid u; if ( following ) { // We've got all the forward events and exceptions already // Now remove then from the "old" series. Of course, just // to be difficult, we can't do that so remove then all and // then add back the appropriate ones orig.clearExceptions(); QValueList<QDate> processedDates; QValueListIterator<QUuid> uiter; QValueListIterator<QDate> diter; // Children first for ( uiter = pastChildren.begin(); uiter != pastChildren.end(); uiter++ ) { QUuid u = *uiter; PimEvent child = db->find( u ); QDate dateOfChild = child.start().date(); orig.addException( dateOfChild, u ); processedDates.append( dateOfChild ); } // Now the extra exceptions for ( diter = pastExceptions.begin(); diter != pastExceptions.end(); diter++ ) { QDate d = *diter; if ( processedDates.contains( d ) == 0 ) ((PrEvent&)orig).addException( d ); } // Change the repeat end for the "old" series to be the current event's date orig.setRepeatTill( newEv.start().date().addDays( -1 ) ); db->updateEvent( orig ); u = db->addEvent( newEv ); // Now change all the "future" children to belong to the correct series for ( uiter = futureChildren.begin(); uiter != futureChildren.end(); uiter++ ) { QUuid uid = *uiter; PimEvent child = db->find( uid ); ((PrEvent&)child).setParentUid( u ); db->updateEvent( child ); } } else { if (asException) { u = db->addException(ev.date(),ev.event(), newEv); } else { if (affectsExceptions(newEv, e)) { if (QMessageBox::warning(parentWidget, tr("Calendar"), tr( "<p>Changes to the start time or recurrence pattern" " of this event will cause all exceptions to this event" " to be lost. Continue?"), QMessageBox::Ok, QMessageBox::Cancel|QMessageBox::Default ) != QMessageBox::Ok) return; /// need to clear exceptions db->removeExceptions(newEv); newEv.clearExceptions(); } db->updateEvent(newEv); u = newEv.uid(); } } emit eventsChanged(); if ( views->visibleWidget() == dayView ) { bool ok; PimEvent e = db->find( u, &ok ); if ( ok ) dayView->setCurrentEvent( e ); } break; }}void DateBook::removeOccurrence( const Occurrence &o ){#if !defined(QTOPIA_DESKTOP) if ( checkSyncing() ) return;#endif PimEvent e = o.event(); QString strName = e.description(); if (e.hasRepeat()) { // ask if just this one or is series? if (!exceptionMb) initExceptionMb(); exceptionMb->setCaption( tr("Delete Event") ); QValueListIterator<QUuid> uiter; QValueListIterator<QDate> diter; switch (exceptionMb->exec()) { default: return; case ExceptionDialog::Current: db->addException( o.start().date(), e ); break; case ExceptionDialog::All: db->removeEvent( e ); break; case ExceptionDialog::Following: // If we select Following but we're looking at the first instance, // just do the same as All. if ( o.date() == e.start().date() ) { db->removeEvent( e ); break; } PimEvent orig = o.event(); QValueList<QDate> pastExceptions = ((PrEvent&)e).exceptions(); QValueList<QDate> futureExceptions = ((PrEvent&)e).exceptions(); QValueList<QUuid> futureChildren = ((PrEvent&)e).childUids(); QValueList<QUuid> pastChildren = ((PrEvent&)e).childUids(); // we can only remove everything // put it back in while processing the lists e.clearExceptions(); // disassociate all children that are in the "past" for ( uiter = futureChildren.begin(); uiter != futureChildren.end(); ) { QUuid u = *uiter; PimEvent child = db->find( u ); QDate dateOfChild = child.start().date(); if ( dateOfChild < o.date() ) { uiter = futureChildren.remove( uiter ); } else { uiter++; pastChildren.remove( u ); } } // remove all exceptions from the "past" for ( diter = futureExceptions.begin(); diter != futureExceptions.end(); ) { QDate d = *diter; if ( d < o.date() ) { diter = futureExceptions.remove( diter ); } else { diter++; pastExceptions.remove( d ); } } // We've got all the forward events and exceptions already // Now remove them from the "old" series. Of course, just // to be difficult, we can't do that so remove then all and // then add back the appropriate ones orig.clearExceptions(); QValueList<QDate> processedDates; // Children first for ( uiter = pastChildren.begin(); uiter != pastChildren.end(); uiter++ ) { QUuid u = *uiter; PimEvent child = db->find( u ); QDate dateOfChild = child.start().date(); orig.addException( dateOfChild, u ); processedDates.append( dateOfChild ); } // Now the extra exceptions for ( diter = pastExceptions.begin(); diter != pastExceptions.end(); diter++ ) { QDate d = *diter; if ( processedDates.contains( d ) == 0 ) ((PrEvent&)orig).addException( d ); } // Change the repeat end for the "old" series to be the current event's date orig.setRepeatTill( o.date().addDays( -1 ) ); db->updateEvent( orig ); // Now delete all the "future" children for ( uiter = futureChildren.begin(); uiter != futureChildren.end(); uiter++ ) { QUuid uid = *uiter; PimEvent child = db->find( uid ); db->removeEvent( child ); } break; } } else { if ( !QPEMessageBox::confirmDelete( parentWidget, tr( "Calendar" ),strName ) ) return; db->removeEvent( e ); } if ( views->visibleWidget() == dayView && dayView ) dayView->redraw();}void DateBook::addEvent( const PimEvent &e ){ QDate d = e.start().date(); initDay(); dayView->selectDate( d );}void DateBook::editCurrentEvent(){ bool inViewMode = views->visibleWidget() == eventView; if ( inViewMode ) hideEventDetails(); if (eventSelected()) editOccurrence(currentOccurrence()); if ( inViewMode && eventSelected() ) showEventDetails();}void DateBook::removeCurrentEvent(){ if ( views->visibleWidget() == eventView ) hideEventDetails(); if (eventSelected()) removeOccurrence(currentOccurrence());}void DateBook::beamCurrentEvent(){#ifdef Q_WS_QWS if ( views->visibleWidget() == eventView ) hideEventDetails(); if (eventSelected()) beamEvent(currentEvent());#endif}bool DateBook::eventSelected() const{ if (views->visibleWidget() && views->visibleWidget() == dayView) { return dayView->hasSelection(); } return FALSE;}PimEvent DateBook::currentEvent() const{ return dayView->currentEvent();}Occurrence DateBook::currentOccurrence() const{ return dayView->currentItem();}void DateBook::initDay(){ if ( !dayView ) { dayView = new DayView( db, onMonday, views, "dayview" ); // No tr dayView->setCompressDay( compressDay ); views->addWidget( dayView, DAY ); dayView->setDayStarts( startTime ); connect( this, SIGNAL( eventsChanged() ), dayView, SLOT( redraw() ) ); connect( dayView, SIGNAL( newEvent() ), this, SLOT( fileNew() ) ); connect( dayView, SIGNAL( removeOccurrence(const Occurrence&) ), this, SLOT( removeOccurrence(const Occurrence&) ) ); connect( dayView, SIGNAL( editOccurrence(const Occurrence&) ), this, SLOT( editOccurrence(const Occurrence&) ) ); connect( dayView, SIGNAL( beamEvent(const PimEvent&) ), this, SLOT( beamEvent(const PimEvent&) ) ); connect( dayView, SIGNAL(newEvent(const QString&)), this, SLOT(newEvent(const QString&)) ); connect( dayView, SIGNAL(selectionChanged()), this, SLOT(updateIcons()) ); connect( dayView, SIGNAL(showDetails()), this, SLOT(showEventDetails()) ); // qApp connections connect( qApp, SIGNAL(weekChanged(bool)), dayView, SLOT(setStartOnMonday(bool)) ); }}void DateBook::initWeek(){ if ( !weekView ) { weekView = new WeekView( db, onMonday, views, "weekview" ); // No tr weekView->setDayStarts( startTime ); views->addWidget( weekView, WEEK ); connect( weekView, SIGNAL( dateActivated(const QDate&) ), this, SLOT( viewDay(const QDate&) ) ); connect( this, SIGNAL( eventsChanged() ), weekView, SLOT( redraw() ) ); // qApp connections connect( qApp, SIGNAL(weekChanged(bool)), weekView, SLOT(setStartOnMonday(bool)) ); }}void DateBook::initMonth(){ if ( !monthView ) { monthView = new MonthView( db, views, "monthview" ); // No tr#if !defined(QTOPIA_DESKTOP) monthView->setMargin(0);#endif views->addWidget( monthView, MONTH ); connect( monthView, SIGNAL( dateClicked(const QDate&) ), this, SLOT( viewDay(const QDate&) ) ); connect( this, SIGNAL( eventsChanged() ), monthView, SLOT( updateOccurrences() ) ); }}void DateBook::initEvent(){ if ( ! eventView ) { eventView = new EventView( views, "eventview" ); views->addWidget( eventView, EVENT );#ifdef QTOPIA_PHONE eventView->setMargin(0);#endif connect( eventView, SIGNAL(done()), this, SLOT(hideEventDetails()) ); }}void DateBook::loadSettings(){ { Config config( "qpe" ); config.setGroup("Time"); onMonday = config.readBoolEntry( "MONDAY" ); } { Config config("DateBook"); config.setGroup("Main"); startTime = config.readNumEntry("startviewtime", 8); aPreset = config.readBoolEntry("alarmpreset"); presetTime = config.readNumEntry("presettime");#ifdef QTOPIA_PHONE compressDay = TRUE;#else compressDay = config.readBoolEntry("compressday", TRUE);#endif }}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("compressday", compressDay);}void DateBook::appMessage(const QCString& msg, const QByteArray& data){ bool needShow = FALSE; QDataStream stream( data, IO_ReadOnly ); if ( msg == "alarm(QDateTime,int)" ) { QDateTime when; int warn; stream >> when >> warn; // may be more than one item. QValueList<Occurrence> items = db->getNextAlarm(when, warn); QValueListIterator<Occurrence> it; bool skip_dialogs = FALSE; for (it = items.begin(); it != items.end(); ++it) { Occurrence item = *it; // First Update the alarm for the event. db->updateAlarm(item.event()); QDateTime current = QDateTime::currentDateTime(); // if we are told to skip and still getting a flood of messages, // continue. if (lastcall.addSecs(1) >= current && lastcall.addSecs(-1) <= current && skip_dialogs) continue; // if alarm in past, (or nearly in the past) go off. if (current.addSecs(60) >= when) { bool bSound = FALSE; int stopTimer = 0; if ( item.event().alarmSound() != PimEvent::Silent ) { bSound = TRUE; Sound::soundAlarm(); stopTimer = startTimer( 5000 ); } AlarmDialog dlg( parentWidget->isVisible() ? parentWidget : 0, 0, TRUE ); switch ( dlg.exec(item) ) { case AlarmDialog::Details: needShow = TRUE; break; default: //close(); needShow = FALSE; break; } skip_dialogs = dlg.getSkipDialogs(); if ( bSound ) killTimer( stopTimer ); lastcall = QDateTime::currentDateTime(); if ( needShow ) { viewDay( item.startInCurrentTZ().date() ); dayView->setCurrentItem(item); showEventDetails(); } } } } else if ( msg == "newEvent()" ) { if ( newEvent(QDateTime(),QDateTime(),QString::null,QString::null) ) needShow = TRUE; } else if ( msg == "receiveData(QString,QString)" ) { QString f,t; stream >> f >> t; if ( t.lower() == "text/x-vcalendar" ) if ( receiveFile(f) ) needShow = TRUE; QFile::remove(f); } else if ( msg == "newEvent(QDateTime,QDateTime,QString,QString)" ) { QDateTime s,e; QString d,n; stream >> s >> e >> d >> n; if ( newEvent(s,e,d,n) ) needShow = TRUE;// PimLibrary stuff } else if ( msg == "updateEvent(PimEvent)" && !syncing ) { PimEvent e; stream >> e; db->updateEvent(e); refreshWidgets(); } else if ( msg == "addEvent(PimEvent)" && !syncing ) { PimEvent e; stream >> e; db->addEvent(e); refreshWidgets(); } else if ( msg == "removeEvent(PimEvent)" && !syncing ) { PimEvent e; stream >> e; db->removeEvent(e); refreshWidgets(); } else if ( msg == "addException(PimEvent,QDate)" && !syncing ) { PimEvent e, x; QDate date; stream >> e; stream >> date; db->addException(date, e); refreshWidgets(); } else if ( msg == "addException(PimEvent,QDate,PimEvent)" && !syncing ) { PimEvent e, x; QDate date; stream >> e; stream >> date; stream >> x; db->addException(date, e, x); refreshWidgets(); } else if ( msg == "removeException(PimEvent,QDate)" && !syncing ) { PimEvent e; QDate date; stream >> e; stream >> date; e.removeException(date); db->updateEvent(e); refreshWidgets(); } else if ( msg == "removeException(PimEvent,PimEvent)" && !syncing ) { PimEvent e, x; stream >> e; stream >> x; if (x.seriesUid() == e.uid()) { db->removeEvent(x); refreshWidgets(); } } else if ( msg == "removeAllExceptions(PimEvent)" && !syncing ) { PimEvent e; stream >> e; db->removeExceptions(e); e.clearExceptions(); db->updateEvent(e); refreshWidgets(); } else if ( msg == "raiseToday()" ) { bool visible=FALSE; if ( data.size() ) { int i; stream >> i; // backdoor kludge visible = i; } if ( visible ) nextView(); else viewToday(); needShow = TRUE; } else if ( msg == "nextView()" ) { nextView(); needShow = !!views->visibleWidget(); } else if ( msg == "showEvent(QUuid)" ) { QUuid u; stream >> u; bool ok; Occurrence o = db->find(u, QDate::currentDate(), &ok); if (ok) { viewDay( o.startInCurrentTZ().date() ); //dayView->selectDate( o.startInCurrentTZ().date() ); dayView->setCurrentItem(o); showEventDetails(); needShow = TRUE; } } else if ( msg == "showEvent(QUuid,QDate)" ) { QUuid u; QDate date; stream >> u >> date; bool ok; Occurrence o = db->find(u, date, &ok); if (ok) { viewDay( o.startInCurrentTZ().date() ); //dayView->selectDate( o.startInCurrentTZ().date() ); dayView->setCurrentItem(o); showEventDetails(); needShow = TRUE; } }#ifdef QTOPIA_DATA_LINKING else if ( msg == "QDLRequestLink(QString,QString)" ) { QString clientID, hint; stream >> clientID >> hint; QDLHeartBeat hb( clientID ); EventPicker evtPick( this, parentWidget, "evtPick", TRUE ); evtPick.showMaximized(); if ( evtPick.exec() ) { if ( !evtPick.eventSelected() ) { qDebug( "No Event Selected!" ); } else { QByteArray dataref;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -