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
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
)
43 static guint signals
[LAST_SIGNAL
] = {0};
45 struct _EmpathyBadPasswordDialogPriv
{
50 empathy_bad_password_dialog_get_property (GObject
*object
,
55 EmpathyBadPasswordDialog
*self
= (EmpathyBadPasswordDialog
*) object
;
60 g_value_set_string (value
, self
->priv
->password
);
63 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
69 empathy_bad_password_dialog_set_property (GObject
*object
,
74 EmpathyBadPasswordDialog
*self
= (EmpathyBadPasswordDialog
*) object
;
79 g_assert (self
->priv
->password
== NULL
); /* construct only */
80 self
->priv
->password
= g_value_dup_string (value
);
83 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
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
);
99 bad_password_dialog_response_cb (GtkDialog
*dialog
,
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
));
119 empathy_bad_password_dialog_constructed (GObject
*object
)
121 EmpathyBadPasswordDialog
*self
= (EmpathyBadPasswordDialog
*) object
;
122 EmpathyBasePasswordDialog
*base
= (EmpathyBasePasswordDialog
*) object
;
125 G_OBJECT_CLASS (empathy_bad_password_dialog_parent_class
)->constructed (
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
);
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
);
147 empathy_bad_password_dialog_init (EmpathyBadPasswordDialog
*self
)
149 self
->priv
= G_TYPE_INSTANCE_GET_PRIVATE (self
,
150 EMPATHY_TYPE_BAD_PASSWORD_DIALOG
, EmpathyBadPasswordDialogPriv
);
154 empathy_bad_password_dialog_class_init (EmpathyBadPasswordDialogClass
*klass
)
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",
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,
176 g_cclosure_marshal_generic
,
177 G_TYPE_NONE
, 2, TP_TYPE_ACCOUNT
, G_TYPE_STRING
);
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
,
188 "password", password
,