1 #include "Gtk_LdapTreeItem.h"
3 Gtk_LdapTreeItem::Gtk_LdapTreeItem() : Gtk_TreeItem() {
4 this->objectClass = NULL;
7 Gtk_LdapTreeItem::Gtk_LdapTreeItem(char *c, My_Window *w, LDAP *ld) : Gtk_TreeItem() {
8 debug("Gtk_LdapTreeItem::Gtk_LdapTreeItem(%s)\n", c);
11 s = ldap_explode_dn(this->dn, 1);
12 this->rdn = g_strdup_printf("%s", s[0]);
15 this->objectClass = NULL;
19 Gtk_LdapTreeItem::Gtk_LdapTreeItem(GtkTreeItem *t) : Gtk_TreeItem(t) {
22 Gtk_LdapTreeItem::~Gtk_LdapTreeItem() {
23 cout << "Bye" << endl;
27 Gtk_LdapTree* Gtk_LdapTreeItem::getSubtree(LDAP *ld, int counter) {
28 debug("Gtk_LdapTreeItem::getSubtree(%s)\n", this->dn);
29 if (counter <= 0) return NULL;
30 if (this->gtkobj()->subtree != NULL) {
31 //return (Gtk_LdapTree *)GTK_TREE(this->gtkobj()->subtree);
32 debug("This item has a subtree\n");
33 return (Gtk_LdapTree *)this->get_subtree(); //gtkobj()->subtree);
36 Gtk_LdapTree *subtree = NULL, *tree = NULL;
37 Gtk_LdapTreeItem *subtreeitem = NULL;
38 LDAPMessage *r_i = NULL, *entry = NULL;
41 int entriesCount = 0, error;
44 if (this->dn == "cn=config" || this->dn == "cn=monitor" || this->dn == "cn=schema") error = ldap_search_s(this->ld, this->dn, LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, &r_i);
46 if (strcasecmp(this->objectClass,"alias") == 0) error = ldap_search_s(this->ld, this->getAttribute("aliasedobjectname"), LDAP_SCOPE_ONELEVEL, "objectclass=*", NULL, 0, &r_i);
47 else error = ldap_search_s(this->ld, this->dn, LDAP_SCOPE_ONELEVEL, "objectclass=*", NULL, 0, &r_i);
49 // printf("%s\n", ldap_err2string(error));
50 entriesCount = ldap_count_entries(this->ld, r_i);
51 debug("%i results\n", entriesCount);
52 if (entriesCount != 0) {
53 tree = new Gtk_LdapTree();
54 tree->set_selection_mode(GTK_SELECTION_BROWSE);
55 tree->set_view_mode(GTK_TREE_VIEW_ITEM);
56 tree->set_view_lines(false);
57 entry = ldap_first_entry(this->ld, r_i);
59 gfloat percent = 100/entriesCount;
60 debug("percent is %f\n", percent);
61 // this->par->progress.set_percentage(percent/100);
62 // this->par->progress.show();
63 while (entry != NULL) {
64 subtreeitem = new Gtk_LdapTreeItem(ldap_get_dn(this->ld, entry), this->par, this->ld);
65 subtree = subtreeitem->getSubtree(this->ld, counter);
66 debug("inserting %s into %s\n",subtreeitem->rdn,this->rdn);
67 tree->append(*subtreeitem);
69 if (subtree != NULL) subtreeitem->set_subtree(*subtree);
71 entry = ldap_next_entry(this->ld, entry);
72 // gfloat pvalue = (i*percent)/100;
73 // cout << pvalue << " %" << endl;
74 // this->par->progress.update(pvalue);
75 // this->par->progress.show();
78 // this->set_subtree(*tree);
79 // this->par->progress.update(0);
80 // this->par->progress->show();
82 // this->getDetails();
87 void Gtk_LdapTreeItem::setType(int t) {
88 debug("Gtk_LdapTreeItem::setType(%s)\n", this->objectClass);
91 if (this->get_child() != NULL) {
92 debug("got a child here");
93 //xpm_label = new Gtk_HBox(this->get_child());
96 //xpm_label = new Gtk_HBox(*GTK_HBOX(this->get_child()->gtkobj()));
97 xpm_label = new Gtk_HBox(this->get_child()); //->gtkobj());
98 //xpm_label->remove_c(xpm_label->children().nth_data(0));
99 Gtk_HBox::BoxList &list = xpm_label->children();
100 Gtk_HBox::BoxList::iterator i = list.begin();
101 xpm_label->remove(*i);
102 //xpm_label->remove_c(xpm_label->children().nth_data(0));
103 xpm_label->remove(*xpm_label->children().begin());
106 xpm_label = new Gtk_HBox();
107 if (strcasecmp(this->objectClass,"organization") == 0)
108 //xpm_icon=new Gtk_Pixmap(*xpm_label, root_node);
109 xpm_icon=new Gtk_Pixmap(root_node);
110 else if (strcasecmp(this->objectClass,"organizationalunit") == 0)
111 //xpm_icon=new Gtk_Pixmap(*xpm_label, branch_node);
112 xpm_icon=new Gtk_Pixmap(branch_node);
113 else if (strcasecmp(this->objectClass,"person") == 0)
114 //xpm_icon=new Gtk_Pixmap(*xpm_label, leaf_node);
115 xpm_icon=new Gtk_Pixmap(leaf_node);
116 else if (strcasecmp(this->objectClass,"alias") == 0)
117 //xpm_icon=new Gtk_Pixmap(*xpm_label, alias_node);
118 xpm_icon=new Gtk_Pixmap(alias_node);
119 else if (strcasecmp(this->objectClass,"rfc822mailgroup") == 0)
120 //xpm_icon=new Gtk_Pixmap(*xpm_label, rfc822mailgroup_node);
121 xpm_icon=new Gtk_Pixmap(rfc822mailgroup_node);
122 else if (strcasecmp(this->objectClass,"LDAPsubentry") == 0)
123 xpm_icon=new Gtk_Pixmap(monitor);
124 else //xpm_icon=new Gtk_Pixmap(*xpm_label, general_node);
125 xpm_icon=new Gtk_Pixmap(general_node);
126 label = new Gtk_Label(this->rdn);
127 xpm_label->pack_start(*xpm_icon, false, false, 1);
128 xpm_label->pack_start(*label, false, false, 1);
129 if (this->get_child() == NULL) {
130 debug("no children - GREAT!!");
131 this->add(*xpm_label);
139 int Gtk_LdapTreeItem::showDetails() {
140 debug("Gtk_LdapTreeItem::showDetails()\n");
141 if (this->notebook == NULL) this->getDetails();
142 if (this->notebook != NULL) {
143 debug("Have a notebook here");
144 if (par->viewport2->get_child() != NULL) {
145 debug(" and the viewport has children");
146 //par->viewport2->remove(par->viewport2->get_child());
147 par->viewport2->remove();
148 debug(" which have been removed");
150 else debug(" and viewport has no children");
151 par->viewport2->add(*this->notebook);
152 this->notebook->show();
153 par->viewport2->show();
156 else debug("No notebook and no details");
160 char* Gtk_LdapTreeItem::getAttribute(char *c) {
161 int entriesCount, error;
164 char *attribute, **values;
165 error = ldap_search_s(this->ld, this->dn, LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, &this->result_identifier);
166 entriesCount = ldap_count_entries(this->ld, this->result_identifier);
167 if (entriesCount == 0) return 0;
168 for (entry = ldap_first_entry(ld, result_identifier); entry != NULL; entry = ldap_next_entry(ld, result_identifier)) {
169 for (attribute = ldap_first_attribute(ld, entry, &ber); attribute != NULL; attribute = ldap_next_attribute(ld, entry, ber)) {
170 values = ldap_get_values(ld, entry, attribute);
171 if (strcasecmp(attribute, "aliasedobjectname") == 0) {
172 this->aliasedObjectName = strdup(values[0]);
176 return this->aliasedObjectName;
179 int Gtk_LdapTreeItem::getDetails() {
180 debug("Gtk_LdapTreeItem::getDetails()\n");
181 int error, entriesCount;
184 char *attribute, **values;
189 Gtk_Viewport *viewport;
190 error = ldap_search_s(this->ld, this->dn, LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, &this->result_identifier);
191 entriesCount = ldap_count_entries(this->ld, this->result_identifier);
192 if (entriesCount == 0) return 0;
193 this->notebook = new Gtk_Notebook();
194 this->notebook->set_tab_pos(GTK_POS_LEFT);
195 const gchar *titles[] = { "values" };
197 for (entry = ldap_first_entry(ld, result_identifier); entry != NULL; entry = ldap_next_entry(ld, result_identifier)) {
198 for (attribute = ldap_first_attribute(ld, entry, &ber); attribute != NULL; attribute = ldap_next_attribute(ld, entry, ber)) {
199 values = ldap_get_values(ld, entry, attribute);
200 if (strcasecmp(attribute, "objectclass") == 0) {
201 // debug("processing objectclass\n");
202 if (strcasecmp(values[0],"top") == 0)
203 this->objectClass = strdup(values[1]);
204 else this->objectClass = strdup(values[0]);
206 table = new Gtk_CList(1, titles);
207 for (int i=0; i<ldap_count_values(values); i++) {
208 // debug("%i:%s\n",i, values[i]);
209 const gchar *t[] = { values[i] };
212 ldap_value_free(values);
213 sprintf(attrib, "%s", attribute);
214 label = new Gtk_Label(attrib);
215 label->set_alignment(0, 0);
216 label->set_justify(GTK_JUSTIFY_LEFT);
217 this->notebook->pages().push_back(Gtk_Notebook_Helpers::TabElem(*table, *label));
227 void Gtk_LdapTreeItem::show_impl() {
228 debug("%s showed\n", this->dn);
229 // Gtk_c_signals_Base *sig=(Gtk_c_signals_Base *)internal_getsignalbase();
230 // sig->show(GTK_WIDGET(gtkobj()));
233 void Gtk_LdapTreeItem::select_impl() {
234 debug("%s selected\n", this->dn);
236 Gtk_TreeItem::select_impl();
239 void Gtk_LdapTreeItem::collapse_impl() {
240 debug("%s collapsed\n", this->dn);
241 Gtk_TreeItem::collapse_impl();
244 void Gtk_LdapTreeItem::expand_impl() {
245 debug("%s expanded\n",this->dn);
246 Gtk_LdapTreeItem *item;
247 G_List<GtkWidget> *list;
249 Gtk_TreeItem::expand_impl();