preparing for release of 19
[Samba.git] / source / client / tree.c
blob94fd93c21062c7bf5c5839d1715d49c4f8544573
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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /* example-gtk+ application, ripped off from the gtk+ tree.c sample */
25 #include <stdio.h>
26 #include <errno.h>
27 #include <gtk/gtk.h>
28 #include "libsmbclient.h"
30 static GtkWidget *clist;
32 struct tree_data {
34 guint32 type; /* Type of tree item, an SMBC_TYPE */
35 char name[256]; /* May need to change this later */
39 void error_message(gchar *message) {
41 GtkWidget *dialog, *label, *okay_button;
43 /* Create the widgets */
45 dialog = gtk_dialog_new();
46 gtk_window_set_modal(GTK_WINDOW(dialog), True);
47 label = gtk_label_new (message);
48 okay_button = gtk_button_new_with_label("Okay");
50 /* Ensure that the dialog box is destroyed when the user clicks ok. */
52 gtk_signal_connect_object (GTK_OBJECT (okay_button), "clicked",
53 GTK_SIGNAL_FUNC (gtk_widget_destroy), dialog);
54 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area),
55 okay_button);
57 /* Add the label, and show everything we've added to the dialog. */
59 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
60 label);
61 gtk_widget_show_all (dialog);
65 * We are given a widget, and we want to retrieve its URL so we
66 * can do a directory listing.
68 * We walk back up the tree, picking up pieces until we hit a server or
69 * workgroup type and return a path from there
72 static char path_string[1024];
74 char *get_path(GtkWidget *item)
76 GtkWidget *p = item;
77 struct tree_data *pd;
78 char *comps[1024]; /* We keep pointers to the components here */
79 int i = 0, j, level,type;
81 /* Walk back up the tree, getting the private data */
83 level = GTK_TREE(item->parent)->level;
85 /* Pick up this item's component info */
87 pd = (struct tree_data *)gtk_object_get_user_data(GTK_OBJECT(item));
89 comps[i++] = pd->name;
90 type = pd->type;
92 while (level > 0 && type != SMBC_SERVER && type != SMBC_WORKGROUP) {
94 /* Find the parent and extract the data etc ... */
96 p = GTK_WIDGET(p->parent);
97 p = GTK_WIDGET(GTK_TREE(p)->tree_owner);
99 pd = (struct tree_data *)gtk_object_get_user_data(GTK_OBJECT(p));
101 level = GTK_TREE(item->parent)->level;
103 comps[i++] = pd->name;
104 type = pd->type;
109 * Got a list of comps now, should check that we did not hit a workgroup
110 * when we got other things as well ... Later
112 * Now, build the path
115 snprintf(path_string, sizeof(path_string), "smb:/");
117 for (j = i - 1; j >= 0; j--) {
119 strncat(path_string, "/", sizeof(path_string) - strlen(path_string));
120 strncat(path_string, comps[j], sizeof(path_string) - strlen(path_string));
124 fprintf(stdout, "Path string = %s\n", path_string);
126 return path_string;
130 struct tree_data *make_tree_data(guint32 type, const char *name)
132 struct tree_data *p = (struct tree_data *)malloc(sizeof(struct tree_data));
134 if (p) {
136 p->type = type;
137 strncpy(p->name, name, sizeof(p->name));
141 return p;
145 /* Note that this is called every time the user clicks on an item,
146 whether it is already selected or not. */
147 static void cb_select_child (GtkWidget *root_tree, GtkWidget *child,
148 GtkWidget *subtree)
150 gint dh, err, dirlen;
151 char dirbuf[512];
152 struct smbc_dirent *dirp;
153 struct stat st1;
154 char path[1024], path1[1024];
156 g_print ("select_child called for root tree %p, subtree %p, child %p\n",
157 root_tree, subtree, child);
159 /* Now, figure out what it is, and display it in the clist ... */
161 gtk_clist_clear(GTK_CLIST(clist)); /* Clear the CLIST */
163 /* Now, get the private data for the subtree */
165 strncpy(path, get_path(child), 1024);
167 if ((dh = smbc_opendir(path)) < 0) { /* Handle error */
169 g_print("cb_select_child: Could not open dir %s, %s\n", path,
170 strerror(errno));
172 gtk_main_quit();
174 return;
178 while ((err = smbc_getdents(dh, (struct smbc_dirent *)dirbuf,
179 sizeof(dirbuf))) != 0) {
181 if (err < 0) {
183 g_print("cb_select_child: Could not read dir %s, %s\n", path,
184 strerror(errno));
186 gtk_main_quit();
188 return;
192 dirp = (struct smbc_dirent *)dirbuf;
194 while (err > 0) {
195 gchar col1[128], col2[128], col3[128], col4[128];
196 gchar *rowdata[4] = {col1, col2, col3, col4};
198 dirlen = dirp->dirlen;
200 /* Format each of the items ... */
202 strncpy(col1, dirp->name, 128);
204 col2[0] = col3[0] = col4[0] = (char)0;
206 switch (dirp->smbc_type) {
208 case SMBC_WORKGROUP:
210 break;
212 case SMBC_SERVER:
214 strncpy(col2, (dirp->comment?dirp->comment:""), 128);
216 break;
218 case SMBC_FILE_SHARE:
220 strncpy(col2, (dirp->comment?dirp->comment:""), 128);
222 break;
224 case SMBC_PRINTER_SHARE:
226 strncpy(col2, (dirp->comment?dirp->comment:""), 128);
227 break;
229 case SMBC_COMMS_SHARE:
231 break;
233 case SMBC_IPC_SHARE:
235 break;
237 case SMBC_DIR:
238 case SMBC_FILE:
240 /* Get stats on the file/dir and see what we have */
242 if ((strcmp(dirp->name, ".") != 0) &&
243 (strcmp(dirp->name, "..") != 0)) {
245 strncpy(path1, path, sizeof(path1));
246 strncat(path1, "/", sizeof(path) - strlen(path));
247 strncat(path1, dirp->name, sizeof(path) - strlen(path));
249 if (smbc_stat(path1, &st1) < 0) {
251 if (errno != EBUSY) {
253 g_print("cb_select_child: Could not stat file %s, %s\n", path1,
254 strerror(errno));
256 gtk_main_quit();
258 return;
261 else {
263 strncpy(col2, "Device or resource busy", sizeof(col2));
267 else {
268 /* Now format each of the relevant things ... */
270 snprintf(col2, sizeof(col2), "%c%c%c%c%c%c%c%c%c(%0X)",
271 (st1.st_mode&S_IRUSR?'r':'-'),
272 (st1.st_mode&S_IWUSR?'w':'-'),
273 (st1.st_mode&S_IXUSR?'x':'-'),
274 (st1.st_mode&S_IRGRP?'r':'-'),
275 (st1.st_mode&S_IWGRP?'w':'-'),
276 (st1.st_mode&S_IXGRP?'x':'-'),
277 (st1.st_mode&S_IROTH?'r':'-'),
278 (st1.st_mode&S_IWOTH?'w':'-'),
279 (st1.st_mode&S_IXOTH?'x':'-'),
280 st1.st_mode);
281 snprintf(col3, sizeof(col3), "%u", st1.st_size);
282 snprintf(col4, sizeof(col4), "%s", ctime(&st1.st_mtime));
286 break;
288 default:
290 break;
293 gtk_clist_append(GTK_CLIST(clist), rowdata);
295 (char *)dirp += dirlen;
296 err -= dirlen;
304 /* Note that this is never called */
305 static void cb_unselect_child( GtkWidget *root_tree,
306 GtkWidget *child,
307 GtkWidget *subtree )
309 g_print ("unselect_child called for root tree %p, subtree %p, child %p\n",
310 root_tree, subtree, child);
313 /* for all the GtkItem:: and GtkTreeItem:: signals */
314 static void cb_itemsignal( GtkWidget *item,
315 gchar *signame )
317 GtkWidget *real_tree, *aitem, *subtree;
318 gchar *name;
319 GtkLabel *label;
320 gint dh, err, dirlen, level;
321 char dirbuf[512];
322 struct smbc_dirent *dirp;
324 label = GTK_LABEL (GTK_BIN (item)->child);
325 /* Get the text of the label */
326 gtk_label_get (label, &name);
328 level = GTK_TREE(item->parent)->level;
330 /* Get the level of the tree which the item is in */
331 g_print ("%s called for item %s->%p, level %d\n", signame, name,
332 item, GTK_TREE (item->parent)->level);
334 real_tree = GTK_TREE_ITEM_SUBTREE(item); /* Get the subtree */
336 if (strncmp(signame, "expand", 6) == 0) { /* Expand called */
337 char server[128];
339 if ((dh = smbc_opendir(get_path(item))) < 0) { /* Handle error */
340 gchar errmsg[256];
342 g_print("cb_itemsignal: Could not open dir %s, %s\n", get_path(item),
343 strerror(errno));
345 slprintf(errmsg, sizeof(errmsg), "cb_itemsignal: Could not open dir %s, %s\n", get_path(item), strerror(errno));
347 error_message(errmsg);
349 /* gtk_main_quit();*/
351 return;
355 while ((err = smbc_getdents(dh, (struct smbc_dirent *)dirbuf,
356 sizeof(dirbuf))) != 0) {
358 if (err < 0) { /* An error, report it */
359 gchar errmsg[256];
361 g_print("cb_itemsignal: Could not read dir smbc://, %s\n",
362 strerror(errno));
364 slprintf(errmsg, sizeof(errmsg), "cb_itemsignal: Could not read dir smbc://, %s\n", strerror(errno));
366 error_message(errmsg);
368 /* gtk_main_quit();*/
370 return;
374 dirp = (struct smbc_dirent *)dirbuf;
376 while (err > 0) {
377 struct tree_data *my_data;
379 dirlen = dirp->dirlen;
381 my_data = make_tree_data(dirp->smbc_type, dirp->name);
383 if (!my_data) {
385 g_print("Could not allocate space for tree_data: %s\n",
386 dirp->name);
388 gtk_main_quit();
389 return;
393 aitem = gtk_tree_item_new_with_label(dirp->name);
395 /* Connect all GtkItem:: and GtkTreeItem:: signals */
396 gtk_signal_connect (GTK_OBJECT(aitem), "select",
397 GTK_SIGNAL_FUNC(cb_itemsignal), "select");
398 gtk_signal_connect (GTK_OBJECT(aitem), "deselect",
399 GTK_SIGNAL_FUNC(cb_itemsignal), "deselect");
400 gtk_signal_connect (GTK_OBJECT(aitem), "toggle",
401 GTK_SIGNAL_FUNC(cb_itemsignal), "toggle");
402 gtk_signal_connect (GTK_OBJECT(aitem), "expand",
403 GTK_SIGNAL_FUNC(cb_itemsignal), "expand");
404 gtk_signal_connect (GTK_OBJECT(aitem), "collapse",
405 GTK_SIGNAL_FUNC(cb_itemsignal), "collapse");
406 /* Add it to the parent tree */
407 gtk_tree_append (GTK_TREE(real_tree), aitem);
409 gtk_widget_show (aitem);
411 gtk_object_set_user_data(GTK_OBJECT(aitem), (gpointer)my_data);
413 fprintf(stdout, "Added: %s, len: %u\n", dirp->name, dirlen);
415 if (dirp->smbc_type != SMBC_FILE &&
416 dirp->smbc_type != SMBC_IPC_SHARE &&
417 (strcmp(dirp->name, ".") != 0) &&
418 (strcmp(dirp->name, "..") !=0)){
420 subtree = gtk_tree_new();
421 gtk_tree_item_set_subtree(GTK_TREE_ITEM(aitem), subtree);
423 gtk_signal_connect(GTK_OBJECT(subtree), "select_child",
424 GTK_SIGNAL_FUNC(cb_select_child), real_tree);
425 gtk_signal_connect(GTK_OBJECT(subtree), "unselect_child",
426 GTK_SIGNAL_FUNC(cb_unselect_child), real_tree);
430 (char *)dirp += dirlen;
431 err -= dirlen;
437 smbc_closedir(dh);
440 else if (strncmp(signame, "collapse", 8) == 0) {
441 GtkWidget *subtree = gtk_tree_new();
443 gtk_tree_remove_items(GTK_TREE(real_tree), GTK_TREE(real_tree)->children);
445 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), subtree);
447 gtk_signal_connect (GTK_OBJECT(subtree), "select_child",
448 GTK_SIGNAL_FUNC(cb_select_child), real_tree);
449 gtk_signal_connect (GTK_OBJECT(subtree), "unselect_child",
450 GTK_SIGNAL_FUNC(cb_unselect_child), real_tree);
456 static void cb_selection_changed( GtkWidget *tree )
458 GList *i;
460 g_print ("selection_change called for tree %p\n", tree);
461 g_print ("selected objects are:\n");
463 i = GTK_TREE_SELECTION(tree);
464 while (i){
465 gchar *name;
466 GtkLabel *label;
467 GtkWidget *item;
469 /* Get a GtkWidget pointer from the list node */
470 item = GTK_WIDGET (i->data);
471 label = GTK_LABEL (GTK_BIN (item)->child);
472 gtk_label_get (label, &name);
473 g_print ("\t%s on level %d\n", name, GTK_TREE
474 (item->parent)->level);
475 i = i->next;
480 * Expand or collapse the whole network ...
482 static void cb_wholenet(GtkWidget *item, gchar *signame)
484 GtkWidget *real_tree, *aitem, *subtree;
485 gchar *name;
486 GtkLabel *label;
487 gint dh, err, dirlen;
488 char dirbuf[512];
489 struct smbc_dirent *dirp;
491 label = GTK_LABEL (GTK_BIN (item)->child);
492 gtk_label_get (label, &name);
493 g_print ("%s called for item %s->%p, level %d\n", signame, name,
494 item, GTK_TREE (item->parent)->level);
496 real_tree = GTK_TREE_ITEM_SUBTREE(item); /* Get the subtree */
498 if (strncmp(signame, "expand", 6) == 0) { /* Expand called */
500 if ((dh = smbc_opendir("smb://")) < 0) { /* Handle error */
502 g_print("cb_wholenet: Could not open dir smbc://, %s\n",
503 strerror(errno));
505 gtk_main_quit();
507 return;
511 while ((err = smbc_getdents(dh, (struct smbc_dirent *)dirbuf,
512 sizeof(dirbuf))) != 0) {
514 if (err < 0) { /* An error, report it */
516 g_print("cb_wholenet: Could not read dir smbc://, %s\n",
517 strerror(errno));
519 gtk_main_quit();
521 return;
525 dirp = (struct smbc_dirent *)dirbuf;
527 while (err > 0) {
528 struct tree_data *my_data;
530 dirlen = dirp->dirlen;
532 my_data = make_tree_data(dirp->smbc_type, dirp->name);
534 aitem = gtk_tree_item_new_with_label(dirp->name);
536 /* Connect all GtkItem:: and GtkTreeItem:: signals */
537 gtk_signal_connect (GTK_OBJECT(aitem), "select",
538 GTK_SIGNAL_FUNC(cb_itemsignal), "select");
539 gtk_signal_connect (GTK_OBJECT(aitem), "deselect",
540 GTK_SIGNAL_FUNC(cb_itemsignal), "deselect");
541 gtk_signal_connect (GTK_OBJECT(aitem), "toggle",
542 GTK_SIGNAL_FUNC(cb_itemsignal), "toggle");
543 gtk_signal_connect (GTK_OBJECT(aitem), "expand",
544 GTK_SIGNAL_FUNC(cb_itemsignal), "expand");
545 gtk_signal_connect (GTK_OBJECT(aitem), "collapse",
546 GTK_SIGNAL_FUNC(cb_itemsignal), "collapse");
548 gtk_tree_append (GTK_TREE(real_tree), aitem);
549 /* Show it - this can be done at any time */
550 gtk_widget_show (aitem);
552 gtk_object_set_user_data(GTK_OBJECT(aitem), (gpointer)my_data);
554 fprintf(stdout, "Added: %s, len: %u\n", dirp->name, dirlen);
556 subtree = gtk_tree_new();
558 gtk_tree_item_set_subtree(GTK_TREE_ITEM(aitem), subtree);
560 gtk_signal_connect(GTK_OBJECT(subtree), "select_child",
561 GTK_SIGNAL_FUNC(cb_select_child), real_tree);
562 gtk_signal_connect(GTK_OBJECT(subtree), "unselect_child",
563 GTK_SIGNAL_FUNC(cb_unselect_child), real_tree);
565 (char *)dirp += dirlen;
566 err -= dirlen;
572 smbc_closedir(dh);
575 else { /* Must be collapse ... FIXME ... */
576 GtkWidget *subtree = gtk_tree_new();
578 gtk_tree_remove_items(GTK_TREE(real_tree), GTK_TREE(real_tree)->children);
580 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), subtree);
582 gtk_signal_connect (GTK_OBJECT(subtree), "select_child",
583 GTK_SIGNAL_FUNC(cb_select_child), real_tree);
584 gtk_signal_connect (GTK_OBJECT(subtree), "unselect_child",
585 GTK_SIGNAL_FUNC(cb_unselect_child), real_tree);
592 /* Should put up a dialog box to ask the user for username and password */
594 static void
595 auth_fn(const char *server, const char *share,
596 char *workgroup, int wgmaxlen, char *username, int unmaxlen,
597 char *password, int pwmaxlen)
600 strncpy(username, "test", unmaxlen);
601 strncpy(password, "test", pwmaxlen);
605 static char *col_titles[] = {
606 "Name", "Attributes", "Size", "Modification Date",
609 int main( int argc,
610 char *argv[] )
612 GtkWidget *window, *scrolled_win, *scrolled_win2, *tree;
613 GtkWidget *subtree, *item, *main_hbox, *r_pane, *l_pane;
614 gint err, dh;
615 gint i;
616 char dirbuf[512];
617 struct smbc_dirent *dirp;
619 gtk_init (&argc, &argv);
621 /* Init the smbclient library */
623 err = smbc_init(auth_fn, 10);
625 /* Print an error response ... */
627 if (err < 0) {
629 fprintf(stderr, "smbc_init returned %s (%i)\nDo you have a ~/.smb/smb.conf file?\n", strerror(errno), errno);
630 exit(1);
634 /* a generic toplevel window */
635 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
636 gtk_widget_set_name(window, "main browser window");
637 gtk_signal_connect (GTK_OBJECT(window), "delete_event",
638 GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
639 gtk_window_set_title(GTK_WINDOW(window), "The Linux Windows Network Browser");
640 gtk_widget_set_usize(GTK_WIDGET(window), 750, -1);
641 gtk_container_set_border_width (GTK_CONTAINER(window), 5);
643 gtk_widget_show (window);
645 /* A container for the two panes ... */
647 main_hbox = gtk_hbox_new(FALSE, 1);
648 gtk_container_border_width(GTK_CONTAINER(main_hbox), 1);
649 gtk_container_add(GTK_CONTAINER(window), main_hbox);
651 gtk_widget_show(main_hbox);
653 l_pane = gtk_hpaned_new();
654 gtk_paned_gutter_size(GTK_PANED(l_pane), (GTK_PANED(l_pane))->handle_size);
655 r_pane = gtk_hpaned_new();
656 gtk_paned_gutter_size(GTK_PANED(r_pane), (GTK_PANED(r_pane))->handle_size);
657 gtk_container_add(GTK_CONTAINER(main_hbox), l_pane);
658 gtk_widget_show(l_pane);
660 /* A generic scrolled window */
661 scrolled_win = gtk_scrolled_window_new (NULL, NULL);
662 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
663 GTK_POLICY_AUTOMATIC,
664 GTK_POLICY_AUTOMATIC);
665 gtk_widget_set_usize (scrolled_win, 150, 200);
666 gtk_container_add (GTK_CONTAINER(l_pane), scrolled_win);
667 gtk_widget_show (scrolled_win);
669 /* Another generic scrolled window */
670 scrolled_win2 = gtk_scrolled_window_new (NULL, NULL);
671 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win2),
672 GTK_POLICY_AUTOMATIC,
673 GTK_POLICY_AUTOMATIC);
674 gtk_widget_set_usize (scrolled_win2, 150, 200);
675 gtk_paned_add2 (GTK_PANED(l_pane), scrolled_win2);
676 gtk_widget_show (scrolled_win2);
678 /* Create the root tree */
679 tree = gtk_tree_new();
680 g_print ("root tree is %p\n", tree);
681 /* connect all GtkTree:: signals */
682 gtk_signal_connect (GTK_OBJECT(tree), "select_child",
683 GTK_SIGNAL_FUNC(cb_select_child), tree);
684 gtk_signal_connect (GTK_OBJECT(tree), "unselect_child",
685 GTK_SIGNAL_FUNC(cb_unselect_child), tree);
686 gtk_signal_connect (GTK_OBJECT(tree), "selection_changed",
687 GTK_SIGNAL_FUNC(cb_selection_changed), tree);
688 /* Add it to the scrolled window */
689 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrolled_win),
690 tree);
691 /* Set the selection mode */
692 gtk_tree_set_selection_mode (GTK_TREE(tree),
693 GTK_SELECTION_MULTIPLE);
694 /* Show it */
695 gtk_widget_show (tree);
697 /* Now, create a clist and attach it to the second pane */
699 clist = gtk_clist_new_with_titles(4, col_titles);
701 gtk_container_add (GTK_CONTAINER(scrolled_win2), clist);
703 gtk_widget_show(clist);
705 /* Now, build the top level display ... */
707 if ((dh = smbc_opendir("smb:///")) < 0) {
709 fprintf(stderr, "Could not list default workgroup: smb:///: %s\n",
710 strerror(errno));
712 exit(1);
716 /* Create a tree item for Whole Network */
718 item = gtk_tree_item_new_with_label ("Whole Network");
719 /* Connect all GtkItem:: and GtkTreeItem:: signals */
720 gtk_signal_connect (GTK_OBJECT(item), "select",
721 GTK_SIGNAL_FUNC(cb_itemsignal), "select");
722 gtk_signal_connect (GTK_OBJECT(item), "deselect",
723 GTK_SIGNAL_FUNC(cb_itemsignal), "deselect");
724 gtk_signal_connect (GTK_OBJECT(item), "toggle",
725 GTK_SIGNAL_FUNC(cb_itemsignal), "toggle");
726 gtk_signal_connect (GTK_OBJECT(item), "expand",
727 GTK_SIGNAL_FUNC(cb_wholenet), "expand");
728 gtk_signal_connect (GTK_OBJECT(item), "collapse",
729 GTK_SIGNAL_FUNC(cb_wholenet), "collapse");
730 /* Add it to the parent tree */
731 gtk_tree_append (GTK_TREE(tree), item);
732 /* Show it - this can be done at any time */
733 gtk_widget_show (item);
735 subtree = gtk_tree_new(); /* A subtree for Whole Network */
737 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), subtree);
739 gtk_signal_connect (GTK_OBJECT(subtree), "select_child",
740 GTK_SIGNAL_FUNC(cb_select_child), tree);
741 gtk_signal_connect (GTK_OBJECT(subtree), "unselect_child",
742 GTK_SIGNAL_FUNC(cb_unselect_child), tree);
744 /* Now, get the items in smb:/// and add them to the tree */
746 dirp = (struct smbc_dirent *)dirbuf;
748 while ((err = smbc_getdents(dh, (struct smbc_dirent *)dirbuf,
749 sizeof(dirbuf))) != 0) {
751 if (err < 0) { /* Handle the error */
753 fprintf(stderr, "Could not read directory for smbc:///: %s\n",
754 strerror(errno));
756 exit(1);
760 fprintf(stdout, "Dir len: %u\n", err);
762 while (err > 0) { /* Extract each entry and make a sub-tree */
763 struct tree_data *my_data;
764 int dirlen = dirp->dirlen;
766 my_data = make_tree_data(dirp->smbc_type, dirp->name);
768 item = gtk_tree_item_new_with_label(dirp->name);
769 /* Connect all GtkItem:: and GtkTreeItem:: signals */
770 gtk_signal_connect (GTK_OBJECT(item), "select",
771 GTK_SIGNAL_FUNC(cb_itemsignal), "select");
772 gtk_signal_connect (GTK_OBJECT(item), "deselect",
773 GTK_SIGNAL_FUNC(cb_itemsignal), "deselect");
774 gtk_signal_connect (GTK_OBJECT(item), "toggle",
775 GTK_SIGNAL_FUNC(cb_itemsignal), "toggle");
776 gtk_signal_connect (GTK_OBJECT(item), "expand",
777 GTK_SIGNAL_FUNC(cb_itemsignal), "expand");
778 gtk_signal_connect (GTK_OBJECT(item), "collapse",
779 GTK_SIGNAL_FUNC(cb_itemsignal), "collapse");
780 /* Add it to the parent tree */
781 gtk_tree_append (GTK_TREE(tree), item);
782 /* Show it - this can be done at any time */
783 gtk_widget_show (item);
785 gtk_object_set_user_data(GTK_OBJECT(item), (gpointer)my_data);
787 fprintf(stdout, "Added: %s, len: %u\n", dirp->name, dirlen);
789 subtree = gtk_tree_new();
791 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), subtree);
793 gtk_signal_connect (GTK_OBJECT(subtree), "select_child",
794 GTK_SIGNAL_FUNC(cb_select_child), tree);
795 gtk_signal_connect (GTK_OBJECT(subtree), "unselect_child",
796 GTK_SIGNAL_FUNC(cb_unselect_child), tree);
798 (char *)dirp += dirlen;
799 err -= dirlen;
805 smbc_closedir(dh); /* FIXME, check for error :-) */
807 /* Show the window and loop endlessly */
808 gtk_main();
809 return 0;
811 /* example-end */