Updated Spanish translation
[empathy-mirror.git] / libempathy-gtk / empathy-bad-password-dialog.c
blob2209ff064570c7bb8d7b19074c1939c67d5f3a0c
1 /*
2 * empathy-bad-password-dialog.c - Source for EmpathyBadPasswordDialog
3 * Copyright (C) 2010 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <config.h>
22 #include "empathy-bad-password-dialog.h"
24 #include <glib/gi18n-lib.h>
26 #define DEBUG_FLAG EMPATHY_DEBUG_SASL
27 #include <libempathy/empathy-debug.h>
28 #include <libempathy/empathy-utils.h>
30 G_DEFINE_TYPE (EmpathyBadPasswordDialog, empathy_bad_password_dialog,
31 EMPATHY_TYPE_BASE_PASSWORD_DIALOG)
33 enum {
34 PROP_PASSWORD = 1,
36 LAST_PROPERTY,
39 /* signal enum */
40 enum {
41 RETRY,
42 LAST_SIGNAL,
45 static guint signals[LAST_SIGNAL] = {0};
47 struct _EmpathyBadPasswordDialogPriv {
48 gchar *password;
51 static void
52 empathy_bad_password_dialog_get_property (GObject *object,
53 guint property_id,
54 GValue *value,
55 GParamSpec *pspec)
57 EmpathyBadPasswordDialog *self = (EmpathyBadPasswordDialog *) object;
59 switch (property_id)
61 case PROP_PASSWORD:
62 g_value_set_string (value, self->priv->password);
63 break;
64 default:
65 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
66 break;
70 static void
71 empathy_bad_password_dialog_set_property (GObject *object,
72 guint property_id,
73 const GValue *value,
74 GParamSpec *pspec)
76 EmpathyBadPasswordDialog *self = (EmpathyBadPasswordDialog *) object;
78 switch (property_id)
80 case PROP_PASSWORD:
81 g_assert (self->priv->password == NULL); /* construct only */
82 self->priv->password = g_value_dup_string (value);
83 break;
84 default:
85 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
86 break;
90 static void
91 empathy_bad_password_dialog_finalize (GObject *object)
93 EmpathyBadPasswordDialog *self = (EmpathyBadPasswordDialog *) object;
95 tp_clear_pointer (&self->priv->password, g_free);
97 G_OBJECT_CLASS (empathy_bad_password_dialog_parent_class)->finalize (object);
100 static void
101 bad_password_dialog_response_cb (GtkDialog *dialog,
102 gint response,
103 gpointer user_data)
105 EmpathyBadPasswordDialog *self = (EmpathyBadPasswordDialog *) dialog;
106 EmpathyBasePasswordDialog *base = (EmpathyBasePasswordDialog *) dialog;
108 if (response == GTK_RESPONSE_OK)
110 const gchar *password;
112 password = gtk_entry_get_text (GTK_ENTRY (base->entry));
114 g_signal_emit (self, signals[RETRY], 0, base->account, password);
117 gtk_widget_destroy (GTK_WIDGET (dialog));
120 static void
121 empathy_bad_password_dialog_constructed (GObject *object)
123 EmpathyBadPasswordDialog *self = (EmpathyBadPasswordDialog *) object;
124 EmpathyBasePasswordDialog *base = (EmpathyBasePasswordDialog *) object;
125 gchar *text;
127 G_OBJECT_CLASS (empathy_bad_password_dialog_parent_class)->constructed (
128 object);
130 text = g_strdup_printf (_("Authentification failed for account <b>%s</b>"),
131 tp_account_get_display_name (base->account));
132 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (self), text);
133 g_free (text);
135 if (self->priv->password != NULL)
137 gtk_entry_set_text (GTK_ENTRY (base->entry), self->priv->password);
139 gtk_editable_select_region (GTK_EDITABLE (base->entry), 0, -1);
142 gtk_button_set_label (GTK_BUTTON (base->ok_button), _("Retry"));
144 g_signal_connect (self, "response",
145 G_CALLBACK (bad_password_dialog_response_cb), self);
148 static void
149 empathy_bad_password_dialog_init (EmpathyBadPasswordDialog *self)
151 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
152 EMPATHY_TYPE_BAD_PASSWORD_DIALOG, EmpathyBadPasswordDialogPriv);
155 static void
156 empathy_bad_password_dialog_class_init (EmpathyBadPasswordDialogClass *klass)
158 GParamSpec *pspec;
159 GObjectClass *oclass = G_OBJECT_CLASS (klass);
161 g_type_class_add_private (klass, sizeof (EmpathyBadPasswordDialogPriv));
163 oclass->set_property = empathy_bad_password_dialog_set_property;
164 oclass->get_property = empathy_bad_password_dialog_get_property;
165 oclass->finalize = empathy_bad_password_dialog_finalize;
166 oclass->constructed = empathy_bad_password_dialog_constructed;
168 pspec = g_param_spec_string ("password", "Password",
169 "The wrong password",
170 NULL,
171 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
172 g_object_class_install_property (oclass, PROP_PASSWORD, pspec);
174 signals[RETRY] = g_signal_new ("retry",
175 G_TYPE_FROM_CLASS (klass),
176 G_SIGNAL_RUN_LAST, 0,
177 NULL, NULL,
178 g_cclosure_marshal_generic,
179 G_TYPE_NONE, 2, TP_TYPE_ACCOUNT, G_TYPE_STRING);
182 GtkWidget *
183 empathy_bad_password_dialog_new (TpAccount *account,
184 const gchar *password)
186 g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL);
188 return g_object_new (EMPATHY_TYPE_BAD_PASSWORD_DIALOG,
189 "account", account,
190 "password", password,
191 NULL);