1 #include "xdxfplugin.h"
4 #include <QXmlStreamReader>
6 XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
7 _langFrom(tr("")), _langTo(tr("")),_name(tr("")),
8 _type(tr("xdxf")), _infoNote(tr("")) {
12 QString XdxfPlugin::langFrom() const {
16 QString XdxfPlugin::langTo() const {
20 QString XdxfPlugin::name() const {
24 QString XdxfPlugin::type() const {
28 QString XdxfPlugin::infoNote() const {
32 QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
33 QRegExp regWord(word);
34 regWord.setCaseSensitivity(Qt::CaseInsensitive);
35 regWord.setPatternSyntax(QRegExp::Wildcard);
37 QList<Translation*> translations;
38 QFile dictionaryFile(path);
39 if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
40 qDebug()<<"Error: could not open file";
43 QXmlStreamReader dictionaryReader(&dictionaryFile);
44 dictionaryReader.readNextStartElement();
45 if(dictionaryReader.name()=="xdxf") {
46 if(dictionaryReader.attributes().hasAttribute("lang_from"))
47 _langFrom = dictionaryReader.attributes().value("lang_from").toString();
48 if(dictionaryReader.attributes().hasAttribute("lang_to"))
49 _langTo = dictionaryReader.attributes().value("lang_to").toString();
51 dictionaryReader.readNextStartElement();
52 if(dictionaryReader.name()=="full_name")
53 _name=dictionaryReader.readElementText();
54 dictionaryReader.readNextStartElement();
55 if(dictionaryReader.name()=="description")
56 _infoNote=dictionaryReader.readElementText();
59 while(!dictionaryReader.atEnd() && !stopped){
60 dictionaryReader.readNextStartElement();
61 if(dictionaryReader.name()=="ar"){
62 while(dictionaryReader.name()!="k" && !dictionaryReader.atEnd())
63 dictionaryReader.readNextStartElement();
64 a = dictionaryReader.readElementText();
65 if(regWord.exactMatch(a) && i<limit) {
66 translations.append(new TranslationXdxf(a,_infoNote,this));
74 dictionaryFile.close();
78 QString XdxfPlugin::search(QString key) {
79 QFile dictionaryFile(path);
80 if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
81 qDebug()<<"Error: could not open file";
84 QXmlStreamReader dictionaryReader(&dictionaryFile);
88 while (!dictionaryReader.atEnd()) {
89 dictionaryReader.readNext();
90 if(dictionaryReader.tokenType() == QXmlStreamReader::StartElement) {
91 if(dictionaryReader.name()=="k") {
92 a = dictionaryReader.readElementText();
97 else if(dictionaryReader.tokenType() == QXmlStreamReader::Characters) {
99 QString temp(dictionaryReader.text().toString().replace("\n",""));
100 dictionaryFile.close();
108 void XdxfPlugin::stop() {
112 QDialog* XdxfPlugin::loadDialog() {
116 QDialog* XdxfPlugin::settingsDialog() {
120 CommonDictInterface* XdxfPlugin::getNew(const Settings*) const {
121 // CommonDictInterface *commonDictInterface= new
125 bool XdxfPlugin::isAvailable() const {
129 void XdxfPlugin::setHash(uint _hash)
134 uint XdxfPlugin::hash() const