1998-11-25 02:01:09 +08:00
|
|
|
#include <My_Window.h>
|
|
|
|
|
|
|
|
My_Window::My_Window(GtkWindowType t) : Gtk_Window(t) {
|
1998-12-10 21:05:05 +08:00
|
|
|
debug("My_Window(t)\n");
|
1998-11-25 02:01:09 +08:00
|
|
|
Gtk_VBox *main_hbox;
|
|
|
|
Gtk_HBox *top_hbox;
|
1998-12-04 09:11:12 +08:00
|
|
|
Gtk_VBox *bottom_hbox;
|
1999-12-29 00:22:47 +08:00
|
|
|
Gtk_Menu *menu, *sub_menu;
|
|
|
|
Gtk_MenuItem *new_menu, *file_menu, *options_menu, *menuitem;
|
|
|
|
Gtk_CheckMenuItem *check_menuitem;
|
1998-11-25 02:01:09 +08:00
|
|
|
|
|
|
|
pane = new Gtk_HPaned();
|
|
|
|
this->scroller = new Gtk_ScrolledWindow();
|
1999-02-13 07:45:35 +08:00
|
|
|
this->viewport = new Gtk_Viewport();
|
1998-11-25 02:01:09 +08:00
|
|
|
this->scroller->set_policy(GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
1999-02-13 07:45:35 +08:00
|
|
|
this->scroller->add(*this->viewport);
|
1998-11-26 20:21:23 +08:00
|
|
|
pane->add1(*this->scroller);
|
1998-11-25 02:01:09 +08:00
|
|
|
this->scroller->show();
|
1999-02-13 07:45:35 +08:00
|
|
|
this->viewport->show();
|
1998-11-25 02:01:09 +08:00
|
|
|
|
1998-11-27 08:56:29 +08:00
|
|
|
this->scroller2 = new Gtk_ScrolledWindow();
|
1999-02-13 07:45:35 +08:00
|
|
|
this->viewport2 = new Gtk_Viewport();
|
1998-11-25 02:01:09 +08:00
|
|
|
this->scroller2->set_policy(GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
1999-02-13 07:45:35 +08:00
|
|
|
this->scroller2->add(*this->viewport2);
|
1998-11-26 20:21:23 +08:00
|
|
|
pane->add2(*this->scroller2);
|
1998-11-25 02:01:09 +08:00
|
|
|
this->scroller2->show();
|
1999-02-13 07:45:35 +08:00
|
|
|
this->viewport2->show();
|
1998-11-25 02:01:09 +08:00
|
|
|
|
|
|
|
top_hbox = new Gtk_HBox();
|
1999-12-29 00:22:47 +08:00
|
|
|
|
1998-11-30 08:01:14 +08:00
|
|
|
menu = new Gtk_Menu();
|
1999-12-29 00:22:47 +08:00
|
|
|
|
|
|
|
sub_menu = new Gtk_Menu();
|
|
|
|
menuitem = new Gtk_MenuItem("Server");
|
|
|
|
menuitem->activate.connect(slot(this,&My_Window::addServer));
|
|
|
|
//connect_to_method(menuitem->activate, this, &addServer);
|
|
|
|
sub_menu->append(*menuitem);
|
2000-01-03 20:23:15 +08:00
|
|
|
// menuitem->show();
|
1999-12-29 00:22:47 +08:00
|
|
|
new_menu = new Gtk_MenuItem("New...");
|
|
|
|
new_menu->set_submenu(*sub_menu);
|
2000-01-03 20:23:15 +08:00
|
|
|
// sub_menu->show();
|
1999-12-29 00:22:47 +08:00
|
|
|
menu->append(*new_menu);
|
2000-01-03 20:23:15 +08:00
|
|
|
// new_menu->show();
|
1999-12-29 00:22:47 +08:00
|
|
|
|
1998-11-30 08:01:14 +08:00
|
|
|
menuitem = new Gtk_MenuItem("Quit");
|
1999-12-29 00:22:47 +08:00
|
|
|
menuitem->activate.connect(Gtk_Main::quit.slot());
|
1998-11-30 08:01:14 +08:00
|
|
|
menu->append(*menuitem);
|
2000-01-03 20:23:15 +08:00
|
|
|
// menuitem->show();
|
1998-11-30 08:01:14 +08:00
|
|
|
this->menubar = new Gtk_MenuBar();
|
1999-12-29 00:22:47 +08:00
|
|
|
file_menu = new Gtk_MenuItem("File (?)");
|
1999-02-13 07:45:35 +08:00
|
|
|
file_menu->set_submenu(*menu);
|
1998-11-30 08:01:14 +08:00
|
|
|
this->menubar->append(*file_menu);
|
2000-01-03 20:23:15 +08:00
|
|
|
// menu->show();
|
1999-12-29 00:22:47 +08:00
|
|
|
|
|
|
|
menu = new Gtk_Menu();
|
|
|
|
check_menuitem = new Gtk_CheckMenuItem("Show Debug Info");
|
|
|
|
check_menuitem->toggled.connect(slot(this,&My_Window::setDebug));
|
|
|
|
//connect_to_method(check_menuitem->toggled, this, &setDebug);
|
|
|
|
menu->append(*check_menuitem);
|
|
|
|
check_menuitem->show();
|
|
|
|
options_menu = new Gtk_MenuItem("Options");
|
|
|
|
options_menu->set_submenu(*menu);
|
|
|
|
this->menubar->append(*options_menu);
|
2000-01-03 20:23:15 +08:00
|
|
|
// menu->show();
|
1999-12-29 00:22:47 +08:00
|
|
|
|
2000-01-03 20:23:15 +08:00
|
|
|
// file_menu->show();
|
|
|
|
// options_menu->show();
|
1999-12-29 00:22:47 +08:00
|
|
|
|
1998-11-30 08:01:14 +08:00
|
|
|
// top_hbox->pack_start(*this->menubar, TRUE, TRUE, 1);
|
2000-01-03 20:23:15 +08:00
|
|
|
// this->menubar->show();
|
1998-11-25 02:01:09 +08:00
|
|
|
this->urlfield = new Gtk_Entry();
|
1998-11-26 20:21:23 +08:00
|
|
|
top_hbox->pack_start(*this->urlfield, TRUE, TRUE, 1);
|
2000-01-03 20:23:15 +08:00
|
|
|
// this->urlfield->show();
|
1999-02-13 07:45:35 +08:00
|
|
|
this->display_button = new Gtk_Button("Query Server");
|
1999-12-29 00:22:47 +08:00
|
|
|
this->display_button->clicked.connect(slot(this, &My_Window::getHost));
|
|
|
|
//connect_to_method(this->display_button->clicked, this, &getHost);
|
1998-11-26 20:21:23 +08:00
|
|
|
top_hbox->pack_end(*this->display_button, FALSE, FALSE, 1);
|
2000-01-03 20:23:15 +08:00
|
|
|
// this->display_button->show();
|
1998-11-25 02:01:09 +08:00
|
|
|
|
1998-12-04 09:11:12 +08:00
|
|
|
this->status = new Gtk_Statusbar();
|
2000-01-03 20:23:15 +08:00
|
|
|
// this->progress = new Gtk_ProgressBar();
|
|
|
|
// this->status->add(*progress);
|
|
|
|
// this->progress->show();
|
1998-12-04 09:11:12 +08:00
|
|
|
|
|
|
|
bottom_hbox = new Gtk_VBox();
|
|
|
|
bottom_hbox->pack_start(*pane, TRUE, TRUE, 1);
|
|
|
|
bottom_hbox->pack_end(*status, FALSE, TRUE, 1);
|
|
|
|
pane->show();
|
2000-01-03 20:23:15 +08:00
|
|
|
// status->show();
|
1998-12-04 09:11:12 +08:00
|
|
|
|
1998-11-25 02:01:09 +08:00
|
|
|
main_hbox = new Gtk_VBox();
|
1998-11-30 08:01:14 +08:00
|
|
|
main_hbox->pack_start(*this->menubar, FALSE, FALSE, 1);
|
1998-11-26 20:21:23 +08:00
|
|
|
main_hbox->pack_start(*top_hbox, FALSE, TRUE, 1);
|
1998-12-04 09:11:12 +08:00
|
|
|
main_hbox->pack_end(*bottom_hbox, TRUE, TRUE, 1);
|
1998-11-25 02:01:09 +08:00
|
|
|
top_hbox->show();
|
1998-12-04 09:11:12 +08:00
|
|
|
bottom_hbox->show();
|
1999-12-29 00:22:47 +08:00
|
|
|
this->add(*main_hbox);
|
|
|
|
this->destroy.connect(Gtk_Main::quit.slot());
|
1998-11-25 02:01:09 +08:00
|
|
|
main_hbox->show();
|
2000-01-03 20:23:15 +08:00
|
|
|
// this->show_all();
|
1998-11-25 02:01:09 +08:00
|
|
|
}
|
1998-11-29 04:25:09 +08:00
|
|
|
|
|
|
|
My_Window::~My_Window() {
|
|
|
|
cout << "~My_Window()" << endl;
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
1998-12-04 09:11:12 +08:00
|
|
|
int My_Window::debug(const char *format,...) {
|
1999-12-29 00:22:47 +08:00
|
|
|
if (debug_level > 1) {
|
|
|
|
va_list args;
|
|
|
|
int ret;
|
|
|
|
char *c;
|
|
|
|
char buff[50];
|
|
|
|
unsigned int m_context_id;
|
|
|
|
va_start(args, format);
|
|
|
|
ret = vprintf(format, args);
|
|
|
|
/* if (this->status != NULL) {
|
|
|
|
m_context_id = this->status->get_context_id("gtk-tool");
|
|
|
|
ret = vsprintf(c, format, args);
|
|
|
|
g_snprintf(buff, 50, "Action: %s", c);
|
|
|
|
this->status->push(m_context_id, buff);
|
|
|
|
}
|
|
|
|
*/ va_end(args);
|
|
|
|
return ret;
|
1998-12-04 09:11:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-25 02:01:09 +08:00
|
|
|
void My_Window::do_display() {
|
|
|
|
cout << this->urlfield->get_text() << endl;
|
|
|
|
}
|
|
|
|
|
1999-02-13 07:45:35 +08:00
|
|
|
void My_Window::getHost() {
|
|
|
|
debug("My_Window::getHost()\n");
|
|
|
|
Gtk_Tree *tree, *subtree;
|
|
|
|
Gtk_LdapServer *treeitem;
|
|
|
|
char *host, *prt;
|
|
|
|
int port;
|
|
|
|
|
|
|
|
// viewport = (Gtk_Viewport *) GTK_VIEWPORT(this->scroller->children()->nth_data(1));
|
|
|
|
// viewport = (Gtk_Viewport *)this->scroller->children()->nth_data(1);
|
|
|
|
if (this->viewport->get_child()!=NULL) {
|
|
|
|
tree = (Gtk_Tree *)(this->viewport->get_child());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tree = new Gtk_Tree();
|
|
|
|
}
|
|
|
|
string thing;
|
|
|
|
thing = this->urlfield->get_text();
|
|
|
|
gchar **c;
|
|
|
|
c = g_strsplit(thing.c_str(), ":", 2);
|
|
|
|
host = c[0];
|
|
|
|
prt = c[1]; //strtok(NULL, "\0");
|
|
|
|
if (prt != NULL) port = atoi(prt);
|
|
|
|
else port = LDAP_PORT;
|
|
|
|
treeitem = new Gtk_LdapServer(this, host, port);
|
|
|
|
subtree = treeitem->getSubtree();
|
|
|
|
tree->append(*treeitem);
|
|
|
|
treeitem->set_subtree(*subtree);
|
|
|
|
treeitem->show();
|
1999-12-29 00:22:47 +08:00
|
|
|
this->viewport->add(*tree);
|
1999-02-13 07:45:35 +08:00
|
|
|
tree->show();
|
|
|
|
this->viewport->show();
|
|
|
|
this->scroller->show();
|
2000-01-03 20:23:15 +08:00
|
|
|
treeitem->select();
|
1999-02-13 07:45:35 +08:00
|
|
|
}
|
|
|
|
|
1999-12-29 00:22:47 +08:00
|
|
|
void My_Window::setDebug() {
|
|
|
|
if (debug_level > 0) debug_level = 0;
|
|
|
|
else debug_level = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void My_Window::addServer() {
|
|
|
|
debug("%s\n", "Creating new server");
|
|
|
|
Gtk_Entry *entry = new Gtk_Entry();
|
|
|
|
// entry->connect(slot(entry->activate, this, &getHost));
|
|
|
|
entry->activate.connect(slot(this,&My_Window::getHost));
|
|
|
|
this->dialog = new Gtk_InputDialog();
|
|
|
|
// this->dialog->add(*entry);
|
|
|
|
// entry->show();
|
|
|
|
this->dialog->show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1998-11-30 08:01:14 +08:00
|
|
|
gint My_Window::delete_event_impl(GdkEventAny*) {
|
1999-12-29 00:22:47 +08:00
|
|
|
//Gtk_Main::instance()->quit();
|
1998-11-25 02:01:09 +08:00
|
|
|
return 0;
|
|
|
|
}
|