void Options::Flush() const { json::Object obj_out; for (auto const& ov : values) { switch (ov.second->GetType()) { case OptionValue::Type_String: put_option(obj_out, ov.first, ov.second->GetString()); break; case OptionValue::Type_Int: put_option(obj_out, ov.first, ov.second->GetInt()); break; case OptionValue::Type_Double: put_option(obj_out, ov.first, ov.second->GetDouble()); break; case OptionValue::Type_Color: put_option(obj_out, ov.first, ov.second->GetColor().GetRgbFormatted()); break; case OptionValue::Type_Bool: put_option(obj_out, ov.first, ov.second->GetBool()); break; case OptionValue::Type_List_String: put_array(obj_out, ov.first, "string", ov.second->GetListString()); break; case OptionValue::Type_List_Int: put_array(obj_out, ov.first, "int", ov.second->GetListInt()); break; case OptionValue::Type_List_Double: put_array(obj_out, ov.first, "double", ov.second->GetListDouble()); break; case OptionValue::Type_List_Color: put_array(obj_out, ov.first, "color", ov.second->GetListColor()); break; case OptionValue::Type_List_Bool: put_array(obj_out, ov.first, "bool", ov.second->GetListBool()); break; } } json::Writer::Write(obj_out, io::Save(config_file).Get()); }
int put_all_options(WINDOW *win, node_t *list, node_t *current) { int i; int attr; data_t *d; node_t *node; i = 0; node = list; while(node != NULL) { d = ((data_t *)(node->data)); if(d->hidden == BOOL_TRUE) { node = node->next; continue; } if(node == current) { attr = A_REVERSE; } else { attr = 0; } put_option(win, i, d->text, attr); node = node->next; i++; } return 0; }
void check_integrated_interface (option_file_type *options) { gchar *buf; // The INTEGRATED option cannot be executed in process_options, // because it shouldn't be reinitialized when geomorphrc // is modified without restarting the application if ((buf = get_option(options,"interface","interface_style"))){ if (!strcmp(buf,"Integrated")) INTEGRATED_INTERFACE = TRUE; else INTEGRATED_INTERFACE = FALSE; } else { INTEGRATED_INTERFACE = DEF_INTEGRATED_INTERFACE; if (INTEGRATED_INTERFACE) put_option (options, "interface","interface_style","Integrated"); else put_option (options,"interface","interface_style","Gimp style"); } // Menu mandatory with integrated interface if ((buf = get_option(options,"interface","menu_in_doc_window"))){ if (!strcmp(buf,"TRUE")) MENU_IN_DOC_WINDOW = TRUE; else MENU_IN_DOC_WINDOW = INTEGRATED_INTERFACE; } else { MENU_IN_DOC_WINDOW = INTEGRATED_INTERFACE; if (MENU_IN_DOC_WINDOW) put_option (options,"interface","menu_in_doc_window","TRUE"); else put_option (options,"interface","menu_in_doc_window","FALSE"); } // When the ICONS in the main menu option is not specified, // it defaults to TRUE for the integrated interface if ((buf = get_option(options,"interface","icons_in_doc_window"))){ if (!strcmp(buf,"TRUE")) ICONS_IN_DOC_WINDOW = TRUE; else ICONS_IN_DOC_WINDOW = INTEGRATED_INTERFACE; } else { ICONS_IN_DOC_WINDOW = INTEGRATED_INTERFACE; if (ICONS_IN_DOC_WINDOW) put_option (options,"interface", "icons_in_doc_window", "TRUE"); else put_option (options,"interface", "icons_in_doc_window", "FALSE"); } }
void process_options(option_file_type *options) { // Process some generic defaults from the RC file // DEFAULT_PAD, MAXIMUM_HISTORY... are #defined in globals.h // DEF_PAD, MAX_HISTORY are declared "extern" in globals.h as well gchar *buf, *current_dir, *home; gboolean invalid; DEF_PAD = DEFAULT_PAD; if ( (buf = get_option(options,"interface","pad"))) { if (is_integer(buf)) { DEF_PAD = (gint) atol(buf); invalid = FALSE; } else invalid = TRUE; } if ((!buf) || invalid) { buf = (gchar *) x_malloc(5, "gchar (buf - interface:pad)"); sprintf(buf,"%-4d", DEF_PAD); put_option(options,"interface","pad",buf); } if ((buf = get_option(options,"files","def_dir")) && strlen(buf)) DEF_DIR = buf; else if (!DEF_DIR) { // DEF_DIR is supposed to be initialized by main.c // If not, it defaults to $HOME DEF_DIR = getenv("HOME"); put_option(options,"files","def_dir",DEF_DIR); } // DEF_DIR should have a full path. // If not (like in Geomorph version prior to 0.50), // we try to build it if (DEF_DIR[0] != FILESEP) { // First try to test for a subdirectory // in the current one, then in the home directory current_dir = (gchar *) get_current_dir_name(); // current_dir has no FILESEP at the end buf = (gchar *) x_malloc(strlen(current_dir)+2+strlen(DEF_DIR), "gchar (buf - DEF_DIR)"); sprintf(buf,"%s%c%s",current_dir,FILESEP,DEF_DIR); // printf("CURRENT_DIR: %s; BUF: %s\n",current_dir,buf); if (directory_exists(buf)) DEF_DIR = buf; else { // We try with the home directory x_free(buf); home = getenv("HOME"); buf = (gchar *) x_malloc(strlen(home)+2+strlen(DEF_DIR), "gchar (buf - DEF_DIR)"); sprintf(buf,"%s%c%s", home, FILESEP, DEF_DIR); if (directory_exists(buf)) DEF_DIR = buf; else { DEF_DIR = home; x_free(buf); } // printf("DEF_DIR après BUF: %s\n",DEF_DIR); } } MAX_HISTORY = MAXIMUM_HISTORY; if ((buf = get_option(options,"application","max_history"))) { if (is_integer(buf)) { MAX_HISTORY = atoi(buf); invalid = FALSE; } else invalid = TRUE; } if ((!buf) || invalid) { buf = (gchar *) x_malloc(5, "gchar (buf - put_option)"); sprintf(buf,"%-4d",MAX_HISTORY); put_option(options,"application","max_history",buf); } DEFAULT_SEED = rand(); if ((buf = get_option(options,"application","default_seed"))) { // On some systems, is_integer does not recognizes Hex numbers (0x01b5...) // if (is_integer(buf)) DEFAULT_SEED = (guint) strtoul(buf,NULL,0); } CREATION_X = CREATION_WINDOW_X; if ((buf = get_option(options,"interface","creation_window_x"))) { if (is_integer(buf)) CREATION_X = atol(buf); } CREATION_Y = CREATION_WINDOW_Y; if ((buf = get_option(options,"interface","creation_window_y"))) { if (is_integer(buf)) CREATION_Y = atol(buf); } TOOLS_X = TOOLS_WINDOW_X; if ((buf = get_option(options,"interface","tools_window_x"))) { if (is_integer(buf)) TOOLS_X = atol(buf); } TOOLS_Y = TOOLS_WINDOW_Y; if ((buf = get_option(options,"interface","tools_window_y"))) { if (is_integer(buf)) TOOLS_Y = atol(buf); } MAIN_BAR_X = MAIN_MENU_BAR_X; if ((buf = get_option(options,"interface","main_bar_x"))) { if (is_integer(buf)) MAIN_BAR_X = atol(buf); } MAIN_BAR_Y = MAIN_MENU_BAR_Y; if ((buf = get_option(options,"interface","main_bar_y"))) { if (is_integer(buf)) MAIN_BAR_Y = atol(buf); } DISPLAY_DOC_OFFSET = DEFAULT_DOC_OFFSET; if ((buf = get_option(options,"interface","display_doc_offset"))) { if (is_integer(buf)) DISPLAY_DOC_OFFSET = atol(buf); } if ((buf = get_option(options,"files","doc_dir")) && strlen(buf)) DOC_DIR = buf; else { DOC_DIR = DOCUMENT_DIR; put_option(options,"files","doc_dir",DOC_DIR); } if ((buf = get_option(options,"files","doc_reader")) && strlen(buf)) DOC_READER = buf; else { DOC_READER = DEFAULT_DOC_READER; put_option(options,"files","doc_reader",DOC_READER); } }
int menu(WINDOW *win, int line, int col, node_t *list, int keyc, menukey_t *keyv) { int c; int k; int quit; char txt[256]; node_t *current; node_t *last; data_t *d; int current_line; int last_line; int size; current = list; last = current; current_line = 0; last_line = current_line; redraw_screen = BOOL_TRUE; quit = BOOL_FALSE; while(quit != BOOL_TRUE) { if(current == NULL && current->data == NULL) { current = list; } d = (data_t *)(current->data); if(redraw_screen == BOOL_TRUE) { wclear(win); snprintf(txt, sizeof(txt), "%s: %s", g_programName, g_programVersion); put_header(txt, ALIGN_LEFT); if(d->hidden == BOOL_TRUE) { current = list; current_line = 0; d = (data_t *)(current->data); } put_all_options(win, list, current); redraw_screen = BOOL_FALSE; if(d->ops != NULL && d->ops->op_highlight != NULL) { quit = d->ops->op_highlight(win, current, list); } } else if (last != current || redraw_options) { put_option(win, last_line, ((data_t *)(last->data))->text, 0); put_option(win, current_line, d->text, A_REVERSE); redraw_options = BOOL_FALSE; if(((data_t *)(last->data))->ops != NULL && ((data_t *)(last->data))->ops->op_unhighlight != NULL) { quit = ((data_t *)(last->data))->ops->op_unhighlight(win, current, list); } if(d->ops != NULL && d->ops->op_highlight != NULL) { quit = d->ops->op_highlight(win, current, list); } } last = current; last_line = current_line; wrefresh(stdscr); wrefresh(infowin); size = (LINES - 2) - INFO_SIZE; prefresh(win, current_line - (size - 1), 0, line, col, size, COLS - 1); if(quit == BOOL_TRUE) continue; c=wgetch(win); switch(c) { case '?': case KEY_F(1): /* online help */ put_helpscreen(keyc, keyv); redraw_screen = BOOL_TRUE; break; case KEY_UP: case 'k': /* go to previous option */ { data_t *d; node_t *n = current->prev; while(n != NULL) { d = ((data_t *)(n->data)); if(d == NULL) { n = n->prev; continue; } if(d->hidden == BOOL_FALSE) { break; } n = n->prev; } if(n != NULL) { current = n; current_line--; } } break; case KEY_DOWN: case 'j': /* go to next option */ { data_t *d; node_t *n = current->next; while(n != NULL) { d = ((data_t *)(n->data)); if(d == NULL) { n = n->next; continue; } if(d->hidden == BOOL_FALSE) { break; } n = n->next; } if(n != NULL) { current = n; current_line++; } } break; case KEY_RIGHT: case 'l': /* go to next child */ { node_t *n = current->next; int l; if(current != NULL && ((data_t *)(current->data)) == NULL) { break; } l = ((data_t *)(current->data))->level; if(n != NULL && ((data_t *)(n->data)) != NULL && ((data_t *)(n->data))->level > l) { if(((data_t *)(n->data))->hidden == BOOL_TRUE) { menu_expand(win, current, list); } current = n; current_line++; } } break; case KEY_LEFT: case 'h': /* go to parent */ { data_t *d; node_t *n = current->prev; int l = 0; int i; if(current != NULL && ((data_t *)(current->data)) != NULL) { l = ((data_t *)(current->data))->level; } i = current_line - 1; while(n != NULL) { d = ((data_t *)(n->data)); if(d == NULL) { n = n->prev; continue; } if(d->hidden == BOOL_TRUE) { n = n->prev; continue; } if(d->level < l) { break; } n = n->prev; i--; } if(n != NULL) { current = n; current_line = i;; } } break; case ERR: if(errno == EINTR) { /* mainmenu window has been recreated - use new one */ win = mainmenu; } break; default: for(k = 0; k < keyc; k++) { if(c == keyv[k].key || tolower(c) == keyv[k].key) { if (keyv[k].fn != NULL) { quit = keyv[k].fn(win, current, list); break; } else { put_footer("internal error: can't execute function", ALIGN_CENTRE); break; } } } break; } } return 0; }