Thread: [gq-commit] gq/src formfill.h,1.22,1.23 input.c,1.49,1.50
Status: Beta
Brought to you by:
sur5r
From: <sta...@us...> - 2002-09-28 20:10:17
|
Update of /cvsroot/gqclient/gq/src In directory usw-pr-cvs1:/tmp/cvs-serv28832 Modified Files: formfill.h input.c Log Message: * Support for the 'extensibleObject' object class. This introduces a new icon in the browse window. Selecting it opens a dialog to select an attribute to be added to the object. Index: formfill.h =================================================================== RCS file: /cvsroot/gqclient/gq/src/formfill.h,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** formfill.h 27 Sep 2002 00:22:14 -0000 1.22 --- formfill.h 28 Sep 2002 20:10:14 -0000 1.23 *************** *** 62,65 **** --- 62,67 ---- /* Used to suppress the "more" button for single valued attributes */ #define FLAG_SINGLE_VALUE 0x08 + /* Used to temporarily mark attributes added for extensibleObject entries */ + #define FLAG_EXTENSIBLE_OBJECT_ATTR 0x10 /* Used to disable widgets for attributes marked as no_user_mod */ Index: input.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/input.c,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** input.c 27 Sep 2002 00:22:14 -0000 1.49 --- input.c 28 Sep 2002 20:10:14 -0000 1.50 *************** *** 61,64 **** --- 61,65 ---- static void hide_empty_attributes(GtkToggleButton *button, gpointer hash); + static void create_new_attr(GtkButton *button, GHashTable *hash); void create_form_window(GHashTable *hash) *************** *** 107,111 **** target_vbox = g_hash_table_lookup(hash, "target_vbox"); ! hbox1 = gtk_hbox_new(FALSE, 5); gtk_widget_show(hbox1); gtk_box_pack_start(GTK_BOX(target_vbox), hbox1, FALSE, FALSE, 5); --- 108,112 ---- target_vbox = g_hash_table_lookup(hash, "target_vbox"); ! hbox1 = gtk_hbox_new(FALSE, 0); gtk_widget_show(hbox1); gtk_box_pack_start(GTK_BOX(target_vbox), hbox1, FALSE, FALSE, 5); *************** *** 184,192 **** gtk_container_add(GTK_CONTAINER(newattrbutton), pixmap); gtk_widget_show(newattrbutton); ! gtk_widget_set_sensitive(newattrbutton, 0); /* not implemented */ gtk_box_pack_end(GTK_BOX(hbox1), newattrbutton, FALSE, FALSE, 5); ! /* gtk_signal_connect(GTK_OBJECT(newattrbutton), "clicked", */ ! /* GTK_SIGNAL_FUNC(change_displaytype), */ ! /* (gpointer) hash); */ gtk_tooltips_set_tip(tips, newattrbutton, --- 185,194 ---- gtk_container_add(GTK_CONTAINER(newattrbutton), pixmap); gtk_widget_show(newattrbutton); ! gtk_box_pack_end(GTK_BOX(hbox1), newattrbutton, FALSE, FALSE, 5); ! ! gtk_signal_connect(GTK_OBJECT(newattrbutton), "clicked", ! GTK_SIGNAL_FUNC(create_new_attr), ! (gpointer) hash); gtk_tooltips_set_tip(tips, newattrbutton, *************** *** 494,499 **** GdkColor mustcol = { 0, 0x5c00, 0x3800, 0xffff }; GdkColor delcol = { 0, 0xd600, 0xa000, 0x0000 }; ! GtkStyle *not_in_schema, *must_in_schema, *del_schema; GtkWidget *target_table, *inputbox, *arrowbutton, *vbox; GtkWidget *widget = NULL, *align; --- 496,502 ---- GdkColor mustcol = { 0, 0x5c00, 0x3800, 0xffff }; GdkColor delcol = { 0, 0xd600, 0xa000, 0x0000 }; + GdkColor extensible_col = { 0, 0xffff, 0x0000, 0xffff }; ! GtkStyle *not_in_schema, *must_in_schema, *del_schema, *extensible_attr; GtkWidget *target_table, *inputbox, *arrowbutton, *vbox; GtkWidget *widget = NULL, *align; *************** *** 518,521 **** --- 521,528 ---- del_schema->fg[GTK_STATE_NORMAL] = delcol; + + extensible_attr = gtk_style_copy(gtk_widget_get_default_style()); + extensible_attr->fg[GTK_STATE_NORMAL] = extensible_col; + /* mind form->num_inputfields and len(GList * values) may not be the same -- if adding a field with an arrowbutton */ *************** *** 612,615 **** --- 619,624 ---- if(form->flags & FLAG_DEL_ME) gtk_widget_set_style(form->label, del_schema); + if(form->flags & FLAG_EXTENSIBLE_OBJECT_ATTR) + gtk_widget_set_style(form->label, extensible_attr); currcnt = form->widgetList ? g_list_length(form->widgetList) : 0; *************** *** 1789,1792 **** --- 1798,2064 ---- } + /* Datastructure used to communicate between the functions making up the + add attribute dialog */ + + typedef struct { + int breakloop; + int rc; + int destroyed; + gchar **outbuf; + GtkWidget *combo; + GList *entries; + } attr_dialog_comm; + + + /* The set of functions implementing the dialog for the new attribute + button for extensibleObjects */ + + static void attr_destroy(GtkWidget *window, attr_dialog_comm *comm) { + comm->breakloop = 1; + comm->destroyed = 1; + } + + static void attr_ok(GtkWidget *button, attr_dialog_comm *comm) { + *(comm->outbuf) = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(comm->combo)->entry), 0, -1); + + if (g_list_find_custom(comm->entries, + *(comm->outbuf), + (GCompareFunc) strcmp)) { + comm->breakloop = 1; + comm->rc = 1; + } else { + *(comm->outbuf) = NULL; + } + + } + + static void attr_cancel(GtkWidget *button, attr_dialog_comm *comm) { + comm->breakloop = 1; + comm->rc = 0; + } + + /* pops up a dialog to select an attribute type via a GtkCombo. This + functions waits for the data and puts it into outbuf. */ + + int attr_popup(const char *title, + struct ldapserver *server, + gchar **outbuf) + { + GtkWidget *window, *vbox0, *vbox1, *vbox2, *label, *button, *hbox0; + GtkWidget *f = gtk_grab_get_current(); + GList *gl; + struct server_schema *ss = get_schema(server); + + attr_dialog_comm comm = { 0, 0, 0, NULL }; + comm.outbuf = outbuf; + *outbuf = NULL; + + if (!ss) { + error_popup(_("Oops!"), + _("Server schema not available.")); + return 0; + } + + /* This is a BAD hack - it solves a problem with the query popup + dialog that locks up focus handling with all the + window-managers I have been able to test this with. Actually, + it should be sufficient to let go of the focus, but + hiding/showing seems to work... (as I do not know how to + release the focus in gtk) - Any gtk Hackers around? */ + if (f != NULL) { + gtk_widget_hide(f); + gtk_widget_show(f); + } + + window = gtk_dialog_new(); + /* gtk_container_border_width(GTK_CONTAINER(window), 0); */ + gtk_window_set_title(GTK_WINDOW(window), title); + gtk_window_set_policy(GTK_WINDOW(window), FALSE, FALSE, FALSE); + gtk_signal_connect(GTK_OBJECT(window), "destroy", + (GtkSignalFunc) attr_destroy, + (gpointer) &comm); + gtk_signal_connect_object(GTK_OBJECT(window), "key_press_event", + GTK_SIGNAL_FUNC(close_on_esc), + (gpointer) window); + + vbox0 = GTK_DIALOG(window)->vbox; + gtk_widget_show(vbox0); + + vbox1 = gtk_vbox_new(FALSE, 0); + gtk_widget_show(vbox1); + gtk_container_border_width(GTK_CONTAINER(vbox1), CONTAINER_BORDER_WIDTH); + gtk_box_pack_start(GTK_BOX(vbox0), vbox1, TRUE, TRUE, 0); + + label = gtk_label_new(title); + gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0); + gtk_widget_show(label); + gtk_box_pack_start(GTK_BOX(vbox1), label, TRUE, TRUE, 0); + + comm.combo = gtk_combo_new(); + gtk_combo_set_value_in_list(GTK_COMBO(comm.combo), TRUE, TRUE); + + comm.entries = NULL; + + for (gl = ss->at ; gl ; gl = gl->next) { + LDAPAttributeType *at = (LDAPAttributeType *) gl->data; + + if (at && at->at_names) { + int i; + for (i = 0 ; at->at_names[i] ; i++) { + comm.entries = g_list_append(comm.entries, at->at_names[i]); + } + } + } + + comm.entries = g_list_sort(comm.entries, (GCompareFunc) strcmp); + comm.entries = g_list_insert(comm.entries, "", 0); + + gtk_combo_set_popdown_strings(GTK_COMBO(comm.combo), + comm.entries); + + GTK_WIDGET_SET_FLAGS(comm.combo, GTK_CAN_FOCUS); + GTK_WIDGET_SET_FLAGS(comm.combo, GTK_CAN_DEFAULT); + + + gtk_widget_set_sensitive(GTK_COMBO(comm.combo)->entry, FALSE); + + gtk_widget_show(comm.combo); + gtk_box_pack_end(GTK_BOX(vbox1), comm.combo, TRUE, TRUE, 0); + + vbox2 = GTK_DIALOG(window)->action_area; + /* gtk_container_border_width(GTK_CONTAINER(vbox2), CONTAINER_BORDER_WIDTH); */ + gtk_widget_show(vbox2); + + hbox0 = gtk_hbutton_box_new(); + gtk_widget_show(hbox0); + gtk_box_pack_start(GTK_BOX(vbox2), hbox0, TRUE, TRUE, 0); + + button = gtk_button_new_with_label(_("OK")); + gtk_signal_connect(GTK_OBJECT(button), "clicked", + GTK_SIGNAL_FUNC(attr_ok), &comm); + gtk_box_pack_start(GTK_BOX(hbox0), button, FALSE, FALSE, 0); + GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); + GTK_WIDGET_SET_FLAGS(button, GTK_RECEIVES_DEFAULT); + gtk_widget_grab_default(button); + gtk_widget_show(button); + + button = gtk_button_new_with_label(_("Cancel")); + gtk_signal_connect(GTK_OBJECT(button), "clicked", + GTK_SIGNAL_FUNC(attr_cancel), + &comm); + + gtk_box_pack_end(GTK_BOX(hbox0), button, FALSE, FALSE, 0); + gtk_widget_show(button); + + /* gtk_window_set_transient_for(GTK_WINDOW(window), */ + /* GTK_WINDOW(getMainWin())); */ + + + gtk_widget_grab_focus(GTK_WIDGET(window)); + gtk_window_set_modal(GTK_WINDOW(window), TRUE); + + gtk_widget_show(window); + gtk_widget_grab_focus(comm.combo); + + while (!comm.breakloop) { + gtk_main_iteration(); + } + + if (!comm.destroyed) { + gtk_widget_destroy(window); + } + + if (comm.entries) g_list_free(comm.entries); + comm.entries = NULL; + + return comm.rc; + } + + /* Checks if the objectClass attribute contains "extensibleObject" */ + + int is_extensible_object(GHashTable *hash) + { + GList *f, *wl; + GList *formlist = g_hash_table_lookup(hash, "formlist"); + GtkWidget *w; + GByteArray *ndata = NULL; + + if (!formlist) return 0; + + for (f = formlist ; f ; f = f->next) { + struct formfill *form = (struct formfill *) f->data; + + if (strcasecmp(form->attrname, "objectClass") == 0) { + for (wl = form->widgetList ; wl ; wl = wl->next) { + w = GTK_WIDGET(wl->data); + + if (form->dt_handler && form->dt_handler->get_data) { + ndata = form->dt_handler->get_data(form, w); + + if (ndata) { + if (strncasecmp(ndata->data, + "extensibleObject", + ndata->len) == 0) { + + g_byte_array_free(ndata, TRUE); + return 1; + } + g_byte_array_free(ndata, TRUE); + } + } + } + } + } + + return 0; + } + + static void create_new_attr(GtkButton *button, GHashTable *hash) + { + char *outbuf; + struct ldapserver *server = g_hash_table_lookup(hash, "server"); + int rc; + + if (!is_extensible_object(hash)) { + error_popup(_("Oops!"), + _("Not an 'extensibleObject'")); + return; + } + + rc = attr_popup(_("Select name of new attribute"), + server, + &outbuf); + + if (rc && strlen(outbuf) > 0) { + GList *formlist = g_hash_table_lookup(hash, "formlist"); + LDAPAttributeType *at = find_canonical_at_by_at(get_schema(server), + outbuf); + + if (at) { + struct formfill *form = new_formfill(); + + if (form) { + form->server = server; + strncpy(form->attrname, outbuf, + MAX_ATTR_LEN); + form->flags |= FLAG_EXTENSIBLE_OBJECT_ATTR; + if (at->at_single_value) { + form->flags |= FLAG_SINGLE_VALUE; + } + set_displaytype(server, form); + formlist = formlist_append(formlist, form); + + g_hash_table_insert(hash, "formlist", formlist); + + build_or_update_inputform(hash, FALSE); + } else { + error_popup(_("Oops!"), + _("Not enough memory to make form.")); + } + } + } + + if (outbuf) g_free(outbuf); + } |