File: char_conv_dlg.c

package info (click to toggle)
tagtool 0.12.2-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,352 kB
  • ctags: 1,010
  • sloc: ansic: 9,013; sh: 3,571; makefile: 121
file content (208 lines) | stat: -rw-r--r-- 7,012 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include <config.h>
#include <gtk/gtk.h>
#include <glade/glade.h>

#include "gtk_util.h"
#include "prefs.h"

#include "char_conv_dlg.h"


/* options */
static gboolean* tag_space_conv;
static char*     tag_space_conv_chars;
static int*      tag_case_conv;

static gboolean* rename_space_conv;
static char*     rename_space_conv_chars;
static gboolean* rename_invalid_conv;
static char*     rename_invalid_conv_chars;
static int*      rename_case_conv;


/* widgets */
static GtkWindow *dlg_char_conv = NULL;
static GtkNotebook *nb_char_conv = NULL;

static GtkRadioButton *rb_t_conv_space_none = NULL;
static GtkRadioButton *rb_t_conv_space_from = NULL;
static GtkEntry *ent_t_conv_chars = NULL;
static GtkComboBox *combo_t_case = NULL;

static GtkRadioButton *rb_r_conv_space_none = NULL;
static GtkRadioButton *rb_r_conv_space_to = NULL;
static GtkRadioButton *rb_r_invalid_omit = NULL;
static GtkRadioButton *rb_r_invalid_convert = NULL;
static GtkEntry *ent_r_conv_chars = NULL;
static GtkEntry *ent_r_invalid_chars = NULL;
static GtkComboBox *combo_r_case = NULL;


/*** private functions ******************************************************/

/* sets the interface state according to the preferences */
static void from_prefs()
{
	/* tag tab */
	if (*tag_space_conv) {
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rb_t_conv_space_from), TRUE);
		gtk_widget_set_sensitive(GTK_WIDGET(ent_t_conv_chars), TRUE);
	} else {
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rb_t_conv_space_none), TRUE);
		gtk_widget_set_sensitive(GTK_WIDGET(ent_t_conv_chars), FALSE);
	}
	gtk_entry_set_text(ent_t_conv_chars, tag_space_conv_chars);

	gtk_combo_box_set_active(combo_t_case, *tag_case_conv);

	/* rename tab */
	if (*rename_space_conv) {
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rb_r_conv_space_to), TRUE);
		gtk_widget_set_sensitive(GTK_WIDGET(ent_r_conv_chars), TRUE);
	} else {
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rb_r_conv_space_none), TRUE);
		gtk_widget_set_sensitive(GTK_WIDGET(ent_r_conv_chars), FALSE);
	}
	gtk_entry_set_text(ent_r_conv_chars, rename_space_conv_chars);

	if (*rename_invalid_conv) {
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rb_r_invalid_convert), TRUE);
		gtk_widget_set_sensitive(GTK_WIDGET(ent_r_invalid_chars), TRUE);
	} else {
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rb_r_invalid_omit), TRUE);
		gtk_widget_set_sensitive(GTK_WIDGET(ent_r_invalid_chars), FALSE);
	}
	gtk_entry_set_text(ent_r_invalid_chars, rename_invalid_conv_chars);

	gtk_combo_box_set_active(combo_r_case, *rename_case_conv);
}

/* sets the preferences according to the curent interface state */
static void to_prefs()
{
	/* tag tab */
	*tag_space_conv = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rb_t_conv_space_from));
	tag_space_conv_chars = pref_set("chconv:tag_space_conv_chars", PREF_STRING, 
					(void*)gtk_entry_get_text(ent_t_conv_chars));

	*tag_case_conv = gtk_combo_box_get_active(combo_t_case);

	/* rename tab */
	*rename_space_conv = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rb_r_conv_space_to));
	rename_space_conv_chars = pref_set("chconv:rename_space_conv_chars", PREF_STRING, 
					   (void*)gtk_entry_get_text(ent_r_conv_chars));

	*rename_invalid_conv = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rb_r_invalid_convert));
	rename_invalid_conv_chars = pref_set("chconv:rename_invalid_conv_chars", PREF_STRING, 
					     (void*)gtk_entry_get_text(ent_r_invalid_chars));

	*rename_case_conv = gtk_combo_box_get_active(combo_r_case);
}


/* UI callbacks */
void cb_t_conv_space_none_toggled(GtkToggleButton *button, gpointer user_data)
{
	gtk_widget_set_sensitive(GTK_WIDGET(ent_t_conv_chars), !gtk_toggle_button_get_active(button));
}

