]> Dogcows Code - chaz/homebank/blob - src/hub-transaction.c
Merge branch 'upstream'
[chaz/homebank] / src / hub-transaction.c
1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2019 Maxime DOYEN
3 *
4 * This file is part of HomeBank.
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
20
21 #include "homebank.h"
22
23 #include "hub-transaction.h"
24 #include "hub-account.h"
25 #include "dsp-mainwindow.h"
26 #include "list-operation.h"
27
28 #include "ui-transaction.h"
29
30
31 /****************************************************************************/
32 /* Debug macros */
33 /****************************************************************************/
34 #define MYDEBUG 0
35
36 #if MYDEBUG
37 #define DB(x) (x);
38 #else
39 #define DB(x);
40 #endif
41
42 /* our global datas */
43 extern struct HomeBank *GLOBALS;
44 extern struct Preferences *PREFS;
45
46
47 void ui_hub_transaction_populate(struct hbfile_data *data)
48 {
49 GList *lst_acc, *lnk_acc;
50 GList *lnk_txn;
51 GtkTreeModel *model1, *model2;
52 GtkTreeIter iter;
53
54 DB( g_print("\n[ui_hub_txn] populate\n") );
55
56 model1 = gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_txn[HUB_TXN_TYPE_FUTURE]));
57 model2 = gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_txn[HUB_TXN_TYPE_REMIND]));
58
59 gtk_list_store_clear (GTK_LIST_STORE(model1));
60 gtk_list_store_clear (GTK_LIST_STORE(model2));
61
62
63 lst_acc = g_hash_table_get_values(GLOBALS->h_acc);
64 lnk_acc = g_list_first(lst_acc);
65 while (lnk_acc != NULL)
66 {
67 Account *acc = lnk_acc->data;
68
69 // skip closed in showall mode
70 if( (acc->flags & AF_CLOSED) )
71 goto next_acc;
72
73 lnk_txn = g_queue_peek_head_link(acc->txn_queue);
74 while (lnk_txn != NULL)
75 {
76 Transaction *txn = lnk_txn->data;
77
78 if(txn->date > GLOBALS->today)
79 {
80 gtk_list_store_insert_with_values(GTK_LIST_STORE(model1), &iter, -1,
81 MODEL_TXN_POINTER, txn,
82 MODEL_TXN_SPLITAMT, txn->amount,
83 -1);
84 }
85
86 if(txn->status == TXN_STATUS_REMIND)
87 {
88 gtk_list_store_insert_with_values(GTK_LIST_STORE(model2), &iter, -1,
89 MODEL_TXN_POINTER, txn,
90 MODEL_TXN_SPLITAMT, txn->amount,
91 -1);
92 }
93 lnk_txn = g_list_next(lnk_txn);
94 }
95
96 next_acc:
97 lnk_acc = g_list_next(lnk_acc);
98 }
99 g_list_free(lst_acc);
100 }
101
102
103 static void ui_hub_transaction_onRowActivated (GtkTreeView *treeview,
104 GtkTreePath *path,
105 GtkTreeViewColumn *col,
106 gpointer userdata)
107 {
108 struct hbfile_data *data = userdata;
109 Transaction *active_txn;
110 gboolean result;
111
112
113 DB( g_print ("\n[ui_hub_txn] row double-clicked\n") );
114
115 active_txn = list_txn_get_active_transaction(treeview);
116 if(active_txn)
117 {
118 Transaction *old_txn, *new_txn;
119
120 old_txn = da_transaction_clone (active_txn);
121 new_txn = active_txn;
122 result = deftransaction_external_edit(GTK_WINDOW(data->window), old_txn, new_txn);
123
124 if(result == GTK_RESPONSE_ACCEPT)
125 {
126 //#1640885
127 GLOBALS->changes_count++;
128 ui_hub_transaction_populate(data);
129
130 //#1824515 when amount change update acc panel
131 if( old_txn->amount != new_txn->amount )
132 ui_hub_account_populate(GLOBALS->mainwindow, NULL);
133
134 //#1830880 update mainwindow
135 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_BALANCE));
136
137 }
138
139 da_transaction_free (old_txn);
140 }
141 }
142
143
144
145 GtkWidget *ui_hub_transaction_create(struct hbfile_data *data, HbHubTxnType type)
146 {
147 GtkWidget *hub, *vbox, *sw, *widget;
148
149 DB( g_print("\n[ui_hub_txn] create %d\n", type) );
150
151 if( type > HUB_TXN_TYPE_REMIND )
152 return NULL;
153
154 hub = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
155 gtk_container_set_border_width(GTK_CONTAINER(hub), SPACING_SMALL);
156
157 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
158 //gtk_widget_set_margin_top(GTK_WIDGET(vbox), 0);
159 //gtk_widget_set_margin_bottom(GTK_WIDGET(vbox), SPACING_SMALL);
160 //gtk_widget_set_margin_start(GTK_WIDGET(vbox), 2*SPACING_SMALL);
161 //gtk_widget_set_margin_end(GTK_WIDGET(vbox), SPACING_SMALL);
162 gtk_box_pack_start (GTK_BOX (hub), vbox, TRUE, TRUE, 0);
163
164 sw = gtk_scrolled_window_new (NULL, NULL);
165 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN);
166 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
167 gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
168
169 widget = (GtkWidget *)create_list_transaction(LIST_TXN_TYPE_DETAIL, PREFS->lst_ope_columns);
170 list_txn_set_column_acc_visible(GTK_TREE_VIEW(widget), TRUE);
171 data->LV_txn[type] = widget;
172 gtk_container_add (GTK_CONTAINER (sw), widget);
173
174 g_signal_connect (GTK_TREE_VIEW(data->LV_txn[type]), "row-activated", G_CALLBACK (ui_hub_transaction_onRowActivated), data);
175
176 return hub;
177 }
178
This page took 0.039451 seconds and 4 git commands to generate.