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

📄 datebook.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.7平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		needShow = TRUE;	QFile::remove(f);    } else if ( msg == "newEvent(QDateTime,QDateTime,QString,QString)" ) {	QDateTime s,e;	QString d,n;	QDataStream ds(data,IO_ReadOnly);	ds >> s >> e >> d >> n;	if ( newEvent(s,e,d,n) )	    needShow = TRUE;// PimLibrary stuff    } else if ( msg == "updateEvent(PimEvent)" && !syncing ) {	QDataStream ds(data,IO_ReadOnly);	PimEvent e;	ds >> e;	db->updateEvent(e);	refreshWidgets();    } else if ( msg == "addEvent(PimEvent)" && !syncing ) {	QDataStream ds(data,IO_ReadOnly);	PimEvent e;	ds >> e;	db->addEvent(e);	refreshWidgets();    } else if ( msg == "removeEvent(PimEvent)" && !syncing ) {	QDataStream ds(data,IO_ReadOnly);	PimEvent e;	ds >> e;	db->removeEvent(e);	refreshWidgets();    } else if ( msg == "raiseToday()" ) {	bool visible=FALSE;	if ( data.size() ) {	    QDataStream ds(data,IO_ReadOnly);	    int i;	    ds >> 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;	QDataStream ds( data, IO_ReadOnly );	ds >> 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);	    needShow = TRUE;	}    } else if ( msg == "showEvent(QUuid,QDate)" ) {	QUuid u;	QDate date;	QDataStream ds( data, IO_ReadOnly );	ds >> 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);	    needShow = TRUE;	}    }    if ( needShow ) {#if defined(Q_WS_QWS) || defined(_WS_QWS_)	//showMaximized();#else	//show();#endif	//raise();	QPEApplication::setKeepRunning();	//setActiveWindow();    }}void DateBook::nextView(){    QWidget* cur = views->visibleWidget();    if ( cur ) {	if ( cur == dayView )	    viewWeek();	else if ( cur == weekView )	    viewMonth();	else if ( cur == monthView )	    viewDay();    }}void DateBook::reload(){    // reload isn't as meaningful anymore.    //db->reload();} else    db->reload();    if ( dayAction->isOn() )	viewDay();    else if ( weekAction->isOn() )	viewWeek();    else if ( monthAction->isOn() )	viewMonth();    syncing = FALSE;}void DateBook::flush(){    db->flush();    syncing = TRUE;   // db->save();    // neither is saving.}void DateBook::timerEvent( QTimerEvent *e ){    static int stop = 0;    if ( stop < 10 ) {	Sound::soundAlarm();	stop++;    } else {	stop = 0;	killTimer( e->timerId() );    }}void DateBook::changeClock(){    // repaint the affected objects...    if (dayView) dayView->redraw();    if (weekView) weekView->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    lastToday = QDate::currentDate();    if ( views->visibleWidget() == dayView ) {	showDay( lastToday );    } else if (views->visibleWidget() == weekView) {	weekView->selectDate( lastToday );    } else if (views->visibleWidget() == monthView){	monthView->setDate( lastToday );    }}void DateBook::closeEvent( QCloseEvent *e ){    slotToday();    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();#if 0    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();    }#endif}void DateBook::newEvent( const QString &description ){    QDateTime current = QDateTime::currentDateTime();    QDateTime start=current, end=current;    int mod = QTime(0,0,0).secsTo(current.time()) % 900;    if (mod != 0)  {	mod = 900 - mod;	current.setTime( current.time().addSecs( mod ) );    }    start.setTime(current.time());    end.setTime(start.time().addSecs(3600));    newEvent(start,end,description,QString::null);}bool DateBook::newEvent(const QDateTime& dstart,const QDateTime& dend,const QString& description,const QString& notes){    if ( checkSyncing() )	return FALSE;    QDateTime start=dstart, end=dend;    QDateTime current = QDateTime::currentDateTime();    bool snull = start.date().isNull();    bool enull = end.date().isNull();    if ( views->visibleWidget() ) {	if ( views->visibleWidget() == dayView ) {	    dayView->selectedDates( start, end );	} else if ( views->visibleWidget() == monthView ) {	    start.setDate( monthView->selectedDate() );	} else if ( views->visibleWidget() == weekView ) {	    start.setDate( weekView->currentDate() );	}    }    if ( start.date().isNull() )	start.setDate( current.date() );    if ( end.date().isNull() )	end.setDate( start.date() );    if ( (snull && end.time().isNull()) || !start.time().isValid() ) {	// 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.	// move current to the next fifteen minutes	int mod = QTime(0,0,0).secsTo(current.time()) % 900;	if (mod != 0)  {	    mod = 900 - mod;	    current.setTime( current.time().addSecs( mod ) );	}	// default start	start.setTime(current.time());    }    if ( (enull && end.time().isNull()) || !end.time().isValid() ) {	// default end	end = start.addSecs(3600);    }    // 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 );    PimEvent ev;    ev.setDescription(  description );    // When the new gui comes in, change this...    ev.setLocation( "" );    ev.setStart( start );    ev.setEnd( end );    ev.setNotes( notes );    VScrollBox *vsb = new VScrollBox( &newDlg );    e = new DateEntry( onMonday, ev, vsb );    e->setAlarmEnabled( aPreset, presetTime, PimEvent::Loud );    sv->addChild( vsb );    qDebug( "newDlg sizeHint(): %d,%d", newDlg.sizeHint().width(), newDlg.sizeHint().height() );    qDebug( "e minimumsize: %d, %d", e->minimumSize().width(), e->minimumSize().height() );    while (QPEApplication::execDialog(&newDlg)) {	ev = e->event();	//ev.assignUid(); // um, don't know if we can drop this or not	QString error = checkEvent( ev );	if ( !error.isNull() ) {	    if ( QMessageBox::warning( this, tr("Error!"),				       error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 )		continue;	}	QUuid id = db->addEvent( ev );	emit newEvent();	if ( views->visibleWidget() == dayView ) {	    dayView->clearSelectedDates();	    bool ok;	    PimEvent e = db->find( id, &ok );	    if ( ok )		dayView->setCurrentEvent( e );	}	return TRUE;    }    if ( views->visibleWidget() == dayView )	dayView->clearSelectedDates();    return FALSE;}void DateBook::setDocument( const QString &filename ){    DocLnk doc(filename);    if ( doc.isValid() )	receiveFile(doc.file());    else	receiveFile(filename);}bool DateBook::receiveFile( const QString &filename ){    QValueList<PimEvent> tl = PimEvent::readVCalendar( filename );    QString msg = tr("<P>%1 new events.<p>Do you want to add them to your Calendar?").	arg(tl.count());    if ( QMessageBox::information(isVisible() ? this : 0, tr("New Events"),	    msg, QMessageBox::Ok, QMessageBox::Cancel)==QMessageBox::Ok ) {	QDateTime from,to;	for( QValueList<PimEvent>::Iterator it = tl.begin(); it != tl.end(); ++it ) {	    if ( from.isNull() || (*it).start() < from )		from = (*it).start();	    if ( to.isNull() || (*it).end() < to )		to = (*it).end();	    db->addEvent( *it );	}	// Change view to a sensible one...	if ( from.date() == to.date() ) {	    viewDay(from.date());	} else {	    initWeek();	    int fw,fy,tw,ty;	    weekView->calcWeek(from.date(), fw, fy);	    weekView->calcWeek(to.date(), tw, ty);	    if ( fw == tw && fy == ty ) {		viewWeek(from.date());	    } else if ( from.date().month() == to.date().month()		    && from.date().year() == to.date().year() ) {		viewMonth(from.date());	    } else {		viewDay(from.date());	    }	}	emit newEvent();	return TRUE;    }    return FALSE;}static const char * beamfile = "/tmp/obex/event.vcs";void DateBook::beamEvent( const PimEvent &e ){#ifdef Q_WS_QWS    unlink( beamfile ); // delete if exists#if defined (Q_OS_WIN32)    QDir d;    d.mkdir("/tmp/obex/");#else    ::mkdir("/tmp/obex/", 0755);#endif    PimEvent::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" );#endif}void DateBook::beamDone( Ir *ir ){#ifdef Q_WS_QWS    delete ir;    unlink( beamfile );#endif}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 searchForward,			   int category ){    bool ok;    QRegExp r(txt);    r.setCaseSensitive(caseSensitive);    Occurrence o = db->find(r, category, dt,	    searchForward, &ok);    if ( ok ) {	dayView->selectDate( o.startInCurrentTZ().date() );	dayView->setCurrentItem(o);    }}

⌨️ 快捷键说明

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