/*! * \fn void newGameConfig() * Add a new game configuration */ void newGameConfig() { game_config config; char home_path[SIZE_MAX_FILE_NAME]=""; clearScreen(); menuFileName(config.name); menuGameConfig(&config); #ifndef PORTABLE readHomePathSlash(home_path); #endif // PORTABLE if (newConfigFile(config,home_path) == false); systemPause(); }
/*! * \fn G_MODULE_EXPORT void endAssistantNewCsu(GtkWidget *widget, gpointer data) * End the assistant for a new csu file * \param[in] widget the widget which send the signal * \param[in] data the globalData */ G_MODULE_EXPORT void endAssistantNewCsu(GtkWidget *widget, gpointer data) { globalData *user_data = (globalData*) data; gchar name[SIZE_MAX_FILE_NAME]; gchar *folder; /* Read the game configuration list */ char home_path[SIZE_MAX_FILE_NAME]=""; #ifndef PORTABLE readHomePathSlash(home_path); #endif // PORTABLE /* Get the filename */ GtkWidget *grid = getWidgetFromBuilder(user_data->ptr_builder,"grid_new_csu_file_assistant_1"); folder = g_locale_from_utf8(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(gtk_grid_get_child_at(GTK_GRID(grid),1,1))),-1,NULL,NULL,NULL); strncpy(name,g_locale_from_utf8(gtk_entry_get_text(GTK_ENTRY(gtk_grid_get_child_at(GTK_GRID(grid),1,0))),-1,NULL,NULL,NULL),SIZE_MAX_NAME-1); sprintf(user_data->csu_filename,"%s/%s",folder,name); addFileCsuExtension(user_data->csu_filename); /* Save the game configuration if ask */ if (user_data->save_new_game_config) newConfigFile(user_data->config,home_path); /* Update the information of the global data */ if (user_data->ptr_csu_struct != NULL) closeCsuStruct(user_data->ptr_csu_struct); user_data->ptr_csu_struct = user_data->ptr_csu_struct_tmp; user_data->ptr_csu_struct_tmp = NULL; updateMainWindow(user_data,!exceedMaxNumber(user_data->ptr_csu_struct)); if (writeCsuFile(user_data->csu_filename,user_data->ptr_csu_struct) == false) saveFileError(user_data); deleteAllLastCsuStruct(user_data); addLastCsuStruct(user_data); deleteAssistantNewCsu(NULL,user_data); setButtonMainWindow(user_data); fillCalculatorNames(user_data); g_free(folder); }
void ConfigCreator::genarateButtonClicked() { configFileName=ui->lEConfigFileName->text(); templateName=ui->lETemplateName->text(); templateClass=ui->lETemplateClass->text(); templatetag=ui->lETemplateTag->text(); QFile newConfigFile(configFileSavePath+"/"+configFileName); if(!newConfigFile.open(QFile::ReadWrite| QIODevice::Text)) { qDebug()<<"error"; } else { QDomDocument document; document.setContent(&newConfigFile); QDomElement root= document.createElement("Template"); root.setAttribute("name",templateName); root.setAttribute("class",templateClass); root.setAttribute("format","1"); QDomElement tag= document.createElement("Tag"); tag.appendChild(document.createTextNode(templatetag)); QDomElement templateGroup= document.createElement("TemplateGroup"); templateGroup.appendChild(document.createTextNode(templateClass)); QDomElement connection= document.createElement("Connection"); QDomElement expression= document.createElement("Expression"); QDomElement transportOnlyUsedCols= document.createElement("TransportOnlyUsedCols"); transportOnlyUsedCols.appendChild(document.createTextNode("false")); QDomElement priorityObj= document.createElement("PriorityObj"); priorityObj.appendChild(document.createTextNode("false")); QDomElement defaultSortOrder= document.createElement("DefaultSortOrder"); QDomElement columns= document.createElement("Columns"); QFile file(csvFilePath); file.open(QIODevice::ReadOnly | QIODevice::Text); QTextStream in(&file); in.setCodec("UTF-8"); // change the file codec to UTF-8. int x=0; while(!in.atEnd()) { QString line = in.readLine(); if(x==3) { QStringList splitedList=line.split(","); for(int y=0;y<splitedList.size();y++) { if(splitedList.at(y)=="Field Name") fieldNamePosition=y; if(splitedList.at(y)=="Data Type") dataTypePosition=y; } } if(x>4) { QDomElement column= document.createElement("Column"); if(line.length()>0) { QStringList splitedColumnData=line.split(","); column.setAttribute("name",splitedColumnData.at(fieldNamePosition)); column.setAttribute("dataType",splitedColumnData.at(dataTypePosition)); column.setAttribute("description",""); column.setAttribute("alwaysTx","false"); column.setAttribute("unicode","false"); column.setAttribute("translate","false"); column.setAttribute("enum",""); columns.appendChild(column); } } x++; } root.appendChild(tag); root.appendChild(templateGroup); root.appendChild(connection); root.appendChild(expression); root.appendChild(transportOnlyUsedCols); root.appendChild(priorityObj); root.appendChild(columns); root.appendChild(defaultSortOrder); document.appendChild(root); QTextStream stream(&newConfigFile); stream <<document.toString(); newConfigFile.close(); } }