r1455: More Gtk+ updates:
[samba.git] / source / gtk / common / select.c
1 /* 
2    Unix SMB/CIFS implementation.
3    SMB-related GTK+ functions
4    
5    Copyright (C) Jelmer Vernooij 2004
6
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.
11    
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.
16    
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.
20 */
21
22 #include "includes.h"
23 #include "gtk-smb.h"
24
25 /* GtkSelectDomainDialog */
26
27 const char *gtk_select_domain_dialog_get_domain(GtkSelectDomainDialog *d)
28 {
29         return gtk_entry_get_text(GTK_ENTRY(d->entry_domain));
30 }
31
32 void gtk_select_domain_dialog_init (GtkSelectDomainDialog *select_domain_dialog)
33 {
34   GtkWidget *dialog_vbox1;
35   GtkWidget *hbox1;
36   GtkWidget *label1;
37   GtkWidget *scrolledwindow1;
38   GtkWidget *dialog_action_area1;
39   GtkWidget *cancelbutton1;
40   GtkWidget *okbutton1;
41   GtkCellRenderer *renderer;
42   GtkTreeViewColumn *curcol;
43
44   gtk_window_set_title (GTK_WINDOW (select_domain_dialog), "Select Domain");
45
46   dialog_vbox1 = GTK_DIALOG (select_domain_dialog)->vbox;
47   gtk_widget_show (dialog_vbox1);
48
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);
52
53   label1 = gtk_label_new ("Domain:");
54   gtk_widget_show (label1);
55   gtk_box_pack_start (GTK_BOX (hbox1), label1, FALSE, FALSE, 0);
56
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);
60
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);
64
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);
68
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);
75
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);
79
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);
83
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);
88
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);
93 }
94
95 struct policy_handle gtk_select_domain_dialog_get_handle(GtkSelectDomainDialog *d)
96 {
97         struct policy_handle h;
98         
99         
100         /* FIXME */
101         return h;
102 }
103
104 GType gtk_select_domain_dialog_get_type ()
105 {
106   static GType mytype = 0;
107                                                                                                                              
108   if (!mytype)
109     {
110       static const GTypeInfo myinfo =
111       {
112         sizeof (GtkSelectDomainDialogClass),
113         NULL,
114         NULL,
115         NULL,
116         NULL,
117         NULL,
118         sizeof(GtkSelectDomainDialog),
119         0,
120         (GInstanceInitFunc) gtk_select_domain_dialog_init,
121       };
122                                                                                                                              
123       mytype = g_type_register_static (GTK_TYPE_DIALOG,
124                 "GtkSelectDomainDialog", &myinfo, 0);
125     }
126                                                                                                                              
127   return mytype;
128 }
129                                                                                                                              
130 GtkWidget *gtk_select_domain_dialog_new (struct dcerpc_pipe *sam_pipe)
131 {
132         GtkSelectDomainDialog *d = gtk_type_new (gtk_select_domain_dialog_get_type ());
133         NTSTATUS status;
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;
139         int i;
140         TALLOC_CTX *mem_ctx = talloc_init("gtk_select_domain_dialog_new");
141
142         d->sam_pipe = sam_pipe;
143
144         cr.in.system_name = 0;
145         cr.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
146         cr.out.handle = &handle;
147                                                                                                                              
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);
153         }
154                                                                                                                              
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;
159                                                                                                                              
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++) {
165                         GtkTreeIter iter;
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);
169                 }
170         }
171
172         dr.in.handle = &handle;
173         dr.out.handle = &handle;
174                                                                                                                              
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 );
180         }
181
182         talloc_destroy(mem_ctx);
183
184         return GTK_WIDGET ( d );
185 }
186
187
188 /* GtkSelectHostDialog */
189 const char *gtk_select_host_dialog_get_host (GtkSelectHostDialog *d)
190 {
191         return gtk_entry_get_text(GTK_ENTRY(d->entry_host));
192 }
193
194 void gtk_select_host_dialog_init (GtkSelectHostDialog *select_host_dialog)
195 {
196   GtkWidget *dialog_vbox2;
197   GtkWidget *hbox2;
198   GtkWidget *label2;
199   GtkWidget *entry_host;
200   GtkWidget *scrolledwindow2;
201   GtkWidget *dialog_action_area2;
202   GtkWidget *cancelbutton2;
203   GtkWidget *okbutton2;
204
205   gtk_window_set_title (GTK_WINDOW (select_host_dialog), "Select Host");
206
207   dialog_vbox2 = GTK_DIALOG (select_host_dialog)->vbox;
208   gtk_widget_show (dialog_vbox2);
209
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);
213
214   label2 = gtk_label_new ("Host");
215   gtk_widget_show (label2);
216   gtk_box_pack_start (GTK_BOX (hbox2), label2, FALSE, FALSE, 0);
217
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);
221
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);
225
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);
229
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); 
233
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);
237
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);
242
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);
247 }
248
249 GType gtk_select_host_dialog_get_type ()
250 {
251   static GType mytype = 0;
252                                                                                                                              
253   if (!mytype)
254     {
255       static const GTypeInfo myinfo =
256       {
257         sizeof (GtkSelectHostDialogClass),
258         NULL,
259         NULL,
260         NULL,
261         NULL,
262         NULL,
263         sizeof(GtkSelectHostDialog),
264         0,
265         (GInstanceInitFunc) gtk_select_host_dialog_init,
266       };
267                                                                                                                              
268       mytype = g_type_register_static (GTK_TYPE_DIALOG,
269                 "GtkSelectHostDialog", &myinfo, 0);
270     }
271                                                                                                                              
272   return mytype;
273 }
274                                                                                                                              
275 GtkWidget *gtk_select_host_dialog_new (BOOL nocredentials)
276 {
277         return GTK_WIDGET ( gtk_type_new (gtk_select_host_dialog_get_type ()));
278 }
279
280