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();
15 _dictDialog = new XdxfDictDialog(this);
18 QString XdxfPlugin::langFrom() const {
22 QString XdxfPlugin::langTo() const {
26 QString XdxfPlugin::name() const {
30 QString XdxfPlugin::type() const {
34 QString XdxfPlugin::infoNote() const {
38 QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
40 QRegExp regWord(word);
41 regWord.setCaseSensitivity(Qt::CaseInsensitive);
42 regWord.setPatternSyntax(QRegExp::Wildcard);
44 QList<Translation*> translations;
45 QFile dictionaryFile(path);
46 if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
47 qDebug()<<"Error: could not open file";
50 QXmlStreamReader dictionaryReader(&dictionaryFile);
51 dictionaryReader.readNextStartElement();
52 if(dictionaryReader.name()=="xdxf") {
53 if(dictionaryReader.attributes().hasAttribute("lang_from"))
54 _langFrom = dictionaryReader.attributes().value("lang_from").toString();
55 if(dictionaryReader.attributes().hasAttribute("lang_to"))
56 _langTo = dictionaryReader.attributes().value("lang_to").toString();
58 dictionaryReader.readNextStartElement();
59 if(dictionaryReader.name()=="full_name")
60 _name=dictionaryReader.readElementText();
61 dictionaryReader.readNextStartElement();
62 if(dictionaryReader.name()=="description")
63 _infoNote=dictionaryReader.readElementText();
66 while(!dictionaryReader.atEnd() && !stopped){
67 dictionaryReader.readNextStartElement();
68 if(dictionaryReader.name()=="ar"){
69 while(dictionaryReader.name()!="k" && !dictionaryReader.atEnd())
70 dictionaryReader.readNextStartElement();
71 a = dictionaryReader.readElementText();
72 if(regWord.exactMatch(a) && i<limit) {
73 translations.append(new TranslationXdxf(a,_infoNote,this));
81 dictionaryFile.close();
85 QString XdxfPlugin::search(QString key) {
86 QFile dictionaryFile(path);
87 if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
88 qDebug()<<"Error: could not open file";
91 QXmlStreamReader dictionaryReader(&dictionaryFile);
95 while (!dictionaryReader.atEnd()) {
96 dictionaryReader.readNext();
97 if(dictionaryReader.tokenType() == QXmlStreamReader::StartElement) {
98 if(dictionaryReader.name()=="k") {
99 a = dictionaryReader.readElementText();
104 else if(dictionaryReader.tokenType() == QXmlStreamReader::Characters) {
106 QString temp(dictionaryReader.text().toString().replace("\n",""));
107 dictionaryFile.close();
115 void XdxfPlugin::stop() {
119 DictDialog* XdxfPlugin::dictDialog() {
124 CommonDictInterface* XdxfPlugin::getNew(const Settings*) const {
125 return new XdxfPlugin();
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)