~ubuntu-branches/ubuntu/karmic/eqonomize/karmic

« back to all changes in this revision

Viewing changes to src/eqonomize.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Luka Renko
  • Date: 2007-01-06 09:30:45 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070106093045-imo7dgrizfxgtvwe
Tags: 0.4-0ubuntu1
* New upstream release.
* Added homepage to long description. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#include "overtimechart.h"
37
37
#include "importcsvdialog.h"
38
38
#include "eqonomizemonthselector.h"
 
39
#include "editsplitdialog.h"
 
40
#include "ledgerdialog.h"
39
41
 
40
42
#include <qdragobject.h>
41
43
#include <kprinter.h>
55
57
#include <kstatusbar.h>
56
58
#include <kaccel.h>
57
59
#include <kio/netaccess.h>
 
60
#include <kfileitem.h>
58
61
#include <kfiledialog.h>
59
62
#include <kconfig.h>
60
63
#include <kurl.h>
86
89
#include <qvbox.h>
87
90
#include <ksavefile.h>
88
91
#include <kcalendarsystem.h>
 
92
#include <kdatepicker.h>
 
93
 
 
94
#include "qifimportexport.h"
89
95
 
90
96
#if KDE_VERSION_MAJOR < 4 && KDE_VERSION_MINOR < 2
91
97
#include <qtabwidget.h>
374
380
        return QListViewItem::compare(i, col, ascending);
375
381
}
376
382
 
 
383
RefundDialog::RefundDialog(Transaction *trans, QWidget *parent) : KDialogBase(parent, 0, true, i18n("Refund"), Ok | Cancel, Ok, true), transaction(trans) {
 
384
 
 
385
        if(trans->type() == TRANSACTION_TYPE_INCOME) setCaption(i18n("Repayment"));
 
386
        
 
387
        setMainWidget(new QWidget(this));
 
388
        QGridLayout *layout = new QGridLayout(mainWidget(), 5, 2, 0, spacingHint());
 
389
 
 
390
        layout->addWidget(new QLabel(i18n("Date:"), mainWidget()), 0, 0);
 
391
        dateEdit = new KDateEdit(mainWidget());
 
392
        layout->addWidget(dateEdit, 0, 1);
 
393
        dateEdit->setFocus();
 
394
 
 
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() + " ");
 
400
        } else {
 
401
                valueEdit->setSuffix(QString(" ") + KGlobal::locale()->currencySymbol());
 
402
        }
 
403
        layout->addWidget(valueEdit, 1, 1);
 
404
 
 
405
        layout->addWidget(new QLabel(i18n("Account:"), mainWidget()), 2, 0);
 
406
        accountCombo = new KComboBox(mainWidget());
 
407
        accountCombo->setEditable(false);
 
408
        int i = 0;
 
409
        AssetsAccount *account = transaction->budget()->assetsAccounts.first();
 
410
        while(account) {
 
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);
 
414
                        i++;
 
415
                }
 
416
                account = transaction->budget()->assetsAccounts.next();
 
417
        }
 
418
        layout->addWidget(accountCombo, 2, 1);
 
419
 
 
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);
 
423
 
 
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);
 
429
 
 
430
}
 
431
Transaction *RefundDialog::createRefund() {
 
432
        if(!validValues()) return NULL;
 
433
        Transaction *trans = NULL;
 
434
        int i = 0;
 
435
        int cur_i = accountCombo->currentItem();
 
436
        AssetsAccount *account = transaction->budget()->assetsAccounts.first();
 
437
        while(account) {
 
438
                if(account != transaction->budget()->balancingAccount && account->accountType() != ASSETS_TYPE_SECURITIES) {
 
439
                        if(i == cur_i) break;
 
440
                        i++;
 
441
                }
 
442
                account = transaction->budget()->assetsAccounts.next();
 
443
        }
 
444
        trans = transaction->copy();
 
445
        if(transaction->type() == TRANSACTION_TYPE_EXPENSE) {
 
446
                ((Expense*) trans)->setFrom(account);
 
447
        } else {
 
448
                ((Income*) trans)->setTo(account);
 
449
        }
 
450
        trans->setQuantity(-quantityEdit->value());
 
451
        trans->setValue(-valueEdit->value());
 
452
        trans->setDate(dateEdit->date());
 
453
        trans->setComment(commentsEdit->text());
 
454
        return trans;
 
455
}
 
456
void RefundDialog::slotOk() {
 
457
        if(validValues()) {
 
458
                KDialogBase::slotOk();
 
459
        }
 
460
}
 
461
bool RefundDialog::validValues() {
 
462
        if(!dateEdit->date().isValid()) {
 
463
                KMessageBox::error(this, i18n("Invalid date."));
 
464
                return false;
 
465
        }
 
466
        return true;
 
467
}
 
468
 
 
469
 
377
470
EditReinvestedDividendDialog::EditReinvestedDividendDialog(Security *sec, QWidget *parent)  : KDialogBase(parent, 0, true, i18n("Reinvested Dividend"), Ok | Cancel, Ok, true), security(sec) {
378
471
        
379
472
        setMainWidget(new QWidget(this));
564
657
        quotationsView->setSorting(0, false);
565
658
        quotationsView->setAllColumnsShowFocus(true);
566
659
        quotationsView->addColumn(i18n("Date"));
567
 
        quotationsView->addColumn(i18n("Price per share"));
 
660
        quotationsView->addColumn(i18n("Price per Share"));
568
661
        quotationsView->setColumnAlignment(0, Qt::AlignRight);
569
662
        quotationsView->setColumnAlignment(1, Qt::AlignRight);
570
663
        quotationsView->setRootIsDecorated(false);
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"));
697
791
        KButtonBox *buttons = new KButtonBox(mainWidget(), KButtonBox::Vertical);
698
792
        editButton = buttons->addButton(i18n("Edit..."));
699
793
        editButton->setEnabled(false);
 
794
        postponeButton = buttons->addButton(i18n("Postpone..."));
 
795
        postponeButton->setEnabled(false);
700
796
#if KDE_VERSION_MAJOR > 3 || KDE_VERSION_MINOR >= 3     
701
797
        removeButton = buttons->addButton(KStdGuiItem::guiItem(KStdGuiItem::Delete));
702
798
#else
709
805
        connect(transactionsView, SIGNAL(selectionChanged()), this, SLOT(transactionSelectionChanged()));
710
806
        connect(removeButton, SIGNAL(clicked()), this, SLOT(remove()));
711
807
        connect(editButton, SIGNAL(clicked()), this, SLOT(edit()));
 
808
        connect(postponeButton, SIGNAL(clicked()), this, SLOT(postpone()));
712
809
        updateTransactions();
713
810
}
714
811
void ConfirmScheduleDialog::transactionSelectionChanged() {
716
813
        if(i == NULL) {
717
814
                editButton->setEnabled(false);
718
815
                removeButton->setEnabled(false);
 
816
                postponeButton->setEnabled(false);
719
817
        } else {
720
818
                editButton->setEnabled(true);
721
819
                removeButton->setEnabled(true);
 
820
                postponeButton->setEnabled(true);
722
821
        }
723
822
}
724
823
void ConfirmScheduleDialog::remove() {
727
826
        Transaction *trans = ((ConfirmScheduleListViewItem*) i)->transaction();
728
827
        delete trans;
729
828
        delete i;
 
829
        if(transactionsView->childCount() == 0) reject();
 
830
}
 
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));
 
841
                        delete i;
 
842
                } else {
 
843
                        KMessageBox::error(this, i18n("Can only postpone to future dates."));
 
844
                }
 
845
        }
 
846
        dialog->deleteLater();
 
847
        if(transactionsView->childCount() == 0) reject();
730
848
}
731
849
void ConfirmScheduleDialog::edit() {
732
850
        QListViewItem *i = transactionsView->selectedItem();
738
856
        } else if(trans->type() == TRANSACTION_TYPE_INCOME && ((Income*) trans)->security()) {
739
857
                security = ((Income*) trans)->security();
740
858
        }
741
 
        TransactionEditDialog *dialog = new TransactionEditDialog(b_extra, trans->type(), security, SECURITY_VALUE_AND_SHARES, budget, this);
 
859
        TransactionEditDialog *dialog = new TransactionEditDialog(b_extra, trans->type(), false, false, security, SECURITY_ALL_VALUES, budget, this);
742
860
        dialog->editWidget->updateAccounts();
743
861
        dialog->editWidget->setTransaction(trans);
744
862
        if(trans->type() == TRANSACTION_TYPE_SECURITY_SELL) dialog->editWidget->setMaxShares(((SecurityTransaction*) trans)->security()->shares(QDate::currentDate()));
764
882
                        }
765
883
                }
766
884
        }
767
 
        delete dialog;
 
885
        dialog->deleteLater();
 
886
        if(transactionsView->childCount() == 0) reject();
768
887
}
769
888
void ConfirmScheduleDialog::updateTransactions() {
770
889
        ScheduledTransaction *strans = budget->scheduledTransactions.first();
793
912
                        }
794
913
                }
795
914
        }
 
915
        QListViewItem *i = transactionsView->firstChild();
 
916
        if(i) transactionsView->setSelected(i, true);
