Diffstat (limited to 'libopie2/opiepim/ui/opimrecurrencewidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/ui/opimrecurrencewidget.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/libopie2/opiepim/ui/opimrecurrencewidget.cpp b/libopie2/opiepim/ui/opimrecurrencewidget.cpp index 90c1a5f..ee7f3a3 100644 --- a/libopie2/opiepim/ui/opimrecurrencewidget.cpp +++ b/libopie2/opiepim/ui/opimrecurrencewidget.cpp @@ -1,380 +1,382 @@ #include <qapplication.h> #include <qlabel.h> #include <qpopupmenu.h> #include <qspinbox.h> #include <qpe/timestring.h> #include "opimrecurrencewidget.h" + +using namespace Opie; // Global Templates for use in setting up the repeat label... // the problem is these strings get initialized before QPEApplication can install the translator -zecke namespace { QString strDayTemplate; QString strYearTemplate; QString strMonthDateTemplate; QString strMonthDayTemplate; QString strWeekTemplate; QString dayLabel[7]; } /* * static linkage to not polute the symbol table... * The problem is that const and static linkage are resolved prior to installing a translator * leading to that the above strings are translted but to the original we delay the init of these strings... * -zecke */ static void fillStrings() { strDayTemplate = QObject::tr("Every"); strYearTemplate = QObject::tr("%1 %2 every "); strMonthDateTemplate = QObject::tr("The %1 every "); strMonthDayTemplate = QObject::tr("The %1 %2 of every"); strWeekTemplate = QObject::tr("Every "); dayLabel[0] = QObject::tr("Monday"); dayLabel[1] = QObject::tr("Tuesday"); dayLabel[2] = QObject::tr("Wednesday"); dayLabel[3] = QObject::tr("Thursday"); dayLabel[4] = QObject::tr("Friday"); dayLabel[5] = QObject::tr("Saturday"); dayLabel[6] = QObject::tr("Sunday"); } static QString numberPlacing( int x ); // return the proper word format for // x (1st, 2nd, etc) static int week( const QDate &dt ); // what week in the month is dt? /** * Constructs the Widget * @param startOnMonday Does the week start on monday * @param newStart The start date of the recurrence * @param parent The parent widget * @param name the name of object * @param modal if the dialog should be modal * @param fl Additional window flags */ OPimRecurrenceWidget::OPimRecurrenceWidget( bool startOnMonday, const QDate& newStart, QWidget* parent, const char* name, bool modal, WFlags fl ) : OPimRecurrenceBase( parent, name, modal, fl ), start( newStart ), currInterval( None ), startWeekOnMonday( startOnMonday ) { if (strDayTemplate.isEmpty() ) fillStrings(); init(); fraType->setButton( currInterval ); chkNoEnd->setChecked( TRUE ); setupNone(); } /** * Different constructor * @param startOnMonday Does the week start on monday? * @param rp Already set OPimRecurrence object * @param startDate The start date * @param parent The parent widget * @param name The name of the object * @param modal * @param fl The flags for window */ OPimRecurrenceWidget::OPimRecurrenceWidget( bool startOnMonday, - const OPimRecurrence& rp, const QDate& startDate, + const Opie::OPimRecurrence& rp, const QDate& startDate, QWidget* parent, const char* name, bool modal, WFlags fl) : OPimRecurrenceBase( parent, name, modal, fl ), start( startDate ), end( rp.endDate() ), startWeekOnMonday( startOnMonday ) { if (strDayTemplate.isEmpty() ) fillStrings(); // do some stuff with the repeat pattern init(); setRecurrence( rp ); } OPimRecurrenceWidget::~OPimRecurrenceWidget() { } /** * set the start date * @param date the new start date */ void OPimRecurrenceWidget::setStartDate( const QDate& date ) { setRecurrence( recurrence(), date ); } /** * set the recurrence * @param rp The OPimRecurrence object with the new recurrence rules */ -void OPimRecurrenceWidget::setRecurrence( const OPimRecurrence& rp ) { +void OPimRecurrenceWidget::setRecurrence( const Opie::OPimRecurrence& rp ) { setRecurrence( rp, start ); } /** * overloaded method taking OPimRecurrence and a new start date * @param rp Recurrence rule * @param date The new start date */ -void OPimRecurrenceWidget::setRecurrence( const OPimRecurrence& rp, const QDate& date ) { +void OPimRecurrenceWidget::setRecurrence( const Opie::OPimRecurrence& rp, const QDate& date ) { start = date; end = rp.endDate(); switch ( rp.type() ) { default: case OPimRecurrence::NoRepeat: currInterval = None; setupNone(); break; case OPimRecurrence::Daily: currInterval = Day; setupDaily(); break; case OPimRecurrence::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 OPimRecurrence::MonthlyDay: currInterval = Month; setupMonthly(); fraExtra->setButton( 0 ); slotMonthLabel( 0 ); break; case OPimRecurrence::MonthlyDate: currInterval = Month; setupMonthly(); fraExtra->setButton( 1 ); slotMonthLabel( 1 ); break; case OPimRecurrence::Yearly: currInterval = Year; setupYearly(); break; } fraType->setButton( currInterval ); spinFreq->setValue( rp.frequency() ); if ( !rp.hasEndDate() ) { cmdEnd->setText( tr("No End Date") ); chkNoEnd->setChecked( TRUE ); } else cmdEnd->setText( TimeString::shortDate( end ) ); } /** * the user selected recurrence rule. * @return The recurrence rule. */ OPimRecurrence OPimRecurrenceWidget::recurrence()const { QListIterator<QToolButton> it( listRTypeButtons ); QListIterator<QToolButton> itExtra( listExtra ); OPimRecurrence rpTmp; int i; for ( i = 0; *it; ++it, i++ ) { if ( (*it)->isOn() ) { switch ( i ) { case None: rpTmp.setType( OPimRecurrence::NoRepeat ); break; case Day: rpTmp.setType( OPimRecurrence::Daily ); break; case Week:{ rpTmp.setType( OPimRecurrence::Weekly ); int day; int day2 = 0; for ( day = 1; *itExtra; ++itExtra, day = day << 1 ) { if ( (*itExtra)->isOn() ) { if ( startWeekOnMonday ) day2 |= day; else { if ( day == 1 ) day2 |= Event::SUN; else day2 |= day >> 1; } } } rpTmp.setDays( day2 ); } break; case Month: if ( cmdExtra1->isOn() ) rpTmp.setType( OPimRecurrence::MonthlyDay ); else if ( cmdExtra2->isOn() ) rpTmp.setType( OPimRecurrence::MonthlyDate ); // figure out the montly day... rpTmp.setPosition( week( start ) ); break; case Year: rpTmp.setType( OPimRecurrence::Yearly ); break; } break; // no need to keep looking! } } rpTmp.setFrequency(spinFreq->value() ); rpTmp.setHasEndDate( !chkNoEnd->isChecked() ); if ( rpTmp.hasEndDate() ) { rpTmp.setEndDate( end ); } // timestamp it... // rpTmp.setCreateTime( ); current DateTime is already set -zecke return rpTmp; } /** * Return the end date of the recurrence. This is only * valid if the recurrence rule does contain an enddate */ QDate OPimRecurrenceWidget::endDate()const { return end; } void OPimRecurrenceWidget::slotSetRType(int rtype) { // now call the right function based on the type... currInterval = static_cast<repeatButtons>(rtype); switch ( currInterval ) { case None: setupNone(); break; case Day: setupDaily(); break; case Week: setupWeekly(); slotWeekLabel(); break; case Month: setupMonthly(); cmdExtra2->setOn( TRUE ); slotMonthLabel( 1 ); break; case Year: setupYearly(); break; } } void OPimRecurrenceWidget::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 OPimRecurrenceWidget::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( tr("No End Date") ); } else { end = start; cmdEnd->setText( TimeString::shortDate(end) ); } } void OPimRecurrenceWidget::setupRepeatLabel( const QString& s) { lblVar1->setText( s ); } void OPimRecurrenceWidget::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 = tr( "months" ); else strVar2 = tr( "month" ); break; case Year: if ( x > 1 ) strVar2 = tr( "years" ); else strVar2 = tr( "year" ); break; } if ( !strVar2.isNull() ) lblVar2->setText( strVar2 ); } void OPimRecurrenceWidget::slotWeekLabel() { QString str; QListIterator<QToolButton> it( listExtra ); unsigned int i; unsigned int keepMe; bool bNeedCarriage = FALSE; // don't do something we'll regret!!! if ( currInterval != Week ) return; if ( startWeekOnMonday ) keepMe = start.dayOfWeek() - 1; else keepMe = start.dayOfWeek() % 7; QStringList list; for ( i = 0; *it; ++it, i++ ) { // a crazy check, if you are repeating weekly, the current day // must be selected!!! if ( i == keepMe && !( (*it)->isOn() ) ) (*it)->setOn( TRUE ); if ( (*it)->isOn() ) { if ( startWeekOnMonday ) list.append( dayLabel[i] ); else { if ( i == 0 ) list.append( dayLabel[6] ); else list.append( dayLabel[i - 1] ); } } } QStringList::Iterator itStr; for ( i = 0, itStr = list.begin(); itStr != list.end(); ++itStr, i++ ) { if ( i == 3 ) bNeedCarriage = TRUE; else bNeedCarriage = FALSE; if ( str.isNull() ) str = *itStr; else if ( i == list.count() - 1 ) { if ( i < 2 ) str += tr(" and ") + *itStr; else { if ( bNeedCarriage ) str += tr( ",\nand " ) + *itStr; |