author | hakan <hakan> | 2002-03-09 11:39:21 (UTC) |
---|---|---|
committer | hakan <hakan> | 2002-03-09 11:39:21 (UTC) |
commit | 603e969bb8cef91534a1785e27106ba71eb03ba6 (patch) (side-by-side diff) | |
tree | 20642ed29acb08ab0cecc1dffd1d63baa8914ae2 /core/pim/datebook/datebook.cpp | |
parent | 3d03d0e3f679578080bbbf7d8b7f9eba1b9560db (diff) | |
download | opie-603e969bb8cef91534a1785e27106ba71eb03ba6.zip opie-603e969bb8cef91534a1785e27106ba71eb03ba6.tar.gz opie-603e969bb8cef91534a1785e27106ba71eb03ba6.tar.bz2 |
Added a WeekLst view showing an entire week and appointment descriptions and made default view configurable
Diffstat (limited to 'core/pim/datebook/datebook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/datebook/datebook.cpp | 122 |
1 files changed, 106 insertions, 16 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp index e8d808f..9880e2d 100644 --- a/core/pim/datebook/datebook.cpp +++ b/core/pim/datebook/datebook.cpp @@ -21,16 +21,17 @@ **********************************************************************/ #define QTOPIA_INTERNAL_FD #include "datebook.h" #include "datebookday.h" #include "datebooksettings.h" #include "datebookweek.h" +#include "datebookweeklst.h" #include "dateentryimpl.h" #include <qpe/datebookmonth.h> #include <qpe/qpeapplication.h> #include <qpe/config.h> #include <qpe/qpedebug.h> #include <qpe/event.h> #include <qpe/finddialog.h> @@ -64,16 +65,17 @@ #include <sys/types.h> #include <fcntl.h> #include <unistd.h> #include <stdlib.h> #define DAY 1 #define WEEK 2 +#define WEEKLST 4 #define MONTH 3 DateBook::DateBook( QWidget *parent, const char *, WFlags f ) : QMainWindow( parent, "datebook", f ), aPreset( FALSE ), presetTime( -1 ), startTime( 8 ), // an acceptable default @@ -85,16 +87,24 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f ) db = new DateBookDB; qDebug("loading db t=%d", t.elapsed() ); loadSettings(); setCaption( tr("Calendar") ); setIcon( Resource::loadPixmap( "datebook_icon" ) ); setToolBarsMovable( FALSE ); + views = new QWidgetStack( this ); + setCentralWidget( views ); + + dayView = 0; + weekView = 0; + weekLstView = 0; + monthView = 0; + QPEToolBar *bar = new QPEToolBar( this ); bar->setHorizontalStretchable( TRUE ); QPEMenuBar *mb = new QPEMenuBar( bar ); mb->setMargin( 0 ); QPEToolBar *sub_bar = new QPEToolBar(this); @@ -119,64 +129,93 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f ) a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); a->addTo( sub_bar ); a->addTo( view ); a->setToggleAction( TRUE ); a->setOn( TRUE ); dayAction = a; + a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); a->addTo( sub_bar ); a->addTo( view ); a->setToggleAction( TRUE ); weekAction = a; + + a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "weeklst" ), QString::null, 0, g, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); + a->addTo( sub_bar ); + a->addTo( view ); + a->setToggleAction( TRUE ); + weekLstAction = a; + a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); a->addTo( sub_bar ); a->addTo( view ); a->setToggleAction( TRUE ); monthAction = a; a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 ); connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); a->addTo( sub_bar ); a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); a->addTo( settings ); - views = new QWidgetStack( this ); - setCentralWidget( views ); - - dayView = 0; - weekView = 0; - monthView = 0; + QPopupMenu *default_view = new QPopupMenu(this); + settings->insertItem( tr( "Default View" ),default_view ); + default_view->setCheckable(TRUE); - viewDay(); + + Config config("DateBook"); + config.setGroup("Main"); + int current=config.readNumEntry("defaultview", DAY); + + QActionGroup *ag = new QActionGroup(this); + a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true ); + if (current==DAY) a->setOn(true), viewDay(); + ag->insert(a); + a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true ); + if (current==WEEK) a->setOn(true), viewWeek(); + ag->insert(a); + a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true ); + if (current==WEEKLST) a->setOn(true), viewWeekLst(); + ag->insert(a); + a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true ); + if (current==MONTH) a->setOn(true), viewMonth(); + ag->insert(a); + + ag->addTo(default_view); + connect(ag, SIGNAL( selected ( QAction * ) ), + this, SLOT( newDefaultView(QAction *) ) + ); + connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) ); connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(changeWeek(bool)) ); - + #if defined(Q_WS_QWS) && !defined(QT_NO_COP) connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), this, SLOT(appMessage(const QCString&, const QByteArray&)) ); #endif - + // listen on QPE/System #if defined(Q_WS_QWS) #if !defined(QT_NO_COP) QCopChannel *channel = new QCopChannel( "QPE/System", this ); connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), - this, SLOT(receive(const QCString&, const QByteArray&)) ); + this, SLOT(receive(const QCString&, const QByteArray&)) ); #endif #endif - + qDebug("done t=%d", t.elapsed() ); } void DateBook::receive( const QCString &msg, const QByteArray &data ) { QDataStream stream( data, IO_ReadOnly ); if ( msg == "timeChange(QString)" ) { @@ -259,16 +298,18 @@ QString DateBook::checkEvent(const Event &e) QDate DateBook::currentDate() { QDate d = QDate::currentDate(); if ( dayView && views->visibleWidget() == dayView ) { d = dayView->date(); } else if ( weekView && views->visibleWidget() == weekView ) { d = weekView->date(); + } else if ( weekLstView && views->visibleWidget() == weekLstView ) { + d = weekLstView->date(); } else if ( monthView && views->visibleWidget() == monthView ) { d = monthView->selectedDate(); } return d; } void DateBook::viewDay() @@ -286,16 +327,25 @@ void DateBook::viewWeek() initWeek(); weekAction->setOn( TRUE ); QDate d = currentDate(); weekView->setDate( d ); views->raiseWidget( weekView ); weekView->redraw(); } +void DateBook::viewWeekLst() { + initWeekLst(); + weekLstAction->setOn( TRUE ); + QDate d=currentDate(); + weekLstView->setDate(d); + views->raiseWidget( weekLstView ); + weekLstView->redraw(); +} + void DateBook::viewMonth() { initMonth(); monthAction->setOn( TRUE ); QDate d = currentDate(); monthView->setDate( d.year(), d.month(), d.day() ); views->raiseWidget( monthView ); monthView->redraw(); @@ -326,17 +376,18 @@ void DateBook::editEvent( const Event &e ) #if defined(Q_WS_QWS) || defined(_WS_QWS_) editDlg.showMaximized(); #endif while (editDlg.exec() ) { Event newEv = entry->event(); QString error = checkEvent(newEv); if (!error.isNull()) { if (QMessageBox::warning(this, "error box", - error, "Fix it", "Continue", 0, 0, 1) == 0) + error, "Fix it", "Continue", + 0, 0, 1) == 0) continue; } db->editEvent(e, newEv); emit newEvent(); break; } } @@ -396,37 +447,59 @@ void DateBook::initDay() void DateBook::initWeek() { if ( !weekView ) { weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); weekView->setStartViewTime( startTime ); views->addWidget( weekView, WEEK ); connect( weekView, SIGNAL( showDate( int, int, int ) ), - this, SLOT( showDay( int, int, int ) ) ); + this, SLOT( showDay( int, int, int ) ) ); connect( this, SIGNAL( newEvent() ), weekView, SLOT( redraw() ) ); } //But also get it right: the year that we display can be different //from the year of the current date. So, first find the year //number of the current week. int yearNumber, totWeeks; calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); QDate d = QDate( yearNumber, 12, 31 ); calcWeek( d, totWeeks, yearNumber, onMonday ); - + while ( totWeeks == 1 ) { d = d.addDays( -1 ); calcWeek( d, totWeeks, yearNumber, onMonday ); } if ( totWeeks != weekView->totalWeeks() ) weekView->setTotalWeeks( totWeeks ); } +void DateBook::initWeekLst() { + if ( !weekLstView ) { + weekLstView = new DateBookWeekLst( ampm, onMonday, db, + views, "weeklst view" ); + views->addWidget( weekLstView, WEEKLST ); + + //weekLstView->setStartViewTime( startTime ); + connect( weekLstView, SIGNAL( showDate( int, int, int ) ), + this, SLOT( showDay( int, int, int ) ) ); + connect( weekLstView, SIGNAL( addEvent( const QDateTime &, + const QDateTime &, + const QString & ) ), + this, SLOT( slotNewEntry( const QDateTime &, + const QDateTime &, + const QString & ) ) ); + connect( this, SIGNAL( newEvent() ), + weekLstView, SLOT( redraw() ) ); + connect( weekLstView, SIGNAL( editEvent( const Event & ) ), + this, SLOT( editEvent( const Event & ) ) ); + } +} + void DateBook::initMonth() { if ( !monthView ) { monthView = new DateBookMonth( views, "month view", FALSE, db ); views->addWidget( monthView, MONTH ); connect( monthView, SIGNAL( dateClicked( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) ); @@ -439,17 +512,17 @@ void DateBook::initMonth() void DateBook::loadSettings() { { Config config( "qpe" ); config.setGroup("Time"); ampm = config.readBoolEntry( "AMPM", TRUE ); onMonday = config.readBoolEntry( "MONDAY" ); } - + { Config config("DateBook"); config.setGroup("Main"); startTime = config.readNumEntry("startviewtime", 8); aPreset = config.readBoolEntry("alarmpreset"); presetTime = config.readNumEntry("presettime"); } } @@ -459,16 +532,28 @@ 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::newDefaultView(QAction *a) { + int val=DAY; + if (a->text() == "Day") val=DAY; + if (a->text() == "Week") val=WEEK; + if (a->text() == "WeekLst") val=WEEKLST; + if (a->text() == "Month") val=MONTH; + + Config configDB( "DateBook" ); + configDB.setGroup( "Main" ); + configDB.writeEntry("defaultview",val); +} + 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; @@ -531,16 +616,18 @@ void DateBook::appMessage(const QCString& msg, const QByteArray& data) } } } else if ( msg == "nextView()" ) { 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_) @@ -585,16 +672,17 @@ void DateBook::timerEvent( QTimerEvent *e ) } 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; } @@ -655,17 +743,19 @@ void DateBook::slotNewEventFromKey( const QString &str ) 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 ) ); } - + 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 ); |