]> git.sur5r.net Git - openldap/commitdiff
gtk-tool updates
authorPredrag "Pele" Balorda <pele@openldap.org>
Sat, 28 Nov 1998 20:25:09 +0000 (20:25 +0000)
committerPredrag "Pele" Balorda <pele@openldap.org>
Sat, 28 Nov 1998 20:25:09 +0000 (20:25 +0000)
contrib/gtk-tool/ChangeLog
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/My_Window.h
contrib/gtk-tool/TODO
contrib/gtk-tool/main.cc

index a002fc7edd602aef0773df8604632b060da86b31..dbd38b36de5fc1b5b98fe27155853bd724e64fd3 100644 (file)
@@ -1,5 +1,11 @@
 ChangeLog for gtk-tool
 
+28/11/1998 - Pele
+       * Fixes, enhancements, started using ldap utility api
+       * It now traverses the whole tree at startup, not sure if it's smart
+       but I did it because of something that has no relevance to network
+       traffic
+
 27/11/1998 - Pele
        * Added viewports, both sides now scroll automatically
        * Brought back the "cache" stuff, now data gets reused if it's allready
index 355691145379271c3da025237cc38c143ccf1dd4..7efcb58d6c408ce2e0d57a14a828ac86950eb4b3 100644 (file)
@@ -2,45 +2,66 @@
 #include <gtk--/base.h>
 
 Gtk_LdapTreeItem::Gtk_LdapTreeItem() : Gtk_TreeItem() {
+       this->objectClass = NULL;
 }
 
 Gtk_LdapTreeItem::Gtk_LdapTreeItem(char *c, My_Window *w) : Gtk_TreeItem() {
        this->rdn = c;
        this->par = w;
+       this->objectClass = NULL;
 }
 
 Gtk_LdapTreeItem::Gtk_LdapTreeItem(GtkTreeItem *t) : Gtk_TreeItem(t) {
 }
 
