]> git.sur5r.net Git - openldap/blob - contrib/gtk-tool/My_Window.cc
Fix typo
[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, *sub_menu;
9         Gtk_MenuItem *new_menu, *file_menu, *options_menu, *menuitem;
10         Gtk_CheckMenuItem *check_menuitem;
11
12         pane = new Gtk_HPaned();
13         this->scroller = new Gtk_ScrolledWindow();
14         this->viewport = new Gtk_Viewport();
15         this->scroller->set_policy(GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
16         this->scroller->add(*this->viewport);
17         pane->add1(*this->scroller);
18         this->scroller->show();
19         this->viewport->show();
20
21         this->scroller2 = new Gtk_ScrolledWindow();
22         this->viewport2 = new Gtk_Viewport();
23         this->scroller2->set_policy(GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
24         this->scroller2->add(*this->viewport2);
25         pane->add2(*this->scroller2);   
26         this->scroller2->show();
27         this->viewport2->show();
28
29         top_hbox = new Gtk_HBox();
30
31         menu = new Gtk_Menu();
32
33         sub_menu = new Gtk_Menu();
34         menuitem = new Gtk_MenuItem("Server");
35         menuitem->activate.connect(slot(this,&My_Window::addServer));
36         //connect_to_method(menuitem->activate, this, &addServer);
37         sub_menu->append(*menuitem);
38 //      menuitem->show();
39         new_menu = new Gtk_MenuItem("New...");
40         new_menu->set_submenu(*sub_menu);
41 //      sub_menu->show();
42         menu->append(*new_menu);
43 //      new_menu->show();
44
45         menuitem = new Gtk_MenuItem("Quit");
46         menuitem->activate.connect(Gtk_Main::quit.slot());      
47         menu->append(*menuitem);
48 //      menuitem->show();
49         this->menubar = new Gtk_MenuBar();
50         file_menu = new Gtk_MenuItem("File (?)");
51         file_menu->set_submenu(*menu);
52         this->menubar->append(*file_menu);
53 //      menu->show();
54
55         menu = new Gtk_Menu();
56         check_menuitem = new Gtk_CheckMenuItem("Show Debug Info");
57         check_menuitem->toggled.connect(slot(this,&My_Window::setDebug));
58         //connect_to_method(check_menuitem->toggled, this, &setDebug);
59         menu->append(*check_menuitem);
60         check_menuitem->show();
61         options_menu = new Gtk_MenuItem("Options");
62         options_menu->set_submenu(*menu);
63         this->menubar->append(*options_menu);
64 //      menu->show();
65         
66 //      file_menu->show();
67 //      options_menu->show();
68
69 //      top_hbox->pack_start(*this->menubar, TRUE, TRUE, 1);
70 //      this->menubar->show();
71         this->urlfield = new Gtk_Entry();
72         top_hbox->pack_start(*this->urlfield, TRUE, TRUE, 1);
73 //      this->urlfield->show();
74         this->display_button = new Gtk_Button("Query Server");
75         this->display_button->clicked.connect(slot(this, &My_Window::getHost));
76         //connect_to_method(this->display_button->clicked, this, &getHost);
77         top_hbox->pack_end(*this->display_button, FALSE, FALSE, 1);
78 //      this->display_button->show();
79
80         this->status = new Gtk_Statusbar();
81 //      this->progress = new Gtk_ProgressBar();
82 //      this->status->add(*progress);
83 //      this->progress->show();
84
85         bottom_hbox = new Gtk_VBox();
86         bottom_hbox->pack_start(*pane, TRUE, TRUE, 1);
87         bottom_hbox->pack_end(*status, FALSE, TRUE, 1);
88         pane->show();
89 //      status->show();
90
91         main_hbox = new Gtk_VBox();
92         main_hbox->pack_start(*this->menubar, FALSE, FALSE, 1);
93         main_hbox->pack_start(*top_hbox, FALSE, TRUE, 1);
94         main_hbox->pack_end(*bottom_hbox, TRUE, TRUE, 1);
95         top_hbox->show();
96         bottom_hbox->show();
97         this->add(*main_hbox);
98         this->destroy.connect(Gtk_Main::quit.slot());   
99         main_hbox->show();
100 //      this->show_all();
101 }
102
103 My_Window::~My_Window() {
104         cout << "~My_Window()" << endl;
105         delete this;
106 }
107
108 int My_Window::debug(const char *format,...) {
109         if (debug_level > 1) {
110                 va_list args;
111                 int ret;
112                 char *c;
113                 char buff[50];
114                 unsigned int m_context_id;
115                 va_start(args, format);
116                 ret = vprintf(format, args);
117         /*      if (this->status != NULL) {
118                         m_context_id = this->status->get_context_id("gtk-tool");
119                         ret = vsprintf(c, format, args);
120                         g_snprintf(buff, 50, "Action: %s", c);
121                         this->status->push(m_context_id, buff);
122                 }
123         */      va_end(args);
124                 return ret;
125         }
126 }
127
128 void My_Window::do_display() {
129         cout << this->urlfield->get_text() << endl;
130 }
131
132 void My_Window::getHost() {
133         debug("My_Window::getHost()\n");
134         Gtk_Tree *tree, *subtree;
135         Gtk_LdapServer *treeitem;
136         char *host, *prt;
137         int port;
138
139 //      viewport = (Gtk_Viewport *) GTK_VIEWPORT(this->scroller->children()->nth_data(1));
140 //      viewport = (Gtk_Viewport *)this->scroller->children()->nth_data(1);
141         if (this->viewport->get_child()!=NULL) {
142                 tree = (Gtk_Tree *)(this->viewport->get_child());
143         }
144         else {
145                 tree = new Gtk_Tree();
146         }
147         string thing;
148         thing = this->urlfield->get_text();
149         gchar **c;
150         c = g_strsplit(thing.c_str(), ":", 2);
151         host = c[0];
152         prt = c[1]; //strtok(NULL, "\0");
153         if (prt != NULL) port = atoi(prt);
154         else port = LDAP_PORT;
155         treeitem = new Gtk_LdapServer(this, host, port);
156         subtree = treeitem->getSubtree();
157         tree->append(*treeitem);
158         treeitem->set_subtree(*subtree);
159         treeitem->show();
160         this->viewport->add(*tree);
161         tree->show();
162         this->viewport->show();
163         this->scroller->show();
164         treeitem->select();
165 }
166
167 void My_Window::setDebug() {
168         if (debug_level > 0) debug_level = 0;
169         else debug_level = 1;
170 }
171
172 void My_Window::addServer() {
173         debug("%s\n", "Creating new server");
174         Gtk_Entry *entry = new Gtk_Entry();
175 //      entry->connect(slot(entry->activate, this, &getHost));
176         entry->activate.connect(slot(this,&My_Window::getHost));
177         this->dialog = new Gtk_InputDialog();
178 //      this->dialog->add(*entry);
179 //      entry->show();
180         this->dialog->show();
181         
182 }
183
184 gint My_Window::delete_event_impl(GdkEventAny*) {
185         //Gtk_Main::instance()->quit();
186         return 0;
187 }