added GUI interface to edit the path translations

This commit is contained in:
Jean-Francois Dockes
2013-03-26 18:49:59 +01:00
parent 6a4a385657
commit 6c41ff55d6
15 changed files with 429 additions and 59 deletions
-1
View File
@@ -82,7 +82,6 @@ void ConfIndexW::acceptChanges()
delete m_conf;
m_conf = 0;
m_rclconf->updateMainConfig();
snapshotConfig();
hide();
}
-10
View File
@@ -51,20 +51,12 @@
#include "recollq.h"
extern RclConfig *theconfig;
RclConfig *thestableconfig;
PTMutexInit thestableconfiglock;
// To avoid writing settings if we stopped before reading them (else
// some kinds of errors would reset the qt/recoll settings to
// defaults)
static bool havereadsettings;
void snapshotConfig()
{
PTMutexLocker locker(thestableconfiglock);
thestableconfig = new RclConfig(*theconfig);
}
PTMutexInit thetempfileslock;
static vector<TempFile> o_tempfiles;
/* Keep an array of temporary files for deletion at exit. It happens that we
@@ -156,7 +148,6 @@ static void recollCleanup()
LOGDEB2(("recollCleanup: closing database\n"));
deleteZ(rcldb);
deleteZ(theconfig);
// deleteZ(thestableconfig);
PTMutexLocker locker(thetempfileslock);
o_tempfiles.clear();
@@ -308,7 +299,6 @@ int main(int argc, char **argv)
exit(1);
}
// fprintf(stderr, "recollinit done\n");
snapshotConfig();
// Translations for Qt standard widgets
QString slang = QLocale::system().name().left(2);
+142
View File
@@ -0,0 +1,142 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EditTransBase</class>
<widget class="QDialog" name="EditTransBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>649</width>
<height>362</height>
</rect>
</property>
<property name="windowTitle">
<string>Path Translations</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="whatIdxLA">
<property name="text">
<string>Setting path translations for </string>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QTableWidget" name="transTW">
<property name="toolTip">
<string>Select one or several file types, then use the controls in the frame below to change how they are processed</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="showGrid">
<bool>true</bool>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<property name="columnCount">
<number>2</number>
</property>
<property name="allColumnsShowFocus" stdset="0">
<bool>true</bool>
</property>
<property name="showSortIndicator" stdset="0">
<bool>false</bool>
</property>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>300</number>
</attribute>
<attribute name="horizontalHeaderMinimumSectionSize">
<number>20</number>
</attribute>
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
<bool>false</bool>
</attribute>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<column/>
<column/>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="addPB">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="delPB">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Delete</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="cancelPB">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="savePB">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
+134
View File
@@ -0,0 +1,134 @@
/* Copyright (C) 2006 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 <stdio.h>
#include <vector>
#include <utility>
#include <string>
using namespace std;
#include <qpushbutton.h>
#include <qtimer.h>
#include <qlistwidget.h>
#include <qmessagebox.h>
#include <qinputdialog.h>
#include <qlayout.h>
#include "recoll.h"
#include "debuglog.h"
#include "guiutils.h"
#include "conftree.h"
#include "ptrans_w.h"
void EditTrans::init(const string& dbdir)
{
m_dbdir = path_canon(dbdir);
connect(transTW, SIGNAL(itemDoubleClicked(QTableWidgetItem *)),
this, SLOT(onItemDoubleClicked(QTableWidgetItem *)));
connect(cancelPB, SIGNAL(clicked()), this, SLOT(close()));
QString lab = whatIdxLA->text();
lab.append(QString::fromLocal8Bit(m_dbdir.c_str()));
whatIdxLA->setText(lab);
QStringList labels(tr("Source path"));
labels.push_back(tr("Local path"));
transTW->setHorizontalHeaderLabels(labels);
ConfSimple *conftrans = theconfig->getPTrans();
if (!conftrans)
return;
int row = 0;
vector<string> opaths = conftrans->getNames(m_dbdir);
for (vector<string>::const_iterator it = opaths.begin();
it != opaths.end(); it++) {
transTW->setRowCount(row+1);
transTW->setItem(row, 0, new QTableWidgetItem(
QString::fromLocal8Bit(it->c_str())));
string npath;
conftrans->get(*it, npath, m_dbdir);
transTW->setItem(row, 1, new QTableWidgetItem(
QString::fromLocal8Bit(npath.c_str())));
row++;
}
resize(QSize(640, 300).expandedTo(minimumSizeHint()));
}
void EditTrans::onItemDoubleClicked(QTableWidgetItem *item)
{
transTW->editItem(item);
}
void EditTrans::on_savePB_clicked()
{
ConfSimple *conftrans = theconfig->getPTrans();
if (!conftrans) {
QMessageBox::warning(0, "Recoll", tr("Config error"));
return;
}
conftrans->holdWrites(true);
conftrans->eraseKey(m_dbdir);
for (int row = 0; row < transTW->rowCount(); row++) {
QTableWidgetItem *item0 = transTW->item(row, 0);
string from = path_canon((const char *)item0->text().toLocal8Bit());
QTableWidgetItem *item1 = transTW->item(row, 1);
string to = path_canon((const char*)item1->text().toLocal8Bit());
conftrans->set(from, to, m_dbdir);
}
conftrans->holdWrites(false);
close();
}
void EditTrans::on_addPB_clicked()
{
transTW->setRowCount(transTW->rowCount()+1);
int row = transTW->rowCount()-1;
transTW->setItem(row, 0, new QTableWidgetItem(tr("Original path")));
transTW->setItem(row, 1, new QTableWidgetItem(tr("Local path")));
transTW->editItem(transTW->item(row, 0));
}
void EditTrans::on_delPB_clicked()
{
QModelIndexList indexes = transTW->selectionModel()->selectedIndexes();
vector<int> rows;
for (int i = 0; i < indexes.size(); i++) {
rows.push_back(indexes.at(i).row());
}
sort(rows.begin(), rows.end());
rows.resize(unique(rows.begin(), rows.end()) - rows.begin());
for (int i = rows.size()-1; i >= 0; i--) {
transTW->removeRow(rows[i]);
}
}
void EditTrans::on_transTW_itemSelectionChanged()
{
QModelIndexList indexes = transTW->selectionModel()->selectedIndexes();
if(indexes.size() < 1)
delPB->setEnabled(0);
else
delPB->setEnabled(1);
}
+52
View File
@@ -0,0 +1,52 @@
/* Copyright (C) 2006 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 _PTRANS_W_H_INCLUDED_
#define _PTRANS_W_H_INCLUDED_
#include <string>
#include <qvariant.h>
#include <qdialog.h>
#include "ui_ptrans.h"
class QTableWidgetItem;
class EditTrans : public QDialog, public Ui::EditTransBase
{
Q_OBJECT
public:
EditTrans(const std::string& dbdir, QWidget* parent = 0)
: QDialog(parent)
{
setupUi(this);
init(dbdir);
}
public slots:
virtual void onItemDoubleClicked(QTableWidgetItem *);
virtual void on_savePB_clicked();
virtual void on_addPB_clicked();
virtual void on_delPB_clicked();
virtual void on_transTW_itemSelectionChanged();
private:
virtual void init(const std::string& dbdir);
std::string m_dbdir;
};
#endif /* _PTRANS_W_H_INCLUDED_ */
+1 -3
View File
@@ -35,9 +35,7 @@ extern bool maybeOpenDb(std::string &reason, bool force = true,
bool getStemLangs(vector<string>& langs);
extern RclConfig *theconfig;
extern RclConfig *thestableconfig;
extern PTMutexInit thestableconfiglock;
extern void snapshotConfig();
extern void rememberTempFile(TempFile);
extern void forgetTempFile(string &fn);
+3 -1
View File
@@ -22,6 +22,7 @@ HEADERS += \
idxsched.h \
listdialog.h \
preview_w.h \
ptrans_w.h \
rclhelp.h \
rclmain_w.h \
reslist.h \
@@ -34,7 +35,6 @@ HEADERS += \
uiprefs_w.h \
viewaction_w.h \
SOURCES += \
advsearch_w.cpp \
advshist.cpp \
@@ -44,6 +44,7 @@ SOURCES += \
guiutils.cpp \
main.cpp \
preview_w.cpp \
ptrans_w.cpp \
rclhelp.cpp \
rclmain_w.cpp \
rclzg.cpp \
@@ -65,6 +66,7 @@ FORMS = \
firstidx.ui \
idxsched.ui \
listdialog.ui \
ptrans.ui \
rclmain.ui \
restable.ui \
rtitool.ui \
+4 -5
View File
@@ -306,14 +306,14 @@ void SpellW::showStats()
resTW->setItem(row++, 1, new QTableWidgetItem(
QString::number(res.maxdoclen)));
if (!thestableconfig)
if (!theconfig)
return;
ExecCmd cmd;
vector<string> args;
int status;
args.push_back("-sk");
args.push_back(thestableconfig->getDbDir());
args.push_back(theconfig->getDbDir());
string output;
status = cmd.doexec("du", args, 0, &output);
int dbkbytes = 0;
@@ -327,14 +327,13 @@ void SpellW::showStats()
QString::fromUtf8(
displayableBytes(dbkbytes*1024).c_str())));
vector<string> allmimetypes = thestableconfig->getAllMimeTypes();
vector<string> allmimetypes = theconfig->getAllMimeTypes();
multimap<int, string> mtbycnt;
for (vector<string>::const_iterator it = allmimetypes.begin();
it != allmimetypes.end(); it++) {
string reason;
string q = string("mime:") + *it;
Rcl::SearchData *sd =
wasaStringToRcl(thestableconfig, "", q, reason);
Rcl::SearchData *sd = wasaStringToRcl(theconfig, "", q, reason);
RefCntr<Rcl::SearchData> rq(sd);
Rcl::Query query(rcldb);
if (!query.setQuery(rq)) {
+43 -36
View File
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>531</width>
<height>422</height>
<height>427</height>
</rect>
</property>
<property name="windowTitle">
@@ -22,7 +22,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>3</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
@@ -133,39 +133,39 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Plain text to HTML line style</string>
</property>
<property name="toolTip">
<string>Lines in PRE text are not folded. Using BR loses some indentation. PRE + Wrap style may be what you want.</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="plainBRRB">
<property name="text">
<string>&lt;BR&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="plainPRERB">
<property name="text">
<string>&lt;PRE&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="plainPREWRAPRB">
<property name="text">
<string>&lt;PRE&gt; + wrap</string>
</property>
</widget>
</item>
</layout>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="toolTip">
<string>Lines in PRE text are not folded. Using BR loses some indentation. PRE + Wrap style may be what you want.</string>
</property>
<property name="text">
<string>Plain text to HTML line style</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="plainBRRB">
<property name="text">
<string>&lt;BR&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="plainPRERB">
<property name="text">
<string>&lt;PRE&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="plainPREWRAPRB">
<property name="text">
<string>&lt;PRE&gt; + wrap</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="viewActionPB">
@@ -715,6 +715,13 @@ May be slow for big documents.</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ptransPB">
<property name="text">
<string>Paths translations</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
@@ -761,7 +768,7 @@ May be slow for big documents.</string>
<bool>true</bool>
</property>
<property name="toolTip">
<string>Click to add another index directory to the list</string>
<string>Click to add another index directory to the list. You can select either a Recoll configuration directory or a Xapian index.</string>
</property>
<property name="text">
<string>Add index</string>
+32
View File
@@ -53,6 +53,7 @@
#include "debuglog.h"
#include "editdialog.h"
#include "rclmain_w.h"
#include "ptrans_w.h"
void UIPrefsDialog::init()
{
@@ -64,6 +65,10 @@ void UIPrefsDialog::init()
connect(stylesheetPB, SIGNAL(clicked()), this, SLOT(showStylesheetDialog()));
connect(resetSSPB, SIGNAL(clicked()), this, SLOT(resetStylesheet()));
connect(idxLV, SIGNAL(itemSelectionChanged()),
this, SLOT(extradDbSelectChanged()));
connect(ptransPB, SIGNAL(clicked()),
this, SLOT(extraDbEditPtrans()));
connect(addExtraDbPB, SIGNAL(clicked()),
this, SLOT(addExtraDbPB_clicked()));
connect(delExtraDbPB, SIGNAL(clicked()),
@@ -397,6 +402,33 @@ void UIPrefsDialog::showViewAction(const QString& mt)
////////////////////////////////////////////
// External / extra search indexes setup
void UIPrefsDialog::extradDbSelectChanged()
{
if (idxLV->selectedItems().size() <= 1)
ptransPB->setEnabled(true);
else
ptransPB->setEnabled(false);
}
void UIPrefsDialog::extraDbEditPtrans()
{
string dbdir;
if (idxLV->selectedItems().size() == 0) {
dbdir = theconfig->getDbDir();
} else if (idxLV->selectedItems().size() == 1) {
QListWidgetItem *item = idxLV->selectedItems()[0];
QString qd = item->data(Qt::DisplayRole).toString();
dbdir = (const char *)qd.toLocal8Bit();
} else {
QMessageBox::warning(
0, "Recoll", tr("At most one index should be selected"));
return;
}
dbdir = path_canon(dbdir);
EditTrans *etrans = new EditTrans(dbdir, this);
etrans->show();
}
void UIPrefsDialog::togExtraDbPB_clicked()
{
for (int i = 0; i < idxLV->count(); i++) {
+2
View File
@@ -59,6 +59,8 @@ public slots:
virtual void setStemLang(const QString& lang);
virtual void editParaFormat();
virtual void editHeaderText();
virtual void extradDbSelectChanged();
virtual void extraDbEditPtrans();
signals:
void uiprefsDone();