Updated Hungarian translation
[evolution.git] / mail / e-mail-label-dialog.c
blobeb02461baaa05138ffd269c74edd064437bca0d2
1 /*
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
11 * for more details.
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)
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
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 {
34 GtkWidget *entry;
35 GtkWidget *colorsel;
38 enum {
39 PROP_0,
40 PROP_LABEL_COLOR,
41 PROP_LABEL_NAME
44 G_DEFINE_TYPE (EMailLabelDialog, e_mail_label_dialog, GTK_TYPE_DIALOG)
46 static void
47 mail_label_dialog_entry_changed_cb (EMailLabelDialog *dialog)
49 const gchar *text;
50 gboolean sensitive;
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);
59 static void
60 mail_label_dialog_set_property (GObject *object,
61 guint property_id,
62 const GValue *value,
63 GParamSpec *pspec)
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));
70 return;
72 case PROP_LABEL_NAME:
73 e_mail_label_dialog_set_label_name (
74 E_MAIL_LABEL_DIALOG (object),
75 g_value_get_string (value));
76 return;
79 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
82 static void
83 mail_label_dialog_get_property (GObject *object,
84 guint property_id,
85 GValue *value,
86 GParamSpec *pspec)
88 GdkColor color;
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);
95 return;
97 case PROP_LABEL_NAME:
98 g_value_set_string (
99 value, e_mail_label_dialog_get_label_name (
100 E_MAIL_LABEL_DIALOG (object)));
101 return;
104 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
107 static void
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);
116 priv->entry = NULL;
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);
128 static void
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);
149 static void
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 (
163 object_class,
164 PROP_LABEL_COLOR,
165 g_param_spec_boxed (
166 "label-color",
167 "Label Color",
168 NULL,
169 GDK_TYPE_COLOR,
170 G_PARAM_READWRITE));
172 g_object_class_install_property (
173 object_class,
174 PROP_LABEL_NAME,
175 g_param_spec_string (
176 "label-name",
177 "Label Name",
178 NULL,
179 NULL,
180 G_PARAM_READWRITE));
183 static void
184 e_mail_label_dialog_init (EMailLabelDialog *dialog)
186 GtkWidget *content_area;
187 GtkWidget *container;
188 GtkWidget *widget;
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 (
195 GTK_DIALOG (dialog),
196 _("_Cancel"), GTK_RESPONSE_CANCEL);
198 gtk_dialog_add_button (
199 GTK_DIALOG (dialog),
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);
210 container = 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 (
219 widget, "changed",
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);
238 GtkWidget *
239 e_mail_label_dialog_new (GtkWindow *parent)
241 return g_object_new (
242 E_TYPE_MAIL_LABEL_DIALOG,
243 "transient-for", parent, NULL);
246 const gchar *
247 e_mail_label_dialog_get_label_name (EMailLabelDialog *dialog)
249 GtkEntry *entry;
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);
258 void
259 e_mail_label_dialog_set_label_name (EMailLabelDialog *dialog,
260 const gchar *label_name)
262 GtkEntry *entry;
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)
269 return;
271 gtk_entry_set_text (entry, label_name);
273 g_object_notify (G_OBJECT (dialog), "label-name");
276 void
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);
290 void
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");