Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/plugins/csvimport/bankingwizardpage.cpp
Show All 17 Lines | |||||
18 | ********************************************************************************/ | 18 | ********************************************************************************/ | ||
19 | 19 | | |||
20 | #include "bankingwizardpage.h" | 20 | #include "bankingwizardpage.h" | ||
21 | 21 | | |||
22 | // ---------------------------------------------------------------------------- | 22 | // ---------------------------------------------------------------------------- | ||
23 | // QT Includes | 23 | // QT Includes | ||
24 | 24 | | |||
25 | #include <QtCore/QTextStream> | 25 | #include <QtCore/QTextStream> | ||
26 | #include <QFile> | ||||
26 | 27 | | |||
27 | // ---------------------------------------------------------------------------- | 28 | // ---------------------------------------------------------------------------- | ||
28 | // KDE Includes | 29 | // KDE Includes | ||
29 | 30 | | |||
30 | #include <KMessageBox> | 31 | #include <KMessageBox> | ||
31 | 32 | | |||
32 | // ---------------------------------------------------------------------------- | 33 | // ---------------------------------------------------------------------------- | ||
33 | // Project Includes | 34 | // Project Includes | ||
34 | 35 | | |||
35 | #include "mymoneyfile.h" | 36 | #include <mymoneyfile.h> | ||
36 | #include "csvwizard.h" | 37 | #include "csvwizard.h" | ||
38 | #include "csvimporter.h" | ||||
37 | 39 | | |||
38 | #include "ui_bankingwizardpage.h" | 40 | #include "ui_bankingwizardpage.h" | ||
39 | 41 | | |||
40 | // ---------------------------------------------------------------------------- | 42 | // ---------------------------------------------------------------------------- | ||
41 | 43 | | |||
42 | BankingPage::BankingPage(CSVWizard *dlg, CSVImporter *imp) : | 44 | BankingPage::BankingPage(CSVWizard *dlg, CSVImporter *imp) : | ||
43 | CSVWizardPage(dlg, imp), | 45 | CSVWizardPage(dlg, imp), | ||
44 | ui(new Ui::BankingPage) | 46 | ui(new Ui::BankingPage) | ||
45 | { | 47 | { | ||
46 | ui->setupUi(this); | 48 | ui->setupUi(this); | ||
47 | m_pageLayout = new QVBoxLayout; | | |||
48 | ui->horizontalLayout->insertLayout(0, m_pageLayout); | | |||
49 | 49 | | |||
50 | connect(ui->m_clear, &QAbstractButton::clicked, this, &BankingPage::clearColumns); | 50 | connect(ui->m_clear, &QAbstractButton::clicked, this, &BankingPage::clearColumns); | ||
51 | connect(ui->m_radioAmount, &QAbstractButton::toggled, this, &BankingPage::amountToggled); | 51 | connect(ui->m_radioAmount, &QAbstractButton::toggled, this, &BankingPage::amountToggled); | ||
52 | connect(ui->m_radioDebitCredit, &QAbstractButton::toggled, this, &BankingPage::debitCreditToggled); | 52 | connect(ui->m_radioDebitCredit, &QAbstractButton::toggled, this, &BankingPage::debitCreditToggled); | ||
53 | connect(ui->m_oppositeSigns, &QAbstractButton::clicked, this, &BankingPage::oppositeSignsClicked); | 53 | connect(ui->m_oppositeSigns, &QAbstractButton::clicked, this, &BankingPage::oppositeSignsClicked); | ||
54 | 54 | | |||
55 | // initialize column names | 55 | // initialize column names | ||
56 | m_dlg->m_colTypeName.insert(ColumnPayee,i18n("Payee")); | 56 | m_dlg->m_colTypeName.insert(Column::Payee,i18n("Payee")); | ||
57 | m_dlg->m_colTypeName.insert(ColumnNumber,i18n("Number")); | 57 | m_dlg->m_colTypeName.insert(Column::Number,i18n("Number")); | ||
58 | m_dlg->m_colTypeName.insert(ColumnDebit,i18n("Debit")); | 58 | m_dlg->m_colTypeName.insert(Column::Debit,i18n("Debit")); | ||
59 | m_dlg->m_colTypeName.insert(ColumnCredit,i18n("Credit")); | 59 | m_dlg->m_colTypeName.insert(Column::Credit,i18n("Credit")); | ||
60 | m_dlg->m_colTypeName.insert(ColumnDate,i18n("Date")); | 60 | m_dlg->m_colTypeName.insert(Column::Date,i18n("Date")); | ||
61 | m_dlg->m_colTypeName.insert(ColumnAmount,i18n("Amount")); | 61 | m_dlg->m_colTypeName.insert(Column::Amount,i18n("Amount")); | ||
62 | m_dlg->m_colTypeName.insert(ColumnCategory,i18n("Category")); | 62 | m_dlg->m_colTypeName.insert(Column::Category,i18n("Category")); | ||
63 | m_dlg->m_colTypeName.insert(ColumnMemo,i18n("Memo")); | 63 | m_dlg->m_colTypeName.insert(Column::Memo,i18n("Memo")); | ||
64 | 64 | | |||
65 | m_profile = dynamic_cast<BankingProfile *>(m_imp->m_profile); | 65 | m_profile = dynamic_cast<BankingProfile *>(m_imp->m_profile); | ||
66 | } | | |||
67 | | ||||
68 | BankingPage::~BankingPage() | | |||
69 | { | | |||
70 | delete ui; | | |||
71 | } | | |||
72 | | ||||
73 | void BankingPage::initializeComboBoxes() | | |||
74 | { | | |||
75 | // disable banking widgets allowing their initialization | | |||
76 | disconnect(ui->m_amountCol, SIGNAL(currentIndexChanged(int)), this, SLOT(amountColSelected(int))); | | |||
77 | disconnect(ui->m_debitCol, SIGNAL(currentIndexChanged(int)), this, SLOT(debitColSelected(int))); | | |||
78 | disconnect(ui->m_creditCol, SIGNAL(currentIndexChanged(int)), this, SLOT(creditColSelected(int))); | | |||
79 | disconnect(ui->m_memoCol, SIGNAL(currentIndexChanged(int)), this, SLOT(memoColSelected(int))); | | |||
80 | disconnect(ui->m_numberCol, SIGNAL(currentIndexChanged(int)), this, SLOT(numberColSelected(int))); | | |||
81 | disconnect(ui->m_dateCol, SIGNAL(currentIndexChanged(int)), this, SLOT(dateColSelected(int))); | | |||
82 | disconnect(ui->m_payeeCol, SIGNAL(currentIndexChanged(int)), this, SLOT(payeeColSelected(int))); | | |||
83 | disconnect(ui->m_categoryCol, SIGNAL(currentIndexChanged(int)), this, SLOT(categoryColSelected(int))); | | |||
84 | | ||||
85 | // clear all existing items before adding new ones | | |||
86 | ui->m_numberCol->clear(); | | |||
87 | ui->m_dateCol->clear(); | | |||
88 | ui->m_payeeCol->clear(); | | |||
89 | ui->m_memoCol->clear(); | | |||
90 | ui->m_amountCol->clear(); | | |||
91 | ui->m_creditCol->clear(); | | |||
92 | ui->m_debitCol->clear(); | | |||
93 | ui->m_categoryCol->clear(); | | |||
94 | | ||||
95 | QStringList columnNumbers; | | |||
96 | for (int i = 0; i < m_imp->m_file->m_columnCount; ++i) | | |||
97 | columnNumbers.append(QString::number(i + 1)); | | |||
98 | | ||||
99 | // populate comboboxes with col # values | | |||
100 | ui->m_numberCol->addItems(columnNumbers); | | |||
101 | ui->m_dateCol->addItems(columnNumbers); | | |||
102 | ui->m_payeeCol->addItems(columnNumbers); | | |||
103 | ui->m_memoCol->addItems(columnNumbers); | | |||
104 | ui->m_amountCol->addItems(columnNumbers); | | |||
105 | ui->m_creditCol->addItems(columnNumbers); | | |||
106 | ui->m_debitCol->addItems(columnNumbers); | | |||
107 | ui->m_categoryCol->addItems(columnNumbers); | | |||
108 | 66 | | |||
109 | clearColumns(); // all comboboxes are set to 0 so set them to -1 | | |||
110 | connect(ui->m_amountCol, SIGNAL(currentIndexChanged(int)), this, SLOT(amountColSelected(int))); | 67 | connect(ui->m_amountCol, SIGNAL(currentIndexChanged(int)), this, SLOT(amountColSelected(int))); | ||
111 | connect(ui->m_debitCol, SIGNAL(currentIndexChanged(int)), this, SLOT(debitColSelected(int))); | 68 | connect(ui->m_debitCol, SIGNAL(currentIndexChanged(int)), this, SLOT(debitColSelected(int))); | ||
112 | connect(ui->m_creditCol, SIGNAL(currentIndexChanged(int)), this, SLOT(creditColSelected(int))); | 69 | connect(ui->m_creditCol, SIGNAL(currentIndexChanged(int)), this, SLOT(creditColSelected(int))); | ||
113 | connect(ui->m_memoCol, SIGNAL(currentIndexChanged(int)), this, SLOT(memoColSelected(int))); | 70 | connect(ui->m_memoCol, SIGNAL(currentIndexChanged(int)), this, SLOT(memoColSelected(int))); | ||
114 | connect(ui->m_numberCol, SIGNAL(currentIndexChanged(int)), this, SLOT(numberColSelected(int))); | 71 | connect(ui->m_numberCol, SIGNAL(currentIndexChanged(int)), this, SLOT(numberColSelected(int))); | ||
115 | connect(ui->m_dateCol, SIGNAL(currentIndexChanged(int)), this, SLOT(dateColSelected(int))); | 72 | connect(ui->m_dateCol, SIGNAL(currentIndexChanged(int)), this, SLOT(dateColSelected(int))); | ||
116 | connect(ui->m_payeeCol, SIGNAL(currentIndexChanged(int)), this, SLOT(payeeColSelected(int))); | 73 | connect(ui->m_payeeCol, SIGNAL(currentIndexChanged(int)), this, SLOT(payeeColSelected(int))); | ||
117 | connect(ui->m_categoryCol, SIGNAL(currentIndexChanged(int)), this, SLOT(categoryColSelected(int))); | 74 | connect(ui->m_categoryCol, SIGNAL(currentIndexChanged(int)), this, SLOT(categoryColSelected(int))); | ||
118 | } | 75 | } | ||
119 | 76 | | |||
77 | BankingPage::~BankingPage() | ||||
78 | { | ||||
79 | delete ui; | ||||
80 | } | ||||
81 | | ||||
120 | void BankingPage::initializePage() | 82 | void BankingPage::initializePage() | ||
121 | { | 83 | { | ||
84 | QHash<Column, QComboBox *> columns {{Column::Amount, ui->m_amountCol}, {Column::Debit, ui->m_debitCol}, | ||||
85 | {Column::Credit, ui->m_creditCol}, {Column::Memo, ui->m_memoCol}, | ||||
86 | {Column::Number, ui->m_numberCol}, {Column::Date, ui->m_dateCol}, | ||||
87 | {Column::Payee, ui->m_payeeCol}, {Column::Category, ui->m_categoryCol}}; | ||||
88 | | ||||
122 | if (ui->m_dateCol->count() != m_imp->m_file->m_columnCount) | 89 | if (ui->m_dateCol->count() != m_imp->m_file->m_columnCount) | ||
123 | initializeComboBoxes(); | 90 | m_dlg->initializeComboBoxes(columns); | ||
91 | | ||||
92 | columns.remove(Column::Memo); | ||||
93 | for (auto it = columns.cbegin(); it != columns.cend(); ++it) | ||||
94 | it.value()->setCurrentIndex(m_profile->m_colTypeNum.value(it.key())); | ||||
124 | 95 | | |||
125 | ui->m_payeeCol->setCurrentIndex(m_profile->m_colTypeNum.value(ColumnPayee)); | | |||
126 | ui->m_numberCol->setCurrentIndex(m_profile->m_colTypeNum.value(ColumnNumber)); | | |||
127 | ui->m_amountCol->setCurrentIndex(m_profile->m_colTypeNum.value(ColumnAmount)); | | |||
128 | ui->m_debitCol->setCurrentIndex(m_profile->m_colTypeNum.value(ColumnDebit)); | | |||
129 | ui->m_creditCol->setCurrentIndex(m_profile->m_colTypeNum.value(ColumnCredit)); | | |||
130 | ui->m_dateCol->setCurrentIndex(m_profile->m_colTypeNum.value(ColumnDate)); | | |||
131 | ui->m_categoryCol->setCurrentIndex(m_profile->m_colTypeNum.value(ColumnCategory)); | | |||
132 | ui->m_oppositeSigns->setChecked(m_profile->m_oppositeSigns); | 96 | ui->m_oppositeSigns->setChecked(m_profile->m_oppositeSigns); | ||
133 | 97 | | |||
134 | if (m_profile->m_memoColList.count() > 0) | 98 | if (m_profile->m_memoColList.count() > 0) | ||
135 | { | 99 | { | ||
136 | for (int i = 0; i < m_profile->m_memoColList.count(); ++i) | 100 | for (int i = 0; i < m_profile->m_memoColList.count(); ++i) | ||
137 | ui->m_memoCol->setCurrentIndex(m_profile->m_memoColList.value(i)); | 101 | ui->m_memoCol->setCurrentIndex(m_profile->m_memoColList.value(i)); | ||
138 | } else | 102 | } else | ||
139 | ui->m_memoCol->setCurrentIndex(-1); | 103 | ui->m_memoCol->setCurrentIndex(-1); | ||
140 | 104 | | |||
141 | if (this->m_profile->m_colTypeNum.value(ColumnDebit) == -1) // If amount previously selected, set check radio_amount | 105 | if (this->m_profile->m_colTypeNum.value(Column::Debit) == -1) // If amount previously selected, set check radio_amount | ||
142 | ui->m_radioAmount->setChecked(true); | 106 | ui->m_radioAmount->setChecked(true); | ||
143 | else // ...else set check radio_debCred to clear amount col | 107 | else // ...else set check radio_debCred to clear amount col | ||
144 | ui->m_radioDebitCredit->setChecked(true); | 108 | ui->m_radioDebitCredit->setChecked(true); | ||
145 | } | 109 | } | ||
146 | 110 | | |||
147 | int BankingPage::nextId() const | 111 | int BankingPage::nextId() const | ||
148 | { | 112 | { | ||
149 | return CSVWizard::PageFormats; | 113 | return CSVWizard::PageFormats; | ||
Show All 10 Lines | |||||
160 | 124 | | |||
161 | bool BankingPage::validateMemoComboBox() | 125 | bool BankingPage::validateMemoComboBox() | ||
162 | { | 126 | { | ||
163 | if (m_profile->m_memoColList.count() == 0) | 127 | if (m_profile->m_memoColList.count() == 0) | ||
164 | return true; | 128 | return true; | ||
165 | for (int i = 0; i < ui->m_memoCol->count(); ++i) | 129 | for (int i = 0; i < ui->m_memoCol->count(); ++i) | ||
166 | { | 130 | { | ||
167 | QString txt = ui->m_memoCol->itemText(i); | 131 | QString txt = ui->m_memoCol->itemText(i); | ||
168 | if (txt.contains(QChar(QLatin1Char('*')))) // check if text containing '*' belongs to valid column types | 132 | if (txt.contains(QLatin1Char('*'))) // check if text containing '*' belongs to valid column types | ||
169 | if (m_profile->m_colNumType.value(i) != ColumnPayee) { | 133 | if (m_profile->m_colNumType.value(i) != Column::Payee) { | ||
170 | ui->m_memoCol->setItemText(i, QString::number(i + 1)); | 134 | ui->m_memoCol->setItemText(i, QString::number(i + 1)); | ||
171 | m_profile->m_memoColList.removeOne(i); | 135 | m_profile->m_memoColList.removeOne(i); | ||
172 | return false; | 136 | return false; | ||
173 | } | 137 | } | ||
174 | } | 138 | } | ||
175 | return true; | 139 | return true; | ||
176 | } | 140 | } | ||
177 | 141 | | |||
178 | void BankingPage::memoColSelected(int col) | 142 | void BankingPage::memoColSelected(int col) | ||
179 | { | 143 | { | ||
180 | if (m_profile->m_colNumType.value(col) == ColumnPayee ) { | 144 | if (m_profile->m_colNumType.value(col) == Column::Payee ) { | ||
181 | int rc = KMessageBox::Yes; | 145 | int rc = KMessageBox::Yes; | ||
182 | if (isVisible()) | 146 | if (isVisible()) | ||
183 | rc = KMessageBox::questionYesNo(m_dlg, i18n("<center>The '<b>%1</b>' field already has this column selected.</center>" | 147 | rc = KMessageBox::questionYesNo(m_dlg, i18n("<center>The '<b>%1</b>' field already has this column selected.</center>" | ||
184 | "<center>If you wish to copy the Payee data to the memo field, click 'Yes'.</center>", | 148 | "<center>If you wish to copy the Payee data to the memo field, click 'Yes'.</center>", | ||
185 | m_dlg->m_colTypeName.value(m_profile->m_colNumType.value(col)))); | 149 | m_dlg->m_colTypeName.value(m_profile->m_colNumType.value(col)))); | ||
186 | if (rc == KMessageBox::Yes) { | 150 | if (rc == KMessageBox::Yes) { | ||
187 | ui->m_memoCol->setItemText(col, QString::number(col + 1) + QChar(QLatin1Char('*'))); | 151 | ui->m_memoCol->setItemText(col, QString::number(col + 1) + QLatin1Char('*')); | ||
188 | if (!m_profile->m_memoColList.contains(col)) | 152 | if (!m_profile->m_memoColList.contains(col)) | ||
189 | m_profile->m_memoColList.append(col); | 153 | m_profile->m_memoColList.append(col); | ||
190 | } else { | 154 | } else { | ||
191 | ui->m_memoCol->setItemText(col, QString::number(col + 1)); | 155 | ui->m_memoCol->setItemText(col, QString::number(col + 1)); | ||
192 | m_profile->m_memoColList.removeOne(col); | 156 | m_profile->m_memoColList.removeOne(col); | ||
193 | } | 157 | } | ||
194 | //allow only separate memo field occupy combobox | 158 | //allow only separate memo field occupy combobox | ||
195 | ui->m_memoCol->blockSignals(true); | 159 | ui->m_memoCol->blockSignals(true); | ||
196 | if (m_profile->m_colTypeNum.value(ColumnMemo) != -1) | 160 | if (m_profile->m_colTypeNum.value(Column::Memo) != -1) | ||
197 | ui->m_memoCol->setCurrentIndex(m_profile->m_colTypeNum.value(ColumnMemo)); | 161 | ui->m_memoCol->setCurrentIndex(m_profile->m_colTypeNum.value(Column::Memo)); | ||
198 | else | 162 | else | ||
199 | ui->m_memoCol->setCurrentIndex(-1); | 163 | ui->m_memoCol->setCurrentIndex(-1); | ||
200 | ui->m_memoCol->blockSignals(false); | 164 | ui->m_memoCol->blockSignals(false); | ||
201 | return; | 165 | return; | ||
202 | } | 166 | } | ||
203 | 167 | | |||
204 | if (m_profile->m_colTypeNum.value(ColumnMemo) != -1) // check if this memo has any column 'number' assigned... | 168 | if (m_profile->m_colTypeNum.value(Column::Memo) != -1) // check if this memo has any column 'number' assigned... | ||
205 | m_profile->m_memoColList.removeOne(col); // ...if true remove it from memo list | 169 | m_profile->m_memoColList.removeOne(col); // ...if true remove it from memo list | ||
206 | 170 | | |||
207 | if(validateSelectedColumn(col, ColumnMemo)) | 171 | if(validateSelectedColumn(col, Column::Memo)) | ||
208 | if (col != - 1 && !m_profile->m_memoColList.contains(col)) | 172 | if (col != - 1 && !m_profile->m_memoColList.contains(col)) | ||
209 | m_profile->m_memoColList.append(col); | 173 | m_profile->m_memoColList.append(col); | ||
210 | } | 174 | } | ||
211 | 175 | | |||
212 | void BankingPage::categoryColSelected(int col) | 176 | void BankingPage::categoryColSelected(int col) | ||
213 | { | 177 | { | ||
214 | validateSelectedColumn(col, ColumnCategory); | 178 | validateSelectedColumn(col, Column::Category); | ||
215 | } | 179 | } | ||
216 | 180 | | |||
217 | void BankingPage::numberColSelected(int col) | 181 | void BankingPage::numberColSelected(int col) | ||
218 | { | 182 | { | ||
219 | validateSelectedColumn(col, ColumnNumber); | 183 | validateSelectedColumn(col, Column::Number); | ||
220 | } | 184 | } | ||
221 | 185 | | |||
222 | void BankingPage::payeeColSelected(int col) | 186 | void BankingPage::payeeColSelected(int col) | ||
223 | { | 187 | { | ||
224 | if (validateSelectedColumn(col, ColumnPayee)) | 188 | if (validateSelectedColumn(col, Column::Payee)) | ||
225 | if (!validateMemoComboBox()) // user could have it already in memo so... | 189 | if (!validateMemoComboBox()) // user could have it already in memo so... | ||
226 | memoColSelected(col); // ...if true set memo field again | 190 | memoColSelected(col); // ...if true set memo field again | ||
227 | } | 191 | } | ||
228 | 192 | | |||
229 | void BankingPage::dateColSelected(int col) | 193 | void BankingPage::dateColSelected(int col) | ||
230 | { | 194 | { | ||
231 | validateSelectedColumn(col, ColumnDate); | 195 | validateSelectedColumn(col, Column::Date); | ||
232 | } | 196 | } | ||
233 | 197 | | |||
234 | void BankingPage::debitColSelected(int col) | 198 | void BankingPage::debitColSelected(int col) | ||
235 | { | 199 | { | ||
236 | validateSelectedColumn(col, ColumnDebit); | 200 | validateSelectedColumn(col, Column::Debit); | ||
237 | } | 201 | } | ||
238 | 202 | | |||
239 | void BankingPage::creditColSelected(int col) | 203 | void BankingPage::creditColSelected(int col) | ||
240 | { | 204 | { | ||
241 | validateSelectedColumn(col, ColumnCredit); | 205 | validateSelectedColumn(col, Column::Credit); | ||
242 | } | 206 | } | ||
243 | 207 | | |||
244 | void BankingPage::amountColSelected(int col) | 208 | void BankingPage::amountColSelected(int col) | ||
245 | { | 209 | { | ||
246 | validateSelectedColumn(col, ColumnAmount); | 210 | validateSelectedColumn(col, Column::Amount); | ||
247 | } | 211 | } | ||
248 | 212 | | |||
249 | void BankingPage::amountToggled(bool checked) | 213 | void BankingPage::amountToggled(bool checked) | ||
250 | { | 214 | { | ||
251 | if (checked) { | 215 | if (checked) { | ||
252 | ui->m_amountCol->setEnabled(true); // disable credit & debit ui choices | 216 | ui->m_amountCol->setEnabled(true); // disable credit & debit ui choices | ||
253 | ui->labelBnk_amount->setEnabled(true); | 217 | ui->labelBnk_amount->setEnabled(true); | ||
254 | ui->labelBnk_credits->setEnabled(false); | 218 | ui->labelBnk_credits->setEnabled(false); | ||
Show All 32 Lines | 248 | { | |||
287 | ui->m_memoCol->setCurrentIndex(-1); | 251 | ui->m_memoCol->setCurrentIndex(-1); | ||
288 | ui->m_numberCol->setCurrentIndex(-1); | 252 | ui->m_numberCol->setCurrentIndex(-1); | ||
289 | ui->m_amountCol->setCurrentIndex(-1); | 253 | ui->m_amountCol->setCurrentIndex(-1); | ||
290 | ui->m_debitCol->setCurrentIndex(-1); | 254 | ui->m_debitCol->setCurrentIndex(-1); | ||
291 | ui->m_creditCol->setCurrentIndex(-1); | 255 | ui->m_creditCol->setCurrentIndex(-1); | ||
292 | ui->m_categoryCol->setCurrentIndex(-1); | 256 | ui->m_categoryCol->setCurrentIndex(-1); | ||
293 | } | 257 | } | ||
294 | 258 | | |||
295 | void BankingPage::resetComboBox(const columnTypeE comboBox) | 259 | void BankingPage::resetComboBox(const Column comboBox) | ||
296 | { | 260 | { | ||
297 | switch (comboBox) { | 261 | switch (comboBox) { | ||
298 | case ColumnAmount: | 262 | case Column::Amount: | ||
299 | ui->m_amountCol->setCurrentIndex(-1); | 263 | ui->m_amountCol->setCurrentIndex(-1); | ||
300 | break; | 264 | break; | ||
301 | case ColumnCredit: | 265 | case Column::Credit: | ||
302 | ui->m_creditCol->setCurrentIndex(-1); | 266 | ui->m_creditCol->setCurrentIndex(-1); | ||
303 | break; | 267 | break; | ||
304 | case ColumnDate: | 268 | case Column::Date: | ||
305 | ui->m_dateCol->setCurrentIndex(-1); | 269 | ui->m_dateCol->setCurrentIndex(-1); | ||
306 | break; | 270 | break; | ||
307 | case ColumnDebit: | 271 | case Column::Debit: | ||
308 | ui->m_debitCol->setCurrentIndex(-1); | 272 | ui->m_debitCol->setCurrentIndex(-1); | ||
309 | break; | 273 | break; | ||
310 | case ColumnMemo: | 274 | case Column::Memo: | ||
311 | ui->m_memoCol->setCurrentIndex(-1); | 275 | ui->m_memoCol->setCurrentIndex(-1); | ||
312 | break; | 276 | break; | ||
313 | case ColumnNumber: | 277 | case Column::Number: | ||
314 | ui->m_numberCol->setCurrentIndex(-1); | 278 | ui->m_numberCol->setCurrentIndex(-1); | ||
315 | break; | 279 | break; | ||
316 | case ColumnPayee: | 280 | case Column::Payee: | ||
317 | ui->m_payeeCol->setCurrentIndex(-1); | 281 | ui->m_payeeCol->setCurrentIndex(-1); | ||
318 | break; | 282 | break; | ||
319 | case ColumnCategory: | 283 | case Column::Category: | ||
320 | ui->m_categoryCol->setCurrentIndex(-1); | 284 | ui->m_categoryCol->setCurrentIndex(-1); | ||
321 | break; | 285 | break; | ||
322 | default: | 286 | default: | ||
323 | KMessageBox::sorry(m_dlg, i18n("<center>Field name not recognised.</center> <center>'<b>%1</b>'</center> Please re-enter your column selections." | 287 | KMessageBox::sorry(m_dlg, i18n("<center>Field name not recognised.</center> <center>'<b>%1</b>'</center> Please re-enter your column selections." | ||
324 | , comboBox), i18n("CSV import")); | 288 | , (int)comboBox), i18n("CSV import")); | ||
325 | } | 289 | } | ||
326 | } | 290 | } | ||
327 | 291 | | |||
328 | bool BankingPage::validateSelectedColumn(const int col, const columnTypeE type) | 292 | bool BankingPage::validateSelectedColumn(const int col, const Column type) | ||
329 | { | 293 | { | ||
330 | if (m_profile->m_colTypeNum.value(type) != -1) // check if this 'type' has any column 'number' assigned... | 294 | if (m_profile->m_colTypeNum.value(type) != -1) // check if this 'type' has any column 'number' assigned... | ||
331 | m_profile->m_colNumType.remove(m_profile->m_colTypeNum[type]); // ...if true remove 'type' assigned to this column 'number' | 295 | m_profile->m_colNumType.remove(m_profile->m_colTypeNum[type]); // ...if true remove 'type' assigned to this column 'number' | ||
332 | 296 | | |||
333 | bool ret = true; | 297 | bool ret = true; | ||
334 | if (col == -1) { // user only wanted to reset his column so allow him | 298 | if (col == -1) { // user only wanted to reset his column so allow him | ||
335 | m_profile->m_colTypeNum[type] = col; // assign new column 'number' to this 'type' | 299 | m_profile->m_colTypeNum[type] = col; // assign new column 'number' to this 'type' | ||
336 | } else if (m_profile->m_colNumType.contains(col)) { // if this column 'number' has already 'type' assigned | 300 | } else if (m_profile->m_colNumType.contains(col)) { // if this column 'number' has already 'type' assigned | ||
Show All 9 Lines | |||||
346 | emit completeChanged(); | 310 | emit completeChanged(); | ||
347 | return ret; | 311 | return ret; | ||
348 | } | 312 | } | ||
349 | 313 | | |||
350 | bool BankingPage::validateCreditDebit() | 314 | bool BankingPage::validateCreditDebit() | ||
351 | { | 315 | { | ||
352 | for (int row = m_profile->m_startLine; row <= m_profile->m_endLine; ++row) { | 316 | for (int row = m_profile->m_startLine; row <= m_profile->m_endLine; ++row) { | ||
353 | // process credit/debit field | 317 | // process credit/debit field | ||
354 | if (m_profile->m_colTypeNum.value(ColumnCredit) != -1 && | 318 | if (m_profile->m_colTypeNum.value(Column::Credit) != -1 && | ||
355 | m_profile->m_colTypeNum.value(ColumnDebit) != -1) { | 319 | m_profile->m_colTypeNum.value(Column::Debit) != -1) { | ||
356 | QString credit = m_imp->m_file->m_model->item(row, m_profile->m_colTypeNum.value(ColumnCredit))->text(); | 320 | QString credit = m_imp->m_file->m_model->item(row, m_profile->m_colTypeNum.value(Column::Credit))->text(); | ||
357 | QString debit = m_imp->m_file->m_model->item(row, m_profile->m_colTypeNum.value(ColumnDebit))->text(); | 321 | QString debit = m_imp->m_file->m_model->item(row, m_profile->m_colTypeNum.value(Column::Debit))->text(); | ||
358 | m_imp->processCreditDebit(credit, debit); | 322 | m_imp->processCreditDebit(credit, debit); | ||
359 | if (!credit.isEmpty() && !debit.isEmpty()) { | 323 | if (!credit.isEmpty() && !debit.isEmpty()) { | ||
360 | int ret = KMessageBox::questionYesNoCancel(m_dlg, | 324 | int ret = KMessageBox::questionYesNoCancel(m_dlg, | ||
361 | i18n("<center>The %1 field contains '%2'</center>" | 325 | i18n("<center>The %1 field contains '%2'</center>" | ||
362 | "<center>and the %3 field contains '%4'.</center>" | 326 | "<center>and the %3 field contains '%4'.</center>" | ||
363 | "<center>Please choose which you wish to accept.</center>", | 327 | "<center>Please choose which you wish to accept.</center>", | ||
364 | m_dlg->m_colTypeName.value(ColumnDebit), | 328 | m_dlg->m_colTypeName.value(Column::Debit), | ||
365 | debit, | 329 | debit, | ||
366 | m_dlg->m_colTypeName.value(ColumnCredit), | 330 | m_dlg->m_colTypeName.value(Column::Credit), | ||
367 | credit), | 331 | credit), | ||
368 | i18n("CSV invalid field values"), | 332 | i18n("CSV invalid field values"), | ||
369 | KGuiItem(i18n("Accept %1", m_dlg->m_colTypeName.value(ColumnDebit))), | 333 | KGuiItem(i18n("Accept %1", m_dlg->m_colTypeName.value(Column::Debit))), | ||
370 | KGuiItem(i18n("Accept %1", m_dlg->m_colTypeName.value(ColumnCredit))), | 334 | KGuiItem(i18n("Accept %1", m_dlg->m_colTypeName.value(Column::Credit))), | ||
371 | KGuiItem(i18n("Cancel"))); | 335 | KGuiItem(i18n("Cancel"))); | ||
372 | switch(ret) { | 336 | switch(ret) { | ||
373 | case KMessageBox::Cancel: | 337 | case KMessageBox::Cancel: | ||
374 | return false; | 338 | return false; | ||
375 | case KMessageBox::Yes: | 339 | case KMessageBox::Yes: | ||
376 | m_imp->m_file->m_model->item(row, m_profile->m_colTypeNum.value(ColumnCredit))->setText(QString()); | 340 | m_imp->m_file->m_model->item(row, m_profile->m_colTypeNum.value(Column::Credit))->setText(QString()); | ||
377 | break; | 341 | break; | ||
378 | case KMessageBox::No: | 342 | case KMessageBox::No: | ||
379 | m_imp->m_file->m_model->item(row, m_profile->m_colTypeNum.value(ColumnDebit))->setText(QString()); | 343 | m_imp->m_file->m_model->item(row, m_profile->m_colTypeNum.value(Column::Debit))->setText(QString()); | ||
380 | break; | 344 | break; | ||
381 | } | 345 | } | ||
382 | } | 346 | } | ||
383 | } | 347 | } | ||
384 | } | 348 | } | ||
385 | return true; | 349 | return true; | ||
386 | } | 350 | } | ||
387 | 351 | | |||
388 | void BankingPage::makeQIF(MyMoneyStatement& st, QFile& file) | 352 | void BankingPage::makeQIF(const MyMoneyStatement& st, const QString& outFileName) | ||
389 | { | 353 | { | ||
390 | QTextStream out(&file); | 354 | QFile oFile(outFileName); | ||
355 | oFile.open(QIODevice::WriteOnly); | ||||
356 | QTextStream out(&oFile); | ||||
391 | 357 | | |||
392 | QString buffer; | 358 | QString buffer; | ||
393 | QString strEType; | 359 | QString strEType; | ||
394 | 360 | | |||
395 | switch (st.m_eType) { | 361 | switch (st.m_eType) { | ||
396 | case MyMoneyStatement::etCreditCard: | 362 | case MyMoneyStatement::etCreditCard: | ||
397 | strEType = QStringLiteral("CCard"); | 363 | strEType = QStringLiteral("CCard"); | ||
398 | case MyMoneyStatement::etSavings: | 364 | case MyMoneyStatement::etSavings: | ||
Show All 22 Lines | 379 | for (QList<MyMoneyStatement::Transaction>::const_iterator it = st.m_listTransactions.constBegin(); it != st.m_listTransactions.constEnd(); ++it) { | |||
421 | if (!it->m_strNumber.isEmpty()) | 387 | if (!it->m_strNumber.isEmpty()) | ||
422 | buffer.append(QChar(QLatin1Char('N')) + it->m_strNumber + QChar(QLatin1Char('\n'))); | 388 | buffer.append(QChar(QLatin1Char('N')) + it->m_strNumber + QChar(QLatin1Char('\n'))); | ||
423 | if (!it->m_strMemo.isEmpty()) | 389 | if (!it->m_strMemo.isEmpty()) | ||
424 | buffer.append(QChar(QLatin1Char('M')) + it->m_strMemo + QChar(QLatin1Char('\n'))); | 390 | buffer.append(QChar(QLatin1Char('M')) + it->m_strMemo + QChar(QLatin1Char('\n'))); | ||
425 | buffer.append(QStringLiteral("^\n")); | 391 | buffer.append(QStringLiteral("^\n")); | ||
426 | out << buffer;// output qif file | 392 | out << buffer;// output qif file | ||
427 | buffer.clear(); | 393 | buffer.clear(); | ||
428 | } | 394 | } | ||
395 | oFile.close(); | ||||
429 | } | 396 | } |