]>
Dogcows Code - chaz/homebank/blob - src/ui-hbfile.c
1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2014 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 "ui-hbfile.h"
24 #include "ui-category.h"
26 /****************************************************************************/
28 /****************************************************************************/
37 /* our global datas */
38 extern struct HomeBank
*GLOBALS
;
45 ** get widgets contents from the selected account
47 static void defhbfile_get(GtkWidget
*widget
, gpointer user_data
)
49 struct defhbfile_data
*data
;
52 gint smode
, weekday
, nbdays
;
54 DB( g_print("(ui-hbfile) get\n") );
56 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
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])) )
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
));
69 if(strcasecmp(owner
, GLOBALS
->owner
))
71 if(vehicle
!= GLOBALS
->vehicle_category
)
73 if(smode
!= GLOBALS
->auto_smode
)
75 if(weekday
!= GLOBALS
->auto_weekday
)
77 if(nbdays
!= GLOBALS
->auto_nbdays
)
82 hbfile_change_owner(g_strdup(owner
));
84 GLOBALS
->vehicle_category
= vehicle
;
85 GLOBALS
->auto_smode
= smode
;
86 GLOBALS
->auto_weekday
= weekday
;
87 GLOBALS
->auto_nbdays
= nbdays
;
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
) );
99 ** set widgets contents from the selected account
101 static void defhbfile_set(GtkWidget
*widget
, gpointer user_data
)
103 struct defhbfile_data
*data
;
105 DB( g_print("(ui-hbfile) set\n") );
107 data
= g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget
, GTK_TYPE_WINDOW
)), "inst_data");
109 DB( g_print(" -> ccgrp %d\n", GLOBALS
->vehicle_category
) );
110 DB( g_print(" -> autoinsert %d\n", GLOBALS
->auto_nbdays
) );
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
);
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
);
126 static gboolean
defhbfile_cleanup(struct defhbfile_data
*data
, gint result
)
128 gboolean doupdate
= FALSE
;
130 DB( g_print("(ui-hbfile) cleanup\n") );
132 if(result
== GTK_RESPONSE_ACCEPT
)
134 defhbfile_get(data
->ST_owner
, NULL
);
137 DB( g_print(" -> GLOBAL change = %d\n", GLOBALS
->changes_count
) );
139 DB( g_print(" -> we update, change = %d\n", data
->change
) );
142 GLOBALS
->changes_count
+= data
->change
;
150 static void defhbfile_setup(struct defhbfile_data
*data
)
152 DB( g_print("(ui-hbfile) setup\n") );
156 ui_cat_comboboxentry_populate(GTK_COMBO_BOX(data
->PO_grp
), GLOBALS
->h_cat
);
158 defhbfile_set(data
->ST_owner
, NULL
);
163 GtkWidget
*create_defhbfile_dialog (void)
165 struct defhbfile_data data
;
166 GtkWidget
*dialog
, *content_area
, *hbox
, *vbox
, *table
;
167 GtkWidget
*label
, *widget
, *entry
, *combo
, *spinner
;
168 GtkWidget
*alignment
;
171 dialog
= gtk_dialog_new_with_buttons (_("HomeBank file properties"),
172 GTK_WINDOW(GLOBALS
->mainwindow
),
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
) );
184 gtk_window_set_icon_name(GTK_WINDOW (dialog
), GTK_STOCK_PROPERTIES
);
185 gtk_window_set_resizable(GTK_WINDOW (dialog
), FALSE
);
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);
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
);
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
);
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);
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);
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);
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);
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);
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);
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);
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);
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
);
258 gtk_table_attach (GTK_TABLE (table
), combo
, 2, 3, row
, row
+1, (GtkAttachOptions
) (GTK_EXPAND
| GTK_FILL
), (GtkAttachOptions
) (0), 0, 0);
261 //connect all our signals
262 g_signal_connect (dialog
, "destroy", G_CALLBACK (gtk_widget_destroyed
), &dialog
);
264 //setup, init and show window
265 defhbfile_setup(&data
);
266 //defhbfile_update(data.LV_arc, NULL);
268 gtk_widget_show_all (dialog
);
271 gint result
= gtk_dialog_run (GTK_DIALOG (dialog
));
273 // cleanup and destroy
274 defhbfile_cleanup(&data
, result
);
275 gtk_widget_destroy (dialog
);
This page took 0.046943 seconds and 4 git commands to generate.