ammend password dialog to accept an optional message to display at the top (for example, when asking for a retry after a bad password); fix time service to use the password dialog correctly and obey the cancel button and the 'remember' checkbox, and to give you three tries before giving up

This commit is contained in:
Robey Pointer 2000-07-29 00:19:50 +00:00
parent ed21d92de0
commit c1deba356e
8 changed files with 139 additions and 31 deletions

View file

@ -1,3 +1,24 @@
2000-07-28 Robey Pointer <robey@eazel.com>
*
components/services/time/nautilus-view/trilobite-eazel-time-view.c:
(sync_button_pressed), (trilobite_eazel_time_view_get_password),
(trilobite_eazel_time_view_initialize),
(trilobite_eazel_time_view_destroy):
* helper-utilities/authenticate/nautilus-authenticate.c: (main):
* libnautilus-extensions/nautilus-password-dialog.c:
(nautilus_password_dialog_initialize),
(nautilus_password_dialog_destroy), (nautilus_password_dialog_new):
* libnautilus-extensions/nautilus-password-dialog.h:
* test/test-nautilus-password-dialog.c:
(authenticate_boink_callback):
Ammend password dialog to accept an optional message to display
at the top (for example, when asking for a retry after a bad
password). Fix time service to use the password dialog correctly
and obey the cancel button and the "remember" checkbox, and to
give you three tries before giving up.
2000-07-28 Arlo Rose <arlo@eazel.com>
* icons/arlo/side_bar_images/fill-active.png

View file

