No issues found
1 /*
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with the program; if not, see <http://www.gnu.org/licenses/>
15 *
16 *
17 * Authors:
18 * Chris Lahey <clahey@ximian.com>
19 *
20 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
21 *
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <gtk/gtk.h>
29
30 #include <glib/gi18n.h>
31 #include "e-util/e-util.h"
32
33 #include "e-table-field-chooser-dialog.h"
34
35 enum {
36 PROP_0,
37 PROP_DND_CODE,
38 PROP_FULL_HEADER,
39 PROP_HEADER
40 };
41
42 G_DEFINE_TYPE (
43 ETableFieldChooserDialog,
44 e_table_field_chooser_dialog,
45 GTK_TYPE_DIALOG)
46
47 static void
48 e_table_field_chooser_dialog_set_property (GObject *object,
49 guint property_id,
50 const GValue *value,
51 GParamSpec *pspec)
52 {
53 ETableFieldChooserDialog *etfcd = E_TABLE_FIELD_CHOOSER_DIALOG (object);
54 switch (property_id) {
55 case PROP_DND_CODE:
56 g_free (etfcd->dnd_code);
57 etfcd->dnd_code = g_strdup (g_value_get_string (value));
58 if (etfcd->etfc)
59 g_object_set (
60 etfcd->etfc,
61 "dnd_code", etfcd->dnd_code,
62 NULL);
63 break;
64 case PROP_FULL_HEADER:
65 if (etfcd->full_header)
66 g_object_unref (etfcd->full_header);
67 if (g_value_get_object (value))
68 etfcd->full_header = E_TABLE_HEADER (g_value_get_object (value));
69 else
70 etfcd->full_header = NULL;
71 if (etfcd->full_header)
72 g_object_ref (etfcd->full_header);
73 if (etfcd->etfc)
74 g_object_set (
75 etfcd->etfc,
76 "full_header", etfcd->full_header,
77 NULL);
78 break;
79 case PROP_HEADER:
80 if (etfcd->header)
81 g_object_unref (etfcd->header);
82 if (g_value_get_object (value))
83 etfcd->header = E_TABLE_HEADER (g_value_get_object (value));
84 else
85 etfcd->header = NULL;
86 if (etfcd->header)
87 g_object_ref (etfcd->header);
88 if (etfcd->etfc)
89 g_object_set (
90 etfcd->etfc,
91 "header", etfcd->header,
92 NULL);
93 break;
94 default:
95 break;
96 }
97 }
98
99 static void
100 e_table_field_chooser_dialog_get_property (GObject *object,
101 guint property_id,
102 GValue *value,
103 GParamSpec *pspec)
104 {
105 ETableFieldChooserDialog *etfcd = E_TABLE_FIELD_CHOOSER_DIALOG (object);
106 switch (property_id) {
107 case PROP_DND_CODE:
108 g_value_set_string (value, etfcd->dnd_code);
109 break;
110 case PROP_FULL_HEADER:
111 g_value_set_object (value, etfcd->full_header);
112 break;
113 case PROP_HEADER:
114 g_value_set_object (value, etfcd->header);
115 break;
116 default:
117 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
118 break;
119 }
120 }
121
122 static void
123 e_table_field_chooser_dialog_dispose (GObject *object)
124 {
125 ETableFieldChooserDialog *etfcd = E_TABLE_FIELD_CHOOSER_DIALOG (object);
126
127 if (etfcd->dnd_code)
128 g_free (etfcd->dnd_code);
129 etfcd->dnd_code = NULL;
130
131 if (etfcd->full_header)
132 g_object_unref (etfcd->full_header);
133 etfcd->full_header = NULL;
134
135 if (etfcd->header)
136 g_object_unref (etfcd->header);
137 etfcd->header = NULL;
138
139 G_OBJECT_CLASS (e_table_field_chooser_dialog_parent_class)->dispose (object);
140 }
141
142 static void
143 e_table_field_chooser_dialog_response (GtkDialog *dialog,
144 gint id)
145 {
146 if (id == GTK_RESPONSE_OK)
147 gtk_widget_destroy (GTK_WIDGET (dialog));
148 }
149
150 static void
151 e_table_field_chooser_dialog_class_init (ETableFieldChooserDialogClass *class)
152 {
153 GObjectClass *object_class;
154 GtkDialogClass *dialog_class;
155
156 object_class = G_OBJECT_CLASS (class);
157 object_class->set_property = e_table_field_chooser_dialog_set_property;
158 object_class->get_property = e_table_field_chooser_dialog_get_property;
159 object_class->dispose = e_table_field_chooser_dialog_dispose;
160
161 dialog_class = GTK_DIALOG_CLASS (class);
162 dialog_class->response = e_table_field_chooser_dialog_response;
163
164 g_object_class_install_property (
165 object_class,
166 PROP_DND_CODE,
167 g_param_spec_string (
168 "dnd_code",
169 "DnD code",
170 NULL,
171 NULL,
172 G_PARAM_READWRITE));
173
174 g_object_class_install_property (
175 object_class,
176 PROP_FULL_HEADER,
177 g_param_spec_object (
178 "full_header",
179 "Full Header",
180 NULL,
181 E_TYPE_TABLE_HEADER,
182 G_PARAM_READWRITE));
183
184 g_object_class_install_property (
185 object_class,
186 PROP_HEADER,
187 g_param_spec_object (
188 "header",
189 "Header",
190 NULL,
191 E_TYPE_TABLE_HEADER,
192 G_PARAM_READWRITE));
193 }
194
195 static void
196 e_table_field_chooser_dialog_init (ETableFieldChooserDialog *e_table_field_chooser_dialog)
197 {
198 GtkDialog *dialog;
199 GtkWidget *content_area;
200 GtkWidget *widget;
201
202 dialog = GTK_DIALOG (e_table_field_chooser_dialog);
203
204 e_table_field_chooser_dialog->etfc = NULL;
205 e_table_field_chooser_dialog->dnd_code = g_strdup ("");
206 e_table_field_chooser_dialog->full_header = NULL;
207 e_table_field_chooser_dialog->header = NULL;
208
209 gtk_dialog_add_button (dialog, GTK_STOCK_CLOSE, GTK_RESPONSE_OK);
210
211 gtk_window_set_resizable (GTK_WINDOW (dialog), TRUE);
212
213 widget = e_table_field_chooser_new ();
214 e_table_field_chooser_dialog->etfc = E_TABLE_FIELD_CHOOSER (widget);
215
216 g_object_set (
217 widget,
218 "dnd_code", e_table_field_chooser_dialog->dnd_code,
219 "full_header", e_table_field_chooser_dialog->full_header,
220 "header", e_table_field_chooser_dialog->header,
221 NULL);
222
223 content_area = gtk_dialog_get_content_area (dialog);
224 gtk_box_pack_start (GTK_BOX (content_area), widget, TRUE, TRUE, 0);
225
226 gtk_widget_show (GTK_WIDGET (widget));
227
228 gtk_window_set_title (GTK_WINDOW (dialog), _("Add a Column"));
229 }
230
231 GtkWidget *
232 e_table_field_chooser_dialog_new (void)
233 {
234 return g_object_new (E_TYPE_TABLE_FIELD_CHOOSER_DIALOG, NULL);
235 }