Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/dialogs/kaccountselectdlg.cpp
Context not available. | |||||
9 | John C <thetacoturtle@users.sourceforge.net> | 9 | John C <thetacoturtle@users.sourceforge.net> | ||
---|---|---|---|---|---|
10 | Thomas Baumgart <ipwizard@users.sourceforge.net> | 10 | Thomas Baumgart <ipwizard@users.sourceforge.net> | ||
11 | Kevin Tambascio <ktambascio@users.sourceforge.net> | 11 | Kevin Tambascio <ktambascio@users.sourceforge.net> | ||
12 | (C) 2017 by Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> | ||||
12 | ***************************************************************************/ | 13 | ***************************************************************************/ | ||
13 | 14 | | |||
14 | /*************************************************************************** | 15 | /*************************************************************************** | ||
Context not available. | |||||
39 | // ---------------------------------------------------------------------------- | 40 | // ---------------------------------------------------------------------------- | ||
40 | // Project Includes | 41 | // Project Includes | ||
41 | 42 | | |||
43 | #include "ui_kaccountselectdlg.h" | ||||
44 | | ||||
45 | #include "mymoneyaccount.h" | ||||
42 | #include "mymoneyfile.h" | 46 | #include "mymoneyfile.h" | ||
43 | #include "kmymoneycategory.h" | 47 | #include "kmymoneycategory.h" | ||
44 | #include "kmymoneyaccountselector.h" | 48 | #include "kmymoneyaccountselector.h" | ||
45 | 49 | | |||
46 | #include <../kmymoney.h> | 50 | #include <../kmymoney.h> | ||
51 | #include "dialogenums.h" | ||||
47 | #include "icons/icons.h" | 52 | #include "icons/icons.h" | ||
48 | 53 | | |||
49 | using namespace Icons; | 54 | using namespace Icons; | ||
50 | 55 | | |||
51 | KAccountSelectDlg::KAccountSelectDlg(const KMyMoneyUtils::categoryTypeE accountType, const QString& purpose, QWidget *parent) | 56 | class KAccountSelectDlgPrivate | ||
52 | : KAccountSelectDlgDecl(parent), | 57 | { | ||
53 | m_purpose(purpose), | 58 | Q_DISABLE_COPY(KAccountSelectDlgPrivate) | ||
54 | m_accountType(accountType), | 59 | | ||
60 | public: | ||||
61 | KAccountSelectDlgPrivate() : | ||||
62 | ui(new Ui::KAccountSelectDlg), | ||||
55 | m_aborted(false) | 63 | m_aborted(false) | ||
64 | { | ||||
65 | } | ||||
66 | | ||||
67 | ~KAccountSelectDlgPrivate() | ||||
68 | { | ||||
69 | delete ui; | ||||
70 | } | ||||
71 | | ||||
72 | Ui::KAccountSelectDlg *ui; | ||||
73 | QString m_purpose; | ||||
74 | MyMoneyAccount m_account; | ||||
75 | int m_mode; // 0 - select or create, 1 - create only | ||||
76 | eDialogs::Category m_accountType; | ||||
77 | bool m_aborted; | ||||
78 | }; | ||||
79 | | ||||
80 | KAccountSelectDlg::KAccountSelectDlg(const eDialogs::Category accountType, const QString& purpose, QWidget *parent) : | ||||
81 | QDialog(parent), | ||||
82 | d_ptr(new KAccountSelectDlgPrivate) | ||||
56 | { | 83 | { | ||
84 | Q_D(KAccountSelectDlg); | ||||
85 | d->ui->setupUi(this); | ||||
86 | d->m_purpose = purpose; | ||||
87 | d->m_accountType = accountType; | ||||
57 | // Hide the abort button. It needs to be shown on request by the caller | 88 | // Hide the abort button. It needs to be shown on request by the caller | ||
58 | // using showAbortButton() | 89 | // using showAbortButton() | ||
59 | m_kButtonAbort->hide(); | 90 | d->ui->m_kButtonAbort->hide(); | ||
60 | 91 | | |||
61 | slotReloadWidget(); | 92 | slotReloadWidget(); | ||
62 | 93 | | |||
Context not available. | |||||
64 | QIcon::fromTheme(g_Icons[Icon::MediaSkipForward]), | 95 | QIcon::fromTheme(g_Icons[Icon::MediaSkipForward]), | ||
65 | i18n("Skip this transaction"), | 96 | i18n("Skip this transaction"), | ||
66 | i18n("Use this to skip importing this transaction and proceed with the next one.")); | 97 | i18n("Use this to skip importing this transaction and proceed with the next one.")); | ||
67 | KGuiItem::assign(m_qbuttonCancel, skipButtonItem); | 98 | KGuiItem::assign(d->ui->m_qbuttonCancel, skipButtonItem); | ||
68 | 99 | | |||
69 | KGuiItem createButtenItem(i18n("&Create..."), | 100 | KGuiItem createButtenItem(i18n("&Create..."), | ||
70 | QIcon::fromTheme(g_Icons[Icon::DocumentNew]), | 101 | QIcon::fromTheme(g_Icons[Icon::DocumentNew]), | ||
71 | i18n("Create a new account/category"), | 102 | i18n("Create a new account/category"), | ||
72 | i18n("Use this to add a new account/category to the file")); | 103 | i18n("Use this to add a new account/category to the file")); | ||
73 | KGuiItem::assign(m_createButton, createButtenItem); | 104 | KGuiItem::assign(d->ui->m_createButton, createButtenItem); | ||
74 | KGuiItem::assign(m_qbuttonOk, KStandardGuiItem::ok()); | 105 | KGuiItem::assign(d->ui->m_qbuttonOk, KStandardGuiItem::ok()); | ||
75 | 106 | | |||
76 | KGuiItem abortButtenItem(i18n("&Abort"), | 107 | KGuiItem abortButtenItem(i18n("&Abort"), | ||
77 | QIcon::fromTheme(g_Icons[Icon::DialogCancel]), | 108 | QIcon::fromTheme(g_Icons[Icon::DialogCancel]), | ||
78 | i18n("Abort the import operation and dismiss all changes"), | 109 | i18n("Abort the import operation and dismiss all changes"), | ||
79 | i18n("Use this to abort the import. Your financial data will be in the state before you started the QIF import.")); | 110 | i18n("Use this to abort the import. Your financial data will be in the state before you started the QIF import.")); | ||
80 | KGuiItem::assign(m_kButtonAbort, abortButtenItem); | 111 | KGuiItem::assign(d->ui->m_kButtonAbort, abortButtenItem); | ||
81 | 112 | | |||
113 | connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, this, &KAccountSelectDlg::slotReloadWidget); | ||||
82 | 114 | | |||
83 | connect(MyMoneyFile::instance(), SIGNAL(dataChanged()), this, SLOT(slotReloadWidget())); | 115 | connect(d->ui->m_createButton, &QAbstractButton::clicked, this, &KAccountSelectDlg::slotCreateAccount); | ||
84 | 116 | connect(d->ui->m_qbuttonOk, &QAbstractButton::clicked, this, &QDialog::accept); | |||
85 | connect(m_createButton, SIGNAL(clicked()), this, SLOT(slotCreateAccount())); | 117 | connect(d->ui->m_qbuttonCancel, &QAbstractButton::clicked, this, &QDialog::reject); | ||
86 | connect(m_qbuttonOk, SIGNAL(clicked()), this, SLOT(accept())); | 118 | connect(d->ui->m_kButtonAbort, &QAbstractButton::clicked, this, &KAccountSelectDlg::abort); | ||
87 | connect(m_qbuttonCancel, SIGNAL(clicked()), this, SLOT(reject())); | | |||
88 | connect(m_kButtonAbort, SIGNAL(clicked()), this, SLOT(abort())); | | |||
89 | } | 119 | } | ||
90 | 120 | | |||
91 | KAccountSelectDlg::~KAccountSelectDlg() | 121 | KAccountSelectDlg::~KAccountSelectDlg() | ||
92 | { | 122 | { | ||
123 | Q_D(KAccountSelectDlg); | ||||
124 | delete d; | ||||
93 | } | 125 | } | ||
94 | 126 | | |||
95 | void KAccountSelectDlg::slotReloadWidget() | 127 | void KAccountSelectDlg::slotReloadWidget() | ||
96 | { | 128 | { | ||
129 | Q_D(KAccountSelectDlg); | ||||
97 | AccountSet set; | 130 | AccountSet set; | ||
98 | if (m_accountType & KMyMoneyUtils::asset) | 131 | if (d->m_accountType & eDialogs::Category::asset) | ||
99 | set.addAccountGroup(eMyMoney::Account::Asset); | 132 | set.addAccountGroup(eMyMoney::Account::Asset); | ||
100 | if (m_accountType & KMyMoneyUtils::liability) | 133 | if (d->m_accountType & eDialogs::Category::liability) | ||
101 | set.addAccountGroup(eMyMoney::Account::Liability); | 134 | set.addAccountGroup(eMyMoney::Account::Liability); | ||
102 | if (m_accountType & KMyMoneyUtils::income) | 135 | if (d->m_accountType & eDialogs::Category::income) | ||
103 | set.addAccountGroup(eMyMoney::Account::Income); | 136 | set.addAccountGroup(eMyMoney::Account::Income); | ||
104 | if (m_accountType & KMyMoneyUtils::expense) | 137 | if (d->m_accountType & eDialogs::Category::expense) | ||
105 | set.addAccountGroup(eMyMoney::Account::Expense); | 138 | set.addAccountGroup(eMyMoney::Account::Expense); | ||
106 | if (m_accountType & KMyMoneyUtils::equity) | 139 | if (d->m_accountType & eDialogs::Category::equity) | ||
107 | set.addAccountGroup(eMyMoney::Account::Equity); | 140 | set.addAccountGroup(eMyMoney::Account::Equity); | ||
108 | if (m_accountType & KMyMoneyUtils::checking) | 141 | if (d->m_accountType & eDialogs::Category::checking) | ||
109 | set.addAccountType(eMyMoney::Account::Checkings); | 142 | set.addAccountType(eMyMoney::Account::Checkings); | ||
110 | if (m_accountType & KMyMoneyUtils::savings) | 143 | if (d->m_accountType & eDialogs::Category::savings) | ||
111 | set.addAccountType(eMyMoney::Account::Savings); | 144 | set.addAccountType(eMyMoney::Account::Savings); | ||
112 | if (m_accountType & KMyMoneyUtils::investment) | 145 | if (d->m_accountType & eDialogs::Category::investment) | ||
113 | set.addAccountType(eMyMoney::Account::Investment); | 146 | set.addAccountType(eMyMoney::Account::Investment); | ||
114 | if (m_accountType & KMyMoneyUtils::creditCard) | 147 | if (d->m_accountType & eDialogs::Category::creditCard) | ||
115 | set.addAccountType(eMyMoney::Account::CreditCard); | 148 | set.addAccountType(eMyMoney::Account::CreditCard); | ||
116 | 149 | | |||
117 | set.load(m_accountSelector->selector()); | 150 | set.load(d->ui->m_accountSelector->selector()); | ||
118 | } | 151 | } | ||
119 | 152 | | |||
120 | void KAccountSelectDlg::setDescription(const QString& msg) | 153 | void KAccountSelectDlg::setDescription(const QString& msg) | ||
121 | { | 154 | { | ||
122 | m_descLabel->setText(msg); | 155 | Q_D(KAccountSelectDlg); | ||
156 | d->ui->m_descLabel->setText(msg); | ||||
123 | } | 157 | } | ||
124 | 158 | | |||
125 | void KAccountSelectDlg::setHeader(const QString& msg) | 159 | void KAccountSelectDlg::setHeader(const QString& msg) | ||
126 | { | 160 | { | ||
127 | m_headerLabel->setText(msg); | 161 | Q_D(KAccountSelectDlg); | ||
162 | d->ui->m_headerLabel->setText(msg); | ||||
128 | } | 163 | } | ||
129 | 164 | | |||
130 | void KAccountSelectDlg::setAccount(const MyMoneyAccount& account, const QString& id) | 165 | void KAccountSelectDlg::setAccount(const MyMoneyAccount& account, const QString& id) | ||
131 | { | 166 | { | ||
132 | m_account = account; | 167 | Q_D(KAccountSelectDlg); | ||
133 | m_accountSelector->setSelectedItem(id); | 168 | d->m_account = account; | ||
169 | d->ui->m_accountSelector->setSelectedItem(id); | ||||
134 | } | 170 | } | ||
135 | 171 | | |||
136 | void KAccountSelectDlg::slotCreateInstitution() | 172 | void KAccountSelectDlg::slotCreateInstitution() | ||
Context not available. | |||||
140 | 176 | | |||
141 | void KAccountSelectDlg::slotCreateAccount() | 177 | void KAccountSelectDlg::slotCreateAccount() | ||
142 | { | 178 | { | ||
143 | if (!(m_accountType & (KMyMoneyUtils::expense | KMyMoneyUtils::income))) { | 179 | Q_D(KAccountSelectDlg); | ||
144 | kmymoney->slotAccountNew(m_account); | 180 | if (!((int)d->m_accountType & ((int)eDialogs::Category::expense | (int)eDialogs::Category::income))) { | ||
145 | if (!m_account.id().isEmpty()) { | 181 | kmymoney->slotAccountNew(d->m_account); | ||
182 | if (!d->m_account.id().isEmpty()) { | ||||
146 | slotReloadWidget(); | 183 | slotReloadWidget(); | ||
147 | m_accountSelector->setSelectedItem(m_account.id()); | 184 | d->ui->m_accountSelector->setSelectedItem(d->m_account.id()); | ||
148 | accept(); | 185 | accept(); | ||
149 | } | 186 | } | ||
150 | } else { | 187 | } else { | ||
151 | if (m_account.accountType() == eMyMoney::Account::Expense) | 188 | if (d->m_account.accountType() == eMyMoney::Account::Expense) | ||
152 | kmymoney->createCategory(m_account, MyMoneyFile::instance()->expense()); | 189 | kmymoney->createCategory(d->m_account, MyMoneyFile::instance()->expense()); | ||
153 | else | 190 | else | ||
154 | kmymoney->createCategory(m_account, MyMoneyFile::instance()->income()); | 191 | kmymoney->createCategory(d->m_account, MyMoneyFile::instance()->income()); | ||
155 | if (!m_account.id().isEmpty()) { | 192 | if (!d->m_account.id().isEmpty()) { | ||
156 | slotReloadWidget(); | 193 | slotReloadWidget(); | ||
157 | m_accountSelector->setSelectedItem(m_account.id()); | 194 | d->ui->m_accountSelector->setSelectedItem(d->m_account.id()); | ||
158 | accept(); | 195 | accept(); | ||
159 | } | 196 | } | ||
160 | } | 197 | } | ||
Context not available. | |||||
162 | 199 | | |||
163 | void KAccountSelectDlg::abort() | 200 | void KAccountSelectDlg::abort() | ||
164 | { | 201 | { | ||
165 | m_aborted = true; | 202 | Q_D(KAccountSelectDlg); | ||
203 | d->m_aborted = true; | ||||
166 | reject(); | 204 | reject(); | ||
167 | } | 205 | } | ||
168 | 206 | | |||
169 | void KAccountSelectDlg::setMode(const int mode) | 207 | void KAccountSelectDlg::setMode(const int mode) | ||
170 | { | 208 | { | ||
171 | m_mode = mode ? 1 : 0; | 209 | Q_D(KAccountSelectDlg); | ||
210 | d->m_mode = mode ? 1 : 0; | ||||
172 | } | 211 | } | ||
173 | 212 | | |||
174 | void KAccountSelectDlg::showAbortButton(const bool visible) | 213 | void KAccountSelectDlg::showAbortButton(const bool visible) | ||
175 | { | 214 | { | ||
176 | m_kButtonAbort->setVisible(visible); | 215 | Q_D(KAccountSelectDlg); | ||
216 | d->ui->m_kButtonAbort->setVisible(visible); | ||||
217 | } | ||||
218 | | ||||
219 | bool KAccountSelectDlg::aborted() const | ||||
220 | { | ||||
221 | Q_D(const KAccountSelectDlg); | ||||
222 | return d->m_aborted; | ||||
223 | } | ||||
224 | | ||||
225 | void KAccountSelectDlg::hideQifEntry() | ||||
226 | { | ||||
227 | Q_D(KAccountSelectDlg); | ||||
228 | d->ui->m_qifEntry->hide(); | ||||
177 | } | 229 | } | ||
178 | 230 | | |||
179 | int KAccountSelectDlg::exec() | 231 | int KAccountSelectDlg::exec() | ||
180 | { | 232 | { | ||
233 | Q_D(KAccountSelectDlg); | ||||
181 | int rc = Rejected; | 234 | int rc = Rejected; | ||
182 | 235 | | |||
183 | if (m_mode == 1) { | 236 | if (d->m_mode == 1) { | ||
184 | slotCreateAccount(); | 237 | slotCreateAccount(); | ||
185 | rc = result(); | 238 | rc = result(); | ||
186 | } | 239 | } | ||
187 | if (rc != Accepted) { | 240 | if (rc != Accepted) { | ||
188 | m_createButton->setFocus(); | 241 | d->ui->m_createButton->setFocus(); | ||
189 | rc = KAccountSelectDlgDecl::exec(); | 242 | rc = QDialog::exec(); | ||
190 | } | 243 | } | ||
191 | return rc; | 244 | return rc; | ||
192 | } | 245 | } | ||
193 | 246 | | |||
194 | const QString& KAccountSelectDlg::selectedAccount() const | 247 | QString KAccountSelectDlg::selectedAccount() const | ||
195 | { | 248 | { | ||
196 | return m_accountSelector->selectedItem(); | 249 | Q_D(const KAccountSelectDlg); | ||
250 | return d->ui->m_accountSelector->selectedItem(); | ||||
197 | } | 251 | } | ||
Context not available. |