[gq-commit] gq/src search.c,1.22,1.23 mainwin.h,1.10,1.11 mainwin.c,1.24,1.25 browse.h,1.19,1.20 bro
Status: Beta
Brought to you by:
sur5r
From: <sta...@us...> - 2002-07-13 16:53:44
|
Update of /cvsroot/gqclient/gq/src In directory usw-pr-cvs1:/tmp/cvs-serv10006 Modified Files: search.c mainwin.h mainwin.c browse.h browse.c Log Message: * Added a new feature: The popup menu for a search/filter result allows to find the same object in the browser. If multiple browsers are available the browser used last is chosen. The best thing about this feature is that it allows to jump to objects in the browse tree that might not be found otherwise (eg. due to a size limit). This allows to explore parts of an LDAP server otherwise not available. * The base combo box on a search tab can now be changed. This allows to use gq for searches where the base must be different from the root objects of the server. For an example where this might be useful see http://www.ldap.research.netsol.com/ldapsearch.html Index: search.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/search.c,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** search.c 18 Jun 2002 22:07:14 -0000 1.22 --- search.c 13 Jul 2002 16:53:41 -0000 1.23 *************** *** 44,51 **** --- 44,54 ---- #include "encode.h" #include "i18n.h" + #include "browse.h" extern struct gq_config config; + void find_in_browser(GHashTable *hash); + static gboolean search_button_press_on_tree_item(GtkWidget *clist, GdkEventButton *event, *************** *** 123,127 **** gtk_signal_connect(GTK_OBJECT(GTK_COMBO(searchbase_combo)->button), "button_press_event", GTK_SIGNAL_FUNC(searchbase_button_pressed), hash); ! GTK_WIDGET_UNSET_FLAGS(GTK_ENTRY(GTK_COMBO(searchbase_combo)->entry), GTK_CAN_FOCUS); GTK_WIDGET_UNSET_FLAGS(GTK_BUTTON(GTK_COMBO(searchbase_combo)->button), GTK_CAN_FOCUS); gtk_widget_show(searchbase_combo); --- 126,130 ---- gtk_signal_connect(GTK_OBJECT(GTK_COMBO(searchbase_combo)->button), "button_press_event", GTK_SIGNAL_FUNC(searchbase_button_pressed), hash); ! /* GTK_WIDGET_UNSET_FLAGS(GTK_ENTRY(GTK_COMBO(searchbase_combo)->entry), GTK_CAN_FOCUS); */ GTK_WIDGET_UNSET_FLAGS(GTK_BUTTON(GTK_COMBO(searchbase_combo)->button), GTK_CAN_FOCUS); gtk_widget_show(searchbase_combo); *************** *** 456,459 **** --- 459,463 ---- searchbase_combo = g_hash_table_lookup(hash, "searchbase_combo"); cur_searchbase = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(searchbase_combo)->entry), 0, -1); + if(config.sort_search) msg = ldap_search_s(ld, cur_searchbase, LDAP_SCOPE_SUBTREE, *************** *** 521,525 **** gtk_clist_set_column_visibility(GTK_CLIST(new_main_clist), oc_col, 0); - row = 0; if(!config.sort_search) --- 525,528 ---- *************** *** 529,534 **** while(rc) { ! ! for(e = ldap_first_entry(ld, res); e != NULL; e = ldap_next_entry(ld, e)) { /* not every attribute necessarily comes back for every entry, --- 532,537 ---- while(rc) { ! for(e = ldap_first_entry(ld, res); e != NULL; ! e = ldap_next_entry(ld, e)) { /* not every attribute necessarily comes back for every entry, *************** *** 608,611 **** --- 611,615 ---- if(server->maxentries == 0 || row < server->maxentries) { ldap_msgfree(res); + res = NULL; rc = (ldap_result(ld, msg, 0, NULL, &res) == LDAP_RES_SEARCH_ENTRY); } *************** *** 625,629 **** gtk_clist_column_titles_passive(GTK_CLIST(new_main_clist)); free_attrlist(attrlist); ! ldap_msgfree(res); close_connection(server, FALSE); --- 629,633 ---- gtk_clist_column_titles_passive(GTK_CLIST(new_main_clist)); free_attrlist(attrlist); ! if (res) ldap_msgfree(res); close_connection(server, FALSE); *************** *** 668,671 **** --- 672,683 ---- gtk_widget_show(menu_item); + /* Find in Browser */ + menu_item = gtk_menu_item_new_with_label(_("Find in browser")); + gtk_menu_append(GTK_MENU(menu), menu_item); + gtk_signal_connect_object(GTK_OBJECT(menu_item), "activate", + GTK_SIGNAL_FUNC(find_in_browser), + (gpointer) hash); + gtk_widget_show(menu_item); + /* separator */ menu_item = gtk_menu_item_new(); *************** *** 681,687 **** --- 693,727 ---- gtk_widget_show(menu_item); + gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, event->time); + } + + void find_in_browser(GHashTable *hash) + { + struct ldapserver *server; + struct resultset *set; + GHashTable *browsehash; + GtkCTree *ctree; + + set = g_hash_table_lookup(hash, "set"); + g_hash_table_remove(hash, "set"); + if(set == NULL || set->dn == NULL) + return; + + if( (server = g_hash_table_lookup(hash, "cur_resultset_server")) == NULL) + return; + + /* find last used browser... */ + + browsehash = get_last_of_mode(BROWSE_MODE); + if (browsehash) { + ctree = g_hash_table_lookup(browsehash, "ctreeroot"); + show_server_dn(ctree, server, set->dn); + go_to_page(browsehash); + } else { + single_warning_popup(_("No browser available")); + } } Index: mainwin.h =================================================================== RCS file: /cvsroot/gqclient/gq/src/mainwin.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** mainwin.h 13 Jun 2002 10:03:33 -0000 1.10 --- mainwin.h 13 Jul 2002 16:53:41 -0000 1.11 *************** *** 46,49 **** --- 46,53 ---- extern GtkWidget *statusbar; + GHashTable *get_last_of_mode(int mode); + void go_to_page(GHashTable *hash); + void enter_last_of(int mode, GHashTable *hash); + void fill_serverlist_combo(GtkWidget *combo); void cleanup(void); Index: mainwin.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/mainwin.c,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** mainwin.c 18 Jun 2002 22:07:14 -0000 1.24 --- mainwin.c 13 Jul 2002 16:53:41 -0000 1.25 *************** *** 55,58 **** --- 55,82 ---- GList *tablist = NULL; + static GHashTable *lastofmode = NULL; + + GHashTable *get_last_of_mode(int mode) + { + if (!lastofmode) return NULL; + return g_hash_table_lookup(lastofmode, GINT_TO_POINTER(mode)); + } + + void go_to_page(GHashTable *hash) + { + gtk_notebook_set_page(GTK_NOTEBOOK(mainbook), + g_list_index(tablist, hash)); + } + + void enter_last_of(int mode, GHashTable *hash) + { + if (!lastofmode) { + lastofmode = g_hash_table_new(g_direct_hash, g_direct_equal); + } + + g_hash_table_insert(lastofmode, + (gpointer) mode, hash); + } + void fill_serverlist_combo(GtkWidget *combo) { *************** *** 382,385 **** --- 406,411 ---- g_hash_table_insert(hash, "mode", GINT_TO_POINTER(mode)); + enter_last_of(mode, hash); + switch(mode) { case SEARCH_MODE: *************** *** 423,426 **** --- 449,453 ---- GHashTable *hash; GtkWidget *focusbox; + int mode; hash = g_list_nth_data(tablist, pagenum); *************** *** 428,431 **** --- 455,463 ---- return; + /* retrieve mode, store this pane as the last one used for this mode */ + mode = GPOINTER_TO_INT(g_hash_table_lookup(hash, "mode")); + + enter_last_of(mode, hash); + focusbox = g_hash_table_lookup(hash, "focus"); if(focusbox) { *************** *** 461,468 **** { GHashTable *hash; ! int tab; tab = gtk_notebook_get_current_page(GTK_NOTEBOOK(mainbook)); hash = g_list_nth_data(tablist, tab); cleanup_tab(hash); g_hash_table_destroy(hash); --- 493,506 ---- { GHashTable *hash; ! int tab, thismode = -1; ! GList *tl; tab = gtk_notebook_get_current_page(GTK_NOTEBOOK(mainbook)); hash = g_list_nth_data(tablist, tab); + + if (hash) { + thismode = GPOINTER_TO_INT(g_hash_table_lookup(hash, "mode")); + } + cleanup_tab(hash); g_hash_table_destroy(hash); *************** *** 472,475 **** --- 510,526 ---- gtk_widget_destroy(mainwin); + enter_last_of(thismode, NULL); + + /* try to find another tab with the same mode so we can put that + one into lastofmode... */ + + for (tl = tablist ; tl ; tl = tl->next) { + if (GPOINTER_TO_INT(g_hash_table_lookup((GHashTable *) tl->data, + "mode")) == thismode) { + /* found one! */ + enter_last_of(thismode, tl->data); + break; + } + } } *************** *** 687,688 **** --- 738,745 ---- } + + /* + Local Variables: + c-basic-offset: 5 + End: + */ Index: browse.h =================================================================== RCS file: /cvsroot/gqclient/gq/src/browse.h,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** browse.h 21 Jun 2002 00:34:32 -0000 1.19 --- browse.h 13 Jul 2002 16:53:41 -0000 1.20 *************** *** 141,144 **** --- 141,145 ---- GtkCTreeNode *node); + void show_server_dn(GtkCTree *tree, struct ldapserver *server, char *dn); void show_dn(GtkCTree *tree, GtkCTreeNode *node, char *dn); Index: browse.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/browse.c,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** browse.c 13 Jul 2002 07:04:20 -0000 1.53 --- browse.c 13 Jul 2002 16:53:41 -0000 1.54 *************** *** 87,90 **** --- 87,137 ---- } + + static GtkCTreeNode *dn_browse_single_add(LDAP *ld, + LDAPMessage *e, + GtkCTree *ctree, + GtkCTreeNode *node) + { + char *dn = ldap_get_dn(ld, e); + char **exploded_dn = 0; + char *labels[] = { NULL, NULL }; + char *dummy[] = { "dummy", NULL }; + dn_browse_entry *new_entry; + GtkCTreeNode *new_item, *added; + + /* explode DN */ + exploded_dn = gq_ldap_explode_dn(dn, FALSE); + labels[0] = decoded_string(exploded_dn[0]); + + new_entry = (dn_browse_entry *) new_dn_browse_entry(dn); + + added = gtk_ctree_insert_node(ctree, + node, NULL, + labels, + 0, + NULL, NULL, NULL, NULL, + FALSE, FALSE); + + gtk_ctree_node_set_row_data_full(ctree, + added, + new_entry, + (GtkDestroyNotify) destroy_browse_entry); + + /* add dummy node */ + new_item = gtk_ctree_insert_node(ctree, + added, NULL, + dummy, + 0, + NULL, NULL, NULL, NULL, + TRUE, FALSE); + + free(labels[0]); + gq_exploded_free(exploded_dn); + free(dn); + + return added; + } + + static void dn_browse_entry_expand(dn_browse_entry *entry, GtkCTree *ctree, *************** *** 95,106 **** LDAPMessage *res, *e; struct ldapserver *server; ! int msg, rc, num_children, update_counter; ! char *dn, message[MAX_DN_LEN + 21]; char *dummy[] = { "dummy", NULL }; - char *labels[] = { NULL, NULL }; char *c; ! dn_browse_entry *new_entry; ! GtkCTreeNode *new_item; ! char **exploded_dn = 0; if (!entry->seen) { --- 142,150 ---- LDAPMessage *res, *e; struct ldapserver *server; ! int msg, rc, num_children, update_counter, err; ! char message[MAX_DN_LEN + 21]; char *dummy[] = { "dummy", NULL }; char *c; ! int context = error_new_context(_("Expand entry")); if (!entry->seen) { *************** *** 111,114 **** --- 155,159 ---- if( (ld = open_connection(server)) == NULL) { + error_flush(context); return; } *************** *** 142,145 **** --- 187,192 ---- close_connection(server, FALSE); gtk_clist_thaw(GTK_CLIST(ctree)); + + error_flush(context); return; } *************** *** 150,185 **** NULL, &res)) == LDAP_RES_SEARCH_ENTRY) { for(e = ldap_first_entry(ld, res) ; e != NULL ; ! e=ldap_next_entry(ld, e)) { ! dn = ldap_get_dn(ld, e); ! ! /* explode DN */ ! exploded_dn = gq_ldap_explode_dn(dn, FALSE); ! labels[0] = decoded_string(exploded_dn[0]); ! ! new_entry = (dn_browse_entry *) new_dn_browse_entry(dn); ! ! new_item = gtk_ctree_insert_node(ctree, ! node, NULL, ! labels, ! 0, ! NULL, NULL, NULL, NULL, ! FALSE, FALSE); ! ! gtk_ctree_node_set_row_data_full(ctree, ! new_item, ! new_entry, ! (GtkDestroyNotify) destroy_browse_entry); ! /* add dummy node */ ! new_item = gtk_ctree_insert_node(ctree, ! new_item, NULL, ! dummy, ! 0, ! NULL, NULL, NULL, NULL, ! TRUE, FALSE); ! ! free(labels[0]); ! gq_exploded_free(exploded_dn); ! free(dn); num_children++; --- 197,203 ---- NULL, &res)) == LDAP_RES_SEARCH_ENTRY) { for(e = ldap_first_entry(ld, res) ; e != NULL ; ! e = ldap_next_entry(ld, e)) { ! dn_browse_single_add(ld, e, ctree, node); num_children++; *************** *** 195,205 **** ldap_msgfree(res); } - if (res) ldap_msgfree(res); entry->leaf = (num_children == 0); make_message(message, sizeof(message), num_children, _("entry"), _("entries"), _("found (finished)")); statusbar_msg(message); gtk_clist_thaw(GTK_CLIST(ctree)); --- 213,247 ---- ldap_msgfree(res); } entry->leaf = (num_children == 0); make_message(message, sizeof(message), num_children, _("entry"), _("entries"), _("found (finished)")); + + + rc = ldap_parse_result(ld, res, + &err, NULL, NULL, NULL, NULL, 0); + + if (rc != LDAP_SUCCESS) { + error_push(context, ldap_err2string(rc)); + push_ldap_addl_error(ld, context); + } else { + if (err == LDAP_SIZELIMIT_EXCEEDED) { + int l = strlen(message); + snprintf(message + l, sizeof(message) - l, + " - %s", _("size limit exceeded")); + } else if (err == LDAP_TIMELIMIT_EXCEEDED) { + int l = strlen(message); + snprintf(message + l, sizeof(message) - l, + " - %s", _("time limit exceeded")); + } else if (err != LDAP_SUCCESS) { + error_push(context, ldap_err2string(err)); + push_ldap_addl_error(ld, context); + } + } + statusbar_msg(message); + if (res) ldap_msgfree(res); + gtk_clist_thaw(GTK_CLIST(ctree)); *************** *** 219,223 **** } ! } --- 261,265 ---- } ! error_flush(context); } *************** *** 797,800 **** --- 839,845 ---- if (IS_SERVER_ENTRY(e)) { sd->currserver = ((server_browse_entry *)e)->server; + if (strlen(sd->dn) == 0 && sd->currserver == sd->server) { + sd->found = node; + } return; } *************** *** 974,977 **** --- 1019,1031 ---- } + void show_server_dn(GtkCTree *tree, struct ldapserver *server, char *dn) + { + GtkCTreeNode *node = tree_node_from_server_dn(tree, server, ""); + if (node) { + gtk_ctree_expand(tree, node); + show_dn(tree, node, dn); + } + } + void show_dn(GtkCTree *tree, GtkCTreeNode *node, char *dn) { *************** *** 979,982 **** --- 1033,1037 ---- int i; GString *s; + GtkCTreeNode *found = NULL; if (!dn) return; *************** *** 992,1001 **** g_string_insert(s, 0, dnparts[i]); ! node = node_from_dn(tree, ! node, ! s->str); ! if (node) gtk_ctree_expand(tree, node); ! else break; g_string_insert(s, 0, ","); --- 1047,1083 ---- g_string_insert(s, 0, dnparts[i]); ! /* printf("try %s at %08lx\n", s->str, node); */ if (node) gtk_ctree_expand(tree, node); ! ! found = node_from_dn(tree, node, s->str); ! ! if (found) { ! node = found; ! } else if (node) { ! /* check if the object with this dn actually exists. If ! it does, we add it to the tree by hand, as we ! probably cannot see it due to a size limit */ ! struct ldapserver *server = server_from_node(tree, node); ! LDAP *ld; ! ! if( (ld = open_connection(server)) != NULL) { ! LDAPMessage *res, *e; ! int rc = ldap_search_s(ld, s->str, LDAP_SCOPE_BASE, ! "(objectClass=*)", NULL, 0, &res); ! if (rc == LDAP_SUCCESS) { ! e = ldap_first_entry(ld, res); ! if (e) { ! /* have it!! */ ! found = dn_browse_single_add(ld, e, tree, node); ! node = found; ! } ! ldap_msgfree(res); ! } ! ! close_connection(server, FALSE); ! } ! } ! ! /* else break; */ g_string_insert(s, 0, ","); *************** *** 1004,1007 **** --- 1086,1096 ---- gq_exploded_free(dnparts); g_string_free(s, TRUE); + + if (found) { + gtk_ctree_select(tree, found); + gtk_ctree_node_moveto(tree, node, + 0, + 0.5, 0); + } } |