query fragments: initial: parse and create, does nothing yet

This commit is contained in:
Jean-Francois Dockes 2014-12-10 14:07:37 +01:00
parent 91b05540b2
commit a6e4cb7d37
8 changed files with 222 additions and 0 deletions

145
src/qtgui/fragbuts.cpp Normal file
View File

@ -0,0 +1,145 @@
/* Copyright (C) 2005 J.F.Dockes
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "autoconfig.h"
#include <string>
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <QtGui/QCheckBox>
#include <QtGui/QRadioButton>
#include <QtGui/QButtonGroup>
#include <QtXml/QXmlDefaultHandler>
#include "fragbuts.h"
#include "pathut.h"
#include "smallut.h"
#include "recoll.h"
#include "debuglog.h"
#include "readfile.h"
using namespace std;
class FragButsParser : public QXmlDefaultHandler {
public:
FragButsParser(QWidget *_parent)
: parent(_parent), vlw(new QVBoxLayout(parent)),
vl(new QVBoxLayout()), hl(0), bg(0), radio(false)
{
}
bool startElement(const QString & /* namespaceURI */,
const QString & /* localName */,
const QString &qName,
const QXmlAttributes &attributes);
bool endElement(const QString & /* namespaceURI */,
const QString & /* localName */,
const QString &qName);
bool characters(const QString &str)
{
currentText += str;
return true;
}
private:
QWidget *parent;
QVBoxLayout *vlw;
QVBoxLayout *vl;
// Temporary data while parsing.
QHBoxLayout *hl;
QButtonGroup *bg;
QString currentText;
QString label;
QString frag;
bool radio;
};
bool FragButsParser::startElement(const QString & /* namespaceURI */,
const QString & /* localName */,
const QString &qName,
const QXmlAttributes &attributes)
{
currentText = "";
if (qName == "buttons") {
radio = false;
hl = new QHBoxLayout();
} else if (qName == "radiobuttons") {
radio = true;
bg = new QButtonGroup(parent);
hl = new QHBoxLayout();
}
return true;
}
bool FragButsParser::endElement(const QString & /* namespaceURI */,
const QString & /* localName */,
const QString &qName)
{
if (qName == "label") {
label = currentText;
} else if (qName == "frag") {
frag = currentText;
} else if (qName == "fragbut") {
string slab = qs2utf8s(label);
trimstring(slab, " \t\n\t");
label = QString::fromUtf8(slab.c_str());
if (radio) {
QRadioButton *but = new QRadioButton(label, parent);
bg->addButton(but);
if (bg->buttons().length() == 1)
but->setChecked(true);
hl->addWidget(but);
} else {
QCheckBox *but = new QCheckBox(label, parent);
hl->addWidget(but);
}
} else if (qName == "buttons" || qName == "radiobuttons") {
vl->addLayout(hl);
hl = 0;
} else if (qName == "fragbuts") {
vlw->addLayout(vl);
}
return true;
}
FragButs::FragButs(QWidget* parent)
: QWidget(parent)
{
string conf = path_cat(theconfig->getConfDir(), "fragbuts.xml");
string data, reason;
if (!file_to_string(conf, data, &reason)) {
LOGERR(("Fragbuts:: can't read [%s]\n", conf.c_str()));
return;
}
FragButsParser parser(this);
QXmlSimpleReader reader;
reader.setContentHandler(&parser);
reader.setErrorHandler(&parser);
QXmlInputSource xmlInputSource;
xmlInputSource.setData(QString::fromUtf8(data.c_str()));
if (!reader.parse(xmlInputSource)) {
LOGERR(("FragButs:: parse failed for [%s]\n", conf.c_str()));
return;
}
}
FragButs::~FragButs()
{
}

45
src/qtgui/fragbuts.h Normal file
View File

@ -0,0 +1,45 @@
/* Copyright (C) 2005 J.F.Dockes
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _FRAGBUTS_H_INCLUDED_
#define _FRAGBUTS_H_INCLUDED_
#include <QWidget>
/*
* Display a series of user-defined buttons which activate query
* language fragments to augment the current search
*/
class FragButs : public QWidget
{
Q_OBJECT;
public:
FragButs(QWidget* parent = 0);
virtual ~FragButs();
public slots:
signals:
private:
// Detect source file change
time_t m_reftime;
};
#endif /* _FRAGBUTS_H_INCLUDED_ */

