]> Dogcows Code - chaz/homebank/blob - src/hub-transaction.c
import homebank-5.2.4
[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 "dsp-mainwindow.h"
25 #include "list-operation.h"
26
27 #include "ui-transaction.h"
28
29
30 /****************************************************************************/
31 /* Debug macros */
32 /****************************************************************************/
33 #define MYDEBUG 0
34
35 #if MYDEBUG
36 #define DB(x) (x);
37 #else
38 #define DB(x);
39 #endif
40
41 /* our global datas */
42 extern struct HomeBank *GLOBALS;
43 extern struct Preferences *PREFS;
44
45
46 void ui_hub_transaction_populate(struct hbfile_data *data)
47 {
48 GList *lst_acc, *lnk_acc;
49 GList *lnk_txn;
50 GtkTreeModel *model1, *model2;
51 GtkTreeIter iter;
52
53 DB( g_print("\n[ui_hub_txn] populate\n") );
54
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]));
57
58 gtk_list_store_clear (GTK_LIST_STORE(model1));
59 gtk_list_store_clear (GTK_LIST_STORE(model2));
60
61
62 lst_acc = g_hash_table_get_values(GLOBALS->h_acc);
63 lnk_acc = g_list_first(lst_acc);
64 while (lnk_acc != NULL)
65 {
66 Account *acc = lnk_acc->data;
67
68 // skip closed in showall mode
69 if( (acc->flags & AF_CLOSED) )
70 goto next_acc;
71
72 lnk_txn = g_queue_peek_head_link(acc->txn_queue);
73 while (lnk_txn != NULL)
74 {
75 Transaction *txn = lnk_txn->data;
76
77 if(txn->date > GLOBALS->today)
78 {
79 gtk_list_store_insert_with_values(GTK_LIST_STORE(model1), &iter, -1,
80 LST_DSPOPE_DATAS, txn,
81 -1);
82 }
83
84 if(txn->status == TXN_STATUS_REMIND)
85 {
86 gtk_list_store_insert_with_values(GTK_LIST_STORE(model2), &iter, -1,
87 LST_DSPOPE_DATAS, txn,
88 -1);
89 }
90 lnk_txn = g_list_next(lnk_txn);
91 }
92
93 next_acc:
94 lnk_acc = g_list_next(lnk_acc);
95 }
96 g_list_free(lst_acc);
97 }
98
99
100 static void ui_hub_transaction_onRowActivated (GtkTreeView *treeview,
101 GtkTreePath *path,
102 GtkTreeViewColumn *col,
103 gpointer userdata)
104 {
105 struct hbfile_data *data = userdata;
106 Transaction *active_txn;
107 gboolean result;
108
109
110 DB( g_print ("\n[ui_hub_txn] row double-clicked\n") );
111
112 active_txn = list_txn_get_active_transaction(treeview);
113 if(active_txn)
114 {
115 Transaction *old_txn, *new_txn;
116
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);
120
121 if(result == GTK_RESPONSE_ACCEPT)
122 {
123 //#1640885
124 GLOBALS->changes_count++;
125 ui_hub_transaction_populate(data);
126 }
127
128 da_transaction_free (old_txn);
129 }
130 }
131
132
133
134 GtkWidget *ui_hub_transaction_create(struct hbfile_data *data, HbHubTxnType type)
135 {
136 GtkWidget *hub, *vbox, *sw, *widget;
137
138 DB( g_print("\n[ui_hub_txn] create %d\n", type) );
139
140 if( type > HUB_TXN_TYPE_REMIND )
141 return NULL;
142
143 hub = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
144 gtk_container_set_border_width(GTK_CONTAINER(hub), SPACING_SMALL);
145
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);
152
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);
157
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);
162
163 g_signal_connect (GTK_TREE_VIEW(data->LV_txn[type]), "row-activated", G_CALLBACK (ui_hub_transaction_onRowActivated), data);
164
165 return hub;
166 }
167
This page took 0.038037 seconds and 4 git commands to generate.