1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2019 Maxime DOYEN
4 * This file is part of HomeBank.
6 * HomeBank is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * HomeBank is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "hub-transaction.h"
24 #include "dsp-mainwindow.h"
25 #include "list-operation.h"
27 #include "ui-transaction.h"
30 /****************************************************************************/
32 /****************************************************************************/
41 /* our global datas */
42 extern struct HomeBank
*GLOBALS
;
43 extern struct Preferences
*PREFS
;
46 void ui_hub_transaction_populate(struct hbfile_data
*data
)
48 GList
*lst_acc
, *lnk_acc
;
50 GtkTreeModel
*model1
, *model2
;
53 DB( g_print("\n[ui_hub_txn] populate\n") );
55 model1
= gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_txn
[HUB_TXN_TYPE_FUTURE
]));
56 model2
= gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_txn
[HUB_TXN_TYPE_REMIND
]));
58 gtk_list_store_clear (GTK_LIST_STORE(model1
));
59 gtk_list_store_clear (GTK_LIST_STORE(model2
));
62 lst_acc
= g_hash_table_get_values(GLOBALS
->h_acc
);
63 lnk_acc
= g_list_first(lst_acc
);
64 while (lnk_acc
!= NULL
)
66 Account
*acc
= lnk_acc
->data
;
68 // skip closed in showall mode
69 if( (acc
->flags
& AF_CLOSED
) )
72 lnk_txn
= g_queue_peek_head_link(acc
->txn_queue
);
73 while (lnk_txn
!= NULL
)
75 Transaction
*txn
= lnk_txn
->data
;
77 if(txn
->date
> GLOBALS
->today
)
79 gtk_list_store_insert_with_values(GTK_LIST_STORE(model1
), &iter
, -1,
80 LST_DSPOPE_DATAS
, txn
,
84 if(txn
->status
== TXN_STATUS_REMIND
)
86 gtk_list_store_insert_with_values(GTK_LIST_STORE(model2
), &iter
, -1,
87 LST_DSPOPE_DATAS
, txn
,
90 lnk_txn
= g_list_next(lnk_txn
);
94 lnk_acc
= g_list_next(lnk_acc
);
100 static void ui_hub_transaction_onRowActivated (GtkTreeView
*treeview
,
102 GtkTreeViewColumn
*col
,
105 struct hbfile_data
*data
= userdata
;
106 Transaction
*active_txn
;
110 DB( g_print ("\n[ui_hub_txn] row double-clicked\n") );
112 active_txn
= list_txn_get_active_transaction(treeview
);
115 Transaction
*old_txn
, *new_txn
;
117 old_txn
= da_transaction_clone (active_txn
);
118 new_txn
= active_txn
;
119 result
= deftransaction_external_edit(GTK_WINDOW(data
->window
), old_txn
, new_txn
);
121 if(result
== GTK_RESPONSE_ACCEPT
)
124 GLOBALS
->changes_count
++;
125 ui_hub_transaction_populate(data
);
128 da_transaction_free (old_txn
);
134 GtkWidget
*ui_hub_transaction_create(struct hbfile_data
*data
, HbHubTxnType type
)
136 GtkWidget
*hub
, *vbox
, *sw
, *widget
;
138 DB( g_print("\n[ui_hub_txn] create %d\n", type
) );
140 if( type
> HUB_TXN_TYPE_REMIND
)
143 hub
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
144 gtk_container_set_border_width(GTK_CONTAINER(hub
), SPACING_SMALL
);
146 vbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
147 //gtk_widget_set_margin_top(GTK_WIDGET(vbox), 0);
148 //gtk_widget_set_margin_bottom(GTK_WIDGET(vbox), SPACING_SMALL);
149 //gtk_widget_set_margin_start(GTK_WIDGET(vbox), 2*SPACING_SMALL);
150 //gtk_widget_set_margin_end(GTK_WIDGET(vbox), SPACING_SMALL);
151 gtk_box_pack_start (GTK_BOX (hub
), vbox
, TRUE
, TRUE
, 0);
153 sw
= gtk_scrolled_window_new (NULL
, NULL
);
154 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw
), GTK_SHADOW_ETCHED_IN
);
155 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw
), GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
156 gtk_box_pack_start (GTK_BOX (vbox
), sw
, TRUE
, TRUE
, 0);
158 widget
= (GtkWidget
*)create_list_transaction(LIST_TXN_TYPE_DETAIL
, PREFS
->lst_ope_columns
);
159 list_txn_set_column_acc_visible(GTK_TREE_VIEW(widget
), TRUE
);
160 data
->LV_txn
[type
] = widget
;
161 gtk_container_add (GTK_CONTAINER (sw
), widget
);
163 g_signal_connect (GTK_TREE_VIEW(data
->LV_txn
[type
]), "row-activated", G_CALLBACK (ui_hub_transaction_onRowActivated
), data
);