796
917
}
797
918
Transaction *ConfirmScheduleDialog::firstTransaction() {
798
919
        current_item = (ConfirmScheduleListViewItem*) transactionsView->firstChild();
993
1114
        typeCombo->insertItem(i18n("Mutual Fund"));
994
1115
        typeCombo->insertItem(i18n("Bond"));
995
1116
        typeCombo->insertItem(i18n("Stock"));
 
1117
        typeCombo->insertItem(i18n("Other"));
996
1118
        grid->addWidget(typeCombo, 0, 1);
997
1119
        typeCombo->setFocus();
998
1120
        grid->addWidget(new QLabel(i18n("Name:"), mainWidget()), 1, 0);
1025
1147
                quotationEdit->setSuffix(QString(" ") + KGlobal::locale()->currencySymbol());
1026
1148
        }
1027
1149
        grid->addWidget(quotationEdit, 5, 1);
1028
 
        grid->addWidget(new QLabel(i18n("Date:"), mainWidget()), 6, 0);
 
1150
        quotationDateLabel = new QLabel(i18n("Date:"), mainWidget());
 
1151
        grid->addWidget(quotationDateLabel, 6, 0);
1029
1152
        quotationDateEdit = new KDateEdit(mainWidget());
1030
1153
        grid->addWidget(quotationDateEdit, 6, 1);
1031
1154
        grid->addWidget(new QLabel(i18n("Description:"), mainWidget()), 7, 0);
1052
1175
        switch(typeCombo->currentItem()) {
1053
1176
                case 1: {type = SECURITY_TYPE_BOND; break;}
1054
1177
                case 2: {type = SECURITY_TYPE_STOCK; break;}
 
1178
                case 3: {type = SECURITY_TYPE_OTHER; break;}
1055
1179
                default: {type = SECURITY_TYPE_MUTUAL_FUND; break;}
1056
1180
        }
1057
1181
        Security *security = new Security(budget, accounts[accountCombo->currentItem()], type, sharesEdit->value(), decimalsEdit->value(), nameEdit->text(), descriptionEdit->text());
1070
1194
        switch(typeCombo->currentItem()) {
1071
1195
                case 1: {security->setType(SECURITY_TYPE_BOND); break;}
1072
1196
                case 2: {security->setType(SECURITY_TYPE_STOCK); break;}
 
1197
                case 3: {security->setType(SECURITY_TYPE_OTHER); break;}
1073
1198
                default: {security->setType(SECURITY_TYPE_MUTUAL_FUND); break;}
1074
1199
        }
1075
1200
        return true;
1079
1204
        quotationEdit->hide();
1080
1205
        quotationDateEdit->hide();
1081
1206
        quotationLabel->hide();
 
1207
        quotationDateLabel->hide();
1082
1208
        descriptionEdit->setText(security->description());
1083
1209
        decimalsEdit->setValue(security->decimals());
1084
1210
        decimalsChanged(security->decimals());
1092
1218
        switch(security->type()) {
1093
1219
                case SECURITY_TYPE_BOND: {typeCombo->setCurrentItem(1); break;}
1094
1220
                case SECURITY_TYPE_STOCK: {typeCombo->setCurrentItem(2); break;}
 
1221
                case SECURITY_TYPE_OTHER: {typeCombo->setCurrentItem(3); break;}
1095
1222
                default: {typeCombo->setCurrentItem(0); break;}
1096
1223
        }
1097
1224
}
1127
1254
        descriptionEdit = new KTextEdit(mainWidget());
1128
1255
        grid->addMultiCellWidget(descriptionEdit, 5, 5, 0, 1);
1129
1256
        nameEdit->setFocus();
1130
 
 
 
1257
        current_account = NULL;
1131
1258
        connect(typeCombo, SIGNAL(activated(int)), this, SLOT(typeActivated(int)));
1132
1259
 
1133
1260
}
1165
1292
        }
1166
1293
}
1167
1294
void EditAssetsAccountDialog::setAccount(AssetsAccount *account) {
 
1295
        current_account = account;
1168
1296
        nameEdit->setText(account->name());
1169
1297
        valueEdit->setValue(account->initialBalance());
1170
1298
        descriptionEdit->setText(account->description());
1179
1307
        }
1180
1308
        typeActivated(typeCombo->currentItem());
1181
1309
}
1182
 
 
 
1310
void EditAssetsAccountDialog::slotOk() {
 
1311
        QString sname = nameEdit->text().stripWhiteSpace();
 
1312
        if(sname.isEmpty()) {
 
1313
                nameEdit->setFocus();
 
1314
                KMessageBox::error(this, i18n("Empty name."));
 
1315
                return;
 
1316
        }
 
1317
        AssetsAccount *aaccount = budget->findAssetsAccount(sname);
 
1318
        if(aaccount && aaccount != current_account) {
 
1319
                nameEdit->setFocus();
 
1320
                KMessageBox::error(this, i18n("The entered name is used by another account."));
 
1321
                return;
 
1322
        }
 
1323
        KDialogBase::slotOk();
 
1324
}
1183
1325
 
1184
1326
 
1185
1327
EditIncomesAccountDialog::EditIncomesAccountDialog(Budget *budg, QWidget *parent, QString title) : KDialogBase(parent, 0, true, title, Ok | Cancel, Ok, true), budget(budg) {
1203
1345
        descriptionEdit = new KTextEdit(mainWidget());
1204
1346
        grid->addMultiCellWidget(descriptionEdit, 3, 3, 0, 1);
1205
1347
        nameEdit->setFocus();
 
1348
        current_account = NULL;
1206
1349
        connect(budgetButton, SIGNAL(toggled(bool)), this, SLOT(budgetEnabled(bool)));
1207
1350
}
1208
1351
IncomesAccount *EditIncomesAccountDialog::newAccount() {
1218
1361
        account->setDescription(descriptionEdit->text());
1219
1362
}
1220
1363
void EditIncomesAccountDialog::setAccount(IncomesAccount *account) {
 
1364
        current_account = account;
1221
1365
        nameEdit->setText(account->name());
1222
1366
        budgetEdit->hide();
1223
1367
        budgetButton->hide();
1226
1370
void EditIncomesAccountDialog::budgetEnabled(bool b) {
1227
1371
        budgetEdit->setEnabled(b);
1228
1372
}
 
1373
void EditIncomesAccountDialog::slotOk() {
 
1374
        QString sname = nameEdit->text().stripWhiteSpace();
 
1375
        if(sname.isEmpty()) {
 
1376
                nameEdit->setFocus();
 
1377
                KMessageBox::error(this, i18n("Empty name."));
 
1378
                return;
 
1379
        }
 
1380
        IncomesAccount *iaccount = budget->findIncomesAccount(sname);
 
1381
        if(iaccount && iaccount != current_account) {
 
1382
                nameEdit->setFocus();
 
1383
                KMessageBox::error(this, i18n("The entered name is used by another income category."));
 
1384
                return;
 
1385
        }
 
1386
        KDialogBase::slotOk();
 
1387
}
1229
1388
 
1230
1389
EditExpensesAccountDialog::EditExpensesAccountDialog(Budget *budg, QWidget *parent, QString title) : KDialogBase(parent, 0, true, title, Ok | Cancel, Ok, true), budget(budg) {
1231
1390
        setMainWidget(new QWidget(this));
1248
1407
        descriptionEdit = new KTextEdit(mainWidget());
1249
1408
        grid->addMultiCellWidget(descriptionEdit, 3, 3, 0, 1);
1250
1409
        nameEdit->setFocus();
 
1410
        current_account = NULL;
1251
1411
        connect(budgetButton, SIGNAL(toggled(bool)), this, SLOT(budgetEnabled(bool)));
1252
1412
}
1253
1413
ExpensesAccount *EditExpensesAccountDialog::newAccount() {
1263
1423
        account->setDescription(descriptionEdit->text());
1264
1424
}
1265
1425
void EditExpensesAccountDialog::setAccount(ExpensesAccount *account) {
 
1426
        current_account = account;
1266
1427
        nameEdit->setText(account->name());
1267
1428
        budgetEdit->hide();
1268
1429
        budgetButton->hide();
1271
1432
void EditExpensesAccountDialog::budgetEnabled(bool b) {
1272
1433
        budgetEdit->setEnabled(b);
1273
1434
}
 
1435
void EditExpensesAccountDialog::slotOk() {
 
1436
        QString sname = nameEdit->text().stripWhiteSpace();
 
1437
        if(sname.isEmpty()) {
 
1438
                nameEdit->setFocus();
 
1439
                KMessageBox::error(this, i18n("Empty name."));
 
1440
                return;
 
1441
        }
 
1442
        ExpensesAccount *eaccount = budget->findExpensesAccount(sname);
 
1443
        if(eaccount && eaccount != current_account) {
 
1444
                nameEdit->setFocus();
 
1445
                KMessageBox::error(this, i18n("The entered name is used by another expense category."));
 
1446
                return;
 
1447
        }
 
1448
        KDialogBase::slotOk();
 
1449
}
1274
1450
 
1275
1451
#define CHANGE_COLUMN                           2
1276
1452
#define BUDGET_COLUMN                           1
1326
1502
        expenses_accounts_change = 0.0;
1327
1503
        assets_accounts_value = 0.0;
1328
1504
        assets_accounts_change = 0.0;
1329
 
        period_months = 0.0;
1330
1505
        total_value = 0.0;
1331
1506
        total_cost = 0.0;
1332
1507
        total_profit = 0.0;
1335
1510
        partial_budget = false;
1336
1511
 
1337
1512
        modified = false;
 
1513
        modified_auto_save = false;
1338
1514
 
1339
1515
        budget = new Budget();
1340
1516
 
1345
1521
        
1346
1522
        setAcceptDrops(true);
1347
1523
 
 
1524
        prev_cur_date = QDate::currentDate();
 
1525
 
1348
1526
        QWidget *w_top = new QWidget(this);
1349
1527
        setCentralWidget(w_top);
1350
1528
 
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);
1417
1597
        accountsPeriodFromButton->setChecked(true);
1418
1598
        accountsPeriodLayout2->addWidget(accountsPeriodFromButton);
1419
1599
        accountsPeriodFromEdit = new KDateEdit(periodWidget);
1420
 
        QDate curdate = QDate::currentDate();
 
1600
        QDate curdate = prev_cur_date;
1421
1601
        calSys->setYMD(from_date, calSys->year(curdate), calSys->month(curdate), 1);
1422
1602
        frommonth_begin = from_date;
1423
1603
        prevmonth_begin = addMonths(frommonth_begin, -1);
1429
1609
        accountsPeriodLayout2->addWidget(accountsPeriodFromEdit);
1430
1610
        accountsPeriodLayout2->addWidget(new QLabel(i18n("To"), periodWidget));
1431
1611
        accountsPeriodToEdit = new KDateEdit(periodWidget);
1432
 
        to_date = QDate::currentDate();
 
1612
        to_date = prev_cur_date;
1433
1613
        accountsPeriodToEdit->setDate(to_date);
1434
1614
        accountsPeriodToEdit->setEnabled(true);
1435
1615
        accountsPeriodToEdit->setSizePolicy(sp);
1712
1892
        QTimer *scheduleTimer = new QTimer();
1713
1893
        connect(scheduleTimer, SIGNAL(timeout()), this, SLOT(checkSchedule()));
1714
1894
        scheduleTimer->start(1000 * 60 * 30);
 
1895
 
 
1896
        auto_save_timeout = true;
 
1897
        
 
1898
        QTimer *autoSaveTimer = new QTimer();
 
1899
        connect(autoSaveTimer, SIGNAL(timeout()), this, SLOT(onAutoSaveTimeout()));
 
1900
        autoSaveTimer->start(1000 * 60 * 1);
 
1901
 
 
1902
        QTimer *dateTimer = new QTimer();
 
1903
        connect(dateTimer, SIGNAL(timeout()), this, SLOT(checkDate()));
 
1904
        dateTimer->start(1000 * 60);
1715
1905
        
1716
1906
        current_page = tabs->activePageIndex();
1717
1907
#if KDE_VERSION_MAJOR < 4 && KDE_VERSION_MINOR < 4
1751
1941
        
1752
1942
}
1753
1943
 
 
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);
 
