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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with the program; if not, see <http://www.gnu.org/licenses/>
*
*
* Authors:
* Chris Lahey <clahey@ximian.com>
*
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
*
*/
#include <config.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include "e-util/e-util.h"
#include "e-table-config-field.h"
G_DEFINE_TYPE (ETableConfigField, etcf, GTK_TYPE_VBOX)
static void
etcf_dispose (GObject *object)
{
ETableConfigField *etcf = E_TABLE_CONFIG_FIELD (object);
if (etct->spec)
g_object_unref (etcf->spec);
etct->spec = NULL;
if (etct->sort_info)
g_object_unref (etcf->sort_info);
etct->sort_info = NULL;
G_OBJECT_CLASS (etcf_parent_class)->dispose (object);
}
static void
etcf_class_init (ETableConfigFieldClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = etcf_dispose;
}
static void
etcf_init (ETableConfigField *etcf)
{
etcf->spec = NULL;
etcf->sort_info = NULL;
etcf->combo = NULL;
etcf->radio_ascending = NULL;
etcf->radio_descending = NULL;
etcf->child_fields = NULL;
}
ETableConfigField *
e_table_config_field_new (ETableSpecification *spec,
ETableSortInfo *sort_info,
gboolean grouping)
{
ETableConfigField *etcf = g_object_new (E_TABLE_CONFIG_FIELD_TYPE, NULL);
e_table_config_field_construct (etcf, spec, sort_info, grouping);
return (ETableConfigField *) etcf;
}
inline static int
etcf_get_count (ETableConfigField *etcf)
{
if (etcf->grouping)
return e_table_sort_info_grouping_get_count(etcf->sort_info);
else
return e_table_sort_info_sorting_get_count(etcf->sort_info);
}
inline static ETableSortColumn
etcf_get_nth (ETableConfigField *etcf)
{
if (etcf->grouping)
return e_table_sort_info_grouping_get_nth(etcf->sort_info, etcf->n);
else
return e_table_sort_info_sorting_get_nth(etcf->sort_info, etcf->n);
}
inline static void
etcf_set_nth (ETableConfigField *etcf, ETableSortColumn column)
{
if (etcf->grouping)
e_table_sort_info_grouping_set_nth(etcf->sort_info, etcf->n, column);
else
e_table_sort_info_sorting_set_nth(etcf->sort_info, etcf->n, column);
}
inline static void
etcf_truncate (ETableConfigField *etcf)
{
if (etcf->grouping)
e_table_sort_info_grouping_truncate(etcf->sort_info, etcf->n);
else
e_table_sort_info_sorting_truncate(etcf->sort_info, etcf->n);
}
static void
etcf_set_sensitivity(ETableConfigField *etcf)
{
gint count = etcf_get_count(etcf);
if (etcf->n >= count) {
gtk_widget_set_sensitive(etcf->radio_ascending, FALSE);
gtk_widget_set_sensitive(etcf->radio_descending, FALSE);
if (etcf->child_fields)
gtk_widget_set_sensitive(etcf->child_fields, FALSE);
} else {
gtk_widget_set_sensitive(etcf->radio_ascending, TRUE);
gtk_widget_set_sensitive(etcf->radio_descending, TRUE);
if (etcf->child_fields)
gtk_widget_set_sensitive(etcf->child_fields, TRUE);
}
}
static void
toggled(GtkWidget *widget, ETableConfigField *etcf)
{
gint count;
count = etcf_get_count(etcf);
if (count > etcf->n) {
ETableSortColumn sort_column;
sort_column = etcf_get_nth(etcf);
sort_column.ascending = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(etcf->radio_ascending));
etcf_set_nth(etcf, sort_column);
}
}
static void
changed(GtkWidget *widget, ETableConfigField *etcf)
{
ETableColumnSpecification **column;
gchar *text;
text = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(etcf->combo)->entry));
for (column = etcf->spec->columns; *column; column++) {
if (!strcmp((*column)->title_, text)) {
ETableSortColumn sort_column;
sort_column.ascending = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(etcf->radio_ascending));
sort_column.column = (*column)->model_col;
etcf_set_nth(etcf, sort_column);
etcf_set_sensitivity(etcf);
return;
}
}
etcf_truncate(etcf);
etcf_set_sensitivity(etcf);
}
static void
etcf_setup(ETableConfigField *etcf)
{
gint count;
GList *list = NULL;
ETableColumnSpecification **column;
ETableColumnSpecification *chosen_column = NULL;
gint model_col = -1;
etcf_set_sensitivity(etcf);
count = etcf_get_count(etcf);
if (count > etcf->n) {
ETableSortColumn sort_column;
sort_column = etcf_get_nth(etcf);
model_col = sort_column.column;
if (sort_column.ascending)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(etcf->radio_ascending), TRUE);
else
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(etcf->radio_descending), TRUE);
}
for (column = etcf->spec->columns; *column; column++) {
list = g_list_prepend(list, (*column)->title_);
if (count > etcf->n && chosen_column == NULL && (*column)->model_col == model_col) {
chosen_column = *column;
}
}
list = g_list_reverse(list);
list = g_list_prepend(list, "None");
gtk_combo_set_popdown_strings(GTK_COMBO(etcf->combo), list);
g_list_free(list);
if (chosen_column) {
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(etcf->combo)->entry), chosen_column->title_);
} else {
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(etcf->combo)->entry), "None");
}
g_signal_connect(GTK_COMBO(etcf->combo)->entry, "changed",
G_CALLBACK (changed), etcf);
g_signal_connect(etcf->radio_ascending, "toggled",
G_CALLBACK (toggled), etcf);
g_signal_connect(etcf->radio_descending, "toggled",
G_CALLBACK (toggled), etcf);
}
static ETableConfigField *
e_table_config_field_construct_nth (ETableConfigField *etcf,
ETableSpecification *spec,
ETableSortInfo *sort_info,
gboolean grouping,
gint n)
{
GtkWidget *frame;
GtkWidget *internal_hbox;
GtkWidget *internal_vbox1;
GtkWidget *internal_vbox2;
etcf->spec = spec;
g_object_ref (spec);
etcf->sort_info = sort_info;
g_object_ref (sort_info);
etcf->grouping = grouping;
etcf->n = n;
gtk_box_set_spacing(GTK_BOX(etcf), 6);
frame = gtk_frame_new(n > 0 ? _("Then By") : (grouping ? _("Group By") : _("Sort By")));
gtk_box_pack_start(GTK_BOX(etcf), frame, FALSE, FALSE, 0);
internal_hbox = gtk_hbox_new(FALSE, 6);
gtk_container_add(GTK_CONTAINER(frame), internal_hbox);
gtk_container_set_border_width(GTK_CONTAINER(internal_hbox), 6);
internal_vbox1 = gtk_vbox_new(FALSE, 6);
gtk_box_pack_start(GTK_BOX(internal_hbox), internal_vbox1, FALSE, FALSE, 0);
etcf->combo = gtk_combo_new();
gtk_box_pack_start(GTK_BOX(internal_vbox1), etcf->combo, FALSE, FALSE, 0);
internal_vbox2 = gtk_vbox_new(FALSE, 6);
gtk_box_pack_start(GTK_BOX(internal_hbox), internal_vbox2, FALSE, FALSE, 0);
etcf->radio_ascending = gtk_radio_button_new_with_label (NULL, _("Ascending"));
gtk_box_pack_start(GTK_BOX(internal_vbox2), etcf->radio_ascending, FALSE, FALSE, 0);
etcf->radio_descending = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON(etcf->radio_ascending), _("Descending"));
gtk_box_pack_start(GTK_BOX(internal_vbox2), etcf->radio_descending, FALSE, FALSE, 0);
if (n < 3) {
etcf->child_fields = GTK_WIDGET(g_object_new (E_TABLE_CONFIG_FIELD_TYPE, NULL));
e_table_config_field_construct_nth(E_TABLE_CONFIG_FIELD(etcf->child_fields), spec, sort_info, grouping, n + 1);
gtk_box_pack_start(GTK_BOX(etcf), etcf->child_fields, FALSE, FALSE, 0);
gtk_widget_show(etcf->child_fields);
} else
etcf->child_fields = NULL;
etcf_setup(etcf);
gtk_widget_show(etcf->radio_descending);
gtk_widget_show(etcf->radio_ascending);
gtk_widget_show(internal_vbox2);
gtk_widget_show(etcf->combo);
gtk_widget_show(internal_vbox1);
gtk_widget_show(internal_hbox);
gtk_widget_show(frame);
return etcf;
}
ETableConfigField *
e_table_config_field_construct (ETableConfigField *etcf,
ETableSpecification *spec,
ETableSortInfo *sort_info,
gboolean grouping)
{
return e_table_config_field_construct_nth(etcf, spec, sort_info, grouping, 0);
}
|