File indexing completed on 2024-06-16 04:46:16

0001 /*
0002     SPDX-FileCopyrightText: 2009 Cristian Onet onet.cristian @gmail.com
0003     SPDX-FileCopyrightText: 2008 Thomas Baumgart ipwizard @users.sourceforge.net
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 #ifdef HAVE_CONFIG_H
0007 # include <config-kmymoney.h>
0008 #endif
0009 
0010 #include "kbaccountsettings.h"
0011 
0012 #include <KMessageBox>
0013 #include <KLocalizedString>
0014 
0015 #include "mymoneykeyvaluecontainer.h"
0016 #include "mymoneyaccount.h"
0017 
0018 #include "ui_kbaccountsettings.h"
0019 
0020 #include <aqbanking/version.h>
0021 
0022 struct KBAccountSettings::Private {
0023     Ui::KBAccountSettings ui;
0024 };
0025 
0026 KBAccountSettings::KBAccountSettings(const MyMoneyAccount& /*acc*/,
0027                                      QWidget* parent) :
0028     QWidget(parent),
0029     d(new Private)
0030 {
0031     d->ui.setupUi(this);
0032 }
0033 
0034 KBAccountSettings::~KBAccountSettings()
0035 {
0036     delete d;
0037 }
0038 
0039 void KBAccountSettings::loadUi(const MyMoneyKeyValueContainer& kvp)
0040 {
0041     d->ui.m_usePayeeAsIsButton->setChecked(true);
0042     d->ui.m_transactionDownload->setChecked(kvp.value("kbanking-txn-download") != "no");
0043     d->ui.m_preferredStatementDate->setCurrentIndex(kvp.value("kbanking-statementDate").toInt());
0044     if (!kvp.value("kbanking-payee-regexp").isEmpty()) {
0045         d->ui.m_extractPayeeButton->setChecked(true);
0046         d->ui.m_payeeRegExpEdit->setText(kvp.value("kbanking-payee-regexp"));
0047         d->ui.m_memoRegExpEdit->setText(kvp.value("kbanking-memo-regexp"));
0048         d->ui.m_payeeExceptions->clear();
0049         d->ui.m_payeeExceptions->insertStringList(kvp.value("kbanking-payee-exceptions").split(';', Qt::SkipEmptyParts));
0050     }
0051     d->ui.m_removeLineBreaksFromMemo->setChecked(kvp.value("kbanking-memo-removelinebreaks").compare(QLatin1String("no")));
0052 
0053     d->ui.m_includePayeeDetails->setChecked(kvp.value("kbanking-memo-includepayeedetails").compare(QLatin1String("no")));
0054     // don't present the option to the user if it is not available
0055 #if QT_VERSION_CHECK(AQBANKING_VERSION_MAJOR, AQBANKING_VERSION_MINOR, AQBANKING_VERSION_PATCHLEVEL) <= QT_VERSION_CHECK(6, 2, 0)
0056     d->ui.m_includePayeeDetails->hide();
0057 #endif
0058 }
0059 
0060 void KBAccountSettings::loadKvp(MyMoneyKeyValueContainer& kvp)
0061 {
0062     kvp.deletePair("kbanking-payee-regexp");
0063     kvp.deletePair("kbanking-memo-regexp");
0064     kvp.deletePair("kbanking-payee-exceptions");
0065     kvp.deletePair("kbanking-txn-download");
0066     kvp.deletePair("kbanking-memo-removelinebreaks");
0067     kvp.deletePair("kbanking-memo-includepayeedetails");
0068     // The key "kbanking-jobexec" is not used since version 4.8 anymore
0069     kvp.deletePair("kbanking-jobexec");
0070 
0071     if (d->ui.m_extractPayeeButton->isChecked()
0072             && !d->ui.m_payeeRegExpEdit->text().isEmpty()
0073             && !d->ui.m_memoRegExpEdit->text().isEmpty()) {
0074         kvp["kbanking-payee-regexp"] = d->ui.m_payeeRegExpEdit->text();
0075         kvp["kbanking-memo-regexp"] = d->ui.m_memoRegExpEdit->text();
0076         kvp["kbanking-payee-exceptions"] = d->ui.m_payeeExceptions->items().join(";");
0077     } else if (d->ui.m_extractPayeeButton->isChecked()) {
0078         KMessageBox::information(0, i18n("You selected to extract the payee from the memo field but did not supply a regular expression for payee and memo extraction. The option will not be activated."), i18n("Missing information"));
0079     }
0080     if (!d->ui.m_transactionDownload->isChecked())
0081         kvp["kbanking-txn-download"] = "no";
0082 
0083     // remove linebreaks, default is on
0084     if (!d->ui.m_removeLineBreaksFromMemo->isChecked())
0085         kvp["kbanking-memo-removelinebreaks"] = "no";
0086 
0087     // include payee details, default is no
0088     if (!d->ui.m_includePayeeDetails->isChecked())
0089         kvp["kbanking-memo-includepayeedetails"] = "no";
0090 
0091     kvp["kbanking-statementDate"] = QString("%1").arg(d->ui.m_preferredStatementDate->currentIndex());
0092 }