Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/wizards/newaccountwizard/kinstitutionpage.cpp
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | kinstitutionpage.cpp | ||||
3 | ------------------- | ||||
4 | begin : Tue Sep 25 2006 | ||||
5 | copyright : (C) 2007 Thomas Baumgart | ||||
6 | email : Thomas Baumgart <ipwizard@users.sourceforge.net> | ||||
7 | (C) 2017 by Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> | ||||
8 | ***************************************************************************/ | ||||
9 | | ||||
10 | /*************************************************************************** | ||||
11 | * * | ||||
12 | * This program is free software; you can redistribute it and/or modify * | ||||
13 | * it under the terms of the GNU General Public License as published by * | ||||
14 | * the Free Software Foundation; either version 2 of the License, or * | ||||
15 | * (at your option) any later version. * | ||||
16 | * * | ||||
17 | ***************************************************************************/ | ||||
18 | | ||||
19 | #include "kinstitutionpage.h" | ||||
20 | #include "kinstitutionpage_p.h" | ||||
21 | | ||||
22 | // ---------------------------------------------------------------------------- | ||||
23 | // QT Includes | ||||
24 | | ||||
25 | #include <QList> | ||||
26 | #include <QPushButton> | ||||
27 | | ||||
28 | // ---------------------------------------------------------------------------- | ||||
29 | // KDE Includes | ||||
30 | | ||||
31 | #include <KComboBox> | ||||
32 | #include <KLineEdit> | ||||
33 | | ||||
34 | // ---------------------------------------------------------------------------- | ||||
35 | // Project Includes | ||||
36 | | ||||
37 | #include "ui_kinstitutionpage.h" | ||||
38 | | ||||
39 | #include "knewaccountwizard.h" | ||||
40 | #include "knewaccountwizard_p.h" | ||||
41 | #include "kaccounttypepage.h" | ||||
42 | #include "kinstitutionpage_p.h" | ||||
43 | #include "mymoneyfile.h" | ||||
44 | #include "mymoneyinstitution.h" | ||||
45 | #include "wizardpage.h" | ||||
46 | | ||||
47 | namespace NewAccountWizard | ||||
48 | { | ||||
49 | InstitutionPage::InstitutionPage(Wizard* wizard) : | ||||
50 | QWidget(wizard), | ||||
51 | WizardPage<Wizard>(*new InstitutionPagePrivate(wizard),StepInstitution, this, wizard) | ||||
52 | { | ||||
53 | Q_D(InstitutionPage); | ||||
54 | d->ui->setupUi(this); | ||||
55 | connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, this, &InstitutionPage::slotLoadWidgets); | ||||
56 | connect(d_func()->ui->m_newInstitutionButton, &QAbstractButton::clicked, this, &InstitutionPage::slotNewInstitution); | ||||
57 | connect(d_func()->ui->m_institutionComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &InstitutionPage::slotSelectInstitution); | ||||
58 | | ||||
59 | slotLoadWidgets(); | ||||
60 | d_func()->ui->m_institutionComboBox->setCurrentItem(0); | ||||
61 | slotSelectInstitution(0); | ||||
62 | } | ||||
63 | | ||||
64 | InstitutionPage::~InstitutionPage() | ||||
65 | { | ||||
66 | } | ||||
67 | | ||||
68 | void InstitutionPage::slotLoadWidgets() | ||||
69 | { | ||||
70 | Q_D(InstitutionPage); | ||||
71 | d_func()->ui->m_institutionComboBox->clear(); | ||||
72 | | ||||
73 | d->m_list.clear(); | ||||
74 | MyMoneyFile::instance()->institutionList(d->m_list); | ||||
75 | qSort(d->m_list); | ||||
76 | | ||||
77 | QList<MyMoneyInstitution>::const_iterator it_l; | ||||
78 | d->ui->m_institutionComboBox->addItem(QString()); | ||||
79 | for (it_l = d->m_list.constBegin(); it_l != d->m_list.constEnd(); ++it_l) { | ||||
80 | d->ui->m_institutionComboBox->addItem((*it_l).name()); | ||||
81 | } | ||||
82 | } | ||||
83 | | ||||
84 | void InstitutionPage::slotNewInstitution() | ||||
85 | { | ||||
86 | Q_D(InstitutionPage); | ||||
87 | MyMoneyInstitution institution; | ||||
88 | | ||||
89 | emit d->m_wizard->createInstitution(institution); | ||||
90 | | ||||
91 | if (!institution.id().isEmpty()) { | ||||
92 | QList<MyMoneyInstitution>::const_iterator it_l; | ||||
93 | int i = 0; | ||||
94 | for (it_l = d->m_list.constBegin(); it_l != d->m_list.constEnd(); ++it_l) { | ||||
95 | if ((*it_l).id() == institution.id()) { | ||||
96 | // select the item and remember that the very first one is the empty item | ||||
97 | d->ui->m_institutionComboBox->setCurrentIndex(i + 1); | ||||
98 | slotSelectInstitution(i + 1); | ||||
99 | d->ui->m_accountNumber->setFocus(); | ||||
100 | break; | ||||
101 | } | ||||
102 | ++i; | ||||
103 | } | ||||
104 | } | ||||
105 | } | ||||
106 | | ||||
107 | void InstitutionPage::slotSelectInstitution(const int index) | ||||
108 | { | ||||
109 | Q_D(InstitutionPage); | ||||
110 | d->ui->m_accountNumber->setEnabled(index != 0); | ||||
111 | d->ui->m_iban->setEnabled(index != 0); | ||||
112 | } | ||||
113 | | ||||
114 | void InstitutionPage::selectExistingInstitution(const QString& id) | ||||
115 | { | ||||
116 | Q_D(InstitutionPage); | ||||
117 | for (int i = 0; i < d->m_list.length(); ++i) { | ||||
118 | if (d->m_list[i].id() == id) { | ||||
119 | d->ui->m_institutionComboBox->setCurrentIndex(i + 1); | ||||
120 | slotSelectInstitution(i + 1); | ||||
121 | break; | ||||
122 | } | ||||
123 | } | ||||
124 | } | ||||
125 | | ||||
126 | const MyMoneyInstitution& InstitutionPage::institution() const | ||||
127 | { | ||||
128 | Q_D(const InstitutionPage); | ||||
129 | static MyMoneyInstitution emptyInstitution; | ||||
130 | if (d->ui->m_institutionComboBox->currentIndex() == 0) | ||||
131 | return emptyInstitution; | ||||
132 | | ||||
133 | return d->m_list[d->ui->m_institutionComboBox->currentIndex()-1]; | ||||
134 | } | ||||
135 | | ||||
136 | KMyMoneyWizardPage* InstitutionPage::nextPage() const | ||||
137 | { | ||||
138 | Q_D(const InstitutionPage); | ||||
139 | return d->m_wizard->d_func()->m_accountTypePage; | ||||
140 | } | ||||
141 | | ||||
142 | QWidget* InstitutionPage::initialFocusWidget(void) const | ||||
143 | { | ||||
144 | Q_D(const InstitutionPage); | ||||
145 | return d->ui->m_institutionComboBox; | ||||
146 | } | ||||
147 | } |