⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datebook.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.7平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
void DateBook::updateIcons(){    bool s = eventSelected();    removeAction->setEnabled(s);#ifdef Q_WS_QWS    if (Ir::supported()) {	beamAction->setEnabled(s);    }#endif    editAction->setEnabled(s);}void DateBook::initExceptionMb() {    exceptionMb = new QMessageBox(tr("Calendar"),	    tr("Edit all events in this series or just this single event."),	    QMessageBox::Warning, QMessageBox::Yes,	    QMessageBox::No | QMessageBox::Default, QMessageBox::Cancel, this);    exceptionMb->setButtonText(QMessageBox::Yes, tr("All"));    exceptionMb->setButtonText(QMessageBox::No, tr("Single","1 event, not all"));    exceptionMb->setTextFormat(RichText);}// a bit to extreme.// should be possible to check each exception for if it still fits// on a valid date.bool affectsExceptions(const PimEvent &ne, const PimEvent &oe){    if (oe.hasExceptions()) {	if (ne.start() != oe.start())	    return TRUE;	if (ne.frequency() != oe.frequency())	    return TRUE;	if (ne.repeatType() != oe.repeatType())	    return TRUE;	if ( ((PrEvent &)ne).p_weekMask() != ((PrEvent &)oe).p_weekMask())	    return TRUE;    }    return FALSE;}bool DateBook::checkSyncing(){    if (syncing) {	if ( QMessageBox::warning(this, tr("Calendar"),	                     tr("Can not edit data, currently syncing"),			    QMessageBox::Ok, QMessageBox::Abort ) == QMessageBox::Abort )	{	    // Okay, if you say so (eg. Qtopia Desktop may have crashed)....	    syncing = FALSE;	} else	    return TRUE;    }    return FALSE;}void DateBook::editOccurrence( const Occurrence &ev ){    if ( checkSyncing() )	return;    // if this event is an exception, or has exceptions we may need to do somethign different.    bool asException;    PimEvent e;    if (ev.event().hasRepeat()) {	// ask if just this one or is series?	if (!exceptionMb)	    initExceptionMb();	exceptionMb->setText(tr("Edit all events in this series or just this single event."));	switch (exceptionMb->exec()) {	    default:		return;	    case QMessageBox::Yes:		e = ev.event();		asException = FALSE;		break;	    case QMessageBox::No:		e = ev.event();		// modify e to be an exceptional event.		// with no uid (yet).		e.setSeriesUid(ev.event().uid());		e.setRepeatType(PimEvent::NoRepeat);		e.setStart(ev.start());		e.clearExceptions();		asException = TRUE;		break;	}    } else {	e = ev.event();	asException = FALSE;    }    // workaround added for text input.    QDialog editDlg( this, 0, TRUE );    DateEntry *entry;    if (e.isException())	editDlg.setCaption( tr("Edit Event Exception") );    else	editDlg.setCaption( tr("Edit Event") );    QVBoxLayout *vb = new QVBoxLayout( &editDlg );    QScrollView *sv = new QScrollView( &editDlg, "scrollview" );    sv->setResizePolicy( QScrollView::AutoOneFit );    // KLUDGE!!!    sv->setHScrollBarMode( QScrollView::AlwaysOff );    vb->addWidget( sv );    VScrollBox *vsb = new VScrollBox( &editDlg );    entry = new DateEntry( onMonday, e, vsb, "editor" ); // No tr    // connect the qApp stuff.    connect( qApp, SIGNAL(weekChanged(bool)),	     entry, SLOT(setWeekStartsMonday(bool)) );    //entry->timezone->setEnabled(FALSE);    sv->addChild( vsb );    while (QPEApplication::execDialog(&editDlg) ) {	PimEvent newEv = entry->event();	QString error = checkEvent(newEv);	if (!error.isNull()) {	    if (QMessageBox::warning(this, "Error",			error, "Fix it", "Continue", 0, 0, 1) == 0)		continue;	}	QUuid u;	if (asException) {	    u = db->addException(ev.date(),ev.event(), newEv);	} else {	    if (affectsExceptions(newEv, e)) {		if (QMessageBox::warning(this, 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 newEvent();	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 ( checkSyncing() )	return;    PimEvent e = o.event();    QString strName = e.description();    if (e.isException() || e.hasRepeat()) {	// ask if just this one or is series?	if (!exceptionMb)	    initExceptionMb();	exceptionMb->setText(		tr("Delete all events in this series or just this single event:<br>%1")		.arg(strName)		);	switch (exceptionMb->exec()) {	    default:		return;	    case QMessageBox::Yes:		if (e.isException()) {		    e = db->find(e.seriesUid());		}		db->removeEvent( e );		break;	    case QMessageBox::No:		if (e.isException()) {		    db->removeEvent( e );		} else {		    db->addException( o.start().date(), e );		}	}    } else  {	if ( !QPEMessageBox::confirmDelete( this, 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(){    if (eventSelected())	editOccurrence(currentOccurrence());}void DateBook::removeCurrentEvent(){    if (eventSelected())	removeOccurrence(currentOccurrence());}void DateBook::beamCurrentEvent(){#ifdef Q_WS_QWS    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::showDay( int year, int month, int day ){    showDay(QDate(year, month, day));}void DateBook::showDay( const QDate &dt ){    initDay();    dayView->selectDate( dt );    views->raiseWidget( dayView );    dayView->setFocus();    dayAction->setOn( TRUE );    updateIcons();}void DateBook::initDay(){    if ( !dayView ) {	dayView = new DayView( db, onMonday, views, "day view" ); // No tr	views->addWidget( dayView, DAY );	dayView->setDayStarts( startTime );	connect( this, SIGNAL( newEvent() ),		 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()) );	// qApp connections	connect( qApp, SIGNAL(weekChanged(bool)),		dayView, SLOT(setStartOnMonday(bool)) );    }}void DateBook::initWeek(){    if ( !weekView ) {	weekView = new WeekView( db, onMonday, views, "week view" ); // No tr	weekView->setDayStarts( startTime );	views->addWidget( weekView, WEEK );	connect( weekView, SIGNAL( dateActivated( const QDate & ) ),             this, SLOT( showDay( const QDate & ) ) );	connect( this, SIGNAL( newEvent() ),		 weekView, SLOT( redraw() ) );	// qApp connections	connect( qApp, SIGNAL(weekChanged(bool)),		weekView, SLOT(setStartOnMonday(bool)) );    }}void DateBook::initMonth(){    if ( !monthView ) {	monthView = new MonthView( db, views, "month view" ); // No tr	views->addWidget( monthView, MONTH );	connect( monthView, SIGNAL( dateClicked( const QDate &) ),             this, SLOT( showDay( const QDate &) ) );	connect( this, SIGNAL( newEvent() ),		 monthView, SLOT( updateOccurrences() ) );	qApp->processEvents();    }}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");    }}void DateBook::saveSettings(){    Config config( "qpe" );    Config configDB( "DateBook" );    configDB.setGroup( "Main" );    configDB.writeEntry("startviewtime",startTime);    configDB.writeEntry("alarmpreset",aPreset);    configDB.writeEntry("presettime",presetTime);}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;	// may be more than one item.	QValueList<Occurrence> items = db->getNextAlarm(when, warn);	QValueListIterator<Occurrence> it;	static 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) {		QString msg;		bool bSound = FALSE;		int stopTimer = 0;		msg += "<CENTER><B>" + item.event().description() + "</B>"		    + "<BR>" + item.event().location() + "<BR>";		if (item.event().timeZone().isValid()) {		    QString tzText = item.event().timeZone().id();		    int i = tzText.find('/');		    tzText = tzText.mid( i + 1 );		    tzText = tzText.replace(QRegExp("_"), " ");		    msg += "<B>" + tr("Time zone: ") + "</B>" + tzText + "<BR>";		}		msg += TimeString::localYMDHMS(item.event().start())		    + (warn			    ? " " + tr("(in %1 minutes)").arg(warn)			    : QString(""))		    + "<BR>"		    + item.event().notes() + "</CENTER>";		if ( item.event().alarmSound() != PimEvent::Silent ) {		    bSound = TRUE;		    Sound::soundAlarm();		    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 );		needShow = QPEApplication::execDialog(&dlg);		*/		//QMessageBox mb(tr("ALRARM"), msg, QMessageBox::NoIcon, QMessageBox::OkButton, 		switch (QMessageBox::information(this, tr("Alarm"), msg, tr("OK"), 			    (lastcall.addSecs(1) >= current && lastcall.addSecs(-1) <= current) 				? tr("OK to all") : QString::null))		{		    default:		    case -1:			// escape, don't need to show.			needShow = FALSE;			skip_dialogs = FALSE;			break;		    case 0:			needShow = TRUE;			skip_dialogs = FALSE;			break;		    case 1:			skip_dialogs = TRUE;			break;		}		if ( bSound )		    killTimer( stopTimer );		lastcall = QDateTime::currentDateTime();	    }	}    } else if ( msg == "newEvent()" ) {	if ( newEvent(QDateTime(),QDateTime(),QString::null,QString::null) )	    needShow = TRUE;    } else if ( msg == "receiveData(QString,QString)" ) {	QDataStream stream(data,IO_ReadOnly);	QString f,t;	stream >> f >> t;	if ( t.lower() == "text/x-vcalendar" )	    if ( receiveFile(f) )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -