From: Jonny Lamb Date: Fri, 3 Dec 2010 13:04:04 +0000 (+0000) Subject: auth-client: improve the password request dialog X-Git-Url: https://git.0d.be/?p=empathy.git;a=commitdiff_plain;h=fd337e4163b26ea7e284473817a1d17946ab12d4 auth-client: improve the password request dialog Signed-off-by: Jonny Lamb --- diff --git a/libempathy/empathy-server-sasl-handler.c b/libempathy/empathy-server-sasl-handler.c index 5c78591e..9f10a792 100644 --- a/libempathy/empathy-server-sasl-handler.c +++ b/libempathy/empathy-server-sasl-handler.c @@ -241,7 +241,8 @@ start_mechanism_with_data_cb (TpChannel *proxy, void empathy_server_sasl_handler_provide_password ( EmpathyServerSASLHandler *handler, - const gchar *password) + const gchar *password, + gboolean remember) { EmpathyServerSASLHandlerPriv *priv; GArray *array; @@ -262,6 +263,13 @@ empathy_server_sasl_handler_provide_password ( NULL, NULL, G_OBJECT (handler)); g_array_unref (array); + + DEBUG ("%sremembering the password", remember ? "" : "not "); + + if (remember) + { + /* TODO */ + } } void diff --git a/libempathy/empathy-server-sasl-handler.h b/libempathy/empathy-server-sasl-handler.h index 47f49e2a..cdedef90 100644 --- a/libempathy/empathy-server-sasl-handler.h +++ b/libempathy/empathy-server-sasl-handler.h @@ -62,7 +62,8 @@ EmpathyServerSASLHandler * empathy_server_sasl_handler_new ( TpAccount *account, TpChannel *channel); void empathy_server_sasl_handler_provide_password ( - EmpathyServerSASLHandler *handler, const gchar *password); + EmpathyServerSASLHandler *handler, const gchar *password, + gboolean remember); void empathy_server_sasl_handler_cancel (EmpathyServerSASLHandler *handler); diff --git a/src/empathy-auth-client.c b/src/empathy-auth-client.c index 864253bb..6b03a03d 100644 --- a/src/empathy-auth-client.c +++ b/src/empathy-auth-client.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -209,6 +210,7 @@ typedef struct { EmpathyServerSASLHandler *handler; GtkWidget *entry; + GtkWidget *ticky; } PasswordDialogData; static void @@ -218,10 +220,11 @@ password_dialog_response_cb (GtkDialog *dialog, { PasswordDialogData *data = user_data; - if (response == GTK_RESPONSE_ACCEPT) + if (response == GTK_RESPONSE_OK) { empathy_server_sasl_handler_provide_password (data->handler, - gtk_entry_get_text (GTK_ENTRY (data->entry))); + gtk_entry_get_text (GTK_ENTRY (data->entry)), + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->ticky))); } else { @@ -234,33 +237,82 @@ password_dialog_response_cb (GtkDialog *dialog, 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)); +} + static void auth_factory_new_sasl_handler_cb (EmpathyAuthFactory *factory, EmpathyServerSASLHandler *handler, gpointer user_data) { - GtkWidget *dialog, *entry; + GtkWidget *dialog, *entry, *icon, *ticky; + GtkBox *box; + TpAccount *account; PasswordDialogData *data; DEBUG ("New SASL server handler received from the factory"); - dialog = gtk_dialog_new_with_buttons (_("Enter password"), NULL, - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, - GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, - NULL); + account = empathy_server_sasl_handler_get_account (handler); + + dialog = gtk_message_dialog_new_with_markup (NULL, 0, + GTK_MESSAGE_OTHER, GTK_BUTTONS_OK_CANCEL, + _("Enter your password for account\n%s"), + tp_account_get_display_name (account)); + + 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); - gtk_box_pack_start (GTK_BOX ( - gtk_dialog_get_content_area (GTK_DIALOG (dialog))), - entry, FALSE, FALSE, 10); + /* 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);