Query Fragments: re-read file if changed. Print informative error message if file cant be parsed
This commit is contained in:
parent
94e9567bb6
commit
bfed6cb41a
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
#include "autoconfig.h"
|
#include "autoconfig.h"
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -59,6 +61,19 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool error(const QXmlParseException& exception) {
|
||||||
|
fatalError(exception);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool fatalError(const QXmlParseException& x) {
|
||||||
|
errorMessage = QString("%2 at line %3 column %4")
|
||||||
|
.arg(x.message())
|
||||||
|
.arg(x.lineNumber())
|
||||||
|
.arg(x.columnNumber());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString errorMessage;
|
||||||
private:
|
private:
|
||||||
QWidget *parent;
|
QWidget *parent;
|
||||||
QVBoxLayout *vlw;
|
QVBoxLayout *vlw;
|
||||||
@ -127,19 +142,18 @@ bool FragButsParser::endElement(const QString & /* namespaceURI */,
|
|||||||
}
|
}
|
||||||
|
|
||||||
FragButs::FragButs(QWidget* parent)
|
FragButs::FragButs(QWidget* parent)
|
||||||
: QWidget(parent), m_ok(false)
|
: QWidget(parent), m_reftime(0), m_ok(false)
|
||||||
{
|
{
|
||||||
string conf = path_cat(theconfig->getConfDir(), "fragbuts.xml");
|
m_fn = path_cat(theconfig->getConfDir(), "fragbuts.xml");
|
||||||
|
|
||||||
string data, reason;
|
string data, reason;
|
||||||
if (!file_to_string(conf, data, &reason)) {
|
if (!file_to_string(m_fn, data, &reason)) {
|
||||||
QMessageBox::warning(0, "Recoll",
|
QMessageBox::warning(0, "Recoll",
|
||||||
tr("%1 not found.").arg(
|
tr("%1 not found.").arg(
|
||||||
QString::fromLocal8Bit(conf.c_str())));
|
QString::fromLocal8Bit(m_fn.c_str())));
|
||||||
LOGERR(("Fragbuts:: can't read [%s]\n", conf.c_str()));
|
LOGERR(("Fragbuts:: can't read [%s]\n", m_fn.c_str()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FragButsParser parser(this, m_buttons);
|
FragButsParser parser(this, m_buttons);
|
||||||
QXmlSimpleReader reader;
|
QXmlSimpleReader reader;
|
||||||
reader.setContentHandler(&parser);
|
reader.setContentHandler(&parser);
|
||||||
@ -147,10 +161,9 @@ 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",
|
QMessageBox::warning(0, "Recoll", tr("%1:\n %2")
|
||||||
tr("%1 could not be parsed.").arg(
|
.arg(QString::fromLocal8Bit(m_fn.c_str()))
|
||||||
QString::fromLocal8Bit(conf.c_str())));
|
.arg(parser.errorMessage));
|
||||||
LOGERR(("FragButs:: parse failed for [%s]\n", conf.c_str()));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (vector<ButFrag>::iterator it = m_buttons.begin();
|
for (vector<ButFrag>::iterator it = m_buttons.begin();
|
||||||
@ -159,6 +172,7 @@ FragButs::FragButs(QWidget* parent)
|
|||||||
this, SLOT(onButtonClicked(bool)));
|
this, SLOT(onButtonClicked(bool)));
|
||||||
}
|
}
|
||||||
setWindowTitle(tr("Fragment Buttons"));
|
setWindowTitle(tr("Fragment Buttons"));
|
||||||
|
isStale(&m_reftime);
|
||||||
m_ok = true;
|
m_ok = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,6 +180,16 @@ FragButs::~FragButs()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FragButs::isStale(time_t *reftime)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
stat(m_fn.c_str(), &st);
|
||||||
|
bool ret = st.st_mtime != m_reftime;
|
||||||
|
if (reftime)
|
||||||
|
*reftime = st.st_mtime;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void FragButs::onButtonClicked(bool on)
|
void FragButs::onButtonClicked(bool on)
|
||||||
{
|
{
|
||||||
LOGDEB(("FragButs::onButtonClicked: [%d]\n", int(on)));
|
LOGDEB(("FragButs::onButtonClicked: [%d]\n", int(on)));
|
||||||
|
|||||||
@ -17,6 +17,9 @@
|
|||||||
|
|
||||||
#ifndef _FRAGBUTS_H_INCLUDED_
|
#ifndef _FRAGBUTS_H_INCLUDED_
|
||||||
#define _FRAGBUTS_H_INCLUDED_
|
#define _FRAGBUTS_H_INCLUDED_
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -47,6 +50,7 @@ public:
|
|||||||
|
|
||||||
void getfrags(std::vector<std::string>&);
|
void getfrags(std::vector<std::string>&);
|
||||||
bool ok() {return m_ok;}
|
bool ok() {return m_ok;}
|
||||||
|
bool isStale(time_t *reftime);
|
||||||
private slots:
|
private slots:
|
||||||
void onButtonClicked(bool);
|
void onButtonClicked(bool);
|
||||||
|
|
||||||
@ -54,10 +58,10 @@ signals:
|
|||||||
void fragmentsChanged();
|
void fragmentsChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Detect source file change
|
|
||||||
time_t m_reftime;
|
|
||||||
std::vector<ButFrag> m_buttons;
|
std::vector<ButFrag> m_buttons;
|
||||||
bool m_ok;
|
std::string m_fn;
|
||||||
|
time_t m_reftime;
|
||||||
|
bool m_ok;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1064,6 +1064,9 @@ void RclMain::showSpellDialog()
|
|||||||
|
|
||||||
void RclMain::showFragButs()
|
void RclMain::showFragButs()
|
||||||
{
|
{
|
||||||
|
if (fragbuts && fragbuts->isStale(0)) {
|
||||||
|
deleteZ(fragbuts);
|
||||||
|
}
|
||||||
if (fragbuts == 0) {
|
if (fragbuts == 0) {
|
||||||
fragbuts = new FragButs(0);
|
fragbuts = new FragButs(0);
|
||||||
if (fragbuts->ok()) {
|
if (fragbuts->ok()) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user