1 /*
2 ** 2001-08-18 -	Configuration handling for the error reporting stuff. Small.
3 */
4 
5 #include "gentoo.h"
6 
7 #include "cfg_module.h"
8 #include "configure.h"
9 
10 #include "cfg_errors.h"
11 
12 #define	NODE	"Errors"
13 
14 /* ----------------------------------------------------------------------------------------- */
15 
16 typedef struct {
17 	GtkWidget	*vbox;
18 	GtkWidget	*standard, *main_title, *dialog;
19 	GtkWidget	*beep;
20 
21 	MainInfo	*min;
22 	ErrInfo		edit;
23 	gboolean	modified;
24 } P_Errors;
25 
26 static P_Errors	the_page;
27 
28 /* ----------------------------------------------------------------------------------------- */
29 
evt_dialog_toggled(GtkWidget * wid,gpointer user)30 static void evt_dialog_toggled(GtkWidget *wid, gpointer user)
31 {
32 	((P_Errors *) user)->modified = TRUE;
33 }
34 
evt_beep_toggled(GtkWidget * wid,gpointer user)35 static void evt_beep_toggled(GtkWidget *wid, gpointer user)
36 {
37 	((P_Errors *) user)->modified = TRUE;
38 }
39 
cer_init(MainInfo * min,gchar ** name)40 static GtkWidget * cer_init(MainInfo *min, gchar **name)
41 {
42 	P_Errors	*page = &the_page;
43 	GtkWidget	*vbox, *frame;
44 
45 	if(name == NULL)
46 		return NULL;
47 
48 	*name = _("Errors");
49 
50 	page->min = min;
51 	page->modified = FALSE;
52 
53 	page->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
54 
55 	frame = gtk_frame_new(_("Error and Status Message Display"));
56 	vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
57 	page->standard = gtk_radio_button_new_with_label(NULL, _("Status Bar, Above Panes"));
58 	g_signal_connect(G_OBJECT(page->standard), "toggled", G_CALLBACK(evt_dialog_toggled), page);
59 	gtk_box_pack_start(GTK_BOX(vbox), page->standard, FALSE, FALSE, 0);
60 	page->main_title = gtk_radio_button_new_with_label(gtk_radio_button_get_group(GTK_RADIO_BUTTON(page->standard)), _("Main Window's Title Bar"));
61 	g_signal_connect(G_OBJECT(page->main_title), "toggled", G_CALLBACK(evt_dialog_toggled), page);
62 	gtk_box_pack_start(GTK_BOX(vbox), page->main_title, FALSE, FALSE, 0);
63 	page->dialog = gtk_radio_button_new_with_label(gtk_radio_button_get_group(GTK_RADIO_BUTTON(page->standard)), _("Separate Dialog"));
64 	g_signal_connect(G_OBJECT(page->dialog), "toggled", G_CALLBACK(evt_dialog_toggled), page);
65 	gtk_box_pack_start(GTK_BOX(vbox), page->dialog, FALSE, FALSE, 0);
66 	gtk_container_add(GTK_CONTAINER(frame), vbox);
67 	gtk_box_pack_start(GTK_BOX(page->vbox), frame, FALSE, FALSE, 0);
68 
69 	page->beep = gtk_check_button_new_with_label(_("Cause Console Beep on Error?"));
70 	g_signal_connect(G_OBJECT(page->beep), "toggled", G_CALLBACK(evt_beep_toggled), page);
71 	gtk_box_pack_start(GTK_BOX(page->vbox), page->beep, FALSE, FALSE, 0);
72 
73 	gtk_widget_show_all(page->vbox);
74 	return page->vbox;
75 }
76 
77 /* ----------------------------------------------------------------------------------------- */
78 
cer_update(MainInfo * min)79 static void cer_update(MainInfo *min)
80 {
81 	P_Errors	*page = &the_page;
82 
83 	page->edit = min->cfg.errors;
84 	if(page->edit.display == ERR_DISPLAY_STATUSBAR)
85 		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->standard), TRUE);
86 	else if(page->edit.display == ERR_DISPLAY_TITLEBAR)
87 		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->main_title), TRUE);
88 	else
89 		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->dialog), TRUE);
90 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->beep),   page->edit.beep);
91 	page->modified = FALSE;
92 }
93 
94 /* ----------------------------------------------------------------------------------------- */
95 
cer_accept(MainInfo * min)96 static void cer_accept(MainInfo *min)
97 {
98 	P_Errors	*page = &the_page;
99 
100 	if(!page->modified)
101 		return;
102 	/* We have very little widget state, so just grab it right here. */
103 	if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->standard)))
104 		page->edit.display = ERR_DISPLAY_STATUSBAR;
105 	else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->main_title)))
106 		page->edit.display = ERR_DISPLAY_TITLEBAR;
107 	else
108 		page->edit.display = ERR_DISPLAY_DIALOG;
109 	page->edit.beep = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->beep));
110 	if(min->cfg.errors.display != page->edit.display)
111 		cfg_set_flags(CFLG_REBUILD_TOP);
112 	min->cfg.errors = page->edit;
113 	page->modified = FALSE;
114 }
115 
116 /* ----------------------------------------------------------------------------------------- */
117 
cer_save(MainInfo * min,FILE * out)118 static gint cer_save(MainInfo *min, FILE *out)
119 {
120 	xml_put_node_open(out, NODE);
121 	xml_put_integer(out, "display", min->cfg.errors.display);
122 	xml_put_boolean(out, "beep",   min->cfg.errors.beep);
123 	xml_put_node_close(out, NODE);
124 
125 	return TRUE;
126 }
127 
cer_load(MainInfo * min,const XmlNode * node)128 static void cer_load(MainInfo *min, const XmlNode *node)
129 {
130 	const XmlNode	*root;
131 
132 	if((root = xml_tree_search(node, NODE)) != NULL)
133 	{
134 		gboolean	tmp;
135 		gint		itmp;
136 
137 		if(xml_get_integer(root, "display", &itmp))
138 			min->cfg.errors.display = itmp;
139 		else if(xml_get_boolean(root, "dialog", &tmp))	/* Legacy "dialog" boolean support. */
140 		{
141 			if(tmp)
142 				min->cfg.errors.display = ERR_DISPLAY_DIALOG;
143 			else
144 				min->cfg.errors.display = ERR_DISPLAY_STATUSBAR;
145 		}
146 		if(xml_get_boolean(root, "beep", &tmp))
147 			min->cfg.errors.beep = tmp;
148 	}
149 }
150 
151 /* ----------------------------------------------------------------------------------------- */
152 
cer_describe(MainInfo * min)153 const CfgModule * cer_describe(MainInfo *min)
154 {
155 	static const CfgModule	desc = { NODE, cer_init, cer_update, cer_accept, cer_save, cer_load, NULL };
156 
157 	return &desc;
158 }
159