33 #include <config-kleopatra.h>
37 #include "ui_expirydialog.h"
46 using namespace Kleo::Dialogs;
60 const QDate current = QDate::currentDate();
62 case Days:
return current.addDays( inAmount );
break;
63 case Weeks:
return current.addDays( 7*inAmount );
break;
64 case Months:
return current.addMonths( inAmount );
break;
65 case Years:
return current.addYears( inAmount );
break;
67 assert( !
"Should not reach here" );
76 const int days = d1.daysTo( d2 );
81 const int days = d1.daysTo( d2 );
88 class ExpiryDialog::Private {
89 friend class ::Kleo::Dialogs::ExpiryDialog;
97 connect( ui.inSB, SIGNAL(valueChanged(
int)),
98 q, SLOT(slotInAmountChanged()) );
99 connect( ui.inCB, SIGNAL(currentIndexChanged(
int)),
100 q, SLOT(slotInUnitChanged()) );
101 connect( ui.onCW, SIGNAL(selectionChanged()),
102 q, SLOT(slotOnDateChanged()) );
104 assert( ui.inCB->currentIndex() == inUnit );
108 void slotInAmountChanged();
109 void slotInUnitChanged();
110 void slotOnDateChanged();
113 QDate inDate()
const;
114 int inAmountByDate(
const QDate & date )
const;
119 struct UI :
public Ui::ExpiryDialog {
123 setupUi( qq->mainWidget() );
128 onCW->setMinimumDate( QDate::currentDate().addDays( 1 ) );
134 :
KDialog( p, f ),
d( new Private( this ) )
143 const QDate current = QDate::currentDate();
144 if ( date.isValid() ) {
145 d->ui.onRB->setChecked(
true );
146 d->ui.onCW->setSelectedDate( qMax( date, current ) );
148 d->ui.neverRB->setChecked(
true );
149 d->ui.onCW->setSelectedDate( current );
150 d->ui.inSB->setValue( 0 );
156 d->ui.inRB->isChecked() ? d->inDate() :
157 d->ui.onRB->isChecked() ? d->ui.onCW->selectedDate() :
164 void ExpiryDialog::Private::slotInUnitChanged() {
165 const int oldInAmount = ui.inSB->value();
167 inUnit = ui.inCB->currentIndex();
168 if ( targetDate.isValid() )
169 ui.inSB->setValue( inAmountByDate( targetDate ) );
171 slotInAmountChanged();
174 void ExpiryDialog::Private::slotInAmountChanged() {
176 if ( ui.inRB->isChecked() )
177 ui.onCW->setSelectedDate( inDate() );
180 void ExpiryDialog::Private::slotOnDateChanged() {
182 if ( ui.onRB->isChecked() )
183 ui.inSB->setValue( inAmountByDate( ui.onCW->selectedDate() ) );
189 QDate ExpiryDialog::Private::inDate()
const {
193 int ExpiryDialog::Private::inAmountByDate(
const QDate & selected )
const {
194 const QDate current = QDate::currentDate();
196 switch ( ui.inCB->currentIndex() ) {
197 case Days:
return current.daysTo( selected );
198 case Weeks:
return qRound( current.daysTo( selected ) / 7.0 );
202 assert( !
"Should not reach here" );
206 #include "moc_expirydialog.cpp"
static const double DAYS_IN_GREGORIAN_YEAR
void setDateOfExpiry(const QDate &date)
ExpiryDialog(QWidget *parent=0, Qt::WindowFlags f=0)
QDate dateOfExpiry() const
static int yearsBetween(const QDate &d1, const QDate &d2)
static QDate date_by_amount_and_unit(int inAmount, int inUnit)
static int monthsBetween(const QDate &d1, const QDate &d2)