File indexing completed on 2024-05-12 16:42:10
0001 /* 0002 SPDX-FileCopyrightText: 2005 Andreas Nicolai <Andreas.Nicolai@gmx.net> 0003 SPDX-FileCopyrightText: 2007-2008 Thomas Baumgart <tbaumgart@kde.org> 0004 SPDX-FileCopyrightText: 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "kpayeereassigndlg.h" 0009 0010 // ---------------------------------------------------------------------------- 0011 // QT Includes 0012 0013 #include <QList> 0014 #include <QLineEdit> 0015 #include <QPushButton> 0016 0017 // ---------------------------------------------------------------------------- 0018 // KDE Includes 0019 0020 #include <KMessageBox> 0021 #include <kguiutils.h> 0022 #include <KLocalizedString> 0023 0024 // ---------------------------------------------------------------------------- 0025 // Project Includes 0026 0027 #include "ui_kpayeereassigndlg.h" 0028 0029 #include <kmymoneymvccombo.h> 0030 0031 /** This lookup table needs to be in sync with KPayeeReassignDlg::OperationType enum */ 0032 static const char * labelText[KPayeeReassignDlg::TypeCount] = { 0033 I18N_NOOP("To be able to merge previous selected payees, please select a payee from the list below or create a new one."), 0034 I18N_NOOP("The transactions associated with the selected payees need to be re-assigned to a different payee before the selected payees can be deleted. Please select a payee from the list below."), 0035 }; 0036 0037 class KPayeeReassignDlgPrivate 0038 { 0039 Q_DISABLE_COPY(KPayeeReassignDlgPrivate) 0040 0041 public: 0042 KPayeeReassignDlgPrivate() : 0043 ui(new Ui::KPayeeReassignDlg), 0044 m_type(KPayeeReassignDlg::OperationType::TypeMerge) 0045 { 0046 } 0047 0048 ~KPayeeReassignDlgPrivate() 0049 { 0050 delete ui; 0051 } 0052 0053 Ui::KPayeeReassignDlg *ui; 0054 KPayeeReassignDlg::OperationType m_type; 0055 }; 0056 0057 KPayeeReassignDlg::KPayeeReassignDlg(KPayeeReassignDlg::OperationType type, QWidget* parent) : 0058 QDialog(parent), 0059 d_ptr(new KPayeeReassignDlgPrivate) 0060 { 0061 Q_D(KPayeeReassignDlg); 0062 d->ui->setupUi(this); 0063 d->m_type = type; 0064 auto mandatory = new KMandatoryFieldGroup(this); 0065 mandatory->add(d->ui->payeeCombo); 0066 mandatory->setOkButton(d->ui->buttonBox->button(QDialogButtonBox::Ok)); 0067 d->ui->textLabel1->setText(i18n(labelText[d->m_type])); 0068 } 0069 0070 KPayeeReassignDlg::~KPayeeReassignDlg() 0071 { 0072 Q_D(KPayeeReassignDlg); 0073 delete d; 0074 } 0075 0076 QString KPayeeReassignDlg::show(const QList<MyMoneyPayee>& payeeslist) 0077 { 0078 Q_D(KPayeeReassignDlg); 0079 if (payeeslist.isEmpty()) 0080 return QString(); // no payee available? nothing can be selected... 0081 0082 d->ui->payeeCombo->loadPayees(payeeslist); 0083 0084 // execute dialog and if aborted, return empty string 0085 if (this->exec() == QDialog::Rejected) 0086 return QString(); 0087 0088 // allow to return the text (new payee) if type is Merge 0089 if (d->m_type == TypeMerge && d->ui->payeeCombo->selectedItem().isEmpty()) 0090 return d->ui->payeeCombo->lineEdit()->text(); 0091 0092 // otherwise return index of selected payee 0093 return d->ui->payeeCombo->selectedItem(); 0094 } 0095 0096 0097 bool KPayeeReassignDlg::addToMatchList() const 0098 { 0099 Q_D(const KPayeeReassignDlg); 0100 return d->ui->m_copyToMatchList->isChecked(); 0101 } 0102 0103 void KPayeeReassignDlg::accept() 0104 { 0105 Q_D(KPayeeReassignDlg); 0106 // force update of d->ui->payeeCombo 0107 d->ui->buttonBox->button(QDialogButtonBox::Ok)->setFocus(); 0108 0109 if (d->m_type == TypeDelete && d->ui->payeeCombo->selectedItem().isEmpty()) { 0110 KMessageBox::information(this, i18n("This dialog does not allow new payees to be created. Please pick a payee from the list."), i18n("Payee creation")); 0111 } else { 0112 QDialog::accept(); 0113 } 0114 }