@ -19,8 +19,9 @@
* Boston, MA 02111-1307, USA.
*
* Authors: Michael Fleming <mfleming@eazel.com>
* Based on nautilus-sample-content-view by Maciej Stachowiak <mjs@eazel.com>
* Robey Pointer <robey@eazel.com>
*
* Based on nautilus-sample-content-view by Maciej Stachowiak <mjs@eazel.com>
*/
/* trilobite-eazel-time-view.c: a simple Nautilus view for a simple service
@ -49,17 +50,12 @@
*/
/* FIXME: no way to save the url once you change it */
/* FIXME: externally visible time server no longer exists */
#if 0
#define DEFAULT_SERVER_URL "http://eazel24.eazel.com/time.pl"
#else
#define DEFAULT_SERVER_URL "http://testmachine.eazel.com:8888/examples/time/current"
#endif
#define DEFAULT_TIME_DIFF "180"
#define OAFIID_TIME_SERVICE "OAFIID:trilobite_eazel_time_service:13a2dbd9-84f9-4400-bd9e-bb4575b86894"
#define OAFIID_TIME_SERVICE "OAFIID:trilobite_eazel_time_service:13a2dbd9-84f9-4400-bd9e-bb4575b86894"
#define STATUS_ERROR_NO_SERVER "Could not load time service backend"
#define STATUS_ERROR_NO_SERVER "Could not load time service backend"
/* A NautilusContentView's private information. */
struct TrilobiteEazelTimeViewDetails {
@ -74,6 +70,8 @@ struct TrilobiteEazelTimeViewDetails {
Trilobite_Eazel_Time service;
guint timeout_slot;
TrilobiteRootClient *root_client;
char * remembered_password;
guint password_attempts;
};
static void trilobite_eazel_time_view_initialize_class (TrilobiteEazelTimeViewClass *klass);
@ -83,12 +81,6 @@ static void load_location_callback (NautilusView
const char *location,
TrilobiteEazelTimeView *view);
#if 0
static void sample_merge_bonobo_items_callback (BonoboObject *control,
gboolean state,
gpointer user_data);
#endif /* 0 */
NAUTILUS_DEFINE_CLASS_BOILERPLATE (TrilobiteEazelTimeView, trilobite_eazel_time_view, GTK_TYPE_EVENT_BOX)
@ -107,26 +99,51 @@ sync_button_pressed( GtkButton *p_button, TrilobiteEazelTimeView *view )
g_assert (TRILOBITE_IS_EAZEL_TIME_VIEW (view));
if (! view->details->service) {
set_status_text (view, STATUS_ERROR_NO_SERVER);
return;
}
view->details->password_attempts = 0;
CORBA_exception_init (&ev);
if (view->details->service) {
while (1) {
Trilobite_Eazel_Time_update_time (view->details->service, &ev);
if (CORBA_USER_EXCEPTION == ev._major) {
if ( 0 == strcmp( ex_Trilobite_Eazel_Time_NotPermitted, CORBA_exception_id (&ev) ) ) {
if (ev._major != CORBA_USER_EXCEPTION) {
set_status_text (view, "Set time!");
break;
}
if ( 0 == strcmp( ex_Trilobite_Eazel_Time_NotPermitted, CORBA_exception_id (&ev) ) ) {
/* bad password -- let em try again? */
if (view->details->password_attempts == 0) {
/* cancelled */
set_status_text (view, "Cancelled");
break;
}
/* a wrong password shouldn't be remembered :) */
g_free (view->details->remembered_password);
view->details->remembered_password = NULL;
CORBA_exception_free (&ev);
if (view->details->password_attempts >= 3) {
/* give up. */
set_status_text (view, "Operation not permitted");
} else {
set_status_text (view, "Exception: could not set time");
break;
}
} else {
set_status_text (view, "Updated local time");
}
} else {
set_status_text (view, STATUS_ERROR_NO_SERVER);
}
set_status_text (view, "Exception: could not set time");
break;
}
}
CORBA_exception_free (&ev);
}
static void
url_button_pressed( GtkButton *p_button, TrilobiteEazelTimeView *view )
{
@ -216,18 +233,43 @@ update_time_display( TrilobiteEazelTimeView *view )
}
static char *
trilobite_eazel_time_view_get_password (GtkObject *object, const char *prompt)
trilobite_eazel_time_view_get_password (GtkObject *object, const char *prompt, void *my_object)
{
TrilobiteEazelTimeView *view;
GtkWidget *dialog;
gboolean rv;
gboolean okay;
char *tmp;
char *message = NULL;
dialog = nautilus_password_dialog_new ("Authenticate Me", prompt, "", TRUE);
view = TRILOBITE_EAZEL_TIME_VIEW (my_object);
rv = nautilus_password_dialog_run_and_block (NAUTILUS_PASSWORD_DIALOG (dialog));
tmp = nautilus_password_dialog_get_password (NAUTILUS_PASSWORD_DIALOG (dialog));
if (view->details->remembered_password) {
return g_strdup (view->details->remembered_password);
}
if (view->details->password_attempts > 0) {
message = "Incorrect password.";
}
dialog = nautilus_password_dialog_new ("Authenticate Me", message, prompt, "", TRUE);
okay = nautilus_password_dialog_run_and_block (NAUTILUS_PASSWORD_DIALOG (dialog));
if (! okay) {
view->details->password_attempts = 0;
tmp = g_strdup ("");
} else {
tmp = nautilus_password_dialog_get_password (NAUTILUS_PASSWORD_DIALOG (dialog));
if (nautilus_password_dialog_get_remember (NAUTILUS_PASSWORD_DIALOG (dialog))) {
view->details->remembered_password = g_strdup (tmp);
}
}
gtk_widget_destroy (dialog);
gtk_main_iteration ();
if (okay) {
view->details->password_attempts++;
}
return tmp;
}
@ -359,7 +401,7 @@ trilobite_eazel_time_view_initialize (TrilobiteEazelTimeView *view)
view->details->root_client = trilobite_root_client_new ();
trilobite_root_client_attach (view->details->root_client, p_service);
gtk_signal_connect (GTK_OBJECT (view->details->root_client), "need_password",
GTK_SIGNAL_FUNC (trilobite_eazel_time_view_get_password), NULL);
GTK_SIGNAL_FUNC (trilobite_eazel_time_view_get_password), view);
if (p_service) {
bonobo_object_unref (BONOBO_OBJECT(p_service));
@ -401,6 +443,7 @@ trilobite_eazel_time_view_destroy (GtkObject *object)
g_free (view->details->server_url);
g_free (view->details->max_time_diff);
g_free (view->details->remembered_password);
Trilobite_Eazel_Time_unref (view->details->service, NULL);
trilobite_root_client_unref (GTK_OBJECT (view->details->root_client));

View file

@ -73,6 +73,7 @@ int main (int argc, char *argv[])
command = g_strdup("");
password_dialog = nautilus_password_dialog_new ("Privileged Command Execution",
NULL,
"root",
"",
TRUE);

View file

@ -44,6 +44,7 @@ struct _NautilusPasswordDialogDetails
/* Internal widgetry and flags */
GtkWidget *table;
GtkWidget *remember_button;
GtkLabel *message;
};
static const char * stock_buttons[] =
@ -117,6 +118,7 @@ nautilus_password_dialog_initialize (NautilusPasswordDialog *password_dialog)
password_dialog->details->table = NULL;
password_dialog->details->remember_button = NULL;
password_dialog->details->message = NULL;
}
/* GtkObjectClass methods */
@ -142,6 +144,10 @@ nautilus_password_dialog_destroy (GtkObject* object)
g_free (password_dialog->details->remember_label_text);
}
if (password_dialog->details->message) {
gtk_widget_destroy (GTK_WIDGET (password_dialog->details->message));
}
g_free (password_dialog->details);
}
@ -206,6 +212,7 @@ caption_table_activate_callback (GtkWidget *widget, gint entry, gpointer callbac
/* Public NautilusPasswordDialog methods */
GtkWidget*
nautilus_password_dialog_new (const char *dialog_title,
const char *message,
const char *username,
const char *password,
gboolean readonly_username)
@ -274,6 +281,19 @@ nautilus_password_dialog_new (const char *dialog_title,
gtk_box_set_spacing (GTK_BOX (GNOME_DIALOG (password_dialog)->vbox), 10);
if (message) {
password_dialog->details->message =
GTK_LABEL (gtk_label_new (message));
gtk_label_set_justify (password_dialog->details->message, GTK_JUSTIFY_LEFT);
gtk_label_set_line_wrap (password_dialog->details->message, TRUE);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (password_dialog)->vbox),
GTK_WIDGET (password_dialog->details->message),
TRUE, /* expand */
TRUE, /* fill */
0); /* padding */
}
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (password_dialog)->vbox),
password_dialog->details->table,
TRUE, /* expand */

