add gitignore
[chaz/homebank] / src / ui-hbfile.c
1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2014 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 "ui-hbfile.h"
24 #include "ui-category.h"
25
26 /****************************************************************************/
27 /* Debug macros */
28 /****************************************************************************/
29 #define MYDEBUG 0
30
31 #if MYDEBUG
32 #define DB(x) (x);
33 #else
34 #define DB(x);
35 #endif
36
37 /* our global datas */
38 extern struct HomeBank *GLOBALS;
39
40
41
42
43
44 /*
45 ** get widgets contents from the selected account
46 */
47 static void defhbfile_get(GtkWidget *widget, gpointer user_data)
48 {
49 struct defhbfile_data *data;
50 gchar *owner;
51 guint32 vehicle;
52 gint smode, weekday, nbdays;
53
54 DB( g_print("(ui-hbfile) get\n") );
55
56 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
57
58 // get values
59 owner = (gchar *)gtk_entry_get_text(GTK_ENTRY(data->ST_owner));
60 vehicle = ui_cat_comboboxentry_get_key(GTK_COMBO_BOX(data->PO_grp));
61 if( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->radio[0])) )
62 smode = 0;
63 else
64 smode = 1;
65 weekday = gtk_spin_button_get_value(GTK_SPIN_BUTTON(data->NU_weekday));
66 nbdays = gtk_spin_button_get_value(GTK_SPIN_BUTTON(data->NU_nbdays));
67
68 // check for changes
69 if(strcasecmp(owner, GLOBALS->owner))
70 data->change++;
71 if(vehicle != GLOBALS->vehicle_category)
72 data->change++;
73 if(smode != GLOBALS->auto_smode)
74 data->change++;
75 if(weekday != GLOBALS->auto_weekday)
76 data->change++;
77 if(nbdays != GLOBALS->auto_nbdays)
78 data->change++;
79
80 // update
81 if (owner && *owner)
82 hbfile_change_owner(g_strdup(owner));
83
84 GLOBALS->vehicle_category = vehicle;
85 GLOBALS->auto_smode = smode;
86 GLOBALS->auto_weekday = weekday;
87 GLOBALS->auto_nbdays = nbdays;
88
89 DB( g_print(" -> owner %s\n", GLOBALS->owner) );
90 DB( g_print(" -> ccgrp %d\n", GLOBALS->vehicle_category) );
91 DB( g_print(" -> smode %d\n", GLOBALS->auto_smode) );
92 DB( g_print(" -> weekday %d\n", GLOBALS->auto_weekday) );
93 DB( g_print(" -> nbdays %d\n", GLOBALS->auto_nbdays) );
94
95 }
96
97
98 /*
99 ** set widgets contents from the selected account
100 */
101 static void defhbfile_set(GtkWidget *widget, gpointer user_data)
102 {
103 struct defhbfile_data *data;
104
105 DB( g_print("(ui-hbfile) set\n") );
106
107 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
108
109 DB( g_print(" -> ccgrp %d\n", GLOBALS->vehicle_category) );
110 DB( g_print(" -> autoinsert %d\n", GLOBALS->auto_nbdays) );
111
112 if(GLOBALS->owner) gtk_entry_set_text(GTK_ENTRY(data->ST_owner), GLOBALS->owner);
113 ui_cat_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_grp), GLOBALS->vehicle_category);
114
115 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->radio[GLOBALS->auto_smode]), TRUE);
116 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->NU_nbdays), GLOBALS->auto_nbdays);
117 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->NU_weekday), GLOBALS->auto_weekday);
118
119
120 }
121
122
123 /*
124 **
125 */
126 static gboolean defhbfile_cleanup(struct defhbfile_data *data, gint result)
127 {
128 gboolean doupdate = FALSE;
129
130 DB( g_print("(ui-hbfile) cleanup\n") );
131
132 if(result == GTK_RESPONSE_ACCEPT)
133 {
134 defhbfile_get(data->ST_owner, NULL);
135
136
137 DB( g_print(" -> GLOBAL change = %d\n", GLOBALS->changes_count) );
138
139 DB( g_print(" -> we update, change = %d\n", data->change) );
140
141
142 GLOBALS->changes_count += data->change;
143 }
144 return doupdate;
145 }
146
147 /*
148 **
149 */
150 static void defhbfile_setup(struct defhbfile_data *data)
151 {
152 DB( g_print("(ui-hbfile) setup\n") );
153
154 data->change = 0;
155
156 ui_cat_comboboxentry_populate(GTK_COMBO_BOX(data->PO_grp), GLOBALS->h_cat);
157
158 defhbfile_set(data->ST_owner, NULL);
159
160 }
161
162
163 GtkWidget *create_defhbfile_dialog (void)
164 {
165 struct defhbfile_data data;
166 GtkWidget *dialog, *content_area, *hbox, *vbox, *table;
167 GtkWidget *label, *widget, *entry, *combo, *spinner;
168 GtkWidget *alignment;
169 gint row;
170
171 dialog = gtk_dialog_new_with_buttons (_("HomeBank file properties"),
172 GTK_WINDOW(GLOBALS->mainwindow),
173 0,
174 GTK_STOCK_CANCEL,
175 GTK_RESPONSE_REJECT,
176 GTK_STOCK_OK,
177 GTK_RESPONSE_ACCEPT,
178 NULL);
179
180 //store our dialog private data
181 g_object_set_data(G_OBJECT(dialog), "inst_data", (gpointer)&data);
182 DB( g_print("(defaccount) dialog=%p, inst_data=%p\n", dialog, &data) );
183
184 gtk_window_set_icon_name(GTK_WINDOW (dialog), GTK_STOCK_PROPERTIES);
185 gtk_window_set_resizable(GTK_WINDOW (dialog), FALSE);
186
187 content_area = gtk_dialog_get_content_area(GTK_DIALOG (dialog));
188 vbox = gtk_vbox_new (FALSE, 0);
189 gtk_container_set_border_width (GTK_CONTAINER(vbox), HB_MAINBOX_SPACING);
190 gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
191
192 table = gtk_table_new (6, 3, FALSE);
193 gtk_table_set_row_spacings (GTK_TABLE (table), HB_TABROW_SPACING);
194 gtk_table_set_col_spacings (GTK_TABLE (table), HB_TABCOL_SPACING);
195
196 // gtk_alignment_new(xalign, yalign, xscale, yscale)
197 alignment = gtk_alignment_new(0.5, 0.0, 1.0, 0.0);
198 gtk_container_add(GTK_CONTAINER(alignment), table);
199 gtk_container_add (GTK_CONTAINER (vbox), alignment);
200
201 // part 1
202 row = 0;
203 label = make_label(_("General"), 0.0, 0.5);
204 gimp_label_set_attributes(GTK_LABEL(label), PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD, -1);
205 gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 3, row, row+1);
206
207 row++;
208 label = make_label(_("_Owner:"), 0, 0.5);
209 gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
210 entry = make_string(label);
211 data.ST_owner = entry;
212 gtk_table_attach (GTK_TABLE (table), entry, 2, 3, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
213
214 // frame 2
215 row++;
216 label = make_label(_("Scheduled transaction"), 0.0, 0.5);
217 gimp_label_set_attributes(GTK_LABEL(label), PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD, -1);
218 gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 3, row, row+1);
219
220 row++;
221 widget = gtk_radio_button_new_with_label (NULL, _("add until"));
222 data.radio[0] = widget;
223 gtk_table_attach (GTK_TABLE (table), widget, 1, 2, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
224
225 hbox = gtk_hbox_new(FALSE, HB_BOX_SPACING);
226 gtk_table_attach (GTK_TABLE (table), hbox, 2, 3, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
227 spinner = make_numeric(NULL, 1, 28);
228 data.NU_weekday = spinner;
229 gtk_box_pack_start (GTK_BOX (hbox), spinner, FALSE, FALSE, 0);
230 label = make_label(_("of each month (excluded)"), 1, 0.5);
231 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
232
233 row++;
234 widget = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON (data.radio[0]), _("add"));
235 data.radio[1] = widget;
236 gtk_table_attach (GTK_TABLE (table), widget, 1, 2, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
237
238 hbox = gtk_hbox_new(FALSE, HB_BOX_SPACING);
239 gtk_table_attach (GTK_TABLE (table), hbox, 2, 3, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
240 spinner = make_numeric(NULL, 0, 366);
241 data.NU_nbdays = spinner;
242 gtk_box_pack_start (GTK_BOX (hbox), spinner, FALSE, FALSE, 0);
243 //TRANSLATORS: there is a spinner on the left of this label, and so you have 0....x days in advance the current date
244 label = make_label(_("days in advance the current date"), 1, 0.5);
245 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
246
247 // frame 3
248 row++;
249 label = make_label(_("Vehicle cost"), 0.0, 0.5);
250 gimp_label_set_attributes(GTK_LABEL(label), PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD, -1);
251 gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 3, row, row+1);
252
253 row++;
254 label = make_label(_("_Category:"), 0, 0.5);
255 gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
256 combo = ui_cat_comboboxentry_new(label);
257 data.PO_grp = combo;
258 gtk_table_attach (GTK_TABLE (table), combo, 2, 3, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
259
260
261 //connect all our signals
262 g_signal_connect (dialog, "destroy", G_CALLBACK (gtk_widget_destroyed), &dialog);
263
264 //setup, init and show window
265 defhbfile_setup(&data);
266 //defhbfile_update(data.LV_arc, NULL);
267
268 gtk_widget_show_all (dialog);
269
270 //wait for the user
271 gint result = gtk_dialog_run (GTK_DIALOG (dialog));
272
273 // cleanup and destroy
274 defhbfile_cleanup(&data, result);
275 gtk_widget_destroy (dialog);
276
277 return dialog;
278 }
This page took 0.055249 seconds and 4 git commands to generate.