374
380
return QListViewItem::compare(i, col, ascending);
383
RefundDialog::RefundDialog(Transaction *trans, QWidget *parent) : KDialogBase(parent, 0, true, i18n("Refund"), Ok | Cancel, Ok, true), transaction(trans) {
385
if(trans->type() == TRANSACTION_TYPE_INCOME) setCaption(i18n("Repayment"));
387
setMainWidget(new QWidget(this));
388
QGridLayout *layout = new QGridLayout(mainWidget(), 5, 2, 0, spacingHint());
390
layout->addWidget(new QLabel(i18n("Date:"), mainWidget()), 0, 0);
391
dateEdit = new KDateEdit(mainWidget());
392
layout->addWidget(dateEdit, 0, 1);
393
dateEdit->setFocus();
395
if(trans->type() == TRANSACTION_TYPE_INCOME) layout->addWidget(new QLabel(i18n("Cost:"), mainWidget()), 1, 0);
396
else layout->addWidget(new QLabel(i18n("Income:"), mainWidget()), 1, 0);
397
valueEdit = new KDoubleSpinBox(0.0, INT_MAX / pow(10, KGlobal::locale()->fracDigits()) - 1.0, 1.0, trans->value(), KGlobal::locale()->fracDigits(), mainWidget());
398
if(KGlobal::locale()->positivePrefixCurrencySymbol() && KGlobal::locale()->negativePrefixCurrencySymbol()) {
399
valueEdit->setPrefix(KGlobal::locale()->currencySymbol() + " ");
401
valueEdit->setSuffix(QString(" ") + KGlobal::locale()->currencySymbol());
403
layout->addWidget(valueEdit, 1, 1);
405
layout->addWidget(new QLabel(i18n("Account:"), mainWidget()), 2, 0);
406
accountCombo = new KComboBox(mainWidget());
407
accountCombo->setEditable(false);
409
AssetsAccount *account = transaction->budget()->assetsAccounts.first();
411
if(account != transaction->budget()->balancingAccount && account->accountType() != ASSETS_TYPE_SECURITIES) {
412
accountCombo->insertItem(account->name());
413
if((transaction->type() == TRANSACTION_TYPE_EXPENSE && account == ((Expense*) transaction)->from()) || (transaction->type() == TRANSACTION_TYPE_INCOME && account == ((Income*) transaction)->to())) accountCombo->setCurrentItem(i);
416
account = transaction->budget()->assetsAccounts.next();
418
layout->addWidget(accountCombo, 2, 1);
420
layout->addWidget(new QLabel(i18n("Quantity:"), mainWidget()), 3, 0);
421
quantityEdit = new KDoubleSpinBox(0.0, INT_MAX / 100 - 1.0, 1.0, trans->quantity(), 2, mainWidget());
422
layout->addWidget(quantityEdit, 3, 1);
424
layout->addWidget(new QLabel(i18n("Comments:"), mainWidget()), 4, 0);
425
commentsEdit = new KLineEdit(mainWidget());
426
if(trans->type() == TRANSACTION_TYPE_INCOME) commentsEdit->setText(i18n("Repayment"));
427
else commentsEdit->setText(i18n("Refund"));
428
layout->addWidget(commentsEdit, 4, 1);
431
Transaction *RefundDialog::createRefund() {
432
if(!validValues()) return NULL;
433
Transaction *trans = NULL;
435
int cur_i = accountCombo->currentItem();
436
AssetsAccount *account = transaction->budget()->assetsAccounts.first();
438
if(account != transaction->budget()->balancingAccount && account->accountType() != ASSETS_TYPE_SECURITIES) {
439
if(i == cur_i) break;
442
account = transaction->budget()->assetsAccounts.next();
444
trans = transaction->copy();
445
if(transaction->type() == TRANSACTION_TYPE_EXPENSE) {
446
((Expense*) trans)->setFrom(account);
448
((Income*) trans)->setTo(account);
450
trans->setQuantity(-quantityEdit->value());
451
trans->setValue(-valueEdit->value());
452
trans->setDate(dateEdit->date());
453
trans->setComment(commentsEdit->text());
456
void RefundDialog::slotOk() {
458
KDialogBase::slotOk();
461
bool RefundDialog::validValues() {
462
if(!dateEdit->date().isValid()) {
463
KMessageBox::error(this, i18n("Invalid date."));
377
470
EditReinvestedDividendDialog::EditReinvestedDividendDialog(Security *sec, QWidget *parent) : KDialogBase(parent, 0, true, i18n("Reinvested Dividend"), Ok | Cancel, Ok, true), security(sec) {
379
472
setMainWidget(new QWidget(this));
678
771
ConfirmScheduleDialog::ConfirmScheduleDialog(bool extra_parameters, Budget *budg, QWidget *parent, QString title) : KDialogBase(parent, 0, true, title, Ok, Ok, true), budget(budg), b_extra(extra_parameters) {
679
772
setMainWidget(new QWidget(this));
680
773
QVBoxLayout *box1 = new QVBoxLayout(mainWidget(), 0, spacingHint());
681
box1->addWidget(new QLabel(i18n("The following transactions was scheduled to occur today or before today.\nConfirm that they have indeed occurred (or will occur today)."), mainWidget()));
774
QLabel *label = new QLabel(i18n("The following transactions was scheduled to occur today or before today.\nConfirm that they have indeed occurred (or will occur today)."), mainWidget());
775
box1->addWidget(label);
682
776
QHBoxLayout *box2 = new QHBoxLayout(box1);
683
777
transactionsView = new KListView(mainWidget());
684
778
transactionsView->addColumn(i18n("Date"));
727
826
Transaction *trans = ((ConfirmScheduleListViewItem*) i)->transaction();
829
if(transactionsView->childCount() == 0) reject();
831
void ConfirmScheduleDialog::postpone() {
832
QListViewItem *i = transactionsView->selectedItem();
833
if(i == NULL) return;
834
KDialogBase *dialog = new KDialogBase(this, 0, true, i18n("Date"), Ok|Cancel);
835
KDatePicker *datePicker = new KDatePicker(dialog->makeVBoxMainWidget(), KGlobal::locale()->calendar()->addDays(QDate::currentDate(), 1));
836
if(dialog->exec() == QDialog::Accepted) {
837
if(datePicker->date() > QDate::currentDate()) {
838
Transaction *trans = ((ConfirmScheduleListViewItem*) i)->transaction();
839
trans->setDate(datePicker->date());
840
budget->addScheduledTransaction(new ScheduledTransaction(budget, trans, NULL));
843
KMessageBox::error(this, i18n("Can only postpone to future dates."));
846
dialog->deleteLater();
847
if(transactionsView->childCount() == 0) reject();
731
849
void ConfirmScheduleDialog::edit() {
732
850
QListViewItem *i = transactionsView->selectedItem();
1383
1561
sp.setVerData(QSizePolicy::MinimumExpanding);
1384
1562
accountsView->setSizePolicy(sp);
1385
1563
QFontMetrics fm(accountsView->font());
1386
int w = fm.width(i18n("%2 remains of %1 budget", "%2 of %1").arg(KGlobal::locale()->formatNumber(1000000.0, KGlobal::locale()->fracDigits())).arg(KGlobal::locale()->formatNumber(1000000.0, KGlobal::locale()->fracDigits())));
1564
int w = fm.width(i18n("%2 remains of %1 budget", "%2 of %1").arg(KGlobal::locale()->formatNumber(10000.0, KGlobal::locale()->fracDigits())).arg(KGlobal::locale()->formatNumber(100000.0, KGlobal::locale()->fracDigits())));
1387
1565
if(accountsView->columnWidth(BUDGET_COLUMN) < w) accountsView->setColumnWidth(BUDGET_COLUMN, w);
1388
1566
w = fm.width(KGlobal::locale()->formatNumber(999999999.99, KGlobal::locale()->fracDigits()));
1389
1567
if(accountsView->columnWidth(CHANGE_COLUMN) < w) accountsView->setColumnWidth(CHANGE_COLUMN, w);
1390
1568
w = fm.width(KGlobal::locale()->formatNumber(999999999.99, KGlobal::locale()->fracDigits()) + " ");
1391
1569
if(accountsView->columnWidth(VALUE_COLUMN) < w) accountsView->setColumnWidth(VALUE_COLUMN, w);
1570
w = fm.width(i18n("Account / Category"));
1571
if(accountsView->columnWidth(0) < w) accountsView->setColumnWidth(0, w);
1392
1572
accountsView->header()->setStretchEnabled(true, 0);
1393
assetsItem = new TotalListViewItem(accountsView, i18n("Accounts"), QString::null, KGlobal::locale()->formatNumber(0.0, KGlobal::locale()->fracDigits()), KGlobal::locale()->formatNumber(0.0, KGlobal::locale()->fracDigits()));
1394
incomesItem = new TotalListViewItem(accountsView, assetsItem, i18n("Incomes"), "-", KGlobal::locale()->formatNumber(0.0, KGlobal::locale()->fracDigits()), KGlobal::locale()->formatNumber(0.0, KGlobal::locale()->fracDigits()));
1395
expensesItem = new TotalListViewItem(accountsView, incomesItem, i18n("Expenses"), "-", KGlobal::locale()->formatNumber(0.0, KGlobal::locale()->fracDigits()), KGlobal::locale()->formatNumber(0.0, KGlobal::locale()->fracDigits()));
1573
assetsItem = new TotalListViewItem(accountsView, i18n("Accounts"), QString::null, KGlobal::locale()->formatNumber(0.0, KGlobal::locale()->fracDigits()), KGlobal::locale()->formatNumber(0.0, KGlobal::locale()->fracDigits()) + " ");
1574
incomesItem = new TotalListViewItem(accountsView, assetsItem, i18n("Incomes"), "-", KGlobal::locale()->formatNumber(0.0, KGlobal::locale()->fracDigits()), KGlobal::locale()->formatNumber(0.0, KGlobal::locale()->fracDigits()) + " ");
1575
expensesItem = new TotalListViewItem(accountsView, incomesItem, i18n("Expenses"), "-", KGlobal::locale()->formatNumber(0.0, KGlobal::locale()->fracDigits()), KGlobal::locale()->formatNumber(0.0, KGlobal::locale()->fracDigits()) + " ");
1396
1576
accountsLayoutView->addWidget(accountsView);
1397
1577
QHBoxLayout *accountsLayoutFooter = new QHBoxLayout(accountsLayoutView, 0, 0);
1398
1578
accountsLayoutFooter->addStretch(1);
1712
1892
QTimer *scheduleTimer = new QTimer();
1713
1893
connect(scheduleTimer, SIGNAL(timeout()), this, SLOT(checkSchedule()));
1714
1894
scheduleTimer->start(1000 * 60 * 30);
1896
auto_save_timeout = true;
1898
QTimer *autoSaveTimer = new QTimer();
1899
connect(autoSaveTimer, SIGNAL(timeout()), this, SLOT(onAutoSaveTimeout()));
1900
autoSaveTimer->start(1000 * 60 * 1);
1902
QTimer *dateTimer = new QTimer();
1903
connect(dateTimer, SIGNAL(timeout()), this, SLOT(checkDate()));
1904
dateTimer->start(1000 * 60);
1716
1906
current_page = tabs->activePageIndex();
1717
1907
#if KDE_VERSION_MAJOR < 4 && KDE_VERSION_MINOR < 4
1944
void Eqonomize::checkDate() {
1945
if(QDate::currentDate() != prev_cur_date) {
1946
QDate prev_cur_date_bak = prev_cur_date;
1947
prev_cur_date = QDate::currentDate();
1948
if(to_date == prev_cur_date_bak) {
1949
accountsPeriodToEdit->setDate(prev_cur_date);
1950
accountsPeriodToChanged(prev_cur_date);
1952
if(securities_to_date == prev_cur_date_bak) {
1953
securitiesPeriodToEdit->setDate(prev_cur_date);
1954
securitiesPeriodToChanged(prev_cur_date);
1956
expensesWidget->currentDateChanged(prev_cur_date_bak, prev_cur_date);
1957
incomesWidget->currentDateChanged(prev_cur_date_bak, prev_cur_date);
1958
transfersWidget->currentDateChanged(prev_cur_date_bak, prev_cur_date);
1754
1962
void Eqonomize::showExpenses() {
1755
1963
tabs->showPage(1);
1756
1964
onPageChange(expenses_page);
2285
2496
security = budget->securities.next();
2288
void Eqonomize::newScheduledTransaction(int transaction_type, Security *security) {
2289
newScheduledTransaction(transaction_type, security, this);
2291
void Eqonomize::newScheduledTransaction(int transaction_type, Security *security, QWidget *parent) {
2292
ScheduledTransaction *strans = EditScheduledTransactionDialog::newScheduledTransaction(transaction_type, budget, parent, security, b_extra);
2499
void Eqonomize::newSplitTransaction() {
2500
newSplitTransaction(this);
2502
bool Eqonomize::newSplitTransaction(QWidget *parent, AssetsAccount *account) {
2503
EditSplitDialog *dialog = new EditSplitDialog(budget, parent, account, b_extra);
2504
if(dialog->checkAccounts() && dialog->exec() == QDialog::Accepted) {
2505
SplitTransaction *split = dialog->createSplitTransaction();
2507
budget->addSplitTransaction(split);
2508
splitTransactionAdded(split);
2509
dialog->deleteLater();
2513
dialog->deleteLater();
2516
bool Eqonomize::editSplitTransaction(SplitTransaction *split) {
2517
return editSplitTransaction(split, this);
2519
bool Eqonomize::editSplitTransaction(SplitTransaction *split, QWidget *parent) {
2520
EditSplitDialog *dialog = new EditSplitDialog(budget, parent);
2521
dialog->setSplitTransaction(split);
2522
if(dialog->exec() == QDialog::Accepted) {
2523
SplitTransaction *new_split = dialog->createSplitTransaction();
2525
removeSplitTransaction(split);
2526
budget->addSplitTransaction(new_split);
2527
splitTransactionAdded(new_split);
2528
dialog->deleteLater();
2532
dialog->deleteLater();
2535
bool Eqonomize::splitUpTransaction(SplitTransaction *split) {
2537
budget->removeSplitTransaction(split, true);
2538
splitTransactionRemoved(split);
2542
bool Eqonomize::removeSplitTransaction(SplitTransaction *split) {
2543
budget->removeSplitTransaction(split, true);
2544
splitTransactionRemoved(split);
2548
bool Eqonomize::newScheduledTransaction(int transaction_type, Security *security) {
2549
return newScheduledTransaction(transaction_type, security, this);
2551
bool Eqonomize::newScheduledTransaction(int transaction_type, Security *security, QWidget *parent, Account *account) {
2552
ScheduledTransaction *strans = EditScheduledTransactionDialog::newScheduledTransaction(transaction_type, budget, parent, security, account, b_extra);
2294
2554
if(!strans->recurrence() && strans->transaction()->date() <= QDate::currentDate()) {
2295
2555
Transaction *trans = strans->transaction()->copy();
2449
2713
w->editScheduledTransaction();
2451
void Eqonomize::editTransaction(Transaction *trans) {
2452
editTransaction(trans, this);
2715
void Eqonomize::editSelectedSplitTransaction() {
2716
TransactionListWidget *w = NULL;
2717
switch(tabs->activePageIndex()) {
2719
case 1: {w = expensesWidget; break;}
2720
case 2: {w = incomesWidget; break;}
2721
case 3: {w = transfersWidget; break;}
2726
w->editSplitTransaction();
2728
void Eqonomize::joinSelectedTransactions() {
2729
TransactionListWidget *w = NULL;
2730
switch(tabs->activePageIndex()) {
2732
case 1: {w = expensesWidget; break;}
2733
case 2: {w = incomesWidget; break;}
2734
case 3: {w = transfersWidget; break;}
2739
w->joinTransactions();
2741
void Eqonomize::splitUpSelectedTransaction() {
2742
TransactionListWidget *w = NULL;
2743
switch(tabs->activePageIndex()) {
2745
case 1: {w = expensesWidget; break;}
2746
case 2: {w = incomesWidget; break;}
2747
case 3: {w = transfersWidget; break;}
2752
w->splitUpTransaction();
2754
bool Eqonomize::editTransaction(Transaction *trans) {
2755
return editTransaction(trans, this);
2454
2757
bool Eqonomize::editTransaction(Transaction *trans, QWidget *parent) {
2455
2758
Transaction *oldtrans = trans->copy();
2456
2759
Recurrence *rec = NULL;
2457
if(EditScheduledTransactionDialog::editTransaction(trans, rec, parent, b_extra)) {
2760
if(trans->parentSplit()) {
2761
SplitTransaction *split = trans->parentSplit();
2762
TransactionEditDialog *dialog = new TransactionEditDialog(b_extra, trans->type(), true, trans->fromAccount() == split->account(), NULL, SECURITY_ALL_VALUES, budget, parent);
2763
dialog->editWidget->updateAccounts(split->account());
2764
dialog->editWidget->setTransaction(trans);
2765
if(dialog->exec() == QDialog::Accepted) {
2766
if(dialog->editWidget->modifyTransaction(trans)) {
2767
transactionModified(trans, oldtrans);
2772
dialog->deleteLater();
2773
} else if(EditScheduledTransactionDialog::editTransaction(trans, rec, parent, b_extra)) {
2458
2774
if(!rec && trans->date() <= QDate::currentDate()) {
2459
2775
transactionModified(trans, oldtrans);
2470
2786
delete oldtrans;
2789
void Eqonomize::newRefund() {
2790
if(tabs->activePageIndex() == 1) expensesWidget->newRefundRepayment();
2792
void Eqonomize::newRepayment() {
2793
if(tabs->activePageIndex() == 2) incomesWidget->newRefundRepayment();
2795
void Eqonomize::newRefundRepayment() {
2796
if(tabs->activePageIndex() == 1) expensesWidget->newRefundRepayment();
2797
else if(tabs->activePageIndex() == 2) incomesWidget->newRefundRepayment();
2799
bool Eqonomize::newRefundRepayment(Transaction *trans) {
2800
if(trans->type() != TRANSACTION_TYPE_EXPENSE && trans->type() != TRANSACTION_TYPE_INCOME) return false;
2801
RefundDialog *dialog = new RefundDialog(trans, this);
2802
if(dialog->exec() == QDialog::Accepted) {
2803
Transaction *new_trans = dialog->createRefund();
2805
budget->addTransaction(new_trans);
2806
transactionAdded(new_trans);
2807
dialog->deleteLater();
2811
dialog->deleteLater();
2473
2814
void Eqonomize::editSelectedTransaction() {
2474
2815
TransactionListWidget *w = NULL;
2475
2816
switch(tabs->activePageIndex()) {
2583
2943
ActionBalanceAccount->plug(accountPopupMenu);
2584
2944
ActionDeleteAccount->plug(accountPopupMenu);
2585
2945
accountPopupMenu->insertSeparator();
2586
ActionShowAccountExpenses->plug(accountPopupMenu);
2587
ActionShowAccountIncomes->plug(accountPopupMenu);
2946
ActionShowAccountTransactions->plug(accountPopupMenu);
2589
2948
accountPopupMenu->popup(p);
2593
void Eqonomize::showAccountIncomes(bool b) {
2952
void Eqonomize::showAccountTransactions(bool b) {
2594
2953
QListViewItem *i = accountsView->selectedItem();
2595
if(i != NULL && i != expensesItem && (i == incomesItem || i == assetsItem || account_items[i]->type() != ACCOUNT_TYPE_EXPENSES)) {
2596
Account *to = NULL, *from = NULL;
2597
if(i != incomesItem) {
2598
Account *account = account_items[i];
2599
if(account->type() == ACCOUNT_TYPE_INCOMES) {
2601
} else if(account->type() == ACCOUNT_TYPE_ASSETS) {
2605
if(b) incomesWidget->setFilter(QDate(), to_date, -1.0, -1.0, from, to);
2606
else incomesWidget->setFilter(accountsPeriodFromButton->isChecked() ? from_date : QDate(), to_date, -1.0, -1.0, from, to);
2954
if(i == NULL || i == assetsItem) return;
2955
if(i == incomesItem) {
2956
if(b) incomesWidget->setFilter(QDate(), to_date, -1.0, -1.0, NULL, NULL);
2957
else incomesWidget->setFilter(accountsPeriodFromButton->isChecked() ? from_date : QDate(), to_date, -1.0, -1.0, NULL, NULL);
2607
2958
incomesWidget->showFilter();
2608
2959
tabs->showPage(2);
2609
2960
onPageChange(incomes_page);
2612
void Eqonomize::showAccountExpenses(bool b) {
2613
QListViewItem *i = accountsView->selectedItem();
2614
if(i != NULL && i != incomesItem && (i == expensesItem || i == assetsItem || account_items[i]->type() != ACCOUNT_TYPE_INCOMES)) {
2615
Account *to = NULL, *from = NULL;
2616
if(i != expensesItem && i != assetsItem) {
2617
Account *account = account_items[i];
2618
if(account->type() == ACCOUNT_TYPE_EXPENSES) {
2620
} else if(account->type() == ACCOUNT_TYPE_ASSETS) {
2624
if(b) expensesWidget->setFilter(QDate(), to_date, -1.0, -1.0, from, to);
2625
else expensesWidget->setFilter(accountsPeriodFromButton->isChecked() ? from_date : QDate(), to_date, -1.0, -1.0, from, to);
2961
} else if(i == expensesItem) {
2962
if(b) expensesWidget->setFilter(QDate(), to_date, -1.0, -1.0, NULL, NULL);
2963
else expensesWidget->setFilter(accountsPeriodFromButton->isChecked() ? from_date : QDate(), to_date, -1.0, -1.0, NULL, NULL);
2626
2964
expensesWidget->showFilter();
2627
2965
tabs->showPage(1);
2628
2966
onPageChange(expenses_page);
2968
Account *account = account_items[i];
2969
AccountType type = account->type();
2970
if(type == ACCOUNT_TYPE_INCOMES) {
2971
if(b) incomesWidget->setFilter(QDate(), to_date, -1.0, -1.0, account, NULL);
2972
else incomesWidget->setFilter(accountsPeriodFromButton->isChecked() ? from_date : QDate(), to_date, -1.0, -1.0, account, NULL);
2973
incomesWidget->showFilter();
2975
onPageChange(incomes_page);
2976
} else if(type == ACCOUNT_TYPE_EXPENSES) {
2977
if(b) expensesWidget->setFilter(QDate(), to_date, -1.0, -1.0, NULL, account);
2978
else expensesWidget->setFilter(accountsPeriodFromButton->isChecked() ? from_date : QDate(), to_date, -1.0, -1.0, NULL, account);
2979
expensesWidget->showFilter();
2981
onPageChange(expenses_page);
2982
} else if(((AssetsAccount*) account)->accountType() == ASSETS_TYPE_SECURITIES) {
2984
onPageChange(securities_page);
2986
LedgerDialog *dialog = new LedgerDialog((AssetsAccount*) account, this, i18n("Ledger"), b_extra);
2632
2991
void Eqonomize::accountsPeriodToChanged(const QDate &date) {
2633
2992
bool error = false;
2634
2993
if(!date.isValid()) {
2924
3283
void Eqonomize::setModified(bool has_been_modified) {
3284
modified_auto_save = has_been_modified;
3285
if(has_been_modified) autoSave();
2925
3286
if(modified == has_been_modified) return;
2926
3287
modified = has_been_modified;
2927
3288
ActionSave->setEnabled(modified);
2928
3289
if(!current_url.isValid()) setCaption(i18n("Untitled"), has_been_modified);
2929
3290
else setCaption(current_url.fileName(), has_been_modified);
2930
3291
if(modified) emit budgetUpdated();
3292
else auto_save_timeout = true;
2932
3294
void Eqonomize::createDefaultBudget() {
2933
3295
if(!askSave()) return;
2934
3296
budget->clear();
2935
3297
current_url = "";
3298
ActionFileReload->setEnabled(false);
3299
config->setGroup("General Options");
3300
#if KDE_IS_VERSION(3,1,3)
3301
config->writePathEntry("lastURL", current_url.url());
3303
config->writeEntry("lastURL", current_url.url());
2936
3306
budget->addAccount(new AssetsAccount(budget, ASSETS_TYPE_CASH, i18n("Cash"), 100.0));
2937
3307
budget->addAccount(new AssetsAccount(budget, ASSETS_TYPE_CURRENT, i18n("Check Account"), 1000.0));
2938
3308
budget->addAccount(new AssetsAccount(budget, ASSETS_TYPE_SAVINGS, i18n("Savings Account"), 10000.0));
3040
3422
bool Eqonomize::saveURL(const KURL& url) {
3042
3424
if(url.isLocalFile()) {
3043
if(url != current_url && QFile::exists(url.path())) {
3044
if(KMessageBox::warningYesNo(this, i18n("That file already exists. Would you like to overwrite the old copy?")) != KMessageBox::Yes) return false;
3425
bool exists = QFile::exists(url.path());
3426
if(url != current_url && exists) {
3427
if(KMessageBox::warningYesNo(this, i18n("The selected file already exists. Would you like to overwrite the old copy?")) != KMessageBox::Yes) return false;
3431
u.setFileName(url.fileName() + "~");
3432
mode_t perms = 0600;
3433
KIO::UDSEntry fentry;
3434
if (KIO::NetAccess::stat(url, fentry, this)) {
3435
KFileItem item(fentry, url);
3436
perms = item.permissions();
3438
if((!KIO::NetAccess::exists(u, false, this) || KIO::NetAccess::del(u, this))) {
3439
KIO::NetAccess::file_copy(url, u, perms, true, false, this);
3046
3443
QString error = budget->saveFile(url.path());
3047
3444
if(!error.isNull()) {
3048
3445
KMessageBox::error(this, i18n("Error saving %1: %2.").arg(url.prettyURL()).arg(error), i18n("Couldn't save file"));
3669
4097
ActionSave = KStdAction::save(this, SLOT(fileSave()), actionCollection());
3670
4098
ActionOpenRecent = KStdAction::openRecent(this, SLOT(fileOpenRecent(const KURL&)), actionCollection());
3671
4099
KStdAction::saveAs(this, SLOT(fileSaveAs()), actionCollection());
3672
KStdAction::quit(kapp, SLOT(quit()), actionCollection());
4100
KStdAction::quit(this, SLOT(close()), actionCollection());
4102
ActionFileReload = KStdAction::revert(this, SLOT(fileReload()), actionCollection());
3674
4104
ActionSaveView = new KAction(i18n("Export View..."), "filesave", 0, this, SLOT(saveView()), actionCollection(), "save_view");
3675
4105
ActionPrintView = KStdAction::print(this, SLOT(printView()), actionCollection());
3676
4106
ActionPrintView->setText(i18n("Print View..."));
3678
4108
ActionImportCSV = new KAction(i18n("Import CSV File..."), "fileimport", 0, this, SLOT(importCSV()), actionCollection(), "import_csv");
4109
ActionImportQIF = new KAction(i18n("Import QIF File..."), "fileimport", 0, this, SLOT(importQIF()), actionCollection(), "import_qif");
4110
ActionExportQIF = new KAction(i18n("Export As QIF File..."), "filesave", 0, this, SLOT(exportQIF()), actionCollection(), "export_qif");
3680
4112
ActionAddAccount = new KAction(i18n("Add Account..."), "filenew", 0, this, SLOT(addAccount()), actionCollection(), "add_account");
3681
4113
ActionNewAssetsAccount = new KAction(i18n("New Account..."), "filenew", 0, this, SLOT(newAssetsAccount()), actionCollection(), "new_assets_account");
3685
4117
ActionEditAccount = new KAction(i18n("Edit..."), "edit", 0, this, SLOT(editAccount()), actionCollection(), "edit_account");
3686
4118
ActionDeleteAccount = new KAction(i18n("Remove"), "editdelete", 0, this, SLOT(deleteAccount()), actionCollection(), "delete_account");
3688
ActionShowAccountExpenses = new KAction(i18n("Show Expenses"), "back", 0, this, SLOT(showAccountExpenses()), actionCollection(), "show_account_expenses");
3689
ActionShowAccountIncomes = new KAction(i18n("Show Incomes"), "forward", 0, this, SLOT(showAccountIncomes()), actionCollection(), "show_account_incomes");
4120
ActionShowAccountTransactions = new KAction(i18n("Show Transactions"), 0, this, SLOT(showAccountTransactions()), actionCollection(), "show_account_transactions");
3691
4122
ActionNewExpense = new KAction(i18n("New Expense..."), "filenew", CTRL+Key_E, this, SLOT(newScheduledExpense()), actionCollection(), "new_expense");
3692
4123
ActionNewIncome = new KAction(i18n("New Income..."), "filenew", CTRL+Key_I, this, SLOT(newScheduledIncome()), actionCollection(), "new_income");
3693
4124
ActionNewTransfer = new KAction(i18n("New Transfer..."), "filenew", CTRL+Key_T, this, SLOT(newScheduledTransfer()), actionCollection(), "new_transfer");
4125
ActionNewSplitTransaction = new KAction(i18n("New Split Transaction..."), "filenew", 0, this, SLOT(newSplitTransaction()), actionCollection(), "new_split_transaction");
3694
4126
ActionEditTransaction = new KAction(i18n("Edit Transaction(s) (Occurrence)..."), "edit", 0, this, SLOT(editSelectedTransaction()), actionCollection(), "edit_transaction");
3695
4127
ActionEditScheduledTransaction = new KAction(i18n("Edit Schedule (Recurrence)..."), "edit", 0, this, SLOT(editSelectedScheduledTransaction()), actionCollection(), "edit_scheduled_transaction");
3696
ActionDeleteTransaction = new KAction(i18n("Remove Transaction(s) (Occurrence)..."), "editdelete", 0, this, SLOT(deleteSelectedTransaction()), actionCollection(), "delete_transaction");
3697
ActionDeleteScheduledTransaction = new KAction(i18n("Delete Schedule (Recurrence)..."), "editdelete", 0, this, SLOT(deleteSelectedScheduledTransaction()), actionCollection(), "delete_scheduled_transaction");
4128
ActionDeleteTransaction = new KAction(i18n("Remove Transaction(s) (Occurrence)"), "editdelete", 0, this, SLOT(deleteSelectedTransaction()), actionCollection(), "delete_transaction");
4129
ActionDeleteScheduledTransaction = new KAction(i18n("Delete Schedule (Recurrence)"), "editdelete", 0, this, SLOT(deleteSelectedScheduledTransaction()), actionCollection(), "delete_scheduled_transaction");
4130
ActionEditSplitTransaction = new KAction(i18n("Edit Split Transaction..."), "edit", 0, this, SLOT(editSelectedSplitTransaction()), actionCollection(), "edit_split_transaction");
4131
ActionDeleteSplitTransaction = new KAction(i18n("Remove Split Transaction"), "editdelete", 0, this, SLOT(deleteSelectedSplitTransaction()), actionCollection(), "delete_split_transaction");
4132
ActionJoinTransactions = new KAction(i18n("Join Transactions..."), 0, this, SLOT(joinSelectedTransactions()), actionCollection(), "joins_transactions");
4133
ActionSplitUpTransaction = new KAction(i18n("Split Up Transaction"), 0, this, SLOT(splitUpSelectedTransaction()), actionCollection(), "split_up_transaction");
4135
ActionNewRefund = new KAction(i18n("Refund..."), "forward", 0, this, SLOT(newRefund()), actionCollection(), "new_refund");
4136
ActionNewRepayment = new KAction(i18n("Repayment..."), "back", 0, this, SLOT(newRepayment()), actionCollection(), "new_repayment");
4137
ActionNewRefundRepayment = new KAction(i18n("New Refund/Repayment..."), "filenew", 0, this, SLOT(newRefundRepayment()), actionCollection(), "new_refund_repayment");
3699
4139
ActionNewSecurity = new KAction(i18n("New Security..."), "filenew", 0, this, SLOT(newSecurity()), actionCollection(), "new_security");
3700
4140
ActionEditSecurity = new KAction(i18n("Edit Security..."), "edit", 0, this, SLOT(editSecurity()), actionCollection(), "edit_security");
3716
4156
ActionExtraProperties = new KToggleAction(i18n("Use Additional Transaction Properties"), 0, actionCollection(), "extra_properties");
3717
4157
ActionExtraProperties->setChecked(b_extra);
3718
4158
QObject::connect(ActionExtraProperties, SIGNAL(toggled(bool)), this, SLOT(useExtraProperties(bool)));
3720
4160
ActionSave->setEnabled(false);
4161
ActionFileReload->setEnabled(false);
3721
4162
ActionBalanceAccount->setEnabled(false);
3722
4163
ActionEditAccount->setEnabled(false);
3723
4164
ActionDeleteAccount->setEnabled(false);
3724
ActionShowAccountExpenses->setEnabled(false);
3725
ActionShowAccountIncomes->setEnabled(false);
4165
ActionShowAccountTransactions->setEnabled(false);
3726
4166
ActionEditTransaction->setEnabled(false);
3727
4167
ActionDeleteTransaction->setEnabled(false);
4168
ActionEditSplitTransaction->setEnabled(false);
4169
ActionDeleteSplitTransaction->setEnabled(false);
4170
ActionJoinTransactions->setEnabled(false);
4171
ActionSplitUpTransaction->setEnabled(false);
3728
4172
ActionEditScheduledTransaction->setEnabled(false);
3729
4173
ActionDeleteScheduledTransaction->setEnabled(false);
4174
ActionNewRefund->setEnabled(false);
4175
ActionNewRepayment->setEnabled(false);
4176
ActionNewRefundRepayment->setEnabled(false);
3730
4177
ActionEditSecurity->setEnabled(false);
3731
4178
ActionDeleteSecurity->setEnabled(false);
3732
4179
ActionSellShares->setEnabled(false);
4190
bool Eqonomize::crashRecovery(KURL url) {
4191
config->setGroup("General Options");
4193
if(url.isLocalFile()) {
4194
cr_tmp_file = kapp->checkRecoverFile(url.path(), b);
4195
} else if(url.isEmpty()) {
4196
cr_tmp_file = kapp->checkRecoverFile("/UNSAVED EQZ", b);
4199
if(KMessageBox::questionYesNo(this, i18n("Eqonomize! exited unexpectedly before the file was saved and data was lost.\nDo you want to load the last auto-saved version of the file?"), i18n("Crash Recovery")) == KMessageBox::Yes) {
4201
QString error = budget->loadFile(cr_tmp_file, errors);
4202
if(!error.isNull()) {
4203
KMessageBox::error(this, i18n("Error loading %1: %2.").arg(cr_tmp_file).arg(error), i18n("Couldn't open file"));
4207
if(!errors.isEmpty()) {
4208
KMessageBox::error(this, errors);
4211
ActionFileReload->setEnabled(true);
4212
setCaption(current_url.fileName(), false);
4213
QFile file(cr_tmp_file); file.remove();
4217
emit accountsModified();
4218
emit transactionsModified();
4219
emit budgetUpdated();
4222
checkSchedule(true);
4227
QFile file(cr_tmp_file); file.remove();
4235
void Eqonomize::onAutoSaveTimeout() {
4236
auto_save_timeout = true;
4237
if(modified_auto_save) {
4241
void Eqonomize::autoSave() {
4242
if(auto_save_timeout) {
4243
saveCrashRecovery();
4244
modified_auto_save = false;
4245
auto_save_timeout = false;
4248
void Eqonomize::saveCrashRecovery() {
4249
if(cr_tmp_file.isEmpty() && current_url.isEmpty()) {
4250
cr_tmp_file = kapp->tempSaveName("/UNSAVED EQZ");
4252
if(budget->saveFile(cr_tmp_file).isNull()) {
4253
config->setGroup("General Options");
4254
#if KDE_IS_VERSION(3,1,3)
4255
config->writePathEntry("lastURL", current_url.url());
4257
config->writeEntry("lastURL", current_url.url());
3743
4263
void Eqonomize::saveOptions() {
3744
4264
config->setGroup("General Options");
3745
config->writeEntry("firstRun", false);
3746
4265
ActionOpenRecent->saveEntries(config);
3747
4266
#if KDE_IS_VERSION(3,1,3)
3748
4267
config->writePathEntry("lastURL", current_url.url());
3844
bool Eqonomize::askSave() {
4376
bool Eqonomize::askSave(bool before_exit) {
3845
4377
if(!modified) return true;
3846
int b_save = KMessageBox::warningYesNoCancel(this, i18n("The current file has been modified. Do you want to save it?"));
4379
if(before_exit && current_url.isValid()) b_save = KMessageBox::warningYesNoCancel(this, i18n("The current file has been modified. Do you want to save it?"), i18n("Warning"), KStdGuiItem::yes(), KStdGuiItem::no(), "saveOnExit");
4380
else b_save = KMessageBox::warningYesNoCancel(this, i18n("The current file has been modified. Do you want to save it?"));
3847
4381
if(b_save == KMessageBox::Yes) {
3848
4382
if(!current_url.isValid()) {
3849
KURL file_url = KFileDialog::getSaveURL(QString::null, "application/x-eqonomize", this);
4383
KURL file_url = KFileDialog::getSaveURL("budget", "application/x-eqonomize", this);
3850
4384
if (!file_url.isEmpty() && file_url.isValid()) {
3851
4385
return saveURL(file_url);
3993
if(account_items.contains(i) && account_items[i]->type() != ACCOUNT_TYPE_ASSETS) {
3994
accountsTabs->setCurrentPage(1);
3995
if(budgetEdit->isEnabled()) {
3996
budgetEdit->setFocus();
3997
budgetEdit->lineEdit()->selectAll();
4526
if(account_items.contains(i)) {
4527
if(account_items[i]->type() == ACCOUNT_TYPE_ASSETS) {
4528
showAccountTransactions();
3999
budgetButton->setFocus();
4530
accountsTabs->setCurrentPage(1);
4531
if(budgetEdit->isEnabled()) {
4532
budgetEdit->setFocus();
4533
budgetEdit->lineEdit()->selectAll();
4535
budgetButton->setFocus();
4005
if(i == incomesItem || (account_items.contains(i) && account_items[i]->type() == ACCOUNT_TYPE_INCOMES)) {
4006
showAccountIncomes();
4008
showAccountExpenses();
4542
showAccountTransactions();
4013
if(i == incomesItem || (account_items.contains(i) && account_items[i]->type() == ACCOUNT_TYPE_INCOMES)) {
4014
showAccountIncomes(true);
4016
showAccountExpenses(true);
4546
showAccountTransactions(true);
4076
4603
Account *i_account = account_items[i];
4077
4604
editAccount(i_account);
4079
void Eqonomize::editAccount(Account *i_account) {
4606
bool Eqonomize::editAccount(Account *i_account) {
4607
return editAccount(i_account, this);
4609
bool Eqonomize::editAccount(Account *i_account, QWidget *parent) {
4080
4610
QListViewItem *i = item_accounts[i_account];
4081
4611
switch(i_account->type()) {
4082
4612
case ACCOUNT_TYPE_ASSETS: {
4083
EditAssetsAccountDialog *dialog = new EditAssetsAccountDialog(budget, this, i18n("Edit Account"));
4613
EditAssetsAccountDialog *dialog = new EditAssetsAccountDialog(budget, parent, i18n("Edit Account"));
4084
4614
AssetsAccount *account = (AssetsAccount*) i_account;
4085
4615
dialog->setAccount(account);
4086
4616
double prev_ib = account->initialBalance();
4400
4933
updateSecurity(((Income*) strans->transaction())->security());
4936
void Eqonomize::splitTransactionAdded(SplitTransaction *split) {
4938
QValueVector<Transaction*>::size_type c = split->splits.count();
4939
for(QValueVector<Transaction*>::size_type i = 0; i < c; i++) {
4940
transactionAdded(split->splits[i]);
4942
blockSignals(false);
4943
emit transactionsModified();
4945
void Eqonomize::splitTransactionRemoved(SplitTransaction *split) {
4947
QValueVector<Transaction*>::size_type c = split->splits.count();
4948
for(QValueVector<Transaction*>::size_type i = 0; i < c; i++) {
4949
transactionRemoved(split->splits[i]);
4951
blockSignals(false);
4952
emit transactionsModified();
4404
4955
void Eqonomize::appendExpensesAccount(ExpensesAccount *account) {
4405
4956
QListViewItem *i = new QListViewItem(expensesItem, account->name(), "-", KGlobal::locale()->formatNumber(0.0, KGlobal::locale()->fracDigits()), KGlobal::locale()->formatNumber(0.0, KGlobal::locale()->fracDigits()) + " ");
4595
5146
balfrom = (trans->fromAccount() == budget->balancingAccount);
4596
if(!balfrom) account_value[trans->fromAccount()] -= value;
4597
assets_accounts_value -= value;
4599
if(!balfrom) account_change[(AssetsAccount*) trans->fromAccount()] -= value;
4600
assets_accounts_change -= value;
4601
if(update_value_display) {
4602
assetsItem->setText(CHANGE_COLUMN, KGlobal::locale()->formatNumber(assets_accounts_change, KGlobal::locale()->fracDigits()));
4603
if(!balfrom) item_accounts[trans->fromAccount()]->setText(CHANGE_COLUMN, KGlobal::locale()->formatNumber(account_change[trans->fromAccount()], KGlobal::locale()->fracDigits()));
5148
account_value[trans->fromAccount()] -= value;
5149
assets_accounts_value -= value;
5151
account_change[trans->fromAccount()] -= value;
5152
assets_accounts_change -= value;
5153
if(update_value_display) {
5154
assetsItem->setText(CHANGE_COLUMN, KGlobal::locale()->formatNumber(assets_accounts_change, KGlobal::locale()->fracDigits()));
5155
item_accounts[trans->fromAccount()]->setText(CHANGE_COLUMN, KGlobal::locale()->formatNumber(account_change[trans->fromAccount()], KGlobal::locale()->fracDigits()));
5158
if(update_value_display) assetsItem->setText(VALUE_COLUMN, KGlobal::locale()->formatNumber(assets_accounts_value, KGlobal::locale()->fracDigits()) + " ");
4606
if(update_value_display) assetsItem->setText(VALUE_COLUMN, KGlobal::locale()->formatNumber(assets_accounts_value, KGlobal::locale()->fracDigits()) + " ");
4704
5257
balto = (trans->toAccount() == budget->balancingAccount);
4705
if(!balto) account_value[trans->toAccount()] += value;
4706
assets_accounts_value += value;
4708
if(!balto) account_change[trans->toAccount()] += value;
4709
assets_accounts_change += value;
4710
if(update_value_display) {
4711
assetsItem->setText(CHANGE_COLUMN, KGlobal::locale()->formatNumber(assets_accounts_change, KGlobal::locale()->fracDigits()));
4712
if(!balto) item_accounts[trans->toAccount()]->setText(CHANGE_COLUMN, KGlobal::locale()->formatNumber(account_change[trans->toAccount()], KGlobal::locale()->fracDigits()));
5259
account_value[trans->toAccount()] += value;
5260
assets_accounts_value += value;
5262
account_change[trans->toAccount()] += value;
5263
assets_accounts_change += value;
5264
if(update_value_display) {
5265
assetsItem->setText(CHANGE_COLUMN, KGlobal::locale()->formatNumber(assets_accounts_change, KGlobal::locale()->fracDigits()));
5266
item_accounts[trans->toAccount()]->setText(CHANGE_COLUMN, KGlobal::locale()->formatNumber(account_change[trans->toAccount()], KGlobal::locale()->fracDigits()));
5269
if(update_value_display) assetsItem->setText(VALUE_COLUMN, KGlobal::locale()->formatNumber(assets_accounts_value, KGlobal::locale()->fracDigits()) + " ");
4715
if(update_value_display) assetsItem->setText(VALUE_COLUMN, KGlobal::locale()->formatNumber(assets_accounts_value, KGlobal::locale()->fracDigits()) + " ");
4719
if(update_value_display) {
5274
if(update_value_display && !b_lastmonth) {
4721
5276
item_accounts[trans->fromAccount()]->setText(VALUE_COLUMN, KGlobal::locale()->formatNumber(account_value[trans->fromAccount()], KGlobal::locale()->fracDigits()) + " ");
5277
item_accounts[trans->fromAccount()]->setText(CHANGE_COLUMN, KGlobal::locale()->formatNumber(account_change[trans->fromAccount()], KGlobal::locale()->fracDigits()));
4724
5280
item_accounts[trans->toAccount()]->setText(VALUE_COLUMN, KGlobal::locale()->formatNumber(account_value[trans->toAccount()], KGlobal::locale()->fracDigits()) + " ");
5281
item_accounts[trans->toAccount()]->setText(CHANGE_COLUMN, KGlobal::locale()->formatNumber(account_change[trans->toAccount()], KGlobal::locale()->fracDigits()));