2 Unix SMB/CIFS implementation.
4 Copyright (C) Jelmer Vernooij 2005
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "gtk/common/gtk-smb.h"
23 #include "auth/credentials/credentials.h"
25 static void gtk_get_credentials(struct cli_credentials
*credentials
)
31 GtkWidget
*entry_username
;
32 GtkWidget
*entry_password
;
33 GtkWidget
*dialog_action_area1
;
34 GtkWidget
*cancelbutton1
;
39 dialog
= gtk_dialog_new ();
40 gtk_window_set_title (GTK_WINDOW (dialog
), "Credentials");
41 gtk_window_set_resizable (GTK_WINDOW (dialog
), FALSE
);
42 gtk_window_set_type_hint (GTK_WINDOW (dialog
), GDK_WINDOW_TYPE_HINT_DIALOG
);
44 table
= gtk_table_new(4, 2, FALSE
);
45 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->vbox
), table
);
47 label
= gtk_label_new ("Username:");
49 gtk_table_attach(GTK_TABLE(table
),label
,0,1,1,2,GTK_FILL
,0,0,0);
51 entry_username
= gtk_entry_new ();
52 gtk_table_attach(GTK_TABLE(table
),entry_username
,1,2,1,2,GTK_FILL
,0,0,0);
53 gtk_entry_set_activates_default (GTK_ENTRY (entry_username
), TRUE
);
55 username
= cli_credentials_get_unparsed_name(credentials
, credentials
);
57 if (credentials
->username_obtained
!= CRED_UNINITIALISED
&&
59 gtk_entry_set_text(GTK_ENTRY(entry_username
), username
);
62 label
= gtk_label_new ("Password:");
64 gtk_table_attach(GTK_TABLE(table
),label
,0,1,3,4,GTK_FILL
,0,0,0);
66 entry_password
= gtk_entry_new ();
67 gtk_table_attach(GTK_TABLE(table
),entry_password
,1,2,3,4,GTK_FILL
,0,0,0);
68 gtk_entry_set_visibility (GTK_ENTRY (entry_password
), FALSE
);
69 gtk_entry_set_activates_default (GTK_ENTRY (entry_password
), TRUE
);
70 if (credentials
->password_obtained
!= CRED_UNINITIALISED
&&
71 credentials
->password_obtained
!= CRED_CALLBACK
&&
72 credentials
->password
) {
73 gtk_entry_set_text(GTK_ENTRY(entry_password
), credentials
->password
);
76 anonymous
= gtk_check_button_new_with_mnemonic("_Anonymous");
77 gtk_table_attach(GTK_TABLE(table
),anonymous
,0,2,4,5,GTK_FILL
,0,0,0);
79 dialog_action_area1
= GTK_DIALOG (dialog
)->action_area
;
80 gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1
), GTK_BUTTONBOX_END
);
82 cancelbutton1
= gtk_button_new_from_stock ("gtk-cancel");
83 gtk_dialog_add_action_widget (GTK_DIALOG (dialog
), cancelbutton1
, GTK_RESPONSE_CANCEL
);
84 GTK_WIDGET_SET_FLAGS (cancelbutton1
, GTK_CAN_DEFAULT
);
86 okbutton1
= gtk_button_new_from_stock ("gtk-ok");
87 gtk_dialog_add_action_widget (GTK_DIALOG (dialog
), okbutton1
, GTK_RESPONSE_OK
);
88 GTK_WIDGET_SET_FLAGS (okbutton1
, GTK_CAN_DEFAULT
);
90 gtk_widget_show_all (dialog
);
92 switch (gtk_dialog_run (GTK_DIALOG (dialog
))) {
94 cli_credentials_parse_string(credentials
, gtk_entry_get_text(GTK_ENTRY(entry_username
)), CRED_CALLBACK_RESULT
);
95 cli_credentials_set_password(credentials
, gtk_entry_get_text(GTK_ENTRY(entry_password
)), CRED_CALLBACK_RESULT
);
97 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(anonymous
))) {
98 cli_credentials_set_anonymous(credentials
);
106 gtk_widget_destroy (dialog
);
109 static const char *gtk_get_username(struct cli_credentials
*credentials
)
111 gtk_get_credentials(credentials
);
112 return credentials
->username
;
115 static const char *gtk_get_userpassword(struct cli_credentials
*credentials
)
117 gtk_get_credentials(credentials
);
118 return credentials
->password
;
121 static const char *gtk_get_domain(struct cli_credentials
*credentials
)
123 gtk_get_credentials(credentials
);
124 return credentials
->domain
;
127 void cli_credentials_set_gtk_callbacks(struct cli_credentials
*cred
)
129 cli_credentials_set_username_callback(cred
, gtk_get_username
);
130 cli_credentials_set_domain_callback(cred
, gtk_get_domain
);
131 cli_credentials_set_password_callback(cred
, gtk_get_userpassword
);