void Controller::parseSpecFile(std::string file) { std::string expandedFilename; if(file[0] == '~') { file.erase(0,1); expandedFilename = std::string(getenv("HOME")); expandedFilename += file; } else { expandedFilename = file; } std::ifstream specFile(expandedFilename.c_str()); if(!specFile.fail()) { YAML::Parser specParser(specFile); YAML::Node specDoc; specParser.GetNextDocument(specDoc); for(int i=0; i<specDoc["commands"].size(); i++) { if(specDoc["commands"][i]["command"].GetType() == YAML::CT_SCALAR && specDoc["commands"][i]["source"].GetType() == YAML::CT_SEQUENCE) { std::string command; specDoc["commands"][i]["command"] >> command; // lets check whether this command is for us for(int s=0; s<specDoc["commands"][i]["source"].size(); s++) { std::string source; specDoc["commands"][i]["source"][s] >> source; if(source == "controller") { CommandParser *parser = new CommandParser(specDoc["commands"][i]); commands->insert(std::make_pair(command, parser)); if(parser->getCommand().length() > maxCommandNameLength) { maxCommandNameLength = parser->getCommand().length(); } } } } }
void RxDev::openSpecFile(){ const QModelIndex index = ui->treeView_availableNodes->selectionModel()->currentIndex(); QModelIndex seekRoot = index; while(seekRoot.parent() != QModelIndex()) { seekRoot = seekRoot.parent(); } QString filePath = seekRoot.child(0,0).child(0,0).data(Qt::DisplayRole).toString(); //qDebug()<<filePath; SpecFileParser *specParser = new SpecFileParser; specParser->nodeParser(filePath); SpecFileEdit specFile(&specParser->node); //qDebug()<<QString::fromStdString(specParser->node.type); specFile.setWindowTitle("Specfile: "+seekRoot.data(Qt::DisplayRole).toString()); bool accept = specFile.exec(); if ((accept)){ QFile file; file.setFileName(filePath); file.open(QIODevice::WriteOnly | QIODevice::Text); if (file.isWritable()){ QString tempContens = specParser->writeSpecFile(&specParser->node); QTextStream text(&file); text<<tempContens; //qDebug()<<"subs "<<specFile.getSubscriptions(); file.close(); QMessageBox::information( this, "File written!", "The file "+filePath+" was updated\n", QMessageBox::Ok, 0 ); on_pushButton_refreshNodesOrComps_clicked(); } else QMessageBox::critical(this, "File is write protected!", "The file "+filePath+" could not get updated\n", QMessageBox::Ok, 0 ); // setType(nodeEdit.getType()); // setName(nodeEdit.getName()); // setArgs(nodeEdit.getArgs()); } // QDesktopServices::openUrl(QUrl::fromLocalFile( filePath)); }