Friendly email address to contact me.
[bityugov.git] / ccs / setup_counter.c
blob9f4d0622645cebeb5567a631bb0fe4cb52da1ef3
1 /* Cash Counter System
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
13 #include <gtk/gtk.h>
14 #include "ccs.h"
15 #include "MyCounter.h"
16 #include "MyTotal.h"
17 #include "MyTouchscreen.h"
18 #include "MyTotalWidget.h"
20 void setup_counter_pages(GtkNotebook *notebook) {
21 guint i;
22 gsize length;
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) {
37 guint j;
38 GtkWidget *mts;
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);
47 g_strfreev(counters);
48 g_free(prices);
50 gtk_container_add (GTK_CONTAINER (vbox), mts);
51 gtk_widget_show (mts);
53 if (totalcounters != NULL) {
54 gboolean calendar;
55 guint j;
56 GtkWidget *mt;
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);
70 calendar = TRUE;
71 gtk_widget_show (start);
72 gtk_widget_show (end);
73 } else {
74 mt = mytotal_new(totalcounters);
75 gtk_container_add (GTK_CONTAINER (hbox), mt);
76 calendar = FALSE;
79 gtk_widget_show (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);
87 g_strfreev(linkto);
89 g_strfreev(totalcounters);
93 gtk_widget_show (vbox);
94 gtk_notebook_append_page(notebook, vbox, gtk_label_new(countertabs[i]));
95 } else {
96 g_warning("Because the counters failed, I did not add the tab %s", countertabs[i]);
99 g_free(countergroup);
100 g_free(totalgroup);
101 } else {
102 g_warning("Because there was no counter or prices group, I skipped tab %s", countertabs[i]);
104 } else {
105 g_warning("Because the group %s was not found, I skipped it.", countertabs[i]);
109 g_strfreev(countertabs);