]> git.sur5r.net Git - openldap/commitdiff
various updates and fixes for gtk-tool
authorPredrag "Pele" Balorda <pele@openldap.org>
Wed, 2 Dec 1998 15:18:47 +0000 (15:18 +0000)
committerPredrag "Pele" Balorda <pele@openldap.org>
Wed, 2 Dec 1998 15:18:47 +0000 (15:18 +0000)
contrib/gtk-tool/ChangeLog
contrib/gtk-tool/Gtk_LdapServer.cc
contrib/gtk-tool/Gtk_LdapServer.h
contrib/gtk-tool/Gtk_LdapTreeItem.cc
contrib/gtk-tool/Gtk_LdapTreeItem.h
contrib/gtk-tool/Makefile
contrib/gtk-tool/My_Window.cc
contrib/gtk-tool/main.cc

index 097ae5670750ee9ed6c33ae8301e9be4a4efe2f6..19bfd7daeae714e72c4c5e67aa99ef8f283f8742 100644 (file)
@@ -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
index a4459814b5b812404e7cd0dc97af44d1e0f2a3c1..d9fddb5b938d7ef2ae760439b6b9cb4a41700c88 100644 (file)
@@ -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<char>;
                                t = ldap_get_values(this->ld, entry, attribute);
                                for (int i=0; i<ldap_count_values(t); i++) {
                                        this->databases->append(strdup(t[i]));
                                }
                                ldap_value_free(t);
-                               cout << "databases loaded" << endl;
+                               debug("databases loaded\n");
                                for (int i=0; i<this->databases->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; i<len; i++) {
                tok = strdup(this->databases->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()));
index 21c1a1ef4b52e37f61e7ef7da6b7e938a6e0eaf7..3f9daf9834dca95eccd8f929830f62b5711d45be 100644 (file)
@@ -1,9 +1,9 @@
 #ifndef GTK_LDAPSERVER_H
 #define GTK_LDAPSERVER_H
 #include "gtk.h"
+#include "utils.h"
 #include <My_Window.h>
-/*#include <LdapOpts.h>*/
-#include <Gtk_LdapItem.h>
+#include <Gtk_LdapTree.h>
 #include <Gtk_LdapTreeItem.h>
 #include <lber.h>
 #include <ldap.h>
@@ -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();
index 5a44bd3ef019570561a620a269113c2c7032eabf..24f5398b75088bbbe116e9cc38be934e88529c7a 100644 (file)
@@ -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<GtkWidget> *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()));
index ee8f711a1e2f588ea5b75106cdcb581501677464..799181f1bc7046e2e7bc90fa17a7b7d5ba79fbfc 100644 (file)
@@ -1,10 +1,11 @@
 #ifndef GTK_LDAPTREEITEM_H
 #define GTK_LDAPTREEITEM_H
 #include "gtk.h"
+#include "utils.h"
 #include <My_Window.h>
+#include <Gtk_LdapTree.h>
 #include <lber.h>
 #include <ldap.h>
-/*#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();
index 9932f81945acd4adb7f4fb7f844165d232c7ee0a..e1259393c26cdc844df8dda2d4f73e57a8de6b15 100644 (file)
@@ -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
 
 ################################################################################
 
index cece9bdd8fcd90c0529ef25d329561907ad485df..718f994f188b4c57bbe24ef001626d893d18c521 100644 (file)
@@ -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();
index d473ea01dfacc6afe2cb4a53027d2b76bdc628eb..dadc194a7f7a3b89cd35576bd9114c86c6c7788a 100644 (file)
@@ -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);