#include <fields.h>
Inheritance diagram for FIELD_DEF:

Public Methods | |
| FIELD_DEF (void) | |
| void | delval (CONFDB *c_data, const char *key) |
| int | edit (void) |
| void | loadval (CONFDB *c_data, const char *key) |
| void | saveval (CONFDB *c_data, const char *key) |
Public Attributes | |
| SSTRING | id |
| SSTRING | title |
| SSTRING | fdefault |
| int | type |
| int | minimum |
| int | maximum |
| int | order |
| char | must_fill |
| SSTRINGS | values |
| struct { | |
| SSTRING str | |
| int num | |
| char sel | |
| } | val |
| int | field_num |
|
|
Definition at line 25 of file fields.cc. 00026 {
00027 type = FLD_TYPE_STRING;
00028 minimum = 0;
00029 maximum = 8000000;
00030 must_fill = 0;
00031 val.sel = 0;
00032 val.num = 0;
00033 order = 100;
00034 }
|
|
|
Definition at line 162 of file fields.cc. 00163 {
00164 c_data->removeall (key,id.get());
00165 }
|
|
|
Definition at line 47 of file fields.cc. 00048 {
00049 int ret = -1;
00050 DIALOG dia;
00051 dia.newf_str (MSG_U(F_ID,"Field ID"),id);
00052 dia.last_noempty();
00053 dia.newf_str (MSG_U(F_TITLE,"Field title"),title);
00054 dia.last_noempty();
00055 dia.newf_num (MSG_U(F_ORDER,"Field order"),order);
00056 FIELD_ENUM *fenum = dia.newf_enum (MSG_U(F_TYPE,"Field type"),type);
00057 for (int i=0; i<8; i++) fenum->addopt(tbtype[i]);
00058 dia.newf_chk (MSG_U(F_STRINGF,"String field"),must_fill
00059 ,MSG_U(I_STRINGF,"must be filled"));
00060 dia.newf_num (MSG_U(F_MINIMUM,"Minimum value"),minimum);
00061 int field_maximum = dia.getnb();
00062 dia.newf_num (MSG_U(F_MAXIMUM,"Maximum value"),maximum);
00063 dia.newf_title ("",MSG_U(T_VALUES,"List values"));
00064 int field_value = dia.getnb();
00065 {
00066 // Make sure there are at least 4 empty value entries
00067 int nb_empty = 0;
00068 for (int i=0; i<values.getnb(); i++){
00069 if (values.getitem(i)->is_empty()) nb_empty++;
00070 }
00071 for (int i=nb_empty; i<4; i++) values.add (new SSTRING);
00072 for (int i=0; i<values.getnb(); i++){
00073 dia.newf_str ("",*values.getitem(i));
00074 }
00075 }
00076 int nof = 0;
00077 dia.delwhat (MSG_U(I_DELFIELD,"the field definition"));
00078 while (1){
00079 MENU_STATUS code = dia.edit (MSG_U(T_FIELD_DEF,"Field definition")
00080 ,MSG_U(I_FIELD_DEF,"You must describe one input field")
00081 ,help_field
00082 ,nof,MENUBUT_DEL|MENUBUT_CANCEL|MENUBUT_ACCEPT);
00083 if (code == MENU_CANCEL || code == MENU_ESCAPE){
00084 break;
00085 }else if (code == MENU_DEL){
00086 if (xconf_delok()){
00087 ret = 1;
00088 break;
00089 }
00090 }else if (minimum > maximum){
00091 xconf_error (MSG_U(E_RANGE,"Maximum must be greater than minimum"));
00092 nof = field_maximum;
00093 }else if (id.strchr(' ')!=NULL){
00094 xconf_error (MSG_U(E_NOSPACE,"No space allowed in ID"));
00095 nof = 0;
00096 }else{
00097 int nb_empty = 0;
00098 for (int i=0; i<values.getnb(); i++){
00099 if (values.getitem(i)->is_empty()) nb_empty++;
00100 }
00101 if (values.getnb() - nb_empty < 2
00102 && type == FLD_TYPE_LIST){
00103 xconf_error (MSG_U(E_2ITEMS
00104 ,"You must define minimally 2 values\n"
00105 "for an enumeration field"));
00106 nof = field_value;
00107 }else{
00108 values.remove_empty();
00109 ret = 0;
00110 break;
00111 }
00112 }
00113 }
00114 return ret;
00115 }
|
|
|
Definition at line 120 of file fields.cc. 00121 {
00122 /*
00123 Lower the case of the attribute name since confdb is case-sensitive
00124 and we already lowered the name in ldap_object.
00125 */
00126
00127 id.to_lower();
00128 const char *s = c_data->getval (key,id.get());
00129
00130 D(debugf(6,"FIELD_DEF::loadval key=%s id=%s title=%s val=%s\n",key,id.get(),title.get(),s));
00131
00132 if (s != NULL){
00133 if (type == FLD_TYPE_STRING || type == FLD_TYPE_COMBO || type == FLD_TYPE_LIST){
00134 val.str.setfrom (s);
00135 }else if (type == FLD_TYPE_BOOL){
00136 val.sel = atoi(s);
00137 }else if (type == FLD_TYPE_NUM || type == FLD_TYPE_ENUM){
00138 val.num = atoi(s);
00139 }
00140 }
00141 }
|
|
|
Definition at line 145 of file fields.cc. 00146 {
00147 const char *ptid = id.get();
00148 const int MAX_BUF=1000;
00149 char buf[MAX_BUF] = "";
00150 if (type == FLD_TYPE_STRING || type == FLD_TYPE_COMBO || type == FLD_TYPE_LIST){
00151 snprintf(buf,MAX_BUF-1,"%s",val.str.get());
00152 }else if (type == FLD_TYPE_BOOL){
00153 snprintf(buf,MAX_BUF-1,"%s",&val.sel);
00154 }else if (type == FLD_TYPE_NUM || type == FLD_TYPE_ENUM){
00155 snprintf(buf,MAX_BUF-1,"%i",val.num);
00156 }else // Other fields are not for data and should not be saved
00157 return;
00158 c_data->add(key,ptid,buf);
00159 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1.2.1 written by Dimitri van Heesch,
© 1997-2000