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

0001 /*
0002     SPDX-FileCopyrightText: 2004 Martin Preuss <martin@libchipcard.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 
0006 */
0007 
0008 
0009 #ifdef HAVE_CONFIG_H
0010 # include <config-kmymoney.h>
0011 #endif
0012 
0013 
0014 // QBanking includes
0015 #include "kbmapaccount.h"
0016 #include "../widgets/kbaccountlist.h"
0017 #include "../kbanking.h"
0018 
0019 // QT includes
0020 #include <QLabel>
0021 #include <QPushButton>
0022 #include <QMessageBox>
0023 #include <QLayout>
0024 #include <QLineEdit>
0025 
0026 
0027 #include "ui_kbmapaccount.h"
0028 
0029 struct KBMapAccount::Private {
0030     Ui::KBMapAccount ui;
0031     KBankingExt *banking;
0032     AB_ACCOUNT_SPEC *account;
0033 };
0034 
0035 KBMapAccount::KBMapAccount(KBankingExt *kb,
0036                            const char *bankCode,
0037                            const char *accountId,
0038                            QWidget* parent,
0039                            Qt::WindowFlags fl) :
0040     QDialog(parent, fl),
0041     d(new Private)
0042 {
0043     d->banking = kb;
0044     d->account = 0;
0045     d->ui.setupUi(this);
0046 
0047     d->ui.accountList->setSelectionMode(QAbstractItemView::SingleSelection);
0048 
0049     if (bankCode)
0050         d->ui.bankCodeEdit->setText(QString::fromUtf8(bankCode));
0051     else
0052         d->ui.bankCodeEdit->setEnabled(false);
0053     if (accountId)
0054         d->ui.accountIdEdit->setText(QString::fromUtf8(accountId));
0055     else
0056         d->ui.accountIdEdit->setEnabled(false);
0057 
0058     connect(d->ui.accountList, &KBAccountListView::itemSelectionChanged, this, &KBMapAccount::slotSelectionChanged);
0059     connect(d->ui.helpButton, &QPushButton::clicked, this, &KBMapAccount::slotHelpClicked);
0060 
0061     d->ui.accountList->addAccounts(d->banking->getAccounts());
0062 }
0063 
0064 KBMapAccount::~KBMapAccount()
0065 {
0066     delete d;
0067 }
0068 
0069 AB_ACCOUNT_SPEC *KBMapAccount::getAccount()
0070 {
0071     return d->account;
0072 }
0073 
0074 void KBMapAccount::accept()
0075 {
0076     if (d->account)
0077         QDialog::accept();
0078 }
0079 
0080 void KBMapAccount::slotSelectionChanged()
0081 {
0082     std::list<AB_ACCOUNT_SPEC*> al;
0083     AB_ACCOUNT_SPEC *a;
0084 
0085     al = d->ui.accountList->getSelectedAccounts();
0086     if (al.empty()) {
0087         d->ui.assignButton->setEnabled(false);
0088         d->account = 0;
0089         return;
0090     }
0091     a = al.front();
0092     if (AB_AccountSpec_GetUniqueId(a) != 0) {
0093         d->account = a;
0094         d->ui.assignButton->setEnabled(true);
0095     } else
0096         d->ui.assignButton->setEnabled(false);
0097 }
0098 
0099 void KBMapAccount::slotHelpClicked()
0100 {
0101 }
0102