File indexing completed on 2024-05-26 05:10:17

0001 /*
0002     SPDX-FileCopyrightText: 2006 Thomas Baumgart <ipwizard@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2017 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "kcurrencypage.h"
0008 
0009 // ----------------------------------------------------------------------------
0010 // QT Includes
0011 
0012 #include <QIcon>
0013 #include <QLabel>
0014 #include <QList>
0015 #include <QTreeView>
0016 #include <QTreeWidget>
0017 
0018 // ----------------------------------------------------------------------------
0019 // KDE Includes
0020 
0021 // ----------------------------------------------------------------------------
0022 // Project Includes
0023 
0024 #include "icons/icons.h"
0025 #include "knewuserwizard.h"
0026 #include "knewuserwizard_p.h"
0027 #include "kaccountpage.h"
0028 #include "kaccountpage_p.h"
0029 #include "mymoneyfile.h"
0030 #include "mymoneysecurity.h"
0031 #include "ui_currency.h"
0032 #include "ui_kaccountpage.h"
0033 #include "wizardpage.h"
0034 
0035 using namespace Icons;
0036 
0037 namespace NewUserWizard
0038 {
0039 class CurrencyPagePrivate : public WizardPagePrivate<Wizard>
0040 {
0041     Q_DISABLE_COPY(CurrencyPagePrivate)
0042 
0043 public:
0044     CurrencyPagePrivate(QObject* parent) :
0045         WizardPagePrivate<Wizard>(parent)
0046     {
0047     }
0048 };
0049 
0050 CurrencyPage::CurrencyPage(Wizard* wizard) :
0051     Currency(wizard),
0052     WizardPage<Wizard>(*new CurrencyPagePrivate(wizard), stepCount++, this, wizard)
0053 {
0054     QTreeWidgetItem *first = 0;
0055 
0056     QList<MyMoneySecurity> list = MyMoneyFile::instance()->availableCurrencyList();
0057     QList<MyMoneySecurity>::const_iterator it;
0058 
0059     QString localCurrency(QLocale().currencySymbol(QLocale::CurrencyIsoCode));
0060     QString baseCurrency = MyMoneyFile::instance()->baseCurrency().id();
0061 
0062 
0063     ui->m_currencyList->clear();
0064     for (it = list.constBegin(); it != list.constEnd(); ++it) {
0065         QTreeWidgetItem* p = insertCurrency(*it);
0066         if ((*it).id() == baseCurrency) {
0067             first = p;
0068             QIcon icon = Icons::get(Icon::BankAccount);
0069             p->setIcon(0, icon);
0070         } else {
0071             p->setIcon(0, QIcon());
0072         }
0073         if (!first && (*it).id() == localCurrency)
0074             first = p;
0075     }
0076 
0077     QTreeWidgetItemIterator itemsIt = QTreeWidgetItemIterator(ui->m_currencyList, QTreeWidgetItemIterator::All);
0078 
0079     if (first == 0)
0080         first = *itemsIt;
0081     if (first != 0) {
0082         ui->m_currencyList->setCurrentItem(first);
0083         first->setSelected(true);
0084         ui->m_currencyList->scrollToItem(first, QTreeView::PositionAtTop);
0085     }
0086 }
0087 
0088 CurrencyPage::~CurrencyPage()
0089 {
0090 }
0091 
0092 void CurrencyPage::enterPage()
0093 {
0094     ui->m_currencyList->setFocus();
0095 }
0096 
0097 KMyMoneyWizardPage* CurrencyPage::nextPage() const
0098 {
0099     Q_D(const CurrencyPage);
0100     QString selCur = selectedCurrency();
0101     const QList<MyMoneySecurity> currencies = MyMoneyFile::instance()->availableCurrencyList();
0102     for (const auto& currency : currencies) {
0103         if (selCur == currency.id()) {
0104             d->m_wizard->d_func()->m_baseCurrency = currency;
0105             break;
0106         }
0107     }
0108     d->m_wizard->d_func()->m_accountPage->d_func()->ui->m_accountCurrencyLabel->setText(d->m_wizard->d_func()->m_baseCurrency.tradingSymbol());
0109     return d->m_wizard->d_func()->m_accountPage;
0110 }
0111 
0112 }