+Gtk_LdapTreeItem::~Gtk_LdapTreeItem() {
+       cout << "Bye" << endl;
+       delete this;
+}
+
 void Gtk_LdapTreeItem::setType(int t) {
-//     printf("Gtk_LdapTreeItem::setType(%d)\n", t);
+       cout << "Gtk_LdapTreeItem::setType(" << t << ")" << endl;
        Gtk_Pixmap *xpm_icon;
        Gtk_Label *label;
        if (this->getchild() != NULL) {
-       //      printf("There's a label in here - removing");
                xpm_label = new Gtk_HBox(GTK_HBOX(this->getchild()->gtkobj()));
                xpm_label->remove_c(xpm_label->children()->nth_data(0));
                xpm_label->remove_c(xpm_label->children()->nth_data(0));
-       //      xpm_label->remove_c(GTK_WIDGET(xpm_icon->gtkobj()));
-       //      printf("done\n");
        }
        else xpm_label = new Gtk_HBox();
-       switch (t) {
-               case 1: xpm_icon = new Gtk_Pixmap(*xpm_label, "root_node.xpm"); break;
-               case 2: xpm_icon = new Gtk_Pixmap(*xpm_label, "branch_node.xpm"); break;
-               default: xpm_icon = new Gtk_Pixmap(*xpm_label, "leaf_node.xpm"); break;
-       }
+       if (strcasecmp(this->objectClass,"organization") == 0)
+               xpm_icon=new Gtk_Pixmap(*xpm_label, root_node);
+       else if (strcasecmp(this->objectClass,"organizationalunit") == 0)
+               xpm_icon=new Gtk_Pixmap(*xpm_label, branch_node);
+       else if (strcasecmp(this->objectClass,"person") == 0)
+               xpm_icon=new Gtk_Pixmap(*xpm_label, leaf_node);
+       else xpm_icon=new Gtk_Pixmap(*xpm_label, general_node);
        label = new Gtk_Label(this->rdn);
        xpm_label->pack_start(*xpm_icon, false, false, 1);
        xpm_label->pack_start(*label, false, false, 1);
-       xpm_icon->show();
+       if (this->getchild() == NULL) this->add(xpm_label);
        label->show();
        xpm_label->show();
-       if (this->getchild() == NULL) this->add(xpm_label);
-       else printf("There's still a child here!\n");
+       xpm_icon->show();
+}
+
+int Gtk_LdapTreeItem::showDetails() {
+       cout << "Gtk_LdapTreeItem::showDetails()" << endl;
+       if (this->notebook != NULL) {
+               if (par->viewport->getchild() != NULL) {
+                       par->viewport->remove_c(par->viewport->getchild()->gtkobj());
+               }
+               par->viewport->add(this->notebook);
+               this->notebook->show();
+               par->viewport->show();
+               return 0;
+       }
+       else this->getDetails();
+       this->showDetails();
 }
 
 int Gtk_LdapTreeItem::getDetails() {
+       cout << "Gtk_LdapTreeItem::getDetails()" << endl;
        int error, entriesCount;
        BerElement *ber;
        LDAPMessage *entry;
@@ -50,18 +71,6 @@ int Gtk_LdapTreeItem::getDetails() {
        GList *child_list;
        Gtk_Notebook *g;
        Gtk_Viewport *viewport;
-       viewport = new Gtk_Viewport();
-       if (this->notebook != NULL) {
-               printf("Data on %s available\n", this->rdn);
-               if (par->viewport->getchild() != NULL) {
-                       par->viewport->remove_c(par->viewport->getchild()->gtkobj());
-               }
-               par->viewport->add(this->notebook);
-               this->notebook->show();
-               par->viewport->show();
-       //      par->scroller2->show();
-               return 0;
-       }
        error = ldap_search_s(this->ld, this->dn, LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, &result_identifier);
        entriesCount = ldap_count_entries(ld, result_identifier);
        if (entriesCount == 0) return 0;
@@ -71,8 +80,13 @@ int Gtk_LdapTreeItem::getDetails() {
        
        for (entry = ldap_first_entry(ld, result_identifier); entry != NULL; entry = ldap_next_entry(ld, result_identifier)) {
                for (attribute = ldap_first_attribute(ld, entry, &ber); attribute != NULL; attribute = ldap_next_attribute(ld, entry, ber)) {
-                       table = new Gtk_CList(1, titles);
                        values = ldap_get_values(ld, entry, attribute);
+                       if (strcasecmp(attribute, "objectclass") == 0) {
+                               if (strcasecmp(values[0],"top") == 0)
+                                       this->objectClass = strdup(values[1]);
+                               else this->objectClass = values[0];
+                       }
+                       table = new Gtk_CList(1, titles);
                        for (int i=0; i<ldap_count_values(values); i++) {
                                const gchar *t[] = { values[i] };
                                table->append(t);
@@ -84,16 +98,8 @@ int Gtk_LdapTreeItem::getDetails() {
                        label->show();
                }
        }
-       if (par->scroller2 != NULL) {
-               if (par->viewport->getchild() != NULL) {
-                       par->viewport->remove_c(par->viewport->getchild()->gtkobj());
-               }
-               par->viewport->add(this->notebook);
-               this->notebook->show();
-               par->viewport->show();
-       //      par->scroller2->show();
-               cout << "Added details for " << this->rdn << endl;
-       }
+       this->setType(1);
+       cout << ".";
        return 0;
 }
 void Gtk_LdapTreeItem::select_impl() {
@@ -102,7 +108,7 @@ void Gtk_LdapTreeItem::select_impl() {
        Gtk_c_signals_Item *sig=(Gtk_c_signals_Item *)internal_getsignalbase();
        if (!sig->select) return;
        sig->select(GTK_ITEM(gtkobj()));
-       this->getDetails();
+       this->showDetails();
 }
 
 void Gtk_LdapTreeItem::collapse_impl() {
index ab7e562f09126a1eeb9e584f08c18565b7354e67..ee8f711a1e2f588ea5b75106cdcb581501677464 100644 (file)
@@ -5,6 +5,10 @@
 #include <lber.h>
 #include <ldap.h>
 /*#include "XPMLabelBox.h"*/
+#include "icons/root_node.h"
+#include "icons/branch_node.h"
+#include "icons/leaf_node.h"
+#include "icons/general_node.h"
 
 #define ROOT_NODE 1
 #define BRANCH_NODE 2
@@ -16,6 +20,7 @@ class Gtk_LdapTreeItem : public Gtk_TreeItem {
 public:
        char *dn;
        char *rdn;
+       char *objectClass;
        LDAP *ld;
        LDAPMessage *result_identifier;
        My_Window *par;
@@ -24,8 +29,10 @@ public:
        Gtk_LdapTreeItem();
        Gtk_LdapTreeItem(char *c, My_Window *w);
        Gtk_LdapTreeItem(GtkTreeItem *t);
+       ~Gtk_LdapTreeItem();
        void setType(int t);
        int getDetails();
+       int showDetails();
        void select_impl();
        void collapse_impl();
        void expand_impl();
index db8f5d7dc541153f6d5a35054751deaf893975c3..65a52f157f2a35cc713f0a775d4f03a91f3234ed 100644 (file)
@@ -3,7 +3,7 @@ CC=     gcc
 CPLUS= g++
 OPTS=-g -DmyDEBUG
 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
+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:
index 9e07dc89a6bf81d640de60faa296c45bb2893291..6fbe8c45c954673a8e347555e1bcae5fe0fa6e64 100644 (file)
@@ -37,6 +37,12 @@ My_Window::My_Window(GtkWindowType t) : Gtk_Window(t) {
        this->add(main_hbox);
        main_hbox->show();
 }
+
+My_Window::~My_Window() {
+       cout << "~My_Window()" << endl;
+       delete this;
+}
+
 void My_Window::do_display() {
        cout << this->urlfield->get_text() << endl;
 }
@@ -75,8 +81,9 @@ Gtk_LdapItem* My_Window::make_tree(My_Window *p, LDAP* l_i, char* b_d) {
        treeitem = new Gtk_LdapTreeItem(c, p);
        treeitem->dn = b_d; treeitem->ld = l_i;
        treeresult = new Gtk_LdapItem();
+       treeitem->getDetails();
        if (entriesCount == 0) { 
-               treeitem->setType(LEAF_NODE);
+       //      treeitem->setType(LEAF_NODE);
                treeresult->treeitem = new Gtk_LdapTreeItem(*treeitem);
                treeresult->tree = NULL;
                return treeresult;
@@ -103,7 +110,7 @@ Gtk_LdapItem* My_Window::make_tree(My_Window *p, LDAP* l_i, char* b_d) {
        //      printf("\n");
                entry = ldap_next_entry(l_i, entry);
        }
-       treeitem->setType(BRANCH_NODE);
+//     treeitem->setType(BRANCH_NODE);
        treeresult->treeitem = new Gtk_LdapTreeItem(*treeitem);
        treeresult->tree = new Gtk_Tree(*subtree);
        return treeresult;
index 7cf29a0f47ede9f8b2f39092f4f6ce4bd8b01992..f39091ef0aa6c1f8dccd86d539b963b664940ccb 100644 (file)
@@ -20,6 +20,7 @@ public:
        Gtk_Button *display_button;
        Gtk_Paned *pane;
        My_Window(GtkWindowType t);
+       ~My_Window();
        void do_display();
        void expand(Gtk_TreeItem *t);
        gint delete_event_impl(GdkEventAny *);
index fd144406b029bcef0e38bdc08350373fd9d40707..c8aebd70573f647c4893d033a4def535fe82f4b5 100644 (file)
@@ -3,8 +3,6 @@ LOADS!!!
 Priorities:
        Make it useful!
        Implement searches
-       Some sort of config-file parsing (not new files, but existing
-       slapd-config stuff)
        port to autoconf (anyone? it should be easy)
 
 Optional:
index 022fac6d819724a2535b8a8a07c659ed4d63be3d..44c8e41aa5e6307b393a927fefbadff2a5c4a9dd 100644 (file)
@@ -33,8 +33,10 @@ int main(int argc, char **argv) {
                }
        }
 
+//     if (base_dn == NULL) base_dn = ldap_get_option(NULL, LDAP_OPT_BASE);
        if (base_dn == NULL) base_dn = "o=University of Michigan, c=US";
-       if (host == NULL) host = "localhost";
+       if (host == NULL) ldap_get_option(NULL, LDAP_OPT_HOST_NAME, host);
+       //host = "localhost";
        if (port == 0) port = LDAP_PORT;
 
        Gtk_Main m(&argc, &argv);
@@ -48,13 +50,11 @@ int main(int argc, char **argv) {
        tree = new Gtk_Tree();
        treeresult = window->make_tree(window, ld, base_dn);
        treeitem = new Gtk_LdapTreeItem(*treeresult->treeitem);
-//     treeitem->remove_c(treeitem->getchild()->gtkobj());
-//     gtk_widget_destroy(GTK_WIDGET(treeitem->xpm_label->gtkobj()));
-       treeresult->treeitem->setType(ROOT_NODE);
+//     treeresult->treeitem->setType(ROOT_NODE);
        tree->append(*treeitem);
        if (treeresult->tree != NULL) {
                subtree = new Gtk_Tree(*treeresult->tree);
-               printf("inserting %s into root\n", base_dn);
+       //      cout << "Inserting " << base_dn << " into root" << endl;
                treeitem->set_subtree(*subtree);
        }
        treeitem->show();
@@ -64,7 +64,8 @@ int main(int argc, char **argv) {
        tree->show();
        viewport->show();
        window->scroller->show();
-       treeitem->getDetails();
+       treeitem->showDetails();
+//     treeitem->select();
        window->set_title("Hello");
        window->activate();