another minor fix
[sgc.git] / config.c
blobd5023a7625e493ce91364a2055138d455bbb65ce
1 #include "sgc.h"
3 void configOpen() {
4 GKeyFile *config = g_key_file_new();
5 if (g_key_file_load_from_file(config, CONFIGFILE, G_KEY_FILE_NONE, NULL)) {
6 gchar *last;
7 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(glade_xml_get_widget(xml, "checkmenuitemBeforeHum")), g_key_file_get_boolean(config, "before", "hum", NULL));
8 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(glade_xml_get_widget(xml, "checkmenuitemBeforeVoice")), g_key_file_get_boolean(config, "before", "voice", NULL));
9 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(glade_xml_get_widget(xml, "checkmenuitemExampleHum")), g_key_file_get_boolean(config, "example", "hum", NULL));
10 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(glade_xml_get_widget(xml, "checkmenuitemExampleVoice")), g_key_file_get_boolean(config, "example", "voice", NULL));
12 upperRegister = g_key_file_get_double(config, "voice", "upperregister", NULL);
14 if (upperRegister <= 0.0) upperRegister = 200.0;
16 switch ((int)upperRegister) {
17 case 150:
18 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(glade_xml_get_widget(xml, "menuitemVoice_Male_Low")), TRUE);
19 break;
20 case 200:
21 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(glade_xml_get_widget(xml, "menuitemVoice_Male")), TRUE);
22 break;
23 case 300:
24 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(glade_xml_get_widget(xml, "menuitemVoice_Female")), TRUE);
25 break;
26 case 400:
27 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(glade_xml_get_widget(xml, "menuitemVoice_Child")), TRUE);
28 break;
31 if ((last = g_key_file_get_string(config, "wordlist", "last", NULL)) == NULL || (g_access(last, F_OK) != 0)) {
32 gchar *currentDir = g_get_current_dir();
33 g_free(last);
34 last = g_build_filename(currentDir, TESTFILE, NULL);
35 fileOpen(last);
36 fileSave(last);
37 g_free(currentDir);
40 fileOpen(last);
41 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(glade_xml_get_widget(xml, "filechooserdialogWordlist")), last);
42 g_free(last);
44 g_key_file_free(config);
47 void configSave() {
48 GString *output;
49 GKeyFile *config = g_key_file_new();
50 g_key_file_load_from_file(config, CONFIGFILE, G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS, NULL);
51 g_key_file_set_boolean(config, "before", "hum", gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(glade_xml_get_widget(xml, "checkmenuitemBeforeHum"))));
52 g_key_file_set_boolean(config, "before", "voice", gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(glade_xml_get_widget(xml, "checkmenuitemBeforeVoice"))));
53 g_key_file_set_boolean(config, "example", "hum", gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(glade_xml_get_widget(xml, "checkmenuitemExampleHum"))));
54 g_key_file_set_boolean(config, "example", "voice", gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(glade_xml_get_widget(xml, "checkmenuitemExampleVoice"))));
55 g_key_file_set_string(config, "wordlist", "last", file);
57 g_key_file_set_double(config, "voice", "upperregister", upperRegister);
59 output = g_string_new(g_key_file_to_data(config, NULL, NULL));
60 g_file_set_contents(CONFIGFILE, output->str, output->len, NULL);
62 g_string_free(output, TRUE);
63 g_key_file_free(config);