Converted the index preferences to use the shared confgui code

This commit is contained in:
Jean-Francois Dockes 2019-09-22 09:23:17 +02:00
parent db3c401a23
commit 9e51ed8613
6 changed files with 1380 additions and 812 deletions

View File

@ -1,29 +1,38 @@
/* Copyright (C) 2005 J.F.Dockes /* Copyright (C) 2005-2016 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 Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the * along with this program; if not, write to the
* Free Software Foundation, Inc., * Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "confgui.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <vector>
#include <iostream>
#include <algorithm>
#include <qglobal.h> #include <qglobal.h>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QTabWidget>
#include <QDialogButtonBox>
#include <QFrame> #include <QFrame>
#include <QListWidget> #include <QListWidget>
#include <QFileDialog>
#include <QDebug>
#include <QDir>
#include <qobject.h> #include <qobject.h>
#include <qlayout.h> #include <qlayout.h>
#include <qsize.h> #include <qsize.h>
@ -38,32 +47,274 @@
#include <qstringlist.h> #include <qstringlist.h>
#include <qcombobox.h> #include <qcombobox.h>
#include "confgui.h"
#include "smallut.h" #include "smallut.h"
#include "log.h"
#include "rcldb.h"
#include "guiutils.h"
#include <list> #ifdef ENABLE_XMLCONF
#include <vector> #include "picoxml.h"
using std::list; #endif
using std::vector;
using namespace std;
namespace confgui { namespace confgui {
static const int spacing = 2; static const int spacing = 3;
static const int margin = 2; // left,top,right, bottom
static QMargins margin(4,3,4,3);
ConfTabsW::ConfTabsW(QWidget *parent, const QString& title,
ConfLinkFact *fact)
: QDialog(parent), m_makelink(fact)
{
setWindowTitle(title);
tabWidget = new QTabWidget;
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->setSpacing(spacing);
mainLayout->setContentsMargins(margin);
mainLayout->addWidget(tabWidget);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
resize(QSize(500, 400).expandedTo(minimumSizeHint()));
connect(buttonBox, SIGNAL(accepted()), this, SLOT(acceptChanges()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(rejectChanges()));
}
void ConfTabsW::hideButtons()
{
if (buttonBox)
buttonBox->hide();
}
void ConfTabsW::acceptChanges()
{
cerr << "ConfTabsW::acceptChanges()\n";
for (auto& entry : m_panels) {
entry->storeValues();
}
for (auto& entry : m_widgets) {
entry->storeValues();
}
emit sig_prefsChanged();
if (!buttonBox->isHidden())
close();
}
void ConfTabsW::rejectChanges()
{
cerr << "ConfTabsW::rejectChanges()\n";
reloadPanels();
if (!buttonBox->isHidden())
close();
}
void ConfTabsW::reloadPanels()
{
for (auto& entry : m_panels) {
entry->loadValues();
}
for (auto& entry : m_widgets) {
entry->loadValues();
}
}
int ConfTabsW::addPanel(const QString& title)
{
ConfPanelW *w = new ConfPanelW(this);
m_panels.push_back(w);
return tabWidget->addTab(w, title);
}
int ConfTabsW::addForeignPanel(ConfPanelWIF* w, const QString& title)
{
m_widgets.push_back(w);
QWidget *qw = dynamic_cast<QWidget *>(w);
if (qw == 0) {
qDebug() << "Can't cast panel to QWidget";
abort();
}
return tabWidget->addTab(qw, title);
}
void ConfTabsW::setCurrentIndex(int idx)
{
if (tabWidget) {
tabWidget->setCurrentIndex(idx);
}
}
ConfParamW *ConfTabsW::addParam(
int tabindex, ParamType tp, const QString& varname,
const QString& label, const QString& tooltip,
int ival, int maxval, const QStringList* sl)
{
ConfLink lnk = (*m_makelink)(varname);
ConfPanelW *panel = (ConfPanelW*)tabWidget->widget(tabindex);
if (panel == 0) {
return 0;
}
ConfParamW *cp = 0;
switch (tp) {
case CFPT_BOOL:
cp = new ConfParamBoolW(varname, this, lnk, label, tooltip, ival);
break;
case CFPT_INT: {
size_t v = (size_t)sl;
int v1 = (v & 0xffffffff);
cp = new ConfParamIntW(varname, this, lnk, label, tooltip, ival,
maxval, v1);
break;
}
case CFPT_STR:
cp = new ConfParamStrW(varname, this, lnk, label, tooltip);
break;
case CFPT_CSTR:
cp = new ConfParamCStrW(varname, this, lnk, label, tooltip, *sl);
break;
case CFPT_FN:
cp = new ConfParamFNW(varname, this, lnk, label, tooltip, ival);
break;
case CFPT_STRL:
cp = new ConfParamSLW(varname, this, lnk, label, tooltip);
break;
case CFPT_DNL:
cp = new ConfParamDNLW(varname, this, lnk, label, tooltip);
break;
case CFPT_CSTRL:
cp = new ConfParamCSLW(varname, this, lnk, label, tooltip, *sl);
break;
}
panel->addWidget(cp);
m_params.push_back(cp);
return cp;
}
ConfParamW *ConfTabsW::findParamW(const QString& varname)
{
for (vector<ConfParamW *>::iterator it = m_params.begin();
it != m_params.end(); it++) {
if (!varname.compare((*it)->getVarName())) {
return *it;
}
}
return 0;
}
void ConfTabsW::endOfList(int tabindex)
{
ConfPanelW *panel = (ConfPanelW*)tabWidget->widget(tabindex);
if (panel == 0)
return;
panel->endOfList();
}
bool ConfTabsW::enableLink(ConfParamW* boolw, ConfParamW* otherw, bool revert)
{
if (std::find(m_params.begin(), m_params.end(), boolw) == m_params.end() ||
std::find(m_params.begin(), m_params.end(), otherw) ==
m_params.end()) {
cerr << "ConfTabsW::enableLink: param not found\n";
return false;
}
ConfParamBoolW *bw = dynamic_cast<ConfParamBoolW*>(boolw);
if (bw == 0) {
cerr << "ConfTabsW::enableLink: not a boolw\n";
return false;
}
otherw->setEnabled(revert ? !bw->m_cb->isChecked() : bw->m_cb->isChecked());
if (revert) {
connect(bw->m_cb, SIGNAL(toggled(bool)),
otherw, SLOT(setDisabled(bool)));
} else {
connect(bw->m_cb, SIGNAL(toggled(bool)),
otherw, SLOT(setEnabled(bool)));
}
return true;
}
ConfPanelW::ConfPanelW(QWidget *parent)
: QWidget(parent)
{
m_vboxlayout = new QVBoxLayout(this);
m_vboxlayout->setSpacing(spacing);
m_vboxlayout->setAlignment(Qt::AlignTop);
m_vboxlayout->setContentsMargins(margin);
}
void ConfPanelW::addWidget(QWidget *w)
{
m_vboxlayout->addWidget(w);
m_widgets.push_back(w);
}
void ConfPanelW::endOfList()
{
m_vboxlayout->addStretch(2);
}
void ConfPanelW::storeValues()
{
for (vector<QWidget *>::iterator it = m_widgets.begin();
it != m_widgets.end(); it++) {
ConfParamW *p = (ConfParamW*)*it;
p->storeValue();
}
}
void ConfPanelW::loadValues()
{
for (vector<QWidget *>::iterator it = m_widgets.begin();
it != m_widgets.end(); it++) {
ConfParamW *p = (ConfParamW*)*it;
p->loadValue();
}
}
static QString myGetFileName(bool isdir, QString caption = QString(),
bool filenosave = false);
static QString myGetFileName(bool isdir, QString caption, bool filenosave)
{
QFileDialog dialog(0, caption);
if (isdir) {
dialog.setFileMode(QFileDialog::Directory);
dialog.setOptions(QFileDialog::ShowDirsOnly);
} else {
dialog.setFileMode(QFileDialog::AnyFile);
if (filenosave) {
dialog.setAcceptMode(QFileDialog::AcceptOpen);
} else {
dialog.setAcceptMode(QFileDialog::AcceptSave);
}
}
dialog.setViewMode(QFileDialog::List);
QFlags<QDir::Filter> flags = QDir::NoDotAndDotDot | QDir::Hidden;
if (isdir) {
flags |= QDir::Dirs;
} else {
flags |= QDir::Dirs | QDir::Files;
}
dialog.setFilter(flags);
if (dialog.exec() == QDialog::Accepted) {
return dialog.selectedFiles().value(0);
}
return QString();
}
void ConfParamW::setValue(const QString& value) void ConfParamW::setValue(const QString& value)
{ {
#ifndef _WIN32 if (m_fsencoding) {
// On Windows all paths are unicode.
if (m_fsencoding)
m_cflink->set(string((const char *)value.toLocal8Bit())); m_cflink->set(string((const char *)value.toLocal8Bit()));
else } else {
#endif
m_cflink->set(string((const char *)value.toUtf8())); m_cflink->set(string((const char *)value.toUtf8()));
} }
}
void ConfParamW::setValue(int value) void ConfParamW::setValue(int value)
{ {
@ -71,6 +322,7 @@ void ConfParamW::setValue(int value)
sprintf(buf, "%d", value); sprintf(buf, "%d", value);
m_cflink->set(string(buf)); m_cflink->set(string(buf));
} }
void ConfParamW::setValue(bool value) void ConfParamW::setValue(bool value)
{ {
char buf[30]; char buf[30];
@ -78,6 +330,10 @@ void ConfParamW::setValue(bool value)
m_cflink->set(string(buf)); m_cflink->set(string(buf));
} }
extern void setSzPol(QWidget *w, QSizePolicy::Policy hpol,
QSizePolicy::Policy vpol,
int hstretch, int vstretch);
void setSzPol(QWidget *w, QSizePolicy::Policy hpol, void setSzPol(QWidget *w, QSizePolicy::Policy hpol,
QSizePolicy::Policy vpol, QSizePolicy::Policy vpol,
int hstretch, int vstretch) int hstretch, int vstretch)
@ -93,6 +349,7 @@ bool ConfParamW::createCommon(const QString& lbltxt, const QString& tltptxt)
{ {
m_hl = new QHBoxLayout(this); m_hl = new QHBoxLayout(this);
m_hl->setSpacing(spacing); m_hl->setSpacing(spacing);
m_hl->setContentsMargins(margin);
QLabel *tl = new QLabel(this); QLabel *tl = new QLabel(this);
setSzPol(tl, QSizePolicy::Preferred, QSizePolicy::Fixed, 0, 0); setSzPol(tl, QSizePolicy::Preferred, QSizePolicy::Fixed, 0, 0);
@ -104,16 +361,15 @@ bool ConfParamW::createCommon(const QString& lbltxt, const QString& tltptxt)
return true; return true;
} }
ConfParamIntW::ConfParamIntW(QWidget *parent, ConfLink cflink, ConfParamIntW::ConfParamIntW(
const QString& lbltxt, const QString& varnm, QWidget *parent, ConfLink cflink,
const QString& tltptxt, const QString& lbltxt, const QString& tltptxt,
int minvalue, int minvalue, int maxvalue, int defaultvalue)
int maxvalue, : ConfParamW(varnm, parent, cflink), m_defaultvalue(defaultvalue)
int defaultvalue)
: ConfParamW(parent, cflink), m_defaultvalue(defaultvalue)
{ {
if (!createCommon(lbltxt, tltptxt)) if (!createCommon(lbltxt, tltptxt)) {
return; return;
}
m_sb = new QSpinBox(this); m_sb = new QSpinBox(this);
m_sb->setMinimum(minvalue); m_sb->setMinimum(minvalue);
@ -126,26 +382,33 @@ ConfParamIntW::ConfParamIntW(QWidget *parent, ConfLink cflink,
m_hl->addWidget(fr); m_hl->addWidget(fr);
loadValue(); loadValue();
QObject::connect(m_sb, SIGNAL(valueChanged(int)), }
this, SLOT(setValue(int)));
void ConfParamIntW::storeValue()
{
if (m_origvalue != m_sb->value()) {
setValue(m_sb->value());
}
} }
void ConfParamIntW::loadValue() void ConfParamIntW::loadValue()
{ {
string s; string s;
if (m_cflink->get(s)) if (m_cflink->get(s)) {
m_sb->setValue(atoi(s.c_str())); m_sb->setValue(m_origvalue = atoi(s.c_str()));
else } else {
m_sb->setValue(m_defaultvalue); m_sb->setValue(m_origvalue = m_defaultvalue);
}
} }
ConfParamStrW::ConfParamStrW(QWidget *parent, ConfLink cflink, ConfParamStrW::ConfParamStrW(
const QString& lbltxt, const QString& varnm, QWidget *parent, ConfLink cflink,
const QString& tltptxt) const QString& lbltxt, const QString& tltptxt)
: ConfParamW(parent, cflink) : ConfParamW(varnm, parent, cflink)
{ {
if (!createCommon(lbltxt, tltptxt)) if (!createCommon(lbltxt, tltptxt)) {
return; return;
}
m_le = new QLineEdit(this); m_le = new QLineEdit(this);
setSzPol(m_le, QSizePolicy::Preferred, QSizePolicy::Fixed, 1, 0); setSzPol(m_le, QSizePolicy::Preferred, QSizePolicy::Fixed, 1, 0);
@ -153,32 +416,34 @@ ConfParamStrW::ConfParamStrW(QWidget *parent, ConfLink cflink,
m_hl->addWidget(m_le); m_hl->addWidget(m_le);
loadValue(); loadValue();
QObject::connect(m_le, SIGNAL(textChanged(const QString&)), }
this, SLOT(setValue(const QString&)));
void ConfParamStrW::storeValue()
{
if (m_origvalue.compare(m_le->text())) {
setValue(m_le->text());
}
} }
void ConfParamStrW::loadValue() void ConfParamStrW::loadValue()
{ {
string s; string s;
m_cflink->get(s); m_cflink->get(s);
#ifndef _WIN32 if (m_fsencoding) {
// On Windows all paths are unicode. m_le->setText(m_origvalue = QString::fromLocal8Bit(s.c_str()));
if (m_fsencoding) } else {
m_le->setText(QString::fromLocal8Bit(s.c_str())); m_le->setText(m_origvalue = QString::fromUtf8(s.c_str()));
else }
#endif
m_le->setText(QString::fromUtf8(s.c_str()));
} }
ConfParamCStrW::ConfParamCStrW(QWidget *parent, ConfLink cflink, ConfParamCStrW::ConfParamCStrW(
const QString& lbltxt, const QString& varnm, QWidget *parent, ConfLink cflink,
const QString& tltptxt, const QString& lbltxt, const QString& tltptxt, const QStringList& sl)
const QStringList &sl : ConfParamW(varnm, parent, cflink)
)
: ConfParamW(parent, cflink)
{ {
if (!createCommon(lbltxt, tltptxt)) if (!createCommon(lbltxt, tltptxt)) {
return; return;
}
m_cmb = new QComboBox(this); m_cmb = new QComboBox(this);
m_cmb->setEditable(false); m_cmb->setEditable(false);
m_cmb->insertItems(0, sl); m_cmb->insertItems(0, sl);
@ -188,8 +453,20 @@ ConfParamCStrW::ConfParamCStrW(QWidget *parent, ConfLink cflink,
m_hl->addWidget(m_cmb); m_hl->addWidget(m_cmb);
loadValue(); loadValue();
QObject::connect(m_cmb, SIGNAL(activated(const QString&)), }
this, SLOT(setValue(const QString&)));
void ConfParamCStrW::setList(const QStringList& sl)
{
m_cmb->clear();
m_cmb->insertItems(0, sl);
loadValue();
}
void ConfParamCStrW::storeValue()
{
if (m_origvalue.compare(m_cmb->currentText())) {
setValue(m_cmb->currentText());
}
} }
void ConfParamCStrW::loadValue() void ConfParamCStrW::loadValue()
@ -197,13 +474,11 @@ void ConfParamCStrW::loadValue()
string s; string s;
m_cflink->get(s); m_cflink->get(s);
QString cs; QString cs;
#ifndef _WIN32 if (m_fsencoding) {
// On Windows all paths are unicode.
if (m_fsencoding)
cs = QString::fromLocal8Bit(s.c_str()); cs = QString::fromLocal8Bit(s.c_str());
else } else {
#endif
cs = QString::fromUtf8(s.c_str()); cs = QString::fromUtf8(s.c_str());
}
for (int i = 0; i < m_cmb->count(); i++) { for (int i = 0; i < m_cmb->count(); i++) {
if (!cs.compare(m_cmb->itemText(i))) { if (!cs.compare(m_cmb->itemText(i))) {
@ -211,16 +486,18 @@ void ConfParamCStrW::loadValue()
break; break;
} }
} }
m_origvalue = cs;
} }
ConfParamBoolW::ConfParamBoolW(QWidget *parent, ConfLink cflink, ConfParamBoolW::ConfParamBoolW(
const QString& lbltxt, const QString& varnm, QWidget *parent, ConfLink cflink,
const QString& tltptxt) const QString& lbltxt, const QString& tltptxt, bool deflt)
: ConfParamW(parent, cflink) : ConfParamW(varnm, parent, cflink), m_dflt(deflt)
{ {
// No createCommon because the checkbox has a label // No createCommon because the checkbox has a label
m_hl = new QHBoxLayout(this); m_hl = new QHBoxLayout(this);
m_hl->setSpacing(spacing); m_hl->setSpacing(spacing);
m_hl->setContentsMargins(margin);
m_cb = new QCheckBox(lbltxt, this); m_cb = new QCheckBox(lbltxt, this);
setSzPol(m_cb, QSizePolicy::Fixed, QSizePolicy::Fixed, 0, 0); setSzPol(m_cb, QSizePolicy::Fixed, QSizePolicy::Fixed, 0, 0);
@ -232,28 +509,34 @@ ConfParamBoolW::ConfParamBoolW(QWidget *parent, ConfLink cflink,
m_hl->addWidget(fr); m_hl->addWidget(fr);
loadValue(); loadValue();
QObject::connect(m_cb, SIGNAL(toggled(bool)), this, SLOT(setValue(bool))); }
void ConfParamBoolW::storeValue()
{
if (m_origvalue != m_cb->isChecked()) {
setValue(m_cb->isChecked());
}
} }
void ConfParamBoolW::loadValue() void ConfParamBoolW::loadValue()
{ {
string s; string s;
m_cflink->get(s); if (!m_cflink->get(s)) {
m_cb->setChecked(stringToBool(s)); m_origvalue = m_dflt;
} else {
m_origvalue = stringToBool(s);
}
m_cb->setChecked(m_origvalue);
} }
ConfParamFNW::ConfParamFNW(QWidget *parent, ConfLink cflink, ConfParamFNW::ConfParamFNW(
const QString& lbltxt, const QString& varnm, QWidget *parent, ConfLink cflink,
const QString& tltptxt, const QString& lbltxt, const QString& tltptxt, bool isdir)
bool isdir, : ConfParamW(varnm, parent, cflink), m_isdir(isdir)
QString dirloc,
QString dfltnm
)
: ConfParamW(parent, cflink), m_isdir(isdir), m_dirloc(dirloc),
m_dfltnm(dfltnm)
{ {
if (!createCommon(lbltxt, tltptxt)) if (!createCommon(lbltxt, tltptxt)) {
return; return;
}
m_fsencoding = true; m_fsencoding = true;
@ -273,48 +556,55 @@ ConfParamFNW::ConfParamFNW(QWidget *parent, ConfLink cflink,
loadValue(); loadValue();
QObject::connect(m_pb, SIGNAL(clicked()), this, SLOT(showBrowserDialog())); QObject::connect(m_pb, SIGNAL(clicked()), this, SLOT(showBrowserDialog()));
QObject::connect(m_le, SIGNAL(textChanged(const QString&)), }
this, SLOT(setValue(const QString&)));
void ConfParamFNW::storeValue()
{
if (m_origvalue.compare(m_le->text())) {
setValue(m_le->text());
}
} }
void ConfParamFNW::loadValue() void ConfParamFNW::loadValue()
{ {
string s; string s;
m_cflink->get(s); m_cflink->get(s);
#ifndef _WIN32 m_le->setText(m_origvalue = QString::fromLocal8Bit(s.c_str()));
// On Windows all paths are unicode.
m_le->setText(QString::fromLocal8Bit(s.c_str()));
#else
m_le->setText(QString::fromUtf8(s.c_str()));
#endif
} }
void ConfParamFNW::showBrowserDialog() void ConfParamFNW::showBrowserDialog()
{ {
QString s = myGetFileName(m_isdir, "", false, m_dirloc, m_dfltnm); QString s = myGetFileName(m_isdir);
if (!s.isEmpty()) if (!s.isEmpty()) {
m_le->setText(s); m_le->setText(s);
} }
}
class SmallerListWidget: public QListWidget class SmallerListWidget: public QListWidget {
{
public: public:
SmallerListWidget(QWidget *parent) SmallerListWidget(QWidget *parent)
: QListWidget(parent) {} : QListWidget(parent) {}
virtual QSize sizeHint() const {return QSize(150, 40);} virtual QSize sizeHint() const {
return QSize(150, 40);
}
}; };
ConfParamSLW::ConfParamSLW(QWidget *parent, ConfLink cflink, ConfParamSLW::ConfParamSLW(
const QString& lbltxt, const QString& varnm, QWidget *parent, ConfLink cflink,
const QString& tltptxt) const QString& lbltxt, const QString& tltptxt)
: ConfParamW(parent, cflink) : ConfParamW(varnm, parent, cflink)
{ {
// Can't use createCommon here cause we want the buttons below the label // Can't use createCommon here cause we want the buttons below the label
m_hl = new QHBoxLayout(this); m_hl = new QHBoxLayout(this);
m_hl->setSpacing(spacing); m_hl->setSpacing(spacing);
m_hl->setContentsMargins(margin);
QVBoxLayout *vl1 = new QVBoxLayout(); QVBoxLayout *vl1 = new QVBoxLayout();
vl1->setSpacing(spacing);
vl1->setContentsMargins(margin);
QHBoxLayout *hl1 = new QHBoxLayout(); QHBoxLayout *hl1 = new QHBoxLayout();
hl1->setSpacing(spacing);
hl1->setContentsMargins(margin);
QLabel *tl = new QLabel(this); QLabel *tl = new QLabel(this);
setSzPol(tl, QSizePolicy::Preferred, QSizePolicy::Fixed, 0, 0); setSzPol(tl, QSizePolicy::Preferred, QSizePolicy::Fixed, 0, 0);
@ -352,22 +642,41 @@ ConfParamSLW::ConfParamSLW(QWidget *parent, ConfLink cflink,
QObject::connect(pbD, SIGNAL(clicked()), this, SLOT(deleteSelected())); QObject::connect(pbD, SIGNAL(clicked()), this, SLOT(deleteSelected()));
} }
void ConfParamSLW::storeValue()
{
vector<string> ls;
for (int i = 0; i < m_lb->count(); i++) {
// General parameters are encoded as utf-8. File names as
// local8bit There is no hope for 8bit file names anyway
// except for luck: the original encoding is unknown.
QString text = m_lb->item(i)->text();
if (m_fsencoding) {
ls.push_back((const char *)(text.toLocal8Bit()));
} else {
ls.push_back((const char *)(text.toUtf8()));
}
}
string s;
stringsToString(ls, s);
if (s.compare(m_origvalue)) {
m_cflink->set(s);
}
}
void ConfParamSLW::loadValue() void ConfParamSLW::loadValue()
{ {
string s; m_origvalue.clear();
m_cflink->get(s); m_cflink->get(m_origvalue);
list<string> ls; vector<string> ls;
stringToStrings(s, ls); stringToStrings(m_origvalue, ls);
QStringList qls; QStringList qls;
for (list<string>::const_iterator it = ls.begin(); it != ls.end(); it++) { for (vector<string>::const_iterator it = ls.begin(); it != ls.end(); it++) {
// On Windows all paths are unicode. if (m_fsencoding) {
#ifndef _WIN32
if (m_fsencoding)
qls.push_back(QString::fromLocal8Bit(it->c_str())); qls.push_back(QString::fromLocal8Bit(it->c_str()));
else } else {
#endif
qls.push_back(QString::fromUtf8(it->c_str())); qls.push_back(QString::fromUtf8(it->c_str()));
} }
}
m_lb->clear(); m_lb->clear();
m_lb->insertItems(0, qls); m_lb->insertItems(0, qls);
} }
@ -388,42 +697,10 @@ void ConfParamSLW::showInputDialog()
if (items.empty()) { if (items.empty()) {
m_lb->insertItem(0, s); m_lb->insertItem(0, s);
m_lb->sortItems(); m_lb->sortItems();
listToConf();
} }
} }
} }
void ConfParamSLW::listToConf()
{
list<string> ls;
LOGDEB2("ConfParamSLW::listToConf. m_fsencoding " << m_fsencoding << "\n");
for (int i = 0; i < m_lb->count(); i++) {
// General parameters are encoded as utf-8. File names as
// local8bit There is no hope for 8bit file names anyway
// except for luck: the original encoding is unknown.
// As a special Windows hack, if fsencoding is set, we convert
// backslashes to slashes. This is an awful hack because
// fsencoding does not necessarily imply that the values are
// paths, and it will come back to haunt us one day.
QString text = m_lb->item(i)->text();
if (m_fsencoding) {
// On Windows all paths are unicode.
#ifdef _WIN32
string pth((const char *)(text.toUtf8()));
path_slashize(pth);
ls.push_back(pth);
#else
ls.push_back((const char *)(text.toLocal8Bit()));
#endif
} else {
ls.push_back((const char *)(text.toUtf8()));
}
}
string s;
stringsToString(ls, s);
m_cflink->set(s);
}
void ConfParamSLW::deleteSelected() void ConfParamSLW::deleteSelected()
{ {
// We used to repeatedly go through the list and delete the first // We used to repeatedly go through the list and delete the first
@ -444,13 +721,10 @@ void ConfParamSLW::deleteSelected()
} }
for (vector<int>::reverse_iterator it = idxes.rbegin(); for (vector<int>::reverse_iterator it = idxes.rbegin();
it != idxes.rend(); it++) { it != idxes.rend(); it++) {
LOGDEB0("deleteSelected: " << *it << " was selected\n");
QListWidgetItem *item = m_lb->takeItem(*it); QListWidgetItem *item = m_lb->takeItem(*it);
emit entryDeleted(item->text()); emit entryDeleted(item->text());
delete item; delete item;
} }
listToConf();
} }
// "Add entry" dialog for a file name list // "Add entry" dialog for a file name list
@ -466,9 +740,9 @@ void ConfParamDNLW::showInputDialog()
QList<QListWidgetItem *>items = QList<QListWidgetItem *>items =
m_lb->findItems(s, Qt::MatchFixedString | Qt::MatchCaseSensitive); m_lb->findItems(s, Qt::MatchFixedString | Qt::MatchCaseSensitive);
if (m_lb->selectionMode() == QAbstractItemView::SingleSelection && if (m_lb->selectionMode() == QAbstractItemView::SingleSelection &&
!items.empty()) !items.empty()) {
m_lb->setCurrentItem(*items.begin()); m_lb->setCurrentItem(*items.begin());
listToConf(); }
} }
} }
} }
@ -491,9 +765,224 @@ void ConfParamCSLW::showInputDialog()
if (items.empty()) { if (items.empty()) {
m_lb->insertItem(0, s); m_lb->insertItem(0, s);
m_lb->sortItems(); m_lb->sortItems();
listToConf();
} }
} }
} }
#ifdef ENABLE_XMLCONF
static QString u8s2qs(const std::string us)
{
return QString::fromUtf8(us.c_str());
}
static const string& mapfind(const string& nm, const map<string, string>& mp)
{
static string strnull;
map<string, string>::const_iterator it;
it = mp.find(nm);
if (it == mp.end()) {
return strnull;
}
return it->second;
}
static string looksLikeAssign(const string& data)
{
//LOGDEB("looksLikeAssign. data: [" << data << "]");
vector<string> toks;
stringToTokens(data, toks, "\n\r\t ");
if (toks.size() >= 2 && !toks[1].compare("=")) {
return toks[0];
}
return string();
}
ConfTabsW *xmlToConfGUI(const string& xml, string& toptext,
ConfLinkFact* lnkf, QWidget *parent)
{
//LOGDEB("xmlToConfGUI: [" << xml << "]");
class XMLToConfGUI : public PicoXMLParser {
public:
XMLToConfGUI(const string& x, ConfLinkFact *lnkf, QWidget *parent)
: PicoXMLParser(x), m_lnkfact(lnkf), m_parent(parent),
m_idx(0), m_hadTitle(false), m_hadGroup(false) {
}
virtual ~XMLToConfGUI() {}
virtual void startElement(const string& tagname,
const map<string, string>& attrs) {
if (!tagname.compare("var")) {
m_curvar = mapfind("name", attrs);
m_curvartp = mapfind("type", attrs);
m_curvarvals = mapfind("values", attrs);
//LOGDEB("Curvar: " << m_curvar);
if (m_curvar.empty() || m_curvartp.empty()) {
throw std::runtime_error(
"<var> with no name attribute or no type ! nm [" +
m_curvar + "] tp [" + m_curvartp + "]");
} else {
m_brief.clear();
m_descr.clear();
}
} else if (!tagname.compare("filetitle") ||
!tagname.compare("grouptitle")) {
m_other.clear();
}
}
virtual void endElement(const string& tagname) {
if (!tagname.compare("var")) {
if (!m_hadTitle) {
m_w = new ConfTabsW(m_parent, "Teh title", m_lnkfact);
m_hadTitle = true;
}
if (!m_hadGroup) {
m_idx = m_w->addPanel("Group title");
m_hadGroup = true;
}
ConfTabsW::ParamType paramtype;
if (!m_curvartp.compare("bool")) {
paramtype = ConfTabsW::CFPT_BOOL;
} else if (!m_curvartp.compare("int")) {
paramtype = ConfTabsW::CFPT_INT;
} else if (!m_curvartp.compare("string")) {
paramtype = ConfTabsW::CFPT_STR;
} else if (!m_curvartp.compare("cstr")) {
paramtype = ConfTabsW::CFPT_CSTR;
} else if (!m_curvartp.compare("cstrl")) {
paramtype = ConfTabsW::CFPT_CSTRL;
} else if (!m_curvartp.compare("fn")) {
paramtype = ConfTabsW::CFPT_FN;
} else if (!m_curvartp.compare("dfn")) {
paramtype = ConfTabsW::CFPT_FN;
} else if (!m_curvartp.compare("strl")) {
paramtype = ConfTabsW::CFPT_STRL;
} else if (!m_curvartp.compare("dnl")) {
paramtype = ConfTabsW::CFPT_DNL;
} else {
throw std::runtime_error("Bad type " + m_curvartp +
" for " + m_curvar);
}
rtrimstring(m_brief, " .");
switch (paramtype) {
case ConfTabsW::CFPT_BOOL: {
int def = atoi(m_curvarvals.c_str());
m_w->addParam(m_idx, paramtype, u8s2qs(m_curvar),
u8s2qs(m_brief), u8s2qs(m_descr), def);
break;
}
case ConfTabsW::CFPT_INT: {
vector<string> vals;
stringToTokens(m_curvarvals, vals);
int min = 0, max = 0, def = 0;
if (vals.size() >= 3) {
min = atoi(vals[0].c_str());
max = atoi(vals[1].c_str());
def = atoi(vals[2].c_str());
}
QStringList *sldef = 0;
sldef = (QStringList*)(((char*)sldef) + def);
m_w->addParam(m_idx, paramtype, u8s2qs(m_curvar),
u8s2qs(m_brief), u8s2qs(m_descr),
min, max, sldef);
break;
}
case ConfTabsW::CFPT_CSTR:
case ConfTabsW::CFPT_CSTRL: {
vector<string> cstrl;
stringToTokens(neutchars(m_curvarvals, "\n\r"), cstrl);
QStringList qstrl;
for (unsigned int i = 0; i < cstrl.size(); i++) {
qstrl.push_back(u8s2qs(cstrl[i]));
}
m_w->addParam(m_idx, paramtype, u8s2qs(m_curvar),
u8s2qs(m_brief), u8s2qs(m_descr),
0, 0, &qstrl);
break;
}
default:
m_w->addParam(m_idx, paramtype, u8s2qs(m_curvar),
u8s2qs(m_brief), u8s2qs(m_descr));
}
} else if (!tagname.compare("filetitle")) {
m_w = new ConfTabsW(m_parent, u8s2qs(m_other), m_lnkfact);
m_hadTitle = true;
m_other.clear();
} else if (!tagname.compare("grouptitle")) {
if (!m_hadTitle) {
m_w = new ConfTabsW(m_parent, "Teh title", m_lnkfact);
m_hadTitle = true;
}
// Get rid of "parameters" in the title, it's not interesting
// and this makes our tab headers smaller.
string ps{"parameters"};
string::size_type pos = m_other.find(ps);
if (pos != string::npos) {
m_other = m_other.replace(pos, ps.size(), "");
}
m_idx = m_w->addPanel(u8s2qs(m_other));
m_hadGroup = true;
m_other.clear();
} else if (!tagname.compare("descr")) {
} else if (!tagname.compare("brief")) {
m_brief = neutchars(m_brief, "\n\r");
}
}
virtual void characterData(const string& data) {
if (!tagStack().back().compare("brief")) {
m_brief += data;
} else if (!tagStack().back().compare("descr")) {
m_descr += data;
} else if (!tagStack().back().compare("filetitle") ||
!tagStack().back().compare("grouptitle")) {
// We don't want \n in there
m_other += neutchars(data, "\n\r");
m_other += " ";
} else if (!tagStack().back().compare("confcomments")) {
string nvarname = looksLikeAssign(data);
if (!nvarname.empty() && nvarname.compare(m_curvar)) {
cerr << "Var assigned [" << nvarname << "] mismatch "
"with current variable [" << m_curvar << "]\n";
}
m_toptext += data;
}
}
ConfTabsW *m_w;
ConfLinkFact *m_lnkfact;
QWidget *m_parent;
int m_idx;
string m_curvar;
string m_curvartp;
string m_curvarvals;
string m_brief;
string m_descr;
string m_other;
string m_toptext;
bool m_hadTitle;
bool m_hadGroup;
};
XMLToConfGUI parser(xml, lnkf, parent);
try {
if (!parser.parse()) {
cerr << "Parse failed: " << parser.getReason() << endl;
return 0;
}
} catch (const std::runtime_error& e) {
cerr << e.what() << endl;
return 0;
}
toptext = parser.m_toptext;
return parser.m_w;
}
#endif /* ENABLE_XMLCONF */
} // Namespace confgui } // Namespace confgui

