s3: Lift the server_messaging_context from send_spoolss_notify2_msg
[Samba/gbeck.git] / source3 / client / tree.c
blobe0b8c91949ad6a1af14f2d5b8c684672fccb4992
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 static void tree_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;
73 char *get_path(TALLOC_CTX *ctx, 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 TALLOC_FREE(path_string);
115 path_string = talloc_strdup(ctx, "smb:/");
117 if (path_string) {
118 for (j = i - 1; j >= 0; j--) {
119 path_string = talloc_asprintf_append(path_string, "/%s", comps[j]);
123 if (path_string) {
124 fprintf(stdout, "Path string = %s\n", path_string);
127 return path_string;
131 struct tree_data *make_tree_data(guint32 type, const char *name)
133 struct tree_data *p = SMB_MALLOC_P(struct tree_data);
135 if (p) {
137 p->type = type;
138 strncpy(p->name, name, sizeof(p->name));
142 return p;
146 /* Note that this is called every time the user clicks on an item,
147 whether it is already selected or not. */
148 static void cb_select_child (GtkWidget *root_tree, GtkWidget *child,
149 GtkWidget *subtree)
151 gint dh, err, dirlen;
152 char dirbuf[512];
153 struct smbc_dirent *dirp;
154 struct stat st1;
155 char *path;
156 TALLOC_CTX *ctx = talloc_stackframe();
158 g_print ("select_child called for root tree %p, subtree %p, child %p\n",
159 root_tree, subtree, child);
161 /* Now, figure out what it is, and display it in the clist ... */
163 gtk_clist_clear(GTK_CLIST(clist)); /* Clear the CLIST */
165 /* Now, get the private data for the subtree */
167 path = get_path(ctx, child);
168 if (!path) {
169 gtk_main_quit();
170 TALLOC_FREE(ctx);
171 return;
174 if ((dh = smbc_opendir(path)) < 0) { /* Handle error */
175 g_print("cb_select_child: Could not open dir %s, %s\n", path,
176 strerror(errno));
177 gtk_main_quit();
178 TALLOC_FREE(ctx);
179 return;
182 while ((err = smbc_getdents(dh, (struct smbc_dirent *)dirbuf,
183 sizeof(dirbuf))) != 0) {
184 if (err < 0) {
185 g_print("cb_select_child: Could not read dir %s, %s\n", path,
186 strerror(errno));
187 gtk_main_quit();
188 TALLOC_FREE(ctx);
189 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)) {
244 char *path1;
246 path1 = talloc_asprintf(ctx,
247 "%s/%s",
248 path,
249 dirp->name);
250 if (!path1) {
251 gtk_main_quit();
252 TALLOC_FREE(ctx);
253 return;
256 if (smbc_stat(path1, &st1) < 0) {
257 if (errno != EBUSY) {
258 g_print("cb_select_child: Could not stat file %s, %s\n", path1,
259 strerror(errno));
260 gtk_main_quit();
261 TALLOC_FREE(ctx);
262 return;
263 } else {
264 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;
300 TALLOC_FREE(ctx);
303 /* Note that this is never called */
304 static void cb_unselect_child( GtkWidget *root_tree,
305 GtkWidget *child,
306 GtkWidget *subtree )
308 g_print ("unselect_child called for root tree %p, subtree %p, child %p\n",
309 root_tree, subtree, child);
312 /* for all the GtkItem:: and GtkTreeItem:: signals */
313 static void cb_itemsignal( GtkWidget *item,
314 gchar *signame )
316 GtkWidget *real_tree, *aitem, *subtree;
317 gchar *name;
318 GtkLabel *label;
319 gint dh, err, dirlen, level;
320 char dirbuf[512];
321 struct smbc_dirent *dirp;
323 label = GTK_LABEL (GTK_BIN (item)->child);
324 /* Get the text of the label */
325 gtk_label_get (label, &name);
327 level = GTK_TREE(item->parent)->level;
329 /* Get the level of the tree which the item is in */
330 g_print ("%s called for item %s->%p, level %d\n", signame, name,
331 item, GTK_TREE (item->parent)->level);
333 real_tree = GTK_TREE_ITEM_SUBTREE(item); /* Get the subtree */
335 if (strncmp(signame, "expand", 6) == 0) { /* Expand called */
336 char server[128];
338 if ((dh = smbc_opendir(get_path(item))) < 0) { /* Handle error */
339 gchar errmsg[256];
341 g_print("cb_itemsignal: Could not open dir %s, %s\n", get_path(item),
342 strerror(errno));
344 slprintf(errmsg, sizeof(errmsg), "cb_itemsignal: Could not open dir %s, %s\n", get_path(item), strerror(errno));
346 tree_error_message(errmsg);
348 /* gtk_main_quit();*/
350 return;
354 while ((err = smbc_getdents(dh, (struct smbc_dirent *)dirbuf,
355 sizeof(dirbuf))) != 0) {
357 if (err < 0) { /* An error, report it */
358 gchar errmsg[256];
360 g_print("cb_itemsignal: Could not read dir smbc://, %s\n",
361 strerror(errno));
363 slprintf(errmsg, sizeof(errmsg), "cb_itemsignal: Could not read dir smbc://, %s\n", strerror(errno));
365 tree_error_message(errmsg);
367 /* gtk_main_quit();*/
369 return;
373 dirp = (struct smbc_dirent *)dirbuf;
375 while (err > 0) {
376 struct tree_data *my_data;
378 dirlen = dirp->dirlen;
380 my_data = make_tree_data(dirp->smbc_type, dirp->name);
382 if (!my_data) {
384 g_print("Could not allocate space for tree_data: %s\n",
385 dirp->name);
387 gtk_main_quit();
388 return;
392 aitem = gtk_tree_item_new_with_label(dirp->name);
394 /* Connect all GtkItem:: and GtkTreeItem:: signals */
395 gtk_signal_connect (GTK_OBJECT(aitem), "select",
396 GTK_SIGNAL_FUNC(cb_itemsignal), "select");
397 gtk_signal_connect (GTK_OBJECT(aitem), "deselect",
398 GTK_SIGNAL_FUNC(cb_itemsignal), "deselect");
399 gtk_signal_connect (GTK_OBJECT(aitem), "toggle",
400 GTK_SIGNAL_FUNC(cb_itemsignal), "toggle");
401 gtk_signal_connect (GTK_OBJECT(aitem), "expand",
402 GTK_SIGNAL_FUNC(cb_itemsignal), "expand");
403 gtk_signal_connect (GTK_OBJECT(aitem), "collapse",
404 GTK_SIGNAL_FUNC(cb_itemsignal), "collapse");
405 /* Add it to the parent tree */
406 gtk_tree_append (GTK_TREE(real_tree), aitem);
408 gtk_widget_show (aitem);
410 gtk_object_set_user_data(GTK_OBJECT(aitem), (gpointer)my_data);
412 fprintf(stdout, "Added: %s, len: %u\n", dirp->name, dirlen);
414 if (dirp->smbc_type != SMBC_FILE &&
415 dirp->smbc_type != SMBC_IPC_SHARE &&
416 (strcmp(dirp->name, ".") != 0) &&
417 (strcmp(dirp->name, "..") !=0)){
419 subtree = gtk_tree_new();
420 gtk_tree_item_set_subtree(GTK_TREE_ITEM(aitem), subtree);
422 gtk_signal_connect(GTK_OBJECT(subtree), "select_child",
423 GTK_SIGNAL_FUNC(cb_select_child), real_tree);
424 gtk_signal_connect(GTK_OBJECT(subtree), "unselect_child",
425 GTK_SIGNAL_FUNC(cb_unselect_child), real_tree);
429 (char *)dirp += dirlen;
430 err -= dirlen;
436 smbc_closedir(dh);
439 else if (strncmp(signame, "collapse", 8) == 0) {
440 GtkWidget *subtree = gtk_tree_new();
442 gtk_tree_remove_items(GTK_TREE(real_tree), GTK_TREE(real_tree)->children);
444 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), subtree);
446 gtk_signal_connect (GTK_OBJECT(subtree), "select_child",
447 GTK_SIGNAL_FUNC(cb_select_child), real_tree);
448 gtk_signal_connect (GTK_OBJECT(subtree), "unselect_child",
449 GTK_SIGNAL_FUNC(cb_unselect_child), real_tree);
455 static void cb_selection_changed( GtkWidget *tree )
457 GList *i;
459 g_print ("selection_change called for tree %p\n", tree);
460 g_print ("selected objects are:\n");
462 i = GTK_TREE_SELECTION(tree);
463 while (i){
464 gchar *name;
465 GtkLabel *label;
466 GtkWidget *item;
468 /* Get a GtkWidget pointer from the list node */
469 item = GTK_WIDGET (i->data);
470 label = GTK_LABEL (GTK_BIN (item)->child);
471 gtk_label_get (label, &name);
472 g_print ("\t%s on level %d\n", name, GTK_TREE
473 (item->parent)->level);
474 i = i->next;
479 * Expand or collapse the whole network ...
481 static void cb_wholenet(GtkWidget *item, gchar *signame)
483 GtkWidget *real_tree, *aitem, *subtree;
484 gchar *name;
485 GtkLabel *label;
486 gint dh, err, dirlen;
487 char dirbuf[512];
488 struct smbc_dirent *dirp;
490 label = GTK_LABEL (GTK_BIN (item)->child);
491 gtk_label_get (label, &name);
492 g_print ("%s called for item %s->%p, level %d\n", signame, name,
493 item, GTK_TREE (item->parent)->level);
495 real_tree = GTK_TREE_ITEM_SUBTREE(item); /* Get the subtree */
497 if (strncmp(signame, "expand", 6) == 0) { /* Expand called */
499 if ((dh = smbc_opendir("smb://")) < 0) { /* Handle error */
501 g_print("cb_wholenet: Could not open dir smbc://, %s\n",
502 strerror(errno));
504 gtk_main_quit();
506 return;
510 while ((err = smbc_getdents(dh, (struct smbc_dirent *)dirbuf,
511 sizeof(dirbuf))) != 0) {
513 if (err < 0) { /* An error, report it */
515 g_print("cb_wholenet: Could not read dir smbc://, %s\n",
516 strerror(errno));
518 gtk_main_quit();
520 return;
524 dirp = (struct smbc_dirent *)dirbuf;
526 while (err > 0) {
527 struct tree_data *my_data;
529 dirlen = dirp->dirlen;
531 my_data = make_tree_data(dirp->smbc_type, dirp->name);
533 aitem = gtk_tree_item_new_with_label(dirp->name);
535 /* Connect all GtkItem:: and GtkTreeItem:: signals */
536 gtk_signal_connect (GTK_OBJECT(aitem), "select",
537 GTK_SIGNAL_FUNC(cb_itemsignal), "select");
538 gtk_signal_connect (GTK_OBJECT(aitem), "deselect",
539 GTK_SIGNAL_FUNC(cb_itemsignal), "deselect");
540 gtk_signal_connect (GTK_OBJECT(aitem), "toggle",
541 GTK_SIGNAL_FUNC(cb_itemsignal), "toggle");
542 gtk_signal_connect (GTK_OBJECT(aitem), "expand",
543 GTK_SIGNAL_FUNC(cb_itemsignal), "expand");
544 gtk_signal_connect (GTK_OBJECT(aitem), "collapse",
545 GTK_SIGNAL_FUNC(cb_itemsignal), "collapse");
547 gtk_tree_append (GTK_TREE(real_tree), aitem);
548 /* Show it - this can be done at any time */
549 gtk_widget_show (aitem);
551 gtk_object_set_user_data(GTK_OBJECT(aitem), (gpointer)my_data);
553 fprintf(stdout, "Added: %s, len: %u\n", dirp->name, dirlen);
555 subtree = gtk_tree_new();
557 gtk_tree_item_set_subtree(GTK_TREE_ITEM(aitem), subtree);
559 gtk_signal_connect(GTK_OBJECT(subtree), "select_child",
560 GTK_SIGNAL_FUNC(cb_select_child), real_tree);
561 gtk_signal_connect(GTK_OBJECT(subtree), "unselect_child",
562 GTK_SIGNAL_FUNC(cb_unselect_child), real_tree);
564 (char *)dirp += dirlen;
565 err -= dirlen;
571 smbc_closedir(dh);
574 else { /* Must be collapse ... FIXME ... */
575 GtkWidget *subtree = gtk_tree_new();
577 gtk_tree_remove_items(GTK_TREE(real_tree), GTK_TREE(real_tree)->children);
579 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), subtree);
581 gtk_signal_connect (GTK_OBJECT(subtree), "select_child",
582 GTK_SIGNAL_FUNC(cb_select_child), real_tree);
583 gtk_signal_connect (GTK_OBJECT(subtree), "unselect_child",
584 GTK_SIGNAL_FUNC(cb_unselect_child), real_tree);
591 /* Should put up a dialog box to ask the user for username and password */
593 static void
594 auth_fn(const char *server, const char *share,
595 char *workgroup, int wgmaxlen, char *username, int unmaxlen,
596 char *password, int pwmaxlen)
599 strncpy(username, "test", unmaxlen);
600 strncpy(password, "test", pwmaxlen);
604 static char *col_titles[] = {
605 "Name", "Attributes", "Size", "Modification Date",
608 int main( int argc,
609 char *argv[] )
611 GtkWidget *window, *scrolled_win, *scrolled_win2, *tree;
612 GtkWidget *subtree, *item, *main_hbox, *r_pane, *l_pane;
613 gint err, dh;
614 gint i;
615 char dirbuf[512];
616 struct smbc_dirent *dirp;
617 TALLOC_CTX *frame = talloc_stackframe();
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 TALLOC_FREE(frame);
810 return 0;
812 /* example-end */