1951
                }
 
1952
                if(securities_to_date == prev_cur_date_bak) {
 
1953
                        securitiesPeriodToEdit->setDate(prev_cur_date);
 
1954
                        securitiesPeriodToChanged(prev_cur_date);
 
1955
                }
 
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);
 
1959
        }
 
1960
}
 
1961
 
1754
1962
void Eqonomize::showExpenses() {
1755
1963
        tabs->showPage(1);
1756
1964
        onPageChange(expenses_page);
1900
2108
                }
1901
2109
        }
1902
2110
        accountsPeriodFromButton->setChecked(true);
 
2111
        accountsPeriodFromEdit->setEnabled(true);
1903
2112
        accountsPeriodFromEdit->setDate(from_date);
1904
2113
        accountsPeriodToEdit->setDate(to_date);
1905
2114
        accountsPeriodFromEdit->blockSignals(false);
1933
2142
                        setModified(true);
1934
2143
                }
1935
2144
        }
1936
 
        delete dialog;
 
2145
        dialog->deleteLater();
1937
2146
}
1938
2147
void Eqonomize::editSecurity(QListViewItem *i) {
1939
2148
        if(!i) return;
1949
2158
                        transfersWidget->filterTransactions();
1950
2159
                }
1951
2160
        }
1952
 
        delete dialog;
 
2161
        dialog->deleteLater();
1953
2162
}
1954
2163
void Eqonomize::editSecurity() {
1955
2164
        QListViewItem *i = securitiesView->selectedItem();
2018
2227
                        updateSecurity(security);
2019
2228
                        updateSecurityAccount(security->account());
2020
2229
                        setModified(true);
2021
 
                        delete dialog;
 
2230
                        dialog->deleteLater();
2022
2231
                        return true;
2023
2232
                }
2024
2233
        }
2025
 
        delete dialog;
 
2234
        dialog->deleteLater();
2026
2235
        return false;
2027
2236
}
2028
2237
void Eqonomize::newReinvestedDividend() {
2039
2248
                        setModified(true);
2040
2249
                }
2041
2250
        }
2042
 
        delete dialog;
 
2251
        dialog->deleteLater();
2043
2252
}
2044
2253
void Eqonomize::editSecurityTrade(SecurityTrade *ts) {
2045
2254
        editSecurityTrade(ts, this);
2064
2273
                        }
2065
2274
                        setModified(true);
2066
2275
                        delete ts;
2067
 
                        delete dialog;
 
2276
                        dialog->deleteLater();
2068
2277
                        return true;
2069
2278
                }
2070
2279
        }
2071
 
        delete dialog;
 
2280
        dialog->deleteLater();
2072
2281
        return false;
2073
2282
}
2074
2283
void Eqonomize::newSecurityTrade() {
2089
2298
                        setModified(true);
2090
2299
                }
2091
2300
        }
2092
 
        delete dialog;
 
2301
        dialog->deleteLater();
2093
2302
}
2094
2303
void Eqonomize::setQuotation() {
2095
2304
        SecurityListViewItem *i = (SecurityListViewItem*) securitiesView->selectedItem();
2114
2323
                if(!date.isValid()) {
2115
2324
                        KMessageBox::error(this, i18n("Invalid date."));
2116
2325
                } else if(date > QDate::currentDate()) {
2117
 
                        KMessageBox::error(this, i18n("Future dates is not allowed."));
 
2326
                        KMessageBox::error(this, i18n("Future dates are not allowed."));
2118
2327
                } else {
2119
2328
                        i->security()->setQuotation(date, quotationEdit->value());
2120
2329
                        updateSecurity(i);
2123
2332
                        break;
2124
2333
                }
2125
2334
        }
2126
 
        delete dialog;
 
2335
        dialog->deleteLater();
2127
2336
}
2128
2337
void Eqonomize::editQuotations() {
2129
2338
        SecurityListViewItem *i = (SecurityListViewItem*) securitiesView->selectedItem();
2137
2346
                updateSecurityAccount(security->account());
2138
2347
                setModified(true);
2139
2348
        }
2140
 
        delete dialog;
 
2349
        dialog->deleteLater();
2141
2350
}
2142
2351
void Eqonomize::editSecurityTransactions() {
2143
2352
        SecurityListViewItem *i = (SecurityListViewItem*) securitiesView->selectedItem();
2144
2353
        if(!i) return;
2145
2354
        SecurityTransactionsDialog *dialog = new SecurityTransactionsDialog(i->security(), this, i18n("Security Transactions"));
2146
2355
        dialog->exec();
2147
 
        delete dialog;
 
2356
        dialog->deleteLater();
2148
2357
}
2149
2358
void Eqonomize::securitiesSelectionChanged() {
2150
2359
        SecurityListViewItem *i = (SecurityListViewItem*) securitiesView->selectedItem();
2206
2415
        i->profit = profit;
2207
2416
        switch(security->type()) {
2208
2417
                case SECURITY_TYPE_BOND: {i->setText(7, i18n("Bond")); break;}
2209
 
                case SECURITY_TYPE_STOCK: {i->setText(7, i18n("Stock")); break;}
 
2418
                case SECURITY_TYPE_STOCK: {i->setText(7, i18n("Stock")); break;}                
2210
2419
                case SECURITY_TYPE_MUTUAL_FUND: {i->setText(7, i18n("Mutual Fund")); break;}
 
2420
                case SECURITY_TYPE_OTHER: {i->setText(7, i18n("Other")); break;}
2211
2421
        }
2212
2422
        total_rate *= total_value;
2213
2423
        total_value += value;
2263
2473
                case SECURITY_TYPE_BOND: {i->setText(7, i18n("Bond")); break;}
2264
2474
                case SECURITY_TYPE_STOCK: {i->setText(7, i18n("Stock")); break;}
2265
2475
                case SECURITY_TYPE_MUTUAL_FUND: {i->setText(7, i18n("Mutual Fund")); break;}
 
2476
                case SECURITY_TYPE_OTHER: {i->setText(7, i18n("Other")); break;}
2266
2477
        }
2267
2478
        i->setText(1, KGlobal::locale()->formatMoney(value));
2268
2479
        i->setText(2, KGlobal::locale()->formatNumber(shares, security->decimals()));
2285
2496
                security = budget->securities.next();
2286
2497
        }
2287
2498
}
2288
 
void Eqonomize::newScheduledTransaction(int transaction_type, Security *security) {
2289
 
        newScheduledTransaction(transaction_type, security, this);
2290
 
}
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);
 
2501
}
 
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();
 
2506
                if(split) {
 
2507
                        budget->addSplitTransaction(split);
 
2508
                        splitTransactionAdded(split);
 
2509
                        dialog->deleteLater();
 
2510
                        return true;
 
2511
                }
 
