torture-krb5: Do not do post-recv checks if the packet recv failed
[Samba.git] / source4 / client / tree.c
blob035192126cf2bdde25b748423234f12a1694f054
1 /*
2 Unix SMB/CIFS implementation.
3 SMB client GTK+ tree-based application
4 Copyright (C) Andrew Tridgell 1998
5 Copyright (C) Richard Sharpe 2001
6 Copyright (C) John Terpstra 2001
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 /* example-gtk+ application, ripped off from the gtk+ tree.c sample */
24 #include <stdio.h>
25 #include <errno.h>
26 #include <gtk/gtk.h>
27 #include "libsmbclient.h"
29 static GtkWidget *clist;
31 struct tree_data {
33 guint32 type; /* Type of tree item, an SMBC_TYPE */
34 char name[256]; /* May need to change this later */
38 void error_message(gchar *message) {
40 GtkWidget *dialog, *label, *okay_button;
42 /* Create the widgets */
44 dialog = gtk_dialog_new();
45 gtk_window_set_modal(GTK_WINDOW(dialog), True);
46 label = gtk_label_new (message);
47 okay_button = gtk_button_new_with_label("Okay");
49 /* Ensure that the dialog box is destroyed when the user clicks ok. */
51 gtk_signal_connect_object (GTK_OBJECT (okay_button), "clicked",
52 GTK_SIGNAL_FUNC (gtk_widget_destroy), dialog);
53 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area),
54 okay_button);
56 /* Add the label, and show everything we've added to the dialog. */
58 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
59 label);
60 gtk_widget_show_all (dialog);
64 * We are given a widget, and we want to retrieve its URL so we
65 * can do a directory listing.
67 * We walk back up the tree, picking up pieces until we hit a server or
68 * workgroup type and return a path from there
71 static char path_string[1024];
73 char *get_path(GtkWidget *item)
75 GtkWidget *p = item;
76 struct tree_data *pd;
77 char *comps[1024]; /* We keep pointers to the components here */
78 int i = 0, j, level,type;
80 /* Walk back up the tree, getting the private data */
82 level = GTK_TREE(item->parent)->level;
84 /* Pick up this item's component info */
86 pd = (struct tree_data *)gtk_object_get_user_data(GTK_OBJECT(item));
88 comps[i++] = pd->name;
89 type = pd->type;
91 while (level > 0 && type != SMBC_SERVER && type != SMBC_WORKGROUP) {
93 /* Find the parent and extract the data etc ... */
95 p = GTK_WIDGET(p->parent);
96 p = GTK_WIDGET(GTK_TREE(p)->tree_owner);
98 pd = (struct tree_data *)gtk_object_get_user_data(GTK_OBJECT(p));
100 level = GTK_TREE(item->parent)->level;
102 comps[i++] = pd->name;
103 type = pd->type;
108 * Got a list of comps now, should check that we did not hit a workgroup
109 * when we got other things as well ... Later
111 * Now, build the path
114 snprintf(path_string, sizeof(path_string), "smb:/");
116 for (j = i - 1; j >= 0; j--) {
118 strncat(path_string, "/", sizeof(path_string) - strlen(path_string));
119 strncat(path_string, comps[j], sizeof(path_string) - strlen(path_string));
123 fprintf(stdout, "Path string = %s\n", path_string);
125 return path_string;
129 struct tree_data *make_tree_data(guint32 type, const char *name)
131 struct tree_data *p = malloc_p(struct tree_data);
133 if (p) {
135 p->type = type;
136 strncpy(p->name, name, sizeof(p->name));
140 return p;
144 /* Note that this is called every time the user clicks on an item,
145 whether it is already selected or not. */
146 static void cb_select_child (GtkWidget *root_tree, GtkWidget *child,
147 GtkWidget *subtree)
149 gint dh, err, dirlen;
150 char dirbuf[512];
151 struct smbc_dirent *dirp;
152 struct stat st1;
153 char path[1024], path1[1024];
155 g_print ("select_child called for root tree %p, subtree %p, child %p\n",
156 root_tree, subtree, child);
158 /* Now, figure out what it is, and display it in the clist ... */
160 gtk_clist_clear(GTK_CLIST(clist)); /* Clear the CLIST */
162 /* Now, get the private data for the subtree */
164 strncpy(path, get_path(child), 1024);
166 if ((dh = smbc_opendir(path)) < 0) { /* Handle error */
168 g_print("cb_select_child: Could not open dir %s, %s\n", path,
169 strerror(errno));
171 gtk_main_quit();
173 return;
177 while ((err = smbc_getdents(dh, (struct smbc_dirent *)dirbuf,
178 sizeof(dirbuf))) != 0) {
180 if (err < 0) {
182 g_print("cb_select_child: Could not read dir %s, %s\n", path,
183 strerror(errno));
185 gtk_main_quit();
187 return;
191 dirp = (struct smbc_dirent *)dirbuf;
193 while (err > 0) {
194 gchar col1[128], col2[128], col3[128], col4[128];
195 gchar *rowdata[4] = {col1, col2, col3, col4};
197 dirlen = dirp->dirlen;
199 /* Format each of the items ... */
201 strncpy(col1, dirp->name, 128);
203 col2[0] = col3[0] = col4[0] = (char)0;
205 switch (dirp->smbc_type) {
207 case SMBC_WORKGROUP:
209 break;
211 case SMBC_SERVER:
213 strncpy(col2, (dirp->comment?dirp->comment:""), 128);
215 break;
217 case SMBC_FILE_SHARE:
219 strncpy(col2, (dirp->comment?dirp->comment:""), 128);
221 break;
223 case SMBC_PRINTER_SHARE:
225 strncpy(col2, (dirp->comment?dirp->comment:""), 128);
226 break;
228 case SMBC_COMMS_SHARE:
230 break;
232 case SMBC_IPC_SHARE:
234 break;
236 case SMBC_DIR:
237 case SMBC_FILE:
239 /* Get stats on the file/dir and see what we have */
241 if (!ISDOT(dirp->name) && !ISDOTDOT(dirp->name)) {
243 strncpy(path1, path, sizeof(path1));
244 strncat(path1, "/", sizeof(path) - strlen(path));
245 strncat(path1, dirp->name, sizeof(path) - strlen(path));
247 if (smbc_stat(path1, &st1) < 0) {
249 if (errno != EBUSY) {
251 g_print("cb_select_child: Could not stat file %s, %s\n", path1,
252 strerror(errno));
254 gtk_main_quit();
256 return;
259 else {
261 strncpy(col2, "Device or resource busy", sizeof(col2));
265 else {
266 /* Now format each of the relevant things ... */
268 snprintf(col2, sizeof(col2), "%c%c%c%c%c%c%c%c%c(%0X)",
269 (st1.st_mode&S_IRUSR?'r':'-'),
270 (st1.st_mode&S_IWUSR?'w':'-'),
271 (st1.st_mode&S_IXUSR?'x':'-'),
272 (st1.st_mode&S_IRGRP?'r':'-'),
273 (st1.st_mode&S_IWGRP?'w':'-'),
274 (st1.st_mode&S_IXGRP?'x':'-'),
275 (st1.st_mode&S_IROTH?'r':'-'),
276 (st1.st_mode&S_IWOTH?'w':'-'),
277 (st1.st_mode&S_IXOTH?'x':'-'),
278 st1.st_mode);
279 snprintf(col3, sizeof(col3), "%u", st1.st_size);
280 snprintf(col4, sizeof(col4), "%s", ctime(&st1.st_mtime));
284 break;
286 default:
288 break;
291 gtk_clist_append(GTK_CLIST(clist), rowdata);
293 (char *)dirp += dirlen;
294 err -= dirlen;
302 /* Note that this is never called */
303 static void cb_unselect_child( GtkWidget *root_tree,
304 GtkWidget *child,
305 GtkWidget *subtree )
307 g_print ("unselect_child called for root tree %p, subtree %p, child %p\n",
308 root_tree, subtree, child);
311 /* for all the GtkItem:: and GtkTreeItem:: signals */
312 static void cb_itemsignal( GtkWidget *item,
313 gchar *signame )
315 GtkWidget *real_tree, *aitem, *subtree;
316 gchar *name;
317 GtkLabel *label;
318 gint dh, err, dirlen, level;
319 char dirbuf[512];
320 struct smbc_dirent *dirp;
322 label = GTK_LABEL (GTK_BIN (item)->child);
323 /* Get the text of the label */
324 gtk_label_get (label, &name);
326 level = GTK_TREE(item->parent)->level;
328 /* Get the level of the tree which the item is in */
329 g_print ("%s called for item %s->%p, level %d\n", signame, name,
330 item, GTK_TREE (item->parent)->level);
332 real_tree = GTK_TREE_ITEM_SUBTREE(item); /* Get the subtree */
334 if (strncmp(signame, "expand", 6) == 0) { /* Expand called */
335 char server[128];
337 if ((dh = smbc_opendir(get_path(item))) < 0) { /* Handle error */
338 gchar errmsg[256];
340 g_print("cb_itemsignal: Could not open dir %s, %s\n", get_path(item),
341 strerror(errno));
343 slprintf(errmsg, sizeof(errmsg), "cb_itemsignal: Could not open dir %s, %s\n", get_path(item), strerror(errno));
345 error_message(errmsg);
347 /* gtk_main_quit();*/
349 return;
353 while ((err = smbc_getdents(dh, (struct smbc_dirent *)dirbuf,
354 sizeof(dirbuf))) != 0) {
356 if (err < 0) { /* An error, report it */
357 gchar errmsg[256];
359 g_print("cb_itemsignal: Could not read dir smbc://, %s\n",
360 strerror(errno));
362 slprintf(errmsg, sizeof(errmsg), "cb_itemsignal: Could not read dir smbc://, %s\n", strerror(errno));
364 error_message(errmsg);
366 /* gtk_main_quit();*/
368 return;
372 dirp = (struct smbc_dirent *)dirbuf;
374 while (err > 0) {
375 struct tree_data *my_data;
377 dirlen = dirp->dirlen;
379 my_data = make_tree_data(dirp->smbc_type, dirp->name);
381 if (!my_data) {
383 g_print("Could not allocate space for tree_data: %s\n",
384 dirp->name);
386 gtk_main_quit();
387 return;
391 aitem = gtk_tree_item_new_with_label(dirp->name);
393 /* Connect all GtkItem:: and GtkTreeItem:: signals */
394 gtk_signal_connect (GTK_OBJECT(aitem), "select",
395 GTK_SIGNAL_FUNC(cb_itemsignal), "select");
396 gtk_signal_connect (GTK_OBJECT(aitem), "deselect",
397 GTK_SIGNAL_FUNC(cb_itemsignal), "deselect");
398 gtk_signal_connect (GTK_OBJECT(aitem), "toggle",
399 GTK_SIGNAL_FUNC(cb_itemsignal), "toggle");
400 gtk_signal_connect (GTK_OBJECT(aitem), "expand",
401 GTK_SIGNAL_FUNC(cb_itemsignal), "expand");
402 gtk_signal_connect (GTK_OBJECT(aitem), "collapse",
403 GTK_SIGNAL_FUNC(cb_itemsignal), "collapse");
404 /* Add it to the parent tree */
405 gtk_tree_append (GTK_TREE(real_tree), aitem);
407 gtk_widget_show (aitem);
409 gtk_object_set_user_data(GTK_OBJECT(aitem), (gpointer)my_data);
411 fprintf(stdout, "Added: %s, len: %u\n", dirp->name, dirlen);
413 if (dirp->smbc_type != SMBC_FILE &&
414 dirp->smbc_type != SMBC_IPC_SHARE &&
415 (!ISDOT(dirp->name)) &&
416 (!ISDOTDOT(dirp->name))){
418 subtree = gtk_tree_new();
419 gtk_tree_item_set_subtree(GTK_TREE_ITEM(aitem), subtree);
421 gtk_signal_connect(GTK_OBJECT(subtree), "select_child",
422 GTK_SIGNAL_FUNC(cb_select_child), real_tree);
423 gtk_signal_connect(GTK_OBJECT(subtree), "unselect_child",
424 GTK_SIGNAL_FUNC(cb_unselect_child), real_tree);
428 (char *)dirp += dirlen;
429 err -= dirlen;
435 smbc_closedir(dh);
438 else if (strncmp(signame, "collapse", 8) == 0) {
439 GtkWidget *subtree = gtk_tree_new();
441 gtk_tree_remove_items(GTK_TREE(real_tree), GTK_TREE(real_tree)->children);
443 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), subtree);
445 gtk_signal_connect (GTK_OBJECT(subtree), "select_child",
446 GTK_SIGNAL_FUNC(cb_select_child), real_tree);
447 gtk_signal_connect (GTK_OBJECT(subtree), "unselect_child",
448 GTK_SIGNAL_FUNC(cb_unselect_child), real_tree);
454 static void cb_selection_changed( GtkWidget *tree )
456 GList *i;
458 g_print ("selection_change called for tree %p\n", tree);
459 g_print ("selected objects are:\n");
461 i = GTK_TREE_SELECTION(tree);
462 while (i){
463 gchar *name;
464 GtkLabel *label;
465 GtkWidget *item;
467 /* Get a GtkWidget pointer from the list node */
468 item = GTK_WIDGET (i->data);
469 label = GTK_LABEL (GTK_BIN (item)->child);
470 gtk_label_get (label, &name);
471 g_print ("\t%s on level %d\n", name, GTK_TREE
472 (item->parent)->level);
473 i = i->next;
478 * Expand or collapse the whole network ...
480 static void cb_wholenet(GtkWidget *item, gchar *signame)
482 GtkWidget *real_tree, *aitem, *subtree;
483 gchar *name;
484 GtkLabel *label;
485 gint dh, err, dirlen;
486 char dirbuf[512];
487 struct smbc_dirent *dirp;
489 label = GTK_LABEL (GTK_BIN (item)->child);
490 gtk_label_get (label, &name);
491 g_print ("%s called for item %s->%p, level %d\n", signame, name,
492 item, GTK_TREE (item->parent)->level);
494 real_tree = GTK_TREE_ITEM_SUBTREE(item); /* Get the subtree */
496 if (strncmp(signame, "expand", 6) == 0) { /* Expand called */
498 if ((dh = smbc_opendir("smb://")) < 0) { /* Handle error */
500 g_print("cb_wholenet: Could not open dir smbc://, %s\n",
501 strerror(errno));
503 gtk_main_quit();
505 return;
509 while ((err = smbc_getdents(dh, (struct smbc_dirent *)dirbuf,
510 sizeof(dirbuf))) != 0) {
512 if (err < 0) { /* An error, report it */
514 g_print("cb_wholenet: Could not read dir smbc://, %s\n",
515 strerror(errno));
517 gtk_main_quit();
519 return;
523 dirp = (struct smbc_dirent *)dirbuf;
525 while (err > 0) {
526 struct tree_data *my_data;
528 dirlen = dirp->dirlen;
530 my_data = make_tree_data(dirp->smbc_type, dirp->name);
532 aitem = gtk_tree_item_new_with_label(dirp->name);
534 /* Connect all GtkItem:: and GtkTreeItem:: signals */
535 gtk_signal_connect (GTK_OBJECT(aitem), "select",
536 GTK_SIGNAL_FUNC(cb_itemsignal), "select");
537 gtk_signal_connect (GTK_OBJECT(aitem), "deselect",
538 GTK_SIGNAL_FUNC(cb_itemsignal), "deselect");
539 gtk_signal_connect (GTK_OBJECT(aitem), "toggle",
540 GTK_SIGNAL_FUNC(cb_itemsignal), "toggle");
541 gtk_signal_connect (GTK_OBJECT(aitem), "expand",
542 GTK_SIGNAL_FUNC(cb_itemsignal), "expand");
543 gtk_signal_connect (GTK_OBJECT(aitem), "collapse",
544 GTK_SIGNAL_FUNC(cb_itemsignal), "collapse");
546 gtk_tree_append (GTK_TREE(real_tree), aitem);
547 /* Show it - this can be done at any time */
548 gtk_widget_show (aitem);
550 gtk_object_set_user_data(GTK_OBJECT(aitem), (gpointer)my_data);
552 fprintf(stdout, "Added: %s, len: %u\n", dirp->name, dirlen);
554 subtree = gtk_tree_new();
556 gtk_tree_item_set_subtree(GTK_TREE_ITEM(aitem), subtree);
558 gtk_signal_connect(GTK_OBJECT(subtree), "select_child",
559 GTK_SIGNAL_FUNC(cb_select_child), real_tree);
560 gtk_signal_connect(GTK_OBJECT(subtree), "unselect_child",
561 GTK_SIGNAL_FUNC(cb_unselect_child), real_tree);
563 (char *)dirp += dirlen;
564 err -= dirlen;
570 smbc_closedir(dh);
573 else { /* Must be collapse ... FIXME ... */
574 GtkWidget *subtree = gtk_tree_new();
576 gtk_tree_remove_items(GTK_TREE(real_tree), GTK_TREE(real_tree)->children);
578 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), subtree);
580 gtk_signal_connect (GTK_OBJECT(subtree), "select_child",
581 GTK_SIGNAL_FUNC(cb_select_child), real_tree);
582 gtk_signal_connect (GTK_OBJECT(subtree), "unselect_child",
583 GTK_SIGNAL_FUNC(cb_unselect_child), real_tree);
590 /* Should put up a dialog box to ask the user for username and password */
592 static void
593 auth_fn(const char *server, const char *share,
594 char *workgroup, int wgmaxlen, char *username, int unmaxlen,
595 char *password, int pwmaxlen)
598 strncpy(username, "test", unmaxlen);
599 strncpy(password, "test", pwmaxlen);
603 static char *col_titles[] = {
604 "Name", "Attributes", "Size", "Modification Date",
607 int main( int argc,
608 char *argv[] )
610 GtkWidget *window, *scrolled_win, *scrolled_win2, *tree;
611 GtkWidget *subtree, *item, *main_hbox, *r_pane, *l_pane;
612 gint err, dh;
613 gint i;
614 char dirbuf[512];
615 struct smbc_dirent *dirp;
617 gtk_init (&argc, &argv);
619 /* Init the smbclient library */
621 err = smbc_init(auth_fn, 10);
623 /* Print an error response ... */
625 if (err < 0) {
627 fprintf(stderr, "smbc_init returned %s (%i)\nDo you have a ~/.smb/smb.conf file?\n", strerror(errno), errno);
628 exit(1);
632 /* a generic toplevel window */
633 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
634 gtk_widget_set_name(window, "main browser window");
635 gtk_signal_connect (GTK_OBJECT(window), "delete_event",
636 GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
637 gtk_window_set_title(GTK_WINDOW(window), "The Linux Windows Network Browser");
638 gtk_widget_set_usize(GTK_WIDGET(window), 750, -1);
639 gtk_container_set_border_width (GTK_CONTAINER(window), 5);
641 gtk_widget_show (window);
643 /* A container for the two panes ... */
645 main_hbox = gtk_hbox_new(FALSE, 1);
646 gtk_container_border_width(GTK_CONTAINER(main_hbox), 1);
647 gtk_container_add(GTK_CONTAINER(window), main_hbox);
649 gtk_widget_show(main_hbox);
651 l_pane = gtk_hpaned_new();
652 gtk_paned_gutter_size(GTK_PANED(l_pane), (GTK_PANED(l_pane))->handle_size);
653 r_pane = gtk_hpaned_new();
654 gtk_paned_gutter_size(GTK_PANED(r_pane), (GTK_PANED(r_pane))->handle_size);
655 gtk_container_add(GTK_CONTAINER(main_hbox), l_pane);
656 gtk_widget_show(l_pane);
658 /* A generic scrolled window */
659 scrolled_win = gtk_scrolled_window_new (NULL, NULL);
660 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
661 GTK_POLICY_AUTOMATIC,
662 GTK_POLICY_AUTOMATIC);
663 gtk_widget_set_usize (scrolled_win, 150, 200);
664 gtk_container_add (GTK_CONTAINER(l_pane), scrolled_win);
665 gtk_widget_show (scrolled_win);
667 /* Another generic scrolled window */
668 scrolled_win2 = gtk_scrolled_window_new (NULL, NULL);
669 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win2),
670 GTK_POLICY_AUTOMATIC,
671 GTK_POLICY_AUTOMATIC);
672 gtk_widget_set_usize (scrolled_win2, 150, 200);
673 gtk_paned_add2 (GTK_PANED(l_pane), scrolled_win2);
674 gtk_widget_show (scrolled_win2);
676 /* Create the root tree */
677 tree = gtk_tree_new();
678 g_print ("root tree is %p\n", tree);
679 /* connect all GtkTree:: signals */
680 gtk_signal_connect (GTK_OBJECT(tree), "select_child",
681 GTK_SIGNAL_FUNC(cb_select_child), tree);
682 gtk_signal_connect (GTK_OBJECT(tree), "unselect_child",
683 GTK_SIGNAL_FUNC(cb_unselect_child), tree);
684 gtk_signal_connect (GTK_OBJECT(tree), "selection_changed",
685 GTK_SIGNAL_FUNC(cb_selection_changed), tree);
686 /* Add it to the scrolled window */
687 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrolled_win),
688 tree);
689 /* Set the selection mode */
690 gtk_tree_set_selection_mode (GTK_TREE(tree),
691 GTK_SELECTION_MULTIPLE);
692 /* Show it */
693 gtk_widget_show (tree);
695 /* Now, create a clist and attach it to the second pane */
697 clist = gtk_clist_new_with_titles(4, col_titles);
699 gtk_container_add (GTK_CONTAINER(scrolled_win2), clist);
701 gtk_widget_show(clist);
703 /* Now, build the top level display ... */
705 if ((dh = smbc_opendir("smb:///")) < 0) {
707 fprintf(stderr, "Could not list default workgroup: smb:///: %s\n",
708 strerror(errno));
710 exit(1);
714 /* Create a tree item for Whole Network */
716 item = gtk_tree_item_new_with_label ("Whole Network");
717 /* Connect all GtkItem:: and GtkTreeItem:: signals */
718 gtk_signal_connect (GTK_OBJECT(item), "select",
719 GTK_SIGNAL_FUNC(cb_itemsignal), "select");
720 gtk_signal_connect (GTK_OBJECT(item), "deselect",
721 GTK_SIGNAL_FUNC(cb_itemsignal), "deselect");
722 gtk_signal_connect (GTK_OBJECT(item), "toggle",
723 GTK_SIGNAL_FUNC(cb_itemsignal), "toggle");
724 gtk_signal_connect (GTK_OBJECT(item), "expand",
725 GTK_SIGNAL_FUNC(cb_wholenet), "expand");
726 gtk_signal_connect (GTK_OBJECT(item), "collapse",
727 GTK_SIGNAL_FUNC(cb_wholenet), "collapse");
728 /* Add it to the parent tree */
729 gtk_tree_append (GTK_TREE(tree), item);
730 /* Show it - this can be done at any time */
731 gtk_widget_show (item);
733 subtree = gtk_tree_new(); /* A subtree for Whole Network */
735 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), subtree);
737 gtk_signal_connect (GTK_OBJECT(subtree), "select_child",
738 GTK_SIGNAL_FUNC(cb_select_child), tree);
739 gtk_signal_connect (GTK_OBJECT(subtree), "unselect_child",
740 GTK_SIGNAL_FUNC(cb_unselect_child), tree);
742 /* Now, get the items in smb:/// and add them to the tree */
744 dirp = (struct smbc_dirent *)dirbuf;
746 while ((err = smbc_getdents(dh, (struct smbc_dirent *)dirbuf,
747 sizeof(dirbuf))) != 0) {
749 if (err < 0) { /* Handle the error */
751 fprintf(stderr, "Could not read directory for smbc:///: %s\n",
752 strerror(errno));
754 exit(1);
758 fprintf(stdout, "Dir len: %u\n", err);
760 while (err > 0) { /* Extract each entry and make a sub-tree */
761 struct tree_data *my_data;
762 int dirlen = dirp->dirlen;
764 my_data = make_tree_data(dirp->smbc_type, dirp->name);
766 item = gtk_tree_item_new_with_label(dirp->name);
767 /* Connect all GtkItem:: and GtkTreeItem:: signals */
768 gtk_signal_connect (GTK_OBJECT(item), "select",
769 GTK_SIGNAL_FUNC(cb_itemsignal), "select");
770 gtk_signal_connect (GTK_OBJECT(item), "deselect",
771 GTK_SIGNAL_FUNC(cb_itemsignal), "deselect");
772 gtk_signal_connect (GTK_OBJECT(item), "toggle",
773 GTK_SIGNAL_FUNC(cb_itemsignal), "toggle");
774 gtk_signal_connect (GTK_OBJECT(item), "expand",
775 GTK_SIGNAL_FUNC(cb_itemsignal), "expand");
776 gtk_signal_connect (GTK_OBJECT(item), "collapse",
777 GTK_SIGNAL_FUNC(cb_itemsignal), "collapse");
778 /* Add it to the parent tree */
779 gtk_tree_append (GTK_TREE(tree), item);
780 /* Show it - this can be done at any time */
781 gtk_widget_show (item);
783 gtk_object_set_user_data(GTK_OBJECT(item), (gpointer)my_data);
785 fprintf(stdout, "Added: %s, len: %u\n", dirp->name, dirlen);
787 subtree = gtk_tree_new();
789 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), subtree);
791 gtk_signal_connect (GTK_OBJECT(subtree), "select_child",
792 GTK_SIGNAL_FUNC(cb_select_child), tree);
793 gtk_signal_connect (GTK_OBJECT(subtree), "unselect_child",
794 GTK_SIGNAL_FUNC(cb_unselect_child), tree);
796 (char *)dirp += dirlen;
797 err -= dirlen;
803 smbc_closedir(dh); /* FIXME, check for error :-) */
805 /* Show the window and loop endlessly */
806 gtk_main();
807 return 0;
809 /* example-end */