author | drw <drw> | 2005-04-06 22:11:14 (UTC) |
---|---|---|
committer | drw <drw> | 2005-04-06 22:11:14 (UTC) |
commit | 678c792dd69e42a15d8ac5eaaa9228dfd413ed4c (patch) (side-by-side diff) | |
tree | a7ab851cf76be078d145310d45663ffe4fbda4ec | |
parent | 9ea956870ddf74ddc70b83ed529ebb3b36e9231e (diff) | |
download | opie-678c792dd69e42a15d8ac5eaaa9228dfd413ed4c.zip opie-678c792dd69e42a15d8ac5eaaa9228dfd413ed4c.tar.gz opie-678c792dd69e42a15d8ac5eaaa9228dfd413ed4c.tar.bz2 |
Use OResource for loading images, correct display of alarm and reoccurance icons for event and fix headers
27 files changed, 795 insertions, 371 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp index cc7bf4b..68ab07a 100644 --- a/core/pim/datebook/datebook.cpp +++ b/core/pim/datebook/datebook.cpp @@ -1,932 +1,948 @@ -/********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. -** -** This file is part of 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. -** -** $Id$ -** -**********************************************************************/ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ #define QTOPIA_INTERNAL_FD #include "datebook.h" #include "datebookday.h" #include "datebooksettings.h" #include "datebookweek.h" #include "modules/weeklst/datebookweeklst.h" #include "modules/monthview/odatebookmonth.h" #include "dateentryimpl.h" #include <opie2/odebug.h> #include <opie2/oholidaypluginif.h> #include <opie2/oholidayplugin.h> #include <opie2/opluginloader.h> +#include <opie2/oresource.h> #include <opie2/todayplugininterface.h> //#include <qpe/datebookmonth.h> #include <qpe/qpeapplication.h> #include <qpe/config.h> #include <qpe/finddialog.h> #include <qpe/ir.h> #include <qpe/qpemessagebox.h> -#include <qpe/resource.h> #include <qpe/sound.h> #include <qpe/tzselect.h> #include <qtopia/qlibrary.h> #include <qaction.h> #include <qcopchannel_qws.h> #include <qlayout.h> #include <qmessagebox.h> #include <qtimer.h> #include <qtl.h> #include <qtoolbar.h> #include <qwidgetstack.h> #include <qdir.h> #include <qlabel.h> #include <sys/stat.h> #include <sys/types.h> #include <fcntl.h> #include <unistd.h> #include <stdlib.h> DateBook::DateBook( QWidget *parent, const char *, WFlags f ) : QMainWindow( parent, "datebook", f ), aPreset( FALSE ), presetTime( -1 ), startTime( 8 ), // an acceptable default rowStyle( 0 ), bJumpToCurTime(FALSE), syncing(FALSE), inSearch(FALSE), alarmCounter(0) { bool needEvilHack= false; // if we need an Evil Hack QTime t; t.start(); db = new DateBookDBHoliday; odebug << "loading db t=" << t.elapsed() << oendl; db_holiday = new DateBookHoliday(); db->db_holiday=db_holiday; loadSettings(); setCaption( tr("Calendar") ); - setIcon( Resource::loadPixmap( "datebook_icon" ) ); + setIcon( Opie::Core::OResource::loadPixmap( "datebook_icon" ) ); setToolBarsMovable( FALSE ); views = new QWidgetStack( this ); setCentralWidget( views ); dayView = 0; weekView = 0; weekLstView = 0; monthView = 0; // QToolBar *bar = new QToolBar( this ); // bar->setHorizontalStretchable( TRUE ); // QMenuBar *mb = new QMenuBar( bar ); // mb->setMargin( 0 ); // QPopupMenu *view = new QPopupMenu( this ); // mb->insertItem( tr( "View" ), view ); QToolBar *sub_bar = new QToolBar(this); sub_bar->setHorizontalStretchable(TRUE); QActionGroup *g = new QActionGroup( this ); g->setExclusive( TRUE ); - QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); + QAction *a = new QAction( tr( "New" ), Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), + QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); a->addTo( sub_bar ); sub_bar->addSeparator(); - a = new QAction( tr( "Today" ), Resource::loadPixmap( "datebook/to_day" ), QString::null, 0, g, 0 ); + a = new QAction( tr( "Today" ), Opie::Core::OResource::loadPixmap( "datebook/to_day", Opie::Core::OResource::SmallIcon ), + QString::null, 0, g, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); a->addTo( sub_bar ); // a->addTo( view ); sub_bar->addSeparator(); - a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); + a = new QAction( tr( "Day" ), Opie::Core::OResource::loadPixmap( "day", Opie::Core::OResource::SmallIcon ), + 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 ); + a = new QAction( tr( "Week" ), Opie::Core::OResource::loadPixmap( "week", Opie::Core::OResource::SmallIcon ), + 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( "datebook/weeklst" ), QString::null, 0, g, 0 ); + a = new QAction( tr( "WeekLst" ), Opie::Core::OResource::loadPixmap( "datebook/weeklst", Opie::Core::OResource::SmallIcon ), + 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 ); + a = new QAction( tr( "Month" ), Opie::Core::OResource::loadPixmap( "month", Opie::Core::OResource::SmallIcon ), + QString::null, 0, g, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); a->addTo( sub_bar ); // a->addTo( view ); a->setToggleAction( TRUE ); monthAction = a; sub_bar->addSeparator(); - a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 ); + a = new QAction( tr( "Find" ), Opie::Core::OResource::loadPixmap( "mag", Opie::Core::OResource::SmallIcon ), + QString::null, 0, this, 0 ); connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); a->addTo( sub_bar ); - a = new QAction( tr( "Edit..." ), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0 ); + a = new QAction( tr( "Edit..." ), Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ), + QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); a->addTo( sub_bar ); if(defaultView==DAY) viewDay(); if(defaultView==WEEK) needEvilHack=true; // viewWeek(); if(defaultView==WEEKLST) viewWeekLst(); if(defaultView==MONTH) viewMonth(); 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&)) ); channel = new QCopChannel( "QPE/Datebook", this ); connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(receive(const QCString&,const QByteArray&)) ); #endif #endif odebug << "done t=" << t.elapsed() << oendl; connect( qApp, SIGNAL( flush() ), this, SLOT( flush() ) ); connect( qApp, SIGNAL( reload()), this, SLOT( reload() ) ); /* * Here is a problem description: * When Weekview is the default view * a DateBookWeekView get's created * redraw() get's called. So what? * Remember that we're still in the c'tor * and no final layout has happened? Ok * now all Events get arranged. Their x * position get's determined by a QHeader * position. But the QHeader isn't layouted or * at the right position. redraw() is a slot * so we'll call it then via a singleShot * from view() */ if( needEvilHack ){ QTimer::singleShot( 500, this, SLOT(viewWeek()) ); } } void DateBook::receive( const QCString &msg, const QByteArray &data ) { QDataStream stream( data, IO_ReadOnly ); if ( msg == "timeChange(QString)" ) { // update active view! if ( dayAction->isOn() ) viewDay(); else if ( weekAction->isOn() ) viewWeek(); else if ( monthAction->isOn() ) viewMonth(); } else if (msg == "editEvent(int)") { int uid; stream >> uid; Event e=db->eventByUID(uid); editEvent(e); }else if (msg == "viewDefault(QDate)"){ QDate day; stream >> day; viewDefault(day); } } DateBook::~DateBook() { delete db_holiday; } void DateBook::slotSettings() { DateBookSettings frmSettings( ampm, this ); frmSettings.setStartTime( startTime ); frmSettings.setAlarmPreset( aPreset, presetTime ); frmSettings.setJumpToCurTime( bJumpToCurTime ); frmSettings.setRowStyle( rowStyle ); frmSettings.comboDefaultView->setCurrentItem(defaultView-1); frmSettings.comboWeekListView->setCurrentItem(weeklistviewconfig); frmSettings.setPluginList(db_holiday->pluginManager(),db_holiday->pluginLoader()); bool found=false; for (int i=0; i<(frmSettings.comboLocation->count()); i++) { if ( frmSettings.comboLocation->text(i) == defaultLocation ) { frmSettings.comboLocation->setCurrentItem(i); found=true; break; } } if(!found) { frmSettings.comboLocation->insertItem(defaultLocation); frmSettings.comboLocation->setCurrentItem(frmSettings.comboLocation->count()-1); } frmSettings.comboCategory->setCategories(defaultCategories,"Calendar", tr("Calendar")); if ( QPEApplication::execDialog( &frmSettings ) ) { frmSettings.savePlugins(); db_holiday->pluginManager()->save(); db_holiday->reloadPlugins(); aPreset = frmSettings.alarmPreset(); presetTime = frmSettings.presetTime(); startTime = frmSettings.startTime(); bJumpToCurTime = frmSettings.jumpToCurTime(); rowStyle = frmSettings.rowStyle(); defaultView=frmSettings.comboDefaultView->currentItem()+1; weeklistviewconfig=frmSettings.comboWeekListView->currentItem(); defaultLocation=frmSettings.comboLocation->currentText(); defaultCategories=frmSettings.comboCategory->currentCategories(); if ( dayView ) { dayView->setStartViewTime( startTime ); dayView->setJumpToCurTime( bJumpToCurTime ); dayView->setRowStyle( rowStyle ); } if ( weekView ) { weekView->setStartViewTime( startTime ); } saveSettings(); // make the change obvious if ( views->visibleWidget() ) { if ( views->visibleWidget() == dayView ) dayView->redraw(); else if ( views->visibleWidget() == weekView ) weekView->redraw(); else if ( views->visibleWidget() == weekLstView ) weekLstView->redraw(); } } } void DateBook::fileNew() { slotNewEventFromKey(""); } QString DateBook::checkEvent(const Event &e) { /* check if overlaps with itself */ bool checkFailed = FALSE; /* check the next 12 repeats. should catch most problems */ QDate current_date = e.start().date(); Event previous = e; for(int i = 0; i < 12; i++) { QDateTime next; if (!nextOccurance(previous, current_date.addDays(1), next)) { break; // no more repeats } if(next < previous.end()) { checkFailed = TRUE; break; } current_date = next.date(); } if(checkFailed) return tr("Event duration is potentially longer\n" "than interval between repeats."); return QString::null; } 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::view(int v, const QDate &d) { if (v==DAY) { initDay(); dayAction->setOn( TRUE ); dayView->setDate( d ); views->raiseWidget( dayView ); dayView->redraw(); } else if (v==WEEK) { initWeek(); weekAction->setOn( TRUE ); weekView->setDate( d ); views->raiseWidget( weekView ); weekView->redraw(); } else if (v==WEEKLST) { initWeekLst(); weekLstAction->setOn( TRUE ); weekLstView->setDate(d); views->raiseWidget( weekLstView ); weekLstView->redraw(); } else if (v==MONTH) { initMonth(); monthAction->setOn( TRUE ); monthView->setDate( d.year(), d.month(), d.day() ); views->raiseWidget( monthView ); monthView->redraw(); } } void DateBook::viewDefault(const QDate &d) { view(defaultView,d); } void DateBook::viewDay() { view(DAY,currentDate()); } void DateBook::viewWeek() { view(WEEK,currentDate()); } void DateBook::viewWeekLst() { view(WEEKLST,currentDate()); } void DateBook::viewMonth() { view(MONTH,currentDate()); } void DateBook::insertEvent( const Event &e ) { Event dupEvent=e; if(!dupEvent.isValidUid() ) // tkcRom seems to be different dupEvent.assignUid(); dupEvent.setLocation(defaultLocation); dupEvent.setCategories(defaultCategories); db->addEvent(dupEvent); emit newEvent(); } void DateBook::duplicateEvent( const Event &e ) { // Alot of code duplication, as this is almost like editEvent(); if (syncing) { QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); return; } Event dupevent(e); // Make a duplicate. // workaround added for text input. QDialog editDlg( this, 0, TRUE ); DateEntry *entry; editDlg.setCaption( tr("Duplicate Event") ); QVBoxLayout *vb = new QVBoxLayout( &editDlg ); QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); sv->setResizePolicy( QScrollView::AutoOneFit ); // KLUDGE!!! sv->setHScrollBarMode( QScrollView::AlwaysOff ); vb->addWidget( sv ); entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" ); entry->timezone->setEnabled( FALSE ); sv->addChild( entry ); while ( QPEApplication::execDialog( &editDlg ) ) { Event newEv = entry->event(); QString error = checkEvent(newEv); if (!error.isNull()) { if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) continue; } /* * The problem: * DateBookDB does remove repeating events not by uid but by the time * the recurrence was created * so we need to update that time as well */ Event::RepeatPattern rp = newEv.repeatPattern(); rp.createTime = ::time( NULL ); newEv.setRepeat( TRUE, rp ); // has repeat and repeatPattern... if( newEv.uid() == e.uid() || !newEv.isValidUid() ) newEv.assignUid(); db->addEvent(newEv); emit newEvent(); break; } } void DateBook::editEvent( const Event &e ) { if (syncing) { QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); return; } // workaround added for text input. QDialog editDlg( this, 0, TRUE ); DateEntry *entry; 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 ); entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); entry->timezone->setEnabled( FALSE ); sv->addChild( entry ); while ( QPEApplication::execDialog( &editDlg ) ) { Event newEv = entry->event(); if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) break; newEv.setUid(e.uid()); // FIXME: Hack not to clear uid QString error = checkEvent(newEv); if (!error.isNull()) { if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) continue; } db->editEvent(e, newEv); emit newEvent(); break; } } void DateBook::removeEvent( const Event &e ) { if (syncing) { QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); return; } QString strName = e.description(); if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) return; db->removeEvent( e ); if ( views->visibleWidget() == dayView && dayView ) dayView->redraw(); } void DateBook::addEvent( const Event &e ) { QDate d = e.start().date(); initDay(); dayView->setDate( d ); } void DateBook::showDay( int year, int month, int day ) { QDate d(year, month, day); view(DAY,d); } void DateBook::initDay() { if ( !dayView ) { dayView = new DateBookDay( ampm, onMonday, db, db_holiday, views, "day view" ); views->addWidget( dayView, DAY ); dayView->setJumpToCurTime( bJumpToCurTime ); dayView->setStartViewTime( startTime ); dayView->setRowStyle( rowStyle ); connect( this, SIGNAL( newEvent() ), dayView, SLOT( redraw() ) ); connect( dayView, SIGNAL( newEvent() ), this, SLOT( fileNew() ) ); connect( dayView, SIGNAL( removeEvent(const Event&) ), this, SLOT( removeEvent(const Event&) ) ); connect( dayView, SIGNAL( editEvent(const Event&) ), this, SLOT( editEvent(const Event&) ) ); connect( dayView, SIGNAL( duplicateEvent(const Event&) ), this, SLOT( duplicateEvent(const Event&) ) ); connect( dayView, SIGNAL( beamEvent(const Event&) ), this, SLOT( beamEvent(const Event&) ) ); connect( dayView, SIGNAL(sigNewEvent(const QString&)), this, SLOT(slotNewEventFromKey(const QString&)) ); } } 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) ) ); 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 ); } } 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&, const QString&) ), this, SLOT( slotNewEntry(const QDateTime&,const QDateTime&,const QString&, const QString&) ) ); connect( this, SIGNAL( newEvent() ), weekLstView, SLOT( redraw() ) ); connect( weekLstView, SIGNAL( editEvent(const Event&) ), this, SLOT( editEvent(const Event&) ) ); connect( weekLstView, SIGNAL( duplicateEvent( const Event & ) ), this, SLOT( duplicateEvent( const Event & ) ) ); connect( weekLstView, SIGNAL( beamEvent(const Event&) ), this, SLOT( beamEvent(const Event&) ) ); connect( weekLstView, SIGNAL( removeEvent( const Event & ) ), this, SLOT( removeEvent( const Event & ) ) ); } } void DateBook::initMonth() { if ( !monthView ) { monthView = new ODateBookMonth( views, "month view", FALSE, db ); views->addWidget( monthView, MONTH ); connect( monthView, SIGNAL( dateClicked(int,int,int) ), this, SLOT( showDay(int,int,int) ) ); connect( this, SIGNAL( newEvent() ), monthView, SLOT( redraw() ) ); qApp->processEvents(); } } void DateBook::loadSettings() { Config qpeconfig( "qpe" ); qpeconfig.setGroup("Time"); ampm = qpeconfig.readBoolEntry( "AMPM", TRUE ); onMonday = qpeconfig.readBoolEntry( "MONDAY" ); Config config("DateBook"); config.setGroup("Main"); startTime = config.readNumEntry("startviewtime", 8); aPreset = config.readBoolEntry("alarmpreset"); presetTime = config.readNumEntry("presettime"); bJumpToCurTime = config.readBoolEntry("jumptocurtime"); rowStyle = config.readNumEntry("rowstyle"); defaultView = config.readNumEntry("defaultview",DAY); weeklistviewconfig = config.readNumEntry("weeklistviewconfig",NORMAL); defaultLocation=config.readEntry("defaultLocation"); QString tmpString=config.readEntry("defaultCategories"); QStringList tmpStringList=QStringList::split(",",tmpString); defaultCategories.truncate(0); for( QStringList::Iterator i=tmpStringList.begin(); i!=tmpStringList.end(); i++) { defaultCategories.resize(defaultCategories.count()+1); defaultCategories[defaultCategories.count()-1]=(*i).toInt(); } } 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("jumptocurtime", bJumpToCurTime); configDB.writeEntry("rowstyle", rowStyle); configDB.writeEntry("defaultview",defaultView); configDB.writeEntry("weeklistviewconfig",weeklistviewconfig); configDB.writeEntry("defaultLocation",defaultLocation); QStringList tmpStringList; for( uint i=0; i<defaultCategories.count(); i++) { tmpStringList << QString::number(defaultCategories[i]); } configDB.writeEntry("defaultCategories",tmpStringList.join(",")); } 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; // check to make it's okay to continue, // this is the case that the time was set ahead, and // we are forced given a stale alarm... QDateTime current = QDateTime::currentDateTime(); if ( current.time().hour() != when.time().hour() && current.time().minute() != when.time().minute() ) return; QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); if ( list.count() > 0 ) { QString msg; bool bSound = FALSE; int stopTimer = 0; bool found = FALSE; for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); it!=list.end(); ++it ) { if ( (*it).event().hasAlarm() ) { found = TRUE; msg += "<CENTER><B>" + (*it).description() + "</B>" + "<BR>" + (*it).location() + "<BR>" + TimeString::dateString((*it).event().start(),ampm) + (warn ? tr(" (in " + QString::number(warn) + tr(" minutes)")) : QString("")) + "<BR>" + (*it).notes() + "</CENTER>"; if ( (*it).event().alarmSound() != Event::Silent ) { bSound = TRUE; } } } if ( found ) { if ( bSound ) { Sound::soundAlarm(); alarmCounter = 0; 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 ); if ( bSound ) killTimer( stopTimer ); } } } else if ( msg == "nextView()" ) { needShow = true; if ( !qApp-> activeWindow ( )) { needShow = TRUE; } else { 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; } } } else if (msg == "editEvent(int)") { /* simple copy from receive */ QDataStream stream(data,IO_ReadOnly); int uid; stream >> uid; Event e=db->eventByUID(uid); editEvent(e); } else if (msg == "viewDefault(QDate)"){ /* simple copy from receive */ QDataStream stream(data,IO_ReadOnly); QDate day; stream >> day; viewDefault(day); needShow = true; } if ( needShow ) { #if defined(Q_WS_QWS) || defined(_WS_QWS_) // showMaximized(); #else // show(); #endif // raise(); QPEApplication::setKeepRunning(); // setActiveWindow(); } } void DateBook::reload() { db->reload(); if ( dayAction->isOn() ) viewDay(); else if ( weekAction->isOn() ) viewWeek(); else if ( monthAction->isOn() ) viewMonth(); syncing = FALSE; } void DateBook::flush() { syncing = TRUE; db->save(); } void DateBook::timerEvent( QTimerEvent *e ) { if ( alarmCounter < 10 ) { alarmCounter++; Sound::soundAlarm(); } else { killTimer( e->timerId() ); } } 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; } void DateBook::slotToday() { // we need to view today using default view view(defaultView,QDate::currentDate()); } void DateBook::closeEvent( QCloseEvent *e ) { 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(); } 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(); } } // Entering directly from the "keyboard" void DateBook::slotNewEventFromKey( const QString &str ) { if (syncing) { QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); return; } // 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. QDateTime start, end; if ( views->visibleWidget() == dayView ) { dayView->selectedDates( start, end ); } else if ( views->visibleWidget() == monthView ) { QDate d = monthView->selectedDate(); start = end = d; 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 ) ); } else if ( views->visibleWidget() == weekLstView ) { QDate d = weekLstView->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, const QString &location) { // 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 ); Event ev; ev.setDescription( str ); // When the new gui comes in, change this... if(location==0) { if(defaultLocation.isEmpty()) { ev.setLocation(tr("(Unknown)")); } else { ev.setLocation( defaultLocation ); } } else { ev.setLocation(location); } ev.setCategories(defaultCategories); ev.setStart( start ); ev.setEnd( end ); e = new DateEntry( onMonday, ev, ampm, &newDlg ); e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); sv->addChild( e ); while ( QPEApplication::execDialog( &newDlg ) ) { ev = e->event(); ev.assignUid(); QString error = checkEvent( ev ); if ( !error.isNull() ) { if ( QMessageBox::warning( this, tr("Error!"), error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) continue; } db->addEvent( ev ); emit newEvent(); break; } } void DateBook::setDocument( const QString &filename ) { if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; QValueList<Event> tl = Event::readVCalendar( filename ); for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { db->addEvent( *it ); } } static const char * beamfile = "/tmp/obex/event.vcs"; void DateBook::beamEvent( const Event &e ) { odebug << "trying to beam" << oendl; unlink( beamfile ); // delete if exists mkdir("/tmp/obex/", 0755); Event::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" ); diff --git a/core/pim/datebook/datebook.h b/core/pim/datebook/datebook.h index 05ab781..c12f5c4 100644 --- a/core/pim/datebook/datebook.h +++ b/core/pim/datebook/datebook.h @@ -1,134 +1,145 @@ -/********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. -** -** This file is part of 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. -** -**********************************************************************/ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + #ifndef DATEBOOK_H #define DATEBOOK_H #include "datebooktypes.h" #include <qpe/datebookdb.h> #include <qmainwindow.h> class QAction; class QWidgetStack; class DateBookDay; class DateBookWeek; class DateBookWeekLst; class ODateBookMonth; class Event; class QDate; class Ir; class DateBook : public QMainWindow { Q_OBJECT public: static QString appName() { return QString::fromLatin1("datebook"); } DateBook( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); ~DateBook(); signals: void newEvent(); void signalNotFound(); void signalWrapAround(); protected: QDate currentDate(); void timerEvent( QTimerEvent *e ); void closeEvent( QCloseEvent *e ); void view(int v, const QDate &d); public slots: void flush(); void reload(); private slots: void fileNew(); void slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str, const QString &location=0); void slotSettings(); void slotToday(); // view today void changeClock( bool newClock ); void changeWeek( bool newDay ); void appMessage(const QCString& msg, const QByteArray& data); // handle key events in the day view... void slotNewEventFromKey( const QString &str ); void slotFind(); void slotDoFind( const QString &, const QDate &, bool, bool, int ); void viewDefault(const QDate &d); void viewDay(); void viewWeek(); void viewWeekLst(); void viewMonth(); void showDay( int y, int m, int d ); void insertEvent( const Event &e ); void editEvent( const Event &e ); void duplicateEvent( const Event &e ); void removeEvent( const Event &e ); void receive( const QCString &msg, const QByteArray &data ); void setDocument( const QString & ); void beamEvent( const Event &e ); void beamDone( Ir *ir ); private: void addEvent( const Event &e ); void initDay(); void initWeek(); void initWeekLst(); void initMonth(); void loadSettings(); void saveSettings(); private: DateBookDBHoliday *db; DateBookHoliday*db_holiday; QWidgetStack *views; DateBookDay *dayView; DateBookWeek *weekView; ODateBookMonth *monthView; DateBookWeekLst *weekLstView; QAction *dayAction, *weekAction, *weekLstAction, *monthAction; int weeklistviewconfig; bool aPreset; // have everything set to alarm? int presetTime; // the standard time for the alarm int startTime; int rowStyle; int defaultView; QArray<int> defaultCategories; QString defaultLocation; bool bJumpToCurTime; //should jump to current time in dayview? bool ampm; bool onMonday; bool syncing; bool inSearch; int alarmCounter; QString checkEvent(const Event &); }; #endif diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp index 26f0303..b8385aa 100644 --- a/core/pim/datebook/datebookday.cpp +++ b/core/pim/datebook/datebookday.cpp @@ -1,947 +1,961 @@ -/********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. -** -** This file is part of 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. -** -**********************************************************************/ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ #include "datebookday.h" #include "datebooktypes.h" #include "datebookdayheaderimpl.h" #include "datebookdayallday.h" #include <opie2/oholidayplugin.h> -#include <qpe/resource.h> -#include <qpe/qpeapplication.h> +#include <opie2/oresource.h> + +#include <qpe/applnk.h> #include <qpe/ir.h> +#include <qpe/qpeapplication.h> #include <qsimplerichtext.h> #include <qpopupmenu.h> #include <qtimer.h> DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, const char *name ) : QTable( 24, 1, parent, name ), ampm( whichClock ), currDate( QDate::currentDate() ) { enableClipper(TRUE); setTopMargin( 0 ); horizontalHeader()->hide(); setLeftMargin(38); setColumnStretchable( 0, TRUE ); setHScrollBarMode( QScrollView::AlwaysOff ); verticalHeader()->setPalette(white); verticalHeader()->setResizeEnabled(FALSE); setSelectionMode( Single ); // get rid of being able to edit things... QTableItem *tmp; int row; for ( row = 0; row < numRows(); row++ ) { tmp = new QTableItem( this, QTableItem::Never, QString::null); setItem( row, 0, tmp ); //setRowHeight( row, 40); } initHeader(); QObject::connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotChangeClock(bool)) ); } void DateBookDayView::initHeader() { QString strTmp; int preferredWidth = 0; for ( int i = 0; i < 24; ++i ) { if ( ampm ) { if ( i == 0 ) strTmp = QString::number(12) + ":00"; else if ( i == 12 ) strTmp = QString::number(12) + tr(":00p"); else if ( i > 12 ) strTmp = QString::number( i - 12 ) + tr(":00p"); else strTmp = QString::number(i) + ":00"; } else { if ( i < 10 ) strTmp = "0" + QString::number(i) + ":00"; else strTmp = QString::number(i) + ":00"; } strTmp = strTmp.rightJustify( 6, ' ' ); verticalHeader()->setLabel( i, strTmp ); // Compute correct width for current Font (Add some space right) int actWidth = QFontMetrics( QFont::defaultFont() ).width( strTmp + QString(" ") ); if ( preferredWidth < actWidth ) preferredWidth = actWidth; setRowStretchable( i, FALSE ); } // It seems as if the header has a bug. It does not resize // correct horizontally if it is used vertical.. // Thus, we do it manually.. setLeftMargin( preferredWidth ); } void DateBookDayView::slotDateChanged( int y, int m, int d ) { currDate.setYMD(y,m,d); } void DateBookDayView::slotChangeClock( bool newClock ) { ampm = newClock; initHeader(); } bool DateBookDayView::whichClock() const { return ampm; } void DateBookDayView::moveUp() { scrollBy(0, -20); } void DateBookDayView::moveDown() { scrollBy(0, 20); } void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool ) { int w = cr.width(); int h = cr.height(); p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) ); if ( showGrid() ) { // Draw our lines int x2 = w - 1; int y2 = h - 1; QPen pen( p->pen() ); p->setPen( colorGroup().dark() ); p->drawLine( x2, 0, x2, y2 ); p->drawLine( 0, y2, x2, y2 ); p->setPen( colorGroup().midlight() ); p->drawLine( 0, y2 - h/2, x2, y2 - h/2); p->setPen( pen ); } } void DateBookDayView::paintFocus( QPainter *, const QRect & ) { } void DateBookDayView::resizeEvent( QResizeEvent *e ) { QTable::resizeEvent( e ); columnWidthChanged( 0 ); emit sigColWidthChanged(); } void DateBookDayView::keyPressEvent( QKeyEvent *e ) { QString txt = e->text(); if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) { // we this is some sort of thing we know about... e->accept(); emit sigCapturedKey( txt ); } else { // I don't know what this key is, do you? e->ignore(); } } void DateBookDayView::setRowStyle( int style ) { if (style<0) style = 0; for (int i=0; i<numRows(); i++) setRowHeight(i, style*10+20); } void DateBookDayView::contentsMouseReleaseEvent( QMouseEvent* /* e */ ) { int sh=99,eh=-1; for(int i=0;i<this->numSelections();i++) { QTableSelection sel = this->selection( i ); sh = QMIN(sh,sel.topRow()); eh = QMAX(sh,sel.bottomRow()+1); } if (sh > 23 || eh < 1) { sh=8; eh=9; } quickLineEdit=new DateBookDayViewQuickLineEdit(QDateTime(currDate,QTime(sh,0,0,0)),QDateTime(currDate,QTime(eh,0,0,0)),this->viewport(),"quickedit"); quickLineEdit->setGeometry(0,0,this->columnWidth(0)-1,this->rowHeight(0)); this->moveChild(quickLineEdit,0,sh*this->rowHeight(0)); quickLineEdit->setFocus(); quickLineEdit->show(); } //=========================================================================== DateBookDayViewQuickLineEdit::DateBookDayViewQuickLineEdit(const QDateTime &start, const QDateTime &end,QWidget * parent, const char *name) : QLineEdit(parent,name) { active=1; quickEvent.setStart(start); quickEvent.setEnd(end); connect(this,SIGNAL(returnPressed()),this,SLOT(slotReturnPressed())); } void DateBookDayViewQuickLineEdit::slotReturnPressed() { if(active && (!this->text().isEmpty())) { // Fix to avoid having this event beeing added multiple times. quickEvent.setDescription(this->text()); connect(this,SIGNAL(insertEvent(const Event&)),this->topLevelWidget(),SLOT(insertEvent(const Event&))); emit(insertEvent(quickEvent)); active=0; } /* we need to return to this object.. */ QTimer::singleShot(500, this, SLOT(finallyCallClose()) ); // Close and also delete this widget } void DateBookDayViewQuickLineEdit::finallyCallClose() { close(true); // also deletes this widget... } void DateBookDayViewQuickLineEdit::focusOutEvent ( QFocusEvent* /* e */) { slotReturnPressed(); // Reuse code to add event and close this widget. } //=========================================================================== DateBookDay::DateBookDay( bool ampm, bool startOnMonday, DateBookDBHoliday *newDb, DateBookHoliday*newHdb, QWidget *parent, const char *name ) : QVBox( parent, name ), currDate( QDate::currentDate() ), db( newDb ), startTime( 0 ) { widgetList.setAutoDelete( true ); _holiday_db = newHdb; header = new DateBookDayHeader( startOnMonday, this, "day header" ); header->setDate( currDate.year(), currDate.month(), currDate.day() ); m_allDays = new DatebookdayAllday(newDb, this, "all day event list" ); m_allDays->hide(); view = new DateBookDayView( ampm, this, "day view" ); connect( header, SIGNAL( dateChanged(int,int,int) ), this, SLOT( dateChanged(int,int,int) ) ); connect( header, SIGNAL( dateChanged(int,int,int) ), view, SLOT( slotDateChanged(int,int,int) ) ); connect( view, SIGNAL( sigColWidthChanged() ), this, SLOT( slotColWidthChanged() ) ); connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); connect( view, SIGNAL(sigCapturedKey(const QString&)), this, SIGNAL(sigNewEvent(const QString&)) ); QTimer *timer = new QTimer( this ); connect( timer, SIGNAL(timeout()), this, SLOT(updateView()) ); //connect timer for updating timeMarker & daywidgetcolors timer->start( 1000*60*5, FALSE ); //update every 5min selectedWidget = 0; timeMarker = new DateBookDayTimeMarker( this ); timeMarker->setTime( QTime::currentTime() ); rowStyle = -1; // initialize with bogus values jumpToCurTime = false; } void DateBookDay::setJumpToCurTime( bool bJump ) { jumpToCurTime = bJump; } void DateBookDay::setRowStyle( int style ) { if (rowStyle != style) view->setRowStyle( style ); rowStyle = style; } void DateBookDay::updateView( void ) { timeMarker->setTime( QTime::currentTime() ); //need to find a way to update all DateBookDayWidgets } void DateBookDay::setSelectedWidget( DateBookDayWidget *w ) { selectedWidget = w; } DateBookDayWidget * DateBookDay::getSelectedWidget( void ) { return selectedWidget; } void DateBookDay::selectedDates( QDateTime &start, QDateTime &end ) { start.setDate( currDate ); end.setDate( currDate ); int sh=99,eh=-1; int n = dayView()->numSelections(); for (int i=0; i<n; i++) { QTableSelection sel = dayView()->selection( i ); sh = QMIN(sh,sel.topRow()); eh = QMAX(sh,sel.bottomRow()+1); } if (sh > 23 || eh < 1) { sh=8; eh=9; } start.setTime( QTime( sh, 0, 0 ) ); end.setTime( QTime( eh, 0, 0 ) ); } void DateBookDay::setDate( int y, int m, int d ) { header->setDate( y, m, d ); selectedWidget = 0; } void DateBookDay::setDate( QDate d) { header->setDate( d.year(), d.month(), d.day() ); selectedWidget = 0; } void DateBookDay::dateChanged( int y, int m, int d ) { QDate date( y, m, d ); if ( currDate == date ) return; currDate.setYMD( y, m, d ); relayoutPage(); dayView()->clearSelection(); QTableSelection ts; if (jumpToCurTime && this->date() == QDate::currentDate()) { ts.init( QTime::currentTime().hour(), 0); ts.expandTo( QTime::currentTime().hour(), 0); } else { ts.init( startTime, 0 ); ts.expandTo( startTime, 0 ); } dayView()->addSelection( ts ); selectedWidget = 0; } void DateBookDay::redraw() { if ( isUpdatesEnabled() ) relayoutPage(); } void DateBookDay::getEvents() { widgetList.clear(); /* clear the AllDay List */ m_allDays->hide(); // just in case m_allDays->removeAllEvents(); QStringList hdays = _holiday_db->holidaylist(currDate); QStringList::Iterator sit; QObject* object = 0; /* this way we make sure that holiday dummy events are always on top of the widgetlist. */ for (sit=hdays.begin();sit!=hdays.end();++sit) { m_allDays->addHoliday(*sit); } QValueList<EffectiveEvent> eventList = db->getEffectiveEventsNoHoliday( currDate, currDate ); QValueListIterator<EffectiveEvent> it; for ( it = eventList.begin(); it != eventList.end(); ++it ) { EffectiveEvent ev=*it; if(!((ev.end().hour()==0) && (ev.end().minute()==0) && (ev.startDate()!=ev.date()))) { // Skip events ending at 00:00 starting at another day. if (ev.event().type() == Event::AllDay ) { object = m_allDays->addEvent( ev ); if (!object) continue; }else { DateBookDayWidget* w = new DateBookDayWidget( *it, this ); widgetList.append( w ); object = w; } connect( object, SIGNAL( deleteMe(const Event&) ), this, SIGNAL( removeEvent(const Event&) ) ); connect( object, SIGNAL( duplicateMe(const Event&) ), this, SIGNAL( duplicateEvent(const Event&) ) ); connect( object, SIGNAL( editMe(const Event&) ), this, SIGNAL( editEvent(const Event&) ) ); connect( object, SIGNAL( beamMe(const Event&) ), this, SIGNAL( beamEvent(const Event&) ) ); } } } static int place( const DateBookDayWidget *item, bool *used, int maxn ) { int place = 0; int start = item->event().start().hour(); QTime e = item->event().end(); int end = e.hour(); if ( e.minute() < 5 ) end--; if ( end < start ) end = start; while ( place < maxn ) { bool free = TRUE; int s = start; while( s <= end ) { if ( used[10*s+place] ) { free = FALSE; break; } s++; } if ( free ) break; place++; } if ( place == maxn ) { return -1; } while( start <= end ) { used[10*start+place] = TRUE; start++; } return place; } void DateBookDay::relayoutPage( bool fromResize ) { setUpdatesEnabled( FALSE ); if ( !fromResize ) { getEvents(); // no need we already have them! if (m_allDays->items() > 0 ) m_allDays->show(); /* * else if ( m_allDays->items() == 0 ) already hide in getEvents */ } widgetList.sort(); //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view int wCount = widgetList.count(); int wid = view->columnWidth(0)-1; int wd; int n = 1; QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget for (int i = 0; i<wCount; anzIntersect[i] = 1, i++); if ( wCount < 20 ) { QArray<QRect> geometries(wCount); for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++); //stores geometry for each widget in vector for ( int i = 0; i < wCount; i++) { QValueList<int> intersectedWidgets; //find all widgets intersecting with widgetList.at(i) for ( int j = 0; j < wCount; j++) { if (i != j) if (geometries[j].intersects(geometries[i])) intersectedWidgets.append(j); } //for each of these intersecting widgets find out how many widgets are they intersecting with for ( uint j = 0; j < intersectedWidgets.count(); j++) { QArray<int> inter(wCount); inter[j]=1; if (intersectedWidgets[j] != -1) for ( uint k = j; k < intersectedWidgets.count(); k++) { if (j != k && intersectedWidgets[k] != -1) if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]])) { inter[j]++; intersectedWidgets[k] = -1; } if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1; } } if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++; } for ( int i = 0; i < wCount; i++) { DateBookDayWidget *w = widgetList.at(i); QRect geom = w->geometry(); geom.setX( 0 ); wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0); geom.setWidth( wd ); while ( intersects( w, geom ) ) { geom.moveBy( wd + 2 + 1, 0 ); } w->setGeometry( geom ); } if (jumpToCurTime && this->date() == QDate::currentDate()) { view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour } else { view->setContentsPos( 0, startTime * view->rowHeight(0) ); } } else { int hours[24]; memset( hours, 0, 24*sizeof( int ) ); bool overFlow = FALSE; for ( int i = 0; i < wCount; i++ ) { DateBookDayWidget *w = widgetList.at(i); int start = w->event().start().hour(); QTime e = w->event().end(); int end = e.hour(); if ( e.minute() < 5 ) end--; if ( end < start ) end = start; while( start <= end ) { hours[start]++; if ( hours[start] >= 10 ) overFlow = TRUE; ++start; } if ( overFlow ) break; } for ( int i = 0; i < 24; i++ ) { n = QMAX( n, hours[i] ); } wid = ( view->columnWidth(0)-1 ) / n; bool used[24*10]; memset( used, FALSE, 24*10*sizeof( bool ) ); for ( int i = 0; i < wCount; i++ ) { DateBookDayWidget *w = widgetList.at(i); int xp = place( w, used, n ); if ( xp != -1 ) { QRect geom = w->geometry(); geom.setX( xp*(wid+2) ); geom.setWidth( wid ); w->setGeometry( geom ); } } if (jumpToCurTime && this->date() == QDate::currentDate()) { view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour } else { view->setContentsPos( 0, startTime * view->rowHeight(0) ); } } timeMarker->setTime( QTime::currentTime() ); //display timeMarker timeMarker->raise(); //on top of all widgets if (this->date() == QDate::currentDate()) { //only show timeMarker on current day timeMarker->show(); } else { timeMarker->hide(); } setUpdatesEnabled( TRUE ); return; } DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom ) { int i = 0; DateBookDayWidget *w = widgetList.at(i); int wCount = widgetList.count(); while ( i < wCount && w != item ) { if ( w->geometry().intersects( geom ) ) { return w; } w = widgetList.at(++i); } return 0; } QDate DateBookDay::date() const { return currDate; } void DateBookDay::setStartViewTime( int startHere ) { startTime = startHere; dayView()->clearSelection(); QTableSelection ts; if (jumpToCurTime && this->date() == QDate::currentDate()) { //this should probably be in datebook.cpp where it's called? ts.init( QTime::currentTime().hour(), 0); ts.expandTo( QTime::currentTime().hour(), 0); } else { ts.init( startTime, 0 ); ts.expandTo( startTime, 0 ); } dayView()->addSelection( ts ); } int DateBookDay::startViewTime() const { return startTime; } void DateBookDay::slotWeekChanged( bool bStartOnMonday ) { header->setStartOfWeek( bStartOnMonday ); // redraw(); } void DateBookDay::keyPressEvent(QKeyEvent *e) { switch(e->key()) { case Key_Up: view->moveUp(); break; case Key_Down: view->moveDown(); break; case Key_Left: setDate(QDate(currDate).addDays(-1)); break; case Key_Right: setDate(QDate(currDate).addDays(1)); break; default: e->ignore(); } } //=========================================================================== DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e, DateBookDay *db ) : QWidget( db->dayView()->viewport() ), ev( e ), dateBook( db ) { // why would someone use "<"? Oh well, fix it up... // I wonder what other things may be messed up... QString strDesc = ev.description(); int where = strDesc.find( "<" ); while ( where != -1 ) { strDesc.remove( where, 1 ); strDesc.insert( where, "<" ); where = strDesc.find( "<", where ); } QString strCat; // ### Fix later... // QString strCat = ev.category(); // where = strCat.find( "<" ); // while ( where != -1 ) { // strCat.remove( where, 1 ); // strCat.insert( where, "<" ); // where = strCat.find( "<", where ); // } QString strNote = ev.notes(); where = strNote.find( "<" ); while ( where != -1 ) { strNote.remove( where, 1 ); strNote.insert( where, "<" ); where = strNote.find( "<", where ); } text = "<b>" + strDesc + "</b><br>" + "<i>"; if ( !strCat.isEmpty() ) { text += strCat + "</i><br>"; } if (ev.event().type() == Event::Normal ) { setEventText( text ); } else { setAllDayText( text ); } text += "<br><br>" + strNote; setBackgroundMode( PaletteBase ); QTime start = ev.start(); QTime end = ev.end(); int y = start.hour()*60+start.minute(); int h = end.hour()*60+end.minute()-y; int rh = dateBook->dayView()->rowHeight(0); y = y*rh/60; h = h*rh/60; if ( h < 12 ) h = 12; // Make sure the widget is no smaller than 12 pixels high, so that it's possible to read atleast the first line. if ( y > ((24*rh)-12) ) y=(24*rh)-12; // Make sure the widget fits inside the dayview. geom.setY( y ); geom.setHeight( h ); geom.setX( 0 ); geom.setWidth(dateBook->dayView()->columnWidth(0)-1); } void DateBookDayWidget::setAllDayText( QString &text ) { text += "<b>" + tr("This is an all day event.") + "</b>"; } void DateBookDayWidget::setEventText( QString& text ) { bool whichClock = dateBook->dayView()->whichClock(); if ( ev.startDate() != ev.endDate() ) { text += "<b>" + tr("Start") + "</b>: "; text += TimeString::timeString( ev.event().start().time(), whichClock, FALSE ); text += " - " + TimeString::longDateString( ev.startDate() ) + "<br>"; text += "<b>" + tr("End") + "</b>: "; text += TimeString::timeString( ev.event().end().time(), whichClock, FALSE ); text += " - " + TimeString::longDateString( ev.endDate() ); } else { text += "<b>" + tr("Time") + "</b>: "; text += TimeString::timeString( ev.start(), whichClock, FALSE ); text += "<b>" + tr(" - ") + "</b>"; text += TimeString::timeString( ev.end(), whichClock, FALSE ); } } DateBookDayWidget::~DateBookDayWidget() { } void DateBookDayWidget::paintEvent( QPaintEvent *e ) { QPainter p( this ); if (dateBook->getSelectedWidget() == this) { p.setBrush( QColor( 155, 240, 230 ) ); // selected item } else { if (dateBook->date() == QDate::currentDate()) { QTime curTime = QTime::currentTime(); if (ev.end() < curTime) { p.setBrush( QColor( 180, 180, 180 ) ); // grey, inactive } else { //change color in dependence of the time till the event starts int duration = curTime.secsTo(ev.start()); if (duration < 0) duration = 0; int colChange = duration*160/86400; //86400: secs per day, 160: max color shift p.setBrush( QColor( 200-colChange, 200-colChange, 255 ) ); //blue } } else { p.setBrush( QColor( 220, 220, 220 ) ); //light grey, inactive (not current date) //perhaps make a distinction between future/past dates } } p.setPen( QColor(100, 100, 100) ); p.drawRect(rect()); // p.drawRect(0,0, 5, height()); int y = 0; int d = 0; if ( ev.event().hasAlarm() ) { - p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) ); - y = 20; + p.drawPixmap( width() - AppLnk::smallIconSize(), 0, + Opie::Core::OResource::loadPixmap( "bell", Opie::Core::OResource::SmallIcon ) ); + y = AppLnk::smallIconSize() + 2; d = 20; } if ( ev.event().hasRepeat() ) { - p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) ); + p.drawPixmap( width() - AppLnk::smallIconSize(), y, + Opie::Core::OResource::loadPixmap( "repeat", Opie::Core::OResource::SmallIcon ) ); d = 20; - y += 20; + y += AppLnk::smallIconSize() + 2; } QSimpleRichText rt( text, font() ); rt.setWidth( geom.width() - d - 6 ); rt.draw( &p, 7, 0, e->region(), colorGroup() ); } /* * we need to find the real start date for a uid * we need to check from one day to another... */ QDate DateBookDay::findRealStart( int uid, const QDate& isIncluded , DateBookDB* db) { QDate dt( isIncluded ); QDate fnd = dt; bool doAgain = true; do{ dt = dt.addDays( -1 ); QValueList<EffectiveEvent> events = db->getEffectiveEvents( dt, dt ); for (QValueList<EffectiveEvent>::Iterator it = events.begin(); it != events.end(); ++it ) { EffectiveEvent ev = (*it); if ( uid == ev.event().uid() && ev.start() != QTime(0, 0, 0 ) ) return ev.date(); } }while (doAgain ); return fnd; } void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) { DateBookDayWidget *item; item = dateBook->getSelectedWidget(); if (item) item->update(); dateBook->setSelectedWidget(this); update(); dateBook->repaint(); Event eve = ev.event(); QPopupMenu m; m.insertItem( tr( "Edit" ), 1 ); m.insertItem( tr( "Duplicate" ), 4 ); m.insertItem( tr( "Delete" ), 2 ); if(Ir::supported()) m.insertItem( tr( "Beam" ), 3 ); if(Ir::supported() && ev.event().doRepeat() ) m.insertItem( tr( "Beam this occurence"), 5 ); int r = m.exec( e->globalPos() ); if ( r == 1 ) { emit editMe( eve ); } else if ( r == 2 ) { emit deleteMe( eve ); } else if ( r == 3 ) { emit beamMe( eve ); } else if ( r == 4 ) { emit duplicateMe( eve ); } else if ( r == 5 ) { // create an Event and beam it... /* * Start with the easy stuff. If start and end date is the same we can just use * the values of effective events * If it is a multi day event we need to find the real start and end date... */ if ( ev.event().start().date() == ev.event().end().date() ) { Event event( ev.event() ); QDateTime dt( ev.date(), ev.start() ); event.setStart( dt ); dt.setTime( ev.end() ); event.setEnd( dt ); emit beamMe( event ); }else { /* * at least the the Times are right now */ QDateTime start( ev.event().start() ); QDateTime end ( ev.event().end () ); /* * ok we know the start date or we need to find it */ if ( ev.start() != QTime( 0, 0, 0 ) ) { start.setDate( ev.date() ); }else { QDate dt = DateBookDay::findRealStart( ev.event().uid(), ev.date(), dateBook->db ); start.setDate( dt ); } /* * ok we know now the end date... * else * get to know the offset btw the real start and real end * and then add it to the new start date... */ if ( ev.end() != QTime(23, 59, 59 ) ) { end.setDate( ev.date() ); }else{ int days = ev.event().start().date().daysTo( ev.event().end().date() ); end.setDate( start.date().addDays( days ) ); } Event event( ev.event() ); event.setStart( start ); event.setEnd ( end ); emit beamMe( event ); } } } void DateBookDayWidget::setGeometry( const QRect &r ) { geom = r; setFixedSize( r.width()+1, r.height()+1 ); dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); show(); } //--------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------- DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db ) : QWidget( db->dayView()->viewport() ), dateBook( db ) { setBackgroundMode( PaletteBase ); } DateBookDayTimeMarker::~DateBookDayTimeMarker() { } void DateBookDayTimeMarker::paintEvent( QPaintEvent */*e*/ ) { QPainter p( this ); p.setBrush( QColor( 255, 0, 0 ) ); QPen pen; pen.setStyle(NoPen); p.setPen( pen ); p.drawRect(rect()); } void DateBookDayTimeMarker::setTime( const QTime &t ) { int y = t.hour()*60+t.minute(); int rh = dateBook->dayView()->rowHeight(0); y = y*rh/60; geom.setX( 0 ); int x = dateBook->dayView()->columnWidth(0)-1; geom.setWidth( x ); geom.setY( y ); geom.setHeight( 1 ); setGeometry( geom ); time = t; } void DateBookDayTimeMarker::setGeometry( const QRect &r ) { geom = r; setFixedSize( r.width()+1, r.height()+1 ); dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); show(); } diff --git a/core/pim/datebook/datebookday.h b/core/pim/datebook/datebookday.h index 3b75eba..82021af 100644 --- a/core/pim/datebook/datebookday.h +++ b/core/pim/datebook/datebookday.h @@ -1,240 +1,251 @@ -/********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. -** -** This file is part of 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. -** -**********************************************************************/ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + #ifndef DATEBOOKDAY_H #define DATEBOOKDAY_H #include <qpe/event.h> #include <qdatetime.h> #include <qtable.h> #include <qvbox.h> #include <qlist.h> #include "datebook.h" #include "datebooktypes.h" #include <qlineedit.h> class DateBookDayHeader; class DateBookDB; class DateBookDBHoliday; class DatebookdayAllday; class QDateTime; class QMouseEvent; class QPaintEvent; class QResizeEvent; class DateBookDayViewQuickLineEdit : public QLineEdit { Q_OBJECT public: DateBookDayViewQuickLineEdit(const QDateTime &start, const QDateTime &end,QWidget * parent, const char *name=0); protected: Event quickEvent; int active; void focusOutEvent( QFocusEvent *e ); protected slots: void slotReturnPressed(void); void finallyCallClose(); signals: void insertEvent(const Event &e); }; class DateBookDayView : public QTable { Q_OBJECT public: DateBookDayView( bool hourClock, QWidget *parent, const char *name ); bool whichClock() const; void setRowStyle( int style ); public slots: void moveUp(); void moveDown(); void slotDateChanged( int year, int month, int day ); signals: void sigColWidthChanged(); void sigCapturedKey( const QString &txt ); protected slots: void slotChangeClock( bool ); protected: virtual void paintCell( QPainter *p, int row, int col, const QRect &cr, bool selected ); virtual void paintFocus( QPainter *p, const QRect &cr ); virtual void resizeEvent( QResizeEvent *e ); void keyPressEvent( QKeyEvent *e ); void contentsMouseReleaseEvent( QMouseEvent *e ); void initHeader(); private: bool ampm; QDate currDate; DateBookDayViewQuickLineEdit *quickLineEdit; }; class DateBookDay; class DateBookDayWidget : public QWidget { Q_OBJECT public: DateBookDayWidget( const EffectiveEvent &e, DateBookDay *db ); ~DateBookDayWidget(); const QRect &geometry() { return geom; } void setGeometry( const QRect &r ); const EffectiveEvent &event() const { return ev; } signals: void deleteMe( const Event &e ); void duplicateMe( const Event &e ); void editMe( const Event &e ); void beamMe( const Event &e ); protected: void paintEvent( QPaintEvent *e ); void mousePressEvent( QMouseEvent *e ); private: /** * Sets the text for an all day Event * All day events have no time associated */ void setAllDayText( QString& text ); /** * Sets the EventText * it got a start and an end Time */ void setEventText( QString& text ); EffectiveEvent ev; DateBookDay *dateBook; QString text; QRect geom; }; //Marker for current time in the dayview class DateBookDayTimeMarker : public QWidget { Q_OBJECT public: DateBookDayTimeMarker( DateBookDay *db ); ~DateBookDayTimeMarker(); const QRect &geometry() { return geom; } void setGeometry( const QRect &r ); void setTime( const QTime &t ); signals: protected: void paintEvent( QPaintEvent *e ); private: QRect geom; QTime time; DateBookDay *dateBook; }; //reimplemented the compareItems function so that it sorts DayWidgets by geometry heights class WidgetListClass : public QList<DateBookDayWidget> { private: int compareItems( QCollection::Item s1, QCollection::Item s2 ) { //hmm, don't punish me for that ;) if (reinterpret_cast<DateBookDayWidget*>(s1)->geometry().height() > reinterpret_cast<DateBookDayWidget*>(s2)->geometry().height()) { return -1; } else { return 1; } } }; class DateBookDay : public QVBox { Q_OBJECT friend class DateBookDayWidget; // for beam this occurence and access to DateBookDB public: DateBookDay( bool ampm, bool startOnMonday, DateBookDBHoliday *newDb,DateBookHoliday*newHdb, QWidget *parent, const char *name ); void selectedDates( QDateTime &start, QDateTime &end ); QDate date() const; DateBookDayView *dayView() const { return view; } void setStartViewTime( int startHere ); int startViewTime() const; void setSelectedWidget( DateBookDayWidget * ); DateBookDayWidget * getSelectedWidget( void ); void setJumpToCurTime( bool bJump ); void setRowStyle( int style ); static QDate findRealStart( int uid, const QDate& isIncluded, DateBookDB* ); public slots: void setDate( int y, int m, int d ); void setDate( QDate ); void redraw(); void slotWeekChanged( bool bStartOnMonday ); void updateView(); //updates TimeMarker and DayWidget-colors signals: void removeEvent( const Event& ); void editEvent( const Event& ); void duplicateEvent( const Event& ); void beamEvent( const Event& ); void newEvent(); void sigNewEvent( const QString & ); protected slots: void keyPressEvent(QKeyEvent *); private slots: void dateChanged( int y, int m, int d ); void slotColWidthChanged() { relayoutPage(); }; private: void getEvents(); void relayoutPage( bool fromResize = false ); DateBookDayWidget *intersects( const DateBookDayWidget *item, const QRect &geom ); QDate currDate; DateBookDayView *view; DateBookDayHeader *header; DatebookdayAllday *m_allDays; DateBookDBHoliday *db; WidgetListClass widgetList; //reimplemented QList for sorting widgets by height int startTime; bool jumpToCurTime; //should we jump to current time in dayview? int rowStyle; DateBookDayWidget *selectedWidget; //actual selected widget (obviously) DateBookDayTimeMarker *timeMarker; //marker for current time DateBookHoliday*_holiday_db; }; #endif diff --git a/core/pim/datebook/datebookdayallday.cpp b/core/pim/datebook/datebookdayallday.cpp index 27fce44..3807542 100644 --- a/core/pim/datebook/datebookdayallday.cpp +++ b/core/pim/datebook/datebookdayallday.cpp @@ -1,269 +1,292 @@ -/**************************************************************************** -** GPL by Rajko Albrecht -** -** -** -** -** -****************************************************************************/ +/* + This file is part of the Opie Project + + Copyright (C) Rajko Albrecht <> + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + #include "datebookdayallday.h" #include <qlayout.h> #include <qpe/ir.h> #include <qpopupmenu.h> #include <qtimer.h> #include "datebookday.h" /* * Constructs a DatebookdayAllday which is a child of 'parent', with the * name 'name' and widget flags set to 'f' */ DatebookdayAllday::DatebookdayAllday(DateBookDB* db, QWidget* parent, const char* name, WFlags ) : QScrollView( parent, name ),item_count(0),dateBook(db) { if ( !name ) setName( "DatebookdayAllday" ); setMinimumSize( QSize( 0, 0 ) ); setMaximumHeight(3* (QFontMetrics(font()).height()+4) ); m_MainFrame = new QFrame(viewport()); m_MainFrame->setFrameStyle(QFrame::NoFrame|QFrame::Plain); setFrameStyle(QFrame::NoFrame|QFrame::Plain); //setResizePolicy( QScrollView::Default ); setResizePolicy(QScrollView::AutoOneFit); setHScrollBarMode( AlwaysOff ); addChild(m_MainFrame); datebookdayalldayLayout = new QVBoxLayout( m_MainFrame ); datebookdayalldayLayout->setSpacing( 0 ); datebookdayalldayLayout->setMargin( 0 ); lblDesc = new DatebookEventDesc(parent->parentWidget(),""); lblDesc->setBackgroundColor(Qt::yellow); lblDesc->hide(); subWidgets.setAutoDelete(true); } /* * Destroys the object and frees any allocated resources */ DatebookdayAllday::~DatebookdayAllday() { // no need to delete child widgets, Qt does it all for us } DatebookAlldayDisp* DatebookdayAllday::addEvent(const EffectiveEvent&ev) { DatebookAlldayDisp * lb; lb = new DatebookAlldayDisp(dateBook,ev,m_MainFrame,NULL); lb->show(); datebookdayalldayLayout->addWidget(lb); subWidgets.append(lb); connect(lb,SIGNAL(displayMe(const Event&)),lblDesc,SLOT(disp_event(const Event&))); ++item_count; return lb; } DatebookAlldayDisp* DatebookdayAllday::addHoliday(const QString&e) { DatebookAlldayDisp * lb; lb = new DatebookAlldayDisp(e,m_MainFrame,NULL); lb->show(); datebookdayalldayLayout->addWidget(lb); subWidgets.append(lb); connect(lb,SIGNAL(displayMe(const Event&)),lblDesc,SLOT(disp_event(const Event&))); ++item_count; return lb; } void DatebookdayAllday::removeAllEvents() { subWidgets.clear(); item_count = 0; } DatebookAlldayDisp::DatebookAlldayDisp(DateBookDB *db,const EffectiveEvent& ev, QWidget* parent,const char* name,WFlags f) : QLabel(parent,name,f),m_Ev(ev),dateBook(db) { QString strDesc = m_Ev.description(); strDesc = strDesc.replace(QRegExp("<"),"<"); setBackgroundColor(yellow); setText(strDesc); setFrameStyle(QFrame::Raised|QFrame::Panel); int s = QFontMetrics(font()).height()+4; setMaximumHeight( s ); setMinimumSize( QSize( 0, s ) ); m_holiday = false; } DatebookAlldayDisp::DatebookAlldayDisp(const QString&aholiday,QWidget* parent,const char* name, WFlags fl) : QLabel(parent,name,fl),m_Ev(),dateBook(0) { QString strDesc = aholiday; strDesc = strDesc.replace(QRegExp("<"),"<"); Event ev; ev.setDescription(strDesc); ev.setAllDay(true); m_Ev.setEvent(ev); setText(strDesc); setAlignment(AlignHCenter); setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum)); //setFrameStyle(QFrame::Raised|QFrame::Panel); //setBackgroundColor(yellow); int s = QFontMetrics(font()).height()+4; setMaximumHeight( s ); setMinimumSize( QSize( 0, s ) ); m_holiday = true; } DatebookAlldayDisp::~DatebookAlldayDisp() { } void DatebookAlldayDisp::beam_single_event() { if (m_holiday) return; // create an Event and beam it... /* * Start with the easy stuff. If start and end date is the same we can just use * the values of effective m_Events * If it is a multi day m_Event we need to find the real start and end date... */ if ( m_Ev.event().start().date() == m_Ev.event().end().date() ) { Event m_Event( m_Ev.event() ); QDateTime dt( m_Ev.date(), m_Ev.start() ); m_Event.setStart( dt ); dt.setTime( m_Ev.end() ); m_Event.setEnd( dt ); emit beamMe( m_Event ); }else { /* * at least the the Times are right now */ QDateTime start( m_Ev.event().start() ); QDateTime end ( m_Ev.event().end () ); /* * ok we know the start date or we need to find it */ if ( m_Ev.start() != QTime( 0, 0, 0 ) ) { start.setDate( m_Ev.date() ); }else { QDate dt = DateBookDay::findRealStart( m_Ev.event().uid(), m_Ev.date(), dateBook ); start.setDate( dt ); } /* * ok we know now the end date... * else * get to know the offset btw the real start and real end * and then add it to the new start date... */ if ( m_Ev.end() != QTime(23, 59, 59 ) ) { end.setDate( m_Ev.date() ); }else{ int days = m_Ev.event().start().date().daysTo( m_Ev.event().end().date() ); end.setDate( start.date().addDays( days ) ); } Event m_Event( m_Ev.event() ); m_Event.setStart( start ); m_Event.setEnd ( end ); emit beamMe( m_Event ); } } void DatebookAlldayDisp::mousePressEvent(QMouseEvent*e) { Event ev = m_Ev.event(); QColor b = backgroundColor(); setBackgroundColor(green); update(); QPopupMenu m; if (ev.isValidUid()) { m.insertItem( DateBookDayWidget::tr( "Edit" ), 1 ); m.insertItem( DateBookDayWidget::tr( "Duplicate" ), 4 ); m.insertItem( DateBookDayWidget::tr( "Delete" ), 2 ); if(Ir::supported()) m.insertItem( DateBookDayWidget::tr( "Beam" ), 3 ); if(Ir::supported() && m_Ev.event().doRepeat() ) m.insertItem( DateBookDayWidget::tr( "Beam this occurence"), 5 ); } m.insertItem( tr( "Info"),6); int r = m.exec( e->globalPos() ); setBackgroundColor(b); update(); switch (r) { case 1: emit editMe( ev ); break; case 2: emit deleteMe( ev ); break; case 3: emit beamMe( ev ); break; case 4: emit duplicateMe( ev ); break; case 5: beam_single_event(); break; case 6: emit displayMe( ev ); break; default: break; } } DatebookEventDesc::DatebookEventDesc(QWidget*parent,const char*name) :QLabel(parent,name) { m_Timer=new QTimer(this); connect(m_Timer,SIGNAL(timeout()),this,SLOT(hide())); setFrameStyle(QFrame::Sunken|QFrame::Panel); setTextFormat(RichText); } DatebookEventDesc::~DatebookEventDesc() { } void DatebookEventDesc::mousePressEvent(QMouseEvent*) { hide(); if (m_Timer->isActive()) m_Timer->stop(); } void DatebookEventDesc::disp_event(const Event&e) { if (m_Timer->isActive()) m_Timer->stop(); QString text; text = "<b><i>"+e.description()+"</i></b><br>"; if (e.notes().length()>0) { text+="<b>"+e.notes()+"</b><br>"; } if (e.location().length()>0) { text+="<i>"+e.location()+"</i><br>"; } text = text.replace(QRegExp("\n"),"<br>"); setText(text); QSize s = sizeHint(); s+=QSize(10,10); resize(s); move( QMAX(0,(parentWidget()->width()-width()) / 2), (parentWidget()->height()-height())/2 ); show(); m_Timer->start(2000,true); } diff --git a/core/pim/datebook/datebookdayallday.h b/core/pim/datebook/datebookdayallday.h index 4f5cffa..5395dcf 100644 --- a/core/pim/datebook/datebookdayallday.h +++ b/core/pim/datebook/datebookdayallday.h @@ -1,86 +1,117 @@ +/* + This file is part of the Opie Project + + Copyright (C) Rajko Albrecht <> + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + #ifndef DATEBOOKDAYALLDAYBASE_H #define DATEBOOKDAYALLDAYBASE_H #include <qvariant.h> #include <qframe.h> #include <qscrollview.h> #include <qlabel.h> #include <qlist.h> #include <qpe/event.h> class QVBoxLayout; class QHBoxLayout; class QGridLayout; class DatebookAlldayDisp; class DatebookEventDesc; class DateBookDB; class DatebookdayAllday : public QScrollView { Q_OBJECT public: DatebookdayAllday(DateBookDB* db, QWidget* parent = 0, const char* name = 0, WFlags fl = 0); ~DatebookdayAllday(); DatebookAlldayDisp* addEvent(const EffectiveEvent&e); DatebookAlldayDisp* addHoliday(const QString&e); const unsigned int items()const{return item_count;} public slots: void removeAllEvents(); protected: QFrame * m_MainFrame; QVBoxLayout* datebookdayalldayLayout; DatebookEventDesc * lblDesc; unsigned int item_count; QList<DatebookAlldayDisp> subWidgets; DateBookDB *dateBook; }; class DatebookAlldayDisp : public QLabel { Q_OBJECT public: DatebookAlldayDisp(DateBookDB* db,const EffectiveEvent& e, QWidget* parent=0,const char* name = 0, WFlags fl=0); DatebookAlldayDisp(const QString&aholiday, QWidget* parent=0,const char* name = 0, WFlags fl=0); virtual ~DatebookAlldayDisp(); signals: void deleteMe( const Event &e ); void duplicateMe( const Event &e ); void editMe( const Event &e ); void beamMe( const Event &e ); void displayMe(const Event &e); public slots: protected: EffectiveEvent m_Ev; DateBookDB* dateBook; void mousePressEvent( QMouseEvent *e ); void beam_single_event(); bool m_holiday:1; }; class DatebookEventDesc: public QLabel { Q_OBJECT public: DatebookEventDesc(QWidget* Parent=0,const char* name = 0); virtual ~DatebookEventDesc(); public slots: void disp_event(const Event&e); protected: void mousePressEvent(QMouseEvent*e); QTimer* m_Timer; }; #endif // DATEBOOKDAYALLDAYBASE_H diff --git a/core/pim/datebook/datebookdayheaderimpl.cpp b/core/pim/datebook/datebookdayheaderimpl.cpp index 51b78ca..0df1bfe 100644 --- a/core/pim/datebook/datebookdayheaderimpl.cpp +++ b/core/pim/datebook/datebookdayheaderimpl.cpp @@ -1,200 +1,212 @@ -/********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. -** -** This file is part of 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. -** -**********************************************************************/ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + #include "datebookdayheaderimpl.h" +#include <opie2/oresource.h> + #include <qpe/datebookmonth.h> -#include <qpe/resource.h> #include <qbuttongroup.h> #include <qtoolbutton.h> /* * Constructs a DateBookDayHeader which is a child of 'parent', with the * name 'name' and widget flags set to 'f' * * The dialog will by default be modeless, unless you set 'modal' to * TRUE to construct a modal dialog. */ DateBookDayHeader::DateBookDayHeader( bool useMonday, QWidget* parent, const char* name ) : DateBookDayHeaderBase( parent, name ), bUseMonday( useMonday ) { connect(date,SIGNAL(pressed()),this,SLOT(pickDate())); setupNames(); - forward->setPixmap( Resource::loadPixmap( "forward" ) ); - back->setPixmap( Resource::loadPixmap( "back" ) ); - forwardweek->setPixmap( Resource::loadPixmap( "fastforward" ) ); - backweek->setPixmap( Resource::loadPixmap( "fastback" ) ); + forward->setPixmap( Opie::Core::OResource::loadPixmap( "forward" ) ); + back->setPixmap( Opie::Core::OResource::loadPixmap( "back" ) ); + forwardweek->setPixmap( Opie::Core::OResource::loadPixmap( "fastforward" ) ); + backweek->setPixmap( Opie::Core::OResource::loadPixmap( "fastback" ) ); setBackgroundMode( PaletteButton ); grpDays->setBackgroundMode( PaletteButton ); } /* * Destroys the object and frees any allocated resources */ DateBookDayHeader::~DateBookDayHeader() { // no need to delete child widgets, Qt does it all for us } void DateBookDayHeader::setStartOfWeek( bool onMonday ) { bUseMonday = onMonday; setupNames(); setDate( currDate.year(), currDate.month(), currDate.day() ); } void DateBookDayHeader::setupNames() { if ( bUseMonday ) { cmdDay1->setText( DateBookDayHeaderBase::tr("Monday").left(1) ); cmdDay2->setText( DateBookDayHeaderBase::tr("Tuesday").left(1) ); cmdDay3->setText( DateBookDayHeaderBase::tr("Wednesday").left(1) ); cmdDay4->setText( DateBookDayHeaderBase::tr("Thursday").left(1) ); cmdDay5->setText( DateBookDayHeaderBase::tr("Friday").left(1) ); cmdDay6->setText( DateBookDayHeaderBase::tr("Saturday").left(1) ); cmdDay7->setText( DateBookDayHeaderBase::tr("Sunday").left(1) ); } else { cmdDay1->setText( DateBookDayHeaderBase::tr("Sunday").left(1) ); cmdDay2->setText( DateBookDayHeaderBase::tr("Monday").left(1) ); cmdDay3->setText( DateBookDayHeaderBase::tr("Tuesday").left(1) ); cmdDay4->setText( DateBookDayHeaderBase::tr("Wednesday").left(1) ); cmdDay5->setText( DateBookDayHeaderBase::tr("Thursday").left(1) ); cmdDay6->setText( DateBookDayHeaderBase::tr("Friday").left(1) ); cmdDay7->setText( DateBookDayHeaderBase::tr("Saturday").left(1) ); } } void DateBookDayHeader::pickDate() { static QPopupMenu *m1 = 0; static DateBookMonth *picker = 0; if ( !m1 ) { m1 = new QPopupMenu( this ); picker = new DateBookMonth( m1, 0, TRUE ); m1->insertItem( picker ); connect( picker, SIGNAL( dateClicked(int,int,int) ), this, SLOT( setDate(int,int,int) ) ); connect( m1, SIGNAL( aboutToHide() ), this, SLOT( gotHide() ) ); } picker->setDate( currDate.year(), currDate.month(), currDate.day() ); m1->popup(mapToGlobal(date->pos()+QPoint(0,date->height()))); picker->setFocus(); } void DateBookDayHeader::gotHide() { // we have to redo the button... date->setDown( false ); } /* * public slot */ void DateBookDayHeader::goBack() { currDate = currDate.addDays( -1 ); setDate( currDate.year(), currDate.month(), currDate.day() ); } /* * public slot */ void DateBookDayHeader::goForward() { currDate = currDate.addDays( 1 ); setDate( currDate.year(), currDate.month(), currDate.day() ); } /* * public slot */ void DateBookDayHeader::goBackWeek() { currDate = currDate.addDays( -7 ); setDate( currDate.year(), currDate.month(), currDate.day() ); } /* * public slot */ void DateBookDayHeader::goForwardWeek() { currDate = currDate.addDays( 7 ); setDate( currDate.year(), currDate.month(), currDate.day() ); } /* * public slot */ void DateBookDayHeader::setDate( int y, int m, int d ) { currDate.setYMD( y, m, d ); date->setText( TimeString::shortDate( currDate ) ); int iDayOfWeek = currDate.dayOfWeek(); // cleverly adjust the day depending on how we start the week if ( bUseMonday ) iDayOfWeek--; else { if ( iDayOfWeek == 7 ) // Sunday iDayOfWeek = 0; } grpDays->setButton( iDayOfWeek ); emit dateChanged( y, m, d ); } /* * public slot */ void DateBookDayHeader::setDay( int day ) { int realDay; int dayOfWeek = currDate.dayOfWeek(); // a little adjustment is needed... if ( bUseMonday ) realDay = day + 1 ; else if ( !bUseMonday && day == 0 ) // sunday realDay = 7; else realDay = day; // special cases first... if ( realDay == 7 && !bUseMonday ) { while ( currDate.dayOfWeek() != realDay ) currDate = currDate.addDays( -1 ); } else if ( !bUseMonday && dayOfWeek == 7 && dayOfWeek > realDay ) { while ( currDate.dayOfWeek() != realDay ) currDate = currDate.addDays( 1 ); } else if ( dayOfWeek < realDay ) { while ( currDate.dayOfWeek() < realDay ) currDate = currDate.addDays( 1 ); } else if ( dayOfWeek > realDay ) { while ( currDate.dayOfWeek() > realDay ) currDate = currDate.addDays( -1 ); } // update the date... setDate( currDate.year(), currDate.month(), currDate.day() ); } diff --git a/core/pim/datebook/datebookdayheaderimpl.h b/core/pim/datebook/datebookdayheaderimpl.h index a07bd67..ea9f917 100644 --- a/core/pim/datebook/datebookdayheaderimpl.h +++ b/core/pim/datebook/datebookdayheaderimpl.h @@ -1,59 +1,70 @@ -/********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. -** -** This file is part of 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. -** -**********************************************************************/ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + #ifndef DATEBOOKDAYHEADER_H #define DATEBOOKDAYHEADER_H #include "datebookdayheader.h" #include <qdatetime.h> class DateBookDayHeader : public DateBookDayHeaderBase { Q_OBJECT public: DateBookDayHeader( bool bUseMonday, QWidget* parent = 0, const char* name = 0 ); ~DateBookDayHeader(); void setStartOfWeek( bool onMonday ); public slots: void goBack(); void goForward(); void goBackWeek(); void goForwardWeek(); void setDate( int, int, int ); void setDay( int ); void gotHide(); signals: void dateChanged( int y, int m, int d ); private slots: void pickDate(); private: QDate currDate; bool bUseMonday; void setupNames(); }; #endif // DATEBOOKDAYHEADER_H diff --git a/core/pim/datebook/datebooksettings.cpp b/core/pim/datebook/datebooksettings.cpp index 561dc38..c72cd59 100644 --- a/core/pim/datebook/datebooksettings.cpp +++ b/core/pim/datebook/datebooksettings.cpp @@ -1,219 +1,229 @@ -/********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. -** -** This file is part of 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. -** -**********************************************************************/ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ #include "datebooksettings.h" #include <opie2/opluginloader.h> #include <opie2/odebug.h> #include <opie2/oholidaypluginif.h> #include <opie2/oholidayplugin.h> #include <opie2/oholidayplugincfgwidget.h> #include <qpe/qpeapplication.h> #include <qspinbox.h> #include <qcheckbox.h> #include <qlistview.h> #include <qheader.h> #include <qtabwidget.h> #include <qlayout.h> DateBookSettings::DateBookSettings( bool whichClock, QWidget *parent, const char *name, bool modal, WFlags fl ) : DateBookSettingsBase( parent, name, modal, fl ), ampm( whichClock ) { init(); QObject::connect( qApp, SIGNAL( clockChanged(bool) ), this, SLOT( slotChangeClock(bool) ) ); QArray<int> categories; comboCategory->setCategories( categories, "Calendar", tr("Calendar") ); m_loader = 0; m_manager = 0; m_PluginListView->header()->hide(); m_PluginListView->setSorting(-1); } DateBookSettings::~DateBookSettings() { } void DateBookSettings::setStartTime( int newStartViewTime ) { if ( ampm ) { if ( newStartViewTime >= 12 ) { newStartViewTime %= 12; if ( newStartViewTime == 0 ) newStartViewTime = 12; spinStart->setSuffix( tr(":00 PM") ); } else if ( newStartViewTime == 0 ) { newStartViewTime = 12; spinStart->setSuffix( tr(":00 AM") ); } oldtime = newStartViewTime; } spinStart->setValue( newStartViewTime ); } int DateBookSettings::startTime() const { int returnMe = spinStart->value(); if ( ampm ) { if ( returnMe != 12 && spinStart->suffix().contains(tr("PM"), FALSE) ) returnMe += 12; else if (returnMe == 12 && spinStart->suffix().contains(tr("AM"), TRUE)) returnMe = 0; } return returnMe; } void DateBookSettings::setPluginList(Opie::Core::OPluginManager*aManager,Opie::Core::OPluginLoader*aLoader) { m_manager = aManager; m_loader = aLoader; if (!aManager||!aLoader) return; Opie::Core::OPluginItem::List inLst = m_loader->allAvailable(true); QCheckListItem *pitem = 0; for ( Opie::Core::OPluginItem::List::Iterator it = inLst.begin(); it != inLst.end(); ++it ) { pitem = new QCheckListItem(m_PluginListView,(*it).name(),QCheckListItem::CheckBox); pitem->setOn( (*it).isEnabled() ); Opie::Datebook::HolidayPluginIf*hif = m_loader->load<Opie::Datebook::HolidayPluginIf>(*it,IID_HOLIDAY_PLUGIN); if (!hif) continue; Opie::Datebook::HolidayPlugin*pl = hif->plugin(); if (!pl) continue; Opie::Datebook::HolidayPluginConfigWidget*cfg = pl->configWidget(); if (!cfg) continue; QWidget * dtab = new QWidget(TabWidget,pl->description()); QVBoxLayout*dlayout = new QVBoxLayout(dtab); dlayout->setMargin(2); dlayout->setSpacing(2); cfg->reparent(dtab,0,QPoint(0,0)); dlayout->addWidget(cfg); TabWidget->insertTab(dtab,pl->description()); m_cfgWidgets.append(cfg); } } void DateBookSettings::savePlugins() { QValueList<Opie::Datebook::HolidayPluginConfigWidget*>::Iterator it; for (it=m_cfgWidgets.begin();it!=m_cfgWidgets.end();++it) { (*it)->saveConfig(); } } void DateBookSettings::pluginItemClicked(QListViewItem *aItem) { if (!aItem||!m_manager||!m_loader) return; QCheckListItem*pitem = ((QCheckListItem*)aItem); Opie::Core::OPluginItem::List lst = m_loader->allAvailable( true ); for ( Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it != lst.end(); ++it ) { if ( QString::compare( (*it).name() , pitem->text(0) ) == 0 ) { m_manager->setEnabled((*it),pitem->isOn()); break; } } } void DateBookSettings::setAlarmPreset( bool bAlarm, int presetTime ) { chkAlarmPreset->setChecked( bAlarm ); if ( presetTime >=5 ) spinPreset->setValue( presetTime ); } bool DateBookSettings::alarmPreset() const { return chkAlarmPreset->isChecked(); } int DateBookSettings::presetTime() const { return spinPreset->value(); } void DateBookSettings::slot12Hour( int i ) { if ( ampm ) { if ( spinStart->suffix().contains( tr("AM"), FALSE ) ) { if ( oldtime == 12 && i == 11 || oldtime == 11 && i == 12 ) spinStart->setSuffix( tr(":00 PM") ); } else { if ( oldtime == 12 && i == 11 || oldtime == 11 && i == 12 ) spinStart->setSuffix( tr(":00 AM") ); } oldtime = i; } } void DateBookSettings::init() { if ( ampm ) { spinStart->setMinValue( 1 ); spinStart->setMaxValue( 12 ); spinStart->setValue( 12 ); spinStart->setSuffix( tr(":00 AM") ); oldtime = 12; } else { spinStart->setMinValue( 0 ); spinStart->setMaxValue( 23 ); spinStart->setSuffix( tr(":00") ); } } void DateBookSettings::slotChangeClock( bool whichClock ) { int saveMe; saveMe = spinStart->value(); if ( ampm && spinStart->suffix().contains( tr("AM"), FALSE ) ) { if ( saveMe == 12 ) saveMe = 0; } else if ( ampm && spinStart->suffix().contains( tr("PM"), FALSE ) ) { if ( saveMe != 12 ) saveMe += 12; } ampm = whichClock; init(); setStartTime( saveMe ); } void DateBookSettings::setJumpToCurTime( bool bJump ) { chkJumpToCurTime->setChecked( bJump ); } bool DateBookSettings::jumpToCurTime() const { return chkJumpToCurTime->isChecked(); } void DateBookSettings::setRowStyle( int style ) { comboRowStyle->setCurrentItem( style ); } int DateBookSettings::rowStyle() const { return comboRowStyle->currentItem(); } diff --git a/core/pim/datebook/datebooksettings.h b/core/pim/datebook/datebooksettings.h index 912088f..d3aca85 100644 --- a/core/pim/datebook/datebooksettings.h +++ b/core/pim/datebook/datebooksettings.h @@ -1,77 +1,87 @@ -/********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. -** -** This file is part of 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. -** -**********************************************************************/ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ #ifndef DATEBOOKSETTINGS_H #define DATEBOOKSETTINGS_H #include "datebooksettingsbase.h" #include <qpe/categoryselect.h> #include <qvaluelist.h> namespace Opie { namespace Core { class OPluginManager; class OGenericPluginLoader; class OPluginLoader; } namespace Ui { class OPluginConfigWidget; } namespace Datebook { class HolidayPluginConfigWidget; } } class DateBookSettings : public DateBookSettingsBase { Q_OBJECT public: DateBookSettings( bool whichClock, QWidget *parent = 0, const char *name = 0, bool modal = TRUE, WFlags = 0 ); ~DateBookSettings(); void setStartTime( int newStartViewTime ); int startTime() const; void setAlarmPreset( bool bAlarm, int presetTime ); bool alarmPreset() const; int presetTime() const; void setAlarmType( int alarmType ); int alarmType() const; void setJumpToCurTime( bool bJump ); bool jumpToCurTime() const; void setRowStyle( int style ); int rowStyle() const; void setPluginList(Opie::Core::OPluginManager*,Opie::Core::OPluginLoader*); void savePlugins(); private slots: void slot12Hour( int ); void slotChangeClock( bool ); protected slots: virtual void pluginItemClicked(QListViewItem *); protected: void init(); bool ampm; int oldtime; Opie::Core::OPluginManager*m_manager; Opie::Core::OPluginLoader*m_loader; QValueList<Opie::Datebook::HolidayPluginConfigWidget*> m_cfgWidgets; }; #endif diff --git a/core/pim/datebook/datebooktypes.h b/core/pim/datebook/datebooktypes.h index 9453be8..bc94561 100644 --- a/core/pim/datebook/datebooktypes.h +++ b/core/pim/datebook/datebooktypes.h @@ -1,73 +1,103 @@ +/*
+ This file is part of the Opie Project
+
+ Copyright (C) Opie Team <opie-devel@handhelds.org>
+ =.
+ .=l.
+ .>+-=
+ _;:, .> :=|. This program is free software; you can
+.> <`_, > . <= redistribute it and/or modify it under
+:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
+.="- .-=="i, .._ License as published by the Free Software
+ - . .-<_> .<> Foundation; either version 2 of the License,
+ ._= =} : or (at your option) any later version.
+ .%`+i> _;_.
+ .i_,=:_. -<s. This program is distributed in the hope that
+ + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
+ : .. .:, . . . without even the implied warranty of
+ =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
+ _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
+..}^=.= = ; Library General Public License for more
+++= -. .` .: details.
+: = ...= . :.=-
+ -. .:....=;==+<; You should have received a copy of the GNU
+ -_. . . )=. = Library General Public License along with
+ -- :-=` this library; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
#ifndef _DATEBOOK_TYPES_H
#define _DATEBOOK_TYPES_H
#include <qpe/datebookdb.h>
#include <qvaluelist.h>
#include <qstringlist.h>
namespace Opie {
namespace Datebook {
class HolidayPlugin;
class HolidayPluginIf;
}
namespace Core {
class OPluginLoader;
class OPluginManager;
}
}
class QLibrary;
enum { DAY=1,WEEK,WEEKLST,MONTH }; // defaultView values
enum { NONE=0,NORMAL,EXTENDED }; // WeekLstView's modes.
class DateBookDBHack : virtual public DateBookDB {
public:
virtual ~DateBookDBHack(){}
Event eventByUID(int id);
};
class DateBookHoliday
{
public:
DateBookHoliday();
virtual ~DateBookHoliday();
QStringList holidaylist(const QDate&);
QStringList holidaylist(unsigned year, unsigned month, unsigned day);
virtual QValueList<EffectiveEvent> getEffectiveEvents(const QDate &from,const QDate &to );
virtual QValueList<EffectiveEvent> getEffectiveEvents(const QDateTime &start);
void reloadPlugins();
Opie::Core::OPluginLoader*pluginLoader(){return m_pluginLoader;}
Opie::Core::OPluginManager*pluginManager(){return m_pluginManager;}
protected:
void init();
void deinit();
struct HPlugin {
Opie::Datebook::HolidayPlugin*_plugin;
//QLibrary*_lib;
//Opie::Datebook::HolidayPluginIf*_if;
};
QValueList<HPlugin*>_pluginlist;
Opie::Core::OPluginLoader*m_pluginLoader;
Opie::Core::OPluginManager*m_pluginManager;
};
class DateBookDBHoliday:virtual public DateBookDBHack {
public:
DateBookDBHoliday():DateBookDBHack(){db_holiday=0;}
virtual ~DateBookDBHoliday(){}
virtual QValueList<EffectiveEvent> getEffectiveEvents(const QDate &from,const QDate &to );
virtual QValueList<EffectiveEvent> getEffectiveEvents(const QDateTime &start);
virtual QValueList<EffectiveEvent> getEffectiveEventsNoHoliday(const QDate &from,const QDate &to );
virtual QValueList<EffectiveEvent> getEffectiveEventsNoHoliday(const QDateTime &start);
DateBookHoliday*db_holiday;
};
#endif
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp index a509d89..ce0b10b 100644 --- a/core/pim/datebook/datebookweek.cpp +++ b/core/pim/datebook/datebookweek.cpp @@ -1,676 +1,687 @@ -/********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. -** -** This file is part of 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. -** -**********************************************************************/ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + #include "datebookweek.h" #include "datebookweekheaderimpl.h" #include "datebooktypes.h" #include <qpe/datebookdb.h> #include <qpe/qpeapplication.h> #include <qpe/calendar.h> #include <qheader.h> #include <qlabel.h> #include <qlayout.h> #include <qtimer.h> //----------------------------------------------------------------- DateBookWeekItem::DateBookWeekItem( const EffectiveEvent e ) : ev( e ) { // with the current implementation change the color for all day events if ( ev.event().type() == Event::AllDay && !ev.event().hasAlarm() ) { c = Qt::green; } else { c = ev.event().hasAlarm() ? Qt::red : Qt::blue; } } void DateBookWeekItem::setGeometry( int x, int y, int w, int h ) { r.setRect( x, y, w, h ); } //------------------=--------------------------------------------- DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday, QWidget *parent, const char *name ) : QScrollView( parent, name ), ampm( ap ), bOnMonday( startOnMonday ), showingEvent( false ) { items.setAutoDelete( true ); viewport()->setBackgroundMode( PaletteBase ); header = new QHeader( this ); header->addLabel( "" ); header->setMovingEnabled( false ); header->setResizeEnabled( false ); header->setClickEnabled( false, 0 ); initNames(); connect( header, SIGNAL(clicked(int)), this, SIGNAL(showDay(int)) ); QObject::connect(qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotChangeClock(bool))); QFontMetrics fm( font() ); rowHeight = fm.height()+2; resizeContents( width(), 24*rowHeight ); } void DateBookWeekView::initNames() { static bool bFirst = true; if ( bFirst ) { if ( bOnMonday ) { for ( int i = 1; i<=7; i++ ) { header->addLabel( Calendar::nameOfDay( i ) ); } } else { header->addLabel( Calendar::nameOfDay( 7 ) ); for ( int i = 1; i<7; i++ ) { header->addLabel( Calendar::nameOfDay( i ) ); } } bFirst = false; } else { // we are change things... if ( bOnMonday ) { for ( int i = 1; i<=7; i++ ) { header->setLabel( i, Calendar::nameOfDay( i ) ); } } else { header->setLabel( 1, Calendar::nameOfDay( 7 ) ); for ( int i = 1; i<7; i++ ) { header->setLabel( i+1, Calendar::nameOfDay( i ) ); } } } } void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev ) { items.clear(); QValueListIterator<EffectiveEvent> it; for ( it = ev.begin(); it != ev.end(); ++it ) { DateBookWeekItem *i = new DateBookWeekItem( *it ); if(!((i->event().end().hour()==0) && (i->event().end().minute()==0) && (i->event().startDate()!=i->event().date()))) { // Skip events ending at 00:00 starting at another day. positionItem( i ); items.append( i ); } } viewport()->update(); } void DateBookWeekView::moveToHour( int h ) { int offset = h*rowHeight; setContentsPos( 0, offset ); } void DateBookWeekView::keyPressEvent( QKeyEvent *e ) { e->ignore(); } void DateBookWeekView::slotChangeClock( bool c ) { ampm = c; viewport()->update(); } static inline int db_round30min( int m ) { if ( m < 15 ) m = 0; else if ( m < 45 ) m = 1; else m = 2; return m; } void DateBookWeekView::alterDay( int day ) { if ( !bOnMonday ) { day--; } emit showDay( day ); } void DateBookWeekView::positionItem( DateBookWeekItem *i ) { const int Width = 8; const EffectiveEvent ev = i->event(); // 30 minute intervals int y = ev.start().hour() * 2; y += db_round30min( ev.start().minute() ); int y2 = ev.end().hour() * 2; y2 += db_round30min( ev.end().minute() ); if ( y > 47 ) y = 47; if ( y2 > 48 ) y2 = 48; y = (y * rowHeight) / 2; y2 = (y2 * rowHeight) / 2; int h; if ( ev.event().type() == Event::AllDay ) { h = (48 * rowHeight) / 2; y = 0; } else { h=y2-y; if ( h < (1*rowHeight)/2 ) h = (1*rowHeight)/2; } int dow = ev.date().dayOfWeek(); if ( !bOnMonday ) { if ( dow == 7 ) dow = 1; else dow++; } int x = header->sectionPos( dow ) - 1; int xlim = header->sectionPos( dow ) + header->sectionSize( dow ); DateBookWeekItem *isect = 0; do { i->setGeometry( x, y, Width, h ); isect = intersects( i ); x += Width - 1; } while ( isect && x < xlim ); } DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item ) { QRect geom = item->geometry(); // We allow the edges to overlap geom.moveBy( 1, 1 ); geom.setSize( geom.size()-QSize(2,2) ); QListIterator<DateBookWeekItem> it(items); for ( ; it.current(); ++it ) { DateBookWeekItem *i = it.current(); if ( i != item ) { if ( i->geometry().intersects( geom ) ) { return i; } } } return 0; } void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e ) { QListIterator<DateBookWeekItem> it(items); for ( ; it.current(); ++it ) { DateBookWeekItem *i = it.current(); if ( i->geometry().contains( e->pos() ) ) { showingEvent = true; emit signalShowEvent( i->event() ); break; } } } void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e ) { if ( showingEvent ) { showingEvent = false; emit signalHideEvent(); } else { int d = header->sectionAt( e->pos().x() ); if ( d > 0 ) { // if ( !bOnMonday ) // d--; emit showDay( d ); } } } void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) { QRect ur( cx, cy, cw, ch ); p->setPen( lightGray ); for ( int i = 1; i <= 7; i++ ) p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch ); p->setPen( black ); for ( int t = 0; t < 24; t++ ) { int y = t*rowHeight; if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) { QString s; if ( ampm ) { if ( t == 0 ) s = QString::number( 12 ); else if ( t == 12 ) s = QString::number(12) + tr( "p" ); else if ( t > 12 ) { if ( t - 12 < 10 ) s = " "; else s = ""; s += QString::number( t - 12 ) + tr("p"); } else { if ( 12 - t < 3 ) s = ""; else s = " "; s += QString::number( t ); } } else { s = QString::number( t ); if ( s.length() == 1 ) s.prepend( "0" ); } p->drawText( 1, y+p->fontMetrics().ascent()+1, s ); } } QListIterator<DateBookWeekItem> it(items); for ( ; it.current(); ++it ) { DateBookWeekItem *i = it.current(); if ( i->geometry().intersects( ur ) ) { p->setBrush( i->color() ); p->drawRect( i->geometry() ); } } } void DateBookWeekView::resizeEvent( QResizeEvent *e ) { const int hourWidth = 20; QScrollView::resizeEvent( e ); //HEAD /* int avail = visibleWidth(); header->setGeometry( leftMargin()+frameWidth()+frameRect().left() , frameWidth(), visibleWidth(), header->sizeHint().height() ); setMargins( 0, header->sizeHint().height(), 0, 0 ); */ //BRANCH_1_0 int avail = width()-qApp->style().scrollBarExtent().width()-1; header->setGeometry( 0, 0, avail, header->sizeHint().height() ); setMargins( 0, header->height(), 0, 0 ); header->resizeSection( 0, hourWidth ); int sw = (avail - hourWidth) / 7; for ( int i = 1; i < 7; i++ ) header->resizeSection( i, sw ); header->resizeSection( 7, avail - hourWidth - sw*6 ); } void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) { bOnMonday = bStartOnMonday; initNames(); } //------------------------------------------------------------------- DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDBHoliday *newDB, QWidget *parent, const char *name ) : QWidget( parent, name ), db( newDB ), startTime( 0 ), ampm( ap ), bStartOnMonday( startOnMonday ) { setFocusPolicy(StrongFocus); QVBoxLayout *vb = new QVBoxLayout( this ); header = new DateBookWeekHeader( bStartOnMonday, this ); view = new DateBookWeekView( ampm, startOnMonday, this ); vb->addWidget( header ); vb->addWidget( view ); lblDesc = new QLabel( this, "event label" ); lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); lblDesc->setBackgroundColor( yellow ); lblDesc->hide(); tHide = new QTimer( this ); connect( view, SIGNAL( showDay(int) ), this, SLOT( showDay(int) ) ); connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) ); connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) ); connect( header, SIGNAL( dateChanged(QDate&) ), this, SLOT( dateChanged(QDate&) ) ); connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) ); connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool))); setDate(QDate::currentDate()); } void DateBookWeek::keyPressEvent(QKeyEvent *e) { switch(e->key()) { case Key_Up: view->scrollBy(0, -20); break; case Key_Down: view->scrollBy(0, 20); break; case Key_Left: setDate(date().addDays(-7)); break; case Key_Right: setDate(date().addDays(7)); break; default: e->ignore(); } } void DateBookWeek::showDay( int day ) { QDate d=bdate; // Calculate offset to first day of week. int dayoffset=d.dayOfWeek() % 7; if(bStartOnMonday) dayoffset--; day--; d=d.addDays(day-dayoffset); emit showDate( d.year(), d.month(), d.day() ); } void DateBookWeek::setDate( int y, int m, int d ) { setDate(QDate(y, m, d)); } void DateBookWeek::setDate(QDate newdate) { bdate=newdate; dow = newdate.dayOfWeek(); header->setDate( newdate ); } void DateBookWeek::dateChanged( QDate &newdate ) { bdate=newdate; getEvents(); } QDate DateBookWeek::date() const { return bdate; } void DateBookWeek::getEvents() { QDate startWeek = weekDate(); QDate endWeek = startWeek.addDays( 6 ); QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek); view->showEvents( eventList ); view->moveToHour( startTime ); } void DateBookWeek::generateAllDayTooltext( QString& text ) { text += "<b>" + tr("This is an all day event.") + "</b><br>"; } void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) { str += "<b>" + QObject::tr("Start") + "</b>: "; str += TimeString::timeString( ev.event().start().time(), ampm, FALSE ); if( ev.startDate()!=ev.endDate() ) { str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>"; } str += "<br>"; str += "<b>" + QObject::tr("End") + "</b>: "; str += TimeString::timeString( ev.event().end().time(), ampm, FALSE ); if( ev.startDate()!=ev.endDate() ) { str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>"; } } void DateBookWeek::slotShowEvent( const EffectiveEvent &ev ) { if ( tHide->isActive() ) tHide->stop(); // why would someone use "<"? Oh well, fix it up... // I wonder what other things may be messed up... QString strDesc = ev.description(); int where = strDesc.find( "<" ); while ( where != -1 ) { strDesc.remove( where, 1 ); strDesc.insert( where, "<" ); where = strDesc.find( "<", where ); } QString strCat; // ### FIX later... // QString strCat = ev.category(); // where = strCat.find( "<" ); // while ( where != -1 ) { // strCat.remove( where, 1 ); // strCat.insert( where, "<" ); // where = strCat.find( "<", where ); // } QString strLocation = ev.location(); while ( where != -1 ) { strLocation.remove( where, 1 ); strLocation.insert( where, "<" ); where = strLocation.find( "<", where ); } QString strNote = ev.notes(); where = strNote.find( "<" ); while ( where != -1 ) { strNote.remove( where, 1 ); strNote.insert( where, "<" ); where = strNote.find( "<", where ); } QString str = "<b>" + strDesc + "</b><br>" + strLocation + "<br>" + "<i>" + strCat + "</i>" + "<br>" + TimeString::longDateString( ev.date() ) + "<br>"; if (ev.event().type() == Event::Normal ) generateNormalTooltext( str, ev ); else generateAllDayTooltext( str ); str += "<br><br>" + strNote; lblDesc->setText( str ); lblDesc->resize( lblDesc->sizeHint() ); // move the label so it is "centerd" horizontally... lblDesc->move( QMAX(0,(width() - lblDesc->width()) / 2), 0 ); lblDesc->show(); } void DateBookWeek::slotHideEvent() { tHide->start( 2000, true ); } void DateBookWeek::setStartViewTime( int startHere ) { startTime = startHere; view->moveToHour( startTime ); } int DateBookWeek::startViewTime() const { return startTime; } void DateBookWeek::redraw() { getEvents(); } void DateBookWeek::slotYearChanged( int y ) { int totWeek; QDate d( y, 12, 31 ); int throwAway; calcWeek( d, totWeek, throwAway, bStartOnMonday ); while ( totWeek == 1 ) { d = d.addDays( -1 ); calcWeek( d, totWeek, throwAway, bStartOnMonday ); } } void DateBookWeek::slotWeekChanged( bool onMonday ) { bStartOnMonday = onMonday; view->setStartOfWeek( bStartOnMonday ); header->setStartOfWeek( bStartOnMonday ); redraw(); } void DateBookWeek::slotClockChanged( bool ap ) { ampm = ap; } // return the date at the beginning of the week... QDate DateBookWeek::weekDate() const { QDate d=bdate; // Calculate offset to first day of week. int dayoffset=d.dayOfWeek(); if(bStartOnMonday) dayoffset--; else if( dayoffset == 7 ) dayoffset = 0; return d.addDays(-dayoffset); } // this used to only be needed by datebook.cpp, but now we need it inside // week view since // we need to be able to figure out our total number of weeks on the fly... // this is probably the best place to put it.. // For Weeks that start on Monday... (EASY!) // At the moment we will use ISO 8601 method for computing // the week. Granted, other countries use other methods, // bet we aren't doing any Locale stuff at the moment. So, // this should pass. This Algorithim is public domain and // available at: // http://personal.ecu.edu/mccartyr/ISOwdALG.txt // the week number is return, and the year number is returned in year // for Instance 2001/12/31 is actually the first week in 2002. // There is a more mathematical definition, but I will implement it when // we are pass our deadline. // For Weeks that start on Sunday... (ahh... home rolled) // okay, if Jan 1 is on Friday or Saturday, // it will go to the pervious // week... bool calcWeek( const QDate &d, int &week, int &year, bool startOnMonday ) { int weekNumber; int yearNumber; // remove a pesky warning, (Optimizations on g++) weekNumber = -1; int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek(); int dayOfWeek = d.dayOfWeek(); if ( !d.isValid() ) return false; if ( startOnMonday ) { // find the Jan1Weekday; if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) { yearNumber = d.year() - 1; if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) ) weekNumber = 53; else weekNumber = 52; } else yearNumber = d.year(); if ( yearNumber == d.year() ) { int totalDays = 365; if ( QDate::leapYear(yearNumber) ) totalDays++; if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) ) || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) { yearNumber++; weekNumber = 1; } } if ( yearNumber == d.year() ) { int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 ); weekNumber = j / 7; if ( jan1WeekDay > 4 ) weekNumber--; } } else { // it's better to keep these cases separate... if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4 && jan1WeekDay != 7 ) { yearNumber = d.year() - 1; if ( jan1WeekDay == 6 || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) { weekNumber = 53; }else weekNumber = 52; } else yearNumber = d.year(); if ( yearNumber == d.year() ) { int totalDays = 365; if ( QDate::leapYear( yearNumber ) ) totalDays++; if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) { yearNumber++; weekNumber = 1; } } if ( yearNumber == d.year() ) { int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 ); weekNumber = j / 7; if ( jan1WeekDay > 4 ) { weekNumber--; } } } year = yearNumber; week = weekNumber; return true; } diff --git a/core/pim/datebook/datebookweek.h b/core/pim/datebook/datebookweek.h index ddf54ed..2d25f10 100644 --- a/core/pim/datebook/datebookweek.h +++ b/core/pim/datebook/datebookweek.h @@ -1,167 +1,178 @@ -/********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. -** -** This file is part of 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. -** -**********************************************************************/ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + #ifndef DATEBOOKWEEK #define DATEBOOKWEEK #include <qpe/event.h> #include <qlist.h> #include <qscrollview.h> #include <qstring.h> #include <qvaluelist.h> class DateBookDB; class DateBookDBHoliday; class DateBookWeekHeader; class QDate; class QLabel; class QResizeEvent; class QSpinBox; class QTimer; class QHeader; class DateBookWeekItem { public: DateBookWeekItem( const EffectiveEvent e ); void setGeometry( int x, int y, int w, int h ); QRect geometry() const { return r; } const QColor &color() const { return c; } const EffectiveEvent event() const { return ev; } private: const EffectiveEvent ev; QRect r; QColor c; }; class DateBookWeekView : public QScrollView { Q_OBJECT public: DateBookWeekView( bool ampm, bool weekOnMonday, QWidget *parent = 0, const char *name = 0 ); bool whichClock() const; void showEvents( QValueList<EffectiveEvent> &ev ); void moveToHour( int h ); void setStartOfWeek( bool bOnMonday ); signals: void showDay( int d ); void signalShowEvent( const EffectiveEvent & ); void signalHideEvent(); protected slots: void keyPressEvent(QKeyEvent *); private slots: void slotChangeClock( bool ); void alterDay( int ); private: void positionItem( DateBookWeekItem *i ); DateBookWeekItem *intersects( const DateBookWeekItem * ); void drawContents( QPainter *p, int cx, int cy, int cw, int ch ); void contentsMousePressEvent( QMouseEvent * ); void contentsMouseReleaseEvent( QMouseEvent * ); void resizeEvent( QResizeEvent * ); void initNames(); private: bool ampm; bool bOnMonday; QHeader *header; QList<DateBookWeekItem> items; int rowHeight; bool showingEvent; }; class DateBookWeek : public QWidget { Q_OBJECT public: DateBookWeek( bool ampm, bool weekOnMonday, DateBookDBHoliday *newDB, QWidget *parent = 0, const char *name = 0 ); void setDate( int y, int m, int d ); void setDate( QDate d ); QDate date() const; DateBookWeekView *weekView() const { return view; } void setStartViewTime( int startHere ); int startViewTime() const; int week() const { return _week; }; QDate weekDate() const; public slots: void redraw(); void slotWeekChanged( bool bStartOnMonday ); void slotClockChanged( bool a ); signals: void showDate( int y, int m, int d ); protected slots: void keyPressEvent(QKeyEvent *); private slots: void showDay( int day ); void dateChanged( QDate &newdate ); void slotShowEvent( const EffectiveEvent & ); void slotHideEvent(); void slotYearChanged( int ); private: void getEvents(); /** * Wow that's a hell lot of code duplication * in datebook. I vote for a common base class * but never the less. This add a note * that the Event is an all day event * */ void generateAllDayTooltext( QString& text ); /** * This will add the times to the text * It will be shown in the Tooltip bubble */ void generateNormalTooltext( QString& text, const EffectiveEvent &ev); int year; int _week; int dow; QDate bdate; DateBookWeekHeader *header; DateBookWeekView *view; DateBookDBHoliday *db; QLabel *lblDesc; QTimer *tHide; int startTime; bool ampm; bool bStartOnMonday; }; bool calcWeek( const QDate &d, int &week, int &year, bool startOnMonday = false ); #endif diff --git a/core/pim/datebook/datebookweekheaderimpl.cpp b/core/pim/datebook/datebookweekheaderimpl.cpp index 7462de7..9922778 100644 --- a/core/pim/datebook/datebookweekheaderimpl.cpp +++ b/core/pim/datebook/datebookweekheaderimpl.cpp @@ -1,123 +1,134 @@ -/********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. -** -** This file is part of 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. -** -**********************************************************************/ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + #include "datebookweekheaderimpl.h" #include "datebookweek.h" #include <opie2/odebug.h> +#include <opie2/oresource.h> -#include <qpe/resource.h> #include <qpe/datebookmonth.h> #include <qtoolbutton.h> /* * Constructs a DateBookWeekHeader which is a child of 'parent', with the * name 'name' and widget flags set to 'f' */ DateBookWeekHeader::DateBookWeekHeader( bool startOnMonday, QWidget* parent, const char* name, WFlags fl ) : DateBookWeekHeaderBase( parent, name, fl ), bStartOnMonday( startOnMonday ) { setBackgroundMode( PaletteButton ); labelDate->setBackgroundMode( PaletteButton ); - backmonth->setPixmap( Resource::loadPixmap("fastback") ); - backweek->setPixmap( Resource::loadPixmap("back") ); - forwardweek->setPixmap( Resource::loadPixmap("forward") ); - forwardmonth->setPixmap( Resource::loadPixmap("fastforward") ); + backmonth->setPixmap( Opie::Core::OResource::loadPixmap( "fastback", Opie::Core::OResource::SmallIcon ) ); + backweek->setPixmap( Opie::Core::OResource::loadPixmap( "back", Opie::Core::OResource::SmallIcon ) ); + forwardweek->setPixmap( Opie::Core::OResource::loadPixmap( "forward", Opie::Core::OResource::SmallIcon ) ); + forwardmonth->setPixmap( Opie::Core::OResource::loadPixmap( "fastforward", Opie::Core::OResource::SmallIcon ) ); } /* * Destroys the object and frees any allocated resources */ DateBookWeekHeader::~DateBookWeekHeader() { // no need to delete child widgets, Qt does it all for us } void DateBookWeekHeader::pickDate() { static QPopupMenu *m1 = 0; static DateBookMonth *picker = 0; if ( !m1 ) { m1 = new QPopupMenu( this ); picker = new DateBookMonth( m1, 0, TRUE ); m1->insertItem( picker ); connect( picker, SIGNAL( dateClicked(int,int,int) ), this, SLOT( setDate(int,int,int) ) ); // connect( m1, SIGNAL( aboutToHide() ), this, SLOT( gotHide() ) ); } picker->setDate( date.year(), date.month(), date.day() ); m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height()))); picker->setFocus(); } void DateBookWeekHeader::nextMonth() { owarn << "nextMonth()" << oendl; setDate(date.addDays(28)); } void DateBookWeekHeader::prevMonth() { owarn << "prevMonth()" << oendl; setDate(date.addDays(-28)); } void DateBookWeekHeader::nextWeek() { owarn << "nextWeek()" << oendl; setDate(date.addDays(7)); } void DateBookWeekHeader::prevWeek() { owarn << "prevWeek()" << oendl; setDate(date.addDays(-7)); } void DateBookWeekHeader::setDate( int y, int m, int d ) { setDate(QDate(y,m,d)); } void DateBookWeekHeader::setDate(const QDate &d) { int year,week,dayofweek; date=d; dayofweek=d.dayOfWeek(); if(bStartOnMonday) dayofweek--; else if( dayofweek == 7 ) // we already have the right day -7 would lead to the current week.. dayofweek = 0; date=date.addDays(-dayofweek); calcWeek(date,week,year,bStartOnMonday); QDate start=date; QDate stop=start.addDays(6); labelDate->setText( QString::number(start.day()) + "." + Calendar::nameOfMonth( start.month()) + "-" + QString::number(stop.day()) + "." + Calendar::nameOfMonth( stop.month()) +" ("+ tr("w")+":"+QString::number( week ) +")"); date = d; // bugfix: 0001126 - date has to be the selected date, not monday! emit dateChanged(date); } void DateBookWeekHeader::setStartOfWeek( bool onMonday ) { bStartOnMonday = onMonday; setDate( date ); } diff --git a/core/pim/datebook/datebookweekheaderimpl.h b/core/pim/datebook/datebookweekheaderimpl.h index d8dce90..0b388b4 100644 --- a/core/pim/datebook/datebookweekheaderimpl.h +++ b/core/pim/datebook/datebookweekheaderimpl.h @@ -1,57 +1,68 @@ -/********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. -** -** This file is part of 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. -** -**********************************************************************/ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + #ifndef DATEBOOKDAYHEADER_H #define DATEBOOKDAYHEADER_H #include <qdatetime.h> #include "datebookweekheader.h" class DateBookWeekHeader : public DateBookWeekHeaderBase { Q_OBJECT public: DateBookWeekHeader( bool startOnMonday, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~DateBookWeekHeader(); void setDate(const QDate &d); void setStartOfWeek( bool onMonday ); signals: void dateChanged( QDate &date ); public slots: void pickDate(); void nextMonth(); void prevMonth(); void nextWeek(); void prevWeek(); void setDate( int y, int m, int d); protected slots: void keyPressEvent(QKeyEvent *e) { e->ignore(); } private: QDate date; bool bStartOnMonday; }; #endif // DATEBOOKDAYHEADER_H diff --git a/core/pim/datebook/dateentryimpl.cpp b/core/pim/datebook/dateentryimpl.cpp index 297da94..adfa33f 100644 --- a/core/pim/datebook/dateentryimpl.cpp +++ b/core/pim/datebook/dateentryimpl.cpp @@ -1,562 +1,572 @@ -/********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. -** -** This file is part of 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. -** -**********************************************************************/ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ #include "namespace_hack.h" #include "dateentryimpl.h" #include "repeatentry.h" #include <opie2/odebug.h> #include <opie2/otimepicker.h> #include <qpe/qpeapplication.h> #include <qpe/categoryselect.h> #include <qpe/datebookmonth.h> #include <qpe/tzselect.h> #include <qlineedit.h> #include <qspinbox.h> #include "onoteedit.h" #include <stdlib.h> #include <stdio.h> /* * Constructs a DateEntry which is a child of 'parent', with the * name 'name' and widget flags set to 'f' * * The dialog will by default be modeless, unless you set 'modal' to * TRUE to construct a modal dialog. */ DateEntry::DateEntry( bool startOnMonday, const QDateTime &start, const QDateTime &end, bool whichClock, QWidget* parent, const char* name ) : DateEntryBase( parent, name ), ampm( whichClock ), startWeekOnMonday( startOnMonday ), m_showStart(true) { init(); setDates(start,end); setFocusProxy(comboDescription); } bool DateEntry::eventFilter(QObject *obj, QEvent *ev ) { if( ev->type() == QEvent::FocusIn ){ if( obj == comboStart ){ timePickerStart->setHour(startTime.hour()); timePickerStart->setMinute(startTime.minute()); TimePickerLabel->setText( tr("Start Time" ) ); m_showStart= true; }else if( obj == comboEnd ){ timePickerStart->setHour(endTime.hour()); timePickerStart->setMinute(endTime.minute()); TimePickerLabel->setText( tr("End Time") ); m_showStart = false; } } else if( ev->type() == QEvent::FocusOut ){ // if( obj == comboEnd ){ // QString s; // s.sprintf("%.2d:%.2d",endTime.hour(), endTime.minute()); // comboEnd->setText(s); // } // else if( obj == comboStart ){ // QString s; // s.sprintf("%.2d:%.2d",startTime.hour(), startTime.minute()); // comboStart->setText(s); // } } return false; } static void addOrPick( QComboBox* combo, const QString& t ) { // Pick an item if one excists for (int i=0; i<combo->count(); i++) { if ( combo->text(i) == t ) { combo->setCurrentItem(i); return; } } // Else add one combo->insertItem(t); combo->setCurrentItem(combo->count()-1); } DateEntry::DateEntry( bool startOnMonday, const Event &event, bool whichClock, QWidget* parent, const char* name ) : DateEntryBase( parent, name ), ampm( whichClock ), startWeekOnMonday( startOnMonday ), m_showStart(true) { init(); setDates(event.start(),event.end()); comboCategory->setCategories( event.categories(), "Calendar", tr("Calendar") ); if(!event.description().isEmpty()) addOrPick( comboDescription, event.description() ); if(!event.location().isEmpty()) addOrPick( comboLocation, event.location() ); checkAlarm->setChecked( event.hasAlarm() ); checkAllDay->setChecked( event.type() == Event::AllDay ); if(!event.notes().isEmpty()) noteStr=event.notes(); else noteStr=""; spinAlarm->setValue(event.alarmTime()); if ( event.alarmSound() != Event::Silent ) comboSound->setCurrentItem( 1 ); if ( event.hasRepeat() ) { rp = event.repeatPattern(); cmdRepeat->setText( tr("Repeat...") ); } setRepeatLabel(); } void DateEntry::setDates( const QDateTime& s, const QDateTime& e ) { startDate = s.date(); endDate = e.date(); startTime = s.time(); endTime = e.time(); startDateChanged( s.date().year(), s.date().month(), s.date().day() ); endDateChanged( e.date().year(), e.date().month(), e.date().day() ); updateTimeEdit(true,true); } void DateEntry::updateTimeEdit(bool s, bool e) { // Comboboxes QString strStart, strEnd; int shour, ehour; if ( ampm ) { shour = startTime.hour(); ehour = endTime.hour(); if ( shour >= 12 ) { if ( shour > 12 ) shour -= 12; strStart.sprintf( "%d:%02d PM", shour, startTime.minute() ); } else { if ( shour == 0 ) shour = 12; strStart.sprintf( "%d:%02d AM", shour, startTime.minute() ); } if ( ehour == 24 && endTime.minute() == 0 ) { strEnd = "11:59 PM"; // or "midnight" } else if ( ehour >= 12 ) { if ( ehour > 12 ) ehour -= 12; strEnd.sprintf( "%d:%02d PM", ehour, endTime.minute() ); } else { if ( ehour == 0 ) ehour = 12; strEnd.sprintf( "%d:%02d AM", ehour, endTime.minute() ); } } else { strStart.sprintf( "%02d:%02d", startTime.hour(), startTime.minute() ); strEnd.sprintf( "%02d:%02d", endTime.hour(), endTime.minute() ); } if (s) comboStart->setText(strStart); if (e) comboEnd->setText(strEnd); } void DateEntry::init() { comboDescription->setInsertionPolicy(QComboBox::AtCurrent); comboLocation->setInsertionPolicy(QComboBox::AtCurrent); initCombos(); QPopupMenu *m1 = new QPopupMenu( this ); startPicker = new DateBookMonth( m1, 0, TRUE ); m1->insertItem( startPicker ); buttonStart->setPopup( m1 ); connect( startPicker, SIGNAL( dateClicked(int,int,int) ), this, SLOT( startDateChanged(int,int,int) ) ); //Let start button change both start and end dates connect( startPicker, SIGNAL( dateClicked(int,int,int) ), this, SLOT( endDateChanged(int,int,int) ) ); connect( qApp, SIGNAL( clockChanged(bool) ), this, SLOT( slotChangeClock(bool) ) ); connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotChangeStartOfWeek(bool)) ); connect( editNote, SIGNAL(clicked()), this, SLOT(slotEditNote()) ); QPopupMenu *m2 = new QPopupMenu( this ); endPicker = new DateBookMonth( m2, 0, TRUE ); m2->insertItem( endPicker ); buttonEnd->setPopup( m2 ); connect( endPicker, SIGNAL( dateClicked(int,int,int) ), this, SLOT( endDateChanged(int,int,int) ) ); connect(timePickerStart, SIGNAL( timeChanged(const QTime&) ), this, SLOT( startTimePicked(const QTime&) )); // install eventFilters comboEnd->installEventFilter( this ); comboStart->installEventFilter( this ); } /* * Destroys the object and frees any allocated resources */ DateEntry::~DateEntry() { // no need to delete child widgets, Qt does it all for us //cout << "Del: " << comboStart->currentText() << endl; } /* * public slot */ void DateEntry::slotEditNote() { QString s; s = "<B>"+ TimeString::longDateString( startDate ) + "</B>"; // s.sprintf("<B>%d/%d</B> ", startDate.day(), startDate.month()); NoteEntry noteDlg(s+comboDescription->currentText(), noteStr, this,0,TRUE); if ( QPEApplication::execDialog( ¬eDlg ) ) { noteStr=noteDlg.note->text(); } } void DateEntry::endDateChanged( int y, int m, int d ) { endDate.setYMD( y, m, d ); if ( endDate < startDate ) { endDate = startDate; } buttonEnd->setText( TimeString::shortDate( endDate ) ); endPicker->setDate( endDate.year(), endDate.month(), endDate.day() ); } static QTime parseTime( const QString& s, bool ampm ) { QTime tmpTime; QStringList l = QStringList::split( ':', s ); int hour = l[0].toInt(); if ( ampm ) { int i=0; while (i<int(l[1].length()) && l[1][i]>='0' && l[1][i]<='9') i++; QString digits = l[1].left(i); if ( l[1].contains( "PM", FALSE ) ) { if ( hour != 12 ) hour += 12; } else { if ( hour == 12 ) hour = 0; } l[1] = digits; } int minute = l[1].toInt(); if ( minute > 59 ) minute = 59; else if ( minute < 0 ) minute = 0; if ( hour > 23 ) { hour = 23; minute = 59; } else if ( hour < 0 ) hour = 0; tmpTime.setHMS( hour, minute, 0 ); return tmpTime; } /* * public slot */ void DateEntry::endTimeChanged( const QString &s ) { endTimeChanged( parseTime(s,ampm) ); } void DateEntry::endTimeChanged( const QTime &t ) { if ( endDate > startDate || t >= startTime ) { endTime = t; } else { endTime = startTime; //comboEnd->setCurrentItem( comboStart->currentItem() ); } timePickerStart->setHour(endTime.hour()); timePickerStart->setMinute(endTime.minute()); } /* * public slot */ void DateEntry::startDateChanged( int y, int m, int d ) { QDate prev = startDate; startDate.setYMD( y, m, d ); if ( rp.type == Event::Weekly && startDate.dayOfWeek() != prev.dayOfWeek() ) { // if we change the start of a weekly repeating event // set the repeating day appropriately char mask = 1 << (prev.dayOfWeek()-1); rp.days &= (~mask); rp.days |= 1 << (startDate.dayOfWeek()-1); } buttonStart->setText( TimeString::shortDate( startDate ) ); // our pickers must be reset... startPicker->setDate( y, m, d ); endPicker->setDate( y, m, d ); } /* * public slot */ void DateEntry::startTimeEdited( const QString &s ) { startTimeChanged(parseTime(s,ampm)); updateTimeEdit(false,true); timePickerStart->setHour(startTime.hour()); timePickerStart->setMinute(startTime.minute()); } void DateEntry::startTimeChanged( const QTime &t ) { int duration=startTime.secsTo(endTime); startTime = t; endTime=t.addSecs(duration); } void DateEntry::startTimePicked( const QTime &t ) { if(m_showStart ){ startTimeChanged(t); updateTimeEdit(true,true); }else{ endTimeChanged(t); updateTimeEdit(false, true ); } } /* * public slot */ void DateEntry::typeChanged( const QString &s ) { bool b = s != "All Day"; buttonStart->setEnabled( b ); comboStart->setEnabled( b ); comboEnd->setEnabled( b ); } void DateEntry::slotRepeat() { // Work around for compiler Bug.. RepeatEntry *e; // it is better in my opinion to just grab this from the mother, // since, this dialog doesn't need to keep track of it... if ( rp.type != Event::NoRepeat ) e = new RepeatEntry( startWeekOnMonday, rp, startDate, this); else e = new RepeatEntry( startWeekOnMonday, startDate, this ); if ( QPEApplication::execDialog( e ) ) { rp = e->repeatPattern(); setRepeatLabel(); } // deleting sounds like a nice idea... delete e; } void DateEntry::slotChangeStartOfWeek( bool onMonday ) { startWeekOnMonday = onMonday; } Event DateEntry::event() { Event ev; Event::SoundTypeChoice st; ev.setDescription( comboDescription->currentText() ); ev.setLocation( comboLocation->currentText() ); ev.setCategories( comboCategory->currentCategories() ); ev.setType( checkAllDay->isChecked() ? Event::AllDay : Event::Normal ); if ( startDate > endDate ) { QDate tmp = endDate; endDate = startDate; startDate = tmp; } // This is now done in the changed slots // startTime = parseTime( comboStart->text(), ampm ); //endTime = parseTime( comboEnd->text(), ampm ); if ( startTime > endTime && endDate == startDate ) { QTime tmp = endTime; endTime = startTime; startTime = tmp; } // don't set the time if theres no need too if ( ev.type() == Event::AllDay ) { startTime.setHMS( 0, 0, 0 ); endTime.setHMS( 23, 59, 59 ); } // adjust start and end times based on timezone QDateTime start( startDate, startTime ); QDateTime end( endDate, endTime ); time_t start_utc, end_utc; // odebug << "tz: " << timezone->currentZone() << oendl; // get real timezone QString realTZ; realTZ = QString::fromLocal8Bit( getenv("TZ") ); // set timezone if ( setenv( "TZ", timezone->currentZone(), true ) != 0 ) owarn << "There was a problem setting the timezone." << oendl; // convert to UTC based on selected TZ (calling tzset internally) start_utc = TimeConversion::toUTC( start ); end_utc = TimeConversion::toUTC( end ); // done playing around... put it all back unsetenv( "TZ" ); if ( !realTZ.isNull() ) if ( setenv( "TZ", realTZ, true ) != 0 ) owarn << "There was a problem setting the timezone." << oendl; // convert UTC to local time (calling tzset internally) ev.setStart( TimeConversion::fromUTC( start_utc ) ); ev.setEnd( TimeConversion::fromUTC( end_utc ) ); // we only have one type of sound at the moment... LOUD!!! if ( comboSound->currentItem() != 0 ) st = Event::Loud; else st = Event::Silent; ev.setAlarm( checkAlarm->isChecked(), spinAlarm->value(), st ); if ( rp.type != Event::NoRepeat ) ev.setRepeat( TRUE, rp ); ev.setNotes( noteStr ); //cout << "Start: " << comboStart->currentText() << endl; return ev; } void DateEntry::setRepeatLabel() { switch( rp.type ) { case Event::Daily: cmdRepeat->setText( tr("Daily...") ); break; case Event::Weekly: cmdRepeat->setText( tr("Weekly...") ); break; case Event::MonthlyDay: case Event::MonthlyDate: cmdRepeat->setText( tr("Monthly...") ); break; case Event::Yearly: cmdRepeat->setText( tr("Yearly...") ); break; default: cmdRepeat->setText( tr("No Repeat...") ); } } void DateEntry::setAlarmEnabled( bool alarmPreset, int presetTime, Event::SoundTypeChoice sound ) { checkAlarm->setChecked( alarmPreset ); spinAlarm->setValue( presetTime ); if ( sound != Event::Silent ) comboSound->setCurrentItem( 1 ); else comboSound->setCurrentItem( 0 ); } void DateEntry::initCombos() { /* comboStart->clear(); comboEnd->clear(); if ( ampm ) { for ( int i = 0; i < 24; i++ ) { if ( i == 0 ) { comboStart->insertItem( "12:00 AM" ); comboStart->insertItem( "12:30 AM" ); comboEnd->insertItem( "12:00 AM" ); comboEnd->insertItem( "12:30 AM" ); } else if ( i == 12 ) { comboStart->insertItem( "12:00 PM" ); comboStart->insertItem( "12:30 PM" ); comboEnd->insertItem( "12:00 PM" ); comboEnd->insertItem( "12:30 PM" ); } else if ( i > 12 ) { comboStart->insertItem( QString::number( i - 12 ) + ":00 PM" ); comboStart->insertItem( QString::number( i - 12 ) + ":30 PM" ); comboEnd->insertItem( QString::number( i - 12 ) + ":00 PM" ); comboEnd->insertItem( QString::number( i - 12 ) + ":30 PM" ); } else { comboStart->insertItem( QString::number( i) + ":00 AM" ); comboStart->insertItem( QString::number( i ) + ":30 AM" ); comboEnd->insertItem( QString::number( i ) + ":00 AM" ); comboEnd->insertItem( QString::number( i ) + ":30 AM" ); } } } else { for ( int i = 0; i < 24; i++ ) { if ( i < 10 ) { comboStart->insertItem( QString("0") + QString::number(i) + ":00" ); comboStart->insertItem( QString("0") + QString::number(i) + ":30" ); comboEnd->insertItem( QString("0") + QString::number(i) + ":00" ); comboEnd->insertItem( QString("0") + QString::number(i) + ":30" ); } else { comboStart->insertItem( QString::number(i) + ":00" ); comboStart->insertItem( QString::number(i) + ":30" ); comboEnd->insertItem( QString::number(i) + ":00" ); comboEnd->insertItem( QString::number(i) + ":30" ); } } } */ } void DateEntry::slotChangeClock( bool whichClock ) { ampm = whichClock; initCombos(); setDates( QDateTime( startDate, startTime ), QDateTime( endDate, endTime ) ); } diff --git a/core/pim/datebook/dateentryimpl.h b/core/pim/datebook/dateentryimpl.h index a3c4668..2d23ed1 100644 --- a/core/pim/datebook/dateentryimpl.h +++ b/core/pim/datebook/dateentryimpl.h @@ -1,79 +1,90 @@ -/********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. -** -** This file is part of 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. -** -**********************************************************************/ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + #ifndef DATEENTRY_H #define DATEENTRY_H #include "dateentry.h" #include "noteentryimpl.h" #include <qpe/event.h> #include <qdatetime.h> class DateBookMonth; class DateEntry : public DateEntryBase { Q_OBJECT public: DateEntry( bool startOnMonday, const QDateTime &start, const QDateTime &end, bool whichClock = FALSE, QWidget* parent = 0, const char* name = 0 ); DateEntry( bool startOnMonday, const Event &event, bool whichCLock = FALSE, QWidget* parent = 0, const char* name = 0 ); ~DateEntry(); Event event(); void setAlarmEnabled( bool alarmPreset, int presetTime, Event::SoundTypeChoice ); virtual bool eventFilter( QObject *, QEvent * ); public slots: void endDateChanged( int, int, int ); void endTimeChanged( const QString & ); void endTimeChanged( const QTime & ); void startDateChanged(int, int, int); void startTimeEdited( const QString & ); void startTimeChanged( const QTime & ); void startTimePicked( const QTime & ); void typeChanged( const QString & ); void slotRepeat(); void slotChangeClock( bool ); void slotChangeStartOfWeek( bool ); void slotEditNote(); private: void init(); void initCombos(); void setDates( const QDateTime& s, const QDateTime& e ); void setRepeatLabel(); void updateTimeEdit(bool,bool); DateBookMonth *startPicker, *endPicker; QDate startDate, endDate; QTime startTime, endTime; Event::RepeatPattern rp; bool ampm:1; bool startWeekOnMonday:1; bool m_showStart:1; QString noteStr; }; #endif // DATEENTRY_H diff --git a/core/pim/datebook/main.cpp b/core/pim/datebook/main.cpp index 3cb60af..e96e769 100644 --- a/core/pim/datebook/main.cpp +++ b/core/pim/datebook/main.cpp @@ -1,25 +1,35 @@ -/********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. -** -** This file is part of 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. -** -**********************************************************************/ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ #include "datebook.h" #include <opie2/oapplicationfactory.h> - + using namespace Opie::Core; OPIE_EXPORT_APP( OApplicationFactory<DateBook> ) diff --git a/core/pim/datebook/modules/weeklst/datebookweeklst.cpp b/core/pim/datebook/modules/weeklst/datebookweeklst.cpp index 6556373..b36bf6d 100644 --- a/core/pim/datebook/modules/weeklst/datebookweeklst.cpp +++ b/core/pim/datebook/modules/weeklst/datebookweeklst.cpp @@ -1,159 +1,158 @@ #include "namespace_hack.h" #include "datebookweeklst.h" #include "datebookweeklstheader.h" #include "datebookweeklstview.h" #include "datebookweeklstdblview.h" #include "datebook.h" #include <opie2/odebug.h> #include <qpe/datebookmonth.h> #include <qpe/config.h> -#include <qpe/resource.h> #include <qlayout.h> #include <qtoolbutton.h> using namespace Opie::Ui; DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDBHoliday *newDB, QWidget *parent, const char *name ) : QWidget( parent, name ), db( newDB ), startTime( 0 ), ampm( ap ), bStartOnMonday(onM) { setFocusPolicy(StrongFocus); dateset = false; layout = new QVBoxLayout( this ); layout->setMargin(0); header=new DateBookWeekLstHeader(onM, this); layout->addWidget( header ); connect(header, SIGNAL(dateChanged(QDate&)), this, SLOT(dateChanged(QDate&))); connect(header, SIGNAL(setDbl(bool)), this, SLOT(setDbl(bool))); scroll=new QScrollView(this); scroll->setResizePolicy(QScrollView::AutoOneFit); layout->addWidget(scroll); m_CurrentView=NULL; Config config("DateBook"); config.setGroup("Main"); dbl=config.readBoolEntry("weeklst_dbl", false); header->dbl->setOn(dbl); } DateBookWeekLst::~DateBookWeekLst(){ Config config("DateBook"); config.setGroup("Main"); config.writeEntry("weeklst_dbl", dbl); } void DateBookWeekLst::setDate(const QDate &d) { bdate=d; header->setDate(d); } void DateBookWeekLst::setDbl(bool on) { dbl=on; bool displayed = false; if (m_CurrentView) { displayed = m_CurrentView->toggleDoubleView(on); } if (!displayed||dbl) { getEvents(); } } void DateBookWeekLst::redraw() {getEvents();} QDate DateBookWeekLst::date() { return bdate; } // return the date at the beginning of the week... // copied from DateBookWeek QDate DateBookWeekLst::weekDate() const { QDate d=bdate; // Calculate offset to first day of week. int dayoffset=d.dayOfWeek(); if(bStartOnMonday) dayoffset--; else if( dayoffset == 7 ) dayoffset = 0; return d.addDays(-dayoffset); } void DateBookWeekLst::getEvents() { if (!dateset) return; QDate start = weekDate(); //date(); QDate stop = start.addDays(6); QDate start2; QValueList<EffectiveEvent> el = db->getEffectiveEvents(start, stop); QValueList<EffectiveEvent> el2; if (dbl) { start2 = start.addDays(7); stop = start2.addDays(6); el2 = db->getEffectiveEvents(start2, stop); } if (!m_CurrentView) { if (dbl) { m_CurrentView=new DateBookWeekLstDblView(el,el2,start,bStartOnMonday,scroll); } else { m_CurrentView=new DateBookWeekLstDblView(el,start,bStartOnMonday,scroll); } m_CurrentView->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); connect (m_CurrentView, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&))); connect (m_CurrentView, SIGNAL(duplicateEvent(const Event &)), this, SIGNAL(duplicateEvent(const Event &))); connect (m_CurrentView, SIGNAL(removeEvent(const Event &)), this, SIGNAL(removeEvent(const Event &))); connect (m_CurrentView, SIGNAL(beamEvent(const Event &)), this, SIGNAL(beamEvent(const Event &))); connect (m_CurrentView, SIGNAL(redraw()), this, SLOT(redraw())); connect (m_CurrentView, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); connect (m_CurrentView, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)), this, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&))); scroll->addChild(m_CurrentView); } else { if (dbl) { m_CurrentView->setEvents(el,el2,start,bStartOnMonday); } else { m_CurrentView->setEvents(el,start,bStartOnMonday); } } scroll->updateScrollBars(); } void DateBookWeekLst::dateChanged(QDate &newdate) { dateset = true; bdate=newdate; odebug << "Date changed " << oendl; getEvents(); } void DateBookWeekLst::keyPressEvent(QKeyEvent *e) { switch(e->key()) { case Key_Up: scroll->scrollBy(0, -20); break; case Key_Down: scroll->scrollBy(0, 20); break; case Key_Left: header->prevWeek(); break; case Key_Right: header->nextWeek(); break; default: e->ignore(); } } diff --git a/core/pim/datebook/modules/weeklst/datebookweeklstheader.cpp b/core/pim/datebook/modules/weeklst/datebookweeklstheader.cpp index 81e0c31..2da9c22 100644 --- a/core/pim/datebook/modules/weeklst/datebookweeklstheader.cpp +++ b/core/pim/datebook/modules/weeklst/datebookweeklstheader.cpp @@ -1,96 +1,97 @@ #include "datebookweeklstheader.h"
-#include <qpe/resource.h>
+#include <opie2/oresource.h>
+
#include <qpe/datebookmonth.h>
#include <qtoolbutton.h>
#include <qlayout.h>
/* implenented in datebookweek.cpp - HELL */
bool calcWeek(const QDate &d, int &week, int &year,bool startOnMonday = false);
DateBookWeekLstHeader::DateBookWeekLstHeader(bool onM, QWidget* parent, const char* name, WFlags fl)
: DateBookWeekLstHeaderBase(parent, name, fl)
{
setBackgroundMode( PaletteButton );
labelDate->setBackgroundMode( PaletteButton );
forwardweek->setBackgroundMode( PaletteButton );
- forwardweek->setPixmap( Resource::loadPixmap("forward") );
+ forwardweek->setPixmap( Opie::Core::OResource::loadPixmap( "forward", Opie::Core::OResource::SmallIcon ) );
forwardmonth->setBackgroundMode( PaletteButton );
- forwardmonth->setPixmap( Resource::loadPixmap("fastforward") );
+ forwardmonth->setPixmap( Opie::Core::OResource::loadPixmap( "fastforward", Opie::Core::OResource::SmallIcon ) );
backweek->setBackgroundMode( PaletteButton );
- backweek->setPixmap( Resource::loadPixmap("back") );
+ backweek->setPixmap( Opie::Core::OResource::loadPixmap( "back", Opie::Core::OResource::SmallIcon ) );
backmonth->setBackgroundMode( PaletteButton );
- backmonth->setPixmap( Resource::loadPixmap("fastback") );
+ backmonth->setPixmap( Opie::Core::OResource::loadPixmap( "fastback", Opie::Core::OResource::SmallIcon ) );
DateBookWeekLstHeaderBaseLayout->setSpacing(0);
DateBookWeekLstHeaderBaseLayout->setMargin(0);
//setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding));
setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
connect(backmonth, SIGNAL(clicked()), this, SLOT(prevMonth()));
connect(backweek, SIGNAL(clicked()), this, SLOT(prevWeek()));
connect(forwardweek, SIGNAL(clicked()), this, SLOT(nextWeek()));
connect(forwardmonth, SIGNAL(clicked()), this, SLOT(nextMonth()));
connect(labelDate, SIGNAL(clicked()), this, SLOT(pickDate()));
connect(dbl, SIGNAL(toggled(bool)), this, SIGNAL(setDbl(bool)));
bStartOnMonday=onM;
}
DateBookWeekLstHeader::~DateBookWeekLstHeader(){}
void DateBookWeekLstHeader::setDate(const QDate &d) {
int year,week,dayofweek;
date=d;
dayofweek=d.dayOfWeek();
if(bStartOnMonday)
dayofweek--;
else if( dayofweek == 7 )
/* we already have the right day -7 would lead to the same week */
dayofweek = 0;
date=date.addDays(-dayofweek);
calcWeek(date,week,year,bStartOnMonday);
QDate start=date;
QDate stop=start.addDays(6);
labelDate->setText( QString::number(start.day()) + "." +
Calendar::nameOfMonth( start.month() ) + "-" +
QString::number(stop.day()) + "." +
Calendar::nameOfMonth( stop.month()) +" ("+
tr("w")+":"+QString::number( week ) +")");
date = d; // bugfix: 0001126 - date has to be the selected date, not monday!
emit dateChanged(date);
}
void DateBookWeekLstHeader::pickDate() {
static QPopupMenu *m1 = 0;
static DateBookMonth *picker = 0;
if ( !m1 ) {
m1 = new QPopupMenu( this );
picker = new DateBookMonth( m1, 0, TRUE );
m1->insertItem( picker );
connect( picker, SIGNAL( dateClicked(int,int,int) ),this, SLOT( setDate(int,int,int) ) );
//connect( m1, SIGNAL( aboutToHide() ),
//this, SLOT( gotHide() ) );
}
picker->setDate( date.year(), date.month(), date.day() );
m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height())));
picker->setFocus();
}
void DateBookWeekLstHeader::setDate(int y, int m, int d) {
setDate(QDate(y,m,d));
}
void DateBookWeekLstHeader::nextWeek() {
setDate(date.addDays(7));
}
void DateBookWeekLstHeader::prevWeek() {
setDate(date.addDays(-7));
}
void DateBookWeekLstHeader::nextMonth()
{
setDate(date.addDays(28));
}
void DateBookWeekLstHeader::prevMonth()
{
setDate(date.addDays(-28));
}
diff --git a/core/pim/datebook/namespace_hack.h b/core/pim/datebook/namespace_hack.h index c15b5ed..2ed674c 100644 --- a/core/pim/datebook/namespace_hack.h +++ b/core/pim/datebook/namespace_hack.h @@ -1,20 +1,50 @@ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + #ifndef NAME_SPACE_HACK_H #define NAME_SPACE_HACK_H #include <opie2/otimepicker.h> #include <opie2/oclickablelabel.h> class TimePicker : public Opie::Ui::OTimePicker { public: TimePicker( QWidget* p = 0, const char* name = 0, WFlags fl = 0 ) : Opie::Ui::OTimePicker(p,name,fl){} - + }; class ClickableLabel : public Opie::Ui::OClickableLabel { public: ClickableLabel(QWidget *p=0,const char* name=0, WFlags fl = 0 ) : Opie::Ui::OClickableLabel(p,name,fl){} }; #endif diff --git a/core/pim/datebook/noteentryimpl.cpp b/core/pim/datebook/noteentryimpl.cpp index 14fe98e..f967ab2 100644 --- a/core/pim/datebook/noteentryimpl.cpp +++ b/core/pim/datebook/noteentryimpl.cpp @@ -1,15 +1,45 @@ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + #include "noteentryimpl.h" #include "qlabel.h" #include "onoteedit.h" NoteEntry::NoteEntry(const QString &title, const QString ¬eStr, QWidget* parent, const char* name, bool modal, WFlags fl) : NoteEntryBase(parent, name, modal, fl) { eventLabel->setText(title); note->setText(noteStr); int l=note->length(); note->setCursorPosition(l,l,false); } diff --git a/core/pim/datebook/noteentryimpl.h b/core/pim/datebook/noteentryimpl.h index f3adfa6..86ea0ee 100644 --- a/core/pim/datebook/noteentryimpl.h +++ b/core/pim/datebook/noteentryimpl.h @@ -1,18 +1,48 @@ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + #ifndef noteentryimpl_h #define noteentryimpl_h #include "noteentry.h" class QString; -class NoteEntry : public NoteEntryBase +class NoteEntry : public NoteEntryBase { Q_OBJECT public: NoteEntry(const QString &title, const QString ¬eStr, - QWidget* parent = 0, const char* name = 0, + QWidget* parent = 0, const char* name = 0, bool modal=TRUE, WFlags fl=0); }; #endif diff --git a/core/pim/datebook/onoteedit.cpp b/core/pim/datebook/onoteedit.cpp index d66ad86..a5f468d 100644 --- a/core/pim/datebook/onoteedit.cpp +++ b/core/pim/datebook/onoteedit.cpp @@ -1,19 +1,49 @@ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + #include "onoteedit.h" ONoteEdit::ONoteEdit (QWidget * parent, const char * name) : QMultiLineEdit(parent,name) { - setDefaultTabStop(2); + setDefaultTabStop(2); setWordWrap(WidgetWidth); } // Copy indentation from previous line void ONoteEdit::newLine() { int l,c; getCursorPosition(&l,&c); QString s=textLine(l); insert("\n"); int i=0; while (s[i]==' ' || s[i]=='\t') insert(QString(s[i])), i++; } diff --git a/core/pim/datebook/onoteedit.h b/core/pim/datebook/onoteedit.h index 2f71d0d..390b837 100644 --- a/core/pim/datebook/onoteedit.h +++ b/core/pim/datebook/onoteedit.h @@ -1,19 +1,49 @@ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + #ifndef ONOTEEDIT_H #define ONOTEEDIT_H #include <qmultilineedit.h> class ONoteEdit: public QMultiLineEdit { Q_OBJECT public: - + ONoteEdit (QWidget * parent=0, const char * name=0); protected: virtual void newLine (); }; #endif diff --git a/core/pim/datebook/repeatentry.cpp b/core/pim/datebook/repeatentry.cpp index 04c3cf3..30e296c 100644 --- a/core/pim/datebook/repeatentry.cpp +++ b/core/pim/datebook/repeatentry.cpp @@ -1,613 +1,623 @@ -/********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. -** -** This file is part of 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. -** -**********************************************************************/ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ #include "repeatentry.h" #include <qpe/datebookmonth.h> #include <qpe/qpeapplication.h> #include <qlabel.h> #include <qspinbox.h> #include <time.h> // Global Templates for use in setting up the repeat label... // the problem is these strings get initialized before QPEApplication can install the translator -zecke namespace { QString strDayTemplate; QString strYearTemplate; QString strMonthDateTemplate; QString strMonthDayTemplate; QString strWeekTemplate; QString dayLabel[7]; } /* * static linkage to not polute the symbol table... * The problem is that const and static linkage are resolved prior to installing a translator * leading to that the above strings are translted but to the original we delay the init of these strings... * -zecke */ static void fillStrings() { strDayTemplate = QObject::tr("Every"); strYearTemplate = QObject::tr("%1 %2 every "); strMonthDateTemplate = QObject::tr("The %1 every "); strMonthDayTemplate = QObject::tr("The %1 %1 of every"); strWeekTemplate = QObject::tr("Every "); dayLabel[0] = QObject::tr("Monday"); dayLabel[1] = QObject::tr("Tuesday"); dayLabel[2] = QObject::tr("Wednesday"); dayLabel[3] = QObject::tr("Thursday"); dayLabel[4] = QObject::tr("Friday"); dayLabel[5] = QObject::tr("Saturday"); dayLabel[6] = QObject::tr("Sunday"); } static QString numberPlacing( int x ); // return the proper word format for // x (1st, 2nd, etc) static int week( const QDate &dt ); // what week in the month is dt? RepeatEntry::RepeatEntry( bool startOnMonday, const QDate &newStart, QWidget *parent, const char *name, bool modal, WFlags fl ) : RepeatEntryBase( parent, name, modal, fl ), start( newStart ), currInterval( NONE ), startWeekOnMonday( startOnMonday ) { if (strDayTemplate.isEmpty() ) fillStrings(); init(); fraType->setButton( currInterval ); chkNoEnd->setChecked( TRUE ); setupNone(); } RepeatEntry::RepeatEntry( bool startOnMonday, const Event::RepeatPattern &rp, const QDate &startDate, QWidget *parent, const char *name, bool modal, WFlags fl ) : RepeatEntryBase( parent, name, modal, fl ), start( startDate ), end( rp.endDate() ), startWeekOnMonday( startOnMonday ) { if (strDayTemplate.isEmpty() ) fillStrings(); // do some stuff with the repeat pattern init(); switch ( rp.type ) { default: case Event::NoRepeat: currInterval = NONE; setupNone(); break; case Event::Daily: currInterval = DAY; setupDaily(); break; case Event::Weekly: currInterval = WEEK; setupWeekly(); int day, buttons; for ( day = 0x01, buttons = 0; buttons < 7; day = day << 1, buttons++ ) { if ( rp.days & day ) { if ( startWeekOnMonday ) fraExtra->setButton( buttons ); else { if ( buttons == 7 ) fraExtra->setButton( 0 ); else fraExtra->setButton( buttons + 1 ); } } } slotWeekLabel(); break; case Event::MonthlyDay: currInterval = MONTH; setupMonthly(); fraExtra->setButton( 0 ); slotMonthLabel( 0 ); break; case Event::MonthlyDate: currInterval = MONTH; setupMonthly(); fraExtra->setButton( 1 ); slotMonthLabel( 1 ); break; case Event::Yearly: currInterval = YEAR; setupYearly(); break; } fraType->setButton( currInterval ); spinFreq->setValue( rp.frequency ); if ( !rp.hasEndDate ) { cmdEnd->setText( RepeatEntryBase::tr("No End Date") ); chkNoEnd->setChecked( TRUE ); } else cmdEnd->setText( TimeString::shortDate( end ) ); } RepeatEntry::~RepeatEntry() { } Event::RepeatPattern RepeatEntry::repeatPattern() { QListIterator<QToolButton> it( listRTypeButtons ); QListIterator<QToolButton> itExtra( listExtra ); Event::RepeatPattern rpTmp; int i; for ( i = 0; *it; ++it, i++ ) { if ( (*it)->isOn() ) { switch ( i ) { case NONE: rpTmp.type = Event::NoRepeat; break; case DAY: rpTmp.type = Event::Daily; break; case WEEK: rpTmp.type = Event::Weekly; rpTmp.days = 0; int day; for ( day = 1; *itExtra; ++itExtra, day = day << 1 ) { if ( (*itExtra)->isOn() ) { if ( startWeekOnMonday ) rpTmp.days |= day; else { if ( day == 1 ) rpTmp.days |= Event::SUN; else rpTmp.days |= day >> 1; } } } break; case MONTH: if ( cmdExtra1->isOn() ) rpTmp.type = Event::MonthlyDay; else if ( cmdExtra2->isOn() ) rpTmp.type = Event::MonthlyDate; // figure out the montly day... rpTmp.position = week( start ); break; case YEAR: rpTmp.type = Event::Yearly; break; } break; // no need to keep looking! } } rpTmp.frequency = spinFreq->value(); rpTmp.hasEndDate = !chkNoEnd->isChecked(); if ( rpTmp.hasEndDate ) { rpTmp.setEndDate( end ); } // timestamp it... rpTmp.createTime = time( NULL ); return rpTmp; } void RepeatEntry::slotSetRType( int rtype ) { // now call the right function based on the type... currInterval = static_cast<repeatButtons>(rtype); switch ( currInterval ) { case NONE: setupNone(); break; case DAY: setupDaily(); break; case WEEK: setupWeekly(); slotWeekLabel(); break; case MONTH: setupMonthly(); cmdExtra2->setOn( TRUE ); slotMonthLabel( 1 ); break; case YEAR: setupYearly(); break; } } void RepeatEntry::setupNone() { lblRepeat->setText( tr("No Repeat") ); lblVar1->hide(); lblVar2->hide(); hideExtras(); cmdEnd->hide(); lblFreq->hide(); lblEvery->hide(); lblFreq->hide(); spinFreq->hide(); lblEnd->hide(); lblWeekVar->hide(); } void RepeatEntry::setupDaily() { hideExtras(); lblWeekVar->hide(); spinFreq->setValue( 1 ); lblFreq->setText( tr("day(s)") ); lblVar2->show(); showRepeatStuff(); lblRepeat->setText( strDayTemplate ); setupRepeatLabel( 1 ); } void RepeatEntry::setupWeekly() { // reshow the buttons... fraExtra->setTitle( RepeatEntryBase::tr("Repeat On") ); fraExtra->setExclusive( FALSE ); fraExtra->show(); if ( startWeekOnMonday ) { cmdExtra1->setText( RepeatEntryBase::tr("Mon") ); cmdExtra2->setText( RepeatEntryBase::tr("Tue") ); cmdExtra3->setText( RepeatEntryBase::tr("Wed") ); cmdExtra4->setText( RepeatEntryBase::tr("Thu") ); cmdExtra5->setText( RepeatEntryBase::tr("Fri") ); cmdExtra6->setText( RepeatEntryBase::tr("Sat") ); cmdExtra7->setText( RepeatEntryBase::tr("Sun") ); } else { cmdExtra1->setText( RepeatEntryBase::tr("Sun") ); cmdExtra2->setText( RepeatEntryBase::tr("Mon") ); cmdExtra3->setText( RepeatEntryBase::tr("Tue") ); cmdExtra4->setText( RepeatEntryBase::tr("Wed") ); cmdExtra5->setText( RepeatEntryBase::tr("Thu") ); cmdExtra6->setText( RepeatEntryBase::tr("Fri") ); cmdExtra7->setText( RepeatEntryBase::tr("Sat") ); } // I hope clustering these improve performance.... cmdExtra1->setOn( FALSE ); cmdExtra2->setOn( FALSE ); cmdExtra3->setOn( FALSE ); cmdExtra4->setOn( FALSE ); cmdExtra5->setOn( FALSE ); cmdExtra6->setOn( FALSE ); cmdExtra7->setOn( FALSE ); cmdExtra1->show(); cmdExtra2->show(); cmdExtra3->show(); cmdExtra4->show(); cmdExtra5->show(); cmdExtra6->show(); cmdExtra7->show(); lblWeekVar->show(); spinFreq->setValue( 1 ); // might as well set the day too... if ( startWeekOnMonday ) { fraExtra->setButton( start.dayOfWeek() - 1 ); } else { fraExtra->setButton( start.dayOfWeek() % 7 ); } lblFreq->setText( tr("week(s)") ); lblVar2->show(); showRepeatStuff(); setupRepeatLabel( 1 ); } void RepeatEntry::setupMonthly() { hideExtras(); lblWeekVar->hide(); fraExtra->setTitle( tr("Repeat By") ); fraExtra->setExclusive( TRUE ); fraExtra->show(); cmdExtra1->setText( tr("Day") ); cmdExtra1->show(); cmdExtra2->setText( tr("Date") ); cmdExtra2->show(); spinFreq->setValue( 1 ); lblFreq->setText( tr("month(s)") ); lblVar2->show(); showRepeatStuff(); setupRepeatLabel( 1 ); } void RepeatEntry::setupYearly() { hideExtras(); lblWeekVar->hide(); spinFreq->setValue( 1 ); lblFreq->setText( tr("year(s)") ); lblFreq->show(); lblFreq->show(); showRepeatStuff(); lblVar2->show(); QString strEvery = strYearTemplate.arg( start.monthName(start.month()) ).arg( numberPlacing(start.day()) ); lblRepeat->setText( strEvery ); setupRepeatLabel( 1 ); } void RepeatEntry::init() { QPopupMenu *m1 = new QPopupMenu( this ); repeatPicker = new DateBookMonth( m1, 0, TRUE ); m1->insertItem( repeatPicker ); cmdEnd->setPopup( m1 ); cmdEnd->setPopupDelay( 0 ); QObject::connect( repeatPicker, SIGNAL(dateClicked(int,int,int)), this, SLOT(endDateChanged(int,int,int)) ); QObject::connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotChangeStartOfWeek(bool)) ); listRTypeButtons.setAutoDelete( TRUE ); listRTypeButtons.append( cmdNone ); listRTypeButtons.append( cmdDay ); listRTypeButtons.append( cmdWeek ); listRTypeButtons.append( cmdMonth ); listRTypeButtons.append( cmdYear ); listExtra.setAutoDelete( TRUE ); listExtra.append( cmdExtra1 ); listExtra.append( cmdExtra2 ); listExtra.append( cmdExtra3 ); listExtra.append( cmdExtra4 ); listExtra.append( cmdExtra5 ); listExtra.append( cmdExtra6 ); listExtra.append( cmdExtra7 ); } void RepeatEntry::slotNoEnd( bool unused ) { // if the item was toggled, then go ahead and set it to the maximum date if ( unused ) { end.setYMD( 3000, 12, 31 ); cmdEnd->setText( RepeatEntryBase::tr("No End Date") ); } else { end = start; cmdEnd->setText( TimeString::shortDate(end) ); } } void RepeatEntry::endDateChanged( int y, int m, int d ) { end.setYMD( y, m, d ); if ( end < start ) end = start; cmdEnd->setText( TimeString::shortDate( end ) ); repeatPicker->setDate( end.year(), end.month(), end.day() ); } void RepeatEntry::setupRepeatLabel( const QString &s ) { lblVar1->setText( s ); } void RepeatEntry::setupRepeatLabel( int x ) { // change the spelling based on the value of x QString strVar2; if ( x > 1 ) lblVar1->show(); else lblVar1->hide(); switch ( currInterval ) { case NONE: break; case DAY: if ( x > 1 ) strVar2 = tr( "days" ); else strVar2 = tr( "day" ); break; case WEEK: if ( x > 1 ) strVar2 = tr( "weeks" ); else strVar2 = tr( "week" ); break; case MONTH: if ( x > 1 ) strVar2 = RepeatEntryBase::tr( "months" ); else strVar2 = tr( "month" ); break; case YEAR: if ( x > 1 ) strVar2 = RepeatEntryBase::tr( "years" ); else strVar2 = tr( "year" ); break; } if ( !strVar2.isNull() ) lblVar2->setText( strVar2 ); } void RepeatEntry::showRepeatStuff() { cmdEnd->show(); chkNoEnd->show(); lblFreq->show(); lblEvery->show(); lblFreq->show(); spinFreq->show(); lblEnd->show(); lblRepeat->setText( RepeatEntryBase::tr("Every") ); } void RepeatEntry::slotWeekLabel() { QString str; QListIterator<QToolButton> it( listExtra ); unsigned int i; unsigned int keepMe; bool bNeedCarriage = FALSE; // don't do something we'll regret!!! if ( currInterval != WEEK ) return; if ( startWeekOnMonday ) keepMe = start.dayOfWeek() - 1; else keepMe = start.dayOfWeek() % 7; QStringList list; for ( i = 0; *it; ++it, i++ ) { // a crazy check, if you are repeating weekly, the current day // must be selected!!! if ( i == keepMe && !( (*it)->isOn() ) ) (*it)->setOn( TRUE ); if ( (*it)->isOn() ) { if ( startWeekOnMonday ) list.append( dayLabel[i] ); else { if ( i == 0 ) list.append( dayLabel[6] ); else list.append( dayLabel[i - 1] ); } } } QStringList::Iterator itStr; for ( i = 0, itStr = list.begin(); itStr != list.end(); ++itStr, i++ ) { if ( i == 3 ) bNeedCarriage = TRUE; else bNeedCarriage = FALSE; if ( str.isNull() ) str = *itStr; else if ( i == list.count() - 1 ) { if ( i < 2 ) str += tr(" and ") + *itStr; else { if ( bNeedCarriage ) str += tr( ",\nand " ) + *itStr; else str += tr( ", and " ) + *itStr; } } else { if ( bNeedCarriage ) str += ",\n" + *itStr; else str += ", " + *itStr; } } str = str.prepend( tr("on ") ); lblWeekVar->setText( str ); } void RepeatEntry::slotMonthLabel( int type ) { QString str; if ( currInterval != MONTH || type > 1 ) return; if ( type == 1 ) str = strMonthDateTemplate.arg( numberPlacing(start.day()) ); else str = strMonthDayTemplate.arg( numberPlacing(week(start))) .arg( dayLabel[start.dayOfWeek() - 1] ); lblRepeat->setText( str ); } void RepeatEntry::slotChangeStartOfWeek( bool onMonday ) { startWeekOnMonday = onMonday; // we need to make this unintrusive as possible... int saveSpin = spinFreq->value(); char days = 0; int day; QListIterator<QToolButton> itExtra( listExtra ); for ( day = 1; *itExtra; ++itExtra, day = day << 1 ) { if ( (*itExtra)->isOn() ) { if ( !startWeekOnMonday ) days |= day; else { if ( day == 1 ) days |= Event::SUN; else days |= day >> 1; } } } setupWeekly(); spinFreq->setValue( saveSpin ); int buttons; for ( day = 0x01, buttons = 0; buttons < 7; day = day << 1, buttons++ ) { if ( days & day ) { if ( startWeekOnMonday ) fraExtra->setButton( buttons ); else { if ( buttons == 7 ) fraExtra->setButton( 0 ); else fraExtra->setButton( buttons + 1 ); } } } slotWeekLabel(); } static int week( const QDate &start ) { // figure out the week... int stop = start.day(), sentinel = start.dayOfWeek(), dayOfWeek = QDate( start.year(), start.month(), 1 ).dayOfWeek(), week = 1, i; for ( i = 1; i < stop; i++ ) { if ( dayOfWeek++ == sentinel ) week++; if ( dayOfWeek > 7 ) dayOfWeek = 0; } return week; } static QString numberPlacing( int x ) { // I hope this works in other languages besides english... QString str = QString::number( x ); switch ( x % 10 ) { case 1: str += QWidget::tr( "st" ); break; case 2: str += QWidget::tr( "nd" ); break; case 3: str += QWidget::tr( "rd" ); break; default: str += QWidget::tr( "th" ); break; } return str; } diff --git a/core/pim/datebook/repeatentry.h b/core/pim/datebook/repeatentry.h index 949fecd..d75af3c 100644 --- a/core/pim/datebook/repeatentry.h +++ b/core/pim/datebook/repeatentry.h @@ -1,98 +1,108 @@ -/********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. -** -** This file is part of 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. -** -**********************************************************************/ +/* + This file is part of the Opie Project + + Copyright (C) Opie Team <opie-devel@handhelds.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ #ifndef REPEATENTRY_H #define REPEATENTRY_H #include "repeatentrybase.h" #include <qpe/event.h> #include <qcheckbox.h> #include <qbuttongroup.h> #include <qdatetime.h> #include <qlist.h> #include <qtoolbutton.h> class DateBookMonth; class RepeatEntry : public RepeatEntryBase { Q_OBJECT public: RepeatEntry( bool startOnMonday, const QDate &start, QWidget *parent = 0, const char *name = 0, bool modal = TRUE, WFlags fl = 0 ); RepeatEntry( bool startOnMonday, const Event::RepeatPattern &rp, const QDate &start, QWidget *parent = 0, const char *name = 0, bool modal = TRUE, WFlags fl = 0 ); ~RepeatEntry(); Event::RepeatPattern repeatPattern(); QDate endDate() { return end; }; public slots: void slotSetRType( int ); void endDateChanged( int, int, int ); void slotNoEnd( bool unused ); private slots: void setupRepeatLabel( const QString& ); void setupRepeatLabel( int ); void slotWeekLabel(); void slotMonthLabel( int ); void slotChangeStartOfWeek( bool onMonday ); private: void setupNone(); void setupDaily(); void setupWeekly(); void setupMonthly(); void setupYearly(); enum repeatButtons { NONE, DAY, WEEK, MONTH, YEAR }; void init(); inline void hideExtras(); void showRepeatStuff(); QList<QToolButton> listRTypeButtons; QList<QToolButton> listExtra; QDate start; // only used in one spot... QDate end; repeatButtons currInterval; bool startWeekOnMonday; DateBookMonth *repeatPicker; }; inline void RepeatEntry::hideExtras() { // hide the extra buttons... fraExtra->hide(); chkNoEnd->hide(); QListIterator<QToolButton> it( listExtra ); for ( ; *it; ++it ) { (*it)->hide(); (*it)->setOn( FALSE ); } } #endif |