[gq-commit] gq/src dt_int.c,NONE,1.1 dt_int.h,NONE,1.1 dt_numstr.c,NONE,1.1 dt_numstr.h,NONE,1.1 Mak
Status: Beta
Brought to you by:
sur5r
From: <sta...@us...> - 2003-10-21 06:06:07
|
Update of /cvsroot/gqclient/gq/src In directory sc8-pr-cvs1:/tmp/cvs-serv8691 Modified Files: Makefile.am formfill.h syntax.c Added Files: dt_int.c dt_int.h dt_numstr.c dt_numstr.h Log Message: * Added two new display-types for integers and numeric strings - Straight forward --- NEW FILE: dt_int.c --- /* GQ -- a GTK-based LDAP client Copyright (C) 1998-2001 Bert Vermeulen This file (dt_entry.c) is Copyright (C) 2002 by Peter Stamfest and Bert Vermeulen This program is released under the Gnu General Public License with the additional exemption that compiling, linking, and/or using OpenSSL is allowed. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* $Id: dt_int.c,v 1.1 2003/10/21 04:46:41 stamfest Exp $ */ #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <glib.h> #include <gdk/gdk.h> #include <gtk/gtk.h> #include <config.h> #include "dt_int.h" #include "common.h" #include "util.h" #include "errorchain.h" #include "input.h" #include "tinput.h" #include "browse.h" #include "encode.h" #include "ldif.h" /* for b64_decode */ #include "syntax.h" #include "dtutil.h" #include "utf8-compat.h" static dt_int_handler dt_int_handler_vtab = { { "Integer", TRUE, TRUE, dt_int_get_widget, dt_int_get_data, dt_int_set_data, bervalLDAPMod }, #if GTK_MAJOR < 2 decode_utf8, /* encode method */ encode_utf8, /* decode method */ #else /* gtk2 uses UTF-8 natively! Yipieeh */ NULL, NULL, #endif }; display_type_handler *dt_int_get_handler() { return (display_type_handler *) &dt_int_handler_vtab; } static void dt_int_verify(GtkWidget *entry) { char *txt = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1); gunichar c; if (txt) { GString *s = g_string_sized_new(strlen(txt)); int nope = 0; char *t; /* allow only digits, no leading zeroes */ for(t = txt, c = g_utf8_get_char(t) ; c ; t = g_utf8_next_char(t), c = g_utf8_get_char(t)) { if (g_unichar_isdigit(c)) { g_string_append_unichar(s, c); } else { nope = 1; } } g_free(txt); txt = g_strcompress(s->str); /* one-byte chars only */ if (strcmp(txt, "0") != 0) { for(t = txt ; *t == '0' ; t++) nope = 1; if (*t == 0 && txt != t) t--; /* must have zeros-only string */ } if (nope) { gtk_entry_set_text(GTK_ENTRY(entry), t); } g_string_free(s, TRUE); } return; } GtkWidget *dt_int_get_widget(struct formfill *form, GByteArray *data, GtkSignalFunc *activatefunc, gpointer funcdata) { GtkWidget *hbox, *inputbox, *label; hbox = gtk_hbox_new(FALSE, 0); gtk_widget_show(hbox); inputbox = gtk_entry_new(); gtk_widget_show(inputbox); if(activatefunc) gtk_signal_connect_object(GTK_OBJECT(inputbox), "activate", GTK_SIGNAL_FUNC(activatefunc), (gpointer) funcdata); gtk_signal_connect(GTK_OBJECT(inputbox), "changed", GTK_SIGNAL_FUNC(dt_int_verify), (gpointer) NULL); gtk_box_pack_start(GTK_BOX(hbox), inputbox, TRUE, TRUE, 0); label = gtk_label_new(_("(int)")); gtk_widget_show(label); gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); gtk_object_set_data(GTK_OBJECT(hbox), "inputbox", inputbox); dt_int_set_data(form, data, hbox); return hbox; } GByteArray *dt_int_get_data(struct formfill *form, GtkWidget *widget) { return editable_get_text(GTK_EDITABLE(dt_int_retrieve_inputbox(widget))); } void dt_int_set_data(struct formfill *form, GByteArray *data, GtkWidget *widget) { editable_set_text(GTK_EDITABLE(dt_int_retrieve_inputbox(widget)), data, DT_INT(form->dt_handler)->encode, DT_INT(form->dt_handler)->decode); } GtkWidget *dt_int_retrieve_inputbox(GtkWidget *hbox) { return gtk_object_get_data(GTK_OBJECT(hbox), "inputbox"); } /* Local Variables: c-basic-offset: 5 End: */ --- NEW FILE: dt_int.h --- /* GQ -- a GTK-based LDAP client Copyright (C) 1998-2003 Bert Vermeulen Copyright (C) 2002-2003 by Peter Stamfest and Bert Vermeulen This program is released under the Gnu General Public License with the additional exemption that compiling, linking, and/or using OpenSSL is allowed. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* $Id: dt_int.h,v 1.1 2003/10/21 04:46:41 stamfest Exp $ */ #ifndef DT_INT_H_INCLUDED #define DT_INT_H_INCLUDED #include "formfill.h" #include "syntax.h" #include "dt_entry.h" #include "i18n.h" typedef dt_entry_handler dt_int_handler; #define DT_INT(objpointer) ((dt_int_handler*)(objpointer)) display_type_handler *dt_int_get_handler(); /* Methods, only to be used by subclasses */ GtkWidget *dt_int_get_widget(struct formfill *form, GByteArray *data, GtkSignalFunc *activatefunc, gpointer funcdata); GByteArray *dt_int_get_data(struct formfill *form, GtkWidget *widget); void dt_int_set_data(struct formfill *form, GByteArray *data, GtkWidget *widget); GtkWidget *dt_int_retrieve_inputbox(GtkWidget *hbox); #endif /* Local Variables: c-basic-offset: 5 End: */ --- NEW FILE: dt_numstr.c --- /* GQ -- a GTK-based LDAP client Copyright (C) 1998-2001 Bert Vermeulen This file (dt_entry.c) is Copyright (C) 2002 by Peter Stamfest and Bert Vermeulen This program is released under the Gnu General Public License with the additional exemption that compiling, linking, and/or using OpenSSL is allowed. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* $Id: dt_numstr.c,v 1.1 2003/10/21 04:46:41 stamfest Exp $ */ #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <glib.h> #include <gdk/gdk.h> #include <gtk/gtk.h> #include <config.h> #include "dt_numstr.h" #include "common.h" #include "util.h" #include "errorchain.h" #include "input.h" #include "tinput.h" #include "browse.h" #include "encode.h" #include "ldif.h" /* for b64_decode */ #include "syntax.h" #include "dtutil.h" #include "utf8-compat.h" static dt_numstr_handler dt_numstr_handler_vtab = { { "Numeric String", TRUE, TRUE, dt_numstr_get_widget, dt_numstr_get_data, dt_numstr_set_data, bervalLDAPMod }, #if GTK_MAJOR < 2 decode_utf8, /* encode method */ encode_utf8, /* decode method */ #else /* gtk2 uses UTF-8 natively! Yipieeh */ NULL, NULL, #endif }; display_type_handler *dt_numstr_get_handler() { return (display_type_handler *) &dt_numstr_handler_vtab; } static void dt_numstr_verify(GtkWidget *entry) { char *txt = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1); gunichar c; if (txt) { GString *s = g_string_sized_new(strlen(txt)); int nope = 0; char *t; gunichar space = g_utf8_get_char(" "); /* allow only digits and spaces */ for(t = txt, c = g_utf8_get_char(t) ; c ; t = g_utf8_next_char(t), c = g_utf8_get_char(t)) { if (g_unichar_isdigit(c) || c == space) { g_string_append_unichar(s, c); } else { nope = 1; } } if (nope) { gtk_entry_set_text(GTK_ENTRY(entry), s->str); } g_string_free(s, TRUE); g_free(txt); } return; } GtkWidget *dt_numstr_get_widget(struct formfill *form, GByteArray *data, GtkSignalFunc *activatefunc, gpointer funcdata) { GtkWidget *hbox, *inputbox, *label; hbox = gtk_hbox_new(FALSE, 0); gtk_widget_show(hbox); inputbox = gtk_entry_new(); gtk_widget_show(inputbox); if(activatefunc) gtk_signal_connect_object(GTK_OBJECT(inputbox), "activate", GTK_SIGNAL_FUNC(activatefunc), (gpointer) funcdata); gtk_signal_connect(GTK_OBJECT(inputbox), "changed", GTK_SIGNAL_FUNC(dt_numstr_verify), (gpointer) NULL); gtk_box_pack_start(GTK_BOX(hbox), inputbox, TRUE, TRUE, 0); label = gtk_label_new(_("(ns)")); gtk_widget_show(label); gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); gtk_object_set_data(GTK_OBJECT(hbox), "inputbox", inputbox); dt_numstr_set_data(form, data, hbox); return hbox; } GByteArray *dt_numstr_get_data(struct formfill *form, GtkWidget *widget) { return editable_get_text(GTK_EDITABLE(dt_numstr_retrieve_inputbox(widget))); } void dt_numstr_set_data(struct formfill *form, GByteArray *data, GtkWidget *widget) { editable_set_text(GTK_EDITABLE(dt_numstr_retrieve_inputbox(widget)), data, DT_NUMSTR(form->dt_handler)->encode, DT_NUMSTR(form->dt_handler)->decode); } GtkWidget *dt_numstr_retrieve_inputbox(GtkWidget *hbox) { return gtk_object_get_data(GTK_OBJECT(hbox), "inputbox"); } /* Local Variables: c-basic-offset: 5 End: */ --- NEW FILE: dt_numstr.h --- /* GQ -- a GTK-based LDAP client Copyright (C) 1998-2003 Bert Vermeulen Copyright (C) 2002-2003 by Peter Stamfest and Bert Vermeulen This program is released under the Gnu General Public License with the additional exemption that compiling, linking, and/or using OpenSSL is allowed. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* $Id: dt_numstr.h,v 1.1 2003/10/21 04:46:41 stamfest Exp $ */ #ifndef DT_NUMSTR_H_INCLUDED #define DT_NUMSTR_H_INCLUDED #include "formfill.h" #include "syntax.h" #include "dt_entry.h" #include "i18n.h" typedef dt_entry_handler dt_numstr_handler; #define DT_NUMSTR(objpointer) ((dt_numstr_handler*)(objpointer)) display_type_handler *dt_numstr_get_handler(); /* Methods, only to be used by subclasses */ GtkWidget *dt_numstr_get_widget(struct formfill *form, GByteArray *data, GtkSignalFunc *activatefunc, gpointer funcdata); GByteArray *dt_numstr_get_data(struct formfill *form, GtkWidget *widget); void dt_numstr_set_data(struct formfill *form, GByteArray *data, GtkWidget *widget); GtkWidget *dt_numstr_retrieve_inputbox(GtkWidget *hbox); #endif /* Local Variables: c-basic-offset: 5 End: */ Index: Makefile.am =================================================================== RCS file: /cvsroot/gqclient/gq/src/Makefile.am,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** Makefile.am 17 Oct 2003 07:26:25 -0000 1.30 --- Makefile.am 21 Oct 2003 04:46:41 -0000 1.31 *************** *** 65,68 **** --- 65,70 ---- dt_crl.c \ dt_time.c \ + dt_int.c \ + dt_numstr.c \ ldapops.c \ tdefault.c \ *************** *** 113,116 **** --- 115,120 ---- dt_crl.h \ dt_time.h \ + dt_int.h \ + dt_numstr.h \ ldapops.h \ tdefault.h \ Index: formfill.h =================================================================== RCS file: /cvsroot/gqclient/gq/src/formfill.h,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** formfill.h 2 Oct 2003 16:16:26 -0000 1.26 --- formfill.h 21 Oct 2003 04:46:41 -0000 1.27 *************** *** 54,57 **** --- 54,59 ---- # define DISPLAYTYPE_TIME 10 + # define DISPLAYTYPE_INT 11 + # define DISPLAYTYPE_NUMSTR 12 #define FLAG_NOT_IN_SCHEMA 0x01 Index: syntax.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/syntax.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** syntax.c 12 Oct 2003 06:14:18 -0000 1.17 --- syntax.c 21 Oct 2003 04:46:41 -0000 1.18 *************** *** 54,57 **** --- 54,59 ---- #include "dt_crl.h" #include "dt_time.h" + #include "dt_int.h" + #include "dt_numstr.h" /* Syntaxes we recognize and may handle specially. This is a rather *************** *** 222,226 **** { "1.3.6.1.4.1.1466.115.121.1.27", "INTEGER", ! DISPLAYTYPE_ENTRY, NULL, 0, --- 224,228 ---- { "1.3.6.1.4.1.1466.115.121.1.27", "INTEGER", ! DISPLAYTYPE_INT, NULL, 0, *************** *** 276,280 **** { "1.3.6.1.4.1.1466.115.121.1.36", "Numeric String", ! DISPLAYTYPE_ENTRY, NULL, 0, --- 278,282 ---- { "1.3.6.1.4.1.1466.115.121.1.36", "Numeric String", ! DISPLAYTYPE_NUMSTR, NULL, 0, *************** *** 519,522 **** --- 521,526 ---- #endif add_syntax(DISPLAYTYPE_TIME, dt_time_get_handler()); + add_syntax(DISPLAYTYPE_INT, dt_int_get_handler()); + add_syntax(DISPLAYTYPE_NUMSTR, dt_numstr_get_handler()); } |