2512
        }
 
2513
        dialog->deleteLater();
 
2514
        return false;
 
2515
}
 
2516
bool Eqonomize::editSplitTransaction(SplitTransaction *split) {
 
2517
        return editSplitTransaction(split, this);
 
2518
}
 
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();
 
2524
                if(new_split) {
 
2525
                        removeSplitTransaction(split);
 
2526
                        budget->addSplitTransaction(new_split);
 
2527
                        splitTransactionAdded(new_split);
 
2528
                        dialog->deleteLater();
 
2529
                        return true;
 
2530
                }
 
2531
        }
 
2532
        dialog->deleteLater();
 
2533
        return false;
 
2534
}
 
2535
bool Eqonomize::splitUpTransaction(SplitTransaction *split) {
 
2536
        split->clear(true);
 
2537
        budget->removeSplitTransaction(split, true);
 
2538
        splitTransactionRemoved(split);
 
2539
        delete split;
 
2540
        return true;
 
2541
}
 
2542
bool Eqonomize::removeSplitTransaction(SplitTransaction *split) {
 
2543
        budget->removeSplitTransaction(split, true);
 
2544
        splitTransactionRemoved(split);
 
2545
        delete split;
 
2546
        return true;    
 
2547
}
 
2548
bool Eqonomize::newScheduledTransaction(int transaction_type, Security *security) {
 
2549
        return newScheduledTransaction(transaction_type, security, this);
 
2550
}
 
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);
2293
2553
        if(strans) {
2294
2554
                if(!strans->recurrence() && strans->transaction()->date() <= QDate::currentDate()) {
2295
2555
                        Transaction *trans = strans->transaction()->copy();
2301
2561
                        scheduledTransactionAdded(strans);
2302
2562
                        checkSchedule();
2303
2563
                }
 
2564
                return true;
2304
2565
        }
 
2566
        return false;
2305
2567
}
2306
2568
void Eqonomize::newScheduledExpense() {
2307
2569
        newScheduledTransaction(TRANSACTION_TYPE_EXPENSE);
2312
2574
void Eqonomize::newScheduledTransfer() {
2313
2575
        newScheduledTransaction(TRANSACTION_TYPE_TRANSFER);
2314
2576
}
2315
 
void Eqonomize::editScheduledTransaction(ScheduledTransaction *strans) {
2316
 
        editScheduledTransaction(strans, this);
 
2577
bool Eqonomize::editScheduledTransaction(ScheduledTransaction *strans) {
 
2578
        return editScheduledTransaction(strans, this);
2317
2579
}
2318
2580
bool Eqonomize::editScheduledTransaction(ScheduledTransaction *strans, QWidget *parent) {
2319
2581
        ScheduledTransaction *old_strans = strans->copy();
2335
2597
        delete old_strans;
2336
2598
        return false;
2337
2599
}
2338
 
void Eqonomize::editOccurrence(ScheduledTransaction *strans, const QDate &date) {
2339
 
        editOccurrence(strans, date, this);
 
2600
bool Eqonomize::editOccurrence(ScheduledTransaction *strans, const QDate &date) {
 
2601
        return editOccurrence(strans, date, this);
2340
2602
}
2341
2603
bool Eqonomize::editOccurrence(ScheduledTransaction *strans, const QDate &date, QWidget *parent) {
2342
2604
        Security *security = NULL;
2345
2607
        } else if(strans->transaction()->type() == TRANSACTION_TYPE_INCOME && ((Income*) strans->transaction())->security()) {
2346
2608
                security = ((Income*) strans->transaction())->security();
2347
2609
        }
2348
 
        TransactionEditDialog *dialog = new TransactionEditDialog(b_extra, strans->transaction()->type(), security, SECURITY_VALUE_AND_SHARES, budget, parent);
 
2610
        TransactionEditDialog *dialog = new TransactionEditDialog(b_extra, strans->transaction()->type(), false, false, security, SECURITY_ALL_VALUES, budget, parent);
2349
2611
        dialog->editWidget->updateAccounts();
2350
2612
        dialog->editWidget->setScheduledTransaction(strans, date);
2351
2613
        if(dialog->editWidget->checkAccounts() && dialog->exec() == QDialog::Accepted) {
2363
2625
                        strans->addException(date);
2364
2626
                        scheduledTransactionModified(strans, old_strans);
2365
2627
                        delete old_strans;
2366
 
                        delete dialog;
 
2628
                        dialog->deleteLater();
2367
2629
                        return true;
2368
2630
                }
2369
2631
        }
2370
 
        delete dialog;
 
2632
        dialog->deleteLater();
2371
2633
        return false;
2372
2634
}
2373
2635
void Eqonomize::editScheduledTransaction() {
2380
2642
        if(i == NULL) return;
2381
2643
        editOccurrence(i->scheduledTransaction(), i->date());
2382
2644
}
2383
 
void Eqonomize::removeScheduledTransaction(ScheduledTransaction *strans) {
 
2645
bool Eqonomize::removeScheduledTransaction(ScheduledTransaction *strans) {
2384
2646
        budget->removeScheduledTransaction(strans, true);
2385
2647
        scheduledTransactionRemoved(strans);
2386
2648
        delete strans;
 
2649
        return true;
2387
2650
}
2388
2651
void Eqonomize::removeScheduledTransaction() {
2389
2652
        ScheduleListViewItem *i = (ScheduleListViewItem*) scheduleView->selectedItem();
2390
2653
        if(i == NULL) return;
2391
2654
        removeScheduledTransaction(i->scheduledTransaction());
2392
2655
}
2393
 
void Eqonomize::removeOccurrence(ScheduledTransaction *strans, const QDate &date) {
 
2656
bool Eqonomize::removeOccurrence(ScheduledTransaction *strans, const QDate &date) {
2394
2657
        if(strans->isOneTimeTransaction()) {
2395
2658
                removeScheduledTransaction(strans);
2396
2659
        } else {
2399
2662
                scheduledTransactionModified(strans, oldstrans);
2400
2663
                delete oldstrans;
2401
2664
        }
 
2665
        return true;
2402
2666
}
2403
2667
void Eqonomize::removeOccurrence() {
2404
2668
        ScheduleListViewItem *i = (ScheduleListViewItem*) scheduleView->selectedItem();
2448
2712
        if(!w) return;
2449
2713
        w->editScheduledTransaction();
2450
2714
}
2451
 
void Eqonomize::editTransaction(Transaction *trans) {
2452
 
        editTransaction(trans, this);
 
2715
void Eqonomize::editSelectedSplitTransaction() {
 
2716
        TransactionListWidget *w = NULL;
 
2717
        switch(tabs->activePageIndex()) {
 
2718
                case 0: {return;}
 
2719
                case 1: {w = expensesWidget; break;}
 
2720
                case 2: {w = incomesWidget; break;}
 
2721
                case 3: {w = transfersWidget; break;}
 
2722
                case 4: {return;}
 
2723
                case 5: {return;}
 
2724
        }
 
2725
        if(!w) return;
 
2726
        w->editSplitTransaction();
 
2727
}
 
2728
void Eqonomize::joinSelectedTransactions() {
 
2729
        TransactionListWidget *w = NULL;
 
2730
        switch(tabs->activePageIndex()) {
 
2731
                case 0: {return;}
 
2732
                case 1: {w = expensesWidget; break;}
 
2733
                case 2: {w = incomesWidget; break;}
 
2734
                case 3: {w = transfersWidget; break;}
 
2735
                case 4: {return;}
 
2736
                case 5: {return;}
 
2737
        }
 
2738
        if(!w) return;
 
2739
        w->joinTransactions();
 
2740
}
 
2741
void Eqonomize::splitUpSelectedTransaction() {
 
2742
        TransactionListWidget *w = NULL;
 
2743
        switch(tabs->activePageIndex()) {
 
2744
                case 0: {return;}
 
2745
                case 1: {w = expensesWidget; break;}
 
2746
                case 2: {w = incomesWidget; break;}
 
2747
                case 3: {w = transfersWidget; break;}
 
2748
                case 4: {return;}
 
2749
                case 5: {return;}
 
2750
        }
 
2751
        if(!w) return;
 
2752
        w->splitUpTransaction();
 
2753
}
 
2754
bool Eqonomize::editTransaction(Transaction *trans) {
 
2755
        return editTransaction(trans, this);
2453
2756
}
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);
 
2768
                                delete oldtrans;
 
2769
                                return true;
 
2770
                        }
 
2771
                }
 
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);
2460
2776
                } else {
2470
2786
        delete oldtrans;
2471
2787
        return false;
2472
2788
}
 
2789
void Eqonomize::newRefund() {
 
2790
        if(tabs->activePageIndex() == 1) expensesWidget->newRefundRepayment();
 
2791
}
 
2792
void Eqonomize::newRepayment() {
 
2793
        if(tabs->activePageIndex() == 2) incomesWidget->newRefundRepayment();
 
2794
}
 
2795
void Eqonomize::newRefundRepayment() {
 
2796
        if(tabs->activePageIndex() == 1) expensesWidget->newRefundRepayment();
 
2797
        else if(tabs->activePageIndex() == 2) incomesWidget->newRefundRepayment();
 
2798
}
 
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();
 
2804
                if(new_trans) {
 
2805
                        budget->addTransaction(new_trans);
 
2806
                        transactionAdded(new_trans);
 
2807
                        dialog->deleteLater();
 
2808
                        return true;
 
2809
                }
 
