/* * Recursive function responsible to create fields, position them and setting * the modifiable fields. All of this from a service dictionary. * To keep the cursor from moving on signal, a string is affected to mark each * field. This is used by repos_cursor(). * @param longest_key_len The longest length for a label * @param pos The index in main_fields[] * @param jobj The service dictionary * @param is_obj_modifiable Use to set the whole object as modifiable (usefull * for IPv4.Configuration for example) * @param obj_str The string representing the "hash" of a surrounding object */ static void render_fields_from_jobj(int longest_key_len, int *pos, struct json_object *jobj, bool is_obj_modifiable, const char *obj_str) { bool is_autoconnect = false, is_modifiable = false; struct userptr_data *data; json_object_object_foreach(jobj, key, val) { main_fields[*pos] = render_label(longest_key_len, key); assert(main_fields[*pos] != NULL); (*pos)++; is_modifiable = string_ends_with_configuration(key); is_modifiable |= is_obj_modifiable; if (json_object_get_type(val) == json_type_object) { move_field(main_fields[(*pos)-1], ++cur_y, cur_x); cur_y++; render_fields_from_jobj(longest_key_len, pos, val, is_modifiable, key); is_modifiable = false; } else { // insert the page delimiter if (cur_y >= win_body_lines-4) { cur_y = 1; set_new_page(main_fields[(*pos)-1], TRUE); move_field(main_fields[(*pos)-1], cur_y, cur_x); nb_pages++; } main_fields[*pos] = render_field(longest_key_len, val); assert(main_fields[*pos] != NULL); is_autoconnect = strcmp(key, key_serv_autoconnect) == 0; if (is_modifiable || is_autoconnect) { field_opts_on(main_fields[*pos], O_EDIT); field_opts_off(main_fields[*pos], O_BLANK); set_field_back(main_fields[*pos], A_UNDERLINE); } else field_opts_off(main_fields[*pos], O_EDIT); // Specific operations on fields config_fields_type(*pos, is_autoconnect, obj_str, key); field_opts_on(main_fields[*pos], O_NULLOK); data = malloc(sizeof(struct userptr_data)); data->dbus_name = strdup(get_str_key()); data->pretty_name = NULL; set_field_userptr(main_fields[*pos], data); (*pos)++; } cur_y++; }
void getDateTime(char *startdatetime, char *enddatetime){ FIELD *field[5]; FORM *my_form; int ch; int contLoop=1; char *temp = (char*)malloc(50*sizeof(char)); char *month = (char*)malloc(3*sizeof(char)); char *day = (char*)malloc(3*sizeof(char)); char *year = (char*)malloc(5*sizeof(char)); char *hr = (char*)malloc(3*sizeof(char)); char *min = (char*)malloc(3*sizeof(char)); startdatetime = (char *)malloc(13*sizeof(char)); enddatetime = (char *)malloc(13*sizeof(char)); /* Initialize the fields */ field[0] = new_field(1, 2, 6, 5, 0, 0); field[1] = new_field(1, 2, 6, 8, 0, 0); field[2] = new_field(1, 4, 6, 11, 0, 0); field[3] = new_field(1, 2, 6, 26, 0, 0); field[4] = new_field(1, 2, 6, 29, 0, 0); /* Set field options */ set_field_back(field[0], A_UNDERLINE); field_opts_off(field[0], O_NULLOK+O_BLANK); set_field_type(field[0], TYPE_INTEGER,2,1,12); set_field_back(field[1], A_UNDERLINE); field_opts_off(field[1], O_NULLOK+O_BLANK); set_field_type(field[1], TYPE_INTEGER,2,1,31); set_field_back(field[2], A_UNDERLINE); field_opts_off(field[2], O_NULLOK+O_BLANK); set_field_type(field[2], TYPE_INTEGER,4,0,9999); set_field_back(field[3], A_UNDERLINE); field_opts_off(field[3], O_NULLOK+O_BLANK); set_field_type(field[3], TYPE_INTEGER,2,0,23); set_field_back(field[4], A_UNDERLINE); field_opts_off(field[4], O_NULLOK+O_BLANK); set_field_type(field[4], TYPE_INTEGER,2,0,59); /* Create the form and post it */ my_form = new_form(field); post_form(my_form); mvprintw(0,0,"iCal Generator\nWritten by Derek Redfern"); mvprintw(3,1,"Use arrow keys to navigate; press Enter to proceed\n"); mvprintw(5,5,"Start date:"); mvprintw(5,26,"Start time:"); mvprintw(6,7,"/"); mvprintw(6,10,"/"); mvprintw(6,28,":"); refresh(); //getch(); form_driver(my_form, REQ_FIRST_FIELD); get_input(my_form,field); strcpy(month,field_buffer(field[0],0)); strcpy(day,field_buffer(field[1],0)); strcpy(year,field_buffer(field[2],0)); strcpy(hr,field_buffer(field[3],0)); strcpy(min,field_buffer(field[4],0)); strcpy(startdatetime,year); strcat(startdatetime,month); strcat(startdatetime,day); strcat(startdatetime,"T"); strcat(startdatetime,hr); strcat(startdatetime,min); int i; for(i=0;i<5;i++){ set_field_buffer(field[i],0,""); } refresh(); unpost_form(my_form); free_form(my_form); move_field(field[0],9,5); move_field(field[1],9,8); move_field(field[2],9,11); move_field(field[3],9,26); move_field(field[4],9,29); my_form=new_form(field); post_form(my_form); refresh(); mvprintw(0,0,"iCal Generator\nWritten by Derek Redfern"); mvprintw(3,1,"Use arrow keys to navigate; press Enter to proceed\n"); mvprintw(5,5,"Start date:"); mvprintw(5,26,"Start time:"); mvprintw(6,5,"%s/%s/%s",month,day,year); mvprintw(6,26,"%s:%s",hr,min); mvprintw(8,5,"End date:"); mvprintw(8,26,"End time:"); mvprintw(9,7,"/"); mvprintw(9,10,"/"); mvprintw(9,28,":"); form_driver(my_form, REQ_FIRST_FIELD); get_input(my_form,field); strcpy(enddatetime,field_buffer(field[2],0)); strcat(enddatetime,field_buffer(field[0],0)); strcat(enddatetime,field_buffer(field[1],0)); strcat(enddatetime,"T"); strcat(enddatetime,field_buffer(field[3],0)); strcat(enddatetime,field_buffer(field[4],0)); unpost_form(my_form); free_form(my_form); free_field(field[0]); free_field(field[1]); free_field(field[2]); free_field(field[3]); free_field(field[4]); }