Diffstat (limited to 'noncore/apps/checkbook/qcheckview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/checkbook/qcheckview.cpp | 458 |
1 files changed, 0 insertions, 458 deletions
diff --git a/noncore/apps/checkbook/qcheckview.cpp b/noncore/apps/checkbook/qcheckview.cpp deleted file mode 100644 index ddc3fa9..0000000 --- a/noncore/apps/checkbook/qcheckview.cpp +++ b/dev/null | |||
@@ -1,458 +0,0 @@ | |||
1 | #include "qcheckview.h" | ||
2 | |||
3 | #include <qpe/resource.h> | ||
4 | #include <qregexp.h> | ||
5 | #include <qlineedit.h> | ||
6 | #include <qradiobutton.h> | ||
7 | #include <qcombobox.h> | ||
8 | #include <qapplication.h> | ||
9 | #include <qpushbutton.h> | ||
10 | #include <qdir.h> | ||
11 | #include <qlabel.h> | ||
12 | #include <qdatetime.h> | ||
13 | #include <qmessagebox.h> | ||
14 | #include <qcheckbox.h> | ||
15 | #include <qfile.h> | ||
16 | #include <qtextstream.h> | ||
17 | #include <qbuttongroup.h> | ||
18 | #include <qradiobutton.h> | ||
19 | #include <qheader.h> | ||
20 | |||
21 | QCheckView::QCheckView(QWidget *parent, QString filename) | ||
22 | : QCheckViewBase(parent) | ||
23 | { | ||
24 | tblTransactions->setHScrollBarMode( QTable::AlwaysOff ); | ||
25 | tblTransactions->setNumRows( 0 ); | ||
26 | tblTransactions->setNumCols( 4 ); | ||
27 | tblTransactions->setShowGrid( FALSE ); | ||
28 | tblTransactions->horizontalHeader()->setLabel(0, "Num", 29); | ||
29 | tblTransactions->horizontalHeader()->setLabel(1, "Description", 81); | ||
30 | tblTransactions->horizontalHeader()->setLabel(2, "Date", 57); | ||
31 | tblTransactions->horizontalHeader()->setLabel(3, "Amount", 59); | ||
32 | tblTransactions->verticalHeader()->hide(); | ||
33 | tblTransactions->setLeftMargin( 0 ); | ||
34 | tblTransactions->setSelectionMode(QTable::NoSelection); | ||
35 | |||
36 | m_filename = filename; | ||
37 | load(filename); | ||
38 | } | ||
39 | |||
40 | void QCheckView::deleteClicked(int row, int col) | ||
41 | { | ||
42 | QStringList existing; | ||
43 | QString rowText = tblTransactions->text(row, 0); | ||
44 | config->setGroup(rowText); | ||
45 | QString originalamount = config->readEntry("Amount", "0.00"); | ||
46 | |||
47 | config->setGroup("Data"); | ||
48 | int lastCheck = config->readNumEntry("LastCheck", 0); | ||
49 | |||
50 | qWarning(rowText); | ||
51 | config->setGroup(rowText); | ||
52 | QString payment = config->readEntry("Payment", "true"); | ||
53 | if ( payment == QString("true") && rowText.toInt() <= lastCheck) | ||
54 | { | ||
55 | for(int i = row; i != (lastCheck); i++) | ||
56 | { | ||
57 | config->setGroup(tblTransactions->text(i, 0)); | ||
58 | QString ibalance = config->readEntry("Balance", "0.00"); | ||
59 | // this adds the old amount on to the transaction and then takes the new amount away | ||
60 | QString newbalance = calculator(ibalance, originalamount, false); | ||
61 | config->writeEntry("Balance", newbalance); | ||
62 | |||
63 | if (i == (lastCheck - 1)) | ||
64 | { | ||
65 | config->setGroup("Totals"); | ||
66 | config->writeEntry("Balance", newbalance); | ||
67 | break; | ||
68 | } | ||
69 | } | ||
70 | QString category = config->readEntry("Category", "Error"); | ||
71 | if (category != QString("Error")) | ||
72 | { | ||
73 | config->setGroup("Totals"); | ||
74 | config->writeEntry("Spent", calculator(config->readEntry("Spent", QString("0")), originalamount, true)); | ||
75 | QString categorytotal = config->readEntry(category, QString("0")); | ||
76 | categorytotal = calculator(categorytotal, originalamount, true); | ||
77 | config->writeEntry(category, categorytotal); | ||
78 | } | ||
79 | } | ||
80 | if ( payment == QString("false") && rowText.toInt() <= lastCheck) | ||
81 | { | ||
82 | for(int i = row; i != (lastCheck); i++) | ||
83 | { | ||
84 | config->setGroup(tblTransactions->text(i, 0)); | ||
85 | QString ibalance = config->readEntry("Balance", "0.00"); | ||
86 | // this subtracts the old amount on to the transaction and then adds the new amount on | ||
87 | QString newbalance = calculator(ibalance, originalamount, true); | ||
88 | config->writeEntry("Balance", newbalance); | ||
89 | |||
90 | if (i == lastCheck - 1) | ||
91 | { | ||
92 | config->setGroup("Totals"); | ||
93 | config->writeEntry("Balance", newbalance); | ||
94 | break; | ||
95 | } | ||
96 | } | ||
97 | config->setGroup("Totals"); | ||
98 | config->writeEntry("Deposited", calculator(config->readEntry("Deposited", QString("0")), originalamount, true)); | ||
99 | } | ||
100 | for (int i = rowText.toInt(); i != lastCheck; i++) | ||
101 | { | ||
102 | qWarning(QString::number(i +1)); | ||
103 | config->setGroup(QString::number(i +1)); | ||
104 | QString origamount = config->readEntry("Amount", "0"); | ||
105 | qWarning(origamount); | ||
106 | QString origbalance = config->readEntry("Balance", "0"); | ||
107 | QString origchecknumber = config->readEntry("CheckNumber", "0"); | ||
108 | QString origcomments = config->readEntry("Comments", ""); | ||
109 | QString origdate = config->readEntry("Date", "01/01/2000"); | ||
110 | QString origdescription = config->readEntry("Description", "No Description"); | ||
111 | QString origpayment = config->readEntry("Payment", "true"); | ||
112 | QString origtransactionfee = config->readEntry("TransactionFee", "0"); | ||
113 | QString origtype = config->readEntry("Type", "0"); | ||
114 | |||
115 | if (config->hasKey("Category")) | ||
116 | { | ||
117 | QString origcategory = config->readEntry("Category", "No Category"); | ||
118 | config->removeGroup(); | ||
119 | config->setGroup(QString::number(i)); | ||
120 | config->clearGroup(); | ||
121 | config->writeEntry("Category", origcategory); | ||
122 | } else { | ||
123 | config->removeGroup(); | ||
124 | config->setGroup(QString::number(i)); | ||
125 | config->clearGroup(); | ||
126 | } | ||
127 | config->writeEntry("Amount", origamount); | ||
128 | config->writeEntry("Balance", origbalance); | ||
129 | config->writeEntry("CheckNumber", origchecknumber); | ||
130 | config->writeEntry("Comments", origcomments); | ||
131 | config->writeEntry("Date", origdate); | ||
132 | config->writeEntry("Description", origdescription); | ||
133 | config->writeEntry("Payment", origpayment); | ||
134 | config->writeEntry("TransactionFee", origtransactionfee); | ||
135 | config->writeEntry("Type", origtype); | ||
136 | } | ||
137 | tblTransactions->clearCell(row, col); | ||
138 | labelBalance->setText(QString("$" + config->readEntry("Balance", QString("0.00")))); | ||
139 | config->setGroup("Data"); | ||
140 | config->writeEntry("LastCheck", QString::number(QString(config->readEntry("LastCheck", 0)).toInt() -1)); | ||
141 | config->write(); | ||
142 | delete qcd; | ||
143 | emit reload(m_filename); | ||
144 | |||
145 | } | ||
146 | |||
147 | void QCheckView::load(const QString filename) | ||
148 | { | ||
149 | config = new Config(filename, Config::File); | ||
150 | |||
151 | connect(tblTransactions, SIGNAL(clicked(int, int, int, const QPoint &)), this, SLOT(tableClicked(int, int, int, const QPoint &))); | ||
152 | |||
153 | config->setGroup("Totals"); | ||
154 | labelBalance->setText(QString("$" + config->readEntry("Balance", QString("0.00")))); | ||
155 | |||
156 | config->setGroup("Data"); | ||
157 | int lastCheck = config->readNumEntry("LastCheck", 1); | ||
158 | for (int i = 1; i != (lastCheck + 1); i++) | ||
159 | { | ||
160 | config->setGroup(QString::number(i)); | ||
161 | QString item = config->readEntry("Description", QString("Not Found")); | ||
162 | if (item != "Not Found") | ||
163 | { | ||
164 | QTableItem *qti = new QTableItem(tblTransactions, QTableItem::Never, QString::number(i)); | ||
165 | QTableItem *qti1 = new QTableItem(tblTransactions, QTableItem::Never, config->readEntry("Description", QString("None"))); | ||
166 | QTableItem *qti2 = new QTableItem(tblTransactions, QTableItem::Never, config->readEntry("Date", QString("None"))); | ||
167 | QTableItem *qti3 = new QTableItem(tblTransactions, QTableItem::Never, QString("$" + config->readEntry("Amount", QString("0.00")))); | ||
168 | int row = tblTransactions->numRows(); | ||
169 | tblTransactions->setNumRows(row + 1); | ||
170 | tblTransactions->setItem(row,0, qti); | ||
171 | tblTransactions->setItem(row,1, qti1); | ||
172 | tblTransactions->setItem(row,2, qti2); | ||
173 | tblTransactions->setItem(row,3, qti3); | ||
174 | tblTransactions->updateCell(row, 0); | ||
175 | tblTransactions->updateCell(row, 1); | ||
176 | tblTransactions->updateCell(row, 2); | ||
177 | tblTransactions->updateCell(row, 3); | ||
178 | } | ||
179 | } | ||
180 | } | ||
181 | |||
182 | void QCheckView::editClicked(int row, int col) | ||
183 | { | ||
184 | delete qcd; | ||
185 | QStringList existing; | ||
186 | QString rowText = tblTransactions->text(row, 0); | ||
187 | config->setGroup("Data"); | ||
188 | QString recent = config->readEntry("Recent", ""); | ||
189 | |||
190 | config->setGroup(rowText); | ||
191 | //We need the original amount to add or subtract to check's blanaces written after this edited check | ||
192 | QString originalamount = config->readEntry("Amount", "0.00"); | ||
193 | QString originalcategory = config->readEntry("Category", "None"); | ||
194 | |||
195 | existing << config->readEntry("Payment", "true") << config->readEntry("Description", "No Description Found") << config->readEntry("Category", "Misc.") << config->readEntry("Type", "0") << config->readEntry("CheckNumber", "0") << originalamount << config->readEntry("TransactionFee", "") << config->readEntry("Date", "01/01/2001") << config->readEntry("Comments", "") << recent; | ||
196 | QStringList result = QCheckEntry::popupEntry(existing); | ||
197 | if (result.isEmpty() == false) | ||
198 | { | ||
199 | config->setGroup("Data"); | ||
200 | int lastCheck = config->readNumEntry("LastCheck", 0); | ||
201 | config->writeEntry("Recent", result[9]); | ||
202 | |||
203 | config->setGroup(rowText); | ||
204 | |||
205 | tblTransactions->setText(row, 1, result[1]); | ||
206 | tblTransactions->updateCell(row, 1); | ||
207 | |||
208 | tblTransactions->setText(row, 2, result[7]); | ||
209 | tblTransactions->updateCell(row, 2); | ||
210 | |||
211 | tblTransactions->setText(row, 3, QString("$" + result[5])); | ||
212 | tblTransactions->updateCell(row, 3); | ||
213 | |||
214 | // This is how the list looks: | ||
215 | // 0: true or false, true == payment, false == deposit | ||
216 | // 1: description of the transaction | ||
217 | // 2: category name | ||
218 | // 3: transaction type (stores the integer value of the index of the combobox) | ||
219 | // 4: check number of the transaction (if any) | ||
220 | // 5: transaction amount | ||
221 | // 6: transaction fee (e.g. service charge, or ATM charge). | ||
222 | // 7: date of the transaction | ||
223 | // 8: additional comments | ||
224 | config->writeEntry("Payment", result[0]); | ||
225 | config->writeEntry("Description", result[1]); | ||
226 | if (result[0] == QString("true")) | ||
227 | { | ||
228 | config->writeEntry("Category", result[2]); | ||
229 | } | ||
230 | config->writeEntry("Type", result[3]); | ||
231 | config->writeEntry("CheckNumber", result[4]); | ||
232 | config->writeEntry("Amount", result[5]); | ||
233 | config->writeEntry("TransactionFee", result[6]); | ||
234 | config->writeEntry("Date", result[7]); | ||
235 | config->writeEntry("Comments", result[8]); | ||
236 | if (result[0] == QString("true")) | ||
237 | { | ||
238 | if (rowText.toInt() <= lastCheck) | ||
239 | { | ||
240 | for(int i = (rowText.toInt() - 1); i != (lastCheck); i++) | ||
241 | { | ||
242 | config->setGroup(tblTransactions->text(i, 0)); | ||
243 | QString ibalance = config->readEntry("Balance", "0.00"); | ||
244 | |||
245 | // this adds the old amount on to the transaction and then takes the new amount away | ||
246 | QString newbalance = calculator(calculator(ibalance, originalamount, false), result[5], true); | ||
247 | config->writeEntry("Balance", newbalance); | ||
248 | if (i == (lastCheck - 1)) | ||
249 | { | ||
250 | config->setGroup("Totals"); | ||
251 | config->writeEntry("Balance", newbalance); | ||
252 | break; | ||
253 | } | ||
254 | } | ||
255 | } | ||
256 | config->setGroup("Totals"); | ||
257 | config->writeEntry("Spent", calculator(config->readEntry("Spent", QString("0")), originalamount, true)); | ||
258 | config->writeEntry("Spent", calculator(config->readEntry("Spent", QString("0")), result[5], false)); | ||
259 | |||
260 | if (result[2] == originalcategory) | ||
261 | { | ||
262 | QString categorytotal = config->readEntry(result[2], QString("0")); | ||
263 | categorytotal = calculator(categorytotal, originalamount, true); | ||
264 | categorytotal = calculator(categorytotal, result[5], false); | ||
265 | config->writeEntry(result[2], categorytotal); | ||
266 | } else { | ||
267 | QString origtotal = config->readEntry(originalcategory, QString("0")); | ||
268 | QString origfinal = calculator(origtotal, result[5], true); | ||
269 | if (origfinal == "0" || origfinal == "0.00") | ||
270 | { | ||
271 | config->removeEntry(originalcategory); | ||
272 | } else { | ||
273 | config->writeEntry(originalcategory, origfinal); | ||
274 | } | ||
275 | QString categorytotal = config->readEntry(result[2], QString("0")); | ||
276 | categorytotal = calculator(categorytotal, originalamount, false); | ||
277 | config->writeEntry(result[2],categorytotal); | ||
278 | } | ||
279 | } | ||
280 | if (result[0] == QString("false")) | ||
281 | { | ||
282 | if (rowText.toInt() <= lastCheck) | ||
283 | { | ||
284 | for(int i = (rowText.toInt() - 1 ); i != (lastCheck); i++) | ||
285 | { | ||
286 | config->setGroup(tblTransactions->text(i, 0)); | ||
287 | QString ibalance = config->readEntry("Balance", "0.00"); | ||
288 | |||
289 | // this subtracts the old amount on to the transaction and then adds the new amount on | ||
290 | QString newbalance = calculator(calculator(ibalance, originalamount, true), result[5], false); | ||
291 | config->writeEntry("Balance", newbalance); | ||
292 | if (i == lastCheck - 1) | ||
293 | { | ||
294 | config->setGroup("Totals"); | ||
295 | config->writeEntry("Balance", newbalance); | ||
296 | break; | ||
297 | } | ||
298 | } | ||
299 | } | ||
300 | config->setGroup("Totals"); | ||
301 | config->writeEntry("Deposited", calculator(config->readEntry("Deposited", QString("0")), originalamount, true)); | ||
302 | config->writeEntry("Deposited", calculator(config->readEntry("Deposited", QString("0")), result[5], false)); | ||
303 | } | ||
304 | labelBalance->setText(QString("$" + config->readEntry("Balance", QString("0.00")))); | ||
305 | config->write(); | ||
306 | } | ||
307 | } | ||
308 | void QCheckView::tableClicked(int row, int col, int mouseButton, const QPoint &mousePos) | ||
309 | { | ||
310 | if (tblTransactions->text(row, col).isEmpty() == false) | ||
311 | { | ||
312 | QStringList existing; | ||
313 | config->setGroup(tblTransactions->text(row, 0)); | ||
314 | existing << config->readEntry("Payment", "true") << config->readEntry("Description", "No Description Found") << config->readEntry("Category", "Misc.") << config->readEntry("Type", "0") << config->readEntry("CheckNumber", "0") << config->readEntry("Amount", "0.00") << config->readEntry("TransactionFee", "0.00") << config->readEntry("Date", "01/01/2001") << config->readEntry("Comments", "") << config->readEntry("Balance", "0.00"); | ||
315 | qcd = new QCheckDetails(row, col, existing); | ||
316 | qcd->showMaximized(); | ||
317 | connect(qcd, SIGNAL(editClicked(int, int)), this, SLOT(editClicked(int, int))); | ||
318 | connect(qcd, SIGNAL(deleteClicked(int, int)), this, SLOT(deleteClicked(int, int))); | ||
319 | } | ||
320 | } | ||
321 | |||
322 | void QCheckView::newClicked() | ||
323 | { | ||
324 | config->setGroup("Data"); | ||
325 | QString recent = config->readEntry("Recent", ""); | ||
326 | QStringList kindablank; | ||
327 | kindablank << recent; | ||
328 | QStringList result = QCheckEntry::popupEntry(kindablank); | ||
329 | if (result.count() > 1) | ||
330 | { | ||
331 | QTableItem *qti = new QTableItem(tblTransactions, QTableItem::Never, result[1]); | ||
332 | int row = tblTransactions->numRows(); | ||
333 | tblTransactions->setNumRows(row + 1); | ||
334 | tblTransactions->setItem(row,1, qti); | ||
335 | tblTransactions->updateCell(row, 1); | ||
336 | config->setGroup("Data"); | ||
337 | config->writeEntry("Recent", result[9]); | ||
338 | int lastCheck = config->readNumEntry("LastCheck", 0); | ||
339 | if (lastCheck == 0) | ||
340 | { | ||
341 | config->writeEntry("LastCheck", 1); | ||
342 | } else { | ||
343 | config->writeEntry("LastCheck", (lastCheck + 1)); | ||
344 | } | ||
345 | QString number = QString::number(lastCheck + 1); | ||
346 | config->setGroup(number); | ||
347 | |||
348 | QTableItem *qti1 = new QTableItem(tblTransactions, QTableItem::Never, number); | ||
349 | tblTransactions->setItem(row, 0, qti1); | ||
350 | tblTransactions->updateCell(row, 0); | ||
351 | |||
352 | QTableItem *qti2 = new QTableItem(tblTransactions, QTableItem::Never, result[7]); | ||
353 | tblTransactions->setItem(row, 2, qti2); | ||
354 | tblTransactions->updateCell(row, 2); | ||
355 | |||
356 | QTableItem *qti3 = new QTableItem(tblTransactions, QTableItem::Never, QString("$" + result[5])); | ||
357 | tblTransactions->setItem(row, 3, qti3); | ||
358 | tblTransactions->updateCell(row, 3); | ||
359 | |||
360 | // This is how the list looks: | ||
361 | // 0: true or false, true == payment, false == deposit | ||
362 | // 1: description of the transaction | ||
363 | // 2: category name | ||
364 | // 3: transaction type (stores the integer value of the index of the combobox) | ||
365 | // 4: check number of the transaction (if any) | ||
366 | // 5: transaction amount | ||
367 | // 6: transaction fee (e.g. service charge, or ATM charge). | ||
368 | // 7: date of the transaction | ||
369 | config->writeEntry("Payment", result[0]); | ||
370 | config->writeEntry("Description", result[1]); | ||
371 | if (result[0] == QString("true")) | ||
372 | { | ||
373 | config->writeEntry("Category", result[2]); | ||
374 | } | ||
375 | config->writeEntry("Type", result[3]); | ||
376 | config->writeEntry("CheckNumber", result[4]); | ||
377 | config->writeEntry("Amount", result[5]); | ||
378 | config->writeEntry("TransactionFee", result[6]); | ||
379 | config->writeEntry("Date", result[7]); | ||
380 | config->writeEntry("Comments", result[8]); | ||
381 | config->setGroup("Totals"); | ||
382 | if (result[0] == QString("true")) | ||
383 | { | ||
384 | QString totalspent = config->readEntry("Spent", QString("0")); | ||
385 | totalspent = calculator(totalspent, result[5], false); | ||
386 | config->writeEntry("Spent", totalspent); | ||
387 | QString balance = config->readEntry("Balance", QString("0")); | ||
388 | balance = calculator(balance, result[5], true); | ||
389 | |||
390 | // Make sure to add the fee on, if any | ||
391 | balance = calculator(balance, result[6], true); | ||
392 | |||
393 | config->writeEntry("Balance", balance); | ||
394 | |||
395 | config->setGroup(number); | ||
396 | config->writeEntry("Balance", balance); | ||
397 | |||
398 | config->setGroup("Totals"); | ||
399 | QString categorytotal = config->readEntry(result[2], QString("0")); | ||
400 | categorytotal = calculator(categorytotal, result[5], false); | ||
401 | config->writeEntry(result[2], categorytotal); | ||
402 | } | ||
403 | if (result[0] == QString("false")) | ||
404 | { | ||
405 | QString totaldeposited = config->readEntry("Deposited", QString("0")); | ||
406 | totaldeposited = calculator(totaldeposited, result[5], false); | ||
407 | config->writeEntry("Deposited", totaldeposited); | ||
408 | QString balance = config->readEntry("Balance", QString("0")); | ||
409 | balance = calculator(balance, result[5], false); | ||
410 | |||
411 | // Make sure to add the fee on, if any | ||
412 | balance = calculator(balance, result[6], true); | ||
413 | |||
414 | config->writeEntry("Balance", balance); | ||
415 | |||
416 | config->setGroup(number); | ||
417 | config->writeEntry("Balance", balance); | ||
418 | } | ||
419 | } | ||
420 | config->setGroup("Totals"); | ||
421 | labelBalance->setText(QString("$" + config->readEntry("Balance", QString("0.00")))); | ||
422 | config->write(); | ||
423 | } | ||
424 | |||
425 | QString QCheckView::calculator(QString largervalue, QString smallervalue, bool subtract) | ||
426 | { | ||
427 | // This class provides a way to eliminate the ARM processor problem of not being able to handle | ||
428 | // decimals. I just take the two QString'ed numbers and find the decimal point, then I remove the decimal | ||
429 | // point seperating the number into two. Then I convert it to cents (times it times 100) and add/ | ||
430 | // substract the two together. Put the decimals back in, and return. | ||
431 | |||
432 | largervalue = largervalue.remove(largervalue.find(".", 0, false), 1); | ||
433 | smallervalue = smallervalue.remove(smallervalue.find(".", 0, false), 1); | ||
434 | |||
435 | int largercents = largervalue.toInt(); | ||
436 | int smallercents = smallervalue.toInt(); | ||
437 | |||
438 | int finalammount = 0; | ||
439 | |||
440 | if (subtract == true) | ||
441 | { | ||
442 | finalammount = largercents - smallercents; | ||
443 | } else { | ||
444 | finalammount = largercents + smallercents; | ||
445 | } | ||
446 | |||
447 | QString returnvalue = QString::number(finalammount); | ||
448 | if (returnvalue.length() >= 2) | ||
449 | { | ||
450 | returnvalue.insert((returnvalue.length() - 2), "."); | ||
451 | } else { | ||
452 | if (returnvalue.length() == 1) | ||
453 | { | ||
454 | returnvalue.prepend("0.0"); | ||
455 | } | ||
456 | } | ||
457 | return returnvalue; | ||
458 | } | ||