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"
24 static void gtk_get_credentials(struct cli_credentials *credentials)
30 GtkWidget *entry_username;
31 GtkWidget *entry_password;
32 GtkWidget *entry_domain;
33 GtkWidget *dialog_action_area1;
34 GtkWidget *cancelbutton1;
38 dialog = gtk_dialog_new ();
39 gtk_window_set_title (GTK_WINDOW (dialog), "Credentials");
40 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
41 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
43 table = gtk_table_new(4, 2, FALSE);
44 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), table);
46 label = gtk_label_new ("Domain:");
48 gtk_table_attach(GTK_TABLE(table),label,0,1,0,1,GTK_FILL,0,0,0);
50 entry_domain = gtk_entry_new ();
51 gtk_table_attach(GTK_TABLE(table), entry_domain, 1,2,0,1, GTK_FILL, 0,0,0);
52 gtk_entry_set_activates_default (GTK_ENTRY (entry_domain), TRUE);
54 if (credentials->domain_obtained != CRED_UNINITIALISED) {
55 gtk_entry_set_text(GTK_ENTRY(entry_domain), credentials->domain);
58 label = gtk_label_new ("Username:");
60 gtk_table_attach(GTK_TABLE(table),label,0,1,1,2,GTK_FILL,0,0,0);
62 entry_username = gtk_entry_new ();
63 gtk_table_attach(GTK_TABLE(table),entry_username,1,2,1,2,GTK_FILL,0,0,0);
64 gtk_entry_set_activates_default (GTK_ENTRY (entry_username), TRUE);
65 if (credentials->username_obtained != CRED_UNINITIALISED) {
66 gtk_entry_set_text(GTK_ENTRY(entry_username), credentials->username);
69 label = gtk_label_new ("Password:");
71 gtk_table_attach(GTK_TABLE(table),label,0,1,3,4,GTK_FILL,0,0,0);
73 entry_password = gtk_entry_new ();
74 gtk_table_attach(GTK_TABLE(table),entry_password,1,2,3,4,GTK_FILL,0,0,0);
75 gtk_entry_set_visibility (GTK_ENTRY (entry_password), FALSE);
76 gtk_entry_set_activates_default (GTK_ENTRY (entry_password), TRUE);
77 if (credentials->password_obtained != CRED_UNINITIALISED) {
78 gtk_entry_set_text(GTK_ENTRY(entry_password), credentials->password);
81 anonymous = gtk_check_button_new_with_mnemonic("_Anonymous");
82 gtk_table_attach(GTK_TABLE(table),anonymous,0,2,4,5,GTK_FILL,0,0,0);
84 dialog_action_area1 = GTK_DIALOG (dialog)->action_area;
85 gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1), GTK_BUTTONBOX_END);
87 cancelbutton1 = gtk_button_new_from_stock ("gtk-cancel");
88 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), cancelbutton1, GTK_RESPONSE_CANCEL);
89 GTK_WIDGET_SET_FLAGS (cancelbutton1, GTK_CAN_DEFAULT);
91 okbutton1 = gtk_button_new_from_stock ("gtk-ok");
92 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), okbutton1, GTK_RESPONSE_OK);
93 GTK_WIDGET_SET_FLAGS (okbutton1, GTK_CAN_DEFAULT);
95 gtk_widget_show_all (dialog);
97 switch (gtk_dialog_run (GTK_DIALOG (dialog))) {
99 cli_credentials_set_username(credentials, gtk_entry_get_text(GTK_ENTRY(entry_username)), CRED_SPECIFIED);
100 cli_credentials_set_password(credentials, gtk_entry_get_text(GTK_ENTRY(entry_password)), CRED_SPECIFIED);
101 cli_credentials_set_domain(credentials, gtk_entry_get_text(GTK_ENTRY(entry_domain)), CRED_SPECIFIED);
103 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(anonymous))) {
104 cli_credentials_set_anonymous(credentials);
112 gtk_widget_destroy (dialog);
115 static const char *gtk_get_username(struct cli_credentials *credentials)
117 gtk_get_credentials(credentials);
118 return credentials->username;
121 static const char *gtk_get_userpassword(struct cli_credentials *credentials)
123 gtk_get_credentials(credentials);
124 return credentials->password;
127 static const char *gtk_get_domain(struct cli_credentials *credentials)
129 gtk_get_credentials(credentials);
130 return credentials->domain;
133 void cli_credentials_set_gtk_callbacks(struct cli_credentials *cred)
135 if (cred->password_obtained <= CRED_CALLBACK) {
136 cred->password_cb = gtk_get_userpassword;
137 cred->password_obtained = CRED_CALLBACK;
140 if (cred->username_obtained <= CRED_CALLBACK) {
141 cred->username_cb = gtk_get_username;
142 cred->username_obtained = CRED_CALLBACK;
145 if (cred->domain_obtained <= CRED_CALLBACK) {
146 cred->domain_cb = gtk_get_domain;
147 cred->domain_obtained = CRED_CALLBACK;