Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/mymoney/storage/mymoneystoragemgr.cpp
Context not available. | |||||
113 | { | 113 | { | ||
---|---|---|---|---|---|
114 | Q_D(MyMoneyStorageMgr); | 114 | Q_D(MyMoneyStorageMgr); | ||
115 | if (!isStandardAccount(id)) | 115 | if (!isStandardAccount(id)) | ||
116 | throw MYMONEYEXCEPTION("Only standard accounts can be modified using setAccountName()"); | 116 | throw MYMONEYEXCEPTION_CSTRING("Only standard accounts can be modified using setAccountName()"); | ||
117 | 117 | | |||
118 | auto acc = d->m_accountList[id]; | 118 | auto acc = d->m_accountList[id]; | ||
119 | acc.setName(name); | 119 | acc.setName(name); | ||
Context not available. | |||||
135 | } | 135 | } | ||
136 | 136 | | |||
137 | // throw an exception, if it does not exist | 137 | // throw an exception, if it does not exist | ||
138 | const auto msg = QString::fromLatin1("Unknown account id '%1'").arg(id); | 138 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown account id '%1'").arg(id)); | ||
139 | throw MYMONEYEXCEPTION(msg); | | |||
140 | } | 139 | } | ||
141 | 140 | | |||
142 | MyMoneyAccount MyMoneyStorageMgr::accountByName(const QString& name) const | 141 | MyMoneyAccount MyMoneyStorageMgr::accountByName(const QString& name) const | ||
Context not available. | |||||
153 | } | 152 | } | ||
154 | } | 153 | } | ||
155 | 154 | | |||
156 | throw MYMONEYEXCEPTION("Unknown account '" + name + '\''); | 155 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown account '%1'").arg(name)); | ||
157 | } | 156 | } | ||
158 | 157 | | |||
159 | void MyMoneyStorageMgr::accountList(QList<MyMoneyAccount>& list) const | 158 | void MyMoneyStorageMgr::accountList(QList<MyMoneyAccount>& list) const | ||
Context not available. | |||||
200 | void MyMoneyStorageMgr::removeOnlineJob(const onlineJob& job) | 199 | void MyMoneyStorageMgr::removeOnlineJob(const onlineJob& job) | ||
201 | { | 200 | { | ||
202 | Q_D(MyMoneyStorageMgr); | 201 | Q_D(MyMoneyStorageMgr); | ||
203 | if (!d->m_onlineJobList.contains(job.id())) { | 202 | if (!d->m_onlineJobList.contains(job.id())) | ||
204 | throw MYMONEYEXCEPTION("Unknown onlineJob '" + job.id() + "' should be removed."); | 203 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown onlineJob '%1' should be removed.").arg(job.id())); | ||
205 | } | 204 | | ||
206 | d->m_onlineJobList.remove(job.id()); | 205 | d->m_onlineJobList.remove(job.id()); | ||
207 | } | 206 | } | ||
208 | 207 | | |||
Context not available. | |||||
210 | { | 209 | { | ||
211 | Q_D(MyMoneyStorageMgr); | 210 | Q_D(MyMoneyStorageMgr); | ||
212 | QMap<QString, onlineJob>::ConstIterator iter = d->m_onlineJobList.find(job.id()); | 211 | QMap<QString, onlineJob>::ConstIterator iter = d->m_onlineJobList.find(job.id()); | ||
213 | if (iter == d->m_onlineJobList.end()) { | 212 | if (iter == d->m_onlineJobList.end()) | ||
214 | throw MYMONEYEXCEPTION("Got unknown onlineJob '" + job.id() + "' for modifying"); | 213 | throw MYMONEYEXCEPTION(QString::fromLatin1("Got unknown onlineJob '%1' for modifying").arg(job.id())); | ||
215 | } | | |||
216 | onlineJob oldJob = iter.value(); | 214 | onlineJob oldJob = iter.value(); | ||
217 | d->m_onlineJobList.modify((*iter).id(), job); | 215 | d->m_onlineJobList.modify((*iter).id(), job); | ||
218 | } | 216 | } | ||
Context not available. | |||||
223 | if (d->m_onlineJobList.contains(id)) { | 221 | if (d->m_onlineJobList.contains(id)) { | ||
224 | return d->m_onlineJobList[id]; | 222 | return d->m_onlineJobList[id]; | ||
225 | } | 223 | } | ||
226 | throw MYMONEYEXCEPTION("Unknown online Job '" + id + '\''); | 224 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown online Job '%1'").arg(id)); | ||
227 | } | 225 | } | ||
228 | 226 | | |||
229 | ulong MyMoneyStorageMgr::onlineJobId() const | 227 | ulong MyMoneyStorageMgr::onlineJobId() const | ||
Context not available. | |||||
237 | QMap<QString, MyMoneyPayee>::ConstIterator it; | 235 | QMap<QString, MyMoneyPayee>::ConstIterator it; | ||
238 | it = d->m_payeeList.find(id); | 236 | it = d->m_payeeList.find(id); | ||
239 | if (it == d->m_payeeList.end()) | 237 | if (it == d->m_payeeList.end()) | ||
240 | throw MYMONEYEXCEPTION("Unknown payee '" + id + '\''); | 238 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown payee '%1'").arg(id)); | ||
241 | 239 | | |||
242 | return *it; | 240 | return *it; | ||
243 | } | 241 | } | ||
Context not available. | |||||
256 | } | 254 | } | ||
257 | } | 255 | } | ||
258 | 256 | | |||
259 | throw MYMONEYEXCEPTION("Unknown payee '" + payee + '\''); | 257 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown payee '%1'").arg(payee)); | ||
260 | } | 258 | } | ||
261 | 259 | | |||
262 | void MyMoneyStorageMgr::modifyPayee(const MyMoneyPayee& payee) | 260 | void MyMoneyStorageMgr::modifyPayee(const MyMoneyPayee& payee) | ||
Context not available. | |||||
265 | QMap<QString, MyMoneyPayee>::ConstIterator it; | 263 | QMap<QString, MyMoneyPayee>::ConstIterator it; | ||
266 | 264 | | |||
267 | it = d->m_payeeList.find(payee.id()); | 265 | it = d->m_payeeList.find(payee.id()); | ||
268 | if (it == d->m_payeeList.end()) { | 266 | if (it == d->m_payeeList.end()) | ||
269 | QString msg = "Unknown payee '" + payee.id() + '\''; | 267 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown payee '%1'").arg(payee.id())); | ||
270 | throw MYMONEYEXCEPTION(msg); | 268 | | ||
271 | } | | |||
272 | d->m_payeeList.modify((*it).id(), payee); | 269 | d->m_payeeList.modify((*it).id(), payee); | ||
273 | } | 270 | } | ||
274 | 271 | | |||
Context not available. | |||||
280 | QMap<QString, MyMoneyPayee>::ConstIterator it_p; | 277 | QMap<QString, MyMoneyPayee>::ConstIterator it_p; | ||
281 | 278 | | |||
282 | it_p = d->m_payeeList.find(payee.id()); | 279 | it_p = d->m_payeeList.find(payee.id()); | ||
283 | if (it_p == d->m_payeeList.end()) { | 280 | if (it_p == d->m_payeeList.end()) | ||
284 | QString msg = "Unknown payee '" + payee.id() + '\''; | 281 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown payee '%1'").arg(payee.id())); | ||
285 | throw MYMONEYEXCEPTION(msg); | | |||
286 | } | | |||
287 | 282 | | |||
288 | // scan all transactions to check if the payee is still referenced | 283 | // scan all transactions to check if the payee is still referenced | ||
289 | for (it_t = d->m_transactionList.begin(); it_t != d->m_transactionList.end(); ++it_t) { | 284 | for (it_t = d->m_transactionList.begin(); it_t != d->m_transactionList.end(); ++it_t) { | ||
290 | if ((*it_t).hasReferenceTo(payee.id())) { | 285 | if ((*it_t).hasReferenceTo(payee.id())) { | ||
291 | throw MYMONEYEXCEPTION(QString("Cannot remove payee that is still referenced to a %1").arg("transaction")); | 286 | throw MYMONEYEXCEPTION(QString::fromLatin1("Cannot remove payee that is still referenced to a %1").arg("transaction")); | ||
292 | } | 287 | } | ||
293 | } | 288 | } | ||
294 | 289 | | |||
295 | // check referential integrity in schedules | 290 | // check referential integrity in schedules | ||
296 | for (it_s = d->m_scheduleList.begin(); it_s != d->m_scheduleList.end(); ++it_s) { | 291 | for (it_s = d->m_scheduleList.begin(); it_s != d->m_scheduleList.end(); ++it_s) { | ||
297 | if ((*it_s).hasReferenceTo(payee.id())) { | 292 | if ((*it_s).hasReferenceTo(payee.id())) { | ||
298 | throw MYMONEYEXCEPTION(QString("Cannot remove payee that is still referenced to a %1").arg("schedule")); | 293 | throw MYMONEYEXCEPTION(QString::fromLatin1("Cannot remove payee that is still referenced to a %1").arg("schedule")); | ||
299 | } | 294 | } | ||
300 | } | 295 | } | ||
301 | 296 | | |||
Context not available. | |||||
326 | QMap<QString, MyMoneyTag>::ConstIterator it; | 321 | QMap<QString, MyMoneyTag>::ConstIterator it; | ||
327 | it = d->m_tagList.find(id); | 322 | it = d->m_tagList.find(id); | ||
328 | if (it == d->m_tagList.end()) | 323 | if (it == d->m_tagList.end()) | ||
329 | throw MYMONEYEXCEPTION("Unknown tag '" + id + '\''); | 324 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown tag '%1'").arg(id)); | ||
330 | 325 | | |||
331 | return *it; | 326 | return *it; | ||
332 | } | 327 | } | ||
Context not available. | |||||
345 | } | 340 | } | ||
346 | } | 341 | } | ||
347 | 342 | | |||
348 | throw MYMONEYEXCEPTION("Unknown tag '" + tag + '\''); | 343 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown tag '%1'").arg(tag)); | ||
349 | } | 344 | } | ||
350 | 345 | | |||
351 | void MyMoneyStorageMgr::modifyTag(const MyMoneyTag& tag) | 346 | void MyMoneyStorageMgr::modifyTag(const MyMoneyTag& tag) | ||
Context not available. | |||||
354 | QMap<QString, MyMoneyTag>::ConstIterator it; | 349 | QMap<QString, MyMoneyTag>::ConstIterator it; | ||
355 | 350 | | |||
356 | it = d->m_tagList.find(tag.id()); | 351 | it = d->m_tagList.find(tag.id()); | ||
357 | if (it == d->m_tagList.end()) { | 352 | if (it == d->m_tagList.end()) | ||
358 | QString msg = "Unknown tag '" + tag.id() + '\''; | 353 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown tag '%1'").arg(tag.id())); | ||
359 | throw MYMONEYEXCEPTION(msg); | 354 | | ||
360 | } | | |||
361 | d->m_tagList.modify((*it).id(), tag); | 355 | d->m_tagList.modify((*it).id(), tag); | ||
362 | } | 356 | } | ||
363 | 357 | | |||
Context not available. | |||||
369 | QMap<QString, MyMoneyTag>::ConstIterator it_ta; | 363 | QMap<QString, MyMoneyTag>::ConstIterator it_ta; | ||
370 | 364 | | |||
371 | it_ta = d->m_tagList.find(tag.id()); | 365 | it_ta = d->m_tagList.find(tag.id()); | ||
372 | if (it_ta == d->m_tagList.end()) { | 366 | if (it_ta == d->m_tagList.end()) | ||
373 | QString msg = "Unknown tag '" + tag.id() + '\''; | 367 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown tag '%1'").arg(tag.id())); | ||
374 | throw MYMONEYEXCEPTION(msg); | | |||
375 | } | | |||
376 | 368 | | |||
377 | // scan all transactions to check if the tag is still referenced | 369 | // scan all transactions to check if the tag is still referenced | ||
378 | for (it_t = d->m_transactionList.begin(); it_t != d->m_transactionList.end(); ++it_t) { | 370 | for (it_t = d->m_transactionList.begin(); it_t != d->m_transactionList.end(); ++it_t) { | ||
379 | if ((*it_t).hasReferenceTo(tag.id())) { | 371 | if ((*it_t).hasReferenceTo(tag.id())) { | ||
380 | throw MYMONEYEXCEPTION(QString("Cannot remove tag that is still referenced to a %1").arg("transaction")); | 372 | throw MYMONEYEXCEPTION(QString::fromLatin1("Cannot remove tag that is still referenced to a %1").arg("transaction")); | ||
381 | } | 373 | } | ||
382 | } | 374 | } | ||
383 | 375 | | |||
384 | // check referential integrity in schedules | 376 | // check referential integrity in schedules | ||
385 | for (it_s = d->m_scheduleList.begin(); it_s != d->m_scheduleList.end(); ++it_s) { | 377 | for (it_s = d->m_scheduleList.begin(); it_s != d->m_scheduleList.end(); ++it_s) { | ||
386 | if ((*it_s).hasReferenceTo(tag.id())) { | 378 | if ((*it_s).hasReferenceTo(tag.id())) { | ||
387 | throw MYMONEYEXCEPTION(QString("Cannot remove tag that is still referenced to a %1").arg("schedule")); | 379 | throw MYMONEYEXCEPTION(QString::fromLatin1("Cannot remove tag that is still referenced to a %1").arg("schedule")); | ||
388 | } | 380 | } | ||
389 | } | 381 | } | ||
390 | 382 | | |||
Context not available. | |||||
407 | QMap<QString, MyMoneyAccount>::ConstIterator theChild; | 399 | QMap<QString, MyMoneyAccount>::ConstIterator theChild; | ||
408 | 400 | | |||
409 | theParent = d->m_accountList.find(parent.id()); | 401 | theParent = d->m_accountList.find(parent.id()); | ||
410 | if (theParent == d->m_accountList.end()) { | 402 | if (theParent == d->m_accountList.end()) | ||
411 | QString msg = "Unknown parent account '"; | 403 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown parent account '%1'").arg(parent.id())); | ||
412 | msg += parent.id() + '\''; | | |||
413 | throw MYMONEYEXCEPTION(msg); | | |||
414 | } | | |||
415 | 404 | | |||
416 | theChild = d->m_accountList.find(account.id()); | 405 | theChild = d->m_accountList.find(account.id()); | ||
417 | if (theChild == d->m_accountList.end()) { | 406 | if (theChild == d->m_accountList.end()) | ||
418 | QString msg = "Unknown child account '"; | 407 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown child account '%1'").arg(account.id())); | ||
419 | msg += account.id() + '\''; | | |||
420 | throw MYMONEYEXCEPTION(msg); | | |||
421 | } | | |||
422 | 408 | | |||
423 | auto acc = *theParent; | 409 | auto acc = *theParent; | ||
424 | acc.addAccountId(account.id()); | 410 | acc.addAccountId(account.id()); | ||
Context not available. | |||||
515 | 501 | | |||
516 | // first perform all the checks | 502 | // first perform all the checks | ||
517 | if (!transaction.id().isEmpty()) | 503 | if (!transaction.id().isEmpty()) | ||
518 | throw MYMONEYEXCEPTION("transaction already contains an id"); | 504 | throw MYMONEYEXCEPTION_CSTRING("transaction already contains an id"); | ||
519 | if (!transaction.postDate().isValid()) | 505 | if (!transaction.postDate().isValid()) | ||
520 | throw MYMONEYEXCEPTION("invalid post date"); | 506 | throw MYMONEYEXCEPTION_CSTRING("invalid post date"); | ||
521 | 507 | | |||
522 | // now check the splits | 508 | // now check the splits | ||
523 | foreach (const auto split, transaction.splits()) { | 509 | foreach (const auto split, transaction.splits()) { | ||
Context not available. | |||||
568 | pos = d->m_institutionList.find(id); | 554 | pos = d->m_institutionList.find(id); | ||
569 | if (pos != d->m_institutionList.end()) | 555 | if (pos != d->m_institutionList.end()) | ||
570 | return *pos; | 556 | return *pos; | ||
571 | throw MYMONEYEXCEPTION("unknown institution"); | 557 | throw MYMONEYEXCEPTION_CSTRING("unknown institution"); | ||
572 | } | 558 | } | ||
573 | 559 | | |||
574 | bool MyMoneyStorageMgr::dirty() const | 560 | bool MyMoneyStorageMgr::dirty() const | ||
Context not available. | |||||
615 | d->m_accountList.modify(account.id(), account); | 601 | d->m_accountList.modify(account.id(), account); | ||
616 | 602 | | |||
617 | } else | 603 | } else | ||
618 | throw MYMONEYEXCEPTION("Invalid information for update"); | 604 | throw MYMONEYEXCEPTION_CSTRING("Invalid information for update"); | ||
619 | 605 | | |||
620 | } else | 606 | } else | ||
621 | throw MYMONEYEXCEPTION("Unknown account id"); | 607 | throw MYMONEYEXCEPTION_CSTRING("Unknown account id"); | ||
622 | } | 608 | } | ||
623 | 609 | | |||
624 | void MyMoneyStorageMgr::modifyInstitution(const MyMoneyInstitution& institution) | 610 | void MyMoneyStorageMgr::modifyInstitution(const MyMoneyInstitution& institution) | ||
Context not available. | |||||
632 | d->m_institutionList.modify(institution.id(), institution); | 618 | d->m_institutionList.modify(institution.id(), institution); | ||
633 | 619 | | |||
634 | } else | 620 | } else | ||
635 | throw MYMONEYEXCEPTION("unknown institution"); | 621 | throw MYMONEYEXCEPTION_CSTRING("unknown institution"); | ||
636 | } | 622 | } | ||
637 | 623 | | |||
638 | void MyMoneyStorageMgr::modifyTransaction(const MyMoneyTransaction& transaction) | 624 | void MyMoneyStorageMgr::modifyTransaction(const MyMoneyTransaction& transaction) | ||
Context not available. | |||||
649 | if (transaction.id().isEmpty() | 635 | if (transaction.id().isEmpty() | ||
650 | // || transaction.file() != this | 636 | // || transaction.file() != this | ||
651 | || !transaction.postDate().isValid()) | 637 | || !transaction.postDate().isValid()) | ||
652 | throw MYMONEYEXCEPTION("invalid transaction to be modified"); | 638 | throw MYMONEYEXCEPTION_CSTRING("invalid transaction to be modified"); | ||
653 | 639 | | |||
654 | // now check the splits | 640 | // now check the splits | ||
655 | foreach (const auto split, transaction.splits()) { | 641 | foreach (const auto split, transaction.splits()) { | ||
Context not available. | |||||
667 | // new data seems to be ok. find old version of transaction | 653 | // new data seems to be ok. find old version of transaction | ||
668 | // in our pool. Throw exception if unknown. | 654 | // in our pool. Throw exception if unknown. | ||
669 | if (!d->m_transactionKeys.contains(transaction.id())) | 655 | if (!d->m_transactionKeys.contains(transaction.id())) | ||
670 | throw MYMONEYEXCEPTION("invalid transaction id"); | 656 | throw MYMONEYEXCEPTION_CSTRING("invalid transaction id"); | ||
671 | 657 | | |||
672 | QString oldKey = d->m_transactionKeys[transaction.id()]; | 658 | QString oldKey = d->m_transactionKeys[transaction.id()]; | ||
673 | if (!d->m_transactionList.contains(oldKey)) | 659 | if (!d->m_transactionList.contains(oldKey)) | ||
674 | throw MYMONEYEXCEPTION("invalid transaction key"); | 660 | throw MYMONEYEXCEPTION_CSTRING("invalid transaction key"); | ||
675 | 661 | | |||
676 | QMap<QString, MyMoneyTransaction>::ConstIterator it_t; | 662 | QMap<QString, MyMoneyTransaction>::ConstIterator it_t; | ||
677 | 663 | | |||
678 | it_t = d->m_transactionList.find(oldKey); | 664 | it_t = d->m_transactionList.find(oldKey); | ||
679 | if (it_t == d->m_transactionList.end()) | 665 | if (it_t == d->m_transactionList.end()) | ||
680 | throw MYMONEYEXCEPTION("invalid transaction key"); | 666 | throw MYMONEYEXCEPTION_CSTRING("invalid transaction key"); | ||
681 | 667 | | |||
682 | foreach (const auto split, (*it_t).splits()) { | 668 | foreach (const auto split, (*it_t).splits()) { | ||
683 | auto acc = d->m_accountList[split.accountId()]; | 669 | auto acc = d->m_accountList[split.accountId()]; | ||
Context not available. | |||||
723 | Q_D(MyMoneyStorageMgr); | 709 | Q_D(MyMoneyStorageMgr); | ||
724 | // first perform all the checks | 710 | // first perform all the checks | ||
725 | if (transaction.id().isEmpty()) | 711 | if (transaction.id().isEmpty()) | ||
726 | throw MYMONEYEXCEPTION("invalid transaction to be deleted"); | 712 | throw MYMONEYEXCEPTION_CSTRING("invalid transaction to be deleted"); | ||
727 | 713 | | |||
728 | QMap<QString, QString>::ConstIterator it_k; | 714 | QMap<QString, QString>::ConstIterator it_k; | ||
729 | QMap<QString, MyMoneyTransaction>::ConstIterator it_t; | 715 | QMap<QString, MyMoneyTransaction>::ConstIterator it_t; | ||
730 | 716 | | |||
731 | it_k = d->m_transactionKeys.find(transaction.id()); | 717 | it_k = d->m_transactionKeys.find(transaction.id()); | ||
732 | if (it_k == d->m_transactionKeys.end()) | 718 | if (it_k == d->m_transactionKeys.end()) | ||
733 | throw MYMONEYEXCEPTION("invalid transaction to be deleted"); | 719 | throw MYMONEYEXCEPTION_CSTRING("invalid transaction to be deleted"); | ||
734 | 720 | | |||
735 | it_t = d->m_transactionList.find(*it_k); | 721 | it_t = d->m_transactionList.find(*it_k); | ||
736 | if (it_t == d->m_transactionList.end()) | 722 | if (it_t == d->m_transactionList.end()) | ||
737 | throw MYMONEYEXCEPTION("invalid transaction key"); | 723 | throw MYMONEYEXCEPTION_CSTRING("invalid transaction key"); | ||
738 | 724 | | |||
739 | // keep a copy so that we still have the data after removal | 725 | // keep a copy so that we still have the data after removal | ||
740 | MyMoneyTransaction t(*it_t); | 726 | MyMoneyTransaction t(*it_t); | ||
Context not available. | |||||
768 | 754 | | |||
769 | // check that it's not one of the standard account groups | 755 | // check that it's not one of the standard account groups | ||
770 | if (isStandardAccount(account.id())) | 756 | if (isStandardAccount(account.id())) | ||
771 | throw MYMONEYEXCEPTION("Unable to remove the standard account groups"); | 757 | throw MYMONEYEXCEPTION_CSTRING("Unable to remove the standard account groups"); | ||
772 | 758 | | |||
773 | if (hasActiveSplits(account.id())) { | 759 | if (hasActiveSplits(account.id())) { | ||
774 | throw MYMONEYEXCEPTION("Unable to remove account with active splits"); | 760 | throw MYMONEYEXCEPTION_CSTRING("Unable to remove account with active splits"); | ||
775 | } | 761 | } | ||
776 | 762 | | |||
777 | // re-parent all sub-ordinate accounts to the parent of the account | 763 | // re-parent all sub-ordinate accounts to the parent of the account | ||
Context not available. | |||||
791 | 777 | | |||
792 | it_a = d->m_accountList.find(account.id()); | 778 | it_a = d->m_accountList.find(account.id()); | ||
793 | if (it_a == d->m_accountList.end()) | 779 | if (it_a == d->m_accountList.end()) | ||
794 | throw MYMONEYEXCEPTION("Internal error: account not found in list"); | 780 | throw MYMONEYEXCEPTION_CSTRING("Internal error: account not found in list"); | ||
795 | 781 | | |||
796 | it_p = d->m_accountList.find(parent.id()); | 782 | it_p = d->m_accountList.find(parent.id()); | ||
797 | if (it_p == d->m_accountList.end()) | 783 | if (it_p == d->m_accountList.end()) | ||
798 | throw MYMONEYEXCEPTION("Internal error: parent account not found in list"); | 784 | throw MYMONEYEXCEPTION_CSTRING("Internal error: parent account not found in list"); | ||
799 | 785 | | |||
800 | if (!account.institutionId().isEmpty()) | 786 | if (!account.institutionId().isEmpty()) | ||
801 | throw MYMONEYEXCEPTION("Cannot remove account still attached to an institution"); | 787 | throw MYMONEYEXCEPTION_CSTRING("Cannot remove account still attached to an institution"); | ||
802 | 788 | | |||
803 | d->removeReferences(account.id()); | 789 | d->removeReferences(account.id()); | ||
804 | 790 | | |||
Context not available. | |||||
838 | d->m_institutionList.remove(institution.id()); | 824 | d->m_institutionList.remove(institution.id()); | ||
839 | 825 | | |||
840 | } else | 826 | } else | ||
841 | throw MYMONEYEXCEPTION("invalid institution"); | 827 | throw MYMONEYEXCEPTION_CSTRING("invalid institution"); | ||
842 | } | 828 | } | ||
843 | 829 | | |||
844 | void MyMoneyStorageMgr::transactionList(QList<MyMoneyTransaction>& list, MyMoneyTransactionFilter& filter) const | 830 | void MyMoneyStorageMgr::transactionList(QList<MyMoneyTransaction>& list, MyMoneyTransactionFilter& filter) const | ||
Context not available. | |||||
892 | MyMoneyCostCenter MyMoneyStorageMgr::costCenter(const QString& id) const | 878 | MyMoneyCostCenter MyMoneyStorageMgr::costCenter(const QString& id) const | ||
893 | { | 879 | { | ||
894 | Q_D(const MyMoneyStorageMgr); | 880 | Q_D(const MyMoneyStorageMgr); | ||
895 | if (!d->m_costCenterList.contains(id)) { | 881 | if (!d->m_costCenterList.contains(id)) | ||
896 | QString msg = QString("Invalid cost center id '%1'").arg(id); | 882 | throw MYMONEYEXCEPTION(QString::fromLatin1("Invalid cost center id '%1'").arg(id)); | ||
897 | throw MYMONEYEXCEPTION(msg); | | |||
898 | } | | |||
899 | return d->m_costCenterList[id]; | 883 | return d->m_costCenterList[id]; | ||
900 | } | 884 | } | ||
901 | 885 | | |||
Context not available. | |||||
911 | // get the full key of this transaction, throw exception | 895 | // get the full key of this transaction, throw exception | ||
912 | // if it's invalid (unknown) | 896 | // if it's invalid (unknown) | ||
913 | if (!d->m_transactionKeys.contains(id)) { | 897 | if (!d->m_transactionKeys.contains(id)) { | ||
914 | QString msg = QString("Invalid transaction id '%1'").arg(id); | 898 | throw MYMONEYEXCEPTION(QString::fromLatin1("Invalid transaction id '%1'").arg(id)); | ||
915 | throw MYMONEYEXCEPTION(msg); | | |||
916 | } | 899 | } | ||
917 | 900 | | |||
918 | // check if this key is in the list, throw exception if not | 901 | // check if this key is in the list, throw exception if not | ||
919 | QString key = d->m_transactionKeys[id]; | 902 | QString key = d->m_transactionKeys[id]; | ||
920 | if (!d->m_transactionList.contains(key)) { | 903 | if (!d->m_transactionList.contains(key)) | ||
921 | QString msg = QString("Invalid transaction key '%1'").arg(key); | 904 | throw MYMONEYEXCEPTION(QString::fromLatin1("Invalid transaction key '%1'").arg(key)); | ||
922 | throw MYMONEYEXCEPTION(msg); | | |||
923 | } | | |||
924 | 905 | | |||
925 | return d->m_transactionList[key]; | 906 | return d->m_transactionList[key]; | ||
926 | } | 907 | } | ||
Context not available. | |||||
934 | // find account object in list, throw exception if unknown | 915 | // find account object in list, throw exception if unknown | ||
935 | acc = m_accountList.find(account); | 916 | acc = m_accountList.find(account); | ||
936 | if(acc == m_accountList.end()) | 917 | if(acc == m_accountList.end()) | ||
937 | throw MYMONEYEXCEPTION("unknown account id"); | 918 | throw MYMONEYEXCEPTION_CSTRING("unknown account id"); | ||
938 | 919 | | |||
939 | // get the transaction info from the account | 920 | // get the transaction info from the account | ||
940 | MyMoneyAccount::Transaction t = (*acc).transaction(idx); | 921 | MyMoneyAccount::Transaction t = (*acc).transaction(idx); | ||
Context not available. | |||||
955 | 936 | | |||
956 | const auto list = transactionList(filter); | 937 | const auto list = transactionList(filter); | ||
957 | if (idx < 0 || idx >= static_cast<int>(list.count())) | 938 | if (idx < 0 || idx >= static_cast<int>(list.count())) | ||
958 | throw MYMONEYEXCEPTION("Unknown idx for transaction"); | 939 | throw MYMONEYEXCEPTION_CSTRING("Unknown idx for transaction"); | ||
959 | 940 | | |||
960 | return transaction(list[idx].id()); | 941 | return transaction(list[idx].id()); | ||
961 | } | 942 | } | ||
Context not available. | |||||
964 | { | 945 | { | ||
965 | Q_D(const MyMoneyStorageMgr); | 946 | Q_D(const MyMoneyStorageMgr); | ||
966 | if (!d->m_accountList.contains(id)) | 947 | if (!d->m_accountList.contains(id)) | ||
967 | throw MYMONEYEXCEPTION(QString("Unknown account id '%1'").arg(id)); | 948 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown account id '%1'").arg(id)); | ||
968 | 949 | | |||
969 | // the balance of all transactions for this account has | 950 | // the balance of all transactions for this account has | ||
970 | // been requested. no need to calculate anything as we | 951 | // been requested. no need to calculate anything as we | ||
Context not available. | |||||
1206 | Q_D(MyMoneyStorageMgr); | 1187 | Q_D(MyMoneyStorageMgr); | ||
1207 | // first perform all the checks | 1188 | // first perform all the checks | ||
1208 | if (!sched.id().isEmpty()) | 1189 | if (!sched.id().isEmpty()) | ||
1209 | throw MYMONEYEXCEPTION("schedule already contains an id"); | 1190 | throw MYMONEYEXCEPTION_CSTRING("schedule already contains an id"); | ||
1210 | 1191 | | |||
1211 | // The following will throw an exception when it fails | 1192 | // The following will throw an exception when it fails | ||
1212 | sched.validate(false); | 1193 | sched.validate(false); | ||
Context not available. | |||||
1215 | const auto splits = sched.transaction().splits(); | 1196 | const auto splits = sched.transaction().splits(); | ||
1216 | for (const auto& split : splits) | 1197 | for (const auto& split : splits) | ||
1217 | if (!d->m_accountList.contains(split.accountId())) | 1198 | if (!d->m_accountList.contains(split.accountId())) | ||
1218 | throw MYMONEYEXCEPTION("bad account id"); | 1199 | throw MYMONEYEXCEPTION_CSTRING("bad account id"); | ||
1219 | 1200 | | |||
1220 | MyMoneySchedule newSched(d->nextScheduleID(), sched); | 1201 | MyMoneySchedule newSched(d->nextScheduleID(), sched); | ||
1221 | d->m_scheduleList.insert(newSched.id(), newSched); | 1202 | d->m_scheduleList.insert(newSched.id(), newSched); | ||
Context not available. | |||||
1228 | QMap<QString, MyMoneySchedule>::ConstIterator it; | 1209 | QMap<QString, MyMoneySchedule>::ConstIterator it; | ||
1229 | 1210 | | |||
1230 | it = d->m_scheduleList.find(sched.id()); | 1211 | it = d->m_scheduleList.find(sched.id()); | ||
1231 | if (it == d->m_scheduleList.end()) { | 1212 | if (it == d->m_scheduleList.end()) | ||
1232 | QString msg = "Unknown schedule '" + sched.id() + '\''; | 1213 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown schedule '%1'").arg(sched.id())); | ||
1233 | throw MYMONEYEXCEPTION(msg); | | |||
1234 | } | | |||
1235 | 1214 | | |||
1236 | d->m_scheduleList.modify(sched.id(), sched); | 1215 | d->m_scheduleList.modify(sched.id(), sched); | ||
1237 | } | 1216 | } | ||
Context not available. | |||||
1242 | QMap<QString, MyMoneySchedule>::ConstIterator it; | 1221 | QMap<QString, MyMoneySchedule>::ConstIterator it; | ||
1243 | 1222 | | |||
1244 | it = d->m_scheduleList.find(sched.id()); | 1223 | it = d->m_scheduleList.find(sched.id()); | ||
1245 | if (it == d->m_scheduleList.end()) { | 1224 | if (it == d->m_scheduleList.end()) | ||
1246 | QString msg = "Unknown schedule '" + sched.id() + '\''; | 1225 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown schedule '%1'").arg(sched.id())); | ||
1247 | throw MYMONEYEXCEPTION(msg); | | |||
1248 | } | | |||
1249 | 1226 | | |||
1250 | // FIXME: check referential integrity for loan accounts | 1227 | // FIXME: check referential integrity for loan accounts | ||
1251 | d->m_scheduleList.remove(sched.id()); | 1228 | d->m_scheduleList.remove(sched.id()); | ||
Context not available. | |||||
1262 | return (*pos); | 1239 | return (*pos); | ||
1263 | 1240 | | |||
1264 | // throw an exception, if it does not exist | 1241 | // throw an exception, if it does not exist | ||
1265 | QString msg = "Unknown schedule id '" + id + '\''; | 1242 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown schedule '%1'").arg(id)); | ||
1266 | throw MYMONEYEXCEPTION(msg); | | |||
1267 | } | 1243 | } | ||
1268 | 1244 | | |||
1269 | QList<MyMoneySchedule> MyMoneyStorageMgr::scheduleList(const QString& accountId, | 1245 | QList<MyMoneySchedule> MyMoneyStorageMgr::scheduleList(const QString& accountId, | ||
Context not available. | |||||
1426 | QMap<QString, MyMoneySecurity>::ConstIterator it; | 1402 | QMap<QString, MyMoneySecurity>::ConstIterator it; | ||
1427 | 1403 | | |||
1428 | it = d->m_securitiesList.find(security.id()); | 1404 | it = d->m_securitiesList.find(security.id()); | ||
1429 | if (it == d->m_securitiesList.end()) { | 1405 | if (it == d->m_securitiesList.end()) | ||
1430 | QString msg = "Unknown security '"; | 1406 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown security '%1'").arg(security.id())); | ||
1431 | msg += security.id() + "' during modifySecurity()"; | | |||
1432 | throw MYMONEYEXCEPTION(msg); | | |||
1433 | } | | |||
1434 | 1407 | | |||
1435 | d->m_securitiesList.modify(security.id(), security); | 1408 | d->m_securitiesList.modify(security.id(), security); | ||
1436 | } | 1409 | } | ||
Context not available. | |||||
1443 | // FIXME: check referential integrity | 1416 | // FIXME: check referential integrity | ||
1444 | 1417 | | |||
1445 | it = d->m_securitiesList.find(security.id()); | 1418 | it = d->m_securitiesList.find(security.id()); | ||
1446 | if (it == d->m_securitiesList.end()) { | 1419 | if (it == d->m_securitiesList.end()) | ||
1447 | QString msg = "Unknown security '"; | 1420 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown security '%1'").arg(security.id())); | ||
1448 | msg += security.id() + "' during removeSecurity()"; | | |||
1449 | throw MYMONEYEXCEPTION(msg); | | |||
1450 | } | | |||
1451 | 1421 | | |||
1452 | d->m_securitiesList.remove(security.id()); | 1422 | d->m_securitiesList.remove(security.id()); | ||
1453 | } | 1423 | } | ||
Context not available. | |||||
1482 | QMap<QString, MyMoneySecurity>::ConstIterator it; | 1452 | QMap<QString, MyMoneySecurity>::ConstIterator it; | ||
1483 | 1453 | | |||
1484 | it = d->m_currencyList.find(currency.id()); | 1454 | it = d->m_currencyList.find(currency.id()); | ||
1485 | if (it != d->m_currencyList.end()) { | 1455 | if (it != d->m_currencyList.end()) | ||
1486 | throw MYMONEYEXCEPTION(i18n("Cannot add currency with existing id %1", currency.id())); | 1456 | throw MYMONEYEXCEPTION(QString::fromLatin1("Cannot add currency with existing id %1").arg(currency.id())); | ||
1487 | } | | |||
1488 | 1457 | | |||
1489 | d->m_currencyList.insert(currency.id(), currency); | 1458 | d->m_currencyList.insert(currency.id(), currency); | ||
1490 | } | 1459 | } | ||
Context not available. | |||||
1495 | QMap<QString, MyMoneySecurity>::ConstIterator it; | 1464 | QMap<QString, MyMoneySecurity>::ConstIterator it; | ||
1496 | 1465 | | |||
1497 | it = d->m_currencyList.find(currency.id()); | 1466 | it = d->m_currencyList.find(currency.id()); | ||
1498 | if (it == d->m_currencyList.end()) { | 1467 | if (it == d->m_currencyList.end()) | ||
1499 | throw MYMONEYEXCEPTION(i18n("Cannot modify currency with unknown id %1", currency.id())); | 1468 | throw MYMONEYEXCEPTION(QString::fromLatin1("Cannot modify currency with unknown id %1").arg(currency.id())); | ||
1500 | } | | |||
1501 | 1469 | | |||
1502 | d->m_currencyList.modify(currency.id(), currency); | 1470 | d->m_currencyList.modify(currency.id(), currency); | ||
1503 | } | 1471 | } | ||
Context not available. | |||||
1510 | // FIXME: check referential integrity | 1478 | // FIXME: check referential integrity | ||
1511 | 1479 | | |||
1512 | it = d->m_currencyList.find(currency.id()); | 1480 | it = d->m_currencyList.find(currency.id()); | ||
1513 | if (it == d->m_currencyList.end()) { | 1481 | if (it == d->m_currencyList.end()) | ||
1514 | throw MYMONEYEXCEPTION(i18n("Cannot remove currency with unknown id %1", currency.id())); | 1482 | throw MYMONEYEXCEPTION(QString::fromLatin1("Cannot remove currency with unknown id %1").arg(currency.id())); | ||
1515 | } | | |||
1516 | 1483 | | |||
1517 | d->m_currencyList.remove(currency.id()); | 1484 | d->m_currencyList.remove(currency.id()); | ||
1518 | } | 1485 | } | ||
Context not available. | |||||
1526 | QMap<QString, MyMoneySecurity>::ConstIterator it; | 1493 | QMap<QString, MyMoneySecurity>::ConstIterator it; | ||
1527 | 1494 | | |||
1528 | it = d->m_currencyList.find(id); | 1495 | it = d->m_currencyList.find(id); | ||
1529 | if (it == d->m_currencyList.end()) { | 1496 | if (it == d->m_currencyList.end()) | ||
1530 | throw MYMONEYEXCEPTION(i18n("Cannot retrieve currency with unknown id '%1'", id)); | 1497 | throw MYMONEYEXCEPTION(QString::fromLatin1("Cannot retrieve currency with unknown id '%1'").arg(id)); | ||
1531 | } | | |||
1532 | 1498 | | |||
1533 | return *it; | 1499 | return *it; | ||
1534 | } | 1500 | } | ||
Context not available. | |||||
1549 | { | 1515 | { | ||
1550 | Q_D(MyMoneyStorageMgr); | 1516 | Q_D(MyMoneyStorageMgr); | ||
1551 | if (!report.id().isEmpty()) | 1517 | if (!report.id().isEmpty()) | ||
1552 | throw MYMONEYEXCEPTION("report already contains an id"); | 1518 | throw MYMONEYEXCEPTION(QString::fromLatin1("report already contains an id")); | ||
1553 | 1519 | | |||
1554 | MyMoneyReport newReport(d->nextReportID(), report); | 1520 | MyMoneyReport newReport(d->nextReportID(), report); | ||
1555 | d->m_reportList.insert(newReport.id(), newReport); | 1521 | d->m_reportList.insert(newReport.id(), newReport); | ||
Context not available. | |||||
1581 | QMap<QString, MyMoneyReport>::ConstIterator it; | 1547 | QMap<QString, MyMoneyReport>::ConstIterator it; | ||
1582 | 1548 | | |||
1583 | it = d->m_reportList.find(report.id()); | 1549 | it = d->m_reportList.find(report.id()); | ||
1584 | if (it == d->m_reportList.end()) { | 1550 | if (it == d->m_reportList.end()) | ||
1585 | QString msg = "Unknown report '" + report.id() + '\''; | 1551 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown report '%1'").arg(report.id())); | ||
1586 | throw MYMONEYEXCEPTION(msg); | 1552 | | ||
1587 | } | | |||
1588 | d->m_reportList.modify(report.id(), report); | 1553 | d->m_reportList.modify(report.id(), report); | ||
1589 | } | 1554 | } | ||
1590 | 1555 | | |||
Context not available. | |||||
1606 | QMap<QString, MyMoneyReport>::ConstIterator it; | 1571 | QMap<QString, MyMoneyReport>::ConstIterator it; | ||
1607 | 1572 | | |||
1608 | it = d->m_reportList.find(report.id()); | 1573 | it = d->m_reportList.find(report.id()); | ||
1609 | if (it == d->m_reportList.end()) { | 1574 | if (it == d->m_reportList.end()) | ||
1610 | QString msg = "Unknown report '" + report.id() + '\''; | 1575 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown report '%1'").arg(report.id())); | ||
1611 | throw MYMONEYEXCEPTION(msg); | | |||
1612 | } | | |||
1613 | 1576 | | |||
1614 | d->m_reportList.remove(report.id()); | 1577 | d->m_reportList.remove(report.id()); | ||
1615 | } | 1578 | } | ||
Context not available. | |||||
1659 | } | 1622 | } | ||
1660 | } | 1623 | } | ||
1661 | 1624 | | |||
1662 | throw MYMONEYEXCEPTION("Unknown budget '" + budget + '\''); | 1625 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown budget '%1'").arg(budget)); | ||
1663 | } | 1626 | } | ||
1664 | 1627 | | |||
1665 | void MyMoneyStorageMgr::modifyBudget(const MyMoneyBudget& budget) | 1628 | void MyMoneyStorageMgr::modifyBudget(const MyMoneyBudget& budget) | ||
Context not available. | |||||
1668 | QMap<QString, MyMoneyBudget>::ConstIterator it; | 1631 | QMap<QString, MyMoneyBudget>::ConstIterator it; | ||
1669 | 1632 | | |||
1670 | it = d->m_budgetList.find(budget.id()); | 1633 | it = d->m_budgetList.find(budget.id()); | ||
1671 | if (it == d->m_budgetList.end()) { | 1634 | if (it == d->m_budgetList.end()) | ||
1672 | QString msg = "Unknown budget '" + budget.id() + '\''; | 1635 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown budget '%1'").arg(budget.id())); | ||
1673 | throw MYMONEYEXCEPTION(msg); | 1636 | | ||
1674 | } | | |||
1675 | d->m_budgetList.modify(budget.id(), budget); | 1637 | d->m_budgetList.modify(budget.id(), budget); | ||
1676 | } | 1638 | } | ||
1677 | 1639 | | |||
Context not available. | |||||
1693 | QMap<QString, MyMoneyBudget>::ConstIterator it; | 1655 | QMap<QString, MyMoneyBudget>::ConstIterator it; | ||
1694 | 1656 | | |||
1695 | it = d->m_budgetList.find(budget.id()); | 1657 | it = d->m_budgetList.find(budget.id()); | ||
1696 | if (it == d->m_budgetList.end()) { | 1658 | if (it == d->m_budgetList.end()) | ||
1697 | QString msg = "Unknown budget '" + budget.id() + '\''; | 1659 | throw MYMONEYEXCEPTION(QString::fromLatin1("Unknown budget '%1'").arg(budget.id())); | ||
1698 | throw MYMONEYEXCEPTION(msg); | | |||
1699 | } | | |||
1700 | 1660 | | |||
1701 | d->m_budgetList.remove(budget.id()); | 1661 | d->m_budgetList.remove(budget.id()); | ||
1702 | } | 1662 | } | ||
Context not available. |