mirror of
https://gitlab.gnome.org/GNOME/nautilus
synced 2024-08-25 02:36:07 +00:00
Many cleanups and improvements. Use the GnomeDialog run_and_close call
* libnautilus-extensions/nautilus-password-dialog.c: (nautilus_password_dialog_initialize_class), (nautilus_password_dialog_initialize), (nautilus_password_dialog_destroy), (dialog_show_callback), (dialog_close_callback), (caption_table_activate_callback), (nautilus_password_dialog_new), (nautilus_password_dialog_run_and_block), (nautilus_password_dialog_set_username), (nautilus_password_dialog_set_password), (nautilus_password_dialog_set_readonly_username), (nautilus_password_dialog_get_username), (nautilus_password_dialog_get_password), (nautilus_password_dialog_get_remember), (nautilus_password_dialog_set_remember), (nautilus_password_dialog_set_remember_label_text): * libnautilus-extensions/nautilus-password-dialog.h: Many cleanups and improvements. Use the GnomeDialog run_and_close call instead of our own event loop hack. Removed many unneeded callbacks and details member variables. Add checks for all callbacks. Add support for remembering the password. * test/.cvsignore: * test/Makefile.am: * test/test-nautilus-password-dialog.c: (authenticate_boink_callback), (exit_callback), (main): Add a new test for the password dialog. * test/test-nautilus-widgets.c: (main), (text_caption_changed_callback): Removed the old password dialog test.
This commit is contained in:
parent
8ad7134e8c
commit
ba0e6fd383
33
ChangeLog
33
ChangeLog
|
@ -1,3 +1,36 @@
|
|||
2000-07-11 Ramiro Estrugo <ramiro@eazel.com>
|
||||
|
||||
* libnautilus-extensions/nautilus-password-dialog.c:
|
||||
(nautilus_password_dialog_initialize_class),
|
||||
(nautilus_password_dialog_initialize),
|
||||
(nautilus_password_dialog_destroy), (dialog_show_callback),
|
||||
(dialog_close_callback), (caption_table_activate_callback),
|
||||
(nautilus_password_dialog_new),
|
||||
(nautilus_password_dialog_run_and_block),
|
||||
(nautilus_password_dialog_set_username),
|
||||
(nautilus_password_dialog_set_password),
|
||||
(nautilus_password_dialog_set_readonly_username),
|
||||
(nautilus_password_dialog_get_username),
|
||||
(nautilus_password_dialog_get_password),
|
||||
(nautilus_password_dialog_get_remember),
|
||||
(nautilus_password_dialog_set_remember),
|
||||
(nautilus_password_dialog_set_remember_label_text):
|
||||
* libnautilus-extensions/nautilus-password-dialog.h:
|
||||
Many cleanups and improvements. Use the GnomeDialog run_and_close
|
||||
call instead of our own event loop hack. Removed many unneeded
|
||||
callbacks and details member variables. Add checks for all
|
||||
callbacks. Add support for remembering the password.
|
||||
|
||||
* test/.cvsignore:
|
||||
* test/Makefile.am:
|
||||
* test/test-nautilus-password-dialog.c:
|
||||
(authenticate_boink_callback), (exit_callback), (main):
|
||||
Add a new test for the password dialog.
|
||||
|
||||
* test/test-nautilus-widgets.c: (main),
|
||||
(text_caption_changed_callback):
|
||||
Removed the old password dialog test.
|
||||
|
||||
2000-07-10 J Shane Culpepper <pepper@eazel.com>
|
||||
|
||||
*
|
||||
|
|
|
@ -28,23 +28,22 @@
|
|||
|
||||
#include <libgnomeui/gnome-stock.h>
|
||||
#include <gtk/gtkmain.h>
|
||||
#include <gtk/gtkcheckbutton.h>
|
||||
#include <gtk/gtksignal.h>
|
||||
#include "nautilus-gtk-macros.h"
|
||||
|
||||
struct _NautilusPasswordDialogDetail
|
||||
struct _NautilusPasswordDialogDetails
|
||||
{
|
||||
/* Attributes */
|
||||
char *username;
|
||||
char *password;
|
||||
gint last_button_clicked;
|
||||
gboolean readonly_username;
|
||||
GtkWidget *table;
|
||||
GtkWidget *blurb;
|
||||
};
|
||||
gboolean remember;
|
||||
char *remember_label_text;
|
||||
|
||||
enum
|
||||
{
|
||||
ACTIVATE,
|
||||
LAST_SIGNAL
|
||||
/* Internal widgetry and flags */
|
||||
GtkWidget *table;
|
||||
GtkWidget *remember_button;
|
||||
};
|
||||
|
||||
static const char * stock_buttons[] =
|
||||
|
@ -54,38 +53,37 @@ static const char * stock_buttons[] =
|
|||
NULL
|
||||
};
|
||||
|
||||
static const gint UNKNOWN_BUTTON = -1;
|
||||
static const gint OK_BUTTON = 0;
|
||||
static const gint DEFAULT_BUTTON = 0;
|
||||
static const guint DEFAULT_BORDER_WIDTH = 0;
|
||||
/* Dialog button indeces */
|
||||
static const gint DIALOG_OK_BUTTON = 0;
|
||||
|
||||
enum
|
||||
{
|
||||
USERNAME_ROW = 0,
|
||||
PASSWORD_ROW
|
||||
};
|
||||
/* Caption table rows indeces */
|
||||
static const guint CAPTION_TABLE_USERNAME_ROW = 0;
|
||||
static const guint CAPTION_TABLE_PASSWORD_ROW = 1;
|
||||
|
||||
/* Layout constants */
|
||||
static const guint DIALOG_BORDER_WIDTH = 0;
|
||||
static const guint CAPTION_TABLE_BORDER_WIDTH = 4;
|
||||
|
||||
/* NautilusPasswordDialogClass methods */
|
||||
static void nautilus_password_dialog_initialize_class (NautilusPasswordDialogClass *klass);
|
||||
static void nautilus_password_dialog_initialize_class (NautilusPasswordDialogClass *password_dialog_class);
|
||||
static void nautilus_password_dialog_initialize (NautilusPasswordDialog *password_dialog);
|
||||
|
||||
|
||||
|
||||
/* GtkObjectClass methods */
|
||||
static void bnautilus_password_dialog_destroy (GtkObject *object);
|
||||
static void nautilus_password_dialog_destroy (GtkObject *object);
|
||||
|
||||
|
||||
/* GtkDialog callbacks */
|
||||
static void dialog_clicked_callback (GtkWidget *widget,
|
||||
gint n,
|
||||
gpointer data);
|
||||
static void dialog_show_callback (GtkWidget *widget,
|
||||
gpointer data);
|
||||
static void dialog_destroy_callback (GtkWidget *widget,
|
||||
gpointer data);
|
||||
|
||||
/* NautilusCaptionTable callbacks */
|
||||
gpointer callback_data);
|
||||
static void dialog_close_callback (GtkWidget *widget,
|
||||
gpointer callback_data);
|
||||
/* Caption table callbacks */
|
||||
static void caption_table_activate_callback (GtkWidget *widget,
|
||||
gint entry,
|
||||
gpointer data);
|
||||
gpointer callback_data);
|
||||
|
||||
|
||||
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPasswordDialog,
|
||||
nautilus_password_dialog,
|
||||
|
@ -102,72 +100,107 @@ nautilus_password_dialog_initialize_class (NautilusPasswordDialogClass * klass)
|
|||
widget_class = GTK_WIDGET_CLASS(klass);
|
||||
|
||||
/* GtkObjectClass */
|
||||
object_class->destroy = bnautilus_password_dialog_destroy;
|
||||
object_class->destroy = nautilus_password_dialog_destroy;
|
||||
}
|
||||
|
||||
static void
|
||||
nautilus_password_dialog_initialize (NautilusPasswordDialog *password_dialog)
|
||||
{
|
||||
password_dialog->detail = g_new (NautilusPasswordDialogDetail, 1);
|
||||
password_dialog->details = g_new (NautilusPasswordDialogDetails, 1);
|
||||
|
||||
password_dialog->detail->username = NULL;
|
||||
password_dialog->detail->password = NULL;
|
||||
password_dialog->details->username = NULL;
|
||||
password_dialog->details->password = NULL;
|
||||
password_dialog->details->readonly_username = FALSE;
|
||||
|
||||
password_dialog->detail->last_button_clicked = UNKNOWN_BUTTON;
|
||||
password_dialog->detail->readonly_username = FALSE;
|
||||
password_dialog->details->remember_label_text = NULL;
|
||||
password_dialog->details->remember = FALSE;
|
||||
|
||||
password_dialog->detail->table = NULL;
|
||||
password_dialog->details->table = NULL;
|
||||
password_dialog->details->remember_button = NULL;
|
||||
}
|
||||
|
||||
/* GtkObjectClass methods */
|
||||
static void
|
||||
nautilus_password_dialog_destroy (GtkObject* object)
|
||||
{
|
||||
NautilusPasswordDialog *password_dialog;
|
||||
|
||||
g_return_if_fail (object != NULL);
|
||||
g_return_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (object));
|
||||
|
||||
password_dialog = NAUTILUS_PASSWORD_DIALOG (object);
|
||||
|
||||
if (password_dialog->details->username) {
|
||||
g_free (password_dialog->details->username);
|
||||
}
|
||||
|
||||
if (password_dialog->details->password) {
|
||||
g_free (password_dialog->details->password);
|
||||
}
|
||||
|
||||
if (password_dialog->details->remember_label_text) {
|
||||
g_free (password_dialog->details->remember_label_text);
|
||||
}
|
||||
|
||||
g_free (password_dialog->details);
|
||||
}
|
||||
|
||||
/* GtkDialog callbacks */
|
||||
static void
|
||||
dialog_clicked_callback (GtkWidget *widget, gint n, gpointer data)
|
||||
dialog_show_callback (GtkWidget *widget, gpointer callback_data)
|
||||
{
|
||||
NautilusPasswordDialog *password_dialog = (NautilusPasswordDialog *) data;
|
||||
NautilusPasswordDialog *password_dialog;
|
||||
|
||||
g_assert (password_dialog != NULL);
|
||||
g_return_if_fail (callback_data != NULL);
|
||||
g_return_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (callback_data));
|
||||
|
||||
password_dialog->detail->last_button_clicked = n;
|
||||
password_dialog = NAUTILUS_PASSWORD_DIALOG (callback_data);
|
||||
|
||||
gtk_grab_remove(GTK_WIDGET (password_dialog));
|
||||
|
||||
gtk_widget_hide(GTK_WIDGET (password_dialog));
|
||||
/* Move the focus to the password entry */
|
||||
nautilus_caption_table_entry_grab_focus (NAUTILUS_CAPTION_TABLE (password_dialog->details->table),
|
||||
CAPTION_TABLE_PASSWORD_ROW);
|
||||
}
|
||||
|
||||
static void
|
||||
dialog_show_callback (GtkWidget *widget, gpointer data)
|
||||
dialog_close_callback (GtkWidget *widget, gpointer callback_data)
|
||||
{
|
||||
NautilusPasswordDialog *password_dialog = (NautilusPasswordDialog *) data;
|
||||
NautilusPasswordDialog *password_dialog;
|
||||
|
||||
g_assert (password_dialog != NULL);
|
||||
g_return_if_fail (callback_data != NULL);
|
||||
g_return_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (callback_data));
|
||||
|
||||
nautilus_caption_table_entry_grab_focus (NAUTILUS_CAPTION_TABLE (password_dialog->detail->table),
|
||||
PASSWORD_ROW);
|
||||
password_dialog = NAUTILUS_PASSWORD_DIALOG (callback_data);
|
||||
|
||||
gtk_widget_hide (widget);
|
||||
}
|
||||
|
||||
/* Caption table callbacks */
|
||||
static void
|
||||
dialog_destroy_callback (GtkWidget *widget, gpointer data)
|
||||
caption_table_activate_callback (GtkWidget *widget, gint entry, gpointer callback_data)
|
||||
{
|
||||
NautilusPasswordDialog *password_dialog = (NautilusPasswordDialog *) data;
|
||||
NautilusPasswordDialog *password_dialog;
|
||||
|
||||
g_assert (password_dialog != NULL);
|
||||
g_return_if_fail (callback_data != NULL);
|
||||
g_return_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (callback_data));
|
||||
|
||||
g_free (password_dialog->detail);
|
||||
password_dialog = NAUTILUS_PASSWORD_DIALOG (callback_data);
|
||||
|
||||
gtk_grab_remove(GTK_WIDGET (password_dialog));
|
||||
}
|
||||
/* If the username entry was activated, simply advance the focus to the password entry */
|
||||
if (entry == CAPTION_TABLE_USERNAME_ROW) {
|
||||
nautilus_caption_table_entry_grab_focus (NAUTILUS_CAPTION_TABLE (password_dialog->details->table),
|
||||
CAPTION_TABLE_PASSWORD_ROW);
|
||||
}
|
||||
/* If the password entry was activated, then simulate and OK button press to continue to hide process */
|
||||
else if (entry == CAPTION_TABLE_PASSWORD_ROW) {
|
||||
GtkWidget *button;
|
||||
|
||||
button = g_list_nth_data (GNOME_DIALOG (password_dialog)->buttons, DIALOG_OK_BUTTON);
|
||||
|
||||
g_assert (button != NULL);
|
||||
g_assert (GTK_IS_BUTTON (button));
|
||||
|
||||
|
||||
/* NautilusCaptionTable callbacks */
|
||||
static void
|
||||
caption_table_activate_callback (GtkWidget *widget, gint entry, gpointer data)
|
||||
{
|
||||
NautilusPasswordDialog *password_dialog = (NautilusPasswordDialog *) data;
|
||||
|
||||
g_assert (password_dialog != NULL);
|
||||
|
||||
if (entry == (nautilus_caption_table_get_num_rows (NAUTILUS_CAPTION_TABLE (widget)) - 1))
|
||||
dialog_clicked_callback(GTK_WIDGET (password_dialog), OK_BUTTON, (gpointer) password_dialog);
|
||||
gtk_button_clicked (GTK_BUTTON (button));
|
||||
}
|
||||
}
|
||||
|
||||
/* Public NautilusPasswordDialog methods */
|
||||
|
@ -189,51 +222,48 @@ nautilus_password_dialog_new (const char *dialog_title,
|
|||
TRUE, /* allow_grow */
|
||||
FALSE); /* auto_shrink */
|
||||
|
||||
gtk_widget_realize (GTK_WIDGET (password_dialog));
|
||||
|
||||
gdk_window_set_functions (GTK_WIDGET (password_dialog)->window,
|
||||
GDK_FUNC_ALL | GDK_FUNC_RESIZE | GDK_FUNC_MINIMIZE);
|
||||
|
||||
gtk_window_set_position (GTK_WINDOW (password_dialog), GTK_WIN_POS_CENTER);
|
||||
gtk_window_set_modal (GTK_WINDOW (password_dialog), TRUE);
|
||||
|
||||
gtk_container_set_border_width (GTK_CONTAINER (password_dialog),
|
||||
DEFAULT_BORDER_WIDTH);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (password_dialog), DIALOG_BORDER_WIDTH);
|
||||
|
||||
gnome_dialog_set_default (GNOME_DIALOG (password_dialog),
|
||||
DEFAULT_BUTTON);
|
||||
gnome_dialog_set_default (GNOME_DIALOG (password_dialog), DIALOG_OK_BUTTON);
|
||||
|
||||
gtk_signal_connect(GTK_OBJECT (password_dialog),
|
||||
"clicked",
|
||||
GTK_SIGNAL_FUNC (dialog_clicked_callback),
|
||||
(gpointer) password_dialog);
|
||||
/* Dont close the dialog on click. We'll mange the destruction our selves */
|
||||
gnome_dialog_set_close (GNOME_DIALOG (password_dialog), FALSE);
|
||||
|
||||
gtk_signal_connect(GTK_OBJECT (password_dialog),
|
||||
"show",
|
||||
GTK_SIGNAL_FUNC (dialog_show_callback),
|
||||
(gpointer) password_dialog);
|
||||
|
||||
gtk_signal_connect(GTK_OBJECT (password_dialog),
|
||||
"destroy",
|
||||
GTK_SIGNAL_FUNC (dialog_destroy_callback),
|
||||
(gpointer) password_dialog);
|
||||
/* Make the close operation 'just_hide' the dialog - not nuke it */
|
||||
gnome_dialog_close_hides (GNOME_DIALOG (password_dialog), TRUE);
|
||||
|
||||
/* The table that holds the captions */
|
||||
password_dialog->detail->table = nautilus_caption_table_new (2);
|
||||
gtk_signal_connect_while_alive (GTK_OBJECT (password_dialog),
|
||||
"show",
|
||||
GTK_SIGNAL_FUNC (dialog_show_callback),
|
||||
(gpointer) password_dialog,
|
||||
GTK_OBJECT (password_dialog));
|
||||
|
||||
gtk_signal_connect_while_alive (GTK_OBJECT (password_dialog),
|
||||
"close",
|
||||
GTK_SIGNAL_FUNC (dialog_close_callback),
|
||||
(gpointer) password_dialog,
|
||||
GTK_OBJECT (password_dialog));
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (password_dialog->detail->table),
|
||||
/* The table that holds the captions */
|
||||
password_dialog->details->table = nautilus_caption_table_new (2);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (password_dialog->details->table),
|
||||
"activate",
|
||||
GTK_SIGNAL_FUNC (caption_table_activate_callback),
|
||||
(gpointer) password_dialog);
|
||||
|
||||
nautilus_caption_table_set_row_info (NAUTILUS_CAPTION_TABLE (password_dialog->detail->table),
|
||||
USERNAME_ROW,
|
||||
nautilus_caption_table_set_row_info (NAUTILUS_CAPTION_TABLE (password_dialog->details->table),
|
||||
CAPTION_TABLE_USERNAME_ROW,
|
||||
"Username:",
|
||||
"",
|
||||
TRUE,
|
||||
TRUE);
|
||||
|
||||
nautilus_caption_table_set_row_info (NAUTILUS_CAPTION_TABLE (password_dialog->detail->table),
|
||||
PASSWORD_ROW,
|
||||
nautilus_caption_table_set_row_info (NAUTILUS_CAPTION_TABLE (password_dialog->details->table),
|
||||
CAPTION_TABLE_PASSWORD_ROW,
|
||||
"Password:",
|
||||
"",
|
||||
FALSE,
|
||||
|
@ -245,15 +275,23 @@ nautilus_password_dialog_new (const char *dialog_title,
|
|||
gtk_box_set_spacing (GTK_BOX (GNOME_DIALOG (password_dialog)->vbox), 10);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (password_dialog)->vbox),
|
||||
password_dialog->detail->table,
|
||||
password_dialog->details->table,
|
||||
TRUE, /* expand */
|
||||
TRUE, /* fill */
|
||||
0); /* padding */
|
||||
|
||||
/* Configure the table */
|
||||
gtk_container_set_border_width (GTK_CONTAINER(password_dialog->detail->table),
|
||||
DEFAULT_BORDER_WIDTH);
|
||||
password_dialog->details->remember_button =
|
||||
gtk_check_button_new_with_label ("Remember this password");
|
||||
|
||||
gtk_box_pack_end (GTK_BOX (GNOME_DIALOG (password_dialog)->vbox),
|
||||
password_dialog->details->remember_button,
|
||||
TRUE, /* expand */
|
||||
TRUE, /* fill */
|
||||
4); /* padding */
|
||||
|
||||
/* Configure the table */
|
||||
gtk_container_set_border_width (GTK_CONTAINER(password_dialog->details->table), CAPTION_TABLE_BORDER_WIDTH);
|
||||
|
||||
gtk_widget_show_all (GNOME_DIALOG (password_dialog)->vbox);
|
||||
|
||||
nautilus_password_dialog_set_username (password_dialog, username);
|
||||
|
@ -263,78 +301,52 @@ nautilus_password_dialog_new (const char *dialog_title,
|
|||
return GTK_WIDGET (password_dialog);
|
||||
}
|
||||
|
||||
/* GtkObjectClass methods */
|
||||
static void
|
||||
bnautilus_password_dialog_destroy (GtkObject* object)
|
||||
{
|
||||
NautilusPasswordDialog *password_dialog;
|
||||
|
||||
g_return_if_fail (object != NULL);
|
||||
g_return_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (object));
|
||||
|
||||
password_dialog = NAUTILUS_PASSWORD_DIALOG (object);
|
||||
|
||||
if (password_dialog->detail->username)
|
||||
g_free (password_dialog->detail->username);
|
||||
|
||||
if (password_dialog->detail->password)
|
||||
g_free (password_dialog->detail->password);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nautilus_password_dialog_run_and_block(NautilusPasswordDialog *password_dialog)
|
||||
nautilus_password_dialog_run_and_block (NautilusPasswordDialog *password_dialog)
|
||||
{
|
||||
gint button_clicked;
|
||||
|
||||
g_return_val_if_fail (password_dialog != NULL, FALSE);
|
||||
g_return_val_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (password_dialog), FALSE);
|
||||
|
||||
password_dialog->detail->last_button_clicked = UNKNOWN_BUTTON;
|
||||
|
||||
gtk_widget_show_all (GTK_WIDGET (password_dialog));
|
||||
|
||||
gtk_grab_add (GTK_WIDGET (password_dialog));
|
||||
button_clicked = gnome_dialog_run_and_close (GNOME_DIALOG (password_dialog));
|
||||
|
||||
while (password_dialog->detail->last_button_clicked == UNKNOWN_BUTTON)
|
||||
gtk_main_iteration ();
|
||||
|
||||
if (password_dialog->detail->last_button_clicked == OK_BUTTON)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
return (button_clicked == DIALOG_OK_BUTTON);
|
||||
}
|
||||
|
||||
void
|
||||
nautilus_password_dialog_set_username (NautilusPasswordDialog *password_dialog,
|
||||
const char * username)
|
||||
nautilus_password_dialog_set_username (NautilusPasswordDialog *password_dialog,
|
||||
const char *username)
|
||||
{
|
||||
g_return_if_fail (password_dialog != NULL);
|
||||
g_return_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (password_dialog));
|
||||
|
||||
nautilus_caption_table_set_entry_text (NAUTILUS_CAPTION_TABLE (password_dialog->detail->table),
|
||||
USERNAME_ROW,
|
||||
nautilus_caption_table_set_entry_text (NAUTILUS_CAPTION_TABLE (password_dialog->details->table),
|
||||
CAPTION_TABLE_USERNAME_ROW,
|
||||
username);
|
||||
}
|
||||
|
||||
void
|
||||
nautilus_password_dialog_set_password (NautilusPasswordDialog *password_dialog,
|
||||
const char * password)
|
||||
nautilus_password_dialog_set_password (NautilusPasswordDialog *password_dialog,
|
||||
const char *password)
|
||||
{
|
||||
g_return_if_fail (password_dialog != NULL);
|
||||
g_return_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (password_dialog));
|
||||
|
||||
nautilus_caption_table_set_entry_text (NAUTILUS_CAPTION_TABLE (password_dialog->detail->table),
|
||||
PASSWORD_ROW,
|
||||
nautilus_caption_table_set_entry_text (NAUTILUS_CAPTION_TABLE (password_dialog->details->table),
|
||||
CAPTION_TABLE_PASSWORD_ROW,
|
||||
password);
|
||||
}
|
||||
|
||||
void
|
||||
nautilus_password_dialog_set_readonly_username (NautilusPasswordDialog *password_dialog,
|
||||
gboolean readonly)
|
||||
nautilus_password_dialog_set_readonly_username (NautilusPasswordDialog *password_dialog,
|
||||
gboolean readonly)
|
||||
{
|
||||
g_return_if_fail (password_dialog != NULL);
|
||||
g_return_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (password_dialog));
|
||||
|
||||
nautilus_caption_table_set_entry_readonly (NAUTILUS_CAPTION_TABLE (password_dialog->detail->table),
|
||||
USERNAME_ROW,
|
||||
nautilus_caption_table_set_entry_readonly (NAUTILUS_CAPTION_TABLE (password_dialog->details->table),
|
||||
CAPTION_TABLE_USERNAME_ROW,
|
||||
readonly);
|
||||
}
|
||||
|
||||
|
@ -344,8 +356,8 @@ nautilus_password_dialog_get_username (NautilusPasswordDialog *password_dialog)
|
|||
g_return_val_if_fail (password_dialog != NULL, NULL);
|
||||
g_return_val_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (password_dialog), NULL);
|
||||
|
||||
return nautilus_caption_table_get_entry_text (NAUTILUS_CAPTION_TABLE (password_dialog->detail->table),
|
||||
USERNAME_ROW);
|
||||
return nautilus_caption_table_get_entry_text (NAUTILUS_CAPTION_TABLE (password_dialog->details->table),
|
||||
CAPTION_TABLE_USERNAME_ROW);
|
||||
}
|
||||
|
||||
char *
|
||||
|
@ -354,6 +366,43 @@ nautilus_password_dialog_get_password (NautilusPasswordDialog *password_dialog)
|
|||
g_return_val_if_fail (password_dialog != NULL, NULL);
|
||||
g_return_val_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (password_dialog), NULL);
|
||||
|
||||
return nautilus_caption_table_get_entry_text (NAUTILUS_CAPTION_TABLE (password_dialog->detail->table),
|
||||
PASSWORD_ROW);
|
||||
return nautilus_caption_table_get_entry_text (NAUTILUS_CAPTION_TABLE (password_dialog->details->table),
|
||||
CAPTION_TABLE_PASSWORD_ROW);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nautilus_password_dialog_get_remember (NautilusPasswordDialog *password_dialog)
|
||||
{
|
||||
g_return_val_if_fail (password_dialog != NULL, FALSE);
|
||||
g_return_val_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (password_dialog), FALSE);
|
||||
|
||||
return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (password_dialog->details->remember_button));
|
||||
}
|
||||
|
||||
void
|
||||
nautilus_password_dialog_set_remember (NautilusPasswordDialog *password_dialog,
|
||||
gboolean remember)
|
||||
{
|
||||
g_return_if_fail (password_dialog != NULL);
|
||||
g_return_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (password_dialog));
|
||||
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (password_dialog->details->remember_button),
|
||||
remember);
|
||||
}
|
||||
|
||||
void
|
||||
nautilus_password_dialog_set_remember_label_text (NautilusPasswordDialog *password_dialog,
|
||||
const char *remember_label_text)
|
||||
{
|
||||
GtkWidget *label;
|
||||
|
||||
g_return_if_fail (password_dialog != NULL);
|
||||
g_return_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (password_dialog));
|
||||
|
||||
label = GTK_BIN (password_dialog->details->remember_button)->child;
|
||||
|
||||
g_assert (label != NULL);
|
||||
g_assert (GTK_IS_LABEL (label));
|
||||
|
||||
gtk_label_set_text (GTK_LABEL (label), remember_label_text);
|
||||
}
|
||||
|
|
|
@ -37,13 +37,13 @@ BEGIN_GNOME_DECLS
|
|||
|
||||
typedef struct _NautilusPasswordDialog NautilusPasswordDialog;
|
||||
typedef struct _NautilusPasswordDialogClass NautilusPasswordDialogClass;
|
||||
typedef struct _NautilusPasswordDialogDetail NautilusPasswordDialogDetail;
|
||||
typedef struct _NautilusPasswordDialogDetails NautilusPasswordDialogDetails;
|
||||
|
||||
struct _NautilusPasswordDialog
|
||||
{
|
||||
GnomeDialog gnome_dialog;
|
||||
|
||||
NautilusPasswordDialogDetail *detail;
|
||||
NautilusPasswordDialogDetails *details;
|
||||
};
|
||||
|
||||
struct _NautilusPasswordDialogClass
|
||||
|
@ -52,20 +52,29 @@ struct _NautilusPasswordDialogClass
|
|||
};
|
||||
|
||||
|
||||
GtkType nautilus_password_dialog_get_type (void);
|
||||
GtkWidget* nautilus_password_dialog_new (const char *dialog_title,
|
||||
const char *username,
|
||||
const char *password,
|
||||
gboolean readonly_username);
|
||||
gboolean nautilus_password_dialog_run_and_block (NautilusPasswordDialog *auth_dialog);
|
||||
void nautilus_password_dialog_set_username (NautilusPasswordDialog *auth_dialog,
|
||||
GtkType nautilus_password_dialog_get_type (void);
|
||||
GtkWidget* nautilus_password_dialog_new (const char *dialog_title,
|
||||
const char *username,
|
||||
const char *password,
|
||||
gboolean readonly_username);
|
||||
gboolean nautilus_password_dialog_run_and_block (NautilusPasswordDialog *password_dialog);
|
||||
|
||||
/* Attribute mutators */
|
||||
void nautilus_password_dialog_set_username (NautilusPasswordDialog *password_dialog,
|
||||
const char *username);
|
||||
void nautilus_password_dialog_set_password (NautilusPasswordDialog *auth_dialog,
|
||||
void nautilus_password_dialog_set_password (NautilusPasswordDialog *password_dialog,
|
||||
const char *password);
|
||||
void nautilus_password_dialog_set_readonly_username (NautilusPasswordDialog *auth_dialog,
|
||||
void nautilus_password_dialog_set_readonly_username (NautilusPasswordDialog *password_dialog,
|
||||
gboolean readonly);
|
||||
char * nautilus_password_dialog_get_username (NautilusPasswordDialog *auth_dialog);
|
||||
char * nautilus_password_dialog_get_password (NautilusPasswordDialog *auth_dialog);
|
||||
void nautilus_password_dialog_set_remember (NautilusPasswordDialog *password_dialog,
|
||||
gboolean remember);
|
||||
void nautilus_password_dialog_set_remember_label_text (NautilusPasswordDialog *password_dialog,
|
||||
const char *remember_label_text);
|
||||
|
||||
/* Attribute accessors */
|
||||
char * nautilus_password_dialog_get_username (NautilusPasswordDialog *password_dialog);
|
||||
char * nautilus_password_dialog_get_password (NautilusPasswordDialog *password_dialog);
|
||||
gboolean nautilus_password_dialog_get_remember (NautilusPasswordDialog *password_dialog);
|
||||
|
||||
BEGIN_GNOME_DECLS
|
||||
|
||||
|
|
|
@ -28,23 +28,22 @@
|
|||
|
||||
#include <libgnomeui/gnome-stock.h>
|
||||
#include <gtk/gtkmain.h>
|
||||
#include <gtk/gtkcheckbutton.h>
|
||||
#include <gtk/gtksignal.h>
|
||||
#include "nautilus-gtk-macros.h"
|
||||
|
||||
struct _NautilusPasswordDialogDetail
|
||||
struct _NautilusPasswordDialogDetails
|
||||
{
|
||||
/* Attributes */
|
||||
char *username;
|
||||
char *password;
|
||||
gint last_button_clicked;
|
||||
gboolean readonly_username;
|
||||
GtkWidget *table;
|
||||
GtkWidget *blurb;
|
||||
};
|
||||
gboolean remember;
|
||||
char *remember_label_text;
|
||||
|
||||
enum
|
||||
{
|
||||
ACTIVATE,
|
||||
LAST_SIGNAL
|
||||
/* Internal widgetry and flags */
|
||||
GtkWidget *table;
|
||||
GtkWidget *remember_button;
|
||||
};
|
||||
|
||||
static const char * stock_buttons[] =
|
||||
|
@ -54,38 +53,37 @@ static const char * stock_buttons[] =
|
|||
NULL
|
||||
};
|
||||
|
||||
static const gint UNKNOWN_BUTTON = -1;
|
||||
static const gint OK_BUTTON = 0;
|
||||
static const gint DEFAULT_BUTTON = 0;
|
||||
static const guint DEFAULT_BORDER_WIDTH = 0;
|
||||
/* Dialog button indeces */
|
||||
static const gint DIALOG_OK_BUTTON = 0;
|
||||
|
||||
enum
|
||||
{
|
||||
USERNAME_ROW = 0,
|
||||
PASSWORD_ROW
|
||||
};
|
||||
/* Caption table rows indeces */
|
||||
static const guint CAPTION_TABLE_USERNAME_ROW = 0;
|
||||
static const guint CAPTION_TABLE_PASSWORD_ROW = 1;
|
||||
|
||||
/* Layout constants */
|
||||
static const guint DIALOG_BORDER_WIDTH = 0;
|
||||
static const guint CAPTION_TABLE_BORDER_WIDTH = 4;
|
||||
|
||||
/* NautilusPasswordDialogClass methods */
|
||||
static void nautilus_password_dialog_initialize_class (NautilusPasswordDialogClass *klass);
|
||||
static void nautilus_password_dialog_initialize_class (NautilusPasswordDialogClass *password_dialog_class);
|
||||
static void nautilus_password_dialog_initialize (NautilusPasswordDialog *password_dialog);
|
||||
|
||||
|
||||
|
||||
/* GtkObjectClass methods */
|
||||
static void bnautilus_password_dialog_destroy (GtkObject *object);
|
||||
static void nautilus_password_dialog_destroy (GtkObject *object);
|
||||
|
||||
|
||||
/* GtkDialog callbacks */
|
||||
static void dialog_clicked_callback (GtkWidget *widget,
|
||||
gint n,
|
||||
gpointer data);
|
||||
static void dialog_show_callback (GtkWidget *widget,
|
||||
gpointer data);
|
||||
static void dialog_destroy_callback (GtkWidget *widget,
|
||||
gpointer data);
|
||||
|
||||
/* NautilusCaptionTable callbacks */
|
||||
gpointer callback_data);
|
||||
static void dialog_close_callback (GtkWidget *widget,
|
||||
gpointer callback_data);
|
||||
/* Caption table callbacks */
|
||||
static void caption_table_activate_callback (GtkWidget *widget,
|
||||
gint entry,
|
||||
gpointer data);
|
||||
gpointer callback_data);
|
||||
|
||||
|
||||
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPasswordDialog,
|
||||
nautilus_password_dialog,
|
||||
|
@ -102,72 +100,107 @@ nautilus_password_dialog_initialize_class (NautilusPasswordDialogClass * klass)
|
|||
widget_class = GTK_WIDGET_CLASS(klass);
|
||||
|
||||
/* GtkObjectClass */
|
||||
object_class->destroy = bnautilus_password_dialog_destroy;
|
||||
object_class->destroy = nautilus_password_dialog_destroy;
|
||||
}
|
||||
|
||||
static void
|
||||
nautilus_password_dialog_initialize (NautilusPasswordDialog *password_dialog)
|
||||
{
|
||||
password_dialog->detail = g_new (NautilusPasswordDialogDetail, 1);
|
||||
password_dialog->details = g_new (NautilusPasswordDialogDetails, 1);
|
||||
|
||||
password_dialog->detail->username = NULL;
|
||||
password_dialog->detail->password = NULL;
|
||||
password_dialog->details->username = NULL;
|
||||
password_dialog->details->password = NULL;
|
||||
password_dialog->details->readonly_username = FALSE;
|
||||
|
||||
password_dialog->detail->last_button_clicked = UNKNOWN_BUTTON;
|
||||
password_dialog->detail->readonly_username = FALSE;
|
||||
password_dialog->details->remember_label_text = NULL;
|
||||
password_dialog->details->remember = FALSE;
|
||||
|
||||
password_dialog->detail->table = NULL;
|
||||
password_dialog->details->table = NULL;
|
||||
password_dialog->details->remember_button = NULL;
|
||||
}
|
||||
|
||||
/* GtkObjectClass methods */
|
||||
static void
|
||||
nautilus_password_dialog_destroy (GtkObject* object)
|
||||
{
|
||||
NautilusPasswordDialog *password_dialog;
|
||||
|
||||
g_return_if_fail (object != NULL);
|
||||
g_return_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (object));
|
||||
|
||||
password_dialog = NAUTILUS_PASSWORD_DIALOG (object);
|
||||
|
||||
if (password_dialog->details->username) {
|
||||
g_free (password_dialog->details->username);
|
||||
}
|
||||
|
||||
if (password_dialog->details->password) {
|
||||
g_free (password_dialog->details->password);
|
||||
}
|
||||
|
||||
if (password_dialog->details->remember_label_text) {
|
||||
g_free (password_dialog->details->remember_label_text);
|
||||
}
|
||||
|
||||
g_free (password_dialog->details);
|
||||
}
|
||||
|
||||
/* GtkDialog callbacks */
|
||||
static void
|
||||
dialog_clicked_callback (GtkWidget *widget, gint n, gpointer data)
|
||||
dialog_show_callback (GtkWidget *widget, gpointer callback_data)
|
||||
{
|
||||
NautilusPasswordDialog *password_dialog = (NautilusPasswordDialog *) data;
|
||||
NautilusPasswordDialog *password_dialog;
|
||||
|
||||
g_assert (password_dialog != NULL);
|
||||
g_return_if_fail (callback_data != NULL);
|
||||
g_return_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (callback_data));
|
||||
|
||||
password_dialog->detail->last_button_clicked = n;
|
||||
password_dialog = NAUTILUS_PASSWORD_DIALOG (callback_data);
|
||||
|
||||
gtk_grab_remove(GTK_WIDGET (password_dialog));
|
||||
|
||||
gtk_widget_hide(GTK_WIDGET (password_dialog));
|
||||
/* Move the focus to the password entry */
|
||||
nautilus_caption_table_entry_grab_focus (NAUTILUS_CAPTION_TABLE (password_dialog->details->table),
|
||||
CAPTION_TABLE_PASSWORD_ROW);
|
||||
}
|
||||
|
||||
static void
|
||||
dialog_show_callback (GtkWidget *widget, gpointer data)
|
||||
dialog_close_callback (GtkWidget *widget, gpointer callback_data)
|
||||
{
|
||||
NautilusPasswordDialog *password_dialog = (NautilusPasswordDialog *) data;
|
||||
NautilusPasswordDialog *password_dialog;
|
||||
|
||||
g_assert (password_dialog != NULL);
|
||||
g_return_if_fail (callback_data != NULL);
|
||||
g_return_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (callback_data));
|
||||
|
||||
nautilus_caption_table_entry_grab_focus (NAUTILUS_CAPTION_TABLE (password_dialog->detail->table),
|
||||
PASSWORD_ROW);
|
||||
password_dialog = NAUTILUS_PASSWORD_DIALOG (callback_data);
|
||||
|
||||
gtk_widget_hide (widget);
|
||||
}
|
||||
|
||||
/* Caption table callbacks */
|
||||
static void
|
||||
dialog_destroy_callback (GtkWidget *widget, gpointer data)
|
||||
caption_table_activate_callback (GtkWidget *widget, gint entry, gpointer callback_data)
|
||||
{
|
||||
NautilusPasswordDialog *password_dialog = (NautilusPasswordDialog *) data;
|
||||
NautilusPasswordDialog *password_dialog;
|
||||
|
||||
g_assert (password_dialog != NULL);
|
||||
g_return_if_fail (callback_data != NULL);
|
||||
g_return_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (callback_data));
|
||||
|
||||
g_free (password_dialog->detail);
|
||||
password_dialog = NAUTILUS_PASSWORD_DIALOG (callback_data);
|
||||
|
||||
gtk_grab_remove(GTK_WIDGET (password_dialog));
|
||||
}
|
||||
/* If the username entry was activated, simply advance the focus to the password entry */
|
||||
if (entry == CAPTION_TABLE_USERNAME_ROW) {
|
||||
nautilus_caption_table_entry_grab_focus (NAUTILUS_CAPTION_TABLE (password_dialog->details->table),
|
||||
CAPTION_TABLE_PASSWORD_ROW);
|
||||
}
|
||||
/* If the password entry was activated, then simulate and OK button press to continue to hide process */
|
||||
else if (entry == CAPTION_TABLE_PASSWORD_ROW) {
|
||||
GtkWidget *button;
|
||||
|
||||
button = g_list_nth_data (GNOME_DIALOG (password_dialog)->buttons, DIALOG_OK_BUTTON);
|
||||
|
||||
g_assert (button != NULL);
|
||||
g_assert (GTK_IS_BUTTON (button));
|
||||
|
||||
|
||||
/* NautilusCaptionTable callbacks */
|
||||
static void
|
||||
caption_table_activate_callback (GtkWidget *widget, gint entry, gpointer data)
|
||||
{
|
||||
NautilusPasswordDialog *password_dialog = (NautilusPasswordDialog *) data;
|
||||
|
||||
g_assert (password_dialog != NULL);
|
||||
|
||||
if (entry == (nautilus_caption_table_get_num_rows (NAUTILUS_CAPTION_TABLE (widget)) - 1))
|
||||
dialog_clicked_callback(GTK_WIDGET (password_dialog), OK_BUTTON, (gpointer) password_dialog);
|
||||
gtk_button_clicked (GTK_BUTTON (button));
|
||||
}
|
||||
}
|
||||
|
||||
/* Public NautilusPasswordDialog methods */
|
||||
|
@ -189,51 +222,48 @@ nautilus_password_dialog_new (const char *dialog_title,
|
|||
TRUE, /* allow_grow */
|
||||
FALSE); /* auto_shrink */
|
||||
|
||||
gtk_widget_realize (GTK_WIDGET (password_dialog));
|
||||
|
||||
gdk_window_set_functions (GTK_WIDGET (password_dialog)->window,
|
||||
GDK_FUNC_ALL | GDK_FUNC_RESIZE | GDK_FUNC_MINIMIZE);
|
||||
|
||||
gtk_window_set_position (GTK_WINDOW (password_dialog), GTK_WIN_POS_CENTER);
|
||||
gtk_window_set_modal (GTK_WINDOW (password_dialog), TRUE);
|
||||
|
||||
gtk_container_set_border_width (GTK_CONTAINER (password_dialog),
|
||||
DEFAULT_BORDER_WIDTH);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (password_dialog), DIALOG_BORDER_WIDTH);
|
||||
|
||||
gnome_dialog_set_default (GNOME_DIALOG (password_dialog),
|
||||
DEFAULT_BUTTON);
|
||||
gnome_dialog_set_default (GNOME_DIALOG (password_dialog), DIALOG_OK_BUTTON);
|
||||
|
||||
gtk_signal_connect(GTK_OBJECT (password_dialog),
|
||||
"clicked",
|
||||
GTK_SIGNAL_FUNC (dialog_clicked_callback),
|
||||
(gpointer) password_dialog);
|
||||
/* Dont close the dialog on click. We'll mange the destruction our selves */
|
||||
gnome_dialog_set_close (GNOME_DIALOG (password_dialog), FALSE);
|
||||
|
||||
gtk_signal_connect(GTK_OBJECT (password_dialog),
|
||||
"show",
|
||||
GTK_SIGNAL_FUNC (dialog_show_callback),
|
||||
(gpointer) password_dialog);
|
||||
|
||||
gtk_signal_connect(GTK_OBJECT (password_dialog),
|
||||
"destroy",
|
||||
GTK_SIGNAL_FUNC (dialog_destroy_callback),
|
||||
(gpointer) password_dialog);
|
||||
/* Make the close operation 'just_hide' the dialog - not nuke it */
|
||||
gnome_dialog_close_hides (GNOME_DIALOG (password_dialog), TRUE);
|
||||
|
||||
/* The table that holds the captions */
|
||||
password_dialog->detail->table = nautilus_caption_table_new (2);
|
||||
gtk_signal_connect_while_alive (GTK_OBJECT (password_dialog),
|
||||
"show",
|
||||
GTK_SIGNAL_FUNC (dialog_show_callback),
|
||||
(gpointer) password_dialog,
|
||||
GTK_OBJECT (password_dialog));
|
||||
|
||||
gtk_signal_connect_while_alive (GTK_OBJECT (password_dialog),
|
||||
"close",
|
||||
GTK_SIGNAL_FUNC (dialog_close_callback),
|
||||
(gpointer) password_dialog,
|
||||
GTK_OBJECT (password_dialog));
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (password_dialog->detail->table),
|
||||
/* The table that holds the captions */
|
||||
password_dialog->details->table = nautilus_caption_table_new (2);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (password_dialog->details->table),
|
||||
"activate",
|
||||
GTK_SIGNAL_FUNC (caption_table_activate_callback),
|
||||
(gpointer) password_dialog);
|
||||
|
||||
nautilus_caption_table_set_row_info (NAUTILUS_CAPTION_TABLE (password_dialog->detail->table),
|
||||
USERNAME_ROW,
|
||||
nautilus_caption_table_set_row_info (NAUTILUS_CAPTION_TABLE (password_dialog->details->table),
|
||||
CAPTION_TABLE_USERNAME_ROW,
|
||||
"Username:",
|
||||
"",
|
||||
TRUE,
|
||||
TRUE);
|
||||
|
||||
nautilus_caption_table_set_row_info (NAUTILUS_CAPTION_TABLE (password_dialog->detail->table),
|
||||
PASSWORD_ROW,
|
||||
nautilus_caption_table_set_row_info (NAUTILUS_CAPTION_TABLE (password_dialog->details->table),
|
||||
CAPTION_TABLE_PASSWORD_ROW,
|
||||
"Password:",
|
||||
"",
|
||||
FALSE,
|
||||
|
@ -245,15 +275,23 @@ nautilus_password_dialog_new (const char *dialog_title,
|
|||
gtk_box_set_spacing (GTK_BOX (GNOME_DIALOG (password_dialog)->vbox), 10);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (password_dialog)->vbox),
|
||||
password_dialog->detail->table,
|
||||
password_dialog->details->table,
|
||||
TRUE, /* expand */
|
||||
TRUE, /* fill */
|
||||
0); /* padding */
|
||||
|
||||
/* Configure the table */
|
||||
gtk_container_set_border_width (GTK_CONTAINER(password_dialog->detail->table),
|
||||
DEFAULT_BORDER_WIDTH);
|
||||
password_dialog->details->remember_button =
|
||||
gtk_check_button_new_with_label ("Remember this password");
|
||||
|
||||
gtk_box_pack_end (GTK_BOX (GNOME_DIALOG (password_dialog)->vbox),
|
||||
password_dialog->details->remember_button,
|
||||
TRUE, /* expand */
|
||||
TRUE, /* fill */
|
||||
4); /* padding */
|
||||
|
||||
/* Configure the table */
|
||||
gtk_container_set_border_width (GTK_CONTAINER(password_dialog->details->table), CAPTION_TABLE_BORDER_WIDTH);
|
||||
|
||||
gtk_widget_show_all (GNOME_DIALOG (password_dialog)->vbox);
|
||||
|
||||
nautilus_password_dialog_set_username (password_dialog, username);
|
||||
|
@ -263,78 +301,52 @@ nautilus_password_dialog_new (const char *dialog_title,
|
|||
return GTK_WIDGET (password_dialog);
|
||||
}
|
||||
|
||||
/* GtkObjectClass methods */
|
||||
static void
|
||||
bnautilus_password_dialog_destroy (GtkObject* object)
|
||||
{
|
||||
NautilusPasswordDialog *password_dialog;
|
||||
|
||||
g_return_if_fail (object != NULL);
|
||||
g_return_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (object));
|
||||
|
||||
password_dialog = NAUTILUS_PASSWORD_DIALOG (object);
|
||||
|
||||
if (password_dialog->detail->username)
|
||||
g_free (password_dialog->detail->username);
|
||||
|
||||
if (password_dialog->detail->password)
|
||||
g_free (password_dialog->detail->password);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nautilus_password_dialog_run_and_block(NautilusPasswordDialog *password_dialog)
|
||||
nautilus_password_dialog_run_and_block (NautilusPasswordDialog *password_dialog)
|
||||
{
|
||||
gint button_clicked;
|
||||
|
||||
g_return_val_if_fail (password_dialog != NULL, FALSE);
|
||||
g_return_val_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (password_dialog), FALSE);
|
||||
|
||||
password_dialog->detail->last_button_clicked = UNKNOWN_BUTTON;
|
||||
|
||||
gtk_widget_show_all (GTK_WIDGET (password_dialog));
|
||||
|
||||
gtk_grab_add (GTK_WIDGET (password_dialog));
|
||||
button_clicked = gnome_dialog_run_and_close (GNOME_DIALOG (password_dialog));
|
||||
|
||||
while (password_dialog->detail->last_button_clicked == UNKNOWN_BUTTON)
|
||||
gtk_main_iteration ();
|
||||
|
||||
if (password_dialog->detail->last_button_clicked == OK_BUTTON)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
return (button_clicked == DIALOG_OK_BUTTON);
|
||||
}
|
||||
|
||||
void
|
||||
nautilus_password_dialog_set_username (NautilusPasswordDialog *password_dialog,
|
||||
const char * username)
|
||||
nautilus_password_dialog_set_username (NautilusPasswordDialog *password_dialog,
|
||||
const char *username)
|
||||
{
|
||||
g_return_if_fail (password_dialog != NULL);
|
||||
g_return_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (password_dialog));
|
||||
|
||||
nautilus_caption_table_set_entry_text (NAUTILUS_CAPTION_TABLE (password_dialog->detail->table),
|
||||
USERNAME_ROW,
|
||||
nautilus_caption_table_set_entry_text (NAUTILUS_CAPTION_TABLE (password_dialog->details->table),
|
||||
CAPTION_TABLE_USERNAME_ROW,
|
||||
username);
|
||||
}
|
||||
|
||||
void
|
||||
nautilus_password_dialog_set_password (NautilusPasswordDialog *password_dialog,
|
||||
const char * password)
|
||||
nautilus_password_dialog_set_password (NautilusPasswordDialog *password_dialog,
|
||||
const char *password)
|
||||
{
|
||||
g_return_if_fail (password_dialog != NULL);
|
||||
g_return_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (password_dialog));
|
||||
|
||||
nautilus_caption_table_set_entry_text (NAUTILUS_CAPTION_TABLE (password_dialog->detail->table),
|
||||
PASSWORD_ROW,
|
||||
nautilus_caption_table_set_entry_text (NAUTILUS_CAPTION_TABLE (password_dialog->details->table),
|
||||
CAPTION_TABLE_PASSWORD_ROW,
|
||||
password);
|
||||
}
|
||||
|
||||
void
|
||||
nautilus_password_dialog_set_readonly_username (NautilusPasswordDialog *password_dialog,
|
||||
gboolean readonly)
|
||||
nautilus_password_dialog_set_readonly_username (NautilusPasswordDialog *password_dialog,
|
||||
gboolean readonly)
|
||||
{
|
||||
g_return_if_fail (password_dialog != NULL);
|
||||
g_return_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (password_dialog));
|
||||
|
||||
nautilus_caption_table_set_entry_readonly (NAUTILUS_CAPTION_TABLE (password_dialog->detail->table),
|
||||
USERNAME_ROW,
|
||||
nautilus_caption_table_set_entry_readonly (NAUTILUS_CAPTION_TABLE (password_dialog->details->table),
|
||||
CAPTION_TABLE_USERNAME_ROW,
|
||||
readonly);
|
||||
}
|
||||
|
||||
|
@ -344,8 +356,8 @@ nautilus_password_dialog_get_username (NautilusPasswordDialog *password_dialog)
|
|||
g_return_val_if_fail (password_dialog != NULL, NULL);
|
||||
g_return_val_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (password_dialog), NULL);
|
||||
|
||||
return nautilus_caption_table_get_entry_text (NAUTILUS_CAPTION_TABLE (password_dialog->detail->table),
|
||||
USERNAME_ROW);
|
||||
return nautilus_caption_table_get_entry_text (NAUTILUS_CAPTION_TABLE (password_dialog->details->table),
|
||||
CAPTION_TABLE_USERNAME_ROW);
|
||||
}
|
||||
|
||||
char *
|
||||
|
@ -354,6 +366,43 @@ nautilus_password_dialog_get_password (NautilusPasswordDialog *password_dialog)
|
|||
g_return_val_if_fail (password_dialog != NULL, NULL);
|
||||
g_return_val_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (password_dialog), NULL);
|
||||
|
||||
return nautilus_caption_table_get_entry_text (NAUTILUS_CAPTION_TABLE (password_dialog->detail->table),
|
||||
PASSWORD_ROW);
|
||||
return nautilus_caption_table_get_entry_text (NAUTILUS_CAPTION_TABLE (password_dialog->details->table),
|
||||
CAPTION_TABLE_PASSWORD_ROW);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nautilus_password_dialog_get_remember (NautilusPasswordDialog *password_dialog)
|
||||
{
|
||||
g_return_val_if_fail (password_dialog != NULL, FALSE);
|
||||
g_return_val_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (password_dialog), FALSE);
|
||||
|
||||
return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (password_dialog->details->remember_button));
|
||||
}
|
||||
|
||||
void
|
||||
nautilus_password_dialog_set_remember (NautilusPasswordDialog *password_dialog,
|
||||
gboolean remember)
|
||||
{
|
||||
g_return_if_fail (password_dialog != NULL);
|
||||
g_return_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (password_dialog));
|
||||
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (password_dialog->details->remember_button),
|
||||
remember);
|
||||
}
|
||||
|
||||
void
|
||||
nautilus_password_dialog_set_remember_label_text (NautilusPasswordDialog *password_dialog,
|
||||
const char *remember_label_text)
|
||||
{
|
||||
GtkWidget *label;
|
||||
|
||||
g_return_if_fail (password_dialog != NULL);
|
||||
g_return_if_fail (NAUTILUS_IS_PASSWORD_DIALOG (password_dialog));
|
||||
|
||||
label = GTK_BIN (password_dialog->details->remember_button)->child;
|
||||
|
||||
g_assert (label != NULL);
|
||||
g_assert (GTK_IS_LABEL (label));
|
||||
|
||||
gtk_label_set_text (GTK_LABEL (label), remember_label_text);
|
||||
}
|
||||
|
|
|
@ -37,13 +37,13 @@ BEGIN_GNOME_DECLS
|
|||
|
||||
typedef struct _NautilusPasswordDialog NautilusPasswordDialog;
|
||||
typedef struct _NautilusPasswordDialogClass NautilusPasswordDialogClass;
|
||||
typedef struct _NautilusPasswordDialogDetail NautilusPasswordDialogDetail;
|
||||
typedef struct _NautilusPasswordDialogDetails NautilusPasswordDialogDetails;
|
||||
|
||||
struct _NautilusPasswordDialog
|
||||
{
|
||||
GnomeDialog gnome_dialog;
|
||||
|
||||
NautilusPasswordDialogDetail *detail;
|
||||
NautilusPasswordDialogDetails *details;
|
||||
};
|
||||
|
||||
struct _NautilusPasswordDialogClass
|
||||
|
@ -52,20 +52,29 @@ struct _NautilusPasswordDialogClass
|
|||
};
|
||||
|
||||
|
||||
GtkType nautilus_password_dialog_get_type (void);
|
||||
GtkWidget* nautilus_password_dialog_new (const char *dialog_title,
|
||||
const char *username,
|
||||
const char *password,
|
||||
gboolean readonly_username);
|
||||
gboolean nautilus_password_dialog_run_and_block (NautilusPasswordDialog *auth_dialog);
|
||||
void nautilus_password_dialog_set_username (NautilusPasswordDialog *auth_dialog,
|
||||
GtkType nautilus_password_dialog_get_type (void);
|
||||
GtkWidget* nautilus_password_dialog_new (const char *dialog_title,
|
||||
const char *username,
|
||||
const char *password,
|
||||
gboolean readonly_username);
|
||||
gboolean nautilus_password_dialog_run_and_block (NautilusPasswordDialog *password_dialog);
|
||||
|
||||
/* Attribute mutators */
|
||||
void nautilus_password_dialog_set_username (NautilusPasswordDialog *password_dialog,
|
||||
const char *username);
|
||||
void nautilus_password_dialog_set_password (NautilusPasswordDialog *auth_dialog,
|
||||
void nautilus_password_dialog_set_password (NautilusPasswordDialog *password_dialog,
|
||||
const char *password);
|
||||
void nautilus_password_dialog_set_readonly_username (NautilusPasswordDialog *auth_dialog,
|
||||
void nautilus_password_dialog_set_readonly_username (NautilusPasswordDialog *password_dialog,
|
||||
gboolean readonly);
|
||||
char * nautilus_password_dialog_get_username (NautilusPasswordDialog *auth_dialog);
|
||||
char * nautilus_password_dialog_get_password (NautilusPasswordDialog *auth_dialog);
|
||||
void nautilus_password_dialog_set_remember (NautilusPasswordDialog *password_dialog,
|
||||
gboolean remember);
|
||||
void nautilus_password_dialog_set_remember_label_text (NautilusPasswordDialog *password_dialog,
|
||||
const char *remember_label_text);
|
||||
|
||||
/* Attribute accessors */
|
||||
char * nautilus_password_dialog_get_username (NautilusPasswordDialog *password_dialog);
|
||||
char * nautilus_password_dialog_get_password (NautilusPasswordDialog *password_dialog);
|
||||
gboolean nautilus_password_dialog_get_remember (NautilusPasswordDialog *password_dialog);
|
||||
|
||||
BEGIN_GNOME_DECLS
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
*.lo
|
||||
Makefile
|
||||
Makefile.in
|
||||
test-nautilus-graphic
|
||||
test-nautilus-mime-actions
|
||||
test-nautilus-mime-actions-set
|
||||
test-nautilus-widgets
|
||||
test-nautilus-password-dialog
|
||||
test-nautilus-preferences
|
||||
test-nautilus-graphic
|
||||
|
||||
test-nautilus-widgets
|
||||
|
|
97
test/test-nautilus-password-dialog.c
Normal file
97
test/test-nautilus-password-dialog.c
Normal file
|
@ -0,0 +1,97 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#include <libnautilus-extensions/nautilus-password-dialog.h>
|
||||
#include <gnome.h>
|
||||
|
||||
static GtkWidget *password_dialog = NULL;
|
||||
|
||||
static void
|
||||
authenticate_boink_callback (GtkWidget *button, gpointer user_data)
|
||||
{
|
||||
gboolean result;
|
||||
char *username;
|
||||
char *password;
|
||||
gboolean remember;
|
||||
|
||||
if (password_dialog == NULL) {
|
||||
password_dialog = nautilus_password_dialog_new ("Authenticate Me",
|
||||
"foouser",
|
||||
"sekret",
|
||||
TRUE);
|
||||
|
||||
nautilus_password_dialog_set_remember_label_text (NAUTILUS_PASSWORD_DIALOG (password_dialog),
|
||||
"Remember foouser's password");
|
||||
}
|
||||
|
||||
result = nautilus_password_dialog_run_and_block (NAUTILUS_PASSWORD_DIALOG (password_dialog));
|
||||
|
||||
username = nautilus_password_dialog_get_username (NAUTILUS_PASSWORD_DIALOG (password_dialog));
|
||||
password = nautilus_password_dialog_get_password (NAUTILUS_PASSWORD_DIALOG (password_dialog));
|
||||
remember = nautilus_password_dialog_get_remember (NAUTILUS_PASSWORD_DIALOG (password_dialog));
|
||||
|
||||
g_assert (username != NULL);
|
||||
g_assert (password != NULL);
|
||||
|
||||
if (result) {
|
||||
g_print ("authentication submitted: username='%s' , password='%s' , remember=%s\n",
|
||||
username,
|
||||
password,
|
||||
remember ? "TRUE" : "FALSE");
|
||||
}
|
||||
else {
|
||||
g_print ("authentication cancelled:\n");
|
||||
}
|
||||
|
||||
g_free (username);
|
||||
g_free (password);
|
||||
}
|
||||
|
||||
static void
|
||||
exit_callback (GtkWidget *button, gpointer user_data)
|
||||
{
|
||||
if (password_dialog != NULL) {
|
||||
gtk_widget_destroy (password_dialog);
|
||||
}
|
||||
|
||||
gtk_main_quit ();
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char * argv[])
|
||||
{
|
||||
GtkWidget *window;
|
||||
GtkWidget *vbox;
|
||||
GtkWidget *authenticate_button;
|
||||
GtkWidget *exit_button;
|
||||
|
||||
gnome_init ("foo", "bar", argc, argv);
|
||||
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (window), 4);
|
||||
|
||||
vbox = gtk_vbox_new (TRUE, 0);
|
||||
gtk_container_add (GTK_CONTAINER (window), vbox);
|
||||
|
||||
authenticate_button = gtk_button_new_with_label ("Boink me to authenticate");
|
||||
exit_button = gtk_button_new_with_label ("Exit");
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (authenticate_button),
|
||||
"clicked",
|
||||
GTK_SIGNAL_FUNC (authenticate_boink_callback),
|
||||
(gpointer) NULL);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (exit_button),
|
||||
"clicked",
|
||||
GTK_SIGNAL_FUNC (exit_callback),
|
||||
(gpointer) NULL);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (vbox), authenticate_button, TRUE, TRUE, 4);
|
||||
gtk_box_pack_end (GTK_BOX (vbox), exit_button, TRUE, TRUE, 0);
|
||||
|
||||
gtk_widget_show_all (window);
|
||||
|
||||
gtk_main ();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -2,7 +2,6 @@
|
|||
#include <config.h>
|
||||
|
||||
#include <libnautilus-extensions/nautilus-caption-table.h>
|
||||
#include <libnautilus-extensions/nautilus-password-dialog.h>
|
||||
#include <libnautilus-extensions/nautilus-radio-button-group.h>
|
||||
#include <libnautilus-extensions/nautilus-string-picker.h>
|
||||
#include <libnautilus-extensions/nautilus-text-caption.h>
|
||||
|
@ -11,15 +10,12 @@
|
|||
|
||||
static void test_radio_group (void);
|
||||
static void test_caption_table (void);
|
||||
static void test_password_dialog (void);
|
||||
static void test_string_picker (void);
|
||||
static void test_text_caption (void);
|
||||
|
||||
/* Callbacks */
|
||||
static void test_radio_changed_callback (GtkWidget *button_group,
|
||||
gpointer user_data);
|
||||
static void test_authenticate_boink_callback (GtkWidget *button,
|
||||
gpointer user_data);
|
||||
static void string_picker_changed_callback (GtkWidget *string_picker,
|
||||
gpointer user_data);
|
||||
static void text_caption_changed_callback (GtkWidget *text_caption,
|
||||
|
@ -35,7 +31,6 @@ main (int argc, char * argv[])
|
|||
|
||||
test_radio_group ();
|
||||
test_caption_table ();
|
||||
test_password_dialog ();
|
||||
test_string_picker ();
|
||||
test_text_caption ();
|
||||
|
||||
|
@ -182,36 +177,6 @@ test_text_caption (void)
|
|||
gtk_widget_show_all (window);
|
||||
}
|
||||
|
||||
static void
|
||||
test_authenticate_boink_callback (GtkWidget *button, gpointer user_data)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
gboolean rv;
|
||||
char *username;
|
||||
char *password;
|
||||
|
||||
dialog = nautilus_password_dialog_new ("Authenticate Me",
|
||||
"foouser",
|
||||
"sekret",
|
||||
FALSE);
|
||||
|
||||
rv = nautilus_password_dialog_run_and_block (NAUTILUS_PASSWORD_DIALOG (dialog));
|
||||
|
||||
username = nautilus_password_dialog_get_username (NAUTILUS_PASSWORD_DIALOG (dialog));
|
||||
password = nautilus_password_dialog_get_password (NAUTILUS_PASSWORD_DIALOG (dialog));
|
||||
|
||||
g_assert (username != NULL);
|
||||
g_assert (password != NULL);
|
||||
|
||||
g_print ("test_authenticate_boink_callback (rv=%d , username='%s' , password='%s')\n",
|
||||
rv,
|
||||
username,
|
||||
password);
|
||||
|
||||
g_free (username);
|
||||
g_free (password);
|
||||
}
|
||||
|
||||
static void
|
||||
string_picker_changed_callback (GtkWidget *string_picker, gpointer user_data)
|
||||
{
|
||||
|
@ -242,28 +207,6 @@ text_caption_changed_callback (GtkWidget *text_caption, gpointer user_data)
|
|||
g_free (text);
|
||||
}
|
||||
|
||||
static void
|
||||
test_password_dialog (void)
|
||||
{
|
||||
GtkWidget * window;
|
||||
GtkWidget * button;
|
||||
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
|
||||
button = gtk_button_new_with_label ("Boink me to authenticate");
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (button),
|
||||
"clicked",
|
||||
GTK_SIGNAL_FUNC (test_authenticate_boink_callback),
|
||||
(gpointer) NULL);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (window), button);
|
||||
|
||||
gtk_widget_show (button);
|
||||
|
||||
gtk_widget_show (window);
|
||||
}
|
||||
|
||||
static void
|
||||
test_radio_changed_callback (GtkWidget *buttons, gpointer user_data)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue