File indexing completed on 2024-06-16 04:46:16
0001 /* 0002 SPDX-FileCopyrightText: 2009 Thomas Baumgart ipwizard @users.sourceforge.net 0003 SPDX-FileCopyrightText: 2009 Cristian Onet onet.cristian @gmail.com 0004 SPDX-FileCopyrightText: 2004 Martin Preuss aquamaniac @users.sourceforge.net 0005 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 #ifdef HAVE_CONFIG_H 0008 # include <config-kmymoney.h> 0009 #endif 0010 0011 // QBanking includes 0012 #include "kbpickstartdate.h" 0013 0014 // Gwenhywfar includes 0015 #include <gwenhywfar/debug.h> 0016 0017 // QT includes 0018 #include <QRadioButton> 0019 #include <QLabel> 0020 #include <QDateTime> 0021 #include <QPushButton> 0022 0023 // KDE includes 0024 #include <KLocalizedString> 0025 0026 // KMyMoney includes 0027 #include "kmymoneydateedit.h" 0028 #include "widgethintframe.h" 0029 0030 #include "ui_kbpickstartdate.h" 0031 0032 struct KBPickStartDate::Private { 0033 void updateButtonState(const QDate& date) 0034 { 0035 if (date.isValid()) { 0036 WidgetHintFrame::hide(ui.pickDateEdit); 0037 } else { 0038 WidgetHintFrame::show(ui.pickDateEdit, i18nc("@info:tooltip", "The date is invalid.")); 0039 } 0040 } 0041 0042 Ui::KBPickStartDate ui; 0043 KBankingExt *banking; 0044 QDate firstPossible; 0045 QDate lastUpdate; 0046 }; 0047 0048 0049 KBPickStartDate::KBPickStartDate(KBankingExt* qb, 0050 const QDate &firstPossible, 0051 const QDate &lastUpdate, 0052 const QString& accountName, 0053 int defaultChoice, 0054 QWidget* parent, bool modal) : 0055 QDialog(parent), 0056 d(new Private) 0057 { 0058 d->ui.setupUi(this); 0059 d->firstPossible = firstPossible; 0060 d->lastUpdate = lastUpdate; 0061 setModal(modal); 0062 0063 d->banking = qb; 0064 0065 connect(d->ui.buttonBox, &QDialogButtonBox::helpRequested, this, &KBPickStartDate::slotHelpClicked); 0066 0067 /// @todo implement online help 0068 // since we did not fully implement the help, we better hide it for now 0069 d->ui.buttonBox->button(QDialogButtonBox::Help)->hide(); 0070 0071 d->ui.label->setText(i18n("<qt><p>Please select the first date for which transactions are to be retrieved from <b>%1</b>.</p><p>If you specify no date then the bank will choose one.</p></qt>", accountName)); 0072 0073 if (lastUpdate.isValid()) { 0074 d->ui.lastUpdateLabel->setText(lastUpdate.toString()); 0075 d->ui.lastUpdateButton->setEnabled(true); 0076 d->ui.lastUpdateLabel->setEnabled(true); 0077 } else { 0078 d->ui.lastUpdateButton->setEnabled(false); 0079 d->ui.lastUpdateLabel->setEnabled(false); 0080 if (defaultChoice == 2) 0081 defaultChoice = 1; 0082 } 0083 0084 if (firstPossible.isValid()) { 0085 d->ui.firstDateLabel->setText(firstPossible.toString()); 0086 d->ui.firstDateButton->setEnabled(true); 0087 d->ui.firstDateLabel->setEnabled(true); 0088 // As long as we use the KDateWidget we don't have 0089 // a chance to control the range. Once we are able 0090 // to use a KMyMoneyDateInput widget, we can make use 0091 // of the setRange() method again. 0092 // d->ui.pickDateEdit->setRange(firstPossible, QDate()); 0093 } else { 0094 d->ui.firstDateButton->setEnabled(false); 0095 d->ui.firstDateLabel->setEnabled(false); 0096 if (defaultChoice == 3) 0097 defaultChoice = 1; 0098 } 0099 0100 switch (defaultChoice) { 0101 case 2: 0102 d->ui.lastUpdateButton->setChecked(true); 0103 break; 0104 case 3: 0105 d->ui.firstDateButton->setChecked(true); 0106 break; 0107 default: 0108 d->ui.noDateButton->setChecked(true); 0109 break; 0110 } 0111 0112 auto frameCollection = new WidgetHintFrameCollection(this); 0113 frameCollection->addFrame(new WidgetHintFrame(d->ui.pickDateEdit)); 0114 frameCollection->addWidget(d->ui.buttonBox->button(QDialogButtonBox::Ok)); 0115 0116 connect(d->ui.pickDateEdit, &KMyMoneyDateEdit::dateValidityChanged, this, [&](const QDate& date) { 0117 if (d->ui.pickDateButton->isChecked()) { 0118 d->updateButtonState(date); 0119 } 0120 }); 0121 0122 connect(d->ui.pickDateButton, &QRadioButton::toggled, this, [&](bool selected) { 0123 if (selected) { 0124 d->updateButtonState(d->ui.pickDateEdit->date()); 0125 } else { 0126 // this will remove the widget hint frame and enable the OK button 0127 d->updateButtonState(QDate::currentDate()); 0128 } 0129 }); 0130 0131 d->ui.buttonGroup->setFocus(); 0132 } 0133 0134 0135 0136 KBPickStartDate::~KBPickStartDate() 0137 { 0138 delete d; 0139 } 0140 0141 0142 QDate KBPickStartDate::date() 0143 { 0144 if (d->ui.noDateButton->isChecked()) 0145 return QDate(); 0146 else if (d->ui.firstDateButton->isChecked()) 0147 return d->firstPossible; 0148 else if (d->ui.pickDateButton->isChecked()) 0149 return d->ui.pickDateEdit->date(); 0150 else if (d->ui.lastUpdateButton->isChecked()) 0151 return d->lastUpdate; 0152 else { 0153 DBG_ERROR(0, "Unknown date state"); 0154 return QDate(); 0155 } 0156 } 0157 0158 0159 0160 void KBPickStartDate::slotHelpClicked() 0161 { 0162 } 0163