View file

@ -54,6 +54,7 @@ struct _NautilusPasswordDialogClass
GtkType nautilus_password_dialog_get_type (void);
GtkWidget* nautilus_password_dialog_new (const char *dialog_title,
const char *message,
const char *username,
const char *password,
gboolean readonly_username);

View file

@ -44,6 +44,7 @@ struct _NautilusPasswordDialogDetails
/* Internal widgetry and flags */
GtkWidget *table;
GtkWidget *remember_button;
GtkLabel *message;
};
static const char * stock_buttons[] =
@ -117,6 +118,7 @@ nautilus_password_dialog_initialize (NautilusPasswordDialog *password_dialog)
password_dialog->details->table = NULL;
password_dialog->details->remember_button = NULL;
password_dialog->details->message = NULL;
}
/* GtkObjectClass methods */
@ -142,6 +144,10 @@ nautilus_password_dialog_destroy (GtkObject* object)
g_free (password_dialog->details->remember_label_text);
}
if (password_dialog->details->message) {
gtk_widget_destroy (GTK_WIDGET (password_dialog->details->message));
}
g_free (password_dialog->details);
}
@ -206,6 +212,7 @@ caption_table_activate_callback (GtkWidget *widget, gint entry, gpointer callbac
/* Public NautilusPasswordDialog methods */
GtkWidget*
nautilus_password_dialog_new (const char *dialog_title,
const char *message,
const char *username,
const char *password,
gboolean readonly_username)
@ -274,6 +281,19 @@ nautilus_password_dialog_new (const char *dialog_title,
gtk_box_set_spacing (GTK_BOX (GNOME_DIALOG (password_dialog)->vbox), 10);
if (message) {
password_dialog->details->message =
GTK_LABEL (gtk_label_new (message));
gtk_label_set_justify (password_dialog->details->message, GTK_JUSTIFY_LEFT);
gtk_label_set_line_wrap (password_dialog->details->message, TRUE);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (password_dialog)->vbox),
GTK_WIDGET (password_dialog->details->message),
TRUE, /* expand */
TRUE, /* fill */
0); /* padding */
}
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (password_dialog)->vbox),
password_dialog->details->table,
TRUE, /* expand */

View file

@ -54,6 +54,7 @@ struct _NautilusPasswordDialogClass
GtkType nautilus_password_dialog_get_type (void);
GtkWidget* nautilus_password_dialog_new (const char *dialog_title,
const char *message,
const char *username,
const char *password,
gboolean readonly_username);

View file

@ -16,6 +16,7 @@ authenticate_boink_callback (GtkWidget *button, gpointer user_data)
if (password_dialog == NULL) {
password_dialog = nautilus_password_dialog_new ("Authenticate Me",
"My secret message.",
"foouser",
"sekret",
TRUE);