1 #include "xdxfplugin.h"
4 #include <QXmlStreamReader>
6 #include "TranslationXdxf.h"
7 #include "../../../../includes/settings.h"
9 XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
10 _langFrom(tr("")), _langTo(tr("")),_name(tr("")),
11 _type(tr("xdxf")), _infoNote(tr("")) {
14 _settings = new Settings();
17 QString XdxfPlugin::langFrom() const {
21 QString XdxfPlugin::langTo() const {
25 QString XdxfPlugin::name() const {
29 QString XdxfPlugin::type() const {
33 QString XdxfPlugin::infoNote() const {
37 QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
39 QRegExp regWord(word);
40 regWord.setCaseSensitivity(Qt::CaseInsensitive);
41 regWord.setPatternSyntax(QRegExp::Wildcard);
43 QList<Translation*> translations;
44 QFile dictionaryFile(path);
45 if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
46 qDebug()<<"Error: could not open file";
49 QXmlStreamReader dictionaryReader(&dictionaryFile);
50 dictionaryReader.readNextStartElement();
51 if(dictionaryReader.name()=="xdxf") {
52 if(dictionaryReader.attributes().hasAttribute("lang_from"))
53 _langFrom = dictionaryReader.attributes().value("lang_from").toString();
54 if(dictionaryReader.attributes().hasAttribute("lang_to"))
55 _langTo = dictionaryReader.attributes().value("lang_to").toString();
57 dictionaryReader.readNextStartElement();
58 if(dictionaryReader.name()=="full_name")
59 _name=dictionaryReader.readElementText();
60 dictionaryReader.readNextStartElement();
61 if(dictionaryReader.name()=="description")
62 _infoNote=dictionaryReader.readElementText();
65 while(!dictionaryReader.atEnd() && !stopped){
66 dictionaryReader.readNextStartElement();
67 if(dictionaryReader.name()=="ar"){
68 while(dictionaryReader.name()!="k" && !dictionaryReader.atEnd())
69 dictionaryReader.readNextStartElement();
70 a = dictionaryReader.readElementText();
71 if(regWord.exactMatch(a) && i<limit) {
72 translations.append(new TranslationXdxf(a,_infoNote,this));
80 dictionaryFile.close();
84 QString XdxfPlugin::search(QString key) {
85 QFile dictionaryFile(path);
86 if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
87 qDebug()<<"Error: could not open file";
90 QXmlStreamReader dictionaryReader(&dictionaryFile);
94 while (!dictionaryReader.atEnd()) {
95 dictionaryReader.readNext();
96 if(dictionaryReader.tokenType() == QXmlStreamReader::StartElement) {
97 if(dictionaryReader.name()=="k") {
98 a = dictionaryReader.readElementText();
103 else if(dictionaryReader.tokenType() == QXmlStreamReader::Characters) {
105 QString temp(dictionaryReader.text().toString().replace("\n",""));
106 dictionaryFile.close();
114 void XdxfPlugin::stop() {
118 DictDialog* XdxfPlugin::dictDialog() {
123 CommonDictInterface* XdxfPlugin::getNew(const Settings*) const {
124 // CommonDictInterface *commonDictInterface= new
128 bool XdxfPlugin::isAvailable() const {
132 void XdxfPlugin::setHash(uint _hash)
137 uint XdxfPlugin::hash() const
142 Settings* XdxfPlugin::settings() {
146 Q_EXPORT_PLUGIN2(xdxf, XdxfPlugin)