aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/empathy-auth-client.c180
1 files changed, 4 insertions, 176 deletions
diff --git a/src/empathy-auth-client.c b/src/empathy-auth-client.c
index d4e1cd64a..f6cc9def8 100644
--- a/src/empathy-auth-client.c
+++ b/src/empathy-auth-client.c
@@ -34,6 +34,7 @@
#include <libempathy/empathy-tls-verifier.h>
#include <libempathy/empathy-utils.h>
+#include <libempathy-gtk/empathy-password-dialog.h>
#include <libempathy-gtk/empathy-tls-dialog.h>
#include <libempathy-gtk/empathy-ui-utils.h>
@@ -206,191 +207,18 @@ auth_factory_new_tls_handler_cb (EmpathyAuthFactory *factory,
g_free (hostname);
}
-typedef struct
-{
- EmpathyServerSASLHandler *handler;
- GtkWidget *entry;
- GtkWidget *ticky;
-} PasswordDialogData;
-
-static void
-password_dialog_response_cb (GtkDialog *dialog,
- gint response,
- gpointer user_data)
-{
- PasswordDialogData *data = user_data;
-
- if (response == GTK_RESPONSE_OK)
- {
- empathy_server_sasl_handler_provide_password (data->handler,
- gtk_entry_get_text (GTK_ENTRY (data->entry)),
- gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->ticky)));
- }
- else
- {
- empathy_server_sasl_handler_cancel (data->handler);
- }
-
- gtk_widget_destroy (GTK_WIDGET (dialog));
-
- g_object_unref (data->handler);
- g_slice_free (PasswordDialogData, data);
-}
-
-static void
-clear_icon_released_cb (GtkEntry *entry,
- GtkEntryIconPosition icon_pos,
- GdkEvent *event,
- gpointer user_data)
-{
- gtk_entry_set_text (entry, "");
-}
-
-static void
-password_entry_changed_cb (GtkEditable *entry,
- gpointer user_data)
-{
- const gchar *str;
-
- str = gtk_entry_get_text (GTK_ENTRY (entry));
-
- gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
- GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str));
-}
-
-#define KEYBOARD_GRABBED \
- g_quark_from_static_string ("password-entry-keyboard-grabbed")
-
-static gboolean
-password_dialog_grab_keyboard (GtkWidget *widget,
- GdkEvent *event,
- gpointer user_data)
-{
- if (g_object_get_qdata (G_OBJECT (widget), KEYBOARD_GRABBED) == NULL)
- {
- GdkGrabStatus status = gdk_keyboard_grab (gtk_widget_get_window (widget),
- FALSE, gdk_event_get_time (event));
-
- if (status != GDK_GRAB_SUCCESS)
- {
- DEBUG ("Could not grab keyboard; grab status was %u", status);
- }
- else
- {
- g_object_set_qdata (G_OBJECT (widget), KEYBOARD_GRABBED,
- GINT_TO_POINTER (TRUE));
- }
- }
-
- return FALSE;
-}
-
-static gboolean
-password_dialog_ungrab_keyboard (GtkWidget *widget,
- GdkEvent *event,
- gpointer user_data)
-{
- if (g_object_get_qdata (G_OBJECT (widget), KEYBOARD_GRABBED) != NULL)
- {
- gdk_keyboard_ungrab (gdk_event_get_time (event));
- g_object_set_qdata (G_OBJECT (widget), KEYBOARD_GRABBED, NULL);
- }
-
- return FALSE;
-}
-
-static gboolean
-password_dialog_window_state_changed (GtkWidget *widget,
- GdkEventWindowState *event,
- gpointer data)
-{
- GdkWindowState state = gdk_window_get_state (gtk_widget_get_window (widget));
-
- if (state & GDK_WINDOW_STATE_WITHDRAWN
- || state & GDK_WINDOW_STATE_ICONIFIED
- || state & GDK_WINDOW_STATE_FULLSCREEN
- || state & GDK_WINDOW_STATE_MAXIMIZED)
- {
- password_dialog_ungrab_keyboard (widget, (GdkEvent*) event, data);
- }
- else
- {
- password_dialog_grab_keyboard (widget, (GdkEvent*) event, data);
- }
-
- return FALSE;
-}
-
static void
auth_factory_new_sasl_handler_cb (EmpathyAuthFactory *factory,
EmpathyServerSASLHandler *handler,
gpointer user_data)
{
- GtkWidget *dialog, *entry, *icon, *ticky;
- GtkBox *box;
- TpAccount *account;
- PasswordDialogData *data;
+ GtkWidget *dialog;
DEBUG ("New SASL server handler received from the factory");
- account = empathy_server_sasl_handler_get_account (handler);
-
- /* dialog */
- dialog = gtk_message_dialog_new_with_markup (NULL, 0,
- GTK_MESSAGE_OTHER, GTK_BUTTONS_OK_CANCEL,
- _("Enter your password for account\n<b>%s</b>"),
- tp_account_get_display_name (account));
- gtk_window_set_icon_name (GTK_WINDOW (dialog),
- GTK_STOCK_DIALOG_AUTHENTICATION);
-
- box = GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog)));
-
- /* dialog icon */
- icon = gtk_image_new_from_icon_name (tp_account_get_icon_name (account),
- GTK_ICON_SIZE_DIALOG);
- gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), icon);
- gtk_widget_show (icon);
-
- /* entry */
- entry = gtk_entry_new ();
- gtk_entry_set_visibility (GTK_ENTRY (entry), FALSE);
-
- /* entry clear icon */
- gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
- GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
- gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
- GTK_ENTRY_ICON_SECONDARY, FALSE);
-
- g_signal_connect (entry, "icon-release",
- G_CALLBACK (clear_icon_released_cb), NULL);
- g_signal_connect (entry, "changed",
- G_CALLBACK (password_entry_changed_cb), NULL);
-
- gtk_box_pack_start (box, entry, FALSE, FALSE, 0);
- gtk_widget_show (entry);
-
- /* remember password ticky */
- ticky = gtk_check_button_new_with_label (_("Remember password"));
-
- gtk_box_pack_start (box, ticky, FALSE, FALSE, 0);
- gtk_widget_show (ticky);
-
- data = g_slice_new0 (PasswordDialogData);
- data->handler = g_object_ref (handler);
- data->entry = entry;
- data->ticky = ticky;
-
- g_signal_connect (dialog, "response",
- G_CALLBACK (password_dialog_response_cb), data);
- g_signal_connect (dialog, "window-state-event",
- G_CALLBACK (password_dialog_window_state_changed), NULL);
- g_signal_connect (dialog, "map-event",
- G_CALLBACK (password_dialog_grab_keyboard), NULL);
- g_signal_connect (dialog, "unmap-event",
- G_CALLBACK (password_dialog_ungrab_keyboard), NULL);
-
+ /* TODO: check whether to show the dialog */
+ dialog = empathy_password_dialog_new (handler);
gtk_widget_show (dialog);
- gtk_widget_grab_focus (entry);
}
int