2810
        }
 
2811
        dialog->deleteLater();
 
2812
        return false;
 
2813
}
2473
2814
void Eqonomize::editSelectedTransaction() {
2474
2815
        TransactionListWidget *w = NULL;
2475
2816
        switch(tabs->activePageIndex()) {
2496
2837
        if(!w) return;
2497
2838
        w->removeScheduledTransaction();
2498
2839
}
 
2840
void Eqonomize::deleteSelectedSplitTransaction() {
 
2841
        TransactionListWidget *w = NULL;
 
2842
        switch(tabs->activePageIndex()) {
 
2843
                case 0: {return;}
 
2844
                case 1: {w = expensesWidget; break;}
 
2845
                case 2: {w = incomesWidget; break;}
 
2846
                case 3: {w = transfersWidget; break;}
 
2847
                case 4: {return;}
 
2848
                case 5: {return;}
 
2849
        }
 
2850
        if(!w) return;
 
2851
        w->removeSplitTransaction();
 
2852
}
2499
2853
void Eqonomize::deleteSelectedTransaction() {
2500
2854
        TransactionListWidget *w = NULL;
2501
2855
        switch(tabs->activePageIndex()) {
2524
2878
                ActionDeleteAccount->setEnabled(false);
2525
2879
                ActionEditAccount->setEnabled(false);
2526
2880
                ActionBalanceAccount->setEnabled(false);
2527
 
                ActionShowAccountExpenses->setEnabled(false);
2528
 
                ActionShowAccountIncomes->setEnabled(false);
 
2881
                ActionShowAccountTransactions->setEnabled(false);
2529
2882
        }
2530
2883
        if(w == securities_page) {
2531
2884
                securitiesSelectionChanged();
2562
2915
        if(w) {
2563
2916
                w->updateTransactionActions();
2564
2917
        } else {
 
2918
                ActionJoinTransactions->setEnabled(false);
 
2919
                ActionSplitUpTransaction->setEnabled(false);
 
2920
                ActionEditSplitTransaction->setEnabled(false);
 
2921
                ActionDeleteSplitTransaction->setEnabled(false);
2565
2922
                ActionEditTransaction->setEnabled(b_transaction);
2566
2923
                ActionDeleteTransaction->setEnabled(b_transaction);
2567
2924
                ActionEditScheduledTransaction->setEnabled(b_scheduledtransaction);
2568
2925
                ActionDeleteScheduledTransaction->setEnabled(b_scheduledtransaction);
 
2926
                ActionNewRefund->setEnabled(false);
 
2927
                ActionNewRepayment->setEnabled(false);
 
2928
                ActionNewRefundRepayment->setEnabled(false);
2569
2929
        }
2570
2930
}
2571
2931
 
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);
2588
2947
        }
2589
2948
        accountPopupMenu->popup(p);
2590
2949
        
2591
2950
}
2592
2951
 
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) {
2600
 
                                from = account;
2601
 
                        } else if(account->type() == ACCOUNT_TYPE_ASSETS) {
2602
 
                                to = account;
2603
 
                        }
2604
 
                }
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);
2610
 
        }
2611
 
}
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) {
2619
 
                                to = account;
2620
 
                        } else if(account->type() == ACCOUNT_TYPE_ASSETS) {
2621
 
                                from = account;
2622
 
                        }
2623
 
                }
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);
 
2967
        } else {
 
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();
 
2974
                        tabs->showPage(2);
 
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();
 
2980
                        tabs->showPage(1);
 
2981
                        onPageChange(expenses_page);
 
2982
                } else if(((AssetsAccount*) account)->accountType() == ASSETS_TYPE_SECURITIES) {
 
2983
                        tabs->showPage(4);
 
2984
                        onPageChange(securities_page);
 
2985
                } else {
 
2986
                        LedgerDialog *dialog = new LedgerDialog((AssetsAccount*) account, this, i18n("Ledger"), b_extra);
 
2987
                        dialog->show();
 
2988
                }
2629
2989
        }
2630
2990
}
2631
 
 
2632
2991
void Eqonomize::accountsPeriodToChanged(const QDate &date) {
2633
2992
        bool error = false;
2634
2993
        if(!date.isValid()) {
2922
3281
}
2923
3282
 
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;
2931
3293
}
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());
 
3302
#else
 
3303
        config->writeEntry("lastURL", current_url.url());
 
3304
#endif
 
3305
        config->sync();
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));
3001
3371
}
3002
3372
void Eqonomize::openURL(const KURL& url) {
3003
3373
        
 
3374
        if(url != current_url && crashRecovery(KURL(url))) return;
 
3375
                
3004
3376
        QString tmpfile;
3005
3377
        if(!url.isLocalFile()) {
3006
3378
                if(!KIO::NetAccess::download(url, tmpfile, this)) {
3024
3396
        }
3025
3397
        setCaption(url.fileName(), false);
3026
3398
        current_url = url;
 
3399
        ActionFileReload->setEnabled(true);
 
3400
        config->setGroup("General Options");
 
3401
#if KDE_IS_VERSION(3,1,3)
 
3402
        config->writePathEntry("lastURL", current_url.url());
 
3403
#else
 
3404
        config->writeEntry("lastURL", current_url.url());
 
3405
#endif
 
3406
        if(!cr_tmp_file.isEmpty()) {QFile file(cr_tmp_file); file.remove(); cr_tmp_file = "";}
 
3407
        if(current_url.isLocalFile()) cr_tmp_file = kapp->tempSaveName(current_url.path());
 
3408
        config->sync();
3027
3409
        ActionOpenRecent->addURL(url);
3028
3410
 
3029
3411
        reloadBudget();
3040
3422
bool Eqonomize::saveURL(const KURL& url) {
3041
3423
 
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;
3045
 
                }
 
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;
 
3428
                }
 
3429
                if(exists) {
 
3430
                        KURL u(url);
 
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();
 
3437
                        }
 
3438
                        if((!KIO::NetAccess::exists(u, false, this) || KIO::NetAccess::del(u, this))) {
 
3439
                                KIO::NetAccess::file_copy(url, u, perms, true, false, this);
 
3440
                        }
 
3441
                }
 
3442
 
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"));
3050
3447
                } else {
3051
3448
                        setCaption(url.fileName(), false);
3052
3449
                        current_url = url;
 
3450
                        ActionFileReload->setEnabled(true);
 
3451
                        config->setGroup("General Options");
 
3452
#if KDE_IS_VERSION(3,1,3)
 
3453
                        config->writePathEntry("lastURL", current_url.url());
 
3454
#else
 
3455
                        config->writeEntry("lastURL", current_url.url());
 
3456
#endif
 
3457
                        if(!cr_tmp_file.isEmpty()) {QFile file(cr_tmp_file); file.remove();}
 
3458
                        cr_tmp_file = kapp->tempSaveName(current_url.path());
 
3459
                        config->sync();
3053
3460
                        ActionOpenRecent->addURL(url);
3054
3461
                        setModified(false);
3055
3462
                }
3066
3473
        if(KIO::NetAccess::upload(tf.name(), url, this)) {
3067
3474
                setCaption(url.fileName(), false);
3068
3475
                current_url = url;
 
3476
                ActionFileReload->setEnabled(true);
 
3477
                config->setGroup("General Options");
 
3478
#if KDE_IS_VERSION(3,1,3)
 
3479
                config->writePathEntry("lastURL", current_url.url());
 
3480
#else
 
3481
                config->writeEntry("lastURL", current_url.url());
 
3482
#endif
 
3483
                if(!cr_tmp_file.isEmpty()) {QFile file(cr_tmp_file); file.remove(); cr_tmp_file = "";}
 
3484
                config->sync();
3069
3485
                ActionOpenRecent->addURL(url);
3070
3486
                setModified(false);
3071
3487
                return true;
3083
3499
                emit transactionsModified();
3084
3500
                setModified(true);
3085
3501
        }
3086
 
        delete dialog;
 
3502
        dialog->deleteLater();
 
3503
}
 
3504
 
 
3505
void Eqonomize::importQIF() {
 
3506
        if(importQIFFile(budget, this, b_extra)) {
 
3507
                reloadBudget();
 
3508
                emit accountsModified();
 
3509
                emit transactionsModified();
 
3510
                setModified(true);
 
3511
        }
 
3512
}
 
3513
void Eqonomize::exportQIF() {
 
3514
        exportQIFFile(budget, this, b_extra);
3087
3515
}
3088
3516
 
