Updated Friulian translation
[empathy-mirror.git] / libempathy-gtk / empathy-bad-password-dialog.c
blob5cdb90d1eeadbfcb7e671c6d280abcb26627fadb
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"
21 #include "empathy-bad-password-dialog.h"
23 #include <glib/gi18n-lib.h>
25 #define DEBUG_FLAG EMPATHY_DEBUG_SASL
26 #include "empathy-debug.h"
28 G_DEFINE_TYPE (EmpathyBadPasswordDialog, empathy_bad_password_dialog,
29 EMPATHY_TYPE_BASE_PASSWORD_DIALOG)
31 enum {
32 PROP_PASSWORD = 1,
34 LAST_PROPERTY,
37 /* signal enum */
38 enum {
39 RETRY,
40 LAST_SIGNAL,
43 static guint signals[LAST_SIGNAL] = {0};
45 struct _EmpathyBadPasswordDialogPriv {
46 gchar *password;
49 static void
50 empathy_bad_password_dialog_get_property (GObject *object,
51 guint property_id,
52 GValue *value,
53 GParamSpec *pspec)
55 EmpathyBadPasswordDialog *self = (EmpathyBadPasswordDialog *) object;
57 switch (property_id)
59 case PROP_PASSWORD:
60 g_value_set_string (value, self->priv->password);
61 break;
62 default:
63 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
64 break;
68 static void
69 empathy_bad_password_dialog_set_property (GObject *object,
70 guint property_id,
71 const GValue *value,
72 GParamSpec *pspec)
74 EmpathyBadPasswordDialog *self = (EmpathyBadPasswordDialog *) object;
76 switch (property_id)
78 case PROP_PASSWORD:
79 g_assert (self->priv->password == NULL); /* construct only */
80 self->priv->password = g_value_dup_string (value);
81 break;
82 default:
83 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
84 break;
88 static void
89 empathy_bad_password_dialog_finalize (GObject *object)
91 EmpathyBadPasswordDialog *self = (EmpathyBadPasswordDialog *) object;
93 tp_clear_pointer (&self->priv->password, g_free);
95 G_OBJECT_CLASS (empathy_bad_password_dialog_parent_class)->finalize (object);
98 static void
99 bad_password_dialog_response_cb (GtkDialog *dialog,
100 gint response,
101 gpointer user_data)
103 EmpathyBadPasswordDialog *self = (EmpathyBadPasswordDialog *) dialog;
104 EmpathyBasePasswordDialog *base = (EmpathyBasePasswordDialog *) dialog;
106 if (response == GTK_RESPONSE_OK)
108 const gchar *password;
110 password = gtk_entry_get_text (GTK_ENTRY (base->entry));
112 g_signal_emit (self, signals[RETRY], 0, base->account, password);
115 gtk_widget_destroy (GTK_WIDGET (dialog));
118 static void
119 empathy_bad_password_dialog_constructed (GObject *object)
121 EmpathyBadPasswordDialog *self = (EmpathyBadPasswordDialog *) object;
122 EmpathyBasePasswordDialog *base = (EmpathyBasePasswordDialog *) object;
123 gchar *text;
125 G_OBJECT_CLASS (empathy_bad_password_dialog_parent_class)->constructed (
126 object);
128 text = g_strdup_printf (_("Authentication failed for account <b>%s</b>"),
129 tp_account_get_display_name (base->account));
130 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (self), text);
131 g_free (text);
133 if (self->priv->password != NULL)
135 gtk_entry_set_text (GTK_ENTRY (base->entry), self->priv->password);
137 gtk_editable_select_region (GTK_EDITABLE (base->entry), 0, -1);
140 gtk_button_set_label (GTK_BUTTON (base->ok_button), _("Retry"));
142 g_signal_connect (self, "response",
143 G_CALLBACK (bad_password_dialog_response_cb), self);
146 static void
147 empathy_bad_password_dialog_init (EmpathyBadPasswordDialog *self)
149 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
150 EMPATHY_TYPE_BAD_PASSWORD_DIALOG, EmpathyBadPasswordDialogPriv);
153 static void
154 empathy_bad_password_dialog_class_init (EmpathyBadPasswordDialogClass *klass)
156 GParamSpec *pspec;
157 GObjectClass *oclass = G_OBJECT_CLASS (klass);
159 g_type_class_add_private (klass, sizeof (EmpathyBadPasswordDialogPriv));
161 oclass->set_property = empathy_bad_password_dialog_set_property;
162 oclass->get_property = empathy_bad_password_dialog_get_property;
163 oclass->finalize = empathy_bad_password_dialog_finalize;
164 oclass->constructed = empathy_bad_password_dialog_constructed;
166 pspec = g_param_spec_string ("password", "Password",
167 "The wrong password",
168 NULL,
169 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
170 g_object_class_install_property (oclass, PROP_PASSWORD, pspec);
172 signals[RETRY] = g_signal_new ("retry",
173 G_TYPE_FROM_CLASS (klass),
174 G_SIGNAL_RUN_LAST, 0,
175 NULL, NULL,
176 g_cclosure_marshal_generic,
177 G_TYPE_NONE, 2, TP_TYPE_ACCOUNT, G_TYPE_STRING);
180 GtkWidget *
181 empathy_bad_password_dialog_new (TpAccount *account,
182 const gchar *password)
184 g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL);
186 return g_object_new (EMPATHY_TYPE_BAD_PASSWORD_DIALOG,
187 "account", account,
188 "password", password,
189 NULL);