]> git.sur5r.net Git - openldap/blob - contrib/gtk-tool/My_Window.cc
Only bind on TLS port if explicitly requested with -T, otherwise all
[openldap] / contrib / gtk-tool / My_Window.cc
1 #include <My_Window.h>
2
3 My_Window::My_Window(GtkWindowType t) : Gtk_Window(t) {
4         debug("My_Window(t)\n");
5         Gtk_VBox *main_hbox;
6         Gtk_HBox *top_hbox;
7         Gtk_VBox *bottom_hbox;
8         Gtk_Menu *menu;
9         Gtk_MenuItem *file_menu, *menuitem;
10
11         pane = new Gtk_HPaned();
12         this->scroller = new Gtk_ScrolledWindow();
13         this->viewport = new Gtk_Viewport();
14         this->scroller->set_policy(GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
15         this->scroller->add(*this->viewport);
16         pane->add1(*this->scroller);
17         this->scroller->show();
18         this->viewport->show();
19
20         this->scroller2 = new Gtk_ScrolledWindow();
21         this->viewport2 = new Gtk_Viewport();
22         this->scroller2->set_policy(GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
23         this->scroller2->add(*this->viewport2);
24         pane->add2(*this->scroller2);   
25         this->scroller2->show();
26         this->viewport2->show();
27
28         top_hbox = new Gtk_HBox();
29         menu = new Gtk_Menu();
30         menuitem = new Gtk_MenuItem("Quit");
31         menu->append(*menuitem);
32         this->menubar = new Gtk_MenuBar();
33         file_menu = new Gtk_MenuItem("File");
34         file_menu->set_submenu(*menu);
35         this->menubar->append(*file_menu);
36         menuitem->show();
37         menu->show();
38         file_menu->show();
39 //      top_hbox->pack_start(*this->menubar, TRUE, TRUE, 1);
40         this->menubar->show();
41         this->urlfield = new Gtk_Entry();
42         top_hbox->pack_start(*this->urlfield, TRUE, TRUE, 1);
43         this->urlfield->show();
44         this->display_button = new Gtk_Button("Query Server");
45         connect_to_method(this->display_button->clicked, this, &getHost);
46         top_hbox->pack_end(*this->display_button, FALSE, FALSE, 1);
47         this->display_button->show();
48
49         this->status = new Gtk_Statusbar();
50
51         bottom_hbox = new Gtk_VBox();
52         bottom_hbox->pack_start(*pane, TRUE, TRUE, 1);
53         bottom_hbox->pack_end(*status, FALSE, TRUE, 1);
54         pane->show();
55         status->show();
56
57         main_hbox = new Gtk_VBox();
58         main_hbox->pack_start(*this->menubar, FALSE, FALSE, 1);
59         main_hbox->pack_start(*top_hbox, FALSE, TRUE, 1);
60         main_hbox->pack_end(*bottom_hbox, TRUE, TRUE, 1);
61         top_hbox->show();
62         bottom_hbox->show();
63         this->add(main_hbox);
64         main_hbox->show();
65 }
66
67 My_Window::~My_Window() {
68         cout << "~My_Window()" << endl;
69         delete this;
70 }
71
72 int My_Window::debug(const char *format,...) {
73 #ifdef DEBUG
74         va_list args;
75         int ret;
76         char *c;
77         char buff[50];
78         unsigned int m_context_id;
79         va_start(args, format);
80         ret = vprintf(format, args);
81 /*      if (this->status != NULL) {
82                 m_context_id = this->status->get_context_id("gtk-tool");
83                 ret = vsprintf(c, format, args);
84                 g_snprintf(buff, 50, "Action: %s", c);
85                 this->status->push(m_context_id, buff);
86         }
87 */      va_end(args);
88         return ret;
89 #endif
90 }
91
92 void My_Window::do_display() {
93         cout << this->urlfield->get_text() << endl;
94 }
95
96 void My_Window::getHost() {
97         debug("My_Window::getHost()\n");
98         Gtk_Tree *tree, *subtree;
99         Gtk_LdapServer *treeitem;
100         char *host, *prt;
101         int port;
102
103 //      viewport = (Gtk_Viewport *) GTK_VIEWPORT(this->scroller->children()->nth_data(1));
104 //      viewport = (Gtk_Viewport *)this->scroller->children()->nth_data(1);
105         if (this->viewport->get_child()!=NULL) {
106                 tree = (Gtk_Tree *)(this->viewport->get_child());
107         }
108         else {
109                 tree = new Gtk_Tree();
110         }
111         string thing;
112         thing = this->urlfield->get_text();
113         gchar **c;
114         c = g_strsplit(thing.c_str(), ":", 2);
115         host = c[0];
116         prt = c[1]; //strtok(NULL, "\0");
117         if (prt != NULL) port = atoi(prt);
118         else port = LDAP_PORT;
119         treeitem = new Gtk_LdapServer(this, host, port);
120         subtree = treeitem->getSubtree();
121         tree->append(*treeitem);
122         treeitem->set_subtree(*subtree);
123         treeitem->show();
124         this->viewport->add(tree);
125         tree->show();
126         this->viewport->show();
127         this->scroller->show();
128 }
129
130 gint My_Window::delete_event_impl(GdkEventAny*) {
131         Gtk_Main::instance()->quit();
132         return 0;
133 }