void MainWindow::readDefinitions( QString filename ) { ui->statusBar->showMessage( QString("Loading ADIF definitions from \"%1\"").arg(filename) ); QFile *file = new QFile(filename); if( !file->open(QFile::ReadOnly) ) { qDebug() << "Open Definition file failed." << endl; }else{ qDebug() << "Open Definition file success." << endl; } QXmlSimpleReader xmlReader; QXmlInputSource *source = new QXmlInputSource( file ); AdifHandler *handler = new AdifHandler(); xmlReader.setContentHandler(handler); xmlReader.setErrorHandler(handler); bool ok = xmlReader.parse(source); if( !ok ) { qDebug() << "Parsing Definition file failed." << endl; } ui->statusBar->showMessage( QString("Loading Country definitions from \"%1\"").arg("DXCCcountries.xml") ); modes = new QStringList( handler->mode ); country = new QStringList( ); subdivisions = new QStringList( ); bands = QHash <QString, Range>( handler->band ); //qDebug() << bands["160m"].lower; }
bool FrmReports::parseXMLFile(const QString itemName, QString& strName, QString& strAuthor, QString& strPixmap, QString& strDescription) { QString strFileName(qApp->translate("dir", strReportsDir) + tr("\\") + itemName + tr(".bdrt")); QFile file(strFileName); if (!file.exists()) return false; if (!file.open(QFile::ReadOnly | QFile::Text)) return false; //Just try to parse the xml QXmlSimpleReader xmlReader; QXmlInputSource *source = new QXmlInputSource(&file); if (!xmlReader.parse(source)) { file.close(); //exit, but close the file first! return false; } delete source; file.close(); //Initialize the reader if (!file.open(QFile::ReadOnly | QFile::Text)) return false; QXmlStreamReader xml(&file); if (!readProperties(xml, strName, strAuthor, strPixmap, strDescription)) return false; file.close(); return true; }
void Model::loadWorld( const QString& fileName, bool verbose ) { //printf("Loading world file...\n"); WorldHandler handler( this ); QXmlSimpleReader reader; reader.setContentHandler(&handler); reader.setErrorHandler(&handler); QFile file(fileName); if ( !file.open(QFile::ReadOnly | QFile::Text) ) { QString errStr = "failed to open file '"; errStr.append(fileName); errStr.append("'"); throw KinematicModelException(errStr); } QXmlInputSource xmlInputSource( &file ); if ( !reader.parse( xmlInputSource ) ) { QString errStr = "failed to create world from file '"; errStr.append(fileName); errStr.append("'"); throw KinematicModelException(errStr); } //printf("success!\n"); }
QSharedPointer<HighlightDefinition> Manager::definition(const QString &id) { if (!id.isEmpty() && !m_definitions.contains(id)) { QFile definitionFile(id); if (!definitionFile.open(QIODevice::ReadOnly | QIODevice::Text)) return QSharedPointer<HighlightDefinition>(); QSharedPointer<HighlightDefinition> definition(new HighlightDefinition); HighlightDefinitionHandler handler(definition); QXmlInputSource source(&definitionFile); QXmlSimpleReader reader; reader.setContentHandler(&handler); m_isBuildingDefinition.insert(id); try { reader.parse(source); } catch (const HighlighterException &e) { MessageManager::write( QCoreApplication::translate("GenericHighlighter", "Generic highlighter error: ") + e.message(), MessageManager::WithFocus); definition.clear(); } m_isBuildingDefinition.remove(id); definitionFile.close(); m_definitions.insert(id, definition); } return m_definitions.value(id); }
void SvgCanvas::load_file(QString svg_file_name) { statusBar()->clearMessage(); svg_plot->load(svg_file_name); QSvgRenderer *renderer=svg_plot->renderer(); if(! renderer->isValid () ) { QFile file(svg_file_name); QXmlSimpleReader parser; QXmlInputSource source(&file); XmlCheckHandler handler(statusBar(), svg_file_name); file.open(QIODevice::ReadOnly); parser.setContentHandler(&handler); parser.setErrorHandler(&handler); parser.parse(&source); file.close(); } }
void TrainingsTageBuch::writeFileCompleted() { printd("TrainingStageBuch::writeFileCompleted()\n"); QNetworkReply *reply = static_cast<QNetworkReply*>(QObject::sender()); printd("reply:%s\n", reply->readAll().toStdString().c_str()); TTBUploadParser handler; QXmlInputSource source(reply); QXmlSimpleReader reader; reader.setContentHandler(&handler); bool success = true; if(! reader.parse(source)) { success = false; } if(success && handler.error.length() > 0){ success = false; } if(success && handler.id.length() == 0 ){ success = false; } if (success && reply->error() == QNetworkReply::NoError) { notifyWriteComplete(replyName(static_cast<QNetworkReply*>(QObject::sender())), tr("Completed.")); } else { notifyWriteComplete( replyName(static_cast<QNetworkReply*>(QObject::sender())), tr("Error - Upload failed.")); } }
bool Filters::load(const QString& filename) { // clear existing clear(); // load filters m_file = filename; // create XML content handler LoadXmlContentHandler handler(*this, m_types); // create a file object on the file QFile xmlFile(filename); // create an XmlInputSource on the file QXmlInputSource source(&xmlFile); // create an XML parser QXmlSimpleReader reader; // set the content handler reader.setContentHandler(&handler); // parse the file return reader.parse(source); }
void RemoteController::processReadData(const QByteArray &data) { QXmlSimpleReader reader; RemoteController::XmlHandler *xmlHandler = new RemoteController::XmlHandler(); reader.setContentHandler(xmlHandler); QXmlInputSource buffer; buffer.setData(data); reader.parse(&buffer); isStarted = xmlHandler->my_started; isGameOver = xmlHandler->my_gameover; if (isStarted == 1) { myLeftBtn->setEnabled(true); myRightBtn->setEnabled(true); myStartBtn->setEnabled(false); } if (isGameOver == 1) { myLeftBtn->setEnabled(false); myRightBtn->setEnabled(false); --myLostBalls; if (myLostBalls > 0) { myLostBallsLbl->setText(QString::number(myLostBalls)); myStartBtn->setEnabled(true); } else { myLostBallsLbl->setText("The game is over :("); myStartBtn->setEnabled(false); } } }
void cbSimulator::setDefaultGrid(void) { QXmlInputSource *source; source = new QXmlInputSource; source->setData(QByteArray(GRID)); QXmlSimpleReader xmlParser; cbGridHandler *gridHandler = new cbGridHandler; xmlParser.setContentHandler(gridHandler); cbGrid *grid; if(xmlParser.parse(*source)) grid = gridHandler->parsedGrid(); else { cerr << "Error parsing DEFAULT grid\n"; gui->appendMessage(QString("Error parsing DEFAULT grid"), true); assert(0); } setGrid(grid); delete gridHandler; delete source; //rebuild graph if(lab!=0) { buildGraph(); setDistMaxFromGridToTarget(); } // update parameters //param->gridFilename = ""; }
bool ZkbConfig::load(const QString& file, Keymap& keymap, const QString& prefix) { bool ret; QFile *f = new QFile(path+"/"+file); QFileInfo fi(*f); /* Try */ if ( !fi.exists() && !path.contains( QPEApplication::qpeDir()) ) { delete f; f = new QFile( QPEApplication::qpeDir() + "share/zkb/" + file ); fi = QFileInfo( *f ); } odebug << "start loading file=" << file << "\n" << oendl; if (includedFiles.find(fi.absFilePath()) != includedFiles.end()) { return false; } includedFiles.insert(fi.absFilePath(), 1); QXmlInputSource is(*f); QXmlSimpleReader reader; ZkbHandler h(*this, keymap, prefix); reader.setContentHandler(&h); reader.setErrorHandler(this); ret = reader.parse(is); includedFiles.remove(fi.absFilePath()); odebug << "end loading file=" << file << ": status=" << err << oendl; delete f; return ret; }
void FRXMLCharDataReader::parseSingleImageFile(const std::string fileName, const std::string resultFileName, GrayImage<> *pImage, std::vector<ImageChar> &imageCharVec, const int imageId /*= 0*/) const { // create the finereader xml output handler object need for parsing the files FineReaderXMLOutputHandler *pXMLHandler = new FineReaderXMLOutputHandler(); // create simple reader and set the content/error handler QXmlSimpleReader reader; reader.setContentHandler(pXMLHandler); reader.setErrorHandler(pXMLHandler); // create QFile object QFile file( QString::fromStdString(resultFileName) ); if (!file.open(QFile::ReadOnly | QFile::Text)) { throw Exception("Error openening xml-file in FRXMLCharDataReader::parseXMLFiles!"); } // create xml input source from file object QXmlInputSource xmlInputSource(&file); // parse the file using the simple reader reader.parse(xmlInputSource); std::cout << "Successfully parsed xml data of file " << resultFileName << std::endl; // store results SimpleFineReaderXMLData* pData = pXMLHandler->getFineReaderData(); // imageCharVec.clear(); for (int j=0; j<pData->parsedBBoxes.size(); ++j) { ImageChar imChar(pData->parsedBBoxes[j], pImage, imageId, imageCharVec.size()); imChar.text = pData->parsedChars[j]; imChar.suspicious = pData->isSuspicious[j]; imageCharVec.push_back(imChar); } // end for j pXMLHandler->clearData(); delete pXMLHandler; return; } // end parseSingleImageFile
void BDHServerController::loadConfiguration() { QFile file; //! Set XML dir file.setFileName(QString("./hmi.xml")); //! Open file if (!file.open(QFile::ReadOnly | QFile::Text)) { qDebug() << "Not hmi.xml file present and can't configure. \n CLOSING..."; exit(-1); } //! Set XML reader QXmlSimpleReader reader; reader.setContentHandler(m_configurationLoader); reader.setErrorHandler(m_configurationLoader); QXmlInputSource xmlInputSource(&file); //! Parse hmi.xml file for proyect configuration if (!reader.parse(xmlInputSource)) { //!Show error parsing hmi.xml qDebug() << QString("There was an error while loading the configuration: %1. \n CLOSING...").arg(m_configurationLoader->errorString()); exit(-1); } }
bool KDReports::Report::loadFromXML( QIODevice* iodevice, ErrorDetails* details ) { QDomDocument doc; // Read document from the QIODevice, check for errors // We need to be able to see the space in <text> </text>, this is why // we activate the "report-whitespace-only-CharData" feature. // Unfortunately this leads to lots of whitespace text nodes in between real // elements in the rest of the document, watch out for that. if (iodevice->isOpen()) iodevice->reset(); //need to do that to allow consecutive calls of loadFromXML() QXmlInputSource source( iodevice ); QXmlSimpleReader reader; reader.setFeature( QLatin1String( "http://xml.org/sax/features/namespaces" ), false ); reader.setFeature( QLatin1String( "http://xml.org/sax/features/namespace-prefixes" ), true ); reader.setFeature( QLatin1String( "http://trolltech.com/xml/features/report-whitespace-only-CharData" ), true ); QString errorMsg; int errorLine = 0, errorColumn = 0; bool ret = doc.setContent( &source, &reader, &errorMsg, &errorLine, &errorColumn ); if( !ret ) { if ( details ) { details->setLine( errorLine ); details->setColumn( errorColumn ); details->setDriverMessage( errorMsg ); } else qWarning( "Malformed XML read in KDReports::Report::loadFromXML(): error message = %s, error line = %d, error column = %d", qPrintable( errorMsg ), errorLine, errorColumn ); return false; } return loadFromXML( doc, details ); }
Scenegraph* ObjectXMLReader::readObjectXMLFile(string filename, GLint objectColorLocation, GLint modelviewLocation, glm::mat4& modelview) { //Create a file handler and tell it were the color and modelview ObjectXMLFileHandler handler; handler.setObjectColorLocation(objectColorLocation); handler.setModelviewLocation(modelviewLocation); //pass the modelview matrix to the handler (the camera position) handler.setModelview(modelview); //create a simple reader QXmlSimpleReader reader; //create a Qfile QFile xmlFile(QString::fromStdString(filename)); //specify the source QXmlInputSource source(&xmlFile); //declare a new scenegraph Scenegraph* scene; //set the content handler reader.setContentHandler(&handler); //parse bool answer = reader.parse(source); //if successful, set the scene if (answer) { scene = handler.getScene(); } //otherwise, print an error else printf("Parsing unsuccessful because %s\n",handler.errorString().toLatin1().constData()); return scene; }
const QString PatternParser::parseSimplePattern(const QString& pattern, int cdno, const int nooftracks, const QString& artist, const QString& title, const QString& date, const QString& genre, const QString& suffix, bool fat32compatible) { SaxHandler handler; handler.setCDNo(cdno); handler.setNoOfTracks(nooftracks); handler.setArtist(artist); handler.setTitle(title); handler.setDate(date); handler.setGenre(genre); handler.setSuffix(suffix); handler.setFAT32Compatible(fat32compatible); handler.setReplaceSpacesWithUnderscores(false); handler.set2DigitsTrackNum(false); QXmlInputSource inputSource; inputSource.setData("<simplepattern>"+p_xmlize_pattern(pattern)+"</simplepattern>"); QXmlSimpleReader reader; reader.setContentHandler(&handler); reader.setErrorHandler(&handler); reader.parse(inputSource); return handler.text(); }
void cbSimulator::setDefaultParameters(void) { QXmlInputSource *source; source = new QXmlInputSource; source->setData(QByteArray(SIMPARAM)); QXmlSimpleReader xmlParser; cbParamHandler *paramHandler = new cbParamHandler(param); xmlParser.setContentHandler(paramHandler); cbParameters *param; if(xmlParser.parse(*source)) param = paramHandler->parsedParameters(); else { cerr << "Error parsing DEFAULT parameters\n"; gui->appendMessage(QString("Error parsing DEFAULT parameters"), true); assert(0); } setParameters(param); delete paramHandler; delete source; //cout << " done.\n"; }
void PatternParser::parseInfoText(QStringList& text, const QString& artist, const QString& title, const QString& date, const QString& genre, const quint32 discid, const qreal size, const int length, const int nooftracks) { SaxHandler handler; handler.setArtist(artist); handler.setTitle(title); handler.setDate(date); handler.setGenre(genre); handler.setDiscid(discid); handler.setSize(size); handler.setLength(length); handler.setNoOfTracks(nooftracks); handler.set2DigitsTrackNum(false); QXmlInputSource inputSource; inputSource.setData("<textpattern>"+p_xmlize_pattern(text.join("\n"))+"</textpattern>"); QXmlSimpleReader reader; reader.setContentHandler(&handler); reader.setErrorHandler(&handler); reader.parse(inputSource); text = handler.text().split('\n'); }
Map* Loader::loadMap(const QString& filename) { QFile file(filename); if (!file.open(QIODevice::ReadOnly)) { qDebug() << "could not open file " << filename; return nullptr; } QXmlSimpleReader xmlReader; Builder builder; XmlHandler* handler = new XmlHandler(&builder); QXmlInputSource* source = new QXmlInputSource(&file); xmlReader.setContentHandler(handler); xmlReader.setErrorHandler(handler); bool ok = xmlReader.parse(source); Map* map = builder.map(); map->setFilename(filename); delete handler; return map; }
void GuitarChordSelectorDialog::parseChordFile(const QString& chordFileName) { ChordXmlHandler handler(m_chordMap); QFile chordFile(chordFileName); bool ok = chordFile.open(QIODevice::ReadOnly); if (!ok) QMessageBox::critical(0, tr("Rosegarden"), tr("couldn't open file '%1'").arg(handler.errorString())); QXmlInputSource source(&chordFile); QXmlSimpleReader reader; reader.setContentHandler(&handler); reader.setErrorHandler(&handler); // RG_DEBUG << "GuitarChordSelectorDialog::parseChordFile() parsing " << // chordFileName; reader.parse(source); // RG_DEBUG << " parsed OK, without crashing! W00t!"; if (!ok) QMessageBox::critical(0, tr("Rosegarden"), tr("couldn't parse chord dictionary : %1").arg(handler.errorString())); }
bool App::readConfig() { QFile cfgFile(Global::applicationFileName("iqnotes", "iqnotes.cfg")); if (!cfgFile.open(IO_ReadOnly)) { if (!cfgFile.open(IO_WriteOnly)) return false; return saveConfig(); } cfgFile.close(); CfgFileParser handler; QXmlInputSource *source; QXmlSimpleReader reader; connect(&handler, SIGNAL(configLoaded(const NotesConfig &)), this, SLOT(configLoaded(const NotesConfig &))); source = new QXmlInputSource(cfgFile); reader.setContentHandler(&handler); // reader.setErrorHandler(new NotesFileParserError); if(!reader.parse(*source)) { qWarning(tr("can't load config file")); delete source; return false; } delete source; return true; }
void NamedSearches::read() { QFile namedSearchFile(home.canonicalPath() + "/namedsearches.xml"); QXmlInputSource source( &namedSearchFile ); QXmlSimpleReader xmlReader; NamedSearchParser handler; xmlReader.setContentHandler(&handler); xmlReader.setErrorHandler(&handler); xmlReader.parse(source); // go read them! list = handler.getResults(); // If there is no filters yet, add some for multisport use. if (list.isEmpty()) { NamedSearch namedSearch; namedSearch.type = NamedSearch::filter; namedSearch.name = tr("Swim"); namedSearch.text = "isSwim<>0"; list.append(namedSearch); namedSearch.name = tr("Bike"); namedSearch.text = "(isRun=0) and (isSwim=0)"; list.append(namedSearch); namedSearch.name = tr("Run"); namedSearch.text = "isRun<>0"; list.append(namedSearch); } // let everyone know they have changed changed(); }
void IsoCodesPrivate::buildIsoEntryList() { loaded = true; QFile file(QString("%1/iso_%2.xml").arg(isoCodesXmlDir, isoCode)); if( !file.open(QFile::ReadOnly | QFile::Text) ) { kError() << "Can't open the xml file" << file.fileName(); return; } XmlHandler xmlHandler(isoCode, isoEntryList); QXmlSimpleReader reader; reader.setContentHandler(&xmlHandler); reader.setErrorHandler(&xmlHandler); QXmlInputSource xmlInputSource(&file); if( ! reader.parse(xmlInputSource) ) { kError() << "Failed to parse the xml file" << file.fileName(); return; } kDebug() << "Loaded" << isoEntryList.count() << ("iso entry definitions for iso"+isoCode) << "from" << file.fileName(); }
void OsmReader::readFromString(QString xml, shared_ptr<OsmMap> map) { _osmFound = false; _missingNodeCount = 0; _missingWayCount = 0; _badAccuracyCount = 0; _map = map; // do xml parsing QXmlSimpleReader reader; reader.setContentHandler(this); reader.setErrorHandler(this); QBuffer buffer; buffer.setData(xml.toUtf8()); QXmlInputSource xmlInputSource(&buffer); if (reader.parse(xmlInputSource) == false) { throw Exception(_errorString); } ReportMissingElementsVisitor visitor; _map->visitRw(visitor); _map.reset(); }
bool ThemeManager::applyTheme(const QString &file) { bool ok = false; QXmlSimpleReader reader; reader.setContentHandler(this); reader.setErrorHandler(this); QFile f(file); QXmlInputSource xmlsource(&f); if (reader.parse(&xmlsource)) { ok = true; } else { #ifdef K_DEBUG QString msg = "ThemeManager::applyTheme() - Fatal Error: Can't process the theme file: " + file; #ifdef Q_OS_WIN qDebug() << msg; #else tError() << msg; #endif #endif ok = false; } return ok; }
void MainWindow::open() { QString fileName = QFileDialog::getOpenFileName(this, tr("Open Bookmark File"), QDir::currentPath(), tr("XBEL Files (*.xbel *.xml)")); if (fileName.isEmpty()) return; treeWidget->clear(); XbelHandler handler(treeWidget); QXmlSimpleReader reader; reader.setContentHandler(&handler); reader.setErrorHandler(&handler); QFile file(fileName); if (!file.open(QFile::ReadOnly | QFile::Text)) { QMessageBox::warning(this, tr("SAX Bookmarks"), tr("Cannot read file %1:\n%2.") .arg(fileName) .arg(file.errorString())); return; } QXmlInputSource xmlInputSource(&file); if (reader.parse(xmlInputSource)) statusBar()->showMessage(tr("File loaded"), 2000); }
bool ThemeManager::applyTheme(const ThemeDocument &kd) { // tDebug() << "Applying theme" << endl; bool ok = false; QXmlSimpleReader reader; reader.setContentHandler(this); reader.setErrorHandler(this); QXmlInputSource xmlsource; xmlsource.setData(kd.toString()); if (reader.parse(&xmlsource)) { ok = true; } else { #ifdef K_DEBUG QString msg = "ThemeManager::applyTheme() - Fatal Error: Can't process theme document"; #ifdef Q_OS_WIN qDebug() << msg; #else tError() << msg; #endif #endif ok = false; } return ok; }
bool VOCatalogDataParser::parse(const QByteArray &data, QList<VOCatalogHeader> &catalogs, QList<VOCooSys> &cooSys, QList<QStringList> &dataOut) { QXmlInputSource xmlInputStream; QXmlSimpleReader xml; if (data.isEmpty()) { return false; } xmlInputStream.setData(data); xml.setContentHandler(this); xml.setErrorHandler(this); if (xml.parse(&xmlInputStream)) { catalogs = m_list; cooSys = m_cooSys; dataOut = m_data; return true; } return false; }
const QString PatternParser::parseFilenamePattern(const QString& pattern, int trackno, int cdno, int trackoffset, int nooftracks, const QString& artist, const QString& title, const QString& tartist, const QString& ttitle, const QString& date, const QString& genre, const QString& suffix, bool fat32compatible, bool replacespaceswithunderscores, bool _2digitstracknum) { SaxHandler handler; handler.setTrackNo(trackno); handler.setCDNo(cdno); handler.setTrackOffset(trackoffset); handler.setNoOfTracks(nooftracks); handler.setArtist(artist); handler.setTitle(title); handler.setTrackArtist(tartist); handler.setTrackTitle(ttitle); handler.setDate(date); handler.setGenre(genre); handler.setSuffix(suffix); handler.setFAT32Compatible(fat32compatible); handler.setReplaceSpacesWithUnderscores(replacespaceswithunderscores); handler.set2DigitsTrackNum(_2digitstracknum); QXmlInputSource inputSource; inputSource.setData("<filenamepattern>"+p_xmlize_pattern(pattern)+"</filenamepattern>"); QXmlSimpleReader reader; reader.setContentHandler(&handler); reader.setErrorHandler(&handler); reader.parse(inputSource); return handler.text(); }
void TtbDialog::finishSettings(QNetworkReply *reply) { progressBar->setValue(4); TtbSettingsParser handler; QXmlInputSource source( reply ); QXmlSimpleReader reader; reader.setContentHandler( &handler ); if( ! reader.parse( source ) ){ progressLabel->setText(tr("failed to parse Settings response: ") +handler.errorString()); closeButton->setText(tr("&Close")); return; } if( handler.error.length() > 0 ){ progressLabel->setText(tr("failed to get settings: ") +handler.error ); closeButton->setText(tr("&Close")); return; } sessionId = handler.session; proMember = handler.pro; if( sessionId.length() == 0 ){ requestSession(); } else { requestUpload(); } }
/*! * \brief CTConfArch::setParameters * * Sets values of all configurable block parameters based on the content of the * supplied XML string. * * \param xml containing data of all configurable parameters. */ bool CTConfArch::setParameters(QString xml) { // qDebug() << xml; int num_stimuli = NUM_LIGHTS; QXmlSimpleReader xmlReader; QXmlInputSource *source = new QXmlInputSource(); source->setData(xml); CTXmlHandler *handler = new CTXmlHandler; /* *Passing pointer of the class to the xml parser handler, *in order to set the parsed values into it's input fields */ handler->setWidget(9, this, num_stimuli, 0); QList<CTConstLight*> empty1; QList<CTSpeaker*> empty2; QList<CTScreen*> empty3; QList<CTBigLight*> empty4; QList<CTButton*> empty5; handler->setStimuli(empty1, empty2, light_stimuli,empty3,empty4,empty5); xmlReader.setContentHandler(handler); xmlReader.setErrorHandler(handler); bool ok = xmlReader.parse(source); qDebug() << "The parsing went ok? " << ok; block_duration = handler->getBlockDuration(); if(ok) { updateBlockRuntime(1.0); } return true; }