Switch to unified view

a/src/qtgui/webcache.cpp b/src/qtgui/webcache.cpp
...
...
19
#include <sstream>
19
#include <sstream>
20
#include <iostream>
20
#include <iostream>
21
#include <memory>
21
#include <memory>
22
#include <unordered_map>
22
#include <unordered_map>
23
23
24
#ifdef _WIN32
25
#define USING_STD_REGEX
26
#endif
27
28
#ifndef USING_STD_REGEX
29
#include <sys/types.h>
30
#include <regex.h>
31
#else
32
#include <regex>
33
#endif
34
35
#include <QDebug>
24
#include <QDebug>
36
#include <QSettings>
25
#include <QSettings>
37
#include <QCloseEvent>
26
#include <QCloseEvent>
38
#include <QShortcut>
27
#include <QShortcut>
39
#include <QMenu>
28
#include <QMenu>
...
...
45
#include "webcache.h"
34
#include "webcache.h"
46
#include "webstore.h"
35
#include "webstore.h"
47
#include "circache.h"
36
#include "circache.h"
48
#include "conftree.h"
37
#include "conftree.h"
49
#include "rclmain_w.h"
38
#include "rclmain_w.h"
39
#include "smallut.h"
50
40
51
using namespace std;
41
using namespace std;
52
42
53
class CEnt {
43
class CEnt {
54
public:
44
public:
...
...
156
    int row = index.row();
146
    int row = index.row();
157
    if (row < 0 || row >= int(m->disp.size())) {
147
    if (row < 0 || row >= int(m->disp.size())) {
158
        return QVariant();
148
        return QVariant();
159
    }
149
    }
160
150
161
    /* We now read the data on init */
162
#if 0
163
    string sdic;
164
    if (!m->cache->cc()->get(m->disp[row].udi, sdic)) {
165
        return QVariant();
166
    }
167
    ConfSimple dic(sdic);
168
    //ostringstream os; dic.write(os);  cerr << "DIC: " << os.str() << endl;
169
    string mime, url;
170
    dic.get("mimetype", mime);
171
    dic.get("url", url);
172
#else
173
    const string& mime = m->disp[row].mimetype;
151
    const string& mime = m->disp[row].mimetype;
174
    const string& url = m->disp[row].url;
152
    const string& url = m->disp[row].url;
175
#endif
176
    
153
    
177
    switch (index.column()) {
154
    switch (index.column()) {
178
    case 0: return QVariant(QString::fromUtf8(mime.c_str()));
155
    case 0: return QVariant(QString::fromUtf8(mime.c_str()));
179
    case 1: return QVariant(QString::fromUtf8(url.c_str()));
156
    case 1: return QVariant(QString::fromUtf8(url.c_str()));
180
    default: return QVariant();
157
    default: return QVariant();
181
    }
158
    }
182
}
159
}
183
160
184
#ifndef USING_STD_REGEX
185
#define M_regexec(A,B,C,D,E) regexec(&(A),B,C,D,E)
186
#else
187
#define M_regexec(A,B,C,D,E) (!regex_match(B,A))
188
#endif
189
190
void WebcacheModel::setSearchFilter(const QString& _txt)
161
void WebcacheModel::setSearchFilter(const QString& _txt)
191
{
162
{
192
    string txt = qs2utf8s(_txt);
163
    SimpleRegexp re(qs2utf8s(_txt), SimpleRegexp::SRE_NOSUB);
193
    
194
#ifndef USING_STD_REGEX
195
    regex_t exp;
196
    if (regcomp(&exp, txt.c_str(), REG_NOSUB|REG_EXTENDED)) {
197
        //qDebug() << "regcomp failed for " << _txt;
198
        return;
199
    }
200
#else
201
    basic_regex<char> exp;
202
    try {
203
        exp = basic_regex<char>(txt, std::regex_constants::nosubs |
204
                           std::regex_constants::extended);
205
    } catch(...) {
206
        return;
207
    }
208
#endif
209
    
164
    
210
    m->disp.clear();
165
    m->disp.clear();
211
    for (unsigned int i = 0; i < m->all.size(); i++) {
166
    for (unsigned int i = 0; i < m->all.size(); i++) {
212
        if (!M_regexec(exp, m->all[i].url.c_str(), 0, 0, 0)) {
167
        if (re(m->all[i].url)) {
213
            m->disp.push_back(m->all[i]);
168
            m->disp.push_back(m->all[i]);
214
        } else {
169
        } else {
215
            //qDebug() << "match failed. exp" << _txt << "data" <<
170
            //qDebug() << "match failed. exp" << _txt << "data" <<
216
            // m->all[i].url.c_str();
171
            // m->all[i].url.c_str();
217
        }
172
        }