3089
3517
void Eqonomize::showOverTimeReport() {
3151
3579
        CategoriesComparisonChart *chart = new CategoriesComparisonChart(budget, dialog);
3152
3580
        dialog->setMainWidget(chart);
3153
3581
        QDesktopWidget desktop;
3154
 
        QSize default_size = QSize(700, 700).boundedTo(desktop.availableGeometry(this).size());
 
3582
        QSize default_size = QSize(750, 700).boundedTo(desktop.availableGeometry(this).size());
3155
3583
        dialog->setInitialSize(dialog->configDialogSize(*config, "Categories Comparison Chart").expandedTo(default_size));
3156
3584
        dialog->show();
3157
3585
        chart->updateDisplay();
3617
4045
        dialog->setMimeFilter(filter, "text/html");
3618
4046
        dialog->setOperationMode(KFileDialog::Saving);
3619
4047
        dialog->setMode(KFile::File);
3620
 
        if(dialog->exec() != QDialog::Accepted) {delete dialog; return;}
 
4048
        if(dialog->exec() != QDialog::Accepted) {dialog->deleteLater(); return;}
3621
4049
        KURL url = dialog->selectedURL();
3622
4050
        char filetype = 'h';
3623
4051
        if(dialog->currentMimeFilter() == "text/x-csv") filetype = 'c';
3624
 
        delete dialog;
 
4052
        dialog->deleteLater();
3625
4053
        if(url.isEmpty() && url.isValid()) return;
3626
4054
        if(url.isLocalFile()) {
3627
4055
                if(QFile::exists(url.path())) {
3628
 
                        if(KMessageBox::warningYesNo(this, i18n("That file already exists. Would you like to overwrite the old copy?")) != KMessageBox::Yes) return;
 
4056
                        if(KMessageBox::warningYesNo(this, i18n("The selected file already exists. Would you like to overwrite the old copy?")) != KMessageBox::Yes) return;
3629
4057
                }
3630
4058
                QFileInfo info(url.path());
3631
4059
                if(info.isDir()) {
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());
 
4101
 
 
4102
        ActionFileReload = KStdAction::revert(this, SLOT(fileReload()), actionCollection());
3673
4103
 
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..."));
3677
4107
 
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");
3679
4111
 
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");
3687
4119
 
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");
3690
4121
 
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");
 
4134
 
 
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");
3698
4138
 
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)));
3719
 
        
 
4159
 
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);
3740
4187
 
3741
4188
}
3742
4189
 
 
4190
bool Eqonomize::crashRecovery(KURL url) {
 
4191
        config->setGroup("General Options");
 
4192
        bool b = false;
 
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);
 
4197
        }
 
4198
        if(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) {
 
4200
                        QString errors;
 
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"));
 
4204
                                config->sync();
 
4205
                                return false;
 
4206
                        }
 
4207
                        if(!errors.isEmpty()) {
 
4208
                                KMessageBox::error(this, errors);
 
4209
                        }
 
4210
                        current_url = url;
 
4211
                        ActionFileReload->setEnabled(true);
 
4212
                        setCaption(current_url.fileName(), false);
 
4213
                        QFile file(cr_tmp_file); file.remove();
 
4214
 
 
4215
                        reloadBudget();
 
4216
 
 
4217
                        emit accountsModified();
 
4218
                        emit transactionsModified();
 
4219
                        emit budgetUpdated();
 
4220
        
 
4221
                        setModified(true);
 
4222
                        checkSchedule(true);
 
4223
 
 
4224
                        return true;
 
4225
                                        
 
4226
                }
 
4227
                QFile file(cr_tmp_file); file.remove();
 
4228
        } else {
 
4229
                cr_tmp_file = "";
 
4230
        }
 
4231
 
 
4232
        return false;
 
4233
        
 
4234
}
 
4235
void Eqonomize::onAutoSaveTimeout() {
 
4236
        auto_save_timeout = true;
 
4237
        if(modified_auto_save) {
 
4238
                autoSave();
 
4239
        }
 
4240
}
 
4241
void Eqonomize::autoSave() {
 
4242
        if(auto_save_timeout) {
 
4243
                saveCrashRecovery();
 
4244
                modified_auto_save = false;
 
4245
                auto_save_timeout = false;
 
4246
        }
 
4247
}
 
4248
void Eqonomize::saveCrashRecovery() {
 
4249
        if(cr_tmp_file.isEmpty() && current_url.isEmpty()) {
 
4250
                cr_tmp_file = kapp->tempSaveName("/UNSAVED EQZ");
 
4251
        }
 
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());
 
4256
#else
 
4257
                config->writeEntry("lastURL", current_url.url());
 
4258
#endif
 
4259
                config->sync();
 
4260
        }
 
4261
}
 
4262
 
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());
3773
4292
        config->setGroup("General Options");
3774
4293
        ActionOpenRecent->loadEntries(config);
3775
4294
        first_run = config->readBoolEntry("firstRun", true);
 
4295
        config->writeEntry("firstRun", false);
3776
4296
}
3777
4297
 
3778
4298
void Eqonomize::saveProperties(KConfig*) {
3781
4301
}
3782
4302
 
3783
4303
bool Eqonomize::queryClose() {
3784
 
        return askSave();
 
4304
        return askSave(true);
3785
4305
}
3786
4306
bool Eqonomize::queryExit() {
3787
4307
        saveOptions();
3807
4327
        reloadBudget();
3808
4328
        setCaption(QString::null, false);
3809
4329
        current_url = "";
 
4330
        ActionFileReload->setEnabled(false);
 
4331
#if KDE_IS_VERSION(3,1,3)
 
4332
        config->writePathEntry("lastURL", current_url.url());
 
4333
#else
 
4334
        config->writeEntry("lastURL", current_url.url());
 
4335
#endif
 
4336
        if(!cr_tmp_file.isEmpty()) {QFile file(cr_tmp_file); file.remove(); cr_tmp_file = "";}
 
4337
        cr_tmp_file = kapp->tempSaveName("/UNSAVED EQZ");
 
4338
        config->sync();
3810
4339
        setModified(false);
3811
4340
        emit accountsModified();
3812
4341
        emit transactionsModified();
3823
4352
        openURL(url);
3824
4353
}
3825
4354
 
 
4355
void Eqonomize::fileReload() {
 
4356
        openURL(current_url);
 
4357
}
3826
4358
void Eqonomize::fileSave() {
3827
4359
        if(!current_url.isValid()) {
3828
 
                KURL file_url = KFileDialog::getSaveURL(QString::null, "application/x-eqonomize", this);
 
4360
                KURL file_url = KFileDialog::getSaveURL("budget", "application/x-eqonomize", this);
3829
4361
                if (!file_url.isEmpty() && file_url.isValid()) {
3830
4362
                        saveURL(file_url);
3831
4363
                }
3841
4373
        }
3842
4374
}
3843
4375
 
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?"));
 
4378
        int b_save = 0;
 
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);
3852
4386
                        } else {
3856
4390
                        return saveURL(current_url);
3857
4391
                }
3858
4392
        }
3859
 
        return b_save == KMessageBox::No;
 
4393
        if(b_save == KMessageBox::No) {
 
4394
                if(!cr_tmp_file.isEmpty()) {QFile file(cr_tmp_file); file.remove(); cr_tmp_file = "";}
 
4395
                return true;
 
4396
        }
 
4397
        return false;
3860
4398
}
3861
4399
 
3862
4400
void Eqonomize::optionsPreferences() {
3878
4416
                                budget->addTransaction(trans);
3879
4417
                                trans = dialog->nextTransaction();
3880
4418
                        }
3881
 
                        delete dialog;
 
4419
                        dialog->deleteLater();
3882
4420
                        break;
3883
4421
                }
3884
4422
                strans = budget->scheduledTransactions.next();
3944
4482
                emit accountsModified();
3945
4483
                setModified(true);
3946
4484
        }
3947
 
        delete dialog;
 
4485
        dialog->deleteLater();
3948
4486
}
3949
4487
void Eqonomize::newIncomesAccount() {
3950
 
        EditIncomesAccountDialog *dialog = new EditIncomesAccountDialog(budget, this, i18n("New Incomes Category"));
 
4488
        EditIncomesAccountDialog *dialog = new EditIncomesAccountDialog(budget, this, i18n("New Income Category"));
3951
4489
        if(dialog->exec() == QDialog::Accepted) {
3952
4490
                IncomesAccount *account = dialog->newAccount();
3953
4491
                budget->addAccount(account);
3957
4495
                emit accountsModified();
3958
4496
                setModified(true);
3959
4497
        }
3960
 
        delete dialog;
 
4498
        dialog->deleteLater();
3961
4499
}
3962
4500
void Eqonomize::newExpensesAccount() {
3963
 
        EditExpensesAccountDialog *dialog = new EditExpensesAccountDialog(budget, this, i18n("New Expenses Category"));
 
4501
        EditExpensesAccountDialog *dialog = new EditExpensesAccountDialog(budget, this, i18n("New Expense Category"));
3964
4502
        if(dialog->exec() == QDialog::Accepted) {
3965
4503
                ExpensesAccount *account = dialog->newAccount();
3966
4504
                budget->addAccount(account);
3970
4508
                emit accountsModified();
3971
4509
                setModified(true);
3972
4510
        }
3973
 
        delete dialog;
 
4511
        dialog->deleteLater();
3974
4512
}
3975
 
void Eqonomize::accountExecuted(QListViewItem *i) {
3976
 
        if(i == NULL) return;
3977
 
        if(i == incomesItem || (account_items.contains(i) && account_items[i]->type() == ACCOUNT_TYPE_INCOMES)) {
3978
 
                showAccountIncomes();
3979
 
        } else {
3980
 
                showAccountExpenses();
3981
 
        }
 
4513
void Eqonomize::accountExecuted(QListViewItem*) {
 
4514
        showAccountTransactions();
3982
4515
}
3983
4516
void Eqonomize::accountExecuted(QListViewItem *i, const QPoint&, int c) {
3984
4517
        if(i == NULL) return;
3990
4523
                        break;
3991
4524
                }
3992
4525
                case 1: {
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();
3998
4529
                                } else {
3999
 
                                        budgetButton->setFocus();
 
4530
                                        accountsTabs->setCurrentPage(1);
 
4531
                                        if(budgetEdit->isEnabled()) {
 
4532
                                                budgetEdit->setFocus();
 
4533
                                                budgetEdit->lineEdit()->selectAll();
 
4534
                                        } else {
 
4535
                                                budgetButton->setFocus();
 
4536
                                        }
4000
4537
                                }
4001
4538
                        }
