diff --git a/src/qtgui/fragbuts.cpp b/src/qtgui/fragbuts.cpp new file mode 100644 index 00000000..006c9092 --- /dev/null +++ b/src/qtgui/fragbuts.cpp @@ -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 + +#include +#include +#include +#include +#include +#include + +#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() +{ +} diff --git a/src/qtgui/fragbuts.h b/src/qtgui/fragbuts.h new file mode 100644 index 00000000..0bfb1642 --- /dev/null +++ b/src/qtgui/fragbuts.h @@ -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 + +/* + * 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_ */ diff --git a/src/qtgui/images/code-block.png b/src/qtgui/images/code-block.png new file mode 100644 index 00000000..9bb1fd50 Binary files /dev/null and b/src/qtgui/images/code-block.png differ diff --git a/src/qtgui/rclmain.ui b/src/qtgui/rclmain.ui index 5aa6656e..195bddef 100644 --- a/src/qtgui/rclmain.ui +++ b/src/qtgui/rclmain.ui @@ -93,6 +93,7 @@ + @@ -459,6 +460,15 @@ First Page + + + + :/images/code-block.png:/images/code-block.png + + + Query Fragments + + diff --git a/src/qtgui/rclmain_w.cpp b/src/qtgui/rclmain_w.cpp index 93ae3cc5..b53647cc 100644 --- a/src/qtgui/rclmain_w.cpp +++ b/src/qtgui/rclmain_w.cpp @@ -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() diff --git a/src/qtgui/rclmain_w.h b/src/qtgui/rclmain_w.h index 7424a1af..70f2d256 100644 --- a/src/qtgui/rclmain_w.h +++ b/src/qtgui/rclmain_w.h @@ -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; diff --git a/src/qtgui/recoll.pro.in b/src/qtgui/recoll.pro.in index 4c659663..204c420f 100644 --- a/src/qtgui/recoll.pro.in +++ b/src/qtgui/recoll.pro.in @@ -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 \ diff --git a/src/qtgui/recoll.qrc b/src/qtgui/recoll.qrc index 2cf7c28d..53013260 100644 --- a/src/qtgui/recoll.qrc +++ b/src/qtgui/recoll.qrc @@ -3,6 +3,7 @@ images/asearch.png images/cancel.png images/close.png + images/code-block.png images/history.png images/nextpage.png images/prevpage.png