Diffstat (limited to 'korganizer/koeditorrecurrence.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | korganizer/koeditorrecurrence.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/korganizer/koeditorrecurrence.cpp b/korganizer/koeditorrecurrence.cpp index 4209e10..bedc75a 100644 --- a/korganizer/koeditorrecurrence.cpp +++ b/korganizer/koeditorrecurrence.cpp @@ -1,172 +1,173 @@ /* This file is part of KOrganizer. Copyright (c) 2000-2003 Cornelius Schumacher <schumacher@kde.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include <qtooltip.h> #include <qfiledialog.h> #include <qlayout.h> #include <qvbox.h> #include <qbuttongroup.h> #include <qvgroupbox.h> #include <qwidgetstack.h> #include <qdatetime.h> #include <qlistbox.h> #include <qspinbox.h> #include <qcheckbox.h> #include <qapplication.h> #include <kdialog.h> #include <kglobal.h> #include <klocale.h> #include <kiconloader.h> #include <kdebug.h> #include <knumvalidator.h> #include <libkcal/event.h> +#include <libkcal/todo.h> #include <libkdepim/kdateedit.h> #include "koprefs.h" #include "koeditorrecurrence.h" /////////////////////////// RecurBase /////////////////////////////// RecurBase::RecurBase( QWidget *parent, const char *name ) : QWidget( parent, name ) { mFrequencyEdit = new QSpinBox( 1, 9999, 1, this ); mFrequencyEdit->setValue( 1 ); } QWidget *RecurBase::frequencyEdit() { return mFrequencyEdit; } void RecurBase::setFrequency( int f ) { if ( f < 1 ) f = 1; mFrequencyEdit->setValue( f ); } int RecurBase::frequency() { return mFrequencyEdit->value(); } /////////////////////////// RecurDaily /////////////////////////////// RecurDaily::RecurDaily( QWidget *parent, const char *name ) : RecurBase( parent, name ) { QBoxLayout *topLayout = new QHBoxLayout( this ); topLayout->setSpacing( KDialog::spacingHint() ); QLabel *preLabel = new QLabel( i18n("Recur every"), this ); topLayout->addWidget( preLabel ); topLayout->addWidget( frequencyEdit() ); QLabel *postLabel = new QLabel( i18n("day(s)"), this ); topLayout->addWidget( postLabel ); } /////////////////////////// RecurWeekly /////////////////////////////// RecurWeekly::RecurWeekly( QWidget *parent, const char *name ) : RecurBase( parent, name ) { QBoxLayout *topLayout = new QVBoxLayout( this ); topLayout->setSpacing( KDialog::spacingHint() ); topLayout->addStretch( 1 ); QBoxLayout *weeksLayout = new QHBoxLayout( topLayout ); QLabel *preLabel = new QLabel( i18n("Recur every"), this ); weeksLayout->addWidget( preLabel ); weeksLayout->addWidget( frequencyEdit() ); QLabel *postLabel = new QLabel( i18n("week(s) on:"), this ); weeksLayout->addWidget( postLabel ); QHBox *dayBox = new QHBox( this ); topLayout->addWidget( dayBox, 1, AlignVCenter ); // TODO: Respect start of week setting for ( int i = 0; i < 7; ++i ) { QString weekDayName = KGlobal::locale()->weekDayName( i + 1, true ); if ( KOPrefs::instance()->mCompactDialogs ) { weekDayName = weekDayName.left( 1 ); } mDayBoxes[ i ] = new QCheckBox( weekDayName, dayBox ); } topLayout->addStretch( 1 ); } void RecurWeekly::setDays( const QBitArray &days ) { for ( int i = 0; i < 7; ++i ) { mDayBoxes[ i ]->setChecked( days.testBit( i ) ); } } QBitArray RecurWeekly::days() { QBitArray days( 7 ); for ( int i = 0; i < 7; ++i ) { days.setBit( i, mDayBoxes[ i ]->isChecked() ); } return days; } /////////////////////////// RecurMonthly /////////////////////////////// RecurMonthly::RecurMonthly( QWidget *parent, const char *name ) : RecurBase( parent, name ) { QBoxLayout *topLayout = new QVBoxLayout( this ); topLayout->setSpacing( KDialog::spacingHint() ); QBoxLayout *freqLayout = new QHBoxLayout( topLayout ); QLabel *preLabel = new QLabel( i18n("every"), this ); freqLayout->addWidget( preLabel ); freqLayout->addWidget( frequencyEdit() ); QLabel *postLabel = new QLabel( i18n("month(s)"), this ); freqLayout->addWidget( postLabel ); QButtonGroup *buttonGroup = new QButtonGroup( this ); buttonGroup->setFrameStyle( QFrame::NoFrame ); topLayout->addWidget( buttonGroup, 1, AlignVCenter ); QGridLayout *buttonLayout = new QGridLayout( buttonGroup, 3, 2 ); @@ -780,360 +781,367 @@ KOEditorRecurrence::KOEditorRecurrence( QWidget* parent, const char *name ) : mDaily = new RecurDaily( mRuleStack ); mRuleStack->addWidget( mDaily, 0 ); mWeekly = new RecurWeekly( mRuleStack ); mRuleStack->addWidget( mWeekly, 0 ); mMonthly = new RecurMonthly( mRuleStack ); mRuleStack->addWidget( mMonthly, 0 ); mYearly = new RecurYearly( mRuleStack ); mRuleStack->addWidget( mYearly, 0 ); showCurrentRule( mRecurrenceChooser->type() ); if ( KOPrefs::instance()->mCompactDialogs ) { mRecurrenceRangeWidget = 0; mRecurrenceRangeDialog = new RecurrenceRangeDialog( this ); mRecurrenceRange = mRecurrenceRangeDialog; mRecurrenceRangeButton = new QPushButton( i18n("Recurrence Range..."), this ); connect( mRecurrenceRangeButton, SIGNAL( clicked() ), SLOT( showRecurrenceRangeDialog() ) ); mExceptionsWidget = 0; mExceptionsDialog = new ExceptionsDialog( this ); mExceptions = mExceptionsDialog; mExceptionsButton = new QPushButton( i18n("Exceptions..."), this ); if ( QApplication::desktop()->width() < 320 ) { topLayout->addMultiCellWidget( mRecurrenceRangeButton, 3, 3, 0, 1 ); topLayout->addMultiCellWidget( mExceptionsButton, 4, 4, 0, 1 ); } else { topLayout->addWidget( mRecurrenceRangeButton, 3, 0 ); topLayout->addWidget( mExceptionsButton, 3, 1 ); } connect( mExceptionsButton, SIGNAL( clicked() ), SLOT( showExceptionsDialog() ) ); } else { mRecurrenceRangeWidget = new RecurrenceRangeWidget( this ); mRecurrenceRangeDialog = 0; mRecurrenceRange = mRecurrenceRangeWidget; mRecurrenceRangeButton = 0; topLayout->addWidget( mRecurrenceRangeWidget, 3, 0 ); mExceptionsWidget = new ExceptionsWidget( this ); mExceptionsDialog = 0; mExceptions = mExceptionsWidget; mExceptionsButton = 0; topLayout->addWidget( mExceptionsWidget, 3, 1 ); } } KOEditorRecurrence::~KOEditorRecurrence() { } void KOEditorRecurrence::setEnabled( bool enabled ) { // kdDebug() << "KOEditorRecurrence::setEnabled(): " << (enabled ? "on" : "off") << endl; mTimeGroupBox->setEnabled( enabled ); if ( mRecurrenceRangeWidget ) mRecurrenceRangeWidget->setEnabled( enabled ); if ( mRecurrenceRangeButton ) mRecurrenceRangeButton->setEnabled( enabled ); if ( mExceptionsWidget ) mExceptionsWidget->setEnabled( enabled ); if ( mExceptionsButton ) mExceptionsButton->setEnabled( enabled ); mRuleBox->setEnabled( enabled ); } void KOEditorRecurrence::showCurrentRule( int current ) { switch ( current ) { case Daily: mRuleStack->raiseWidget( mDaily ); break; case Weekly: mRuleStack->raiseWidget( mWeekly ); break; case Monthly: mRuleStack->raiseWidget( mMonthly ); break; default: case Yearly: mRuleStack->raiseWidget( mYearly ); break; } } void KOEditorRecurrence::setDateTimes( QDateTime start, QDateTime end ) { // kdDebug() << "KOEditorRecurrence::setDateTimes" << endl; mRecurrenceRange->setDateTimes( start, end ); mExceptions->setDefaults( end ); } void KOEditorRecurrence::setDefaults( QDateTime from, QDateTime to, bool ) { // qDebug("KOEditorRecurrence::setDefaults %s %s ",from.toString().latin1(),to.toString().latin1() ); setDateTimes( from, to ); bool enabled = false; mEnabledCheck->setChecked( enabled ); setEnabled( enabled ); mExceptions->setDefaults( to ); mRecurrenceRange->setDefaults( to ); mRecurrenceChooser->setType( RecurrenceChooser::Weekly ); showCurrentRule( mRecurrenceChooser->type() ); mDaily->setFrequency( 1 ); mWeekly->setFrequency( 1 ); QBitArray days( 7 ); days.fill( 0 ); days.setBit( from.date().dayOfWeek()- 1); mWeekly->setDays( days ); mMonthly->setFrequency( 1 ); mMonthly->setByPos((from.date().day()/7), from.date().dayOfWeek()-1 ); mMonthly->setByDay( from.date().day()-1 ); mYearly->setFrequency( 1 ); mYearly->setByDay( from.date().dayOfYear() ); mYearly->setByMonth( from.date().month(), from.date().day() ); } -void KOEditorRecurrence::readEvent(Event *event) +void KOEditorRecurrence::readEvent(Incidence *event) { - setDefaults( event->dtStart(), event->dtEnd(), true ); + + QDateTime dtEnd; + if ( event->type() == "Event" ) + dtEnd = ((Event*)event)->dtEnd(); + else + dtEnd = ((Todo*)event)->dtDue(); + + setDefaults( event->dtStart(), dtEnd, true ); QBitArray rDays( 7 ); QPtrList<Recurrence::rMonthPos> rmp; QPtrList<int> rmd; int day = 0; int count = 0; int month = 0; - setDateTimes( event->dtStart(), event->dtEnd() ); + setDateTimes( event->dtStart(), dtEnd ); Recurrence *r = event->recurrence(); int f = r->frequency(); int recurs = r->doesRecur(); mEnabledCheck->setChecked( recurs ); setEnabled( recurs ); int recurrenceType = RecurrenceChooser::Weekly; switch ( recurs ) { case Recurrence::rNone: - setDefaults( event->dtStart(), event->dtEnd(), true ); + setDefaults( event->dtStart(), dtEnd, true ); break; case Recurrence::rDaily: recurrenceType = RecurrenceChooser::Daily; mDaily->setFrequency( f ); break; case Recurrence::rWeekly: recurrenceType = RecurrenceChooser::Weekly; mWeekly->setFrequency( f ); mWeekly->setDays( r->days() ); break; case Recurrence::rMonthlyPos: // we only handle one possibility in the list right now, // so I have hardcoded calls with first(). If we make the GUI // more extended, this can be changed. recurrenceType = RecurrenceChooser::Monthly; rmp = r->monthPositions(); if ( rmp.first()->negative ) count = 5 - rmp.first()->rPos - 1; else count = rmp.first()->rPos - 1; day = 0; while ( !rmp.first()->rDays.testBit( day ) ) ++day; mMonthly->setByPos( count, day ); mMonthly->setFrequency( f ); break; case Recurrence::rMonthlyDay: recurrenceType = RecurrenceChooser::Monthly; rmd = r->monthDays(); day = *rmd.first() - 1; mMonthly->setByDay( day ); mMonthly->setFrequency( f ); break; case Recurrence::rYearlyMonth: { recurrenceType = RecurrenceChooser::Yearly; qDebug("Recurrence::rYearlyMonth: "); day = event->dtStart().date().day(); rmd = r->yearNums(); if ( rmd.count() > 0 ) month = *rmd.first(); else month = event->dtStart().date().month() ; mYearly->setByMonth( month, day ); #if 0 qDebug("2day = %d ",day ); QPtrList<Recurrence::rMonthPos> monthlist = r->yearMonthPositions(); int month; if ( !monthlist.isEmpty() ) { month = monthlist.first()->rPos ; } else { month = event->dtStart().date().month() ; } mYearly->setByMonth( day, month ); #endif mYearly->setFrequency( f ); } break; case Recurrence::rYearlyDay: qDebug("Recurrence::rYearlyDay: "); recurrenceType = RecurrenceChooser::Yearly; mYearly->setByDay( event->dtStart().date().dayOfYear() ); mYearly->setFrequency( f ); break; default: - setDefaults( event->dtStart(), event->dtEnd(), true ); + setDefaults( event->dtStart(), dtEnd, true ); break; } mRecurrenceChooser->setType( recurrenceType ); showCurrentRule( recurrenceType ); mRecurrenceRange->setDateTimes( event->dtStart() ); if ( r->doesRecur() ) { mRecurrenceRange->setDuration( r->duration() ); if ( r->duration() == 0 ) { if ( r->endDate() < event->dtStart().date() ) mRecurrenceRange->setEndDate( event->dtStart().date() ); else mRecurrenceRange->setEndDate( r->endDate() ); } else mRecurrenceRange->setEndDate( event->dtStart().date() ); } mExceptions->setDates( event->exDates() ); } -void KOEditorRecurrence::writeEvent( Event *event ) +void KOEditorRecurrence::writeEvent( Incidence *event ) { Recurrence *r = event->recurrence(); // clear out any old settings; r->unsetRecurs(); if ( mEnabledCheck->isChecked() ) { int duration = mRecurrenceRange->duration(); QDate endDate; if ( duration == 0 ) endDate = mRecurrenceRange->endDate(); int recurrenceType = mRecurrenceChooser->type(); if ( recurrenceType == RecurrenceChooser::Daily ) { int freq = mDaily->frequency(); if ( duration != 0 ) r->setDaily( freq, duration ); else r->setDaily( freq, endDate ); } else if ( recurrenceType == RecurrenceChooser::Weekly ) { int freq = mWeekly->frequency(); QBitArray days = mWeekly->days(); int j; bool found = false; for (j = 0; j < 7 ; ++j ) { found |=days.at(j); } if ( !found ) { days.setBit( event->dtStart().date().dayOfWeek()-1); qDebug("bit set %d ", event->dtStart().date().dayOfWeek()-1); } if ( duration != 0 ) r->setWeekly( freq, days, duration ); else r->setWeekly( freq, days, endDate ); } else if ( recurrenceType == RecurrenceChooser::Monthly ) { int freq = mMonthly->frequency(); if ( mMonthly->byPos() ) { int pos = mMonthly->count(); QBitArray days( 7 ); days.fill( false ); days.setBit( mMonthly->weekday() ); if ( duration != 0 ) r->setMonthly( Recurrence::rMonthlyPos, freq, duration ); else r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); r->addMonthlyPos( pos, days ); } else { // it's by day int day = mMonthly->day(); if ( duration != 0 ) { r->setMonthly( Recurrence::rMonthlyDay, freq, duration ); } else { r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); } r->addMonthlyDay( day ); } } else if ( recurrenceType == RecurrenceChooser::Yearly ) { qDebug("RecurrenceChooser::Yearly "); int freq = mYearly->frequency(); if ( mYearly->byDay() ) { if ( duration != 0 ) { r->setYearly( Recurrence::rYearlyDay, freq, duration ); } else { r->setYearly( Recurrence::rYearlyDay, freq, endDate ); } r->addYearlyNum( event->dtStart().date().dayOfYear() ); } else { if ( duration != 0 ) { r->setYearly( Recurrence::rYearlyMonth, freq, duration ); } else { r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); } r->addYearlyNum( mYearly->month() ); } } event->setExDates( mExceptions->dates() ); } } void KOEditorRecurrence::setDateTimeStr( const QString &str ) { mDateTimeLabel->setText( str ); } bool KOEditorRecurrence::validateInput() { // Check input here return true; } void KOEditorRecurrence::showExceptionsDialog() { DateList dates = mExceptions->dates(); int result = mExceptionsDialog->exec(); if ( result == QDialog::Rejected ) mExceptions->setDates( dates ); } void KOEditorRecurrence::showRecurrenceRangeDialog() { int duration = mRecurrenceRange->duration(); QDate endDate = mRecurrenceRange->endDate(); int result = mRecurrenceRangeDialog->exec(); if ( result == QDialog::Rejected ) { mRecurrenceRange->setDuration( duration ); mRecurrenceRange->setEndDate( endDate ); } } |