fragbuts: more file format checks and diags

This commit is contained in:
Jean-Francois Dockes 2020-04-19 11:10:45 +02:00
parent 2287c9d0ca
commit 058cec8466

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2005 J.F.Dockes /* Copyright (C) 2005-2020 J.F.Dockes
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
@ -43,24 +43,22 @@ using namespace std;
class FragButsParser : public QXmlDefaultHandler { class FragButsParser : public QXmlDefaultHandler {
public: public:
FragButsParser(FragButs *_parent, vector<FragButs::ButFrag>& _buttons) FragButsParser(FragButs *_parent, vector<FragButs::ButFrag>& _buttons)
: parent(_parent), vlw(new QVBoxLayout(parent)), : parent(_parent), vlw(new QVBoxLayout(parent)),
vl(new QVBoxLayout()), buttons(_buttons), vl(new QVBoxLayout()), buttons(_buttons),
hl(0), bg(0), radio(false) hl(0), bg(0), radio(false) {
{ }
}
bool startElement(const QString & /* namespaceURI */, bool startElement(const QString & /* namespaceURI */,
const QString & /* localName */, const QString & /* localName */,
const QString &qName, const QString &qName,
const QXmlAttributes &attributes); const QXmlAttributes &attributes);
bool endElement(const QString & /* namespaceURI */, bool endElement(const QString & /* namespaceURI */,
const QString & /* localName */, const QString & /* localName */,
const QString &qName); const QString &qName);
bool characters(const QString &str) bool characters(const QString &str) {
{ currentText += str;
currentText += str; return true;
return true; }
}
bool error(const QXmlParseException& exception) { bool error(const QXmlParseException& exception) {
fatalError(exception); fatalError(exception);
@ -103,6 +101,12 @@ bool FragButsParser::startElement(const QString & /* namespaceURI */,
radio = true; radio = true;
bg = new QButtonGroup(parent); bg = new QButtonGroup(parent);
hl = new QHBoxLayout(); hl = new QHBoxLayout();
} else if (qName == "label" || qName == "frag" || qName == "fragbuts" ||
qName == "fragbut") {
} else {
QMessageBox::warning(0, "Recoll",
QString("Bad element name: [%1]").arg(qName));
return false;
} }
return true; return true;
} }
@ -130,7 +134,7 @@ bool FragButsParser::endElement(const QString & /* namespaceURI */,
QCheckBox *but = new QCheckBox(label, parent); QCheckBox *but = new QCheckBox(label, parent);
abut = but; abut = but;
} }
abut->setToolTip(currentText); abut->setToolTip(currentText);
buttons.push_back(FragButs::ButFrag(abut, frag)); buttons.push_back(FragButs::ButFrag(abut, frag));
hl->addWidget(abut); hl->addWidget(abut);
} else if (qName == "buttons" || qName == "radiobuttons") { } else if (qName == "buttons" || qName == "radiobuttons") {
@ -138,6 +142,10 @@ bool FragButsParser::endElement(const QString & /* namespaceURI */,
hl = 0; hl = 0;
} else if (qName == "fragbuts") { } else if (qName == "fragbuts") {
vlw->addLayout(vl); vlw->addLayout(vl);
} else {
QMessageBox::warning(0, "Recoll",
QString("Bad element name: [%1]").arg(qName));
return false;
} }
return true; return true;
} }
@ -155,7 +163,7 @@ FragButs::FragButs(QWidget* parent)
copyfile(src.c_str(), m_fn.c_str(), reason); copyfile(src.c_str(), m_fn.c_str(), reason);
} }
if (!file_to_string(m_fn, data, &reason)) { if (!file_to_string(m_fn, data, &reason)) {
QMessageBox::warning( QMessageBox::warning(
0, "Recoll", tr("%1 not found.").arg(path2qs(m_fn))); 0, "Recoll", tr("%1 not found.").arg(path2qs(m_fn)));
LOGERR("Fragbuts:: can't read [" << m_fn << "]\n"); LOGERR("Fragbuts:: can't read [" << m_fn << "]\n");
return; return;
@ -167,7 +175,7 @@ FragButs::FragButs(QWidget* parent)
QXmlInputSource xmlInputSource; QXmlInputSource xmlInputSource;
xmlInputSource.setData(QString::fromUtf8(data.c_str())); xmlInputSource.setData(QString::fromUtf8(data.c_str()));
if (!reader.parse(xmlInputSource)) { if (!reader.parse(xmlInputSource)) {
QMessageBox::warning(0, "Recoll", tr("%1:\n %2") QMessageBox::warning(0, "Recoll", tr("%1:\n %2")
.arg(path2qs(m_fn)).arg(parser.errorMessage)); .arg(path2qs(m_fn)).arg(parser.errorMessage));
return; return;
} }