4002
4539
                        break;
4003
4540
                }
4004
4541
                case 2: {
4005
 
                        if(i == incomesItem || (account_items.contains(i) && account_items[i]->type() == ACCOUNT_TYPE_INCOMES)) {
4006
 
                                showAccountIncomes();
4007
 
                        } else {
4008
 
                                showAccountExpenses();
4009
 
                        }
 
4542
                        showAccountTransactions();
4010
4543
                        break;
4011
4544
                }
4012
4545
                case 3: {
4013
 
                        if(i == incomesItem || (account_items.contains(i) && account_items[i]->type() == ACCOUNT_TYPE_INCOMES)) {
4014
 
                                showAccountIncomes(true);
4015
 
                        } else {
4016
 
                                showAccountExpenses(true);
4017
 
                        }
 
4546
                        showAccountTransactions(true);
4018
4547
                        break;
4019
4548
                }
4020
4549
        }
4026
4555
        balanceAccount(i_account);
4027
4556
}
4028
4557
void Eqonomize::balanceAccount(Account *i_account) {
 
4558
        if(!i_account) return;
4029
4559
        if(i_account->type() != ACCOUNT_TYPE_ASSETS || ((AssetsAccount*) i_account)->accountType() == ASSETS_TYPE_SECURITIES) return;
4030
4560
        AssetsAccount *account = (AssetsAccount*) i_account;
4031
4561
        double book_value = account->initialBalance();
4032
4562
        double current_balancing = 0.0;
4033
 
        Transaction *trans = budget->expenses.first();
4034
 
        int ti = 0;
 
4563
        Transaction *trans = budget->transactions.first();
4035
4564
        while(trans) {
4036
4565
                if(trans->fromAccount() == account) {
4037
4566
                        book_value -= trans->value();
4041
4570
                        book_value += trans->value();
4042
4571
                        if(trans->fromAccount() == budget->balancingAccount) current_balancing += trans->value();
4043
4572
                }
4044
 
                if(ti == 0) {trans = budget->expenses.next(); if(!trans) {ti++; trans = budget->incomes.first();}}
4045
 
                else if(ti == 1) {trans = budget->incomes.next(); if(!trans) {ti++; trans = budget->transfers.first();}}
4046
 
                else {trans = budget->transfers.next();}
 
4573
                trans = budget->transactions.next();
4047
4574
        }
4048
4575
        KDialogBase *dialog = new KDialogBase(this, 0, true, i18n("Balance Account"), KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, true);
4049
4576
        dialog->setMainWidget(new QWidget(dialog));
4063
4590
                realEdit->setSuffix(QString(" ") + KGlobal::locale()->currencySymbol());
4064
4591
        }
4065
4592
        grid->addWidget(realEdit, 2, 1);
4066
 
        if(dialog->exec() == QDialog::Accepted) {
 
4593
        if(dialog->exec() == QDialog::Accepted && realEdit->value() != book_value) {
4067
4594
                trans = new Balancing(budget, realEdit->value() - book_value, QDate::currentDate(), account);
4068
4595
                budget->addTransaction(trans);
4069
4596
                transactionAdded(trans);
4070
4597
        }
4071
 
        delete dialog;
 
4598
        dialog->deleteLater();
4072
4599
}
4073
4600
void Eqonomize::editAccount() {
4074
4601
        QListViewItem *i = accountsView->selectedItem();
4076
4603
        Account *i_account = account_items[i];
4077
4604
        editAccount(i_account);
4078
4605
}
4079
 
void Eqonomize::editAccount(Account *i_account) {
 
4606
bool Eqonomize::editAccount(Account *i_account) {
 
4607
        return editAccount(i_account, this);
 
4608
}
 
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();
4106
4636
                                expensesWidget->filterTransactions();
4107
4637
                                incomesWidget->filterTransactions();
4108
4638
                                transfersWidget->filterTransactions();
 
4639
                                dialog->deleteLater();
 
4640
                                return true;
4109
4641
                        }
4110
 
                        delete dialog;
 
4642
                        dialog->deleteLater();
4111
4643
                        break;
4112
4644
                }
4113
4645
                case ACCOUNT_TYPE_INCOMES: {
4114
 
                        EditIncomesAccountDialog *dialog = new EditIncomesAccountDialog(budget, this, i18n("Edit Incomes Category"));
 
4646
                        EditIncomesAccountDialog *dialog = new EditIncomesAccountDialog(budget, parent, i18n("Edit Income Category"));
4115
4647
                        IncomesAccount *account = (IncomesAccount*) i_account;
4116
4648
                        dialog->setAccount(account);
4117
4649
                        if(dialog->exec() == QDialog::Accepted) {
4122
4654
                                incomesWidget->updateFromAccounts();
4123
4655
                                incomesItem->sortChildItems(0, true);
4124
4656
                                incomesWidget->filterTransactions();
 
4657
                                dialog->deleteLater();
 
4658
                                return true;
4125
4659
                        }
4126
 
                        delete dialog;
 
4660
                        dialog->deleteLater();
4127
4661
                        break;
4128
4662
                }
4129
4663
                case ACCOUNT_TYPE_EXPENSES: {
4130
 
                        EditExpensesAccountDialog *dialog = new EditExpensesAccountDialog(budget, this, i18n("Edit Expenses Category"));
 
4664
                        EditExpensesAccountDialog *dialog = new EditExpensesAccountDialog(budget, parent, i18n("Edit Expense Category"));
4131
4665
                        ExpensesAccount *account = (ExpensesAccount*) i_account;
4132
4666
                        dialog->setAccount(account);
4133
4667
                        if(dialog->exec() == QDialog::Accepted) {
4138
4672
                                expensesWidget->updateToAccounts();
4139
4673
                                expensesItem->sortChildItems(0, true);
4140
4674
                                expensesWidget->filterTransactions();
 
4675
                                dialog->deleteLater();
 
4676
                                return true;
4141
4677
                        }
4142
 
                        delete dialog;
 
4678
                        dialog->deleteLater();
4143
4679
                        break;
4144
4680
                }
4145
4681
        }
 
4682
        return false;
