From: Predrag "Pele" Balorda Date: Wed, 2 Dec 1998 15:18:47 +0000 (+0000) Subject: various updates and fixes for gtk-tool X-Git-Tag: OPENLDAP_SLAPD_BACK_LDAP~977 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=fe4497e4f0fa8a1331a6be08f66af923fc8492bc;p=openldap various updates and fixes for gtk-tool --- diff --git a/contrib/gtk-tool/ChangeLog b/contrib/gtk-tool/ChangeLog index 097ae56707..19bfd7daea 100644 --- a/contrib/gtk-tool/ChangeLog +++ b/contrib/gtk-tool/ChangeLog @@ -1,5 +1,12 @@ ChangeLog for gtk-tool +02/12/1998 - Pele + * Added Gtk_LdapTree class + * Added utils (with debug only) + * "Smart" traversing of ldap tree (only 2-deep, then add 2 subtrees as + the tree gets expanded) + * Lots of updates and bug-fixes + 29/11/1998 - Pele * Added Gtk_LdapServer class * Started using cn=config, ldap_get_option (not sure about get_option diff --git a/contrib/gtk-tool/Gtk_LdapServer.cc b/contrib/gtk-tool/Gtk_LdapServer.cc index a4459814b5..d9fddb5b93 100644 --- a/contrib/gtk-tool/Gtk_LdapServer.cc +++ b/contrib/gtk-tool/Gtk_LdapServer.cc @@ -12,7 +12,7 @@ Gtk_LdapServer::Gtk_LdapServer(My_Window *w, char *h, int p) : Gtk_TreeItem() { this->par = w; this->hostname = h; this->port = p; - cout << this->hostname << this->port << endl; + debug("%s %i\n", this->hostname, this->port); this->getConfig(); } @@ -20,12 +20,12 @@ Gtk_LdapServer::Gtk_LdapServer(GtkTreeItem *t) : Gtk_TreeItem(t) { } Gtk_LdapServer::~Gtk_LdapServer() { - cout << "Bye" << endl; + debug("Bye\n"); delete this; } void Gtk_LdapServer::setType(int t) { - cout << "Gtk_LdapServer::setType(" << t << ")" << endl; + debug("Gtk_LdapServer::setType(%i)\n", t); Gtk_Pixmap *xpm_icon; Gtk_Label *label; if (this->getchild() != NULL) { @@ -34,7 +34,7 @@ void Gtk_LdapServer::setType(int t) { xpm_label->remove_c(xpm_label->children()->nth_data(0)); } else xpm_label = new Gtk_HBox(); - cout << this->hostname << endl; + debug(this->hostname); if (strcasecmp(this->hostname,"localhost") == 0) xpm_icon=new Gtk_Pixmap(*xpm_label, local_server); else xpm_icon=new Gtk_Pixmap(*xpm_label, remote_server); @@ -48,7 +48,7 @@ void Gtk_LdapServer::setType(int t) { } int Gtk_LdapServer::showDetails() { - cout << "Gtk_LdapServer::showDetails()" << endl; + debug("Gtk_LdapServer::showDetails()\n"); this->getDetails(); /* if (this->notebook != NULL) { @@ -67,7 +67,7 @@ int Gtk_LdapServer::showDetails() { } int Gtk_LdapServer::getConfig() { - cout << "Gtk_LdapServer::getConfig()" << endl; + debug("Gtk_LdapServer::getConfig()\n"); int error, entriesCount; LDAPMessage *entry, *result_identifier; BerElement *ber; @@ -83,32 +83,32 @@ int Gtk_LdapServer::getConfig() { return 0; } - cout << entriesCount << " entry" << endl; + debug("%i entry\n", entriesCount); for (entry = ldap_first_entry(this->ld, result_identifier); entry != NULL; entry = ldap_next_entry(this->ld, result_identifier)) { for (attribute = ldap_first_attribute(this->ld, entry, &ber); attribute != NULL; attribute = ldap_next_attribute(this->ld, entry, ber)) { - cout << "Attrib: " << attribute << endl; + debug("Attrib: %s\n", attribute); if (strcasecmp(attribute, "database") == 0) { - cout << "have database here" << endl; + debug("have database here\n"); this->databases = new G_List; t = ldap_get_values(this->ld, entry, attribute); for (int i=0; idatabases->append(strdup(t[i])); } ldap_value_free(t); - cout << "databases loaded" << endl; + debug("databases loaded\n"); for (int i=0; idatabases->length(); i++) { - cout << "database(" << i << ") " << this->databases->nth_data(i) << endl; + debug("database(%i) %s\n", i, this->databases->nth_data(i)); } } } - cout << "entry done" << endl; + debug("entry done\n"); } -// cout << "got " << entriesCount << " entries" << endl; +// debug("got %i entries\n", entriesCount); return entriesCount; } int Gtk_LdapServer::getDetails() { - cout << "Gtk_LdapServer::getDetails()" << endl; + debug("Gtk_LdapServer::getDetails()\n"); Gtk_HBox *hbox; Gtk_VBox *vbox; Gtk_Label *label; @@ -167,15 +167,15 @@ int Gtk_LdapServer::getDetails() { return 0; } -int Gtk_LdapServer::getSubtree() { - cout << "Gtk_LdapServer::getSubtree()" << endl; +Gtk_Tree* Gtk_LdapServer::getSubtree() { + debug("Gtk_LdapServer::getSubtree()\n"); Gtk_LdapItem *treeresult; - Gtk_Tree *tree, *subtree; + Gtk_LdapTree *tree, *subtree; Gtk_LdapTreeItem *treeitem; int entries; - cout << "this->hostname=" << this->hostname << endl; - cout << "this->port=" << this->port << endl; + debug("this->hostname=%s\n", this->hostname); + debug("this->port=%i", this->port); /* if ((this->ld = ldap_open(this->hostname, this->port)) == NULL) { perror("connection"); } @@ -185,31 +185,30 @@ int Gtk_LdapServer::getSubtree() { char *tok; int len = this->databases->length(); - cout << "this->databases->length()=" << len << endl; + debug("this->databases->length()=%i\n", len); - tree = new Gtk_Tree(); + tree = new Gtk_LdapTree(); for (int i=0; idatabases->nth_data(i)); tok = strtok(tok, ":"); + // c = strtok(NULL, " "); c = strtok(NULL, "\0"); - cout << "database " << i << " " << c << endl; - treeresult = this->par->make_tree(this->par, this->ld, c); - treeitem = new Gtk_LdapTreeItem(*treeresult->treeitem); + debug("database %i %s\n", i, c); + treeitem = new Gtk_LdapTreeItem(c, this->par, this->ld); + subtree = treeitem->getSubtree(this->ld, 1); + debug("inserting %s into %s\n", treeitem->rdn, this->hostname); tree->append(*treeitem); - if (treeresult->tree != NULL) { - subtree = new Gtk_Tree(*treeresult->tree); - treeitem->set_subtree(*subtree); - } + treeitem->set_subtree(*subtree); treeitem->show(); // tree->show(); } - this->set_subtree(*tree); - cout << "getTree() done" << endl; - return 0; +// this->set_subtree(*tree); + debug("getTree() done\n"); + return tree; } void Gtk_LdapServer::select_impl() { - cout << this->hostname << " selected" << endl; + debug("%s selected\n", this->hostname); // gtk_item_select(GTK_ITEM(GTK_TREE_ITEM(this->gtkobj()))); Gtk_c_signals_Item *sig=(Gtk_c_signals_Item *)internal_getsignalbase(); if (!sig->select) return; @@ -218,7 +217,7 @@ void Gtk_LdapServer::select_impl() { } void Gtk_LdapServer::collapse_impl() { -// cout << this->dn << " collapsed" << endl; + debug("%s collapsed\n", this->hostname); Gtk_c_signals_TreeItem *sig=(Gtk_c_signals_TreeItem *)internal_getsignalbase(); if (!sig->collapse) return; sig->collapse(GTK_TREE_ITEM(gtkobj())); @@ -226,7 +225,7 @@ void Gtk_LdapServer::collapse_impl() { } void Gtk_LdapServer::expand_impl() { -// cout << this->dn << " expanded" << endl; + debug("%s expanded\n", this->hostname); Gtk_c_signals_TreeItem *sig=(Gtk_c_signals_TreeItem *)internal_getsignalbase(); if (!sig->expand) return; sig->expand(GTK_TREE_ITEM(gtkobj())); diff --git a/contrib/gtk-tool/Gtk_LdapServer.h b/contrib/gtk-tool/Gtk_LdapServer.h index 21c1a1ef4b..3f9daf9834 100644 --- a/contrib/gtk-tool/Gtk_LdapServer.h +++ b/contrib/gtk-tool/Gtk_LdapServer.h @@ -1,9 +1,9 @@ #ifndef GTK_LDAPSERVER_H #define GTK_LDAPSERVER_H #include "gtk.h" +#include "utils.h" #include -/*#include */ -#include +#include #include #include #include @@ -36,7 +36,7 @@ public: ~Gtk_LdapServer(); void setType(int t); int getConfig(); - int getSubtree(); + Gtk_Tree* getSubtree(); int getDetails(); int showDetails(); void select_impl(); diff --git a/contrib/gtk-tool/Gtk_LdapTreeItem.cc b/contrib/gtk-tool/Gtk_LdapTreeItem.cc index 5a44bd3ef0..24f5398b75 100644 --- a/contrib/gtk-tool/Gtk_LdapTreeItem.cc +++ b/contrib/gtk-tool/Gtk_LdapTreeItem.cc @@ -5,10 +5,16 @@ Gtk_LdapTreeItem::Gtk_LdapTreeItem() : Gtk_TreeItem() { this->objectClass = NULL; } -Gtk_LdapTreeItem::Gtk_LdapTreeItem(char *c, My_Window *w) : Gtk_TreeItem() { - this->rdn = c; +Gtk_LdapTreeItem::Gtk_LdapTreeItem(char *c, My_Window *w, LDAP *ld) : Gtk_TreeItem() { + debug("Gtk_LdapTreeItem::Gtk_LdapTreeItem(%s)\n", c); + char **s; + this->dn = c; + s = ldap_explode_dn(this->dn, 1); + this->rdn = g_strdup_printf("%s", s[0]); this->par = w; + this->ld = ld; this->objectClass = NULL; + this->getDetails(); } Gtk_LdapTreeItem::Gtk_LdapTreeItem(GtkTreeItem *t) : Gtk_TreeItem(t) { @@ -19,8 +25,50 @@ Gtk_LdapTreeItem::~Gtk_LdapTreeItem() { delete this; } +Gtk_LdapTree* Gtk_LdapTreeItem::getSubtree(LDAP *ld, int counter) { + debug("Gtk_LdapTreeItem::getSubtree(%s)\n", this->dn); + if (counter <= 0) return NULL; + if (this->gtkobj()->subtree != NULL) { + return (Gtk_LdapTree *)GTK_TREE(this->gtkobj()->subtree); + } + counter--; + Gtk_LdapTree *subtree = NULL, *tree = NULL; + Gtk_LdapTreeItem *subtreeitem = NULL; + LDAPMessage *r_i = NULL, *entry = NULL; + gchar *c; + char **s; + int entriesCount = 0, error; + + this->ld = ld; + error = ldap_search_s(this->ld, this->dn, LDAP_SCOPE_ONELEVEL, "objectclass=*", NULL, 0, &r_i); +// printf("%s\n", ldap_err2string(error)); + entriesCount = ldap_count_entries(this->ld, r_i); + debug("%i results\n", entriesCount); + if (entriesCount != 0) { + tree = new Gtk_LdapTree(); + tree->set_selection_mode(GTK_SELECTION_BROWSE); + tree->set_view_mode(GTK_TREE_VIEW_ITEM); + tree->set_view_lines(false); + entry = ldap_first_entry(this->ld, r_i); + while (entry != NULL) { + subtreeitem = new Gtk_LdapTreeItem(ldap_get_dn(this->ld, entry), this->par, this->ld); + subtree = subtreeitem->getSubtree(this->ld, counter); + debug("inserting %s into %s\n",subtreeitem->rdn,this->rdn); + tree->append(*subtreeitem); + subtreeitem->show(); + if (subtree != NULL) subtreeitem->set_subtree(*subtree); + debug("done\n"); + entry = ldap_next_entry(this->ld, entry); + } + // this->set_subtree(*tree); + } +// this->getDetails(); + debug("done\n"); + return tree; +} + void Gtk_LdapTreeItem::setType(int t) { -// cout << "Gtk_LdapTreeItem::setType(" << t << ")" << endl; + debug("Gtk_LdapTreeItem::setType(%i)\n", t); Gtk_Pixmap *xpm_icon; Gtk_Label *label; if (this->getchild() != NULL) { @@ -46,7 +94,7 @@ void Gtk_LdapTreeItem::setType(int t) { } int Gtk_LdapTreeItem::showDetails() { -// cout << "Gtk_LdapTreeItem::showDetails()" << endl; + debug("Gtk_LdapTreeItem::showDetails()\n"); if (this->notebook != NULL) { if (par->viewport->getchild() != NULL) { par->viewport->remove_c(par->viewport->getchild()->gtkobj()); @@ -62,7 +110,7 @@ int Gtk_LdapTreeItem::showDetails() { } int Gtk_LdapTreeItem::getDetails() { -// cout << "Gtk_LdapTreeItem::getDetails()" << endl; + debug("Gtk_LdapTreeItem::getDetails()\n"); int error, entriesCount; BerElement *ber; LDAPMessage *entry; @@ -72,8 +120,8 @@ int Gtk_LdapTreeItem::getDetails() { GList *child_list; Gtk_Notebook *g; Gtk_Viewport *viewport; - error = ldap_search_s(this->ld, this->dn, LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, &result_identifier); - entriesCount = ldap_count_entries(ld, result_identifier); + error = ldap_search_s(this->ld, this->dn, LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, &this->result_identifier); + entriesCount = ldap_count_entries(this->ld, this->result_identifier); if (entriesCount == 0) return 0; notebook = new Gtk_Notebook(); notebook->set_tab_pos(GTK_POS_LEFT); @@ -100,11 +148,18 @@ int Gtk_LdapTreeItem::getDetails() { } } this->setType(1); -// cout << "."; + debug("done\n"); return 0; } + +void Gtk_LdapTreeItem::show_impl() { + debug("%s showed\n", this->dn); + Gtk_c_signals_TreeItem *sig=(Gtk_c_signals_TreeItem *)internal_getsignalbase(); + sig->show(GTK_WIDGET(gtkobj())); +} + void Gtk_LdapTreeItem::select_impl() { -// cout << this->dn << " selected" << endl; + debug("%s selected\n", this->dn); // gtk_item_select(GTK_ITEM(GTK_TREE_ITEM(this->gtkobj()))); Gtk_c_signals_Item *sig=(Gtk_c_signals_Item *)internal_getsignalbase(); if (!sig->select) return; @@ -113,7 +168,7 @@ void Gtk_LdapTreeItem::select_impl() { } void Gtk_LdapTreeItem::collapse_impl() { -// cout << this->dn << " collapsed" << endl; + debug("%s collapsed\n", this->dn); Gtk_c_signals_TreeItem *sig=(Gtk_c_signals_TreeItem *)internal_getsignalbase(); if (!sig->collapse) return; sig->collapse(GTK_TREE_ITEM(gtkobj())); @@ -121,7 +176,10 @@ void Gtk_LdapTreeItem::collapse_impl() { } void Gtk_LdapTreeItem::expand_impl() { -// cout << this->dn << " expanded" << endl; + debug("%s expanded\n",this->dn); + Gtk_LdapTreeItem *item; + G_List *list; + Gtk_Tree *tree; Gtk_c_signals_TreeItem *sig=(Gtk_c_signals_TreeItem *)internal_getsignalbase(); if (!sig->expand) return; sig->expand(GTK_TREE_ITEM(gtkobj())); diff --git a/contrib/gtk-tool/Gtk_LdapTreeItem.h b/contrib/gtk-tool/Gtk_LdapTreeItem.h index ee8f711a1e..799181f1bc 100644 --- a/contrib/gtk-tool/Gtk_LdapTreeItem.h +++ b/contrib/gtk-tool/Gtk_LdapTreeItem.h @@ -1,10 +1,11 @@ #ifndef GTK_LDAPTREEITEM_H #define GTK_LDAPTREEITEM_H #include "gtk.h" +#include "utils.h" #include +#include #include #include -/*#include "XPMLabelBox.h"*/ #include "icons/root_node.h" #include "icons/branch_node.h" #include "icons/leaf_node.h" @@ -15,6 +16,7 @@ #define LEAF_NODE 3 class My_Window; +class Gtk_LdapTree; class Gtk_LdapTreeItem : public Gtk_TreeItem { public: @@ -27,12 +29,14 @@ public: Gtk_Notebook *notebook; Gtk_HBox *xpm_label; Gtk_LdapTreeItem(); - Gtk_LdapTreeItem(char *c, My_Window *w); + Gtk_LdapTreeItem(char *c, My_Window *w, LDAP *ld); Gtk_LdapTreeItem(GtkTreeItem *t); ~Gtk_LdapTreeItem(); + Gtk_LdapTree* getSubtree(LDAP *ld, int i); void setType(int t); int getDetails(); int showDetails(); + void show_impl(); void select_impl(); void collapse_impl(); void expand_impl(); diff --git a/contrib/gtk-tool/Makefile b/contrib/gtk-tool/Makefile index 9932f81945..e1259393c2 100644 --- a/contrib/gtk-tool/Makefile +++ b/contrib/gtk-tool/Makefile @@ -1,15 +1,15 @@ HOME_LOCATION=$(shell pwd) CC= gcc CPLUS= g++ -OPTS=-g -DmyDEBUG +OPTS=-g INCLUDES=`gtkmm-config --cflags` -I. LDFLAGS=`gtkmm-config --libs` -L/usr/lib -L/usr/X11/lib -L/usr/local/gnome/lib -L/usr/local/ldap/lib -lldap -llber -L/usr/local/kerberos/lib -lkrb5 -lkrb4 LIBS=-lXext -lgtkmm -lX11 -lXt -lXxf86dga .EXPORT_ALL_VARIABLES: -SOURCES= My_Window.cc Gtk_LdapTreeItem.cc Gtk_LdapServer.cc main.cc -OBJECTS= My_Window.o Gtk_LdapTreeItem.o Gtk_LdapServer.o main.o +SOURCES= My_Window.cc Gtk_LdapTree.cc Gtk_LdapTreeItem.cc Gtk_LdapServer.cc utils.cc main.cc +OBJECTS= My_Window.o Gtk_LdapTree.o Gtk_LdapTreeItem.o Gtk_LdapServer.o utils.o main.o ################################################################################ diff --git a/contrib/gtk-tool/My_Window.cc b/contrib/gtk-tool/My_Window.cc index cece9bdd8f..718f994f18 100644 --- a/contrib/gtk-tool/My_Window.cc +++ b/contrib/gtk-tool/My_Window.cc @@ -93,7 +93,7 @@ Gtk_LdapItem* My_Window::make_tree(My_Window *p, LDAP* l_i, char* b_d) { // printf("%i results\n", entriesCount); s = ldap_explode_dn(b_d, 1); c = g_strdup_printf("%s", s[0]); - treeitem = new Gtk_LdapTreeItem(c, p); + treeitem = new Gtk_LdapTreeItem(c, p, l_i); treeitem->dn = b_d; treeitem->ld = l_i; treeresult = new Gtk_LdapItem(); treeitem->getDetails(); diff --git a/contrib/gtk-tool/main.cc b/contrib/gtk-tool/main.cc index d473ea01df..dadc194a7f 100644 --- a/contrib/gtk-tool/main.cc +++ b/contrib/gtk-tool/main.cc @@ -44,7 +44,9 @@ int main(int argc, char **argv) { tree = new Gtk_Tree(); treeitem = new Gtk_LdapServer(window, host, port); + subtree = treeitem->getSubtree(); tree->append(*treeitem); + treeitem->set_subtree(*subtree); treeitem->show(); viewport = new Gtk_Viewport(); viewport->add(tree);