void cb_r_conv_space_none_toggled(GtkToggleButton *button, gpointer user_data)
{
	gtk_widget_set_sensitive(GTK_WIDGET(ent_r_conv_chars), !gtk_toggle_button_get_active(button));
}

void cb_r_invalid_omit_toggled(GtkToggleButton *button, gpointer user_data)
{
	gtk_widget_set_sensitive(GTK_WIDGET(ent_r_invalid_chars), !gtk_toggle_button_get_active(button));
}

void cb_chconv_save(GtkButton *button, gpointer user_data)
{
	to_prefs();
}


/*** public functions *******************************************************/

chconv_tag_options chconv_get_tag_options()
{
	chconv_tag_options opt;

	opt.space_conv = (*tag_space_conv ? tag_space_conv_chars : NULL);
	opt.case_conv = *tag_case_conv;
		
	return opt;
}

chconv_rename_options chconv_get_rename_options()
{
	chconv_rename_options opt;

	opt.space_conv = (*rename_space_conv ? rename_space_conv_chars : NULL);
	opt.invalid_conv = (*rename_invalid_conv ? rename_invalid_conv_chars : NULL);
	opt.case_conv = *rename_case_conv;

	return opt;
}


void chconv_display(int tab)
{
	from_prefs();

	gtk_window_present(dlg_char_conv);
	gtk_notebook_set_page(nb_char_conv, tab);
}


void chconv_init(GladeXML *xml)
{
	int nocaseconv = 0;
	gboolean true = TRUE;
	gboolean false = FALSE;

	/* 
	 * get the widgets from glade
	 */

	dlg_char_conv = GTK_WINDOW(glade_xml_get_widget(xml, "dlg_char_conv"));
	nb_char_conv = GTK_NOTEBOOK(glade_xml_get_widget(xml, "nb_char_conv"));

	rb_t_conv_space_none = GTK_RADIO_BUTTON(glade_xml_get_widget(xml, "rb_t_conv_space_none"));
	rb_t_conv_space_from = GTK_RADIO_BUTTON(glade_xml_get_widget(xml, "rb_t_conv_space_from"));
	ent_t_conv_chars = GTK_ENTRY(glade_xml_get_widget(xml, "ent_t_conv_chars"));
	combo_t_case = GTK_COMBO_BOX(glade_xml_get_widget(xml, "combo_t_case"));

	rb_r_conv_space_none = GTK_RADIO_BUTTON(glade_xml_get_widget(xml, "rb_r_conv_space_none"));
	rb_r_conv_space_to = GTK_RADIO_BUTTON(glade_xml_get_widget(xml, "rb_r_conv_space_to"));
	rb_r_invalid_omit = GTK_RADIO_BUTTON(glade_xml_get_widget(xml, "rb_r_invalid_omit"));
	rb_r_invalid_convert = GTK_RADIO_BUTTON(glade_xml_get_widget(xml, "rb_r_invalid_convert"));
	ent_r_conv_chars = GTK_ENTRY(glade_xml_get_widget(xml, "ent_r_conv_chars"));
	ent_r_invalid_chars = GTK_ENTRY(glade_xml_get_widget(xml, "ent_r_invalid_chars"));
	combo_r_case = GTK_COMBO_BOX(glade_xml_get_widget(xml, "combo_r_case"));

	gtk_window_set_transient_for(dlg_char_conv, GTK_WINDOW(glade_xml_get_widget(xml, "w_main")));


	/*
	 * get the preference values, or set them to defaults
	 */

	tag_space_conv = pref_get_or_set("chconv:tag_space_conv", PREF_BOOLEAN, &false);
	tag_space_conv_chars = pref_get_or_set("chconv:tag_space_conv_chars", PREF_STRING, "_");
	tag_case_conv = pref_get_or_set("chconv:tag_case_conv", PREF_INT, &nocaseconv);

	rename_space_conv = pref_get_or_set("chconv:rename_space_conv", PREF_BOOLEAN, &false);
	rename_space_conv_chars = pref_get_or_set("chconv:rename_space_conv_chars", PREF_STRING, "_");
	rename_invalid_conv = pref_get_or_set("chconv:rename_invalid_conv", PREF_BOOLEAN, &true);
	rename_invalid_conv_chars = pref_get_or_set("chconv:rename_invalid_conv_chars", PREF_STRING, "-");
	rename_case_conv = pref_get_or_set("chconv:rename_case_conv", PREF_INT, &nocaseconv);


	/*
	 * synchronize the interface state
	 */
	from_prefs();
}