Binary file not shown.

After

Width:  |  Height:  |  Size: 512 B

View File

@ -93,6 +93,7 @@
<addaction name="toolsAdvanced_SearchAction"/>
<addaction name="toolsSpellAction"/>
<addaction name="actionShowQueryDetails"/>
<addaction name="actionQuery_Fragments"/>
</widget>
<widget class="QMenu" name="preferencesMenu">
<property name="title">
@ -459,6 +460,15 @@
<string>First Page</string>
</property>
</action>
<action name="actionQuery_Fragments">
<property name="icon">
<iconset resource="recoll.qrc">
<normaloff>:/images/code-block.png</normaloff>:/images/code-block.png</iconset>
</property>
<property name="text">
<string>Query Fragments</string>
</property>
</action>
</widget>
<layoutdefault spacing="2" margin="2"/>
<customwidgets>

View File

@ -83,6 +83,7 @@ using std::pair;
#include "rclzg.h"
#include "fileudi.h"
#include "snippets_w.h"
#include "fragbuts.h"
using namespace confgui;
@ -210,6 +211,7 @@ void RclMain::init()
m_toolsTB->addAction(toolsAdvanced_SearchAction);
m_toolsTB->addAction(toolsDoc_HistoryAction);
m_toolsTB->addAction(toolsSpellAction);
m_toolsTB->addAction(actionQuery_Fragments);
this->addToolBar(int2area(prefs.toolArea), m_toolsTB);
m_resTB = new QToolBar(this);
@ -337,6 +339,8 @@ void RclMain::init()
this, SLOT(showAdvSearchDialog()));
connect(toolsSpellAction, SIGNAL(triggered()),
this, SLOT(showSpellDialog()));
connect(actionQuery_Fragments, SIGNAL(triggered()),
this, SLOT(showFragButs()));
connect(indexConfigAction, SIGNAL(triggered()),
this, SLOT(showIndexConfig()));
connect(indexScheduleAction, SIGNAL(triggered()),
@ -1048,7 +1052,18 @@ void RclMain::showSpellDialog()
spellform->close();
spellform->show();
}
}
void RclMain::showFragButs()
{
if (fragbuts == 0) {
fragbuts = new FragButs(0);
fragbuts->show();
} else {
// Close and reopen, in hope that makes us visible...
fragbuts->close();
fragbuts->show();
}
}
void RclMain::showIndexConfig()

View File

@ -39,6 +39,7 @@ class Preview;
class ResTable;
class CronToolW;
class RTIToolW;
class FragButs;
#include "ui_rclmain.h"
@ -64,6 +65,7 @@ public:
cronTool(0),
rtiTool(0),
spellform(0),
fragbuts(0),
periodictimer(0),
restable(0),
displayingTable(0),
@ -110,6 +112,7 @@ public slots:
virtual void previewClosed(Preview *w);
virtual void showAdvSearchDialog();
virtual void showSpellDialog();
virtual void showFragButs();
virtual void showAboutDialog();
virtual void showMissingHelpers();
virtual void showActiveTypes();
@ -177,6 +180,7 @@ private:
CronToolW *cronTool;
RTIToolW *rtiTool;
SpellW *spellform;
FragButs *fragbuts;
QTimer *periodictimer;
ResTable *restable;
bool displayingTable;

View File

@ -19,6 +19,7 @@ HEADERS += \
crontool.h \
editdialog.h \
firstidx.h \
fragbuts.h \
idxsched.h \
listdialog.h \
preview_w.h \
@ -41,6 +42,7 @@ SOURCES += \
confgui/confgui.cpp \
confgui/confguiindex.cpp \
crontool.cpp \
fragbuts.cpp \
guiutils.cpp \
main.cpp \
multisave.cpp \

View File

@ -3,6 +3,7 @@
<file>images/asearch.png</file>
<file>images/cancel.png</file>
<file>images/close.png</file>
<file>images/code-block.png</file>
<file>images/history.png</file>
<file>images/nextpage.png</file>
<file>images/prevpage.png</file>