4146
4683
}
4147
4684
void Eqonomize::deleteAccount() {
4148
4685
        QListViewItem *i = accountsView->selectedItem();
4152
4689
                item_accounts.remove(account);
4153
4690
                account_items.remove(i);
4154
4691
                delete i;
4155
 
                if(account->type() == ACCOUNT_TYPE_ASSETS) account_change.remove(account);
 
4692
                account_change.remove(account);
4156
4693
                account_value.remove(account);
4157
4694
                budget->removeAccount(account);
4158
4695
                expensesWidget->updateAccounts();
4172
4709
                        case ACCOUNT_TYPE_EXPENSES: {accounts_left = budget->expensesAccounts.count() > 1; break;}
4173
4710
                        case ACCOUNT_TYPE_INCOMES: {accounts_left = budget->incomesAccounts.count() > 1; break;}
4174
4711
                        case ACCOUNT_TYPE_ASSETS: {
4175
 
                                if(((AssetsAccount*) account)->accountType() == ASSETS_TYPE_SECURITIES) {
4176
 
                                        AssetsAccount *aaccount = budget->assetsAccounts.first();
4177
 
                                        while(aaccount) {
4178
 
                                                if(aaccount != account && aaccount->accountType() == ASSETS_TYPE_SECURITIES) {
4179
 
                                                        accounts_left = true;
4180
 
                                                        break;
4181
 
                                                }
4182
 
                                                aaccount = budget->assetsAccounts.next();
 
4712
                                AssetsAccount *aaccount = budget->assetsAccounts.first();
 
4713
                                while(aaccount) {
 
4714
                                        if(aaccount != budget->balancingAccount && aaccount != account && ((((AssetsAccount*) account)->accountType() == ASSETS_TYPE_SECURITIES) == (aaccount->accountType() == ASSETS_TYPE_SECURITIES))) {
 
4715
                                                accounts_left = true;
 
4716
                                                break;
4183
4717
                                        }
4184
 
                                } else {
4185
 
                                        accounts_left = budget->assetsAccounts.count() > 2;
 
4718
                                        aaccount = budget->assetsAccounts.next();
4186
4719
                                }
4187
4720
                                break;
4188
4721
                        }
4202
4735
                        moveToCombo->setEditable(false);
4203
4736
                        switch(account->type()) {
4204
4737
                                case ACCOUNT_TYPE_EXPENSES: {
4205
 
                                        label = new QLabel(i18n("The category contains some expenses. What do you want to do with them?"), dialog->mainWidget());
 
4738
                                        label = new QLabel(i18n("The category contains some expenses.\nWhat do you want to do with them?"), dialog->mainWidget());
4206
4739
                                        ExpensesAccount *eaccount = budget->expensesAccounts.first();
4207
4740
                                        while(eaccount) {
4208
4741
                                                if(eaccount != account) {
4214
4747
                                        break;
4215
4748
                                }
4216
4749
                                case ACCOUNT_TYPE_INCOMES: {
4217
 
                                        label = new QLabel(i18n("The category contains some incomes. What do you want to do with them?"), dialog->mainWidget());
 
4750
                                        label = new QLabel(i18n("The category contains some incomes.\nWhat do you want to do with them?"), dialog->mainWidget());
4218
4751
                                        IncomesAccount *iaccount = budget->incomesAccounts.first();
4219
4752
                                        while(iaccount) {
4220
4753
                                                if(iaccount != account) {
4226
4759
                                        break;
4227
4760
                                }
4228
4761
                                case ACCOUNT_TYPE_ASSETS: {
4229
 
                                        label = new QLabel(i18n("The account contains some transactions. What do you want to do with them?"), dialog->mainWidget());
 
4762
                                        label = new QLabel(i18n("The account contains some transactions.\nWhat do you want to do with them?"), dialog->mainWidget());
4230
4763
                                        AssetsAccount *aaccount = budget->assetsAccounts.first();
4231
4764
                                        while(aaccount) {
4232
 
                                                if(aaccount != budget->balancingAccount && aaccount != account && (((AssetsAccount*) account)->accountType() != ASSETS_TYPE_SECURITIES || aaccount->accountType() == ASSETS_TYPE_SECURITIES)) {
 
4765
                                                if(aaccount != budget->balancingAccount && aaccount != account && ((((AssetsAccount*) account)->accountType() == ASSETS_TYPE_SECURITIES) == (aaccount->accountType() == ASSETS_TYPE_SECURITIES))) {
4233
4766
                                                        moveToCombo->insertItem(aaccount->name());
4234
4767
                                                        moveto_accounts.push_back(aaccount);
4235
4768
                                                }
4260
4793
                        item_accounts.remove(account);
4261
4794
                        account_items.remove(i);
4262
4795
                        delete i;
4263
 
                        if(account->type() == ACCOUNT_TYPE_ASSETS) account_change.remove(account);
 
4796
                        account_change.remove(account);
4264
4797
                        account_value.remove(account);
4265
4798
                        AccountType type = account->type();
4266
4799
                        budget->removeAccount(account);
4267
4800
                        filterAccounts();
 
4801
                        updateSecurities();
4268
4802
                        updateScheduledTransactions();
4269
4803
                        switch(type) {
4270
4804
                                case ACCOUNT_TYPE_EXPENSES: {expensesWidget->filterTransactions(); break;}
4271
4805
                                case ACCOUNT_TYPE_INCOMES: {incomesWidget->filterTransactions(); break;}
4272
 
                                case ACCOUNT_TYPE_ASSETS: {transfersWidget->filterTransactions(); break;}
 
4806
                                case ACCOUNT_TYPE_ASSETS: {incomesWidget->filterTransactions(); expensesWidget->filterTransactions(); transfersWidget->filterTransactions(); break;}
4273
4807
                        }
4274
4808
                        expensesWidget->updateAccounts();
4275
4809
                        transfersWidget->updateAccounts();
4278
4812
                        emit transactionsModified();
4279
4813
                        setModified(true);
4280
4814
                }
4281
 
                moveto_accounts.clear();                
4282
 
                if(dialog) delete dialog;
 
4815
                if(dialog) dialog->deleteLater();
4283
4816
                if(group) delete group;
4284
4817
        }
4285
4818
}
4400
4933
                updateSecurity(((Income*) strans->transaction())->security());
4401
4934
        }
4402
4935
}
 
4936
void Eqonomize::splitTransactionAdded(SplitTransaction *split) {
 
4937
        blockSignals(true);
 
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]);
 
4941
        }
 
4942
        blockSignals(false);
 
4943
        emit transactionsModified();
 
4944
}
 
4945
void Eqonomize::splitTransactionRemoved(SplitTransaction *split) {
 
4946
        blockSignals(true);
 
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]);
 
4950
        }
 
4951
        blockSignals(false);
 
4952
        emit transactionsModified();
 
4953
}
4403
4954
 
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()) + " ");
4593
5144
                                break;
4594
5145
                        }
4595
5146
                        balfrom = (trans->fromAccount() == budget->balancingAccount);
4596
 
                        if(!balfrom) account_value[trans->fromAccount()] -= value;
4597
 
                        assets_accounts_value -= value;
4598
 
                        if(!b_filter) {
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()));
 
5147
                        if(!balfrom) {
 
5148
                                account_value[trans->fromAccount()] -= value;
 
5149
                                assets_accounts_value -= value;
 
5150
                                if(!b_filter) {
 
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()));
 
5156
                                        }
4604
5157
                                }
 
5158
                                if(update_value_display) assetsItem->setText(VALUE_COLUMN, KGlobal::locale()->formatNumber(assets_accounts_value, KGlobal::locale()->fracDigits()) + " ");
4605
5159
                        }
4606
 
                        if(update_value_display) assetsItem->setText(VALUE_COLUMN, KGlobal::locale()->formatNumber(assets_accounts_value, KGlobal::locale()->fracDigits()) + " ");
4607
5160
                        break;
4608
5161
                }
4609
5162
        }
4702
5255
                                break;
4703
5256
                        }
4704
5257
                        balto = (trans->toAccount() == budget->balancingAccount);
4705
 
                        if(!balto) account_value[trans->toAccount()] += value;
4706
 
                        assets_accounts_value += value;
4707
 
                        if(!b_filter) {
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()));
 
5258
                        if(!balto) {
 
5259
                                account_value[trans->toAccount()] += value;
 
5260
                                assets_accounts_value += value;
 
5261
                                if(!b_filter) {
 
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()));
 
5267
                                        }
4713
5268
                                }
 
5269
                                if(update_value_display) assetsItem->setText(VALUE_COLUMN, KGlobal::locale()->formatNumber(assets_accounts_value, KGlobal::locale()->fracDigits()) + " ");
4714
5270
                        }
4715
 
                        if(update_value_display) assetsItem->setText(VALUE_COLUMN, KGlobal::locale()->formatNumber(assets_accounts_value, KGlobal::locale()->fracDigits()) + " ");
4716
5271
                        break;
4717
5272
                }
4718
5273
        }
4719
 
        if(update_value_display) {
 
5274
        if(update_value_display && !b_lastmonth) {
4720
5275
                if(!balfrom) {
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()));
4722
5278
                }
4723
5279
                if(!balto) {
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()));
4725
5282
                }
4726
5283
        }
4727
5284
}
4814
5371
 
4815
5372
                QMap<QDate, double>::const_iterator it_n = it;
4816
5373
                ++it_n;         
4817
 
                monthdate = frommonth;
4818
5374
                bool has_budget = false;
4819
5375
                bool b_firstmonth = !after_from && (monthdate != frommonth);
 
5376
                monthdate = frommonth;
4820
5377
                do {
4821
5378
                        m = it.data();
4822
5379
                        if(m >= 0.0) {                          
5063
5620
                ActionEditAccount->setEnabled(true);
5064
5621
                ActionBalanceAccount->setEnabled(account_items[i]->type() == ACCOUNT_TYPE_ASSETS && ((AssetsAccount*) account_items[i])->accountType() != ASSETS_TYPE_SECURITIES);
5065
5622
        }
5066
 
        ActionShowAccountExpenses->setEnabled(i != NULL && i != incomesItem && (i == expensesItem || i == assetsItem || account_items[i]->type() != ACCOUNT_TYPE_INCOMES));
5067
 
        ActionShowAccountIncomes->setEnabled(i != NULL && i != expensesItem && (i == incomesItem || i == assetsItem || account_items[i]->type() != ACCOUNT_TYPE_EXPENSES));
 
5623
        ActionShowAccountTransactions->setEnabled(i != NULL && i != assetsItem);
5068
5624
        updateBudgetEdit();
5069
5625
}
5070
5626
void Eqonomize::updateSecurityAccount(AssetsAccount *account, bool update_display) {
5105
5661
        incomes_budget_diff = 0.0;
5106
5662
        expenses_budget = 0.0;
5107
5663
        expenses_budget_diff = 0.0;
5108
 
        if(!accountsPeriodFromButton->isChecked()) {
5109
 
                if(budget->transactions.count() == 0) period_months = 0.0;
5110
 
                period_months = monthsBetweenDates(budget->transactions.getFirst()->date(), to_date);
5111
 
        } else {
5112
 
                period_months = monthsBetweenDates(from_date, to_date);
5113
 
        }
5114
5664
        AssetsAccount *aaccount = budget->assetsAccounts.first();
5115
5665
        while(aaccount) {
5116
5666
                if(aaccount->accountType() == ASSETS_TYPE_SECURITIES) {
5172
5722
                }
5173
5723
                eaccount = budget->expensesAccounts.next();
5174
5724
        }
5175
 
        if(b_from && (frommonth_begin.isNull() || frommonth_begin < from_date)) {
5176
 
                calSys->setYMD(frommonth_begin, calSys->year(from_date), calSys->month(from_date), 1);
 
5725
        if(frommonth_begin.isNull() || (b_from && frommonth_begin < from_date)) {
 
5726
                if(b_from) calSys->setYMD(frommonth_begin, calSys->year(from_date), calSys->month(from_date), 1);
 
5727
                else frommonth_begin = curmonth_begin;
5177
5728
        }
5178
5729
        if(frommonth_begin.isNull() || frommonth_begin > prevmonth_begin) {
5179
5730
                monthdate_begin = prevmonth_begin;