]> Dogcows Code - chaz/homebank/blob - src/hub-transaction.c
import homebank-5.2.6
[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 -1);
83 }
84
85 if(txn->status == TXN_STATUS_REMIND)
86 {
87 gtk_list_store_insert_with_values(GTK_LIST_STORE(model2), &iter, -1,
88 MODEL_TXN_POINTER, txn,
89 -1);
90 }
91 lnk_txn = g_list_next(lnk_txn);
92 }
93
94 next_acc:
95 lnk_acc = g_list_next(lnk_acc);
96 }
97 g_list_free(lst_acc);
98 }
99
100
101 static void ui_hub_transaction_onRowActivated (GtkTreeView *treeview,
102 GtkTreePath *path,
103 GtkTreeViewColumn *col,
104 gpointer userdata)
105 {
106 struct hbfile_data *data = userdata;
107 Transaction *active_txn;
108 gboolean result;
109
110
111 DB( g_print ("\n[ui_hub_txn] row double-clicked\n") );
112
113 active_txn = list_txn_get_active_transaction(treeview);
114 if(active_txn)
115 {
116 Transaction *old_txn, *new_txn;
117
118 old_txn = da_transaction_clone (active_txn);
119 new_txn = active_txn;
120 result = deftransaction_external_edit(GTK_WINDOW(data->window), old_txn, new_txn);
121
122 if(result == GTK_RESPONSE_ACCEPT)
123 {
124 //#1640885
125 GLOBALS->changes_count++;
126 ui_hub_transaction_populate(data);
127
128 //#1824515 when amount change update acc panel
129 if( old_txn->amount != new_txn->amount )
130 ui_hub_account_populate(GLOBALS->mainwindow, NULL);
131
132 }
133
134 da_transaction_free (old_txn);
135 }
136 }
137
138
139
140 GtkWidget *ui_hub_transaction_create(struct hbfile_data *data, HbHubTxnType type)
141 {
142 GtkWidget *hub, *vbox, *sw, *widget;
143
144 DB( g_print("\n[ui_hub_txn] create %d\n", type) );
145
146 if( type > HUB_TXN_TYPE_REMIND )
147 return NULL;
148
149 hub = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
150 gtk_container_set_border_width(GTK_CONTAINER(hub), SPACING_SMALL);
151
152 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
153 //gtk_widget_set_margin_top(GTK_WIDGET(vbox), 0);
154 //gtk_widget_set_margin_bottom(GTK_WIDGET(vbox), SPACING_SMALL);
155 //gtk_widget_set_margin_start(GTK_WIDGET(vbox), 2*SPACING_SMALL);
156 //gtk_widget_set_margin_end(GTK_WIDGET(vbox), SPACING_SMALL);
157 gtk_box_pack_start (GTK_BOX (hub), vbox, TRUE, TRUE, 0);
158
159 sw = gtk_scrolled_window_new (NULL, NULL);
160 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN);
161 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
162 gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
163
164 widget = (GtkWidget *)create_list_transaction(LIST_TXN_TYPE_DETAIL, PREFS->lst_ope_columns);
165 list_txn_set_column_acc_visible(GTK_TREE_VIEW(widget), TRUE);
166 data->LV_txn[type] = widget;
167 gtk_container_add (GTK_CONTAINER (sw), widget);
168
169 g_signal_connect (GTK_TREE_VIEW(data->LV_txn[type]), "row-activated", G_CALLBACK (ui_hub_transaction_onRowActivated), data);
170
171 return hub;
172 }
173
This page took 0.037185 seconds and 4 git commands to generate.