2 Unix SMB/CIFS implementation.
3 SMB-related GTK+ functions
5 Copyright (C) Jelmer Vernooij 2004
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 /* GtkSelectDomainDialog */
27 const char *gtk_select_domain_dialog_get_domain(GtkSelectDomainDialog *d)
29 return gtk_entry_get_text(GTK_ENTRY(d->entry_domain));
32 void gtk_select_domain_dialog_init (GtkSelectDomainDialog *select_domain_dialog)
34 GtkWidget *dialog_vbox1;
37 GtkWidget *scrolledwindow1;
38 GtkWidget *dialog_action_area1;
39 GtkWidget *cancelbutton1;
41 GtkCellRenderer *renderer;
42 GtkTreeViewColumn *curcol;
44 gtk_window_set_title (GTK_WINDOW (select_domain_dialog), "Select Domain");
46 dialog_vbox1 = GTK_DIALOG (select_domain_dialog)->vbox;
47 gtk_widget_show (dialog_vbox1);
49 hbox1 = gtk_hbox_new (FALSE, 0);
50 gtk_widget_show (hbox1);
51 gtk_box_pack_start (GTK_BOX (dialog_vbox1), hbox1, TRUE, TRUE, 0);
53 label1 = gtk_label_new ("Domain:");
54 gtk_widget_show (label1);
55 gtk_box_pack_start (GTK_BOX (hbox1), label1, FALSE, FALSE, 0);
57 select_domain_dialog->entry_domain = gtk_entry_new ();
58 gtk_widget_show (select_domain_dialog->entry_domain);
59 gtk_box_pack_start (GTK_BOX (hbox1), select_domain_dialog->entry_domain, TRUE, TRUE, 0);
61 scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
62 gtk_widget_show (scrolledwindow1);
63 gtk_box_pack_start (GTK_BOX (dialog_vbox1), scrolledwindow1, TRUE, TRUE, 0);
65 select_domain_dialog->list_domains = gtk_tree_view_new ();
66 gtk_widget_show (select_domain_dialog->list_domains);
67 gtk_container_add (GTK_CONTAINER (scrolledwindow1), select_domain_dialog->list_domains);
69 curcol = gtk_tree_view_column_new ();
70 gtk_tree_view_column_set_title(curcol, "Name");
71 renderer = gtk_cell_renderer_text_new();
72 gtk_tree_view_column_pack_start(curcol, renderer, True);
73 gtk_tree_view_append_column(GTK_TREE_VIEW(select_domain_dialog->list_domains), curcol);
74 gtk_tree_view_column_add_attribute(curcol, renderer, "text", 0);
76 select_domain_dialog->store_domains = gtk_list_store_new(1, G_TYPE_STRING);
77 gtk_tree_view_set_model(GTK_TREE_VIEW(select_domain_dialog->list_domains), GTK_TREE_MODEL(select_domain_dialog->store_domains));
78 g_object_unref(select_domain_dialog->store_domains);
80 dialog_action_area1 = GTK_DIALOG (select_domain_dialog)->action_area;
81 gtk_widget_show (dialog_action_area1);
82 gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1), GTK_BUTTONBOX_END);
84 cancelbutton1 = gtk_button_new_from_stock ("gtk-cancel");
85 gtk_widget_show (cancelbutton1);
86 gtk_dialog_add_action_widget (GTK_DIALOG (select_domain_dialog), cancelbutton1, GTK_RESPONSE_CANCEL);
87 GTK_WIDGET_SET_FLAGS (cancelbutton1, GTK_CAN_DEFAULT);
89 okbutton1 = gtk_button_new_from_stock ("gtk-ok");
90 gtk_widget_show (okbutton1);
91 gtk_dialog_add_action_widget (GTK_DIALOG (select_domain_dialog), okbutton1, GTK_RESPONSE_OK);
92 GTK_WIDGET_SET_FLAGS (okbutton1, GTK_CAN_DEFAULT);
95 struct policy_handle gtk_select_domain_dialog_get_handle(GtkSelectDomainDialog *d)
97 struct policy_handle h;
104 GType gtk_select_domain_dialog_get_type ()
106 static GType mytype = 0;
110 static const GTypeInfo myinfo =
112 sizeof (GtkSelectDomainDialogClass),
118 sizeof(GtkSelectDomainDialog),
120 (GInstanceInitFunc) gtk_select_domain_dialog_init,
123 mytype = g_type_register_static (GTK_TYPE_DIALOG,
124 "GtkSelectDomainDialog", &myinfo, 0);
130 GtkWidget *gtk_select_domain_dialog_new (struct dcerpc_pipe *sam_pipe)
132 GtkSelectDomainDialog *d = gtk_type_new (gtk_select_domain_dialog_get_type ());
134 struct samr_EnumDomains r;
135 struct samr_Connect cr;
136 struct samr_Close dr;
137 struct policy_handle handle;
138 uint32_t resume_handle = 0;
140 TALLOC_CTX *mem_ctx = talloc_init("gtk_select_domain_dialog_new");
142 d->sam_pipe = sam_pipe;
144 cr.in.system_name = 0;
145 cr.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
146 cr.out.handle = &handle;
148 status = dcerpc_samr_Connect(sam_pipe, mem_ctx, &cr);
149 if (!NT_STATUS_IS_OK(status)) {
150 gtk_show_ntstatus(NULL, status);
151 talloc_destroy(mem_ctx);
152 return GTK_WIDGET(d);
155 r.in.handle = &handle;
156 r.in.resume_handle = &resume_handle;
157 r.in.buf_size = (uint32_t)-1;
158 r.out.resume_handle = &resume_handle;
160 status = dcerpc_samr_EnumDomains(sam_pipe, mem_ctx, &r);
161 if (!NT_STATUS_IS_OK(status)) {
162 gtk_show_ntstatus(NULL, status);
163 } else if (r.out.sam) {
164 for (i=0;i<r.out.sam->count;i++) {
166 printf("- %s\n", r.out.sam->entries[i].name.name);
167 gtk_list_store_append(d->store_domains, &iter);
168 gtk_list_store_set (d->store_domains, &iter, 0, r.out.sam->entries[i].name.name, -1);
172 dr.in.handle = &handle;
173 dr.out.handle = &handle;
175 status = dcerpc_samr_Close(sam_pipe, mem_ctx, &dr);
176 if (!NT_STATUS_IS_OK(status)) {
177 gtk_show_ntstatus(NULL, status);
178 talloc_destroy(mem_ctx);
179 return GTK_WIDGET ( d );
182 talloc_destroy(mem_ctx);
184 return GTK_WIDGET ( d );
188 /* GtkSelectHostDialog */
189 const char *gtk_select_host_dialog_get_host (GtkSelectHostDialog *d)
191 return gtk_entry_get_text(GTK_ENTRY(d->entry_host));
194 void gtk_select_host_dialog_init (GtkSelectHostDialog *select_host_dialog)
196 GtkWidget *dialog_vbox2;
199 GtkWidget *entry_host;
200 GtkWidget *scrolledwindow2;
201 GtkWidget *dialog_action_area2;
202 GtkWidget *cancelbutton2;
203 GtkWidget *okbutton2;
205 gtk_window_set_title (GTK_WINDOW (select_host_dialog), "Select Host");
207 dialog_vbox2 = GTK_DIALOG (select_host_dialog)->vbox;
208 gtk_widget_show (dialog_vbox2);
210 hbox2 = gtk_hbox_new (FALSE, 0);
211 gtk_widget_show (hbox2);
212 gtk_box_pack_start (GTK_BOX (dialog_vbox2), hbox2, TRUE, TRUE, 0);
214 label2 = gtk_label_new ("Host");
215 gtk_widget_show (label2);
216 gtk_box_pack_start (GTK_BOX (hbox2), label2, FALSE, FALSE, 0);
218 select_host_dialog->entry_host = gtk_entry_new ();
219 gtk_widget_show (select_host_dialog->entry_host);
220 gtk_box_pack_start (GTK_BOX (hbox2), select_host_dialog->entry_host, TRUE, TRUE, 0);
222 scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
223 gtk_widget_show (scrolledwindow2);
224 gtk_box_pack_start (GTK_BOX (dialog_vbox2), scrolledwindow2, TRUE, TRUE, 0);
226 select_host_dialog->tree_host = gtk_tree_view_new ();
227 gtk_widget_show (select_host_dialog->tree_host);
228 gtk_container_add (GTK_CONTAINER (scrolledwindow2), select_host_dialog->tree_host);
230 select_host_dialog->store_host = gtk_tree_store_new(1, G_TYPE_STRING);
231 gtk_tree_view_set_model(GTK_TREE_VIEW(select_host_dialog->tree_host), GTK_TREE_MODEL(select_host_dialog->store_host));
232 g_object_unref(select_host_dialog->store_host);
234 dialog_action_area2 = GTK_DIALOG (select_host_dialog)->action_area;
235 gtk_widget_show (dialog_action_area2);
236 gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area2), GTK_BUTTONBOX_END);
238 cancelbutton2 = gtk_button_new_from_stock ("gtk-cancel");
239 gtk_widget_show (cancelbutton2);
240 gtk_dialog_add_action_widget (GTK_DIALOG (select_host_dialog), cancelbutton2, GTK_RESPONSE_CANCEL);
241 GTK_WIDGET_SET_FLAGS (cancelbutton2, GTK_CAN_DEFAULT);
243 okbutton2 = gtk_button_new_from_stock ("gtk-ok");
244 gtk_widget_show (okbutton2);
245 gtk_dialog_add_action_widget (GTK_DIALOG (select_host_dialog), okbutton2, GTK_RESPONSE_OK);
246 GTK_WIDGET_SET_FLAGS (okbutton2, GTK_CAN_DEFAULT);
249 GType gtk_select_host_dialog_get_type ()
251 static GType mytype = 0;
255 static const GTypeInfo myinfo =
257 sizeof (GtkSelectHostDialogClass),
263 sizeof(GtkSelectHostDialog),
265 (GInstanceInitFunc) gtk_select_host_dialog_init,
268 mytype = g_type_register_static (GTK_TYPE_DIALOG,
269 "GtkSelectHostDialog", &myinfo, 0);
275 GtkWidget *gtk_select_host_dialog_new (BOOL nocredentials)
277 return GTK_WIDGET ( gtk_type_new (gtk_select_host_dialog_get_type ()));