2 * e-mail-label-dialog.c
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
25 #include "e-mail-label-dialog.h"
27 #include <glib/gi18n.h>
29 #define E_MAIL_LABEL_DIALOG_GET_PRIVATE(obj) \
30 (G_TYPE_INSTANCE_GET_PRIVATE \
31 ((obj), E_TYPE_MAIL_LABEL_DIALOG, EMailLabelDialogPrivate))
33 struct _EMailLabelDialogPrivate
{
44 G_DEFINE_TYPE (EMailLabelDialog
, e_mail_label_dialog
, GTK_TYPE_DIALOG
)
47 mail_label_dialog_entry_changed_cb (EMailLabelDialog
*dialog
)
52 text
= gtk_entry_get_text (GTK_ENTRY (dialog
->priv
->entry
));
53 sensitive
= (text
!= NULL
&& *text
!= '\0');
55 gtk_dialog_set_response_sensitive (
56 GTK_DIALOG (dialog
), GTK_RESPONSE_OK
, sensitive
);
60 mail_label_dialog_set_property (GObject
*object
,
65 switch (property_id
) {
66 case PROP_LABEL_COLOR
:
67 e_mail_label_dialog_set_label_color (
68 E_MAIL_LABEL_DIALOG (object
),
69 g_value_get_boxed (value
));
73 e_mail_label_dialog_set_label_name (
74 E_MAIL_LABEL_DIALOG (object
),
75 g_value_get_string (value
));
79 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
83 mail_label_dialog_get_property (GObject
*object
,
90 switch (property_id
) {
91 case PROP_LABEL_COLOR
:
92 e_mail_label_dialog_get_label_color (
93 E_MAIL_LABEL_DIALOG (object
), &color
);
94 g_value_set_boxed (value
, &color
);
99 value
, e_mail_label_dialog_get_label_name (
100 E_MAIL_LABEL_DIALOG (object
)));
104 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
108 mail_label_dialog_dispose (GObject
*object
)
110 EMailLabelDialogPrivate
*priv
;
112 priv
= E_MAIL_LABEL_DIALOG_GET_PRIVATE (object
);
114 if (priv
->entry
!= NULL
) {
115 g_object_unref (priv
->entry
);
119 if (priv
->colorsel
!= NULL
) {
120 g_object_unref (priv
->colorsel
);
121 priv
->colorsel
= NULL
;
124 /* Chain up to parent's dispose() method. */
125 G_OBJECT_CLASS (e_mail_label_dialog_parent_class
)->dispose (object
);
129 mail_label_dialog_constructed (GObject
*object
)
131 GtkWidget
*action_area
;
132 GtkWidget
*content_area
;
134 /* XXX Override GTK's style property defaults for GtkDialog.
135 * Hopefully GTK+ 3.0 will fix the broken defaults. */
137 action_area
= gtk_dialog_get_action_area (GTK_DIALOG (object
));
138 content_area
= gtk_dialog_get_content_area (GTK_DIALOG (object
));
140 gtk_box_set_spacing (GTK_BOX (content_area
), 12);
141 gtk_container_set_border_width (GTK_CONTAINER (object
), 12);
142 gtk_container_set_border_width (GTK_CONTAINER (action_area
), 0);
143 gtk_container_set_border_width (GTK_CONTAINER (content_area
), 0);
145 /* Chain up to parent's constructed() method. */
146 G_OBJECT_CLASS (e_mail_label_dialog_parent_class
)->constructed (object
);
150 e_mail_label_dialog_class_init (EMailLabelDialogClass
*class)
152 GObjectClass
*object_class
;
154 g_type_class_add_private (class, sizeof (EMailLabelDialogPrivate
));
156 object_class
= G_OBJECT_CLASS (class);
157 object_class
->set_property
= mail_label_dialog_set_property
;
158 object_class
->get_property
= mail_label_dialog_get_property
;
159 object_class
->dispose
= mail_label_dialog_dispose
;
160 object_class
->constructed
= mail_label_dialog_constructed
;
162 g_object_class_install_property (
172 g_object_class_install_property (
175 g_param_spec_string (
184 e_mail_label_dialog_init (EMailLabelDialog
*dialog
)
186 GtkWidget
*content_area
;
187 GtkWidget
*container
;
190 dialog
->priv
= E_MAIL_LABEL_DIALOG_GET_PRIVATE (dialog
);
192 content_area
= gtk_dialog_get_content_area (GTK_DIALOG (dialog
));
194 gtk_dialog_add_button (
196 _("_Cancel"), GTK_RESPONSE_CANCEL
);
198 gtk_dialog_add_button (
200 _("OK"), GTK_RESPONSE_OK
);
202 gtk_dialog_set_default_response (GTK_DIALOG (dialog
), GTK_RESPONSE_OK
);
204 container
= content_area
;
206 widget
= gtk_box_new (GTK_ORIENTATION_HORIZONTAL
, 6);
207 gtk_box_pack_start (GTK_BOX (container
), widget
, FALSE
, FALSE
, 0);
208 gtk_widget_show (widget
);
212 widget
= gtk_entry_new ();
213 gtk_entry_set_activates_default (GTK_ENTRY (widget
), TRUE
);
214 gtk_box_pack_end (GTK_BOX (container
), widget
, TRUE
, TRUE
, 0);
215 dialog
->priv
->entry
= g_object_ref (widget
);
216 gtk_widget_show (widget
);
218 g_signal_connect_swapped (
220 G_CALLBACK (mail_label_dialog_entry_changed_cb
), dialog
);
222 mail_label_dialog_entry_changed_cb (dialog
);
224 widget
= gtk_label_new_with_mnemonic (_("_Label name:"));
225 gtk_label_set_mnemonic_widget (
226 GTK_LABEL (widget
), dialog
->priv
->entry
);
227 gtk_box_pack_end (GTK_BOX (container
), widget
, FALSE
, FALSE
, 0);
228 gtk_widget_show (widget
);
230 container
= content_area
;
232 widget
= gtk_color_selection_new ();
233 gtk_box_pack_start (GTK_BOX (container
), widget
, FALSE
, FALSE
, 0);
234 dialog
->priv
->colorsel
= g_object_ref (widget
);
235 gtk_widget_show (widget
);
239 e_mail_label_dialog_new (GtkWindow
*parent
)
241 return g_object_new (
242 E_TYPE_MAIL_LABEL_DIALOG
,
243 "transient-for", parent
, NULL
);
247 e_mail_label_dialog_get_label_name (EMailLabelDialog
*dialog
)
251 g_return_val_if_fail (E_IS_MAIL_LABEL_DIALOG (dialog
), NULL
);
253 entry
= GTK_ENTRY (dialog
->priv
->entry
);
255 return gtk_entry_get_text (entry
);
259 e_mail_label_dialog_set_label_name (EMailLabelDialog
*dialog
,
260 const gchar
*label_name
)
264 g_return_if_fail (E_IS_MAIL_LABEL_DIALOG (dialog
));
266 entry
= GTK_ENTRY (dialog
->priv
->entry
);
268 if (g_strcmp0 (gtk_entry_get_text (entry
), label_name
) == 0)
271 gtk_entry_set_text (entry
, label_name
);
273 g_object_notify (G_OBJECT (dialog
), "label-name");
277 e_mail_label_dialog_get_label_color (EMailLabelDialog
*dialog
,
278 GdkColor
*label_color
)
280 GtkColorSelection
*colorsel
;
282 g_return_if_fail (E_IS_MAIL_LABEL_DIALOG (dialog
));
283 g_return_if_fail (label_color
!= NULL
);
285 colorsel
= GTK_COLOR_SELECTION (dialog
->priv
->colorsel
);
287 gtk_color_selection_get_current_color (colorsel
, label_color
);
291 e_mail_label_dialog_set_label_color (EMailLabelDialog
*dialog
,
292 const GdkColor
*label_color
)
294 GtkColorSelection
*colorsel
;
296 g_return_if_fail (E_IS_MAIL_LABEL_DIALOG (dialog
));
297 g_return_if_fail (label_color
!= NULL
);
299 colorsel
= GTK_COLOR_SELECTION (dialog
->priv
->colorsel
);
301 gtk_color_selection_set_current_color (colorsel
, label_color
);
303 g_object_notify (G_OBJECT (dialog
), "label-color");