this->backbone = backbone;
+
#ifdef Q_WS_MAEMO_5
setAttribute(Qt::WA_Maemo5StackedWindow);
#endif
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
#include "TranslationXdxf.h"
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
#ifndef TRANSLATIONXDXF_H
#define TRANSLATIONXDXF_H
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
#include "xdxfplugin.h"
#include <QDebug>
#include <QFile>
XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
_langFrom(tr("")), _langTo(tr("")),_name(tr("")),
_type(tr("xdxf")), _infoNote(tr("")) {
- path="dict.xdxf";
- stopped = false;
_settings = new Settings();
_dictDialog = new XdxfDictDialog(this);
+ _settings->setValue("type","xdxf");
+ if(isCached())
+ _settings->setValue("Cached","true");
+ else
+ _settings->setValue("Cached","false");
+ setPath("dict.xdxf");
+ stopped = false;
+
}
-QString XdxfPlugin::langFrom() const {
- return _langFrom;
+QString XdxfPlugin::langFrom() const {
+ return _langFrom;
}
QString XdxfPlugin::langTo() const {
}
QString XdxfPlugin::type() const {
+// return _settings->value("type");
return _type;
}
return _infoNote;
}
-QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
+QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
+ QSet<Translation*> translations;
+ QFile dictionaryFile(path);
+
stopped = false;
+ if(word.indexOf("*")==-1)
+ word+="*";
QRegExp regWord(word);
regWord.setCaseSensitivity(Qt::CaseInsensitive);
regWord.setPatternSyntax(QRegExp::Wildcard);
-
- QList<Translation*> translations;
- QFile dictionaryFile(path);
if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
qDebug()<<"Error: could not open file";
- return translations;
+ return translations.toList();
}
+
+ /*read information about dictionary*/
QXmlStreamReader dictionaryReader(&dictionaryFile);
dictionaryReader.readNextStartElement();
if(dictionaryReader.name()=="xdxf") {
dictionaryReader.readNextStartElement();
if(dictionaryReader.name()=="description")
_infoNote=dictionaryReader.readElementText();
+
+ /*search words list*/
QString a;
int i=0;
while(!dictionaryReader.atEnd() && !stopped){
if(dictionaryReader.name()=="ar"){
while(dictionaryReader.name()!="k" && !dictionaryReader.atEnd())
dictionaryReader.readNextStartElement();
- a = dictionaryReader.readElementText();
- if(regWord.exactMatch(a) && i<limit) {
- translations.append(new TranslationXdxf(a,_infoNote,this));
+ if(!dictionaryReader.atEnd())
+ a = dictionaryReader.readElementText();
+ if(regWord.exactMatch(a) && i<limit) {
+ bool ok=true;
+ Translation *tran;
+ foreach(tran,translations)
+ {
+ if(tran->key()==a)
+ ok=false; /*if key word is in the dictionary more that one */
+ }
+ if(ok) /*add key word to list*/
+ translations<<(new TranslationXdxf(a,_infoNote,this));
i++;
- if(i>=limit)
+ if(i>=limit && limit!=0)
break;
}
}
}
stopped=false;
dictionaryFile.close();
- return translations;
+ return translations.toList();
}
QString XdxfPlugin::search(QString key) {
QFile dictionaryFile(path);
+ QString resultString("");
if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
qDebug()<<"Error: could not open file";
return "";
}
else if(dictionaryReader.tokenType() == QXmlStreamReader::Characters) {
if(match) {
- QString temp(dictionaryReader.text().toString().replace("\n",""));
- dictionaryFile.close();
- return temp;
+ QString temp(dictionaryReader.text().toString());
+ temp.replace("\n","");
+ if(temp == ""){
+ while(dictionaryReader.name()!="ar" && !dictionaryReader.atEnd()){
+ dictionaryReader.readNext();
+ temp+=dictionaryReader.text().toString();
+ }
+ }
+ resultString+=temp.replace("\n","");
+ match=false;
}
}
}
- return "";
+ dictionaryFile.close();
+ return resultString;
}
void XdxfPlugin::stop() {
return _dictDialog;
}
+void XdxfPlugin::setPath(QString path){
+ this->path=path;
+ _settings->setValue("path",path);
+}
+
-CommonDictInterface* XdxfPlugin::getNew(const Settings*) const {
- return new XdxfPlugin();
+CommonDictInterface* XdxfPlugin::getNew(const Settings *settings) const {
+ XdxfPlugin *plugin = new XdxfPlugin();
+ plugin->setPath(settings->value("path"));
+ return new XdxfPlugin();//plugin;
}
bool XdxfPlugin::isAvailable() const {
return _settings;
}
+bool XdxfPlugin::isCached()
+{
+ return false;
+}
+
Q_EXPORT_PLUGIN2(xdxf, XdxfPlugin)
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
#ifndef XDXFPLUGIN_H
#define XDXFPLUGIN_H
private:
bool isCached();
+ void setPath(QString);
QString _langFrom;
QString _langTo;
QString _name;
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
#include "test.h"
#include <QSignalSpy>
void Testowanie::search()
{
XdxfPlugin xdxfPlugin(this);
- xdxfPlugin.loadDialog();
- xdxfPlugin.searchWordList("Cain",10);
- xdxfPlugin.search("Cain");
- QCOMPARE(xdxfPlugin.search("Apacz"), QString("Apachee"));
- // QCOMPARE(xdxfPlugin.search("sin"), QString("grzech"));
- // QCOMPARE(xdxfPlugin.search("boss"), QString(""));
-}
-
-void Testowanie::langFrom()
-{
- XdxfPlugin xdxfPlugin(this);
- xdxfPlugin.loadDialog();
- xdxfPlugin.searchWordList("rope",10);
- QCOMPARE(xdxfPlugin.langFrom(), QString("ENG"));
+ xdxfPlugin.search("wino");
+// QCOMPARE(xdxfPlugin.search("afera"), QString("scam"));
+// QCOMPARE(xdxfPlugin.search("grzech"), QString("sin"));
+ QCOMPARE(xdxfPlugin.search("Advent"), QString("Adwent"));
}
-void Testowanie::hash()
+void Testowanie::searchWordList()
{
XdxfPlugin xdxfPlugin(this);
- xdxfPlugin.loadDialog();
- xdxfPlugin.hash();
+ QList<Translation*> te=xdxfPlugin.searchWordList("Adventeee",10);
+ if(te.size()>0)
+ QCOMPARE(te.at(0)->key(), QString("Advent"));
}
-void Testowanie::sig()
+void Testowanie::langFrom()
{
XdxfPlugin xdxfPlugin(this);
- xdxfPlugin.loadDialog();
-
- QSignalSpy spy(&xdxfPlugin, SIGNAL(finalTranslation()));
-
- xdxfPlugin.searchWordList("Apacz",10);
-
- QCOMPARE(spy.count(), 1); // make sure the signal was emitted exactly one time
+ xdxfPlugin.searchWordList("rope",10);
+ QCOMPARE(xdxfPlugin.langFrom(), QString("POL"));
}
QTEST_MAIN(Testowanie)
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
#ifndef TEST_H
#define TEST_H
private slots:
void search();
+ void searchWordList();
void langFrom();
- void sig();
- void hash();
};