本文整理汇总了C++中QXmlSimpleReader::setContentHandler方法的典型用法代码示例。如果您正苦于以下问题:C++ QXmlSimpleReader::setContentHandler方法的具体用法?C++ QXmlSimpleReader::setContentHandler怎么用?C++ QXmlSimpleReader::setContentHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QXmlSimpleReader
的用法示例。
在下文中一共展示了QXmlSimpleReader::setContentHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handler
KVSO_CLASS_FUNCTION(xmlReader, parse)
{
KviKvsVariant * pVariantData;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("string_or_memorybuffer_object", KVS_PT_VARIANT, 0, pVariantData)
KVSO_PARAMETERS_END(c)
#ifdef QT_NO_XML
fatalError(__tr2qs_ctx("XML support not available in the Qt library"));
c->returnValue()->setBoolean(false);
#else
m_szLastError = "";
KviXmlHandler handler(this);
QXmlInputSource source;
if(pVariantData->isHObject())
{
KviKvsObject * pObject;
kvs_hobject_t hObject;
pVariantData->asHObject(hObject);
pObject = KviKvsKernel::instance()->objectController()->lookupObject(hObject);
if(!pObject)
{
c->warning(__tr2qs_ctx("Data parameter is not an object", "objects"));
return true;
}
if(pObject->inheritsClass("memorybuffer"))
{
source.setData(*((KvsObject_memoryBuffer *)pObject)->pBuffer());
}
else
{
c->warning(__tr2qs_ctx("Data parameter is not a memorybuffer object", "objects"));
return true;
}
}
else if(pVariantData->isString())
{
QString szString;
pVariantData->asString(szString);
// We have a problem here.. most kvirc functions already interpret the data
// read from files. We should have binary data handling features to get this to work correctly.
// The following snippet of code tries to provide a best-effort workaround.
QByteArray utf8data = szString.toUtf8();
QByteArray data = utf8data;
data.truncate(utf8data.length()); // don't include the null terminator in data
source.setData(data);
//qDebug("PARSING(%s) LEN(%d)",szString.toUtf8().data(),szString.toUtf8().length());
}
else
{
c->warning(__tr2qs_ctx("Data is not a memorybuffer object or string", "objects"));
return true;
}
QXmlSimpleReader reader;
reader.setContentHandler(&handler);
reader.setErrorHandler(&handler);
c->returnValue()->setBoolean(reader.parse(source));
#endif
return true;
}
示例2: load
void Fractal::load( QString fileName)
{
int t,h,w;
double miniX,maxiX,miniY,maxiY;
QFile xmlFile( fileName );
QXmlInputSource source( &xmlFile );
QXmlSimpleReader reader;
reader.setContentHandler( &handler );
reader.parse( source );
// set the minimum x & y and maximum x & y according to the values in the
// xml file
handler.setValues();
// once the values are set we get the values from the class
t = handler.getType();
// if the type isn't between 0 and 9 inclusive (suppose the user tried changing the parameter)
// the application will load the default fractaal
if( ( t != 0 ) && ( t != 1 ) && ( t != 2 ) && ( t != 3 ) && ( t != 4 ) && ( t != 5 ) && ( t != 6 ) && ( t != 7 ) && ( t != 8 ) && ( t != 9 ) )
{
static QMessageBox* error = new QMessageBox( "Error", "File has been modified with wrong parameters. \n" "The default fractal will be loaded instead." , QMessageBox::Information, 1, 0, 0, this, 0, FALSE );
error->setButtonText( 1, "Ok" );
error->show();
data.setDefaultData( MANDEL_TYPE1 );
mandel1Action->setOn( TRUE );
update();
render( data.getType() , data.getHeight() , data.getWidth() , data.getDefaultMinX() , data.getDefaultMaxX() , data.getDefaultMinY() , data.getDefaultMaxY() );
} // if
else
{
h = data.getHeight();
w = data.getWidth();
miniX = handler.getMinX();
maxiX = handler.getMaxX();
miniY = handler.getMinY();
maxiY = handler.getMaxY();
// according to the image we load (i.e. whether the image is mandelbrot or julia)
// we check the appropriate action in Fractal -> Select Fractal
if( t == MANDEL_TYPE1 )
mandel1Action->setOn( TRUE );
if( t == MANDEL_TYPE2)
mandel2Action->setOn( TRUE );
if( t == MANDEL_TYPE3)
mandel3Action->setOn( TRUE );
if( t == MANDEL_TYPE4)
mandel4Action->setOn( TRUE );
if( t == MANDEL_TYPE5)
mandel5Action->setOn( TRUE );
if( t == JULIA_TYPE1)
julia1Action->setOn( TRUE );
if( t == JULIA_TYPE2 )
julia2Action->setOn( TRUE );
if( t == JULIA_TYPE3 )
julia3Action->setOn( TRUE );
if( t == JULIA_TYPE4 )
julia4Action->setOn( TRUE );
if( t == JULIA_TYPE5 )
julia5Action->setOn( TRUE );
// now we set the data in the metadata class (the class which stores the minimum
// and maximum values of x & y)
data.setMetaData( t , h , w , miniX , maxiX , miniY , maxiY);
update();
render( t , h , w , miniX , maxiX , miniY , maxiY );
} // else
check = 0;
} // load()
示例3: urlquery
bool
TrainingsTageBuch::open(QStringList &errors)
{
// get a session token, then get the settings for the account
printd("TrainingStageBuch::open\n");
// GET ACCOUNT SETTINGS
QString username = getSetting(GC_TTBUSER).toString();
QString password = getSetting(GC_TTBPASS).toString();
#if QT_VERSION > 0x050000
QUrlQuery urlquery;
#else
QUrl urlquery( TTB_URL + "/settings/list" );
#endif
urlquery.addQueryItem( "view", "xml" );
urlquery.addQueryItem( "user", username );
urlquery.addQueryItem( "pass", password );
#if QT_VERSION > 0x050000
QUrl url (TTB_URL + "/settings/list");
url.setQuery(urlquery.query());
QNetworkRequest request = QNetworkRequest(url);
#else
QNetworkRequest request = QNetworkRequest(urlquery);
#endif
request.setRawHeader( "Accept-Encoding", "identity" );
request.setRawHeader( "Accept", "application/xml" );
request.setRawHeader( "Accept-Charset", "utf-8" );
// block waiting for response...
QEventLoop loop;
reply = nam->get(request);
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
TTBSettingsParser handler;
QXmlInputSource source(reply);
QXmlSimpleReader reader;
reader.setContentHandler(&handler);
if(! reader.parse(source) ){
errors << (tr("failed to parse Settings response: ")+handler.errorString());
return false;
}
if( handler.error.length() > 0 ){
errors << (tr("failed to get settings: ") +handler.error);
return false;
}
sessionId = handler.session;
proMember = handler.pro;
// if we got a session id, no need to go further.
if(sessionId.length() > 0) return true;
// GET SESSION TOKEN
#if QT_VERSION > 0x050000
urlquery = QUrlQuery();
#else
urlquery = QUrl(TTB_URL + "/login/sso");
#endif
urlquery.addQueryItem( "view", "xml" );
urlquery.addQueryItem( "user", username );
urlquery.addQueryItem( "pass", password );
#if QT_VERSION > 0x050000
url = QUrl(TTB_URL + "/login/sso");
url.setQuery(urlquery.query());
request = QNetworkRequest(url);
#else
request = QNetworkRequest(urlquery);
#endif
request.setRawHeader( "Accept-Encoding", "identity" );
request.setRawHeader( "Accept", "application/xml" );
request.setRawHeader( "Accept-Charset", "utf-8" );
// block waiting for response
reply = nam->get(request);
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
TTBSessionParser shandler;
QXmlInputSource ssource(reply);
reader.setContentHandler(&shandler);
if(! reader.parse(ssource)) {
errors << (tr("failed to parse Session response: ")+shandler.errorString());
return false;
}
if(handler.error.length() > 0){
errors << (tr("failed to get new session: ") +shandler.error );
return false;
//.........这里部分代码省略.........
示例4: read
void OsmReader::read(shared_ptr<OsmMap> map)
{
_osmFound = false;
_missingNodeCount = 0;
_missingWayCount = 0;
_badAccuracyCount = 0;
_map = map;
// Ticket 5871: uncompress .osm.bz2 or .osm.gz files before processing
QString originalFile;
if ( _path.endsWith(".osm.bz2") == true )
{
originalFile = _path;
_path.chop(std::strlen(".bz2"));
// "man bunzip2" confirms success return code is zero
// -k option is "keep," meaning don't delete input .osm.bz2
const std::string cmd(std::string("bunzip2 -k ") + originalFile.toStdString());
LOG_DEBUG("Running uncompress command: " << cmd);
int retVal;
if ( (retVal = std::system(cmd.c_str())) != 0 )
{
QString error = QString("Error %1 returned from uncompress command: %2").arg(retVal).
arg(QString::fromStdString(cmd));
throw HootException(error);
}
LOG_DEBUG("Uncompress succeeded!");
}
else if ( _path.endsWith(".osm.gz") == true )
{
originalFile = _path;
_path.chop(std::strlen(".gz"));
// "man gzip" confirms success return code is zero
// -d option is "decompress"
// -k option is "keep," meaning don't delete input .osm.gz
const std::string cmd(std::string("gzip -d -k ") + originalFile.toStdString());
LOG_DEBUG("Running uncompress command: " << cmd);
int retVal;
if ( (retVal = std::system(cmd.c_str())) != 0 )
{
QString error = QString("Error %1 returned from uncompress command: %2").arg(retVal).
arg(QString::fromStdString(cmd));
throw HootException(error);
}
LOG_DEBUG("Uncompress succeeded!");
}
// do xml parsing
QXmlSimpleReader reader;
reader.setContentHandler(this);
reader.setErrorHandler(this);
QFile file(_path);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
throw Exception(QObject::tr("Error opening OSM file for parsing: %1").arg(_path));
}
LOG_DEBUG("File " << _path << " opened for read");
QXmlInputSource xmlInputSource(&file);
if (reader.parse(xmlInputSource) == false)
{
throw HootException(_errorString);
}
file.close();
// Ticket 5871: if we did have to decompress, delete the decompressed file when we're done
if ( originalFile.length() > 0 )
{
// Delete the temp file
std::remove(_path.toStdString().c_str());
LOG_DEBUG("Removed decompressed file " << _path);
}
ReportMissingElementsVisitor visitor;
_map->visitRw(visitor);
_map.reset();
}
示例5: finfo
VideoWindow::VideoWindow(Context *context) :
GcWindow(context), context(context), m_MediaChanged(false)
{
setControls(NULL);
setProperty("color", QColor(Qt::black));
QHBoxLayout *layout = new QHBoxLayout();
setLayout(layout);
curPosition = 1;
init = true; // assume initialisation was ok ...
#ifdef GC_VIDEO_VLC
//
// USE VLC VIDEOPLAYER
//
#if QT_VERSION >= 0x050000
#warning "WARNING: Please ensure the VLC QT4 plugin (gui/libqt4_plugin) is NOT available as it will cause GC to crash."
#endif
// config parameters to libvlc
const char * const vlc_args[] = {
"-I", "dummy", /* Don't use any interface */
"--ignore-config", /* Don't use VLC's config */
"--disable-screensaver", /* disable screensaver during playback */
#ifdef Q_OS_LINUX
"--no-xlib", // avoid xlib thread error messages
#endif
//"--verbose=-1", // -1 = no output at all
//"--quiet"
};
/* create an exception handler */
//libvlc_exception_init(&exceptions);
//vlc_exceptions(&exceptions);
/* Load the VLC engine */
inst = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);
//vlc_exceptions(&exceptions);
/* Create a new item */
if (inst) { // if vlc doesn't initialise don't even try!
m = NULL;
//vlc_exceptions(&exceptions);
/* Create a media player playing environement */
mp = libvlc_media_player_new (inst);
//vlc_exceptions(&exceptions);
//vlc_exceptions(&exceptions);
/* This is a non working code that show how to hooks into a window,
* if we have a window around */
#ifdef Q_OS_LINUX
#if QT_VERSION > 0x50000
x11Container = new QWidget(this); //XXX PORT TO 5.1 BROKEN CODE XXX
#else
x11Container = new QX11EmbedContainer(this);
#endif
layout->addWidget(x11Container);
libvlc_media_player_set_xwindow (mp, x11Container->winId());
#endif
#ifdef WIN32
container = new QWidget(this);
layout->addWidget(container);
libvlc_media_player_set_hwnd (mp, (HWND)(container->winId()));
QString filename = context->athlete->home->config().canonicalPath() + "/" + "video-layout.xml";
QFileInfo finfo(filename);
if (finfo.exists())
{
QFile file(filename);
// clean previous layout
foreach(MeterWidget* p_meterWidget, m_metersWidget)
{
m_metersWidget.removeAll(p_meterWidget);
delete p_meterWidget;
}
VideoLayoutParser handler(&m_metersWidget, container);
QXmlInputSource source (&file);
QXmlSimpleReader reader;
reader.setContentHandler (&handler);
reader.parse (source);
}
示例6: main
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// we can't read config in menaan contructor
// because translator must be create and installed before widgets creating
// so we read conf file there...
qDebug()<<"[Application say:] Reading configuration";
ConfigData *configData;
// read config data for application
{
QFile file(QApplication::applicationDirPath()+"/config.xml");
qDebug()<<"[Application say:] Check file"<<QApplication::applicationDirPath()+"/config.xml";
QXmlInputSource inputSource(&file);
QXmlSimpleReader configReader;
configData = new ConfigData();
ConfigHandler *configHandler = new ConfigHandler(configData);
configReader.setContentHandler(configHandler);
configReader.setErrorHandler(configHandler);
configReader.parse(inputSource);
delete configHandler;
}
// set translation
qDebug()<<"[Application say:] Translation install";
QTranslator trans;
int lg = configData->getLanguage();
switch (lg)
{
case ConfigData::English:
trans.load(QApplication::applicationDirPath()+"/translations/en.qm");
break;
case ConfigData::Russian:
trans.load(QApplication::applicationDirPath()+"/translations/ru.qm");
break;
case ConfigData::Germany:
trans.load(QApplication::applicationDirPath()+"/translations/de.qm");
break;
case ConfigData::French:
trans.load(QApplication::applicationDirPath()+"/translations/fr.qm");
break;
default:
trans.load(QApplication::applicationDirPath()+"/translations/en.qm");
}
app.installTranslator(&trans);
Menaan * mainWidget = new Menaan(configData);
Q_UNUSED(mainWidget)
return app.exec();
}
示例7: seasonFile
//
// Manage the seasons array
//
void
Seasons::readSeasons()
{
QFile seasonFile(home.absolutePath() + "/seasons.xml");
QXmlInputSource source( &seasonFile );
QXmlSimpleReader xmlReader;
SeasonParser( handler );
xmlReader.setContentHandler(&handler);
xmlReader.setErrorHandler(&handler);
xmlReader.parse( source );
seasons = handler.getSeasons();
Season season;
QDate today = QDate::currentDate();
QDate eom = QDate(today.year(), today.month(), today.daysInMonth());
// add Default Date Ranges
season.setName(tr("All Dates"));
season.setType(Season::temporary);
season.setStart(QDate::currentDate().addYears(-50));
season.setEnd(QDate::currentDate().addYears(50));
season.setId(QUuid("{00000000-0000-0000-0000-000000000001}"));
seasons.append(season);
season.setName(tr("This Year"));
season.setType(Season::temporary);
season.setStart(QDate(today.year(), 1,1));
season.setEnd(QDate(today.year(), 12, 31));
season.setId(QUuid("{00000000-0000-0000-0000-000000000002}"));
seasons.append(season);
season.setName(tr("This Month"));
season.setType(Season::temporary);
season.setStart(QDate(today.year(), today.month(),1));
season.setEnd(eom);
season.setId(QUuid("{00000000-0000-0000-0000-000000000003}"));
seasons.append(season);
season.setName(tr("This Week"));
season.setType(Season::temporary);
// from Mon-Sun
QDate wstart = QDate::currentDate();
wstart = wstart.addDays(Qt::Monday - wstart.dayOfWeek());
QDate wend = wstart.addDays(6); // first day + 6 more
season.setStart(wstart);
season.setEnd(wend);
season.setId(QUuid("{00000000-0000-0000-0000-000000000004}"));
seasons.append(season);
season.setName(tr("Last 7 days"));
season.setType(Season::temporary);
season.setStart(today.addDays(-6)); // today plus previous 6
season.setEnd(today);
season.setId(QUuid("{00000000-0000-0000-0000-000000000005}"));
seasons.append(season);
season.setName(tr("Last 14 days"));
season.setType(Season::temporary);
season.setStart(today.addDays(-13));
season.setEnd(today);
season.setId(QUuid("{00000000-0000-0000-0000-000000000006}"));
seasons.append(season);
season.setName(tr("Last 21 days"));
season.setType(Season::temporary);
season.setStart(today.addDays(-20));
season.setEnd(today);
season.setId(QUuid("{00000000-0000-0000-0000-000000000011}"));
seasons.append(season);
season.setName(tr("Last 28 days"));
season.setType(Season::temporary);
season.setStart(today.addDays(-27));
season.setEnd(today);
season.setId(QUuid("{00000000-0000-0000-0000-000000000007}"));
seasons.append(season);
season.setName(tr("Last 3 months"));
season.setType(Season::temporary);
season.setEnd(today);
season.setStart(today.addMonths(-3));
season.setId(QUuid("{00000000-0000-0000-0000-000000000008}"));
seasons.append(season);
season.setName(tr("Last 6 months"));
season.setType(Season::temporary);
season.setEnd(today);
season.setStart(today.addMonths(-6));
season.setId(QUuid("{00000000-0000-0000-0000-000000000009}"));
seasons.append(season);
season.setName(tr("Last 12 months"));
season.setType(Season::temporary);
season.setEnd(today);
season.setStart(today.addMonths(-12));
season.setId(QUuid("{00000000-0000-0000-0000-000000000010}"));
seasons.append(season);
//.........这里部分代码省略.........
示例8: statusXmlIsReady
void MainWindow::statusXmlIsReady(QNetworkReply* reply) {
qDebug() << "updating server status";
if (reply->error() != QNetworkReply::NoError) {
QString errorStr = reply->errorString();
if (!errorStr.isEmpty()) {
ui->textBrowser->setText("Error while fetching server status:" + errorStr);
return;
}
}
QXmlSimpleReader xmlReader;
QXmlInputSource inputSource;
inputSource.setData(reply->readAll());
//StatusXmlContentHandler* handler = new StatusXmlContentHandler(this);
StatusXmlContentHandler handler(this);
xmlReader.setContentHandler(&handler);
xmlReader.parse(&inputSource);
QMap<QString, QString>* values = handler.getValues();
QString labelText;
QTextStream stream(&labelText);
bool up = values->value("status") == "up";
stream << "<div align=\"center\"><b>" << values->value("name") << "</b></div>";
if (up) {
stream << "<div align=\"center\" style=\"color:green\">Status: " << values->value("status") << "</div>";
stream << "<div align=\"center\">Current online connections: " << values->value("connected") << "</div>";
stream << "<div align=\"center\">Max allowed connections: " << values->value("cap") << "</div>";
/*QDateTime upTime;
upTime.addSecs(values->value("uptime").toULong());*/
//upTime.
//stream << "<div align=\"center\">Uptime: " << values->value("uptime") << " seconds</div>";
QString uptimeString;
QTextStream uptimeStream(&uptimeString);
qint64 uptimeSeconds = values->value("uptime").toULongLong();
//if (uptimeSeconds % )
qint64 minutes = uptimeSeconds / 60 % 60;
qint64 hours = uptimeSeconds / 3600 % 24;
qint64 days = uptimeSeconds / 86400;
if (days != 0) {
uptimeStream << days << (days == 1 ? " day " : " days ") << hours << (hours == 1 ? " hour " : " hours ") << minutes << (minutes == 1 ? " minute " : " minutes" );
} else if (hours != 0) {
uptimeStream << hours << (hours == 1 ? " hour " : " hours ") << minutes << (minutes == 1 ? " minute " : " minutes ");
} else {
uptimeStream << minutes << (minutes == 1 ? " minute " : " minutes ") << uptimeSeconds % 60 << " seconds";
}
stream << "<div align=\"center\">Uptime: " << uptimeString << " </div>";
} else
stream << "<div align=\"center\" style=\"color:red\">Status: " << values->value("status") << "</div>";
QDateTime timestamp;
timestamp.setTime_t(values->value("timestamp").toULong());
stream << "<div align=\"center\">Last updated: " << timestamp.toString(Qt::SystemLocaleShortDate) << "</div><br>";
stream << "<div align=\"center\"><i>Notice:</i> " << values->value("notice") << "</div><br>";
stream << "<div align=\"center\">" << values->value("banner") << "</div><br><br>";
ui->textBrowser->insertHtml(labelText);
}
示例9: main
int main(int argc,char* argv[])
{
QCoreApplication a(argc, argv);
QsLogging::initQsLog();
string resourcesPath=string(getenv("LIMA_RESOURCES"));
string configDir=string(getenv("LIMA_CONF"));
string lpConfigFile=string("lima-lp-tvr.xml");
string commonConfigFile=string("lima-common.xml");
string clientId=string("lp-structuredXmlreaderclient");
string workingDir=string(".");
if (resourcesPath.empty())
{
resourcesPath = "/usr/share/apps/lima/resources/";
}
if (configDir.empty())
{
configDir = "/usr/share/config/lima/";
}
deque<string> files;
deque<string> langs;
deque<string> pipelines;
if (argc>1)
{
for (int i = 1 ; i < argc; i++)
{
std::string arg(argv[i]);
std::string::size_type pos = std::string::npos;
if ( arg[0] == '-' )
{
if (arg == "--help")
usage(argc, argv);
else if ( (pos = arg.find("--lp-config-file=")) != std::string::npos )
lpConfigFile = arg.substr(pos+17);
else if ( (pos = arg.find("--common-config-file=")) != std::string::npos )
commonConfigFile = arg.substr(pos+21);
else if ( (pos = arg.find("--config-dir=")) != std::string::npos )
configDir = arg.substr(pos+13);
else if ( (pos = arg.find("--resources-dir=")) != std::string::npos )
resourcesPath = arg.substr(pos+16);
else if ( (pos = arg.find("--client=")) != std::string::npos )
clientId=arg.substr(pos+9);
else if ( (pos = arg.find("--working-dir=")) != std::string::npos )
workingDir=arg.substr(pos+14);
else if ( (pos = arg.find("--language=")) != std::string::npos )
langs.push_back(arg.substr(pos+11));
else usage(argc, argv);
}
else
{
files.push_back(arg);
}
}
}
setlocale(LC_ALL,"fr_FR.UTF-8");
AbstractLinguisticProcessingClient* client(0);
// initialize common
MediaticData::changeable().init(
resourcesPath,
configDir,
commonConfigFile,
langs);
// initialize linguistic processing
Lima::Common::XMLConfigurationFiles::XMLConfigurationFileParser lpconfig(configDir + "/" + lpConfigFile);
LinguisticProcessingClientFactory::changeable().configureClientFactory(
clientId,
lpconfig,
MediaticData::single().getMedias());
client=dynamic_cast<AbstractLinguisticProcessingClient*>(LinguisticProcessingClientFactory::single().createClient(clientId));
ReaderTestCaseProcessor
readerTestCaseProcessor(workingDir, client);
QXmlSimpleReader parser;
TestCasesHandler tch(readerTestCaseProcessor);
parser.setContentHandler(&tch);
parser.setErrorHandler(&tch);
for (deque<string>::const_iterator it=files.begin();
it!=files.end();
it++)
{
cout << "process tests in " << *it << endl;
try
{
QFile file(it->c_str());
if (!file.open(QIODevice::ReadOnly))
{
std::cerr << "Error opening " << *it << std::endl;
return 1;
}
//.........这里部分代码省略.........
示例10: run
int run(int argc, char** argv)
{
readCommandLineArguments(argc, argv);
if (param->help)
{
usage(argc, argv);
exit(0);
}
std::string resourcesPath = (getenv("LIMA_RESOURCES")!=0) ? string(getenv("LIMA_RESOURCES")) : string("/usr/share/apps/lima/resources");
std::string configPath = (param->configDir.size()>0) ? param->configDir : string("");
if (configPath.size() == 0)
configPath = string(getenv("LIMA_CONF"));
if (configPath.size() == 0)
configPath = string("/usr/share/config/lima");
if (QsLogging::initQsLog(QString::fromUtf8(configPath.c_str())) != 0)
{
LOGINIT("Common::Misc");
LERROR << "Call to QsLogging::initQsLog(\"" << configPath << "\") failed.";
return EXIT_FAILURE;
}
// Necessary to initialize factories
Lima::AmosePluginsManager::single();
setlocale(LC_ALL,"fr_FR.UTF-8");
// check that input file exists
{
ifstream fin(param->input.c_str(), std::ifstream::binary);
if (!fin.good())
{
cerr << "can't open input file " << param->input << endl;
exit(-1);
}
fin.close();
}
// parse charchart
if (param->charChart == "") {
cerr << "please specify CharChart file with --charChart=<file> option" << endl;
exit(0);
}
CharChart charChart;
charChart.loadFromFile(param->charChart);
try
{
cerr << "parse charChart file : " << param->charChart << endl;
// cerr << "TODO: to implement at "<<__FILE__<<", line "<<__LINE__<<"!" <<std::endl;
// exit(2);
// charChart = 0;
/* ParseCharClass parseCharClass;
parseCharClass.parse(param->charChart);
charChart = ParseChar::parse(param->charChart, parseCharClass);*/
}
catch (exception& e)
{
cerr << "Caught exception while parsing file " << param->charChart << endl;
cerr << e.what() << endl;
exit(-1);
}
if (param->extractKeys != "")
{
// just extract keys
ofstream fout(param->extractKeys.c_str(), std::ofstream::binary);
if (!fout.good())
{
cerr << "can't open file " << param->extractKeys << endl;
exit(-1);
}
KeysLogger keysLogger(fout,&charChart,param->reverseKeys);
cerr << "parse input file : " << param->input << endl;
try
{
QXmlSimpleReader parser;
// parser->setValidationScheme(SAXParser::Val_Auto);
// parser->setDoNamespaces(false);
// parser->setDoSchema(false);
// parser->setValidationSchemaFullChecking(false);
parser.setContentHandler(&keysLogger);
parser.setErrorHandler(&keysLogger);
QFile file(param->input.c_str());
if (!file.open(QIODevice::ReadOnly))
{
std::cerr << "Error opening " << param->input << std::endl;
return 1;
}
if (!parser.parse( QXmlInputSource(&file)))
{
std::cerr << "Error parsing " << param->input << " : " << parser.errorHandler()->errorString().toUtf8().constData() << std::endl;
return 1;
}
else
{
std::cerr << std::endl;
//.........这里部分代码省略.........
示例11: queueStepBegin
void MainWindow::queueStepBegin()
{
if(queue.isEmpty()) return;
currentAct = queue.dequeue();
switch(currentAct.type)
{
case ACT_LOCK_CONFIG_PAGE:
qDebug() << "ACT: lock config page";
ui->refresh->setEnabled(false);
statusBar()->clearMessage();
cancelStatusBarButton->hide();
ui->progressBar->show();
queueStepBegin();
break;
case ACT_DOWNLOAD_FILE:
qDebug() << "ACT: Download file" << currentAct.param1 << currentAct.param2 << currentAct.param3;
curstep++;
downloader.downloadFile(currentAct.param1, currentAct.param2);
statusBar()->showMessage(tr("Step %1/%2 Downloading file %3...").arg(curstep).arg(totalSteps).arg(currentAct.param1));
cancelStatusBarButton->show();
break;
case ACT_PARSE_CPACK_LIST_XML:
{
qDebug() << "ACT: parse XML file";
XMLCpackList handler;
QXmlSimpleReader reader;
reader.setContentHandler(&handler);
reader.setErrorHandler(&handler);
QFile file(tempDir + "/configs.index");
if(!file.open(QFile::ReadOnly | QFile::Text))
{
queueStepBegin();
break;
}
QXmlInputSource xmlInputSource(&file);
if(reader.parse(xmlInputSource))
{}
queueStepBegin();
}
break;
case ACT_REBUILD_CPACK_LIST:
buildConfigPackList();
queueStepBegin();
break;
case ACT_UNLOCK_CONFIG_PAGE:
qDebug() << "ACT: unlock config page";
ui->refresh->setEnabled(true);
ui->progressBar->hide();
cancelStatusBarButton->hide();
queueStepBegin();
break;
case ACT_SHOWMSG:
qDebug() << "ACT: show msg" << currentAct.param1 << currentAct.param2;
statusBar()->showMessage(currentAct.param1, currentAct.param2.toInt());
queueStepBegin();
break;
default:
queueStepBegin();
break;
}
}
示例12: parseFiles
void FRXMLCharDataReader::parseFiles(Document *pDocument, std::vector<ImageChar> &imageCharVec, std::vector<std::string> &charVec) const
{
imageCharVec.clear(); charVec.clear();
// load document images if not done yet:
if (!pDocument->isDocumentImagesLoaded()) {
std::cout << "opening document images" << std::endl;
pDocument->openDocumentImages();
}
// create XML filenames:
// pDocument->createSegmentationResultFileNames();
pDocument->createSegmentationResultFileNames("xml", pDocument->parsingParameters().filenamePrefix, pDocument->parsingParameters().filenameSuffix);
// 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);
int parsedCharsCount = 0;
for (int i=0; i < pDocument->nFiles(); ++i) {
const std::string& xmlFileName = pDocument->segmentationResultFileName(i);
// create QFile object
QFile file( QString::fromStdString(xmlFileName) );
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 " << xmlFileName << std::endl;
// store results
SimpleFineReaderXMLData* pData = pXMLHandler->getFineReaderData();
GrayImage<>* pImage = pDocument->imagePointer(i);
// const int pType = pDocument->parsingParameters().parsingType;
const ParseSubsetType pType = pDocument->parsingParameters().parsingType;
std::cout << "Parsing type is: " << pType << std::endl;
for (int j=0; j<pData->parsedBBoxes.size(); ++j) {
ImageChar imChar(pData->parsedBBoxes[j], pImage, i, parsedCharsCount);
imChar.text = pData->parsedChars[j];
imChar.suspicious = pData->isSuspicious[j];
// std::cout << "isSusp = " << imChar.suspicious << std::endl;
// add imagechar to list, depending on parsing type:
// 0-->parse all chars, 1-->parse all non-susp. chars, 2-->parse all susp. chars
if (pType == UNKNOWN_PARSESUBSET_TYPE) {
throw Exception("An invalid parsing type was given!");
}
else if ((pType == 0) || (pType == PARSE_ONLY_NON_SUSP && !imChar.suspicious) || (pType == PARSE_ONLY_SUSP && imChar.suspicious)) {
++parsedCharsCount;
imageCharVec.push_back(imChar);
charVec.push_back(pData->parsedChars[j]);
}
else if (pType == PARSE_SUBSET) {
}
} // end for j
pXMLHandler->clearData();
} // end for all xml files
std::cout << "Successfully parsed " << pDocument->nFiles() << " xml files!" << std::endl;
delete pXMLHandler;
return;
} // end parseXMLFiles
示例13: main
/*
* This program accepts the following command line options
* -lab string: name of file with lab description (default, stdin);
* -grid string: name of file with start position grid (default, stdin);
* -log string: name of log file (default, server.log);
* -nc real: compass noise coeficient (default, 0.0);
* -nb real: beacon noise coeficient (default, 0.0);
* -ni real: infrared noise coeficient (default, 0.0);
* -nm real: motors noise coeficient (default, 0.0);
* -st integer: simulation time, in number of cycle time units (default, 3000);
* -ct integer: cycle time, in miliseconds (default, 75).
*/
int main(int argc, char *argv[])
{
/* Copyright and wellcome message */
printf(" CiberRato 2013 Logplayer\n Copyright (C) 2003-2013 Universidade de Aveiro\n");
/* extract option values */
char *logFilename = 0;
int port = 6000;
QApplication app(argc,argv);
//cout << "Parsing command line..."
int p=1;
while (p < argc)
{
if (strcmp(argv[p], "-log") == 0) {
if (p+1 < argc) {
logFilename = argv[p+1];
p+=2;
}
else CommandLineError();
}
else if (strcmp(argv[p], "-port") == 0) {
if (p+1 < argc) {
sscanf(argv[p+1], "%d", &port);
p+=2;
}
else CommandLineError();
}
else {
CommandLineError();
}
}
//cout << " done.\n";
/* create lab object and parse lab file */
//cout << "Creating lab object...";
QXmlInputSource *source;
if(logFilename) {
QFile srcFile(logFilename);
if(!srcFile.exists())
{
cerr << "Could not open log file " << logFilename << "\n";
QMessageBox::critical(0,"Error", QString("Could not open log file ") + logFilename,
QMessageBox::Ok,Qt::NoButton,Qt::NoButton);
return 1;
}
if ((source = new QXmlInputSource(&srcFile)) == 0)
{
cerr << "Fail sourcing log file\n";
QMessageBox::critical(0,"Error", QString("Failed sourcing log file "),
QMessageBox::Ok,Qt::NoButton,Qt::NoButton);
return 1;
}
cbLogHandler *logHandler = new cbLogHandler(&xmlParser);
xmlParser.setContentHandler(logHandler);
if( ! xmlParser.parse(*source) )
{
cerr << "Error parsing log file\n";
QMessageBox::critical(0,"Error", QString("Error parsing log file"),
QMessageBox::Ok,Qt::NoButton,Qt::NoButton);
return 1;
}
vector< vector <cbRobot> > *log = logHandler->parsedLog();
logplayer.setLog(log);
if(logHandler->getLab()!=0)
logplayer.setLab(logHandler->getLab());
else
{
cerr << "Error parsing log file\n";
QMessageBox::critical(0,"Error", QString("Error parsing log file"),
QMessageBox::Ok,Qt::NoButton,Qt::NoButton);
return 1;
}
if(logHandler->getGrid()!=0)
logplayer.setGrid(logHandler->getGrid());
else
{
cerr << "Error parsing log file\n";
QMessageBox::critical(0,"Error", QString("Error parsing log file"),
QMessageBox::Ok,Qt::NoButton,Qt::NoButton);
//.........这里部分代码省略.........
示例14: fileDst
/*******************************************
* DeviceInfo::DeviceInfo
******************************************/
DeviceInfo::DeviceInfo( QObject *parent ) :
QObject(parent),
m_batteryLevel(BATTERYLEVEL_DEFAULT),
m_copyrightInfo(COPYRIGHTINFO_DEFAULT),
m_syncPartner(SYNCPARTNER_DEFAULT),
m_deviceFriendlyName(DEVFRNDNAME_DEFAULT),
m_deviceIconPath(DEVICON_DEFAULT),
m_standardVersion(STDVER_DEFAULT),
m_vendorExtension(VENDOREXTN_DEFAULT),
m_mtpVersion(MTPVER_DEFAULT),
m_mtpExtension(MTPEXTN_DEFAULT),
m_functionalMode(FNMODE_DEFAULT),
m_manufacturer(MFR_DEFAULT),
m_model(MODEL_DEFAULT),
m_serialNo(SERNO_DEFAULT),
m_deviceVersion(DEVVER_DEFAULT),
m_deviceType(DEVTYPE_DEFAULT),
m_imageMinWidth(IMAGE_MIN_WIDTH), m_imageMaxWidth(IMAGE_MAX_WIDTH),
m_imageMinHeight(IMAGE_MIN_HEIGHT), m_imageMaxHeight(IMAGE_MAX_HEIGHT),
m_videoMinWidth(VIDEO_MIN_WIDTH), m_videoMaxWidth(VIDEO_MAX_WIDTH),
m_videoMinHeight(VIDEO_MIN_HEIGHT), m_videoMaxHeight(VIDEO_MAX_HEIGHT),
m_videoMinFPS(0), m_videoMaxFPS(100000), m_videoScanType(0x0001), m_videoSampleRate(0),
m_videoMinBitRate(0), m_videoMaxBitRate(0xFFFFFFFF),
m_audioMinBitRate(0), m_audioMaxBitRate(0xFFFFFFFF),
m_videoAudioMinBitRate(0), m_videoAudioMaxBitRate(0xFFFFFFFF),
m_videoMinKFD(0), m_videoMaxKFD(0xFFFFFFFF),
m_audioSampleRate(0)
{
//Parse deviceinfo.xml to populate default device values.
// Kludge : till we know how and where to securely install a file
// that can be modifed by an apllication.
QFile fileDst(getDeviceInfoXmlPath());
#ifndef UT_ON
QFile fileSrc("/usr/share/mtp/deviceinfo.xml");
if( !fileDst.exists() )
{
fileSrc.copy(m_deviceInfoXmlPath);
}
#endif // UT_ON
fileDst.open(QIODevice::ReadOnly | QIODevice::Text);
QXmlSimpleReader xmlReader;
QXmlInputSource source(&fileDst);
XMLHandler handler(this);
xmlReader.setContentHandler(&handler);
xmlReader.setErrorHandler(&handler);
m_xmlOk = false;
if(0 == xmlReader.parse(&source))
{
MTP_LOG_CRITICAL("Failure reading deviceinfo.xml, using default hard-coded values\n");
//FIXME Hard code the QVectors themselves by default? Then we can avoid the memcpy.
for( quint32 i = 0 ; i < sizeof(m_operationsSupportedTable)/sizeof(m_operationsSupportedTable[0]); i++ )
{
m_mtpOperationsSupported.append( m_operationsSupportedTable[i] );
}
for( quint32 i = 0 ; i < sizeof(m_eventsSupportedTable)/sizeof(m_eventsSupportedTable[0]); i++ )
{
m_mtpEventsSupported.append( m_eventsSupportedTable[i] );
}
for( quint32 i = 0 ; i < sizeof(m_devPropsSupportedTable)/sizeof(m_devPropsSupportedTable[0]); i++ )
{
m_mtpDevicePropertiesSupported.append( m_devPropsSupportedTable[i] );
}
for( quint32 i = 0 ; i < sizeof(m_commonFormatsTable)/sizeof(m_commonFormatsTable[0]); i++ )
{
m_commonFormats.append( m_commonFormatsTable[i] );
}
for( quint32 i = 0 ; i < sizeof(m_audioFormatsTable)/sizeof(m_audioFormatsTable[0]); i++ )
{
m_audioFormats.append( m_audioFormatsTable[i] );
}
for( quint32 i = 0 ; i < sizeof(m_imageFormatsTable)/sizeof(m_imageFormatsTable[0]); i++ )
{
m_imageFormats.append( m_imageFormatsTable[i] );
}
for( quint32 i = 0 ; i < sizeof(m_videoFormatsTable)/sizeof(m_videoFormatsTable[0]); i++ )
{
m_videoFormats.append( m_videoFormatsTable[i] );
}
for( quint32 i = 0 ; i < sizeof(m_audChannelTable)/sizeof(m_audChannelTable[0]); i++ )
{
m_audioChannels.append( m_audChannelTable[i] );
}
for( quint32 i = 0 ; i < sizeof(m_vidChannelTable)/sizeof(m_vidChannelTable[0]); i++ )
{
m_videoChannels.append( m_vidChannelTable[i] );
}
for( quint32 i = 0 ; i < sizeof(m_supportedCodecsTable)/sizeof(m_supportedCodecsTable[0]); i++ )
{
m_supportedCodecs.append( m_supportedCodecsTable[i] );
}
}
else
{
m_xmlOk = true;
}
//.........这里部分代码省略.........
示例15: UpdateList
void Main::UpdateList() {
StructureList handler;
handler.setIgnoreCase(m_IgnoreCase);
handler.setIgnoreAccents(m_IgnoreAccents);
AuxiliarGUI::m=this;
int (*ptrFunction)(QString)=NULL;
ptrFunction = lib2class;
handler.setAddFunction(ptrFunction);
QString search = ui.paraula->text();
handler.setWord(search);
char letter;
QString idioma;
ui.llistat->show();
//prepare the path
if (m_idioma_actiu == Auxiliar::eng2cat() ) {
idioma="cateng";
}
else {
idioma="engcat";
}
if (!isValidWord(search)) {
ui.definicio->setPlainText(""); //not valid input*
return;
}
letter=lletra_buscar(search);
QFile xmlFile(m_directori_usuari+"/"+idioma+"/"+letter+".dic");
if (!xmlFile.exists()) {
showError(tr("Cannot open dictionary file. Check configuration directory and permissions"));
}
else {
Auxiliar::debug("File2: "+m_directori_usuari+"/"+idioma+"/"+letter+".dic");
QXmlInputSource source( &xmlFile );
QXmlSimpleReader reader;
reader.setFeature("http://trolltech.com/xml/features/report-whitespace-only-CharData",false); //if we don't use it, we get more entries because spaces...
reader.setContentHandler(&handler);
handler.setParaula(search);
reader.parse(source);
WordData d = handler.getWordData();
ui.definicio->setPlainText("");
ui.definicio->setPlainText("");
m_searched=search;
selectItem();
}
}