From 15318cad33835e4e2dc620d033e43cd930676cdd Mon Sep 17 00:00:00 2001 From: kergoth Date: Fri, 25 Jan 2002 22:14:26 +0000 Subject: Initial revision --- (limited to 'core/pim/datebook') diff --git a/core/pim/datebook/.cvsignore b/core/pim/datebook/.cvsignore new file mode 100644 index 0000000..4ba477d --- a/dev/null +++ b/core/pim/datebook/.cvsignore @@ -0,0 +1,12 @@ +moc_* +Makefile +dateentry.h +datebookdayheader.h +dateentry.cpp +datebookdayheader.cpp +datebookweekheader.cpp +datebookweekheader.h +datebooksettingsbase.h +datebooksettingsbase.cpp +repeatentrybase.cpp +repeatentrybase.h diff --git a/core/pim/datebook/Makefile.in b/core/pim/datebook/Makefile.in new file mode 100644 index 0000000..bdc69dc --- a/dev/null +++ b/core/pim/datebook/Makefile.in @@ -0,0 +1,385 @@ +############################################################################# + +####### Compiler, tools and options + +CXX = $(SYSCONF_CXX) $(QT_CXX_MT) +CXXFLAGS= $(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS) +CC = $(SYSCONF_CC) $(QT_C_MT) +CFLAGS = $(SYSCONF_CFLAGS) +INCPATH = -I$(QPEDIR)/include +LFLAGS = $(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT) +LIBS = $(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP) +MOC = $(SYSCONF_MOC) +UIC = $(SYSCONF_UIC) + +####### Target + +DESTDIR = $(QPEDIR)/bin/ +VER_MAJ = 1 +VER_MIN = 0 +VER_PATCH = 0 +TARGET = datebook +TARGET1 = lib$(TARGET).so.$(VER_MAJ) + +####### Files + +HEADERS = datebookday.h \ + datebook.h \ + dateentryimpl.h \ + datebookdayheaderimpl.h \ + datebooksettings.h \ + datebookweek.h \ + datebookweekheaderimpl.h \ + repeatentry.h +SOURCES = main.cpp \ + datebookday.cpp \ + datebook.cpp \ + dateentryimpl.cpp \ + datebookdayheaderimpl.cpp \ + datebooksettings.cpp \ + datebookweek.cpp \ + datebookweekheaderimpl.cpp \ + repeatentry.cpp +OBJECTS = main.o \ + datebookday.o \ + datebook.o \ + dateentryimpl.o \ + datebookdayheaderimpl.o \ + datebooksettings.o \ + datebookweek.o \ + datebookweekheaderimpl.o \ + repeatentry.o \ + dateentry.o \ + datebookdayheader.o \ + datebooksettingsbase.o \ + datebookweekheader.o \ + repeatentrybase.o +INTERFACES = dateentry.ui \ + datebookdayheader.ui \ + datebooksettingsbase.ui \ + datebookweekheader.ui \ + repeatentrybase.ui +UICDECLS = dateentry.h \ + datebookdayheader.h \ + datebooksettingsbase.h \ + datebookweekheader.h \ + repeatentrybase.h +UICIMPLS = dateentry.cpp \ + datebookdayheader.cpp \ + datebooksettingsbase.cpp \ + datebookweekheader.cpp \ + repeatentrybase.cpp +SRCMOC = moc_datebookday.cpp \ + moc_datebook.cpp \ + moc_dateentryimpl.cpp \ + moc_datebookdayheaderimpl.cpp \ + moc_datebookweek.cpp \ + moc_datebookweekheaderimpl.cpp \ + moc_repeatentry.cpp \ + moc_dateentry.cpp \ + moc_datebookdayheader.cpp \ + moc_datebooksettingsbase.cpp \ + moc_datebookweekheader.cpp \ + moc_repeatentrybase.cpp +OBJMOC = moc_datebookday.o \ + moc_datebook.o \ + moc_dateentryimpl.o \ + moc_datebookdayheaderimpl.o \ + moc_datebookweek.o \ + moc_datebookweekheaderimpl.o \ + moc_repeatentry.o \ + moc_dateentry.o \ + moc_datebookdayheader.o \ + moc_datebooksettingsbase.o \ + moc_datebookweekheader.o \ + moc_repeatentrybase.o + + +####### Implicit rules + +.SUFFIXES: .cpp .cxx .cc .C .c + +.cpp.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.cxx.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.cc.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.C.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.c.o: + $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $< + +####### Build rules + + +all: $(DESTDIR)$(TARGET) + +$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS) + $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS) + +moc: $(SRCMOC) + +tmake: + tmake datebook.pro + +clean: + -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS) + -rm -f *~ core + -rm -f allmoc.cpp + +####### Extension Modules + +listpromodules: + @echo + +listallmodules: + @echo + +listaddonpromodules: + @echo + +listaddonentmodules: + @echo + + +REQUIRES= + +####### Sub-libraries + + +###### Combined headers + + + +####### Compile + +main.o: main.cpp \ + datebook.h \ + $(QPEDIR)/include/qpe/datebookdb.h \ + $(QPEDIR)/include/qpe/event.h \ + $(QPEDIR)/include/qpe/palmtoprecord.h \ + $(QPEDIR)/include/qpe/qpeapplication.h + +datebookday.o: datebookday.cpp \ + datebookday.h \ + $(QPEDIR)/include/qpe/event.h \ + $(QPEDIR)/include/qpe/palmtoprecord.h \ + datebookdayheaderimpl.h \ + datebookdayheader.h \ + $(QPEDIR)/include/qpe/datebookdb.h \ + $(QPEDIR)/include/qpe/resource.h \ + $(QPEDIR)/include/qpe/qpeapplication.h \ + $(QPEDIR)/include/qpe/timestring.h \ + $(QPEDIR)/include/qpe/qpedebug.h + +datebook.o: datebook.cpp \ + datebook.h \ + $(QPEDIR)/include/qpe/datebookdb.h \ + $(QPEDIR)/include/qpe/event.h \ + $(QPEDIR)/include/qpe/palmtoprecord.h \ + datebookday.h \ + datebooksettings.h \ + datebooksettingsbase.h \ + datebookweek.h \ + dateentryimpl.h \ + dateentry.h \ + $(QPEDIR)/include/qpe/datebookmonth.h \ + $(QPEDIR)/include/qpe/qpeapplication.h \ + $(QPEDIR)/include/qpe/config.h \ + $(QPEDIR)/include/qpe/qpedebug.h \ + $(QPEDIR)/include/qpe/finddialog.h \ + $(QPEDIR)/include/qpe/ir.h \ + $(QPEDIR)/include/qpe/qpemenubar.h \ + $(QPEDIR)/include/qpe/qpemessagebox.h \ + $(QPEDIR)/include/qpe/resource.h \ + $(QPEDIR)/include/qpe/sound.h \ + $(QPEDIR)/include/qpe/timestring.h \ + $(QPEDIR)/include/qpe/qpetoolbar.h \ + $(QPEDIR)/include/qpe/tzselect.h \ + $(QPEDIR)/include/qpe/xmlreader.h + +dateentryimpl.o: dateentryimpl.cpp \ + dateentryimpl.h \ + dateentry.h \ + $(QPEDIR)/include/qpe/event.h \ + $(QPEDIR)/include/qpe/palmtoprecord.h \ + repeatentry.h \ + repeatentrybase.h \ + $(QPEDIR)/include/qpe/qpeapplication.h \ + $(QPEDIR)/include/qpe/categoryselect.h \ + $(QPEDIR)/include/qpe/datebookmonth.h \ + $(QPEDIR)/include/qpe/global.h \ + $(QPEDIR)/include/qpe/timeconversion.h \ + $(QPEDIR)/include/qpe/timestring.h \ + $(QPEDIR)/include/qpe/tzselect.h + +datebookdayheaderimpl.o: datebookdayheaderimpl.cpp \ + datebookdayheaderimpl.h \ + datebookdayheader.h \ + $(QPEDIR)/include/qpe/datebookmonth.h \ + $(QPEDIR)/include/qpe/event.h \ + $(QPEDIR)/include/qpe/palmtoprecord.h \ + $(QPEDIR)/include/qpe/timestring.h + +datebooksettings.o: datebooksettings.cpp \ + datebooksettings.h \ + datebooksettingsbase.h \ + $(QPEDIR)/include/qpe/qpeapplication.h + +datebookweek.o: datebookweek.cpp \ + datebookweek.h \ + $(QPEDIR)/include/qpe/event.h \ + $(QPEDIR)/include/qpe/palmtoprecord.h \ + datebookweekheaderimpl.h \ + datebookweekheader.h \ + $(QPEDIR)/include/qpe/calendar.h \ + $(QPEDIR)/include/qpe/datebookdb.h \ + $(QPEDIR)/include/qpe/qpeapplication.h \ + $(QPEDIR)/include/qpe/timestring.h + +datebookweekheaderimpl.o: datebookweekheaderimpl.cpp \ + datebookweekheaderimpl.h \ + datebookweekheader.h + +repeatentry.o: repeatentry.cpp \ + repeatentry.h \ + repeatentrybase.h \ + $(QPEDIR)/include/qpe/event.h \ + $(QPEDIR)/include/qpe/palmtoprecord.h \ + $(QPEDIR)/include/qpe/datebookmonth.h \ + $(QPEDIR)/include/qpe/qpeapplication.h \ + $(QPEDIR)/include/qpe/timestring.h + +dateentry.h: dateentry.ui + $(UIC) dateentry.ui -o $(INTERFACE_DECL_PATH)/dateentry.h + +dateentry.cpp: dateentry.ui + $(UIC) dateentry.ui -i dateentry.h -o dateentry.cpp + +datebookdayheader.h: datebookdayheader.ui + $(UIC) datebookdayheader.ui -o $(INTERFACE_DECL_PATH)/datebookdayheader.h + +datebookdayheader.cpp: datebookdayheader.ui + $(UIC) datebookdayheader.ui -i datebookdayheader.h -o datebookdayheader.cpp + +datebooksettingsbase.h: datebooksettingsbase.ui + $(UIC) datebooksettingsbase.ui -o $(INTERFACE_DECL_PATH)/datebooksettingsbase.h + +datebooksettingsbase.cpp: datebooksettingsbase.ui + $(UIC) datebooksettingsbase.ui -i datebooksettingsbase.h -o datebooksettingsbase.cpp + +datebookweekheader.h: datebookweekheader.ui + $(UIC) datebookweekheader.ui -o $(INTERFACE_DECL_PATH)/datebookweekheader.h + +datebookweekheader.cpp: datebookweekheader.ui + $(UIC) datebookweekheader.ui -i datebookweekheader.h -o datebookweekheader.cpp + +repeatentrybase.h: repeatentrybase.ui + $(UIC) repeatentrybase.ui -o $(INTERFACE_DECL_PATH)/repeatentrybase.h + +repeatentrybase.cpp: repeatentrybase.ui + $(UIC) repeatentrybase.ui -i repeatentrybase.h -o repeatentrybase.cpp + +dateentry.o: dateentry.cpp + +datebookdayheader.o: datebookdayheader.cpp + +datebooksettingsbase.o: datebooksettingsbase.cpp + +datebookweekheader.o: datebookweekheader.cpp + +repeatentrybase.o: repeatentrybase.cpp + +moc_datebookday.o: moc_datebookday.cpp \ + datebookday.h \ + $(QPEDIR)/include/qpe/event.h \ + $(QPEDIR)/include/qpe/palmtoprecord.h + +moc_datebook.o: moc_datebook.cpp \ + datebook.h \ + $(QPEDIR)/include/qpe/datebookdb.h \ + $(QPEDIR)/include/qpe/event.h \ + $(QPEDIR)/include/qpe/palmtoprecord.h + +moc_dateentryimpl.o: moc_dateentryimpl.cpp \ + dateentryimpl.h \ + dateentry.h \ + $(QPEDIR)/include/qpe/event.h \ + $(QPEDIR)/include/qpe/palmtoprecord.h + +moc_datebookdayheaderimpl.o: moc_datebookdayheaderimpl.cpp \ + datebookdayheaderimpl.h \ + datebookdayheader.h + +moc_datebookweek.o: moc_datebookweek.cpp \ + datebookweek.h \ + $(QPEDIR)/include/qpe/event.h \ + $(QPEDIR)/include/qpe/palmtoprecord.h + +moc_datebookweekheaderimpl.o: moc_datebookweekheaderimpl.cpp \ + datebookweekheaderimpl.h \ + datebookweekheader.h + +moc_repeatentry.o: moc_repeatentry.cpp \ + repeatentry.h \ + repeatentrybase.h \ + $(QPEDIR)/include/qpe/event.h \ + $(QPEDIR)/include/qpe/palmtoprecord.h + +moc_dateentry.o: moc_dateentry.cpp \ + dateentry.h + +moc_datebookdayheader.o: moc_datebookdayheader.cpp \ + datebookdayheader.h + +moc_datebooksettingsbase.o: moc_datebooksettingsbase.cpp \ + datebooksettingsbase.h + +moc_datebookweekheader.o: moc_datebookweekheader.cpp \ + datebookweekheader.h + +moc_repeatentrybase.o: moc_repeatentrybase.cpp \ + repeatentrybase.h + +moc_datebookday.cpp: datebookday.h + $(MOC) datebookday.h -o moc_datebookday.cpp + +moc_datebook.cpp: datebook.h + $(MOC) datebook.h -o moc_datebook.cpp + +moc_dateentryimpl.cpp: dateentryimpl.h + $(MOC) dateentryimpl.h -o moc_dateentryimpl.cpp + +moc_datebookdayheaderimpl.cpp: datebookdayheaderimpl.h + $(MOC) datebookdayheaderimpl.h -o moc_datebookdayheaderimpl.cpp + +moc_datebookweek.cpp: datebookweek.h + $(MOC) datebookweek.h -o moc_datebookweek.cpp + +moc_datebookweekheaderimpl.cpp: datebookweekheaderimpl.h + $(MOC) datebookweekheaderimpl.h -o moc_datebookweekheaderimpl.cpp + +moc_repeatentry.cpp: repeatentry.h + $(MOC) repeatentry.h -o moc_repeatentry.cpp + +moc_dateentry.cpp: dateentry.h + $(MOC) dateentry.h -o moc_dateentry.cpp + +moc_datebookdayheader.cpp: datebookdayheader.h + $(MOC) datebookdayheader.h -o moc_datebookdayheader.cpp + +moc_datebooksettingsbase.cpp: datebooksettingsbase.h + $(MOC) datebooksettingsbase.h -o moc_datebooksettingsbase.cpp + +moc_datebookweekheader.cpp: datebookweekheader.h + $(MOC) datebookweekheader.h -o moc_datebookweekheader.cpp + +moc_repeatentrybase.cpp: repeatentrybase.h + $(MOC) repeatentrybase.h -o moc_repeatentrybase.cpp + + diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp new file mode 100644 index 0000000..6ec6cc2 --- a/dev/null +++ b/core/pim/datebook/datebook.cpp @@ -0,0 +1,854 @@ +/********************************************************************** +** 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$ +** +**********************************************************************/ + +#include "datebook.h" +#include "datebookday.h" +#include "datebooksettings.h" +#include "datebookweek.h" +#include "dateentryimpl.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#define DAY 1 +#define WEEK 2 +#define MONTH 3 + + +DateBook::DateBook( QWidget *parent, const char *, WFlags f ) + : QMainWindow( parent, "datebook", f ), + aPreset( FALSE ), + presetTime( -1 ), + startTime( 8 ), // an acceptable default + syncing(FALSE), + inSearch(FALSE) +{ + QTime t; + t.start(); + db = new DateBookDB; + qDebug("loading db t=%d", t.elapsed() ); + loadSettings(); + setCaption( tr("Calendar") ); + setIcon( Resource::loadPixmap( "datebook_icon" ) ); + + setToolBarsMovable( FALSE ); + + QPEToolBar *bar = new QPEToolBar( this ); + bar->setHorizontalStretchable( TRUE ); + + QPEMenuBar *mb = new QPEMenuBar( bar ); + mb->setMargin( 0 ); + + QPEToolBar *sub_bar = new QPEToolBar(this); + + QPopupMenu *view = new QPopupMenu( this ); + QPopupMenu *settings = new QPopupMenu( this ); + + mb->insertItem( tr( "View" ), view ); + mb->insertItem( tr( "Settings" ), settings ); + + QActionGroup *g = new QActionGroup( this ); + g->setExclusive( TRUE ); + + QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), + QString::null, 0, this, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); + a->addTo( sub_bar ); + + a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); + a->addTo( sub_bar ); + a->addTo( view ); + a->setToggleAction( TRUE ); + a->setOn( TRUE ); + dayAction = a; + a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); + a->addTo( sub_bar ); + a->addTo( view ); + a->setToggleAction( TRUE ); + weekAction = a; + a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); + a->addTo( sub_bar ); + a->addTo( view ); + a->setToggleAction( TRUE ); + monthAction = a; + + a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 ); + connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); + a->addTo( sub_bar ); + + a = new QAction( tr( "Today" ), QString::null, 0, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); + a->addTo( view ); + + a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); + a->addTo( settings ); + + views = new QWidgetStack( this ); + setCentralWidget( views ); + + dayView = 0; + weekView = 0; + monthView = 0; + + viewDay(); + 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&)) ); +#endif +#endif + + qDebug("done t=%d", t.elapsed() ); + +} + +void DateBook::receive( const QCString &msg, const QByteArray &data ) +{ + QDataStream stream( data, IO_ReadOnly ); + if ( msg == "timeChange(QString)" ) { + // update active view! + if ( dayAction->isOn() ) + viewDay(); + else if ( weekAction->isOn() ) + viewWeek(); + else if ( monthAction->isOn() ) + viewMonth(); + } +} + +DateBook::~DateBook() +{ +} + +void DateBook::slotSettings() +{ + DateBookSettings frmSettings( ampm, this ); + frmSettings.setStartTime( startTime ); + frmSettings.setAlarmPreset( aPreset, presetTime ); +#if defined (Q_WS_QWS) || defined(_WS_QWS_) + frmSettings.showMaximized(); +#endif + + if ( frmSettings.exec() ) { + aPreset = frmSettings.alarmPreset(); + presetTime = frmSettings.presetTime(); + startTime = frmSettings.startTime(); + if ( dayView ) + dayView->setStartViewTime( startTime ); + 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(); + } + } +} + +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 ( monthView && views->visibleWidget() == monthView ) { + d = monthView->selectedDate(); + } + + return d; +} + +void DateBook::viewDay() +{ + initDay(); + dayAction->setOn( TRUE ); + QDate d = currentDate(); + dayView->setDate( d ); + views->raiseWidget( dayView ); + dayView->redraw(); +} + +void DateBook::viewWeek() +{ + initWeek(); + weekAction->setOn( TRUE ); + QDate d = currentDate(); + weekView->setDate( d ); + views->raiseWidget( weekView ); + weekView->redraw(); +} + +void DateBook::viewMonth() +{ + initMonth(); + monthAction->setOn( TRUE ); + QDate d = currentDate(); + monthView->setDate( d.year(), d.month(), d.day() ); + views->raiseWidget( monthView ); + monthView->redraw(); +} + +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 ); + +#if defined(Q_WS_QWS) || defined(_WS_QWS_) + editDlg.showMaximized(); +#endif + while (editDlg.exec() ) { + Event newEv = entry->event(); + QString error = checkEvent(newEv); + if (!error.isNull()) { + if (QMessageBox::warning(this, "error box", + error, "Fix it", "Continue", 0, 0, 1) == 0) + 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 ) +{ + initDay(); + dayView->setDate( year, month, day ); + views->raiseWidget( dayView ); + dayAction->setOn( TRUE ); +} + +void DateBook::initDay() +{ + if ( !dayView ) { + dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); + views->addWidget( dayView, DAY ); + dayView->setStartViewTime( startTime ); + 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( 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 ); + } + if ( totWeeks != weekView->totalWeeks() ) + weekView->setTotalWeeks( totWeeks ); +} + +void DateBook::initMonth() +{ + if ( !monthView ) { + monthView = new DateBookMonth( views, "month view", FALSE, db ); + views->addWidget( monthView, MONTH ); + connect( monthView, SIGNAL( dateClicked( int, int, int ) ), + this, SLOT( showDay( int, int, int ) ) ); + connect( this, SIGNAL( newEvent() ), + monthView, SLOT( redraw() ) ); + qApp->processEvents(); + } +} + +void DateBook::loadSettings() +{ + { + Config config( "qpe" ); + config.setGroup("Time"); + ampm = config.readBoolEntry( "AMPM", TRUE ); + onMonday = config.readBoolEntry( "MONDAY" ); + } + + { + Config config("DateBook"); + config.setGroup("Main"); + startTime = config.readNumEntry("startviewtime", 8); + aPreset = config.readBoolEntry("alarmpreset"); + presetTime = config.readNumEntry("presettime"); + } +} + +void DateBook::saveSettings() +{ + Config config( "qpe" ); + Config configDB( "DateBook" ); + configDB.setGroup( "Main" ); + configDB.writeEntry("startviewtime",startTime); + configDB.writeEntry("alarmpreset",aPreset); + configDB.writeEntry("presettime",presetTime); +} + +void DateBook::appMessage(const QCString& msg, const QByteArray& data) +{ + bool needShow = FALSE; + if ( msg == "alarm(QDateTime,int)" ) { + QDataStream ds(data,IO_ReadOnly); + QDateTime when; int warn; + ds >> when >> warn; + + // 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 list = db->getEffectiveEvents(when.addSecs(warn*60)); + if ( list.count() > 0 ) { + QString msg; + bool bSound = FALSE; + int stopTimer = 0; + bool found = FALSE; + for ( QValueList::ConstIterator it=list.begin(); + it!=list.end(); ++it ) { + if ( (*it).event().hasAlarm() ) { + found = TRUE; + msg += "
" + (*it).description() + "" + + "
" + (*it).location() + "
" + + TimeString::dateString((*it).event().start(),ampm) + + (warn + ? tr(" (in " + QString::number(warn) + + tr(" minutes)")) + : QString("")) + + "
" + + (*it).notes() + "
"; + if ( (*it).event().alarmSound() != Event::Silent ) { + bSound = TRUE; + } + } + } + if ( found ) { + if ( bSound ) { + Sound::soundAlarm(); + stopTimer = startTimer( 5000 ); + } + + QDialog dlg( this, 0, TRUE ); + QVBoxLayout *vb = new QVBoxLayout( &dlg ); + QScrollView *view = new QScrollView( &dlg, "scrollView"); + view->setResizePolicy( QScrollView::AutoOneFit ); + vb->addWidget( view ); + QLabel *lblMsg = new QLabel( msg, &dlg ); + view->addChild( lblMsg ); + QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); + connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); + vb->addWidget( cmdOk ); + +#if defined(Q_WS_QWS) || defined(_WS_QWS_) + dlg.showMaximized(); +#endif + needShow = dlg.exec(); + + if ( bSound ) + killTimer( stopTimer ); + } + } + } else if ( msg == "nextView()" ) { + QWidget* cur = views->visibleWidget(); + if ( cur ) { + if ( cur == dayView ) + viewWeek(); + else if ( cur == weekView ) + viewMonth(); + else if ( cur == monthView ) + viewDay(); + 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 ) +{ + static int stop = 0; + if ( stop < 10 ) { + Sound::soundAlarm(); + stop++; + } else { + stop = 0; + killTimer( e->timerId() ); + } +} + +void DateBook::changeClock( bool newClock ) +{ + ampm = newClock; + // repaint the affected objects... + if (dayView) dayView->redraw(); + if (weekView) weekView->redraw(); +} + +void DateBook::changeWeek( bool m ) +{ + /* no need to redraw, each widget catches. Do need to + store though for widgets we haven't made yet */ + onMonday = m; +} + +void DateBook::slotToday() +{ + // we need to view today + QDate dt = QDate::currentDate(); + showDay( dt.year(), dt.month(), dt.day() ); +} + +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 ) ); + } + + // 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... + ev.setLocation( tr("(Unknown)") ); + ev.setStart( start ); + ev.setEnd( end ); + + e = new DateEntry( onMonday, ev, ampm, &newDlg ); + e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); + sv->addChild( e ); +#if defined(Q_WS_QWS) || defined(_WS_QWS_) + newDlg.showMaximized(); +#endif + while (newDlg.exec()) { + 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 tl = Event::readVCalendar( filename ); + for( QValueList::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 ) +{ + qDebug("trying to beamn"); + 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" ); +} + +void DateBook::beamDone( Ir *ir ) +{ + delete ir; + unlink( beamfile ); +} + +void DateBook::slotFind() +{ + // move it to the day view... + viewDay(); + FindDialog frmFind( "Calendar", this ); + frmFind.setUseDate( true ); + frmFind.setDate( currentDate() ); + QObject::connect( &frmFind, + SIGNAL(signalFindClicked(const QString&, const QDate&, + bool, bool, int)), + this, + SLOT(slotDoFind(const QString&, const QDate&, + bool, bool, int)) ); + QObject::connect( this, + SIGNAL(signalNotFound()), + &frmFind, + SLOT(slotNotFound()) ); + QObject::connect( this, + SIGNAL(signalWrapAround()), + &frmFind, + SLOT(slotWrapAround()) ); + frmFind.exec(); + inSearch = false; +} + +bool catComp( QArray cats, int category ) +{ + bool returnMe; + int i, + count; + + count = int(cats.count()); + returnMe = false; + if ( (category == -1 && count == 0) || category == -2 ) + returnMe = true; + else { + for ( i = 0; i < count; i++ ) { + if ( category == cats[i] ) { + returnMe = true; + break; + } + } + } + return returnMe; +} + + +void DateBook::slotDoFind( const QString& txt, const QDate &dt, + bool caseSensitive, bool /*backwards*/, + int category ) +{ + QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), + next; + + QRegExp r( txt ); + r.setCaseSensitive( caseSensitive ); + + + static Event rev, + nonrev; + if ( !inSearch ) { + rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); + nonrev.setStart( rev.start() ); + inSearch = true; + } + static QDate searchDate = dt; + static bool wrapAround = true; + bool candidtate; + candidtate = false; + + QValueList repeats = db->getRawRepeats(); + + // find the candidate for the first repeat that matches... + QValueListConstIterator it; + QDate start = dt; + for ( it = repeats.begin(); it != repeats.end(); ++it ) { + if ( catComp( (*it).categories(), category ) ) { + while ( nextOccurance( *it, start, next ) ) { + if ( next < dtEnd ) { + if ( (*it).match( r ) && !(next <= rev.start()) ) { + rev = *it; + dtEnd = next; + rev.setStart( next ); + candidtate = true; + wrapAround = true; + start = dt; + break; + } else + start = next.date().addDays( 1 ); + } + } + } + } + + // now the for first non repeat... + QValueList nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); + qHeapSort( nonRepeats.begin(), nonRepeats.end() ); + for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { + if ( catComp( (*it).categories(), category ) ) { + if ( (*it).start() < dtEnd ) { + if ( (*it).match( r ) && !(*it <= nonrev) ) { + nonrev = *it; + dtEnd = nonrev.start(); + candidtate = true; + wrapAround = true; + break; + } + } + } + } + if ( candidtate ) { + dayView->setStartViewTime( dtEnd.time().hour() ); + dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), + dtEnd.date().day() ); + } else { + if ( wrapAround ) { + emit signalWrapAround(); + rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); + nonrev.setStart( rev.start() ); + } else + emit signalNotFound(); + wrapAround = !wrapAround; + } +} diff --git a/core/pim/datebook/datebook.h b/core/pim/datebook/datebook.h new file mode 100644 index 0000000..44627bb --- a/dev/null +++ b/core/pim/datebook/datebook.h @@ -0,0 +1,111 @@ +/********************************************************************** +** 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. +** +**********************************************************************/ +#ifndef DATEBOOK_H +#define DATEBOOK_H + +#include + +#include + +class QAction; +class QWidgetStack; +class DateBookDay; +class DateBookWeek; +class DateBookMonth; +class Event; +class QDate; +class Ir; + +class DateBook : public QMainWindow +{ + Q_OBJECT + +public: + 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 ); + +public slots: + void flush(); + void reload(); + +private slots: + void fileNew(); + 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 viewDay(); + void viewWeek(); + void viewMonth(); + + void showDay( int y, int m, int d ); + + void editEvent( 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 initMonth(); + void loadSettings(); + void saveSettings(); + +private: + DateBookDB *db; + QWidgetStack *views; + DateBookDay *dayView; + DateBookWeek *weekView; + DateBookMonth *monthView; + QAction *dayAction, *weekAction, *monthAction; + bool aPreset; // have everything set to alarm? + int presetTime; // the standard time for the alarm + int startTime; + bool ampm; + bool onMonday; + + bool syncing; + bool inSearch; + + QString checkEvent(const Event &); +}; + +#endif diff --git a/core/pim/datebook/datebook.pro b/core/pim/datebook/datebook.pro new file mode 100644 index 0000000..17c02ec --- a/dev/null +++ b/core/pim/datebook/datebook.pro @@ -0,0 +1,36 @@ +TEMPLATE = app +CONFIG += qt warn_on release +DESTDIR = $(QPEDIR)/bin + +HEADERS = datebookday.h \ + datebook.h \ + dateentryimpl.h \ + datebookdayheaderimpl.h \ + datebooksettings.h \ + datebookweek.h \ + datebookweekheaderimpl.h \ + repeatentry.h + +SOURCES = main.cpp \ + datebookday.cpp \ + datebook.cpp \ + dateentryimpl.cpp \ + datebookdayheaderimpl.cpp \ + datebooksettings.cpp \ + datebookweek.cpp \ + datebookweekheaderimpl.cpp \ + repeatentry.cpp + +INTERFACES = dateentry.ui \ + datebookdayheader.ui \ + datebooksettingsbase.ui \ + datebookweekheader.ui \ + repeatentrybase.ui + +INCLUDEPATH += $(QPEDIR)/include +DEPENDPATH += $(QPEDIR)/include +LIBS += -lqpe + +TARGET = datebook + +TRANSLATIONS = ../i18n/de/datebook.ts diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp new file mode 100644 index 0000000..d5daab2 --- a/dev/null +++ b/core/pim/datebook/datebookday.cpp @@ -0,0 +1,553 @@ +/********************************************************************** +** 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. +** +**********************************************************************/ + +#include "datebookday.h" +#include "datebookdayheaderimpl.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, + const char *name ) + : QTable( 24, 1, parent, name ), + ampm( whichClock ) +{ + 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 ); + } + initHeader(); + QObject::connect( qApp, SIGNAL(clockChanged(bool)), + this, SLOT(slotChangeClock(bool)) ); +} + +void DateBookDayView::initHeader() +{ + QString strTmp; + 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 ); + setRowStretchable( i, FALSE ); + } +} + +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().mid() ); + p->drawLine( x2, 0, x2, y2 ); + p->drawLine( 0, y2, x2, y2 ); + 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(); + } +} + + +//=========================================================================== + +DateBookDay::DateBookDay( bool ampm, bool startOnMonday, + DateBookDB *newDb, QWidget *parent, + const char *name ) + : QVBox( parent, name ), + currDate( QDate::currentDate() ), + db( newDb ), + startTime( 0 ) +{ + widgetList.setAutoDelete( true ); + header = new DateBookDayHeader( startOnMonday, this, "day header" ); + header->setDate( currDate.year(), currDate.month(), currDate.day() ); + view = new DateBookDayView( ampm, this, "day view" ); + connect( header, SIGNAL( dateChanged( int, int, int ) ), + this, SLOT( dateChanged( 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&)) ); +} + +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; iselection( 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 ); +} + +void DateBookDay::setDate( QDate d) +{ + header->setDate( d.year(), d.month(), d.day() ); +} + +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; + ts.init( startTime, 0 ); + ts.expandTo( startTime, 0 ); + dayView()->addSelection( ts ); +} + +void DateBookDay::redraw() +{ + if ( isUpdatesEnabled() ) + relayoutPage(); +} + +void DateBookDay::getEvents() +{ + widgetList.clear(); + + QValueList eventList = db->getEffectiveEvents( currDate, + currDate ); + QValueListIterator it; + for ( it = eventList.begin(); it != eventList.end(); ++it ) { + DateBookDayWidget* w = new DateBookDayWidget( *it, this ); + connect( w, SIGNAL( deleteMe( const Event & ) ), + this, SIGNAL( removeEvent( const Event & ) ) ); + connect( w, SIGNAL( editMe( const Event & ) ), + this, SIGNAL( editEvent( const Event & ) ) ); + connect( w, SIGNAL( beamMe( const Event & ) ), + this, SIGNAL( beamEvent( const Event & ) ) ); + widgetList.append( w ); + } +} + +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! + + int wCount = widgetList.count(); + int wid = view->columnWidth(0)-1; + int n = 1; + + if ( wCount < 20 ) { + for ( int i = 0; i < wCount; ) { + DateBookDayWidget *w = widgetList.at(i); + int x = 0; + int xp = 0; + QRect geom = w->geometry(); + geom.setX( x ); + geom.setWidth( wid ); + while ( xp < n && intersects( w, geom ) ) { + x += wid; + xp++; + geom.moveBy( wid, 0 ); + } + if ( xp >= n ) { + n++; + wid = ( view->columnWidth(0)-1 ) / n; + i = 0; + } else { + w->setGeometry( geom ); + i++; + } + } + 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 ); + geom.setWidth( wid ); + w->setGeometry( geom ); + } + } + view->setContentsPos( 0, startTime * view->rowHeight(0) ); + } + 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; + 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 ) +{ + bool whichClock = db->dayView()->whichClock(); + + // 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 = "" + strDesc + "
" + "" + + strCat + "" + + "
" + tr("Start") + ": "; + + + if ( e.startDate() != ev.date() ) { + // multi-day event. Show start date + text += TimeString::longDateString( e.startDate() ); + } else { + // Show start time. + text += TimeString::timeString( ev.start(), whichClock, FALSE ); + } + + text += "
" + tr("End") + ": "; + if ( e.endDate() != ev.date() ) { + // multi-day event. Show end date + text += TimeString::longDateString( e.endDate() ); + } else { + // Show end time. + text += TimeString::timeString( ev.end(), whichClock, FALSE ); + } + text += "

" + strNote; + setBackgroundMode( PaletteBase ); + + QTime s = ev.start(); + QTime e = ev.end(); + int y = s.hour()*60+s.minute(); + int h = e.hour()*60+e.minute()-y; + int rh = dateBook->dayView()->rowHeight(0); + y = y*rh/60; + h = h*rh/60; + if ( h < 3 ) + h = 3; + geom.setY( y ); + geom.setHeight( h ); +} + +DateBookDayWidget::~DateBookDayWidget() +{ +} + +void DateBookDayWidget::paintEvent( QPaintEvent *e ) +{ + QPainter p( this ); + p.setPen( QColor(100, 100, 100) ); + p.setBrush( QColor( 255, 240, 230 ) ); // based on priority? + p.drawRect(rect()); + + int y = 0; + int d = 0; + + if ( ev.event().hasAlarm() ) { + p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) ); + y = 20; + d = 20; + } + + if ( ev.event().hasRepeat() ) { + p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) ); + d = 20; + } + + QSimpleRichText rt( text, font() ); + rt.setWidth( geom.width() - d - 6 ); + rt.draw( &p, 3, 0, e->region(), colorGroup() ); +} + +void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) +{ + QPopupMenu m; + m.insertItem( tr( "Edit" ), 1 ); + m.insertItem( tr( "Delete" ), 2 ); + m.insertItem( tr( "Beam" ), 3 ); + int r = m.exec( e->globalPos() ); + if ( r == 1 ) { + emit editMe( ev.event() ); + } else if ( r == 2 ) { + emit deleteMe( ev.event() ); + } else if ( r == 3 ) { + emit beamMe( ev.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(); +} diff --git a/core/pim/datebook/datebookday.h b/core/pim/datebook/datebookday.h new file mode 100644 index 0000000..531fded --- a/dev/null +++ b/core/pim/datebook/datebookday.h @@ -0,0 +1,138 @@ +/********************************************************************** +** 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. +** +**********************************************************************/ +#ifndef DATEBOOKDAY_H +#define DATEBOOKDAY_H + +#include + +#include +#include +#include +#include + +class DateBookDayHeader; +class DateBookDB; +class QDateTime; +class QMouseEvent; +class QPaintEvent; +class QResizeEvent; + +class DateBookDayView : public QTable +{ + Q_OBJECT +public: + DateBookDayView( bool hourClock, QWidget *parent, const char *name ); + bool whichClock() const; + +public slots: + void moveUp(); + void moveDown(); + +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 initHeader(); +private: + bool ampm; +}; + +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 editMe( const Event &e ); + void beamMe( const Event &e ); + +protected: + void paintEvent( QPaintEvent *e ); + void mousePressEvent( QMouseEvent *e ); + +private: + const EffectiveEvent ev; + DateBookDay *dateBook; + QString text; + QRect geom; +}; + +class DateBookDay : public QVBox +{ + Q_OBJECT + +public: + DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, + 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; + +public slots: + void setDate( int y, int m, int d ); + void setDate( QDate ); + void redraw(); + void slotWeekChanged( bool bStartOnMonday ); + +signals: + void removeEvent( const Event& ); + void editEvent( 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; + DateBookDB *db; + QList widgetList; + int startTime; +}; + +#endif diff --git a/core/pim/datebook/datebookdayheader.ui b/core/pim/datebook/datebookdayheader.ui new file mode 100644 index 0000000..8bc284f --- a/dev/null +++ b/core/pim/datebook/datebookdayheader.ui @@ -0,0 +1,424 @@ + +DateBookDayHeaderBase +/********************************************************************** +** Copyright (C) 2001 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$ +** +**********************************************************************/ + + QWidget + + name + DateBookDayHeaderBase + + + geometry + + 0 + 0 + 249 + 26 + + + + caption + Form1 + + + layoutMargin + + + layoutSpacing + + + + margin + 0 + + + spacing + 0 + + + QToolButton + + name + back + + + text + + + + pixmap + image0 + + + toggleButton + false + + + autoRepeat + true + + + autoRaise + true + + + toggleButton + false + + + toolTip + + + + + QToolButton + + name + date + + + sizePolicy + + 7 + 1 + + + + font + + 1 + + + + text + + + + pixmap + + + + autoRepeat + false + + + autoRaise + false + + + + QButtonGroup + + name + grpDays + + + frameShape + NoFrame + + + frameShadow + Plain + + + title + + + + exclusive + true + + + layoutMargin + + + layoutSpacing + + + + margin + 0 + + + spacing + 1 + + + QToolButton + + name + cmdDay1 + + + text + M + + + toggleButton + true + + + autoRaise + true + + + toggleButton + true + + + toolTip + + + + + QToolButton + + name + cmdDay2 + + + text + T + + + toggleButton + true + + + autoRaise + true + + + toggleButton + true + + + toolTip + + + + + QToolButton + + name + cmdDay3 + + + text + W + + + toggleButton + true + + + autoRaise + true + + + toggleButton + true + + + toolTip + + + + + QToolButton + + name + cmdDay4 + + + text + T + + + pixmap + + + + toggleButton + true + + + autoRepeat + false + + + autoRaise + true + + + toggleButton + true + + + toolTip + + + + + QToolButton + + name + cmdDay5 + + + text + F + + + toggleButton + true + + + autoRaise + true + + + toggleButton + true + + + toolTip + + + + + QToolButton + + name + cmdDay6 + + + text + S + + + toggleButton + true + + + autoRaise + true + + + toggleButton + true + + + toolTip + + + + + QToolButton + + name + cmdDay7 + + + text + S + + + toggleButton + true + + + autoRaise + true + + + toggleButton + true + + + toolTip + + + + + + + QToolButton + + name + forward + + + text + + + + pixmap + image1 + + + autoRepeat + true + + + autoRaise + true + + + + + + + image0 + 789c6dcfcd4e843010c0f13b4fd1d01b31bb6cb325211b1f41e3d1c4789876a60bcbd7aeae07637c773b6d5985d870e0f7ef50605b88e7a707516cb3f72b5c5b2b6c036fa2c08f61f87c79bdffcaf2dd5ef0558b5d7e97e51b61c5e33412df4b7f2fcbb09896a94ab557817063cd744cad74a915734aac35308740d018d9332d5ab0c8ec1229f2c2448d156a661b489ee1ab4e4cf2a08a790e24020abb0dd355442eec8e914e45526215790c749e8e89891069125de466b1fe14295705ccaa5863e2d05cc01894925b2a7e8217dd8a631eb169fd509af10fd1a9ebfbdf32008d9d0c07cd274f70ee162773ba2cdfee935c977ffe6b2edf87ec07796f81cd + + + image1 + 789c7dcfc94ec3301006e07b9ec28a6f114a13cbb1a8108f00e28884387819676993340b07847877329ea8697a60ec83bfdf232f8784bdbfbdb0e4104db39e6bcb6ca54796b8afb6fdfef87cfe89e25cb2650ac1f2f8218a5366d96bdf01aef9b2e65928a4458a0c07b25c29890352e63293e19c53a0968f52230159e8c22981744495133552097554a1f982b4ce6aeb9013d215165c81ec894e109b4070ca85378f2b35f18c04050214b20d04d010762ba457003eecd6442f88f34a45f4817ea147762b35d1acf4c47457d784737d9f18ebee1363614bf852c6f812b6c460f90abb6e93ba694ed7c49fdbaeee2f76b83da71ba772e0db5d9ccf4b07dfdd5e858edd9b2948fff9d796fc3e457f660e8d47 + + + + + forward + clicked() + DateBookDayHeaderBase + goForward() + + + back + clicked() + DateBookDayHeaderBase + goBack() + + + grpDays + clicked(int) + DateBookDayHeaderBase + setDay( int ) + + goBack() + goForward() + setDate( int, int, int ) + setDay( int ) + + diff --git a/core/pim/datebook/datebookdayheaderimpl.cpp b/core/pim/datebook/datebookdayheaderimpl.cpp new file mode 100644 index 0000000..fbcb3d2 --- a/dev/null +++ b/core/pim/datebook/datebookdayheaderimpl.cpp @@ -0,0 +1,181 @@ +/********************************************************************** +** 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. +** +**********************************************************************/ +#include "datebookdayheaderimpl.h" + +#include +#include + +#include +#include +#include +#include +#include + +/* + * 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(); + + 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::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 new file mode 100644 index 0000000..43f3a93 --- a/dev/null +++ b/core/pim/datebook/datebookdayheaderimpl.h @@ -0,0 +1,57 @@ +/********************************************************************** +** 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. +** +**********************************************************************/ +#ifndef DATEBOOKDAYHEADER_H +#define DATEBOOKDAYHEADER_H +#include "datebookdayheader.h" + +#include + +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 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 new file mode 100644 index 0000000..c5d8ac1 --- a/dev/null +++ b/core/pim/datebook/datebooksettings.cpp @@ -0,0 +1,135 @@ +/********************************************************************** +** 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. +** +**********************************************************************/ + +#include "datebooksettings.h" + +#include + +#include +#include +#include + +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 ) ) ); +} + +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::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 ); +} diff --git a/core/pim/datebook/datebooksettings.h b/core/pim/datebook/datebooksettings.h new file mode 100644 index 0000000..ee9f39c --- a/dev/null +++ b/core/pim/datebook/datebooksettings.h @@ -0,0 +1,48 @@ +/********************************************************************** +** 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. +** +**********************************************************************/ + +#ifndef DATEBOOKSETTINGS_H +#define DATEBOOKSETTINGS_H +#include "datebooksettingsbase.h" + +class DateBookSettings : public DateBookSettingsBase +{ +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; + +private slots: + void slot12Hour( int ); + void slotChangeClock( bool ); + +private: + void init(); + bool ampm; + int oldtime; +}; +#endif diff --git a/core/pim/datebook/datebooksettingsbase.ui b/core/pim/datebook/datebooksettingsbase.ui new file mode 100644 index 0000000..0f40773 --- a/dev/null +++ b/core/pim/datebook/datebooksettingsbase.ui @@ -0,0 +1,232 @@ + +DateBookSettingsBase +********************************************************************** +** 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$ +** +********************************************************************** + + QDialog + + name + DateBookSettingsBase + + + geometry + + 0 + 0 + 232 + 290 + + + + caption + Preferences + + + layoutMargin + + + layoutSpacing + + + + margin + 5 + + + spacing + 1 + + + QGroupBox + + name + fraStart + + + frameShape + Box + + + frameShadow + Sunken + + + title + Start viewing events + + + + margin + 11 + + + spacing + 6 + + + QLayoutWidget + + name + Layout1 + + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + lblStartTime + + + text + Start Time: + + + + QSpinBox + + name + spinStart + + + suffix + :00 + + + wrapping + true + + + maxValue + 23 + + + + + + + + QGroupBox + + name + fraAlarm + + + title + Alarm Settings + + + + margin + 11 + + + spacing + 6 + + + QLayoutWidget + + name + Layout6 + + + + margin + 0 + + + spacing + 6 + + + QCheckBox + + name + chkAlarmPreset + + + text + Alarm Preset + + + + QSpinBox + + name + spinPreset + + + enabled + false + + + suffix + minutes + + + maxValue + 180 + + + minValue + 0 + + + lineStep + 5 + + + value + 5 + + + + + + + + + + + chkAlarmPreset + toggled(bool) + spinPreset + setEnabled(bool) + + + spinStart + valueChanged(int) + DateBookSettingsBase + slot12Hour( int ) + + slotChangeClock( bool ) + slot12Hour( int ) + + diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp new file mode 100644 index 0000000..e9fcc39 --- a/dev/null +++ b/core/pim/datebook/datebookweek.cpp @@ -0,0 +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. +** +**********************************************************************/ +#include "datebookweek.h" +#include "datebookweekheaderimpl.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//----------------------------------------------------------------- + + +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 ) { + header->addLabel( tr("M", "Monday" ) ); + header->addLabel( tr("T", "Tuesday") ); + header->addLabel( tr("W", "Wednesday" ) ); + header->addLabel( tr("T", "Thursday" ) ); + header->addLabel( tr("F", "Friday" ) ); + header->addLabel( tr("S", "Saturday" ) ); + header->addLabel( tr("S", "Sunday" ) ); + } else { + header->addLabel( tr("S", "Sunday" ) ); + header->addLabel( tr("M", "Monday") ); + header->addLabel( tr("T", "Tuesday") ); + header->addLabel( tr("W", "Wednesday" ) ); + header->addLabel( tr("T", "Thursday" ) ); + header->addLabel( tr("F", "Friday" ) ); + header->addLabel( tr("S", "Saturday" ) ); + } + bFirst = false; + } else { + // we are change things... + if ( bOnMonday ) { + header->setLabel( 1, tr("M", "Monday") ); + header->setLabel( 2, tr("T", "Tuesday") ); + header->setLabel( 3, tr("W", "Wednesday" ) ); + header->setLabel( 4, tr("T", "Thursday" ) ); + header->setLabel( 5, tr("F", "Friday" ) ); + header->setLabel( 6, tr("S", "Saturday" ) ); + header->setLabel( 7, tr("S", "Sunday" ) ); + } else { + header->setLabel( 1, tr("S", "Sunday" ) ); + header->setLabel( 2, tr("M", "Monday") ); + header->setLabel( 3, tr("T", "Tuesday") ); + header->setLabel( 4, tr("W", "Wednesday" ) ); + header->setLabel( 5, tr("T", "Thursday" ) ); + header->setLabel( 6, tr("F", "Friday" ) ); + header->setLabel( 7, tr("S", "Saturday" ) ); + } + } +} + + + +void DateBookWeekView::showEvents( QValueList &ev ) +{ + items.clear(); + QValueListIterator it; + for ( it = ev.begin(); it != ev.end(); ++it ) { + DateBookWeekItem *i = new DateBookWeekItem( *it ); + 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() ); + if ( y > 47 ) + y = 47; + y = y * rowHeight / 2; + + int h; + if ( ev.event().type() == Event::AllDay ) { + h = 48; + y = 0; + } else { + h = ( ev.end().hour() - ev.start().hour() ) * 2; + h += db_round30min( ev.end().minute() - ev.start().minute() ); + if ( h < 1 ) h = 1; + } + h = h * 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 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 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 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 ); + 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, DateBookDB *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( int, int ) ), + this, SLOT( dateChanged( int, int ) ) ); + connect( tHide, SIGNAL( timeout() ), + lblDesc, SLOT( hide() ) ); + connect( header->spinYear, SIGNAL(valueChanged(int)), + this, SLOT(slotYearChanged(int)) ); + 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; + d = dateFromWeek( _week, year, bStartOnMonday ); + day--; + d = d.addDays( day ); + emit showDate( d.year(), d.month(), d.day() ); +} + +void DateBookWeek::setDate( int y, int m, int d ) +{ + QDate date; + date.setYMD( y, m, d ); + setDate(QDate(y, m, d)); +} + +void DateBookWeek::setDate(QDate date) +{ + dow = date.dayOfWeek(); + int w, y; + calcWeek( date, w, y, bStartOnMonday ); + header->setDate( y, w ); +} + +void DateBookWeek::dateChanged( int y, int w ) +{ + year = y; + _week = w; + getEvents(); +} + +QDate DateBookWeek::date() const +{ + QDate d; + d = dateFromWeek( _week - 1, year, bStartOnMonday ); + if ( bStartOnMonday ) + d = d.addDays( 7 + dow - 1 ); + else { + if ( dow == 7 ) + d = d.addDays( dow ); + else + d = d.addDays( 7 + dow ); + } + return d; +} + +void DateBookWeek::getEvents() +{ + QDate startWeek = weekDate(); + + QDate endWeek = startWeek.addDays( 6 ); + QValueList eventList = db->getEffectiveEvents(startWeek, + endWeek); + view->showEvents( eventList ); + view->moveToHour( startTime ); +} + +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 strNote = ev.notes(); + where = strNote.find( "<" ); + while ( where != -1 ) { + strNote.remove( where, 1 ); + strNote.insert( where, "<" ); + where = strNote.find( "<", where ); + } + + QString str = "" + strDesc + "
" + "" + + strCat + "" + + "
" + TimeString::longDateString( ev.date() ) + + "
" + QObject::tr("Start") + ": "; + + if ( ev.startDate() != ev.date() ) { + // multi-day event. Show start date + str += TimeString::longDateString( ev.startDate() ); + } else { + // Show start time. + str += TimeString::timeString(ev.start(), ampm, FALSE ); + } + + str += "
" + QObject::tr("End") + ": "; + if ( ev.endDate() != ev.date() ) { + // multi-day event. Show end date + str += TimeString::longDateString( ev.endDate() ); + } else { + // Show end time. + str += TimeString::timeString( ev.end(), ampm, FALSE ); + } + str += "

" + 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 ); + } + if ( totWeek != totalWeeks() ) + setTotalWeeks( totWeek ); +} + + +void DateBookWeek::setTotalWeeks( int numWeeks ) +{ + header->spinWeek->setMaxValue( numWeeks ); +} + +int DateBookWeek::totalWeeks() const +{ + return header->spinWeek->maxValue(); +} + +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 +{ + return dateFromWeek( _week, year, bStartOnMonday ); +} + +// 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 = false ) +{ + 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 new file mode 100644 index 0000000..6e675f1 --- a/dev/null +++ b/core/pim/datebook/datebookweek.h @@ -0,0 +1,152 @@ +/********************************************************************** +** 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. +** +**********************************************************************/ +#ifndef DATEBOOKWEEK +#define DATEBOOKWEEK + +#include + +#include +#include +#include +#include + +class DateBookDB; +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 &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 items; + int rowHeight; + bool showingEvent; +}; + +class DateBookWeek : public QWidget +{ + Q_OBJECT + +public: + DateBookWeek( bool ampm, bool weekOnMonday, DateBookDB *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; }; + void setTotalWeeks( int totalWeeks ); + int totalWeeks() const; + 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( int y, int w ); + void slotShowEvent( const EffectiveEvent & ); + void slotHideEvent(); + void slotYearChanged( int ); + +private: + void getEvents(); + int year; + int _week; + int dow; + DateBookWeekHeader *header; + DateBookWeekView *view; + DateBookDB *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/datebookweekheader.ui b/core/pim/datebook/datebookweekheader.ui new file mode 100644 index 0000000..dd6a5b1 --- a/dev/null +++ b/core/pim/datebook/datebookweekheader.ui @@ -0,0 +1,167 @@ + +DateBookWeekHeaderBase +********************************************************************* +** 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. +** +********************************************************************* + + QWidget + + name + DateBookWeekHeaderBase + + + geometry + + 0 + 0 + 281 + 30 + + + + caption + Form1 + + + layoutMargin + + + layoutSpacing + + + + margin + 0 + + + spacing + 6 + + + QSpinBox + + name + spinYear + + + sizePolicy + + 0 + 0 + + + + prefix + Y: + + + maxValue + 2037 + + + minValue + 1970 + + + value + 2002 + + + + QSpinBox + + name + spinWeek + + + sizePolicy + + 0 + 0 + + + + prefix + W: + + + maxValue + 52 + + + minValue + 1 + + + value + 1 + + + + QLabel + + name + labelDate + + + sizePolicy + + 3 + 1 + + + + font + + 1 + + + + text + 00. Jan-00. Jan + + + alignment + AlignCenter + + + hAlign + + + + + + + spinYear + valueChanged(int) + DateBookWeekHeaderBase + yearChanged( int ) + + + spinWeek + valueChanged(int) + DateBookWeekHeaderBase + weekChanged( int ) + + yearChanged( int ) + nextWeek() + prevWeek() + weekChanged( int ) + + diff --git a/core/pim/datebook/datebookweekheaderimpl.cpp b/core/pim/datebook/datebookweekheaderimpl.cpp new file mode 100644 index 0000000..e7c7208 --- a/dev/null +++ b/core/pim/datebook/datebookweekheaderimpl.cpp @@ -0,0 +1,126 @@ +/********************************************************************** +** 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. +** +**********************************************************************/ +#include "datebookweekheaderimpl.h" +#include +#include +#include + +/* + * 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 ); +} + +/* + * Destroys the object and frees any allocated resources + */ +DateBookWeekHeader::~DateBookWeekHeader() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * public slot + */ +void DateBookWeekHeader::yearChanged( int y ) +{ + setDate( y, week ); +} +/* + * public slot + */ +void DateBookWeekHeader::nextWeek() +{ + if ( week < 52 ) + week++; + setDate( year, week ); +} +/* + * public slot + */ +void DateBookWeekHeader::prevWeek() +{ + if ( week > 1 ) + week--; + setDate( year, week ); +} +/* + * public slot + */ +void DateBookWeekHeader::weekChanged( int w ) +{ + setDate( year, w ); +} + +void DateBookWeekHeader::setDate( int y, int w ) +{ + year = y; + week = w; + spinYear->setValue( y ); + spinWeek->setValue( w ); + + QDate d = dateFromWeek( week, year, bStartOnMonday ); + + QString s = QString::number( d.day() ) + ". " + d.monthName( d.month() ) + + "-"; + d = d.addDays( 6 ); + s += QString::number( d.day() ) + ". " + d.monthName( d.month() ); + labelDate->setText( s ); + + emit dateChanged( y, w ); +} + +void DateBookWeekHeader::setStartOfWeek( bool onMonday ) +{ + bStartOnMonday = onMonday; + setDate( year, week ); +} + +// dateFromWeek +// compute the date from the week in the year + +QDate dateFromWeek( int week, int year, bool startOnMonday ) +{ + QDate d; + d.setYMD( year, 1, 1 ); + int dayOfWeek = d.dayOfWeek(); + if ( startOnMonday ) { + if ( dayOfWeek <= 4 ) { + d = d.addDays( ( week - 1 ) * 7 - dayOfWeek + 1 ); + } else { + d = d.addDays( (week) * 7 - dayOfWeek + 1 ); + } + } else { + if ( dayOfWeek <= 4 || dayOfWeek == 7) { + d = d.addDays( ( week - 1 ) * 7 - dayOfWeek % 7 ); + } else { + d = d.addDays( ( week ) * 7 - dayOfWeek % 7 ); + } + } + return d; +} + diff --git a/core/pim/datebook/datebookweekheaderimpl.h b/core/pim/datebook/datebookweekheaderimpl.h new file mode 100644 index 0000000..2abef46 --- a/dev/null +++ b/core/pim/datebook/datebookweekheaderimpl.h @@ -0,0 +1,62 @@ +/********************************************************************** +** 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. +** +**********************************************************************/ +#ifndef DATEBOOKDAYHEADER_H +#define DATEBOOKDAYHEADER_H +#include +#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( int y, int w ); + void setStartOfWeek( bool onMonday ); + +signals: + void dateChanged( int y, int w ); + +public slots: + void yearChanged( int ); + void nextWeek(); + void prevWeek(); + void weekChanged( int ); + +protected slots: + void keyPressEvent(QKeyEvent *e) + { + e->ignore(); + } + +private: + int year, + week; + bool bStartOnMonday; + +}; + +QDate dateFromWeek( int week, int year, bool startOnMonday ); + +#endif // DATEBOOKDAYHEADER_H diff --git a/core/pim/datebook/dateentry.ui b/core/pim/datebook/dateentry.ui new file mode 100644 index 0000000..0c363a4 --- a/dev/null +++ b/core/pim/datebook/dateentry.ui @@ -0,0 +1,1095 @@ + +DateEntryBase +********************************************************************* +** 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$ +** +********************************************************************* + + QWidget + + name + DateEntryBase + + + geometry + + 0 + 0 + 242 + 339 + + + + caption + New Event + + + layoutMargin + + + layoutSpacing + + + + margin + 0 + + + spacing + 0 + + + QLabel + + name + TextLabel2 + + + frameShape + MShape + + + frameShadow + MShadow + + + text + Location + + + + QLabel + + name + TextLabel2_2 + + + text + Category + + + buddy + comboPriority + + + + QComboBox + + + text + (None) + + + + + text + Meeting + + + + + text + Lunch + + + + + text + Dinner + + + + + text + Travel + + + + name + comboDescription + + + sizePolicy + + 7 + 0 + + + + editable + true + + + currentItem + 0 + + + duplicatesEnabled + false + + + + QLabel + + name + TextLabel1 + + + text + Description: + + + + QComboBox + + + text + (Unknown) + + + + + text + Office + + + + + text + Home + + + + name + comboLocation + + + sizePolicy + + 7 + 0 + + + + editable + true + + + currentItem + 0 + + + duplicatesEnabled + false + + + + CategorySelect + + name + comboCategory + + + + QLabel + + name + TextLabel3 + + + text + Start + + + + QPushButton + + name + buttonStart + + + text + Jan 02 00 + + + + QComboBox + + + text + 00:00 + + + + + text + 00:30 + + + + + text + 01:00 + + + + + text + 01:30 + + + + + text + 02:00 + + + + + text + 02:30 + + + + + text + 03:00 + + + + + text + 03:30 + + + + + text + 04:00 + + + + + text + 04:30 + + + + + text + 05:00 + + + + + text + 05:30 + + + + + text + 06:00 + + + + + text + 06:30 + + + + + text + 07:00 + + + + + text + 07:30 + + + + + text + 08:00 + + + + + text + 08:30 + + + + + text + 09:00 + + + + + text + 09:30 + + + + + text + 10:00 + + + + + text + 10:30 + + + + + text + 11:00 + + + + + text + 11:30 + + + + + text + 12:00 + + + + + text + 12:30 + + + + + text + 13:00 + + + + + text + 13:30 + + + + + text + 14:00 + + + + + text + 14:30 + + + + + text + 15:00 + + + + + text + 15:30 + + + + + text + 16:00 + + + + + text + 16:30 + + + + + text + 17:00 + + + + + text + 17:30 + + + + + text + 18:00 + + + + + text + 18:30 + + + + + text + 19:00 + + + + + text + 19:30 + + + + + text + 20:00 + + + + + text + 20:30 + + + + + text + 21:00 + + + + + text + 21:30 + + + + + text + 22:00 + + + + + text + 22:30 + + + + + text + 23:00 + + + + + text + 23:30 + + + + name + comboStart + + + editable + true + + + duplicatesEnabled + false + + + + QPushButton + + name + buttonEnd + + + text + Jan 02 00 + + + + QComboBox + + + text + 00:00 + + + + + text + 00:30 + + + + + text + 01:00 + + + + + text + 01:30 + + + + + text + 02:00 + + + + + text + 02:30 + + + + + text + 03:00 + + + + + text + 03:30 + + + + + text + 04:00 + + + + + text + 04:30 + + + + + text + 05:00 + + + + + text + 05:30 + + + + + text + 06:00 + + + + + text + 06:30 + + + + + text + 07:00 + + + + + text + 07:30 + + + + + text + 08:00 + + + + + text + 08:30 + + + + + text + 09:00 + + + + + text + 09:30 + + + + + text + 10:00 + + + + + text + 10:30 + + + + + text + 11:00 + + + + + text + 11:30 + + + + + text + 12:00 + + + + + text + 12:30 + + + + + text + 13:00 + + + + + text + 13:30 + + + + + text + 14:00 + + + + + text + 14:30 + + + + + text + 15:00 + + + + + text + 15:30 + + + + + text + 16:00 + + + + + text + 16:30 + + + + + text + 17:00 + + + + + text + 17:30 + + + + + text + 18:00 + + + + + text + 18:30 + + + + + text + 19:00 + + + + + text + 19:30 + + + + + text + 20:00 + + + + + text + 20:30 + + + + + text + 21:00 + + + + + text + 21:30 + + + + + text + 22:00 + + + + + text + 22:30 + + + + + text + 23:00 + + + + + text + 23:30 + + + + name + comboEnd + + + editable + true + + + duplicatesEnabled + false + + + + QLabel + + name + TextLabel3_2 + + + text + End + + + + QCheckBox + + name + checkAllDay + + + text + All day + + + + QLabel + + name + TextLabel3_2_2 + + + text + Time zone: + + + + TimeZoneSelector + + name + timezone + + + + QCheckBox + + name + checkAlarm + + + enabled + true + + + autoMask + false + + + text + &Alarm + + + checked + false + + + + QSpinBox + + name + spinAlarm + + + enabled + false + + + suffix + minutes + + + maxValue + 180 + + + minValue + 0 + + + lineStep + 5 + + + value + 5 + + + + QComboBox + + + text + Silent + + + + + text + Loud + + + + name + comboSound + + + enabled + false + + + + QLabel + + name + lblRepeat + + + text + Repeat + + + + QToolButton + + name + cmdRepeat + + + focusPolicy + TabFocus + + + text + No Repeat... + + + + QMultiLineEdit + + name + editNote + + + + + + + TimeZoneSelector +
qpe/tzselect.h
+ + 21 + 10 + + 0 + + 7 + 1 + + image0 +
+ + CategorySelect +
qpe/categoryselect.h
+ + -1 + -1 + + 0 + + 7 + 1 + + image1 +
+
+ + + image0 + 789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade6523250004143a55a6b2e0026630c4f + + + image1 + 789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758 + + + + + checkAlarm + toggled(bool) + spinAlarm + setEnabled(bool) + + + comboEnd + activated(const QString&) + DateEntryBase + endTimeChanged( const QString & ) + + + cmdRepeat + clicked() + DateEntryBase + slotRepeat() + + + comboStart + activated(int) + DateEntryBase + startTimeChanged( int ) + + + checkAllDay + toggled(bool) + comboEnd + setDisabled(bool) + + + checkAlarm + toggled(bool) + comboSound + setEnabled(bool) + + + checkAllDay + toggled(bool) + comboStart + setDisabled(bool) + + endDateChanged( const QString & ) + endDateChanged( int, int, int ) + endTimeChanged( const QString & ) + slotRepeat() + slotWait( int ) + startDateChanged( const QString & ) + startDateChanged(int, int, int) + startTimeChanged( int ) + typeChanged( const QString & ) + tzexecute(void) + +
diff --git a/core/pim/datebook/dateentryimpl.cpp b/core/pim/datebook/dateentryimpl.cpp new file mode 100644 index 0000000..1122f79 --- a/dev/null +++ b/core/pim/datebook/dateentryimpl.cpp @@ -0,0 +1,474 @@ +/********************************************************************** +** 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. +** +**********************************************************************/ + +#include "dateentryimpl.h" +#include "repeatentry.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/* + * 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 ) +{ + init(); + setDates(start,end); +} + +static void addOrPick( QComboBox* combo, const QString& t ) +{ + for (int i=0; icount(); i++) { + if ( combo->text(i) == t ) { + combo->setCurrentItem(i); + return; + } + } + combo->setEditText(t); +} + +DateEntry::DateEntry( bool startOnMonday, const Event &event, bool whichClock, + QWidget* parent, const char* name ) + : DateEntryBase( parent, name ), + ampm( whichClock ), + startWeekOnMonday( startOnMonday ) +{ + 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()) + editNote->setText(event.notes()); + 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 ) +{ + int shour, + ehour; + QString strStart, + strEnd; + startDate = s.date(); + endDate = e.date(); + startTime = s.time(); + endTime = e.time(); + startDateChanged( s.date().year(), s.date().month(), s.date().day() ); + if ( ampm ) { + shour = s.time().hour(); + ehour = e.time().hour(); + if ( shour >= 12 ) { + if ( shour > 12 ) + shour -= 12; + strStart.sprintf( "%d:%02d PM", shour, s.time().minute() ); + } else { + if ( shour == 0 ) + shour = 12; + strStart.sprintf( "%d:%02d AM", shour, s.time().minute() ); + } + if ( ehour == 24 && e.time().minute() == 0 ) { + strEnd = "11:59 PM"; // or "midnight" + } else if ( ehour >= 12 ) { + if ( ehour > 12 ) + ehour -= 12; + strEnd.sprintf( "%d:%02d PM", ehour, e.time().minute() ); + } else { + if ( ehour == 0 ) + ehour = 12; + strEnd.sprintf( "%d:%02d AM", ehour, e.time().minute() ); + } + } else { + strStart.sprintf( "%02d:%02d", s.time().hour(), s.time().minute() ); + strEnd.sprintf( "%02d:%02d", e.time().hour(), e.time().minute() ); + } + addOrPick(comboStart, strStart ); + endDateChanged( e.date().year(), e.date().month(), e.date().day() ); + addOrPick(comboEnd, 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)) ); + + 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 ) ) ); +} + +/* + * Destroys the object and frees any allocated resources + */ +DateEntry::~DateEntry() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * public slot + */ +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='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 ) +{ + QTime tmpTime = parseTime(s,ampm); + if ( endDate > startDate || tmpTime >= startTime ) { + endTime = tmpTime; + } else { + endTime = startTime; + comboEnd->setCurrentItem( comboStart->currentItem() ); + } +} + +/* + * 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::startTimeChanged( int index ) +{ + startTime = parseTime(comboStart->text(index),ampm); + changeEndCombo( index ); +} +/* + * public slot + */ +void DateEntry::typeChanged( const QString &s ) +{ + bool b = s != "All Day"; + buttonStart->setEnabled( b ); + comboStart->setEnabled( b ); + comboEnd->setEnabled( b ); +} +/* + * public slot + */ +void DateEntry::changeEndCombo( int change ) +{ + if ( change + 2 < comboEnd->count() ) + change += 2; + comboEnd->setCurrentItem( change ); + endTimeChanged( comboEnd->currentText() ); +} + +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 defined(Q_WS_QWS) || defined(_WS_QWS_) + e->showMaximized(); +#endif + if ( e->exec() ) { + rp = e->repeatPattern(); + setRepeatLabel(); + } +} + +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; + } + startTime = parseTime( comboStart->currentText(), ampm ); + endTime = parseTime( comboEnd->currentText(), 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; + +// qDebug( "tz: %s", timezone->currentZone().latin1() ); + + // get real timezone + QString realTZ; + realTZ = QString::fromLocal8Bit( getenv("TZ") ); + + // set timezone + if ( setenv( "TZ", timezone->currentZone(), true ) != 0 ) + qWarning( "There was a problem setting the timezone." ); + + // 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 ) + qWarning( "There was a problem setting the timezone." ); + + // 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( editNote->text() ); + 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 new file mode 100644 index 0000000..785af7a --- a/dev/null +++ b/core/pim/datebook/dateentryimpl.h @@ -0,0 +1,71 @@ +/********************************************************************** +** 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. +** +**********************************************************************/ +#ifndef DATEENTRY_H +#define DATEENTRY_H + +#include "dateentry.h" + +#include + +#include + +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 ); + +public slots: + void endDateChanged( int, int, int ); + void endTimeChanged( const QString & ); + void startDateChanged(int, int, int); + void startTimeChanged( int index ); + void typeChanged( const QString & ); + void changeEndCombo( int change ); + void slotRepeat(); + void slotChangeClock( bool ); + void slotChangeStartOfWeek( bool ); + +private: + void init(); + void initCombos(); + void setDates( const QDateTime& s, const QDateTime& e ); + void setRepeatLabel(); + + DateBookMonth *startPicker, *endPicker; + QDate startDate, endDate; + QTime startTime, endTime; + Event::RepeatPattern rp; + bool ampm; + bool startWeekOnMonday; +}; + +#endif // DATEENTRY_H diff --git a/core/pim/datebook/main.cpp b/core/pim/datebook/main.cpp new file mode 100644 index 0000000..caa5fb6 --- a/dev/null +++ b/core/pim/datebook/main.cpp @@ -0,0 +1,38 @@ +/********************************************************************** +** 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. +** +**********************************************************************/ + +#include "datebook.h" +#include + + +int main( int argc, char **argv ) +{ + QPEApplication a( argc, argv ); + + DateBook e; + QObject::connect( &a, SIGNAL( flush() ), &e, SLOT( flush() ) ); + QObject::connect( &a, SIGNAL( reload() ), &e, SLOT( reload() ) ); + + + e.setCaption( DateBook::tr("Calendar") ); + a.showMainWidget(&e); + + return a.exec(); +} diff --git a/core/pim/datebook/qpe-datebook.control b/core/pim/datebook/qpe-datebook.control new file mode 100644 index 0000000..c6ab81a --- a/dev/null +++ b/core/pim/datebook/qpe-datebook.control @@ -0,0 +1,9 @@ +Files: bin/datebook apps/Applications/datebook.desktop +Priority: optional +Section: qpe/applications +Maintainer: Warwick Allison +Architecture: arm +Version: $QPE_VERSION-3 +Depends: qpe-base ($QPE_VERSION) +Description: A datebook/appointment manager + A datebook/appointment manager for the Qtopia environment. diff --git a/core/pim/datebook/repeatentry.cpp b/core/pim/datebook/repeatentry.cpp new file mode 100644 index 0000000..5637c4d --- a/dev/null +++ b/core/pim/datebook/repeatentry.cpp @@ -0,0 +1,595 @@ +/********************************************************************** +** 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. +** +**********************************************************************/ + +#include "repeatentry.h" + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +// Global Templates for use in setting up the repeat label... +const QString strDayTemplate = QObject::tr("Every"); +const QString strYearTemplate = QObject::tr("%1 %2 every "); +const QString strMonthDateTemplate = QObject::tr("The %1 every "); +const QString strMonthDayTemplate = QObject::tr("The %1 %1 of every"); +const QString strWeekTemplate = QObject::tr("Every "); +const QString dayLabel[] = { QObject::tr("Monday"), + QObject::tr("Tuesday"), + QObject::tr("Wednesday"), + QObject::tr("Thursday"), + QObject::tr("Friday"), + QObject::tr("Saturday"), + 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 ) +{ + 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 ) +{ + // 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 it( listRTypeButtons ); + QListIterator 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(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 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( "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 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 new file mode 100644 index 0000000..949fecd --- a/dev/null +++ b/core/pim/datebook/repeatentry.h @@ -0,0 +1,98 @@ +/********************************************************************** +** 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. +** +**********************************************************************/ + +#ifndef REPEATENTRY_H +#define REPEATENTRY_H + +#include "repeatentrybase.h" + +#include + +#include +#include +#include +#include +#include + +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 listRTypeButtons; + QList 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 it( listExtra ); + for ( ; *it; ++it ) { + (*it)->hide(); + (*it)->setOn( FALSE ); + } + +} + +#endif diff --git a/core/pim/datebook/repeatentrybase.ui b/core/pim/datebook/repeatentrybase.ui new file mode 100644 index 0000000..9621d74 --- a/dev/null +++ b/core/pim/datebook/repeatentrybase.ui @@ -0,0 +1,713 @@ + +RepeatEntryBase +********************************************************************* +** 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$ +** +********************************************************************* + + QDialog + + name + RepeatEntryBase + + + geometry + + 0 + 0 + 250 + 309 + + + + caption + Repeating Event + + + layoutMargin + + + layoutSpacing + + + + margin + 5 + + + spacing + 1 + + + QButtonGroup + + name + fraType + + + frameShape + NoFrame + + + frameShadow + Sunken + + + title + + + + exclusive + true + + + layoutMargin + + + layoutSpacing + + + + margin + 5 + + + spacing + 1 + + + QToolButton + + name + cmdNone + + + text + None + + + toggleButton + true + + + toggleButton + true + + + + QToolButton + + name + cmdDay + + + text + Day + + + toggleButton + true + + + toggleButton + true + + + + QToolButton + + name + cmdWeek + + + sizePolicy + + 1 + 0 + + + + text + Week + + + toggleButton + true + + + toggleButton + true + + + + QToolButton + + name + cmdMonth + + + sizePolicy + + 1 + 0 + + + + text + Month + + + toggleButton + true + + + toggleButton + true + + + + QToolButton + + name + cmdYear + + + text + Year + + + toggleButton + true + + + toggleButton + true + + + + + + QLayoutWidget + + name + Layout4 + + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + lblEvery + + + text + Every: + + + + QSpinBox + + name + spinFreq + + + minValue + 1 + + + + QLabel + + name + lblFreq + + + sizePolicy + + 1 + 1 + + + + text + Frequency + + + + + + QLayoutWidget + + name + Layout8 + + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + lblEnd + + + sizePolicy + + 1 + 0 + + + + text + End On: + + + + QToolButton + + name + cmdEnd + + + text + No End Date + + + + QCheckBox + + name + chkNoEnd + + + text + No End Date + + + + + + QButtonGroup + + name + fraExtra + + + sizePolicy + + 7 + 7 + + + + frameShape + Box + + + title + Repeat On + + + layoutMargin + + + layoutSpacing + + + + margin + 5 + + + spacing + 1 + + + QToolButton + + name + cmdExtra1 + + + text + Mon + + + toggleButton + true + + + toggleButton + true + + + + QToolButton + + name + cmdExtra2 + + + text + Tue + + + toggleButton + true + + + toggleButton + true + + + + QToolButton + + name + cmdExtra3 + + + text + Wed + + + toggleButton + true + + + toggleButton + true + + + + QToolButton + + name + cmdExtra4 + + + text + Thu + + + toggleButton + true + + + toggleButton + true + + + + QToolButton + + name + cmdExtra5 + + + text + Fri + + + toggleButton + true + + + toggleButton + true + + + + QToolButton + + name + cmdExtra6 + + + text + Sat + + + toggleButton + true + + + toggleButton + true + + + + QToolButton + + name + cmdExtra7 + + + text + Sun + + + toggleButton + true + + + toggleButton + true + + + + + + QFrame + + name + Frame3 + + + sizePolicy + + 7 + 7 + + + + frameShape + Box + + + frameShadow + Sunken + + + layoutMargin + + + layoutSpacing + + + + margin + 5 + + + spacing + 1 + + + QLayoutWidget + + name + Layout6 + + + layoutSpacing + + + + margin + 0 + + + spacing + 0 + + + QLabel + + name + lblRepeat + + + sizePolicy + + 1 + 3 + + + + text + Every + + + alignment + AlignTop|AlignLeft + + + hAlign + + + vAlign + + + + QLabel + + name + lblVar1 + + + sizePolicy + + 1 + 1 + + + + text + Var1 + + + alignment + AlignTop|AlignLeft + + + hAlign + + + vAlign + + + + QLabel + + name + lblVar2 + + + sizePolicy + + 4 + 1 + + + + text + Var 2 + + + alignment + AlignTop|AlignRight + + + hAlign + + + vAlign + + + + + + QLabel + + name + lblWeekVar + + + sizePolicy + + 1 + 7 + + + + text + WeekVar + + + alignment + AlignTop|AlignHCenter + + + hAlign + + + vAlign + + + + + + + + + chkNoEnd + toggled(bool) + cmdEnd + setDisabled(bool) + + + chkNoEnd + toggled(bool) + RepeatEntryBase + slotNoEnd(bool) + + + spinFreq + valueChanged(int) + lblVar1 + setNum(int) + + + spinFreq + valueChanged(int) + RepeatEntryBase + setupRepeatLabel( int ) + + + fraType + clicked(int) + RepeatEntryBase + slotSetRType( int ) + + + fraExtra + clicked(int) + RepeatEntryBase + slotMonthLabel( int ) + + + fraExtra + clicked(int) + RepeatEntryBase + slotWeekLabel() + + setupRepeatLabel( const QString & ) + setupRepeatLabel( int ) + slotMonthLabel( int ) + slotNoEnd(bool) + slotSetRType( int ) + slotWeekLabel() + + -- cgit v0.9.0.2