View File

@ -1,23 +1,21 @@
/* Copyright (C) 2007 J.F.Dockes /* Copyright (C) 2007-2018 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 Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the * along with this program; if not, write to the
* Free Software Foundation, Inc., * Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef _confgui_h_included_ #ifndef _confgui_h_included_
#define _confgui_h_included_ #define _confgui_h_included_
#include "autoconfig.h"
/** /**
* This file defines a number of simple classes (virtual base: ConfParamW) * This file defines a number of simple classes (virtual base: ConfParamW)
* which let the user input configuration parameters. * which let the user input configuration parameters.
@ -37,28 +35,42 @@
* is then copied to the actual configuration if the data is accepted, or * is then copied to the actual configuration if the data is accepted, or
* destroyed and recreated as a copy if Cancel is pressed (you have to * destroyed and recreated as a copy if Cancel is pressed (you have to
* delete/recreate the widgets in this case as the links are no longer valid). * delete/recreate the widgets in this case as the links are no longer valid).
*
* The set() methods of the link objects are only called if the
* current value() differs from the value obtained by get() when the
* object was initialized. This can be used to avoid cluttering the
* output with values which are unmodified from the defaults.
*
* The file also defines a multi-tabbed dialog container for the
* parameter objects, with simple interface methods to create/add
* panels and elements.
*/ */
#include <string> #include <string>
#include <limits.h> #include <limits.h>
#include <qglobal.h>
#include <qstring.h>
#include <qwidget.h>
#include <memory> #include <memory>
#include <vector>
#include <string>
#include <QString>
#include <QWidget>
#include <QDialog>
class QCheckBox;
class QComboBox;
class QDialogButtonBox;
class QHBoxLayout; class QHBoxLayout;
class QLineEdit; class QLineEdit;
class QListWidget; class QListWidget;
class QSpinBox;
class QComboBox;
class QCheckBox;
class QPushButton; class QPushButton;
class QSpinBox;
class QTabWidget;
class QVBoxLayout;
namespace confgui { namespace confgui {
// A class to isolate the gui widget from the config storage mechanism /** Interface between the GUI widget and the config storage mechanism: */
class ConfLinkRep { class ConfLinkRep {
public: public:
virtual ~ConfLinkRep() {} virtual ~ConfLinkRep() {}
@ -67,104 +79,152 @@ namespace confgui {
}; };
typedef std::shared_ptr<ConfLinkRep> ConfLink; typedef std::shared_ptr<ConfLinkRep> ConfLink;
// Useful to store/manage data which has no direct representation in // May be used to store/manage data which has no direct representation
// the config, ie list of subkey directories // in the config
class ConfLinkNullRep : public ConfLinkRep { class ConfLinkNullRep : public ConfLinkRep {
public: public:
virtual ~ConfLinkNullRep() {} virtual ~ConfLinkNullRep() {}
virtual bool set(const std::string&) virtual bool set(const std::string&) {
{
return true; return true;
} }
virtual bool get(std::string& val) {val = ""; return true;} virtual bool get(std::string& val) {val = ""; return true;}
}; };
// A widget to let the user change one configuration /** Link maker class */
// parameter. Subclassed for specific parameter types. Basically class ConfLinkFact {
// has a label and some kind of entry widget public:
virtual ~ConfLinkFact() {}
virtual ConfLink operator()(const QString& nm) = 0;
};
class ConfPanelWIF {
public:
virtual ~ConfPanelWIF() {}
virtual void storeValues() = 0;
virtual void loadValues() = 0;
};
class ConfPanelW;
class ConfParamW;
/** The top level widget has tabs, each tab/panel has multiple widgets
* for setting parameter values */
class ConfTabsW : public QDialog {
Q_OBJECT;
public:
ConfTabsW(QWidget *parent, const QString& title, ConfLinkFact *linkfact);
enum ParamType {CFPT_BOOL, CFPT_INT, CFPT_STR, CFPT_CSTR, CFPT_FN,
CFPT_STRL, CFPT_DNL, CFPT_CSTRL
};
/** Add tab and return its identifier / index */
int addPanel(const QString& title);
/** Add foreign tab where we only know to call loadvalues/storevalues.
* The object has to derive from QWidget */
int addForeignPanel(ConfPanelWIF* w, const QString& title);
/** Add parameter setter to specified tab */
ConfParamW *addParam(int tabindex, ParamType tp,
const QString& varname, const QString& label,
const QString& tooltip, int isdirorminval = 0,
int maxval = 0, const QStringList* sl = 0);
bool enableLink(ConfParamW* boolw, ConfParamW* otherw, bool revert = false);
void endOfList(int tabindex);
/** Find param widget associated with given variable name */
ConfParamW *findParamW(const QString& varname);
void hideButtons();
public slots:
void acceptChanges();
void rejectChanges();
void reloadPanels();
void setCurrentIndex(int);
signals:
/** This is emitted when acceptChanges() is called, after the
* values have been stored */
void sig_prefsChanged();
private:
ConfLinkFact *m_makelink{nullptr};
std::vector<ConfPanelW *> m_panels;
// "Foreign" panels
std::vector<ConfPanelWIF *> m_widgets;
// All params
std::vector<ConfParamW *> m_params;
QTabWidget *tabWidget{nullptr};
QDialogButtonBox *buttonBox{nullptr};
};
/////////////////////////////////////////////////
// The rest of the class definitions are only useful if you need to
// access a specific element for customisation (use findParamW() and a
// dynamic cast).
/** A panel/tab contains multiple controls for parameters */
class ConfPanelW : public QWidget {
Q_OBJECT
public:
ConfPanelW(QWidget *parent);
void addWidget(QWidget *w);
void storeValues();
void loadValues();
void endOfList();
private:
QVBoxLayout *m_vboxlayout;
std::vector<QWidget *> m_widgets;
};
/** Config panel element: manages one configuration
* parameter. Subclassed for specific parameter types.
*/
class ConfParamW : public QWidget { class ConfParamW : public QWidget {
Q_OBJECT Q_OBJECT
public: public:
ConfParamW(QWidget *parent, ConfLink cflink) ConfParamW(const QString& varnm, QWidget *parent, ConfLink cflink)
: QWidget(parent), m_cflink(cflink), m_fsencoding(false) : QWidget(parent), m_varname(varnm),
{ m_cflink(cflink), m_fsencoding(false) {
} }
virtual void loadValue() = 0; virtual void loadValue() = 0;
virtual void setFsEncoding(bool onoff) {m_fsencoding = onoff;} virtual void setFsEncoding(bool onoff) {
m_fsencoding = onoff;
}
const QString& getVarName() {
return m_varname;
}
public slots:
virtual void setEnabled(bool) = 0;
virtual void storeValue() = 0;
protected: protected:
QString m_varname;
ConfLink m_cflink; ConfLink m_cflink;
QHBoxLayout *m_hl; QHBoxLayout *m_hl;
// File names are encoded as local8bit in the config files. Other // File names are encoded as local8bit in the config files. Other
// are encoded as utf-8 // are encoded as utf-8
bool m_fsencoding; bool m_fsencoding;
virtual bool createCommon(const QString& lbltxt, virtual bool createCommon(const QString& lbltxt, const QString& tltptxt);
const QString& tltptxt);
public slots:
virtual void setEnabled(bool) = 0;
protected slots:
void setValue(const QString& newvalue); void setValue(const QString& newvalue);
void setValue(int newvalue); void setValue(int newvalue);
void setValue(bool newvalue); void setValue(bool newvalue);
}; };
// Widgets for setting the different types of configuration parameters: //////// Widgets for setting the different types of configuration parameters:
// Int /** Boolean */
class ConfParamIntW : public ConfParamW {
Q_OBJECT
public:
// The default value is only used if none exists in the sample
// configuration file. Defaults are normally set in there.
ConfParamIntW(QWidget *parent, ConfLink cflink,
const QString& lbltxt,
const QString& tltptxt,
int minvalue = INT_MIN,
int maxvalue = INT_MAX,
int defaultvalue = 0);
virtual void loadValue();
public slots:
virtual void setEnabled(bool i) {if(m_sb) ((QWidget*)m_sb)->setEnabled(i);}
protected:
QSpinBox *m_sb;
int m_defaultvalue;
};
// Arbitrary string
class ConfParamStrW : public ConfParamW {
Q_OBJECT
public:
ConfParamStrW(QWidget *parent, ConfLink cflink,
const QString& lbltxt,
const QString& tltptxt);
virtual void loadValue();
public slots:
virtual void setEnabled(bool i) {if(m_le) ((QWidget*)m_le)->setEnabled(i);}
protected:
QLineEdit *m_le;
};
// Constrained string: choose from list
class ConfParamCStrW : public ConfParamW {
Q_OBJECT
public:
ConfParamCStrW(QWidget *parent, ConfLink cflink,
const QString& lbltxt,
const QString& tltptxt, const QStringList& sl);
virtual void loadValue();
public slots:
virtual void setEnabled(bool i) {if(m_cmb) ((QWidget*)m_cmb)->setEnabled(i);}
protected:
QComboBox *m_cmb;
};
// Boolean
class ConfParamBoolW : public ConfParamW { class ConfParamBoolW : public ConfParamW {
Q_OBJECT Q_OBJECT
public: public:
ConfParamBoolW(QWidget *parent, ConfLink cflink, ConfParamBoolW(const QString& varnm, QWidget *parent, ConfLink cflink,
const QString& lbltxt, const QString& lbltxt,
const QString& tltptxt); const QString& tltptxt, bool deflt = false);
virtual void loadValue(); virtual void loadValue();
virtual void storeValue();
public slots: public slots:
virtual void setEnabled(bool i) { virtual void setEnabled(bool i) {
if (m_cb) { if (m_cb) {
@ -173,46 +233,123 @@ namespace confgui {
} }
public: public:
QCheckBox *m_cb; QCheckBox *m_cb;
bool m_dflt;
bool m_origvalue;
};
// Int
class ConfParamIntW : public ConfParamW {
Q_OBJECT
public:
// The default value is only used if none exists in the sample
// configuration file. Defaults are normally set in there.
ConfParamIntW(const QString& varnm, QWidget *parent, ConfLink cflink,
const QString& lbltxt,
const QString& tltptxt,
int minvalue = INT_MIN,
int maxvalue = INT_MAX,
int defaultvalue = 0);
virtual void loadValue();
virtual void storeValue();
public slots:
virtual void setEnabled(bool i) {
if (m_sb) {
((QWidget*)m_sb)->setEnabled(i);
}
}
protected:
QSpinBox *m_sb;
int m_defaultvalue;
int m_origvalue;
};
// Arbitrary string
class ConfParamStrW : public ConfParamW {
Q_OBJECT
public:
ConfParamStrW(const QString& varnm, QWidget *parent, ConfLink cflink,
const QString& lbltxt,
const QString& tltptxt);
virtual void loadValue();
virtual void storeValue();
public slots:
virtual void setEnabled(bool i) {
if (m_le) {
((QWidget*)m_le)->setEnabled(i);
}
}
protected:
QLineEdit *m_le;
QString m_origvalue;
};
// Constrained string: choose from list
class ConfParamCStrW : public ConfParamW {
Q_OBJECT
public:
ConfParamCStrW(const QString& varnm, QWidget *parent, ConfLink cflink,
const QString& lbltxt,
const QString& tltptxt, const QStringList& sl);
virtual void loadValue();
virtual void storeValue();
virtual void setList(const QStringList& sl);
public slots:
virtual void setEnabled(bool i) {
if (m_cmb) {
((QWidget*)m_cmb)->setEnabled(i);
}
}
protected:
QComboBox *m_cmb;
QString m_origvalue;
}; };
// File name // File name
class ConfParamFNW : public ConfParamW { class ConfParamFNW : public ConfParamW {
Q_OBJECT Q_OBJECT
public: public:
ConfParamFNW(QWidget *parent, ConfLink cflink, ConfParamFNW(const QString& varnm, QWidget *parent, ConfLink cflink,
const QString& lbltxt, const QString& lbltxt,
const QString& tltptxt, bool isdir = false, const QString& tltptxt, bool isdir = false);
QString dirloc = QString(),
QString dfltnm = QString()
);
virtual void loadValue(); virtual void loadValue();
virtual void storeValue();
protected slots: protected slots:
void showBrowserDialog(); void showBrowserDialog();
public slots: public slots:
virtual void setEnabled(bool i) { virtual void setEnabled(bool i) {
if(m_le) ((QWidget*)m_le)->setEnabled(i); if (m_le) {
if(m_pb) ((QWidget*)m_pb)->setEnabled(i); ((QWidget*)m_le)->setEnabled(i);
}
if (m_pb) {
((QWidget*)m_pb)->setEnabled(i);
}
} }
protected: protected:
QLineEdit *m_le; QLineEdit *m_le;
QPushButton *m_pb; QPushButton *m_pb;
bool m_isdir; bool m_isdir;
QString m_dirloc; QString m_origvalue;
QString m_dfltnm;
}; };
// String list // String list
class ConfParamSLW : public ConfParamW { class ConfParamSLW : public ConfParamW {
Q_OBJECT Q_OBJECT
public: public:
ConfParamSLW(QWidget *parent, ConfLink cflink, ConfParamSLW(const QString& varnm, QWidget *parent, ConfLink cflink,
const QString& lbltxt, const QString& lbltxt,
const QString& tltptxt); const QString& tltptxt);
virtual void loadValue(); virtual void loadValue();
QListWidget *getListBox() {return m_lb;} virtual void storeValue();
QListWidget *getListBox() {
return m_lb;
}
public slots: public slots:
virtual void setEnabled(bool i) {if(m_lb) ((QWidget*)m_lb)->setEnabled(i);} virtual void setEnabled(bool i) {
if (m_lb) {
((QWidget*)m_lb)->setEnabled(i);
}
}
protected slots: protected slots:
virtual void showInputDialog(); virtual void showInputDialog();
void deleteSelected(); void deleteSelected();
@ -221,17 +358,17 @@ namespace confgui {
protected: protected:
QListWidget *m_lb; QListWidget *m_lb;
void listToConf(); void listToConf();
std::string m_origvalue;
}; };
// Dir name list // Dir name list
class ConfParamDNLW : public ConfParamSLW { class ConfParamDNLW : public ConfParamSLW {
Q_OBJECT Q_OBJECT
public: public:
ConfParamDNLW(QWidget *parent, ConfLink cflink, ConfParamDNLW(const QString& varnm, QWidget *parent, ConfLink cflink,
const QString& lbltxt, const QString& lbltxt,
const QString& tltptxt) const QString& tltptxt)
: ConfParamSLW(parent, cflink, lbltxt, tltptxt) : ConfParamSLW(varnm, parent, cflink, lbltxt, tltptxt) {
{
m_fsencoding = true; m_fsencoding = true;
} }
protected slots: protected slots:
@ -242,12 +379,11 @@ namespace confgui {
class ConfParamCSLW : public ConfParamSLW { class ConfParamCSLW : public ConfParamSLW {
Q_OBJECT Q_OBJECT
public: public:
ConfParamCSLW(QWidget *parent, ConfLink cflink, ConfParamCSLW(const QString& varnm, QWidget *parent, ConfLink cflink,
const QString& lbltxt, const QString& lbltxt,
const QString& tltptxt, const QString& tltptxt,
const QStringList& sl) const QStringList& sl)
: ConfParamSLW(parent, cflink, lbltxt, tltptxt), m_sl(sl) : ConfParamSLW(varnm, parent, cflink, lbltxt, tltptxt), m_sl(sl) {
{
} }
protected slots: protected slots:
virtual void showInputDialog(); virtual void showInputDialog();
@ -258,6 +394,56 @@ namespace confgui {
extern void setSzPol(QWidget *w, QSizePolicy::Policy hpol, extern void setSzPol(QWidget *w, QSizePolicy::Policy hpol,
QSizePolicy::Policy vpol, QSizePolicy::Policy vpol,
int hstretch, int vstretch); int hstretch, int vstretch);
#ifdef ENABLE_XMLCONF
/**
* Interpret an XML string and create a configuration interface. XML sample:
*
* <confcomments>
* <filetitle>Configuration file parameters for upmpdcli</filetitle>
* <grouptitle>MPD parameters</grouptitle>
* <var name="mpdhost" type="string">
* <brief>Host MPD runs on.</brief>
* <descr>Defaults to localhost. This can also be specified as -h</descr>
* </var>
* mpdhost = default-host
* <var name="mpdport" type="int" values="0 65635 6600">
* <brief>IP port used by MPD</brief>.
* <descr>Can also be specified as -p port. Defaults to the...</descr>
* </var>
* mpdport = defport
* <var name="ownqueue" type="bool" values="1">
* <brief>Set if we own the MPD queue.</brief>
* <descr>If this is set (on by default), we own the MPD...</descr>
* </var>
* ownqueue =
* </confcomments>
*
* <grouptitle> creates a panel in which the following <var> are set.
* The <var> attributes should be self-explanatory. "values"
* is used for different things depending on the var type
* (min/max, default, str list). Check the code about this.
* type values: "bool" "int" "string" "cstr" "cstrl" "fn" "dfn" "strl" "dnl"
*
* The XML would typically exist as comments inside a reference configuration
* file (ConfSimple can extract such comments).
*
* This means that the reference configuration file can generate both
* the documentation and the GUI interface.
*
* @param xml the input xml
* @param[output] toptxt the top level XML text (text not inside <var>,
* normally commented variable assignments). This will be evaluated
* as a config for default values.
* @lnkf factory to create the objects which link the GUI to the
* storage mechanism.
*/
extern ConfTabsW *xmlToConfGUI(const std::string& xml,
std::string& toptxt,
ConfLinkFact* lnkf,
QWidget *parent);
#endif
} }
#endif /* _confgui_h_included_ */ #endif /* _confgui_h_included_ */

View File

@ -28,15 +28,14 @@
#include <qcheckbox.h> #include <qcheckbox.h>
#include <QListWidget> #include <QListWidget>
#include <list> #include <vector>
#include <set> #include <set>
#include <string> #include <string>
#include <functional> #include <functional>
using std::list; using std::vector;
using std::set; using std::set;
using std::string; using std::string;
#include "confgui.h"
#include "recoll.h" #include "recoll.h"
#include "confguiindex.h" #include "confguiindex.h"
#include "smallut.h" #include "smallut.h"
@ -45,36 +44,32 @@ using std::string;
#include "execmd.h" #include "execmd.h"
#include "rclconfig.h" #include "rclconfig.h"
namespace confgui {
static const int spacing = 3; static const int spacing = 3;
static const int margin = 3; static const int margin = 3;
/** using namespace confgui;
* A Gui-to-Data link class for ConfTree
* Has a subkey pointer member which makes it easy to change the /* Link class for ConfTree. Has a subkey pointer member which makes it easy
* current subkey for a number at a time. * to change the current subkey for multiple instances. */
*/
class ConfLinkRclRep : public ConfLinkRep { class ConfLinkRclRep : public ConfLinkRep {
public: public:
ConfLinkRclRep(ConfNull *conf, const string& nm, ConfLinkRclRep(ConfNull **conf, const string& nm, string *sk = 0)
string *sk = 0)
: m_conf(conf), m_nm(nm), m_sk(sk) /* KEEP THE POINTER, shared data */ : m_conf(conf), m_nm(nm), m_sk(sk) /* KEEP THE POINTER, shared data */
{} {}
virtual ~ConfLinkRclRep() {} virtual ~ConfLinkRclRep() {}
virtual bool set(const string& val) { virtual bool set(const string& val) {
if (!m_conf) if (!m_conf || !*m_conf)
return false; return false;
LOGDEB1("Setting [" << m_nm << "] value to [" << val << "]\n"); bool ret = (*m_conf)->set(m_nm, val, getSk());
bool ret = m_conf->set(m_nm, val, getSk());
if (!ret) if (!ret)
LOGERR("Value set failed\n" ); LOGERR("Value set failed\n" );
return ret; return ret;
} }
virtual bool get(string& val) { virtual bool get(string& val) {
if (!m_conf) if (!m_conf || !*m_conf)
return false; return false;
bool ret = m_conf->get(m_nm, val, getSk()); bool ret = (*m_conf)->get(m_nm, val, getSk());
LOGDEB1("ConfLinkRcl::get: [" << m_nm << "] sk [" << LOGDEB1("ConfLinkRcl::get: [" << m_nm << "] sk [" <<
getSk() << "] -> [" << (ret ? val : "no value") << "]\n"); getSk() << "] -> [" << (ret ? val : "no value") << "]\n");
return ret; return ret;
@ -83,57 +78,56 @@ private:
string getSk() { string getSk() {
return m_sk ? *m_sk : string(); return m_sk ? *m_sk : string();
} }
ConfNull *m_conf; ConfNull **m_conf;
const string m_nm; const string m_nm;
const string *m_sk; const string *m_sk;
}; };
typedef std::function<vector<string>()> RclConfVecValueGetter;
/* Special link for skippedNames and noContentSuffixes which are /* Special link for skippedNames and noContentSuffixes which are
computed as set differences */ computed as set differences */
typedef std::function<vector<string>()> RclConfVecValueGetter;
class ConfLinkPlusMinus : public ConfLinkRep { class ConfLinkPlusMinus : public ConfLinkRep {
public: public:
ConfLinkPlusMinus(RclConfig *rclconf, ConfNull *conf, ConfLinkPlusMinus(RclConfig *rclconf, ConfNull **conf,
const string& basename, RclConfVecValueGetter getter, const string& basename, RclConfVecValueGetter getter,
string *sk = 0) string *sk = 0)
: m_rclconf(rclconf), m_conf(conf), : m_rclconf(rclconf), m_conf(conf),
m_basename(basename), m_getter(getter), m_basename(basename), m_getter(getter),
m_sk(sk) /* KEEP THE POINTER, shared data */ m_sk(sk) /* KEEP THE POINTER, shared data */ {
{
} }
virtual ~ConfLinkPlusMinus() {} virtual ~ConfLinkPlusMinus() {}
virtual bool set(const string& snval) { virtual bool set(const string& snval) {
if (!m_conf || !m_rclconf) if (!m_conf || !*m_conf || !m_rclconf)
return false; return false;
string sbase; string sbase;
m_conf->get(m_basename, sbase, getSk()); (*m_conf)->get(m_basename, sbase, getSk());
std::set<string> nval; std::set<string> nval;
stringToStrings(snval, nval); stringToStrings(snval, nval);
string splus, sminus; string splus, sminus;
RclConfig::setPlusMinus(sbase, nval, splus, sminus); RclConfig::setPlusMinus(sbase, nval, splus, sminus);
LOGDEB1("ConfLinkPlusMinus: base [" << sbase << "] nvalue [" << snval << LOGDEB1("ConfLinkPlusMinus: base [" << sbase << "] nvalue [" << snval <<
"] splus [" << splus << "] sminus [" << sminus << "]\n"); "] splus [" << splus << "] sminus [" << sminus << "]\n");
if (!m_conf->set(m_basename + "-", sminus, getSk())) { if (!(*m_conf)->set(m_basename + "-", sminus, getSk())) {
return false; return false;
} }
if (!m_conf->set(m_basename + "+", splus, getSk())) { if (!(*m_conf)->set(m_basename + "+", splus, getSk())) {
return false; return false;
} }
return true; return true;
} }
virtual bool get(string& val) { virtual bool get(string& val) {
if (!m_conf || !m_rclconf) LOGDEB("ConfLinPlusMinus::get [" << m_basename << "]\n");
if (!m_conf || !*m_conf || !m_rclconf)
return false; return false;
m_rclconf->setKeyDir(getSk()); m_rclconf->setKeyDir(getSk());
vector<string> vval = m_getter(); vector<string> vval = m_getter();
val = stringsToString(vval); val = stringsToString(vval);
LOGDEB1("ConfLinkPlusMinus: "<<m_basename<<" -> " << val <<std::endl); LOGDEB1("ConfLinkPlusMinus: " << m_basename << " -> " << val << "\n");
return true; return true;
} }
@ -143,34 +137,58 @@ private:
} }
RclConfig *m_rclconf; RclConfig *m_rclconf;
ConfNull *m_conf; ConfNull **m_conf;
string m_basename; string m_basename;
RclConfVecValueGetter m_getter; RclConfVecValueGetter m_getter;
const string *m_sk; const string *m_sk;
}; };
ConfIndexW::ConfIndexW(QWidget *parent, RclConfig *config) class MyConfLinkFactRCL : public ConfLinkFact {
: QDialog(parent), m_rclconf(config) public:
MyConfLinkFactRCL() {}
MyConfLinkFactRCL(ConfNull **conf, string *sk = 0)
: m_conf(conf), m_sk(sk) /* KEEP THE POINTER, shared data */
{}
virtual ConfLink operator()(const QString& nm) {
ConfLinkRep *lnk = new ConfLinkRclRep(m_conf, qs2utf8s(nm), m_sk);
return ConfLink(lnk);
}
ConfNull **m_conf{nullptr};
string *m_sk{nullptr};
};
string sknull;
static MyConfLinkFactRCL conflinkfactory;
void ConfIndexW::showPrefs(bool modal)
{ {
QString title(tr("Recoll - Index Settings: ")); delete m_conf;
title += QString::fromLocal8Bit(config->getConfDir().c_str()); if (((m_conf = m_rclconf->cloneMainConfig()) == 0)) {
setWindowTitle(title); return;
tabWidget = new QTabWidget; }
reloadPanels(); m_conf->holdWrites(true);
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok if (nullptr == m_w) {
| QDialogButtonBox::Cancel); QString title = u8s2qs("Recoll - Index Settings: ");
title += QString::fromLocal8Bit(m_rclconf->getConfDir().c_str());
conflinkfactory = MyConfLinkFactRCL(&m_conf, &sknull);
if (nullptr == (m_w = new ConfTabsW(this, title, &conflinkfactory))) {
return;
}
connect(m_w, SIGNAL(sig_prefsChanged()), this, SLOT(acceptChanges()));
initPanels();
} else {
m_w->hide();
}
QVBoxLayout *mainLayout = new QVBoxLayout; m_w->reloadPanels();
mainLayout->addWidget(tabWidget); if (modal) {
mainLayout->addWidget(buttonBox); m_w->exec();
setLayout(mainLayout); m_w->setModal(false);
} else {
resize(QSize(600, 450).expandedTo(minimumSizeHint())); m_w->show();
}
connect(buttonBox, SIGNAL(accepted()), this, SLOT(acceptChanges()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(rejectChanges()));
} }
void ConfIndexW::acceptChanges() void ConfIndexW::acceptChanges()
@ -180,7 +198,6 @@ void ConfIndexW::acceptChanges()
LOGERR("ConfIndexW::acceptChanges: no config\n" ); LOGERR("ConfIndexW::acceptChanges: no config\n" );
return; return;
} }
// Let the changes to disk
if (!m_conf->holdWrites(false)) { if (!m_conf->holdWrites(false)) {
QMessageBox::critical(0, "Recoll", QMessageBox::critical(0, "Recoll",
tr("Can't write configuration file")); tr("Can't write configuration file"));
@ -189,253 +206,85 @@ void ConfIndexW::acceptChanges()
delete m_conf; delete m_conf;
m_conf = 0; m_conf = 0;
m_rclconf->updateMainConfig(); m_rclconf->updateMainConfig();
hide();
} }
void ConfIndexW::rejectChanges() void ConfIndexW::initPanels()
{ {
LOGDEB("ConfIndexW::rejectChanges()\n" ); int idx = m_w->addPanel(tr("Global parameters"));
// Discard local changes. setupTopPanel(idx);
delete m_conf;
m_conf = 0;
hide();
}
void ConfIndexW::reloadPanels() idx = m_w->addForeignPanel(
{ new ConfSubPanelW(m_w, &m_conf, m_rclconf),
if ((m_conf = m_rclconf->cloneMainConfig()) == 0) tr("Local parameters"));
return;
m_conf->holdWrites(true);
tabWidget->clear();
m_widgets.clear();
QWidget *w = new ConfTopPanelW(this, m_conf);
m_widgets.push_back(w);
tabWidget->addTab(w, QObject::tr("Global parameters"));
w = new ConfSubPanelW(this, m_conf, m_rclconf);
m_widgets.push_back(w);
tabWidget->addTab(w, QObject::tr("Local parameters"));
#ifndef _WIN32 #ifndef _WIN32
w = new ConfBeaglePanelW(this, m_conf); idx = m_w->addPanel("Web history");
m_widgets.push_back(w); setupWebHistoryPanel(idx);
tabWidget->addTab(w, QObject::tr("Web history"));
#endif #endif
w = new ConfSearchPanelW(this, m_conf);
m_widgets.push_back(w); idx = m_w->addPanel(tr("Search parameters"));
tabWidget->addTab(w, QObject::tr("Search parameters")); setupSearchPanel(idx);
} }
ConfBeaglePanelW::ConfBeaglePanelW(QWidget *parent, ConfNull *config) bool ConfIndexW::setupTopPanel(int idx)
: QWidget(parent)
{ {
QVBoxLayout *vboxLayout = new QVBoxLayout(this); m_w->addParam(idx, ConfTabsW::CFPT_DNL, "topdirs",
vboxLayout->setSpacing(spacing);
vboxLayout->setMargin(margin);
ConfLink lnk1(new ConfLinkRclRep(config, "processwebqueue"));
ConfParamBoolW* cp1 =
new ConfParamBoolW(this, lnk1, tr("Process the WEB history queue"),
tr("Enables indexing Firefox visited pages.<br>"
"(you need also install the Firefox Recoll plugin)"
));
vboxLayout->addWidget(cp1);
ConfLink lnk2(new ConfLinkRclRep(config, "webcachedir"));
ConfParamFNW* cp2 =
new ConfParamFNW(this, lnk2, tr("Web page store directory name"),
tr("The name for a directory where to store the copies "
"of visited web pages.<br>"
"A non-absolute path is taken relative to the "
"configuration directory."), true);
cp2->setEnabled(cp1->m_cb->isChecked());
connect(cp1->m_cb, SIGNAL(toggled(bool)), cp2, SLOT(setEnabled(bool)));
vboxLayout->addWidget(cp2);
ConfLink lnk3(new ConfLinkRclRep(config, "webcachemaxmbs"));
ConfParamIntW *cp3 =
new ConfParamIntW(this, lnk3, tr("Max. size for the web store (MB)"),
tr("Entries will be recycled once the size is reached."
"<br>"
"Only increasing the size really makes sense because "
"reducing the value will not truncate an existing "
"file (only waste space at the end)."
),
-1, 1000*1000); // Max 1TB...
cp3->setEnabled(cp1->m_cb->isChecked());
connect(cp1->m_cb, SIGNAL(toggled(bool)), cp3, SLOT(setEnabled(bool)));
vboxLayout->addWidget(cp3);
vboxLayout->insertStretch(-1);
}
ConfSearchPanelW::ConfSearchPanelW(QWidget *parent, ConfNull *config)
: QWidget(parent)
{
QVBoxLayout *vboxLayout = new QVBoxLayout(this);
vboxLayout->setSpacing(spacing);
vboxLayout->setMargin(margin);
if (!o_index_stripchars) {
ConfLink lnk1(new ConfLinkRclRep(config, "autodiacsens"));
ConfParamBoolW* cp1 =
new ConfParamBoolW(this, lnk1, tr("Automatic diacritics sensitivity"),
tr("<p>Automatically trigger diacritics sensitivity "
"if the search term has accented characters "
"(not in unac_except_trans). Else you need to "
"use the query language and the <i>D</i> "
"modifier to specify "
"diacritics sensitivity."
));
vboxLayout->addWidget(cp1);
ConfLink lnk2(new ConfLinkRclRep(config, "autocasesens"));
ConfParamBoolW* cp2 =
new ConfParamBoolW(this, lnk2,
tr("Automatic character case sensitivity"),
tr("<p>Automatically trigger character case "
"sensitivity if the entry has upper-case "
"characters in any but the first position. "
"Else you need to use the query language and "
"the <i>C</i> modifier to specify character-case "
"sensitivity."
));
vboxLayout->addWidget(cp2);
}
ConfLink lnk3(new ConfLinkRclRep(config, "maxTermExpand"));
ConfParamIntW* cp3 =
new ConfParamIntW(this, lnk3,
tr("Maximum term expansion count"),
tr("<p>Maximum expansion count for a single term "
"(e.g.: when using wildcards). The default "
"of 10 000 is reasonable and will avoid "
"queries that appear frozen while the engine is "
"walking the term list."
));
vboxLayout->addWidget(cp3);
ConfLink lnk4(new ConfLinkRclRep(config, "maxXapianClauses"));
ConfParamIntW* cp4 =
new ConfParamIntW(this, lnk4,
tr("Maximum Xapian clauses count"),
tr("<p>Maximum number of elementary clauses we "
"add to a single Xapian query. In some cases, "
"the result of term expansion can be "
"multiplicative, and we want to avoid using "
"excessive memory. The default of 100 000 "
"should be both high enough in most cases "
"and compatible with current typical hardware "
"configurations."
));
vboxLayout->addWidget(cp4);
vboxLayout->insertStretch(-1);
}
ConfTopPanelW::ConfTopPanelW(QWidget *parent, ConfNull *config)
: QWidget(parent)
{
QWidget *w = 0;
QGridLayout *gl1 = new QGridLayout(this);
gl1->setSpacing(spacing);
gl1->setMargin(margin);
int gridrow = 0;
w = new ConfParamDNLW(this,
ConfLink(new ConfLinkRclRep(config, "topdirs")),
tr("Top directories"), tr("Top directories"),
tr("The list of directories where recursive " tr("The list of directories where recursive "
"indexing starts. Default: your home.")); "indexing starts. Default: your home."));
setSzPol(w, QSizePolicy::Preferred, QSizePolicy::Preferred, 1, 3);
gl1->addWidget(w, gridrow++, 0, 1, 2);
ConfParamSLW *eskp = new ConfParamW *cparam = m_w->addParam(
ConfParamSLW(this, idx, ConfTabsW::CFPT_STRL, "skippedPaths", tr("Skipped paths"),
ConfLink(new ConfLinkRclRep(config, "skippedPaths")),
tr("Skipped paths"),
tr("These are pathnames of directories which indexing " tr("These are pathnames of directories which indexing "
"will not enter.<br>" "will not enter.<br>Path elements may contain wildcards. "
"Path elements may contain wildcards. "
"The entries must match the paths seen by the indexer " "The entries must match the paths seen by the indexer "
"(e.g.: if topdirs includes '/home/me' and '/home' is " "(e.g.: if topdirs includes '/home/me' and '/home' is "
"actually a link " "actually a link to '/usr/home', a correct skippedPath entry "
"to '/usr/home', a correct skippedPath entry "
"would be '/home/me/tmp*', not '/usr/home/me/tmp*')")); "would be '/home/me/tmp*', not '/usr/home/me/tmp*')"));
eskp->setFsEncoding(true); cparam->setFsEncoding(true);
setSzPol(eskp, QSizePolicy::Preferred, QSizePolicy::Preferred, 1, 3);
gl1->addWidget(eskp, gridrow++, 0, 1, 2);
if (m_stemlangs.empty()) {
vector<string> cstemlangs = Rcl::Db::getStemmerNames(); vector<string> cstemlangs = Rcl::Db::getStemmerNames();
QStringList stemlangs; for (const auto &clang : cstemlangs) {
for (vector<string>::const_iterator it = cstemlangs.begin(); m_stemlangs.push_back(u8s2qs(clang));
it != cstemlangs.end(); it++) {
stemlangs.push_back(QString::fromUtf8(it->c_str()));
} }
w = new }
ConfParamCSLW(this, m_w->addParam(idx, ConfTabsW::CFPT_CSTRL, "indexstemminglanguages",
ConfLink(new ConfLinkRclRep(config,
"indexstemminglanguages")),
tr("Stemming languages"), tr("Stemming languages"),
tr("The languages for which stemming expansion<br>" tr("The languages for which stemming expansion<br>"
"dictionaries will be built."), stemlangs); "dictionaries will be built."), 0, 0, &m_stemlangs);
setSzPol(w, QSizePolicy::Preferred, QSizePolicy::Preferred, 1, 1);
gl1->addWidget(w, gridrow, 0);
m_w->addParam(idx, ConfTabsW::CFPT_FN, "logfilename",
w = new ConfParamFNW(this,
ConfLink(new ConfLinkRclRep(config, "logfilename")),
tr("Log file name"), tr("Log file name"),
tr("The file where the messages will be written.<br>" tr("The file where the messages will be written.<br>"
"Use 'stderr' for terminal output"), false, "Use 'stderr' for terminal output"), 0);
u8s2qs(tmplocation()),
"log-recoll.txt");
gl1->addWidget(w, gridrow++, 1);
m_w->addParam(
idx, ConfTabsW::CFPT_INT, "loglevel", tr("Log verbosity level"),
tr("This value adjusts the amount of messages,<br>from only "
"errors to a lot of debugging data."), 0, 6);
w = new ConfParamIntW(this, m_w->addParam(idx, ConfTabsW::CFPT_INT, "idxflushmb",
ConfLink(new ConfLinkRclRep(config, "loglevel")),
tr("Log verbosity level"),
tr("This value adjusts the amount of "
"messages,<br>from only errors to a "
"lot of debugging data."), 0, 6);
gl1->addWidget(w, gridrow, 0);
w = new ConfParamIntW(this,
ConfLink(new ConfLinkRclRep(config, "idxflushmb")),
tr("Index flush megabytes interval"), tr("Index flush megabytes interval"),
tr("This value adjust the amount of " tr("This value adjust the amount of "
"data which is indexed between flushes to disk.<br>" "data which is indexed between flushes to disk.<br>"
"This helps control the indexer memory usage. " "This helps control the indexer memory usage. "
"Default 10MB "), 0, 1000); "Default 10MB "), 0, 1000);
gl1->addWidget(w, gridrow++, 1);
w = new ConfParamIntW(this, m_w->addParam(idx, ConfTabsW::CFPT_INT, "maxfsoccuppc",
ConfLink(new ConfLinkRclRep(config, "maxfsoccuppc")),
tr("Max disk occupation (%, 0 means no limit)"), tr("Max disk occupation (%, 0 means no limit)"),
tr("This is the percentage of disk usage " tr("This is the percentage of disk usage "
"- total disk usage, not index size - at which " "- total disk usage, not index size - at which "
"indexing will fail and stop.<br>" "indexing will fail and stop.<br>"
"The default value of 0 removes any limit."), "The default value of 0 removes any limit."), 0, 100);
0, 100);
gl1->addWidget(w, gridrow++, 0);
ConfParamBoolW* cpasp = ConfParamW *bparam = m_w->addParam(
new ConfParamBoolW(this, idx, ConfTabsW::CFPT_BOOL, "noaspell", tr("No aspell usage"),
ConfLink(new ConfLinkRclRep(config, "noaspell")),
tr("No aspell usage"),
tr("Disables use of aspell to generate spelling " tr("Disables use of aspell to generate spelling "
"approximation in the term explorer tool.<br> " "approximation in the term explorer tool.<br> "
"Useful if aspell is absent or does not work. ")); "Useful if aspell is absent or does not work. "));
gl1->addWidget(cpasp, gridrow, 0); cparam = m_w->addParam(
idx, ConfTabsW::CFPT_STR, "aspellLanguage",
ConfParamStrW* cpaspl = new
ConfParamStrW(this,
ConfLink(new ConfLinkRclRep(config, "aspellLanguage")),
tr("Aspell language"), tr("Aspell language"),
tr("The language for the aspell dictionary. " tr("The language for the aspell dictionary. "
"This should look like 'en' or 'fr' ...<br>" "This should look like 'en' or 'fr' ...<br>"
@ -444,23 +293,14 @@ ConfTopPanelW::ConfTopPanelW(QWidget *parent, ConfNull *config)
"To get an idea of what is installed on your system, " "To get an idea of what is installed on your system, "
"type 'aspell config' and look for .dat files inside " "type 'aspell config' and look for .dat files inside "
"the 'data-dir' directory. ")); "the 'data-dir' directory. "));
cpaspl->setEnabled(!cpasp->m_cb->isChecked()); m_w->enableLink(bparam, cparam, true);
connect(cpasp->m_cb, SIGNAL(toggled(bool)), cpaspl,SLOT(setDisabled(bool)));
gl1->addWidget(cpaspl, gridrow++, 1);
w = new m_w->addParam(
ConfParamFNW(this, idx, ConfTabsW::CFPT_FN, "dbdir", tr("Database directory name"),
ConfLink(new ConfLinkRclRep(config, "dbdir")),
tr("Database directory name"),
tr("The name for a directory where to store the index<br>" tr("The name for a directory where to store the index<br>"
"A non-absolute path is taken relative to the " "A non-absolute path is taken relative to the "
"configuration directory. The default is 'xapiandb'." "configuration directory. The default is 'xapiandb'."), true);
), true); m_w->addParam(idx, ConfTabsW::CFPT_STR, "unac_except_trans",
gl1->addWidget(w, gridrow++, 0, 1, 2);
w = new
ConfParamStrW(this,
ConfLink(new ConfLinkRclRep(config, "unac_except_trans")),
tr("Unac exceptions"), tr("Unac exceptions"),
tr("<p>These are exceptions to the unac mechanism " tr("<p>These are exceptions to the unac mechanism "
"which, by default, removes all diacritics, " "which, by default, removes all diacritics, "
@ -471,10 +311,85 @@ ConfTopPanelW::ConfTopPanelW(QWidget *parent, ConfNull *config)
"the first character is the source one, and the rest " "the first character is the source one, and the rest "
"is the translation." "is the translation."
)); ));
gl1->addWidget(w, gridrow++, 0, 1, 2); m_w->endOfList(idx);
return true;
} }
ConfSubPanelW::ConfSubPanelW(QWidget *parent, ConfNull *config, bool ConfIndexW::setupWebHistoryPanel(int idx)
{
ConfParamW *bparam = m_w->addParam(
idx, ConfTabsW::CFPT_BOOL, "processwebqueue",
tr("Process the WEB history queue"),
tr("Enables indexing Firefox visited pages.<br>"
"(you need also install the Firefox Recoll plugin)"));
ConfParamW *cparam = m_w->addParam(
idx, ConfTabsW::CFPT_FN, "webcachedir",
tr("Web page store directory name"),
tr("The name for a directory where to store the copies "
"of visited web pages.<br>"
"A non-absolute path is taken relative to the "
"configuration directory."), 1);
m_w->enableLink(bparam, cparam);
cparam = m_w->addParam(
idx, ConfTabsW::CFPT_INT, "webcachemaxmbs",
tr("Max. size for the web store (MB)"),
tr("Entries will be recycled once the size is reached."
"<br>"
"Only increasing the size really makes sense because "
"reducing the value will not truncate an existing "
"file (only waste space at the end)."
), -1, 1000*1000); // Max 1TB...
m_w->enableLink(bparam, cparam);
m_w->endOfList(idx);
return true;
}
bool ConfIndexW::setupSearchPanel(int idx)
{
if (!o_index_stripchars) {
m_w->addParam(idx, ConfTabsW::CFPT_BOOL, "autodiacsens",
tr("Automatic diacritics sensitivity"),
tr("<p>Automatically trigger diacritics sensitivity "
"if the search term has accented characters "
"(not in unac_except_trans). Else you need to "
"use the query language and the <i>D</i> "
"modifier to specify diacritics sensitivity."));
m_w->addParam(idx, ConfTabsW::CFPT_BOOL, "autocasesens",
tr("Automatic character case sensitivity"),
tr("<p>Automatically trigger character case "
"sensitivity if the entry has upper-case "
"characters in any but the first position. "
"Else you need to use the query language and "
"the <i>C</i> modifier to specify character-case "
"sensitivity."));
}
m_w->addParam(idx, ConfTabsW::CFPT_INT, "maxTermExpand",
tr("Maximum term expansion count"),
tr("<p>Maximum expansion count for a single term "
"(e.g.: when using wildcards). The default "
"of 10 000 is reasonable and will avoid "
"queries that appear frozen while the engine is "
"walking the term list."), 0, 100000);
m_w->addParam(idx, ConfTabsW::CFPT_INT, "maxXapianClauses",
tr("Maximum Xapian clauses count"),
tr("<p>Maximum number of elementary clauses we "
"add to a single Xapian query. In some cases, "
"the result of term expansion can be "
"multiplicative, and we want to avoid using "
"excessive memory. The default of 100 000 "
"should be both high enough in most cases "
"and compatible with current typical hardware "
"configurations."), 0, 1000000);
m_w->endOfList(idx);
return true;
}
ConfSubPanelW::ConfSubPanelW(QWidget *parent, ConfNull **config,
RclConfig *rclconf) RclConfig *rclconf)
: QWidget(parent), m_config(config) : QWidget(parent), m_config(config)
{ {
@ -482,14 +397,14 @@ ConfSubPanelW::ConfSubPanelW(QWidget *parent, ConfNull *config,
vboxLayout->setSpacing(spacing); vboxLayout->setSpacing(spacing);
vboxLayout->setMargin(margin); vboxLayout->setMargin(margin);
m_subdirs = new m_subdirs = new ConfParamDNLW(
ConfParamDNLW(this, "bogus00", this, ConfLink(new confgui::ConfLinkNullRep()),
ConfLink(new ConfLinkNullRep()),
QObject::tr("<b>Customised subtrees"), QObject::tr("<b>Customised subtrees"),
QObject::tr("The list of subdirectories in the indexed " QObject::tr("The list of subdirectories in the indexed "
"hierarchy <br>where some parameters need " "hierarchy <br>where some parameters need "
"to be redefined. Default: empty.")); "to be redefined. Default: empty."));
m_subdirs->getListBox()->setSelectionMode(QAbstractItemView::SingleSelection); m_subdirs->getListBox()->setSelectionMode(
QAbstractItemView::SingleSelection);
connect(m_subdirs->getListBox(), connect(m_subdirs->getListBox(),
SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
this, this,
@ -502,14 +417,13 @@ ConfSubPanelW::ConfSubPanelW(QWidget *parent, ConfNull *config,
// customized in the system config like .thunderbird or // customized in the system config like .thunderbird or
// .purple. This doesn't prevent them to add and customize them // .purple. This doesn't prevent them to add and customize them
// further. // further.
vector<string> allkeydirs = config->getSubKeys(true); vector<string> allkeydirs = (*config)->getSubKeys(true);
QStringList qls; QStringList qls;
for (vector<string>::const_iterator it = allkeydirs.begin(); for (const auto& dir: allkeydirs) {
it != allkeydirs.end(); it++) { qls.push_back(u8s2qs(dir));
qls.push_back(QString::fromUtf8(it->c_str()));
} }
m_subdirs->getListBox()->insertItems(0, qls); m_subdirs->getListBox()->insertItems(0, qls);
vboxLayout->addWidget(m_subdirs); vboxLayout->addWidget(m_subdirs);
QFrame *line2 = new QFrame(this); QFrame *line2 = new QFrame(this);
@ -520,8 +434,8 @@ ConfSubPanelW::ConfSubPanelW(QWidget *parent, ConfNull *config,
QLabel *explain = new QLabel(this); QLabel *explain = new QLabel(this);
explain->setWordWrap(true); explain->setWordWrap(true);
explain->setText( explain->setText(
QObject:: QObject::tr(
tr("<i>The parameters that follow are set either at the " "<i>The parameters that follow are set either at the "
"top level, if nothing " "top level, if nothing "
"or an empty line is selected in the listbox above, " "or an empty line is selected in the listbox above, "
"or for the selected subdirectory. " "or for the selected subdirectory. "
@ -539,7 +453,7 @@ ConfSubPanelW::ConfSubPanelW(QWidget *parent, ConfNull *config,
int gridy = 0; int gridy = 0;
ConfParamSLW *eskn = new ConfParamSLW( ConfParamSLW *eskn = new ConfParamSLW(
m_groupbox, "skippedNames", m_groupbox,
ConfLink(new ConfLinkPlusMinus( ConfLink(new ConfLinkPlusMinus(
rclconf, config, "skippedNames", rclconf, config, "skippedNames",
std::bind(&RclConfig::getSkippedNames, rclconf), &m_sk)), std::bind(&RclConfig::getSkippedNames, rclconf), &m_sk)),
@ -552,13 +466,12 @@ ConfSubPanelW::ConfSubPanelW(QWidget *parent, ConfNull *config,
vector<string> amimes = rclconf->getAllMimeTypes(); vector<string> amimes = rclconf->getAllMimeTypes();
QStringList amimesq; QStringList amimesq;
for (vector<string>::const_iterator it = amimes.begin(); for (const auto& mime: amimes) {
it != amimes.end(); it++) { amimesq.push_back(u8s2qs(mime));
amimesq.push_back(QString::fromUtf8(it->c_str()));
} }
ConfParamCSLW *eincm = new ConfParamCSLW( ConfParamCSLW *eincm = new ConfParamCSLW(
m_groupbox, "indexedmimetypes", m_groupbox,
ConfLink(new ConfLinkRclRep(config, "indexedmimetypes", &m_sk)), ConfLink(new ConfLinkRclRep(config, "indexedmimetypes", &m_sk)),
tr("Only mime types"), tr("Only mime types"),
tr("An exclusive list of indexed mime types.<br>Nothing " tr("An exclusive list of indexed mime types.<br>Nothing "
@ -567,7 +480,7 @@ ConfSubPanelW::ConfSubPanelW(QWidget *parent, ConfNull *config,
gl1->addWidget(eincm, gridy++, 1); gl1->addWidget(eincm, gridy++, 1);
ConfParamCSLW *eexcm = new ConfParamCSLW( ConfParamCSLW *eexcm = new ConfParamCSLW(
m_groupbox, "excludedmimetypes", m_groupbox,
ConfLink(new ConfLinkRclRep(config, "excludedmimetypes", &m_sk)), ConfLink(new ConfLinkRclRep(config, "excludedmimetypes", &m_sk)),
tr("Exclude mime types"), tr("Exclude mime types"),
tr("Mime types not to be indexed"), amimesq); tr("Mime types not to be indexed"), amimesq);
@ -575,7 +488,7 @@ ConfSubPanelW::ConfSubPanelW(QWidget *parent, ConfNull *config,
gl1->addWidget(eexcm, gridy, 0); gl1->addWidget(eexcm, gridy, 0);
ConfParamSLW *encs = new ConfParamSLW( ConfParamSLW *encs = new ConfParamSLW(
m_groupbox, "noContentSuffixes", m_groupbox,
ConfLink(new ConfLinkPlusMinus( ConfLink(new ConfLinkPlusMinus(
rclconf, config, "noContentSuffixes", rclconf, config, "noContentSuffixes",
std::bind(&RclConfig::getStopSuffixes, rclconf), &m_sk)), std::bind(&RclConfig::getStopSuffixes, rclconf), &m_sk)),
@ -597,17 +510,16 @@ ConfSubPanelW::ConfSubPanelW(QWidget *parent, ConfNull *config,
LOGERR("Can't get list of charsets from 'iconv -l'"); LOGERR("Can't get list of charsets from 'iconv -l'");
} }
icout = neutchars(icout, ","); icout = neutchars(icout, ",");
list<string> ccsets; vector<string> ccsets;
stringToStrings(icout, ccsets); stringToStrings(icout, ccsets);
QStringList charsets; QStringList charsets;
charsets.push_back(""); charsets.push_back("");
for (list<string>::const_iterator it = ccsets.begin(); for (const auto& charset : ccsets) {
it != ccsets.end(); it++) { charsets.push_back(u8s2qs(charset));
charsets.push_back(QString::fromUtf8(it->c_str()));
} }
ConfParamCStrW *e21 = new ConfParamCStrW( ConfParamCStrW *e21 = new ConfParamCStrW(
m_groupbox, "defaultcharset", m_groupbox,
ConfLink(new ConfLinkRclRep(config, "defaultcharset", &m_sk)), ConfLink(new ConfLinkRclRep(config, "defaultcharset", &m_sk)),
QObject::tr("Default<br>character set"), QObject::tr("Default<br>character set"),
QObject::tr("Character set used for reading files " QObject::tr("Character set used for reading files "
@ -620,7 +532,7 @@ ConfSubPanelW::ConfSubPanelW(QWidget *parent, ConfNull *config,
gl1->addWidget(e21, gridy++, 0); gl1->addWidget(e21, gridy++, 0);
ConfParamBoolW *e3 = new ConfParamBoolW( ConfParamBoolW *e3 = new ConfParamBoolW(
m_groupbox, "followLinks", m_groupbox,
ConfLink(new ConfLinkRclRep(config, "followLinks", &m_sk)), ConfLink(new ConfLinkRclRep(config, "followLinks", &m_sk)),
QObject::tr("Follow symbolic links"), QObject::tr("Follow symbolic links"),
QObject::tr("Follow symbolic links while " QObject::tr("Follow symbolic links while "
@ -630,7 +542,7 @@ ConfSubPanelW::ConfSubPanelW(QWidget *parent, ConfNull *config,
gl1->addWidget(e3, gridy, 0); gl1->addWidget(e3, gridy, 0);
ConfParamBoolW *eafln = new ConfParamBoolW( ConfParamBoolW *eafln = new ConfParamBoolW(
m_groupbox, "indexallfilenames", m_groupbox,
ConfLink(new ConfLinkRclRep(config, "indexallfilenames", &m_sk)), ConfLink(new ConfLinkRclRep(config, "indexallfilenames", &m_sk)),
QObject::tr("Index all file names"), QObject::tr("Index all file names"),
QObject::tr("Index the names of files for which the contents " QObject::tr("Index the names of files for which the contents "
@ -640,7 +552,7 @@ ConfSubPanelW::ConfSubPanelW(QWidget *parent, ConfNull *config,
gl1->addWidget(eafln, gridy++, 1); gl1->addWidget(eafln, gridy++, 1);
ConfParamIntW *ezfmaxkbs = new ConfParamIntW( ConfParamIntW *ezfmaxkbs = new ConfParamIntW(
m_groupbox, "compressedfilemaxkbs", m_groupbox,
ConfLink(new ConfLinkRclRep(config, "compressedfilemaxkbs", &m_sk)), ConfLink(new ConfLinkRclRep(config, "compressedfilemaxkbs", &m_sk)),
tr("Max. compressed file size (KB)"), tr("Max. compressed file size (KB)"),
tr("This value sets a threshold beyond which compressed" tr("This value sets a threshold beyond which compressed"
@ -650,7 +562,7 @@ ConfSubPanelW::ConfSubPanelW(QWidget *parent, ConfNull *config,
gl1->addWidget(ezfmaxkbs, gridy, 0); gl1->addWidget(ezfmaxkbs, gridy, 0);
ConfParamIntW *etxtmaxmbs = new ConfParamIntW( ConfParamIntW *etxtmaxmbs = new ConfParamIntW(
m_groupbox, "textfilemaxmbs", m_groupbox,
ConfLink(new ConfLinkRclRep(config, "textfilemaxmbs", &m_sk)), ConfLink(new ConfLinkRclRep(config, "textfilemaxmbs", &m_sk)),
tr("Max. text file size (MB)"), tr("Max. text file size (MB)"),
tr("This value sets a threshold beyond which text " tr("This value sets a threshold beyond which text "
@ -661,7 +573,7 @@ ConfSubPanelW::ConfSubPanelW(QWidget *parent, ConfNull *config,
gl1->addWidget(etxtmaxmbs, gridy++, 1); gl1->addWidget(etxtmaxmbs, gridy++, 1);
ConfParamIntW *etxtpagekbs = new ConfParamIntW( ConfParamIntW *etxtpagekbs = new ConfParamIntW(
m_groupbox, "textfilepagekbs", m_groupbox,
ConfLink(new ConfLinkRclRep(config, "textfilepagekbs", &m_sk)), ConfLink(new ConfLinkRclRep(config, "textfilepagekbs", &m_sk)),
tr("Text file page size (KB)"), tr("Text file page size (KB)"),
tr("If this value is set (not equal to -1), text " tr("If this value is set (not equal to -1), text "
@ -672,7 +584,7 @@ ConfSubPanelW::ConfSubPanelW(QWidget *parent, ConfNull *config,
gl1->addWidget(etxtpagekbs, gridy, 0); gl1->addWidget(etxtpagekbs, gridy, 0);
ConfParamIntW *efiltmaxsecs = new ConfParamIntW( ConfParamIntW *efiltmaxsecs = new ConfParamIntW(
m_groupbox, "filtermaxseconds", m_groupbox,
ConfLink(new ConfLinkRclRep(config, "filtermaxseconds", &m_sk)), ConfLink(new ConfLinkRclRep(config, "filtermaxseconds", &m_sk)),
tr("Max. filter exec. time (s)"), tr("Max. filter exec. time (s)"),
tr("External filters working longer than this will be " tr("External filters working longer than this will be "
@ -684,13 +596,22 @@ ConfSubPanelW::ConfSubPanelW(QWidget *parent, ConfNull *config,
vboxLayout->addWidget(m_groupbox); vboxLayout->addWidget(m_groupbox);
subDirChanged(0, 0); subDirChanged(0, 0);
LOGDEB("ConfSubPanelW::ConfSubPanelW: done\n");
} }
void ConfSubPanelW::reloadAll() void ConfSubPanelW::loadValues()
{ {
for (list<ConfParamW*>::iterator it = m_widgets.begin(); LOGDEB("ConfSubPanelW::loadValues\n");
it != m_widgets.end(); it++) { for (auto widget : m_widgets) {
(*it)->loadValue(); widget->loadValue();
}
LOGDEB("ConfSubPanelW::loadValues done\n");
}
void ConfSubPanelW::storeValues()
{
for (auto widget : m_widgets) {
widget->storeValue();
} }
} }
@ -702,23 +623,24 @@ void ConfSubPanelW::subDirChanged(QListWidgetItem *current, QListWidgetItem *)
m_sk = ""; m_sk = "";
m_groupbox->setTitle(tr("Global")); m_groupbox->setTitle(tr("Global"));
} else { } else {
m_sk = (const char *) current->text().toUtf8(); m_sk = qs2utf8s(current->text());
m_groupbox->setTitle(current->text()); m_groupbox->setTitle(current->text());
} }
LOGDEB("ConfSubPanelW::subDirChanged: now [" << (m_sk) << "]\n" ); LOGDEB("ConfSubPanelW::subDirChanged: now [" << m_sk << "]\n");
reloadAll(); loadValues();
LOGDEB("ConfSubPanelW::subDirChanged: done\n");
} }
void ConfSubPanelW::subDirDeleted(QString sbd) void ConfSubPanelW::subDirDeleted(QString sbd)
{ {
LOGDEB("ConfSubPanelW::subDirDeleted(" << ((const char *)sbd.toUtf8()) << ")\n" ); LOGDEB("ConfSubPanelW::subDirDeleted(" << qs2utf8s(sbd) << ")\n");
if (sbd == "") { if (sbd == "") {
// Can't do this, have to reinsert it // Can't do this, have to reinsert it
QTimer::singleShot(0, this, SLOT(restoreEmpty())); QTimer::singleShot(0, this, SLOT(restoreEmpty()));
return; return;
} }
// Have to delete all entries for submap // Have to delete all entries for submap
m_config->eraseKey((const char *)sbd.toUtf8()); (*m_config)->eraseKey(qs2utf8s(sbd));
} }
void ConfSubPanelW::restoreEmpty() void ConfSubPanelW::restoreEmpty()
@ -726,5 +648,3 @@ void ConfSubPanelW::restoreEmpty()
LOGDEB("ConfSubPanelW::restoreEmpty()\n"); LOGDEB("ConfSubPanelW::restoreEmpty()\n");
m_subdirs->getListBox()->insertItem(0, ""); m_subdirs->getListBox()->insertItem(0, "");
} }
} // Namespace confgui

View File

@ -30,78 +30,61 @@
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QTabWidget> #include <QTabWidget>
#include <QListWidgetItem> #include <QListWidgetItem>
#include <QStringList>
#include <string> #include <string>
#include <list> #include <vector>
using std::string;
using std::list; #include "confgui.h"
class ConfNull; class ConfNull;
class RclConfig; class RclConfig;
class ConfParamW;
class ConfParamDNLW;
namespace confgui { class ConfIndexW : public QWidget {
class ConfIndexW : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
ConfIndexW(QWidget *parent, RclConfig *config); ConfIndexW(QWidget *parent, RclConfig *config)
: m_parent(parent), m_rclconf(config) {}
public slots: public slots:
void showPrefs(bool modal);
void acceptChanges(); void acceptChanges();
void rejectChanges(); QWidget *getDialog() {return m_w;}
void reloadPanels();
private: private:
void initPanels();
bool setupTopPanel(int idx);
bool setupWebHistoryPanel(int idx);
bool setupSearchPanel(int idx);
QWidget *m_parent;
RclConfig *m_rclconf; RclConfig *m_rclconf;
ConfNull *m_conf; ConfNull *m_conf{nullptr};
list<QWidget *> m_widgets; confgui::ConfTabsW *m_w{nullptr};
QTabWidget *tabWidget; QStringList m_stemlangs;
QDialogButtonBox *buttonBox;
}; };
/**
* A panel with the top-level parameters which can't be redefined in
* subdirectoriess:
*/
class ConfTopPanelW : public QWidget {
Q_OBJECT
public:
ConfTopPanelW(QWidget *parent, ConfNull *config);
};
/** /** A special panel for parameters which may change in subdirectories: */
* A panel for the parameters that can be changed in subdirectories: class ConfSubPanelW : public QWidget, public confgui::ConfPanelWIF {
*/ Q_OBJECT;
class ConfSubPanelW : public QWidget {
Q_OBJECT
public: public:
ConfSubPanelW(QWidget *parent, ConfNull *config, RclConfig *rclconf); ConfSubPanelW(QWidget *parent, ConfNull **config, RclConfig *rclconf);
virtual void storeValues();
virtual void loadValues();
private slots: private slots:
void subDirChanged(QListWidgetItem *, QListWidgetItem *); void subDirChanged(QListWidgetItem *, QListWidgetItem *);
void subDirDeleted(QString); void subDirDeleted(QString);
void restoreEmpty(); void restoreEmpty();
private: private:
string m_sk; std::string m_sk;
ConfParamDNLW *m_subdirs; ConfNull **m_config;
list<ConfParamW*> m_widgets; confgui::ConfParamDNLW *m_subdirs;
ConfNull *m_config; std::vector<confgui::ConfParamW*> m_widgets;
QGroupBox *m_groupbox; QGroupBox *m_groupbox;
void reloadAll();
}; };
class ConfBeaglePanelW : public QWidget {
Q_OBJECT
public:
ConfBeaglePanelW(QWidget *parent, ConfNull *config);
};
class ConfSearchPanelW : public QWidget {
Q_OBJECT
public:
ConfSearchPanelW(QWidget *parent, ConfNull *config);
};
} // Namespace confgui
#endif /* _confguiindex_h_included_ */ #endif /* _confguiindex_h_included_ */

View File

@ -175,20 +175,15 @@ void RclMain::execIndexConfig()
void RclMain::showIndexConfig(bool modal) void RclMain::showIndexConfig(bool modal)
{ {
LOGDEB("showIndexConfig()\n" ); LOGDEB("showIndexConfig()\n" );
bool created{false};
if (indexConfig == 0) { if (indexConfig == 0) {
created = true;
indexConfig = new ConfIndexW(0, theconfig); indexConfig = new ConfIndexW(0, theconfig);
connect(new QShortcut(quitKeySeq, indexConfig), SIGNAL (activated()),
this, SLOT (fileExit()));
} else {
// Close and reopen, in hope that makes us visible...
indexConfig->close();
indexConfig->reloadPanels();
} }
if (modal) { indexConfig->showPrefs(modal);
indexConfig->exec(); if (created) {
indexConfig->setModal(false); connect(new QShortcut(quitKeySeq, indexConfig->getDialog()),
} else { SIGNAL (activated()), this, SLOT (fileExit()));
indexConfig->show();
} }
} }

View File

@ -45,16 +45,11 @@ class RTIToolW;
class FragButs; class FragButs;
class SpecIdxW; class SpecIdxW;
class WebcacheEdit; class WebcacheEdit;
class ConfIndexW;
class RclTrayIcon;
#include "ui_rclmain.h" #include "ui_rclmain.h"
namespace confgui {
class ConfIndexW;
}
using confgui::ConfIndexW;
class RclTrayIcon;
class RclMain : public QMainWindow, public Ui::RclMainBase { class RclMain : public QMainWindow, public Ui::RclMainBase {
Q_OBJECT; Q_OBJECT;