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

📄 datebook.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.7平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/************************************************************************ Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.**** This file is part of the Qtopia Environment.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#define QTOPIA_INTERNAL_FD#include "datebook.h"#include "dayview.h"#include "datebooksettings.h"#include "datebookweek.h"#include "dateentryimpl.h"#include "monthview.h"#include "finddialog.h"#include <qtopia/qpeapplication.h>#include <qtopia/global.h>#include <qtopia/config.h>#include <qtopia/qpedebug.h>#include <qtopia/pim/event.h>#ifdef Q_WS_QWS#include <qtopia/ir.h>#endif#include <qtopia/qpemenubar.h>#include <qtopia/qpemessagebox.h>#include <qtopia/resource.h>#include <qtopia/sound.h>#include <qtopia/timestring.h>#include <qtopia/qpetoolbar.h>#include <qtopia/tzselect.h>#include <qtopia/xmlreader.h>#include <qtopia/applnk.h>#include <qtopia/pim/private/eventio_p.h>#include <qaction.h>#include <qtimer.h>#include <qdatetime.h>#include <qdialog.h>#include <qdir.h>#include <qfile.h>#include <qlabel.h>#include <qlayout.h>#include <qmessagebox.h>#include <qpopupmenu.h>#include <qpushbutton.h>#include <qtextcodec.h>#include <qtextstream.h>#include <qtl.h>#include <qwidgetstack.h>#include <qvbox.h>#include <qregexp.h>//#ifdef QWS////#include <qwindowsystem_qws.h>////#include <qcopchannel_qws.h>////#endif#include <qarray.h>#include <sys/stat.h>#include <sys/types.h>#include <fcntl.h>#ifndef Q_OS_WIN32#include <unistd.h>#endif#include <stdlib.h>#define DAY 1#define WEEK 2#define MONTH 3// Make QScrollView in AutoOneFit mode use the minimum horizontal size// instead of the sizeHint() so that the widgets fit horizontally.class VScrollBox : public QVBox{public:    VScrollBox( QWidget *parent, const char *name=0 )	: QVBox( parent, name ) {}#if defined(_WS_QWS_)    QSize sizeHint() const {	int width = QVBox::sizeHint().width();	if ( width > qApp->desktop()->width()-style().scrollBarExtent().width() )	    width = qApp->desktop()->width()-style().scrollBarExtent().width();	width = QMAX(width, QVBox::minimumSize().width());	return QSize( width, QVBox::sizeHint().height());    }#endif};DateBook::DateBook( QWidget *parent, const char *, WFlags f )    : QMainWindow( parent, "datebook", f ),      aPreset( FALSE ),      presetTime( -1 ),      startTime( 8 ), // an acceptable default      syncing(FALSE),      inSearch(FALSE),      exceptionMb(0){    int timingLoad, timingOther;    QTime t;    t.start();    db = new DateBookTable(this);    timingLoad = t.elapsed();    loadSettings();    setCaption( tr("Calendar") );    setIcon( Resource::loadPixmap( "DateBook" ) );    bool thinScreen = QApplication::desktop()->width() < 200;    setToolBarsMovable( FALSE );    setBackgroundMode( PaletteButton );    QPEToolBar *bar = new QPEToolBar( this );    bar->setHorizontalStretchable( TRUE );    QPEMenuBar *mb = new QPEMenuBar( bar );    mb->setMargin( 0 );#ifdef QTOPIA_NO_POINTER_INPUT    QPEToolBar *sub_bar=0;#else    QPEToolBar *sub_bar = new QPEToolBar(this);#endif;    QPopupMenu *eventMenu = new QPopupMenu( this );    QPopupMenu *view = new QPopupMenu( this );    mb->insertItem( tr( "Event" ), eventMenu );    mb->insertItem( tr( "View" ), view );    QActionGroup *g = new QActionGroup( this );    g->setExclusive( TRUE );    QAction *a = new QAction( tr( "New Event" ), Resource::loadIconSet( "new" ),                              QString::null, 0, this, 0 );    a->setWhatsThis( tr("Create a new event") );    connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );    if (sub_bar) a->addTo( sub_bar );    a->addTo( eventMenu );    editAction = new QAction( tr( "Edit Event" ),	    Resource::loadIconSet( "edit" ), QString::null, 0, this, 0 );    connect( editAction, SIGNAL( activated() ), this, SLOT( editCurrentEvent() ) );    editAction->setWhatsThis( tr("Edit the selected event") );    editAction->addTo( eventMenu );    removeAction = new QAction( tr( "Delete Event" ),	    Resource::loadIconSet( "trash" ), QString::null, 0, this, 0 );    connect( removeAction, SIGNAL( activated() ), this, SLOT( removeCurrentEvent() ) );    removeAction->setWhatsThis( tr("Delete the selected event") );    removeAction->addTo( eventMenu );#ifdef Q_WS_QWS    if (Ir::supported()) {	beamAction = new QAction( tr( "Beam Event" ),	    Resource::loadIconSet( "beam" ), QString::null, 0, this, 0 );	connect( beamAction, SIGNAL( activated() ),	    this, SLOT( beamCurrentEvent() ) );	beamAction->setWhatsThis( tr("Beam the selected event") );	beamAction->addTo( eventMenu );    }#endif    eventMenu->insertSeparator();    /*    a = new QAction( tr( "Delete Events" ), Resource::loadIconSet( "trash" ),                            QString::null, 0, this, 0 );    connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );    a->addTo( sub_bar );    a->addTo( eventMenu );    */    a = new QAction( tr( "Today" ), Resource::loadIconSet( "today" ), QString::null, 0, g, 0 );    connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) );    a->setWhatsThis( tr("Show today's events") );    if (sub_bar) a->addTo( sub_bar );    a->addTo( view );    view->insertSeparator();    if (sub_bar) sub_bar->addSeparator();    a = new QAction( tr( "Day", "day, not date" ), Resource::loadIconSet( "day" ), QString::null, 0, g, 0 );    a->setWhatsThis( tr("Show selected day's events") );    if (!thinScreen)	if (sub_bar) a->addTo( sub_bar );    a->addTo( view );    a->setToggleAction( TRUE );    a->setOn( TRUE );    dayAction = a;    connect( dayAction, SIGNAL( activated() ), this, SLOT( viewDay() ) );    a = new QAction( tr( "Week" ), Resource::loadIconSet( "week" ), QString::null, 0, g, 0 );    connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) );    a->setWhatsThis( tr("Show selected week's events") );    if (!thinScreen)	if (sub_bar) a->addTo( sub_bar );    a->addTo( view );    a->setToggleAction( TRUE );    weekAction = a;    a = new QAction( tr( "Month" ), Resource::loadIconSet( "month" ), QString::null, 0, g, 0 );    connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) );    a->setWhatsThis( tr("Show selected month's events") );    if (!thinScreen)	a->addTo( sub_bar );    a->addTo( view );    a->setToggleAction( TRUE );    monthAction = a;    a = new QAction( tr( "Find Event" ), Resource::loadIconSet( "find" ), QString::null, 0, g, 0 );    connect( a, SIGNAL(activated()), this, SLOT(slotFind()) );    //a->addTo( sub_bar );    a->addTo( eventMenu );    view->insertSeparator();    a = new QAction( tr( "Settings..." ), QString::null, 0, g );    connect( a, SIGNAL( activated() ), this, SLOT( showSettings() ) );    a->addTo( view );    views = new QWidgetStack( this );    setCentralWidget( views );    dayView = 0;    weekView = 0;    monthView = 0;    timingOther = t.elapsed();    viewToday();    TimeString::connectChange(this, SLOT(changeClock()) );    connect( qApp, SIGNAL(weekChanged(bool)),             this, SLOT(changeWeek(bool)) );    connect( qApp, SIGNAL( appMessage(const QCString &, const QByteArray &) ), 	    this, SLOT( appMessage(const QCString &, const QByteArray &) ) );    connect( qApp, SIGNAL( timeChanged() ), 	    this, SLOT( checkToday() ) );    connect( qApp, SIGNAL( timeChanged() ), 	    this, SLOT( updateAlarms() ) );    connect( qApp, SIGNAL( flush() ), 	    this, SLOT( flush() ) );    connect( qApp, SIGNAL( reload() ), 	    this, SLOT( reload() ) );    // start Timer    midnightTimer = new QTimer(this);    connect(midnightTimer, SIGNAL(timeout()), this, SLOT(checkToday()));    // 2 seconds after midnight    midnightTimer->start(	    (QTime::currentTime().secsTo(QTime(23,59,59)) + 3)	    * 1000 );}void DateBook::checkToday(){    if ( lastToday != QDate::currentDate() ) {	if ( lastToday == currentDate() )	    slotToday();	else	    lastToday = QDate::currentDate();    } else {	refreshWidgets();    }    midnightTimer->start(	    (QTime::currentTime().secsTo(QTime(23,59,59)) + 3)	    * 1000 );}void DateBook::updateAlarms(){    /*        time may have gone backwards... but giving the same alarms        again won't hurt (server will ignore) so send them all again,   */    // no real way to tell if forward or backward, so need to do the lot.    db->updateAlarms();}void DateBook::refreshWidgets(){    // update active view!    if ( dayAction->isOn() )	dayView->redraw();    else if ( weekAction->isOn() )	weekView->redraw();    else if ( monthAction->isOn() )	monthView->updateOccurrences();}DateBook::~DateBook(){}void DateBook::showSettings(){    bool whichclock;    Config config( "qpe" );    config.setGroup("Time");    whichclock = config.readBoolEntry("AMPM");        DateBookSettings frmSettings(whichclock, this);    frmSettings.setStartTime( startTime );    frmSettings.setAlarmPreset( aPreset, presetTime );    if ( QPEApplication::execDialog(&frmSettings) ) {	aPreset = frmSettings.alarmPreset();	presetTime = frmSettings.presetTime();	startTime = frmSettings.startTime();	if ( dayView )	    dayView->setDayStarts( startTime );	if ( weekView )	    weekView->setDayStarts( startTime );	saveSettings();	// make the change obvious	if ( views->visibleWidget() ) {	    if ( views->visibleWidget() == dayView )		dayView->redraw();	    else if ( views->visibleWidget() == weekView )		weekView->redraw();	}    }}void DateBook::fileNew(){    newEvent("");}QString DateBook::checkEvent(const PimEvent &e){    /* check if overlaps with itself */    bool checkFailed = FALSE;    /* check the next 12 repeats. should catch most problems */    QDate current_date = e.end().date();    int duration = e.start().date().daysTo(e.end().date());    PimEvent previous = e;    for(int i = 0; i < 12; i++)    {	bool ok;	QDateTime next;	next = e.nextOccurrence(current_date.addDays(1), &ok);	next.setTime(e.start().time());	if (!ok)	    break;  // no more repeats	if(next < previous.end()) {	    checkFailed = TRUE;	    break;	}	current_date = next.date().addDays(duration);    }    if(checkFailed)	return tr("Event duration is potentially longer\n"		  "than interval between repeats.");    return QString::null;}QDate DateBook::currentDate(){    if ( dayView && views->visibleWidget() == dayView ) {	return dayView->currentDate();    } else if ( weekView && views->visibleWidget() == weekView ) {        return weekView->currentDate();    } else if ( monthView && views->visibleWidget() == monthView ) {	return monthView->selectedDate();    } else {	return QDate(); // invalid;    }}void DateBook::viewToday(){    lastToday = QDate::currentDate();    viewDay( lastToday );}void DateBook::viewDay(const QDate& dt){    initDay();    dayAction->setOn( TRUE );    dayView->selectDate( dt );    views->raiseWidget( dayView );    dayView->setFocus();    dayView->redraw();    updateIcons();}void DateBook::viewDay(){    viewDay( currentDate() );}void DateBook::viewWeek(){    viewWeek( currentDate() );}void DateBook::viewWeek( const QDate& dt ){    initWeek();    weekAction->setOn( TRUE );    weekView->selectDate( dt );    views->raiseWidget( weekView );    weekView->redraw();    updateIcons();}void DateBook::viewMonth(){    viewMonth( currentDate() );}void DateBook::viewMonth( const QDate& dt){    initMonth();    monthAction->setOn( TRUE );    monthView->setDate( dt );    views->raiseWidget( monthView );    monthView->updateOccurrences();    updateIcons();}

⌨️ 快捷键说明

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