2 * setup_counter.c: Reads counters from config and creates them
3 * on screen in the GUI.
4 * Copyright (C) 2007 Stepan Bityugov
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation
15 #include "MyCounter.h"
17 #include "MyTouchscreen.h"
18 #include "MyTotalWidget.h"
20 void setup_counter_pages(GtkNotebook
*notebook
) {
23 gchar
** countertabs
= g_key_file_get_string_list(config
, "global", "countertabs", &length
, NULL
);
25 for (i
= 0; i
< length
; i
++) {
26 if (g_key_file_has_group(config
, countertabs
[i
]) == TRUE
) {
27 gsize maxcounters
, maxtotal
;
28 gchar
*totalgroup
= g_key_file_get_string (config
, countertabs
[i
], "counters", NULL
);
29 gchar
*countergroup
= g_key_file_get_string (config
, countertabs
[i
], "prices", NULL
);
31 if (totalgroup
&& countergroup
) {
32 GtkWidget
*vbox
= gtk_vbox_new(TRUE
, 5);
33 gchar
** totalcounters
= g_key_file_get_keys(config
, totalgroup
, &maxtotal
, NULL
);
34 gchar
** counters
= g_key_file_get_keys(config
, countergroup
, &maxcounters
, NULL
);
36 if (counters
!= NULL
) {
39 gdouble
* prices
= g_malloc(sizeof(gdouble
) * maxcounters
);
41 for (j
= 0; j
< maxcounters
; j
++) {
42 /* TODO: add code to find invalid values */
43 prices
[j
] = g_key_file_get_double(config
, countergroup
, counters
[j
], NULL
);
46 mts
= mytouchscreen_new(counters
, prices
);
50 gtk_container_add (GTK_CONTAINER (vbox
), mts
);
51 gtk_widget_show (mts
);
53 if (totalcounters
!= NULL
) {
57 GtkWidget
*hbox
= gtk_hbox_new(TRUE
, 5);
58 GtkWidget
*start
= NULL
, *end
= NULL
;
60 gtk_container_add (GTK_CONTAINER (vbox
), hbox
);
62 if (g_key_file_has_key(config
, countertabs
[i
], "Calendar", NULL
) && g_key_file_get_boolean(config
, countertabs
[i
], "Calendar", NULL
)) {
63 start
= gtk_calendar_new();
64 end
= gtk_calendar_new();
66 mt
= mytotal_new(totalcounters
);
67 gtk_container_add (GTK_CONTAINER (hbox
), start
);
68 gtk_container_add (GTK_CONTAINER (hbox
), mt
);
69 gtk_container_add (GTK_CONTAINER (hbox
), end
);
71 gtk_widget_show (start
);
72 gtk_widget_show (end
);
74 mt
= mytotal_new(totalcounters
);
75 gtk_container_add (GTK_CONTAINER (hbox
), mt
);
80 gtk_widget_show (hbox
);
82 for (j
= 0; j
< maxtotal
; j
++) {
83 gchar
**linkto
= g_key_file_get_string_list(config
, totalgroup
, totalcounters
[j
], NULL
, NULL
);
84 GtkWidget
*mtw
= mytotal_get_counter(MYTOTAL(mt
), totalcounters
[j
]);
85 mytotalwidget_add_links(MYTOTALWIDGET(mtw
), GTK_WIDGET(mt
), MYTOUCHSCREEN(mts
), linkto
, start
, end
);
89 g_strfreev(totalcounters
);
93 gtk_widget_show (vbox
);
94 gtk_notebook_append_page(notebook
, vbox
, gtk_label_new(countertabs
[i
]));
96 g_warning("Because the counters failed, I did not add the tab %s", countertabs
[i
]);
102 g_warning("Because there was no counter or prices group, I skipped tab %s", countertabs
[i
]);
105 g_warning("Because the group %s was not found, I skipped it.", countertabs
[i
]);
109 g_strfreev(countertabs
);