-
Notifications
You must be signed in to change notification settings - Fork 0
/
webshopscript.cpp
113 lines (91 loc) · 2.77 KB
/
webshopscript.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "webshopscript.h"
WebShopScript::WebShopScript(QString filename) :
name("<UNDEF>")
{
qDebug() << "WebShopScript loading:" << filename;
QSettings s(filename, QSettings::IniFormat);
name = s.value("name", "<UNDEF>").toString();
version = s.value("version", "<UNDEF>").toString();
searchUrlScript = s.value("searchUrlScript").toString();
searchIdScript = s.value("searchIdScript").toString();
searchscript = s.value("searchScript").toString();
qDebug() << "WebShopScript loaded:" << name << "ver.:" << version;
/*
QFile f(filename);
f.open(QFile::ReadOnly);
QTextStream s(&f);
while(!s.atEnd())
{
QString line = s.readLine();
if (line.startsWith("//name:"))
{
name = line.remove("//name:").trimmed();
}
else if (line.startsWith("//searchUrl:"))
{
searchurl = line.remove("//searchUrl:").trimmed();
if (idurl.isEmpty())
{
idurl = searchurl;
idurl.replace("%t", "%id");
}
}
else if (line.startsWith("//idUrl:"))
{
idurl = line.remove("//idUrl:").trimmed();
}
}
s.seek(0);
searchscript = s.readAll();*/
}
WebShopScript::~WebShopScript()
{
}
QString WebShopScript::getName()
{
return name;
}
QString WebShopScript::getVersion()
{
return version;
}
QString WebShopScript::getSearchUrl(QString value, QString type, QString pattern)
{
QScriptEngine e;
e.globalObject().setProperty("dtBomLocale", QLocale::system().name());
e.globalObject().setProperty("dtBomValue", value);
e.globalObject().setProperty("dtBomType", type);
e.globalObject().setProperty("dtBomPattern", pattern);
e.evaluate(searchUrlScript);
QString ret = e.globalObject().property("ret").toString();
qDebug() << "WebShopScript::getSearchUrl:" << ret;
return ret;
}
QString WebShopScript::getIdUrl(QString id)
{
QScriptEngine e;
e.globalObject().setProperty("dtBomLocale", QLocale::system().name());
e.globalObject().setProperty("dtBomId", id);
e.evaluate(searchIdScript);
QString ret = e.globalObject().property("ret").toString();
qDebug() << "WebShopScript::getIdUrl:" << ret;
return ret;
}
QString WebShopScript::getSearchScript()
{
return searchscript;
}
QList<WebShopScript> WebShopScript::fromDir(QString dirname)
{
QList<WebShopScript> scriptlist;
QDir dir(dirname);
dir.setFilter(QDir::Files | QDir::Readable);
dir.setSorting(QDir::Size | QDir::Reversed);
QFileInfoList list = dir.entryInfoList();
for (int i = 0; i < list.size(); ++i)
{
if (list[i].fileName().endsWith(".dtboms"))
scriptlist << WebShopScript(list[i].filePath());
}
return scriptlist;
}