2 * empathy-base-password-dialog.c - Source for EmpathyBasePasswordDialog
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-base-password-dialog.h"
23 #include <glib/gi18n-lib.h>
24 #include <tp-account-widgets/tpaw-utils.h>
26 #include "empathy-utils.h"
28 #define DEBUG_FLAG EMPATHY_DEBUG_SASL
29 #include "empathy-debug.h"
31 G_DEFINE_TYPE (EmpathyBasePasswordDialog
, empathy_base_password_dialog
,
32 GTK_TYPE_MESSAGE_DIALOG
)
40 struct _EmpathyBasePasswordDialogPriv
{
45 empathy_base_password_dialog_get_property (GObject
*object
,
50 EmpathyBasePasswordDialog
*self
= (EmpathyBasePasswordDialog
*) object
;
55 g_value_set_object (value
, self
->account
);
58 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
64 empathy_base_password_dialog_set_property (GObject
*object
,
69 EmpathyBasePasswordDialog
*self
= (EmpathyBasePasswordDialog
*) object
;
74 g_assert (self
->account
== NULL
); /* construct only */
75 self
->account
= g_value_dup_object (value
);
78 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
84 empathy_base_password_dialog_dispose (GObject
*object
)
86 EmpathyBasePasswordDialog
*self
= (EmpathyBasePasswordDialog
*) object
;
88 tp_clear_object (&self
->account
);
90 G_OBJECT_CLASS (empathy_base_password_dialog_parent_class
)->dispose (object
);
94 clear_icon_released_cb (GtkEntry
*entry
,
95 GtkEntryIconPosition icon_pos
,
99 gtk_entry_set_text (entry
, "");
103 password_entry_changed_cb (GtkEditable
*entry
,
106 EmpathyBasePasswordDialog
*self
= user_data
;
109 str
= gtk_entry_get_text (GTK_ENTRY (entry
));
111 gtk_entry_set_icon_sensitive (GTK_ENTRY (entry
),
112 GTK_ENTRY_ICON_SECONDARY
, !TPAW_STR_EMPTY (str
));
114 gtk_widget_set_sensitive (self
->ok_button
,
115 !TPAW_STR_EMPTY (str
));
119 password_entry_activate_cb (GtkEntry
*entry
,
120 EmpathyBasePasswordDialog
*self
)
122 gtk_dialog_response (GTK_DIALOG (self
), GTK_RESPONSE_OK
);
126 base_password_dialog_grab_keyboard (GtkWidget
*widget
,
130 EmpathyBasePasswordDialog
*self
= user_data
;
132 if (!self
->priv
->grabbing
)
134 GdkDevice
*device
= gdk_event_get_device (event
);
138 GdkGrabStatus status
= gdk_device_grab (device
,
139 gtk_widget_get_window (widget
),
140 GDK_OWNERSHIP_WINDOW
,
144 gdk_event_get_time (event
));
146 if (status
!= GDK_GRAB_SUCCESS
)
147 DEBUG ("Could not grab keyboard; grab status was %u", status
);
149 self
->priv
->grabbing
= TRUE
;
152 DEBUG ("Could not get the event device!");
159 base_password_dialog_ungrab_keyboard (GtkWidget
*widget
,
163 EmpathyBasePasswordDialog
*self
= user_data
;
165 if (self
->priv
->grabbing
)
167 GdkDevice
*device
= gdk_event_get_device (event
);
171 gdk_device_ungrab (device
, gdk_event_get_time (event
));
172 self
->priv
->grabbing
= FALSE
;
175 DEBUG ("Could not get the event device!");
182 base_password_dialog_window_state_changed (GtkWidget
*widget
,
183 GdkEventWindowState
*event
,
186 GdkWindowState state
= gdk_window_get_state (gtk_widget_get_window (widget
));
188 if (state
& GDK_WINDOW_STATE_WITHDRAWN
189 || state
& GDK_WINDOW_STATE_ICONIFIED
190 || state
& GDK_WINDOW_STATE_FULLSCREEN
191 || state
& GDK_WINDOW_STATE_MAXIMIZED
)
193 base_password_dialog_ungrab_keyboard (widget
, (GdkEvent
*) event
, data
);
197 base_password_dialog_grab_keyboard (widget
, (GdkEvent
*) event
, data
);
204 empathy_base_password_dialog_constructed (GObject
*object
)
206 EmpathyBasePasswordDialog
*self
;
211 self
= EMPATHY_BASE_PASSWORD_DIALOG (object
);
213 g_assert (self
->account
!= NULL
);
215 self
->priv
->grabbing
= FALSE
;
218 gtk_dialog_add_button (GTK_DIALOG (self
),
219 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
);
221 self
->ok_button
= gtk_dialog_add_button (GTK_DIALOG (self
),
222 GTK_STOCK_OK
, GTK_RESPONSE_OK
);
223 gtk_widget_set_sensitive (self
->ok_button
, FALSE
);
225 text
= g_strdup_printf (_("Enter your password for account\n<b>%s</b>"),
226 tp_account_get_display_name (self
->account
));
227 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (self
), text
);
230 gtk_window_set_icon_name (GTK_WINDOW (self
),
231 GTK_STOCK_DIALOG_AUTHENTICATION
);
233 box
= GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (self
)));
236 icon
= gtk_image_new_from_icon_name (
237 tp_account_get_icon_name (self
->account
), GTK_ICON_SIZE_DIALOG
);
238 gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (self
), icon
);
239 gtk_widget_show (icon
);
242 self
->entry
= gtk_entry_new ();
243 gtk_entry_set_visibility (GTK_ENTRY (self
->entry
), FALSE
);
245 /* entry clear icon */
246 gtk_entry_set_icon_from_stock (GTK_ENTRY (self
->entry
),
247 GTK_ENTRY_ICON_SECONDARY
, GTK_STOCK_CLEAR
);
248 gtk_entry_set_icon_sensitive (GTK_ENTRY (self
->entry
),
249 GTK_ENTRY_ICON_SECONDARY
, FALSE
);
251 g_signal_connect (self
->entry
, "icon-release",
252 G_CALLBACK (clear_icon_released_cb
), NULL
);
253 g_signal_connect (self
->entry
, "changed",
254 G_CALLBACK (password_entry_changed_cb
), self
);
255 g_signal_connect (self
->entry
, "activate",
256 G_CALLBACK (password_entry_activate_cb
), self
);
258 gtk_box_pack_start (box
, self
->entry
, FALSE
, FALSE
, 0);
259 gtk_widget_show (self
->entry
);
261 /* remember password ticky box */
262 self
->ticky
= gtk_check_button_new_with_label (_("Remember password"));
264 gtk_box_pack_start (box
, self
->ticky
, FALSE
, FALSE
, 0);
266 g_signal_connect (self
, "window-state-event",
267 G_CALLBACK (base_password_dialog_window_state_changed
), self
);
268 g_signal_connect (self
, "map-event",
269 G_CALLBACK (base_password_dialog_grab_keyboard
), self
);
270 g_signal_connect (self
, "unmap-event",
271 G_CALLBACK (base_password_dialog_ungrab_keyboard
), self
);
273 gtk_widget_grab_focus (self
->entry
);
275 gtk_window_set_position (GTK_WINDOW (self
), GTK_WIN_POS_CENTER_ALWAYS
);
277 gtk_window_set_keep_above (GTK_WINDOW (self
), TRUE
);
281 empathy_base_password_dialog_init (EmpathyBasePasswordDialog
*self
)
283 self
->priv
= G_TYPE_INSTANCE_GET_PRIVATE (self
,
284 EMPATHY_TYPE_BASE_PASSWORD_DIALOG
, EmpathyBasePasswordDialogPriv
);
288 empathy_base_password_dialog_class_init (EmpathyBasePasswordDialogClass
*klass
)
291 GObjectClass
*oclass
= G_OBJECT_CLASS (klass
);
293 g_type_class_add_private (klass
, sizeof (EmpathyBasePasswordDialogPriv
));
295 oclass
->set_property
= empathy_base_password_dialog_set_property
;
296 oclass
->get_property
= empathy_base_password_dialog_get_property
;
297 oclass
->dispose
= empathy_base_password_dialog_dispose
;
298 oclass
->constructed
= empathy_base_password_dialog_constructed
;
300 pspec
= g_param_spec_object ("account", "The TpAccount",
301 "The TpAccount to be used.",
303 G_PARAM_CONSTRUCT_ONLY
| G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
);
304 g_object_class_install_property (oclass
, PROP_ACCOUNT
, pspec
);