]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-bad-password-dialog.c
individual_view_drag_end: remove the auto scroll
[empathy.git] / libempathy-gtk / empathy-bad-password-dialog.c
1 /*
2  * empathy-bad-password-dialog.c - Source for EmpathyBadPasswordDialog
3  * Copyright (C) 2010 Collabora Ltd.
4  *
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.
9  *
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.
14  *
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
18  */
19
20 #include <config.h>
21
22 #include "empathy-bad-password-dialog.h"
23
24 #include <glib/gi18n-lib.h>
25
26 #define DEBUG_FLAG EMPATHY_DEBUG_SASL
27 #include <libempathy/empathy-debug.h>
28 #include <libempathy/empathy-utils.h>
29
30 G_DEFINE_TYPE (EmpathyBadPasswordDialog, empathy_bad_password_dialog,
31     EMPATHY_TYPE_BASE_PASSWORD_DIALOG)
32
33 enum {
34   PROP_PASSWORD = 1,
35
36   LAST_PROPERTY,
37 };
38
39 /* signal enum */
40 enum {
41   RETRY,
42   LAST_SIGNAL,
43 };
44
45 static guint signals[LAST_SIGNAL] = {0};
46
47 struct _EmpathyBadPasswordDialogPriv {
48   gchar *password;
49 };
50
51 static void
52 empathy_bad_password_dialog_get_property (GObject *object,
53     guint property_id,
54     GValue *value,
55     GParamSpec *pspec)
56 {
57   EmpathyBadPasswordDialog *self = (EmpathyBadPasswordDialog *) object;
58
59   switch (property_id)
60     {
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;
67     }
68 }
69
70 static void
71 empathy_bad_password_dialog_set_property (GObject *object,
72     guint property_id,
73     const GValue *value,
74     GParamSpec *pspec)
75 {
76   EmpathyBadPasswordDialog *self = (EmpathyBadPasswordDialog *) object;
77
78   switch (property_id)
79     {
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;
87     }
88 }
89
90 static void
91 empathy_bad_password_dialog_finalize (GObject *object)
92 {
93   EmpathyBadPasswordDialog *self = (EmpathyBadPasswordDialog *) object;
94
95   tp_clear_pointer (&self->priv->password, g_free);
96
97   G_OBJECT_CLASS (empathy_bad_password_dialog_parent_class)->finalize (object);
98 }
99
100 static void
101 bad_password_dialog_response_cb (GtkDialog *dialog,
102     gint response,
103     gpointer user_data)
104 {
105   EmpathyBadPasswordDialog *self = (EmpathyBadPasswordDialog *) dialog;
106   EmpathyBasePasswordDialog *base = (EmpathyBasePasswordDialog *) dialog;
107
108   if (response == GTK_RESPONSE_OK)
109     {
110       const gchar *password;
111
112       password = gtk_entry_get_text (GTK_ENTRY (base->entry));
113
114       g_signal_emit (self, signals[RETRY], 0, base->account, password);
115     }
116
117   gtk_widget_destroy (GTK_WIDGET (dialog));
118 }
119
120 static void
121 empathy_bad_password_dialog_constructed (GObject *object)
122 {
123   EmpathyBadPasswordDialog *self = (EmpathyBadPasswordDialog *) object;
124   EmpathyBasePasswordDialog *base = (EmpathyBasePasswordDialog *) object;
125   gchar *text;
126
127   G_OBJECT_CLASS (empathy_bad_password_dialog_parent_class)->constructed (
128       object);
129
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);
134
135   if (self->priv->password != NULL)
136     {
137       gtk_entry_set_text (GTK_ENTRY (base->entry), self->priv->password);
138
139       gtk_editable_select_region (GTK_EDITABLE (base->entry), 0, -1);
140     }
141
142   gtk_button_set_label (GTK_BUTTON (base->ok_button), _("Retry"));
143
144   g_signal_connect (self, "response",
145       G_CALLBACK (bad_password_dialog_response_cb), self);
146 }
147
148 static void
149 empathy_bad_password_dialog_init (EmpathyBadPasswordDialog *self)
150 {
151   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
152       EMPATHY_TYPE_BAD_PASSWORD_DIALOG, EmpathyBadPasswordDialogPriv);
153 }
154
155 static void
156 empathy_bad_password_dialog_class_init (EmpathyBadPasswordDialogClass *klass)
157 {
158   GParamSpec *pspec;
159   GObjectClass *oclass = G_OBJECT_CLASS (klass);
160
161   g_type_class_add_private (klass, sizeof (EmpathyBadPasswordDialogPriv));
162
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;
167
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);
173
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);
180 }
181
182 GtkWidget *
183 empathy_bad_password_dialog_new (TpAccount *account,
184     const gchar *password)
185 {
186   g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL);
187
188   return g_object_new (EMPATHY_TYPE_BAD_PASSWORD_DIALOG,
189       "account", account,
190       "password", password,
191       NULL);
192 }