1st proto for GUI webcache editor
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#include "fragbuts.h"
|
||||
#include "specialindex.h"
|
||||
#include "rclmain_w.h"
|
||||
#include "webcache.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -74,6 +75,19 @@ void RclMain::showSpellDialog()
|
||||
}
|
||||
}
|
||||
|
||||
void RclMain::showWebcacheDialog()
|
||||
{
|
||||
if (webcache == 0) {
|
||||
webcache = new WebcacheEdit(0);
|
||||
connect(new QShortcut(quitKeySeq, webcache), SIGNAL (activated()),
|
||||
this, SLOT (fileExit()));
|
||||
webcache->show();
|
||||
} else {
|
||||
webcache->close();
|
||||
webcache->show();
|
||||
}
|
||||
}
|
||||
|
||||
void RclMain::showIndexStatistics()
|
||||
{
|
||||
showSpellDialog();
|
||||
|
||||
@@ -103,6 +103,7 @@
|
||||
<addaction name="toolsSpellAction"/>
|
||||
<addaction name="actionShowQueryDetails"/>
|
||||
<addaction name="actionQuery_Fragments"/>
|
||||
<addaction name="actionWebcache_Editor"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="preferencesMenu">
|
||||
<property name="title">
|
||||
@@ -532,6 +533,11 @@
|
||||
<string>Index &statistics</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionWebcache_Editor">
|
||||
<property name="text">
|
||||
<string>Webcache Editor</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="2" margin="2"/>
|
||||
<customwidgets>
|
||||
|
||||
@@ -350,6 +350,8 @@ void RclMain::init()
|
||||
this, SLOT(showAdvSearchDialog()));
|
||||
connect(toolsSpellAction, SIGNAL(triggered()),
|
||||
this, SLOT(showSpellDialog()));
|
||||
connect(actionWebcache_Editor, SIGNAL(triggered()),
|
||||
this, SLOT(showWebcacheDialog()));
|
||||
connect(actionQuery_Fragments, SIGNAL(triggered()),
|
||||
this, SLOT(showFragButs()));
|
||||
connect(actionSpecial_Indexing, SIGNAL(triggered()),
|
||||
|
||||
@@ -42,6 +42,7 @@ class CronToolW;
|
||||
class RTIToolW;
|
||||
class FragButs;
|
||||
class SpecIdxW;
|
||||
class WebcacheEdit;
|
||||
|
||||
#include "ui_rclmain.h"
|
||||
|
||||
@@ -73,6 +74,7 @@ public:
|
||||
fragbuts(0),
|
||||
specidx(0),
|
||||
periodictimer(0),
|
||||
webcache(0),
|
||||
restable(0),
|
||||
displayingTable(0),
|
||||
m_idNoStem(0),
|
||||
@@ -122,6 +124,7 @@ public slots:
|
||||
virtual void previewClosed(Preview *w);
|
||||
virtual void showAdvSearchDialog();
|
||||
virtual void showSpellDialog();
|
||||
virtual void showWebcacheDialog();
|
||||
virtual void showIndexStatistics();
|
||||
virtual void showFragButs();
|
||||
virtual void showSpecIdx();
|
||||
@@ -200,6 +203,7 @@ private:
|
||||
FragButs *fragbuts;
|
||||
SpecIdxW *specidx;
|
||||
QTimer *periodictimer;
|
||||
WebcacheEdit *webcache;
|
||||
ResTable *restable;
|
||||
bool displayingTable;
|
||||
QAction *m_idNoStem;
|
||||
|
||||
@@ -41,6 +41,7 @@ HEADERS += \
|
||||
systray.h \
|
||||
uiprefs_w.h \
|
||||
viewaction_w.h \
|
||||
webcache.h \
|
||||
widgets/editdialog.h \
|
||||
widgets/listdialog.h \
|
||||
widgets/qxtconfirmationmessage.h
|
||||
@@ -78,6 +79,7 @@ SOURCES += \
|
||||
systray.cpp \
|
||||
uiprefs_w.cpp \
|
||||
viewaction_w.cpp \
|
||||
webcache.cpp \
|
||||
widgets/qxtconfirmationmessage.cpp \
|
||||
xmltosd.cpp
|
||||
|
||||
@@ -98,7 +100,8 @@ FORMS = \
|
||||
ssearchb.ui \
|
||||
uiprefs.ui \
|
||||
viewaction.ui \
|
||||
|
||||
webcache.ui
|
||||
|
||||
RESOURCES = recoll.qrc
|
||||
|
||||
unix {
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
/* Copyright (C) 2016 J.F.Dockes
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#include "autoconfig.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include MEMORY_INCLUDE
|
||||
#include UNORDERED_MAP_INCLUDE
|
||||
|
||||
#ifndef USING_STD_REGEX
|
||||
#include <sys/types.h>
|
||||
#include <regex.h>
|
||||
#else
|
||||
#include <regex>
|
||||
#endif
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "recoll.h"
|
||||
#include "webcache.h"
|
||||
#include "beaglequeuecache.h"
|
||||
#include "circache.h"
|
||||
#include "conftree.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class CEnt {
|
||||
public:
|
||||
CEnt(const string& ud, const string& ur, const string& mt)
|
||||
: udi(ud), url(ur), mimetype(mt) {
|
||||
}
|
||||
string udi;
|
||||
string url;
|
||||
string mimetype;
|
||||
};
|
||||
|
||||
class WebcacheModelInternal {
|
||||
public:
|
||||
STD_SHARED_PTR<BeagleQueueCache> cache;
|
||||
vector<CEnt> all;
|
||||
vector<CEnt> disp;
|
||||
};
|
||||
|
||||
WebcacheModel::WebcacheModel(QObject *parent)
|
||||
: QAbstractTableModel(parent), m(new WebcacheModelInternal())
|
||||
{
|
||||
qDebug() << "WebcacheModel::WebcacheModel()";
|
||||
m->cache =
|
||||
STD_SHARED_PTR<BeagleQueueCache>(new BeagleQueueCache(theconfig));
|
||||
|
||||
if (m->cache) {
|
||||
bool eof;
|
||||
m->cache->cc()->rewind(eof);
|
||||
while (!eof) {
|
||||
string udi, sdic;
|
||||
m->cache->cc()->getCurrent(udi, sdic);
|
||||
ConfSimple dic(sdic);
|
||||
string mime, url;
|
||||
dic.get("mimetype", mime);
|
||||
dic.get("url", url);
|
||||
if (!udi.empty()) {
|
||||
m->all.push_back(CEnt(udi, url, mime));
|
||||
m->disp.push_back(CEnt(udi, url, mime));
|
||||
}
|
||||
if (!m->cache->cc()->next(eof))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int WebcacheModel::rowCount(const QModelIndex&) const
|
||||
{
|
||||
//qDebug() << "WebcacheModel::rowCount(): " << m->disp.size();
|
||||
return int(m->disp.size());
|
||||
}
|
||||
|
||||
int WebcacheModel::columnCount(const QModelIndex&) const
|
||||
{
|
||||
//qDebug() << "WebcacheModel::columnCount()";
|
||||
return 2;
|
||||
}
|
||||
|
||||
QVariant WebcacheModel::headerData (int col, Qt::Orientation orientation,
|
||||
int role) const
|
||||
{
|
||||
// qDebug() << "WebcacheModel::headerData()";
|
||||
if (orientation != Qt::Horizontal || role != Qt::DisplayRole) {
|
||||
return QVariant();
|
||||
}
|
||||
switch (col) {
|
||||
case 0: return QVariant(tr("MIME"));
|
||||
case 1: return QVariant(tr("Url"));
|
||||
default: return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
QVariant WebcacheModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
//qDebug() << "WebcacheModel::data()";
|
||||
Q_UNUSED(index);
|
||||
if (role != Qt::DisplayRole) {
|
||||
return QVariant();
|
||||
}
|
||||
int row = index.row();
|
||||
if (row < 0 || row >= int(m->disp.size())) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
/* We now read the data on init */
|
||||
#if 0
|
||||
string sdic;
|
||||
if (!m->cache->cc()->get(m->disp[row].udi, sdic)) {
|
||||
return QVariant();
|
||||
}
|
||||
ConfSimple dic(sdic);
|
||||
//ostringstream os; dic.write(os); cerr << "DIC: " << os.str() << endl;
|
||||
string mime, url;
|
||||
dic.get("mimetype", mime);
|
||||
dic.get("url", url);
|
||||
#else
|
||||
const string& mime = m->disp[row].mimetype;
|
||||
const string& url = m->disp[row].url;
|
||||
#endif
|
||||
|
||||
switch (index.column()) {
|
||||
case 0: return QVariant(QString::fromUtf8(mime.c_str()));
|
||||
case 1: return QVariant(QString::fromUtf8(url.c_str()));
|
||||
default: return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef USING_STD_REGEX
|
||||
#define M_regexec(A,B,C,D,E) regexec(&(A),B,C,D,E)
|
||||
#else
|
||||
#define M_regexec(A,B,C,D,E) (!regex_match(B,A))
|
||||
#endif
|
||||
|
||||
void WebcacheModel::setSearchFilter(const QString& _txt)
|
||||
{
|
||||
string txt = qs2utf8s(_txt);
|
||||
|
||||
#ifndef USING_STD_REGEX
|
||||
regex_t exp;
|
||||
if (regcomp(&exp, txt.c_str(), REG_NOSUB|REG_EXTENDED)) {
|
||||
//qDebug() << "regcomp failed for " << _txt;
|
||||
return;
|
||||
}
|
||||
#else
|
||||
basic_regex exp;
|
||||
try {
|
||||
exp = basic_regexp(txt, std::regex_constants::nosubs |
|
||||
std::regex_constants::extended);
|
||||
} catch(...) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
m->disp.clear();
|
||||
for (unsigned int i = 0; i < m->all.size(); i++) {
|
||||
if (!M_regexec(exp, m->all[i].url.c_str(), 0, 0, 0)) {
|
||||
m->disp.push_back(m->all[i]);
|
||||
} else {
|
||||
//qDebug() << "match failed. exp" << _txt << "data" <<
|
||||
// m->all[i].url.c_str();
|
||||
}
|
||||
}
|
||||
emit dataChanged(createIndex(0,0,0), createIndex(1, m->all.size(),0));
|
||||
}
|
||||
|
||||
|
||||
WebcacheEdit::WebcacheEdit(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
qDebug() << "WebcacheEdit::WebcacheEdit()";
|
||||
setupUi(this);
|
||||
m_model = new WebcacheModel(this);
|
||||
webcacheTV->setModel(m_model);
|
||||
connect(searchLE, SIGNAL(textEdited(const QString&)),
|
||||
m_model, SLOT(setSearchFilter(const QString&)));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/* Copyright (C) 2016 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 _WEBCACHE_H_INCLUDED_
|
||||
#define _WEBCACHE_H_INCLUDED_
|
||||
#include "autoconfig.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include MEMORY_INCLUDE
|
||||
|
||||
#include "ui_webcache.h"
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
class WebcacheModelInternal;
|
||||
|
||||
class WebcacheModel : public QAbstractTableModel {
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
WebcacheModel(QObject *parent = 0);
|
||||
|
||||
// Reimplemented methods
|
||||
virtual int rowCount (const QModelIndex& = QModelIndex()) const;
|
||||
virtual int columnCount(const QModelIndex& = QModelIndex()) const;
|
||||
virtual QVariant headerData (int col, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
virtual QVariant data(const QModelIndex& index,
|
||||
int role = Qt::DisplayRole ) const;
|
||||
public slots:
|
||||
void setSearchFilter(const QString&);
|
||||
|
||||
private:
|
||||
WebcacheModelInternal *m;
|
||||
};
|
||||
|
||||
class WebcacheEdit : public QDialog, public Ui::Webcache {
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
WebcacheEdit(QWidget *parent);
|
||||
private:
|
||||
WebcacheModel *m_model;
|
||||
};
|
||||
|
||||
|
||||
#endif /* _WEBCACHE_H_INCLUDED_ */
|
||||
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Webcache</class>
|
||||
<widget class="QDialog" name="Webcache">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Webcache editor</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="searchLBL">
|
||||
<property name="text">
|
||||
<string>Search regexp</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>searchLE</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="searchLE"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableView" name="webcacheTV">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user