]> git.sur5r.net Git - openldap/blob - contrib/gtk-tool/main.cc
Fix dynamic linking dependencies for NT and Unix
[openldap] / contrib / gtk-tool / main.cc
1 #include "cpluscommon.h"
2 #include "gtk.h"
3 #include <lber.h>
4 #include <ldap.h>
5 #include <My_Window.h>
6 #include <Gtk_LdapItem.h>
7 #include <Gtk_LdapServer.h>
8
9 int debug_level = 0;
10
11 target_drag_leave(GdkDragContext *context, guint time) {
12 }
13
14 int main(int argc, char **argv) {
15         My_Window *window;
16         Gtk_LdapItem *treeresult;
17         Gtk_Tree *tree = NULL, *subtree = NULL;
18         Gtk_Tree *machine, *machinetree;
19         Gtk_LdapServer *server;
20         Gtk_Viewport *viewport;
21         char *host = NULL, *prt = NULL;
22         char *base_dn = NULL;
23         int c, port = 0;
24         GList *hosts = NULL;
25         int host_count = 0;
26         char *pair[2];
27
28         //hosts = new G_List<char>();
29         while ((c = getopt(argc, argv, "d:s:p:h")) != -1) {
30                 switch (c) {
31                         case 'd':
32                                 debug_level = atoi(optarg);
33                                 break;
34                         case 's':
35                                 debug("host\n");
36                                 hosts = g_list_append(hosts, (strdup(optarg)));
37                                 break;
38                         case 'p':
39                                 port = atoi(optarg); break;
40                         case 'h':
41                         default:
42                                 fprintf(stderr, "Usage: %s [-d level] [-s server[:port]]*\n", argv[0]);
43                                 exit(-1);
44                 }
45                 fprintf(stderr,"b");
46         }
47         debug("%i hosts\n", g_list_length(hosts));
48         if (g_list_length(hosts) == 0) {
49 #ifndef LDAP_GET_OPT
50                 ldap_get_option(NULL, LDAP_OPT_HOST_NAME, host);
51 #endif /* LDAP_GET_OPT */
52                 if (host!=NULL) {
53                         hosts = g_list_append(hosts, host);
54                         debug("Default host: %s\n", host);
55                 } else {
56 #ifndef LDAP_GET_OPT
57                         fprintf(stderr,"Why isn't your LDAP_OPT_HOST_NAME defined?\n");
58 #endif
59                         fprintf(stderr,"Supply me with a host please (hint: use -s)\n");
60                 }
61         } else {        
62                 for (int f=0; f<g_list_length(hosts); f++) {
63                         debug("%s\n", g_list_nth(hosts,f)->data);
64                 }
65         }
66         if (port == 0) port = LDAP_PORT;
67
68         Gtk_Main m(&argc, &argv);
69
70         window = new My_Window(GTK_WINDOW_TOPLEVEL);
71
72         if (hosts!=NULL) {
73                 tree = new Gtk_Tree();
74                 window->viewport->add(*tree);
75                 for (int f=0; f<g_list_length(hosts); f++) {
76                         host = strtok((char*)g_list_nth(hosts, f)->data, ":");
77                         prt = strtok(NULL, "\0");
78                         if (prt != NULL) port = atoi(prt);
79                         else port = LDAP_PORT;
80                         server = new Gtk_LdapServer(window, host, port);
81                         subtree = server->getSubtree();
82                         tree->append(*server);
83                         server->set_subtree(*subtree);
84                         server->show();
85                 }
86                 //window->viewport->add(*tree);
87 //              tree->show();
88         }
89
90 //      window->viewport->show();
91 //      window->scroller->show();
92
93         //Select first server
94         if (tree != NULL) {
95                 Gtk_LdapTree::ItemList &items = tree->tree();
96                 Gtk_LdapTree::ItemList::iterator i = items.begin();
97                 server = (Gtk_LdapServer *)(* i);
98         //      server->select_impl();
99         }
100
101         window->set_title("gtk-tool");
102         window->activate();
103         window->set_usize(600, 500);
104
105         window->set_events(window->get_events()|GDK_ALL_EVENTS_MASK);
106         window->drag_dest_set(GTK_DEST_DEFAULT_ALL, target_table, n_targets, static_cast <GdkDragAction> (GDK_ACTION_COPY|GDK_ACTION_MOVE));
107         window->drag_source_set(static_cast<GdkModifierType>(GDK_BUTTON1_MASK|GDK_BUTTON3_MASK), target_table, n_targets, static_cast<GdkDragAction>(GDK_ACTION_COPY|GDK_ACTION_MOVE));
108         window->drag_leave.connect(window->slot(window,target_drag_leave));
109         window->show_all();
110
111         m.run();
112         return 0;
113 }