_langFrom(tr("")), _langTo(tr("")),_name(tr("")),
_type(tr("xdxf")), _infoNote(tr("")) {
_settings = new Settings();
- _dictDialog = new XdxfDictDialog(this);
- _settings->setValue("Type","xdxf");
+ _dictDialog = new XdxfDictDialog(this, this);
+ _settings->setValue("type","xdxf");
if(isCached())
- _settings->setValue("Cached","true");
+ _settings->setValue("cached","true");
else
- _settings->setValue("Cached","false");
- setPath("/usr/lib/mdictionary/dict.xdxf");
+ _settings->setValue("cached","false");
+
+ _wordsCount = 0;
+
stopped = false;
+
+ _icon = QIcon(":/icons/xdxf.png");
}
QString XdxfPlugin::langFrom() const {
QSet<Translation*> translations;
QFile dictionaryFile(path);
+ word = removeAccents(word);
+
stopped = false;
if(word.indexOf("*")==-1)
word+="*";
return translations.toList();
}
- /*read information about dictionary*/
QXmlStreamReader dictionaryReader(&dictionaryFile);
- dictionaryReader.readNextStartElement();
- if(dictionaryReader.name()=="xdxf") {
- if(dictionaryReader.attributes().hasAttribute("lang_from"))
- _langFrom = dictionaryReader.attributes().value("lang_from").toString();
- if(dictionaryReader.attributes().hasAttribute("lang_to"))
- _langTo = dictionaryReader.attributes().value("lang_to").toString();
- }
- dictionaryReader.readNextStartElement();
- if(dictionaryReader.name()=="full_name")
- _name=dictionaryReader.readElementText();
- dictionaryReader.readNextStartElement();
- if(dictionaryReader.name()=="description")
- _infoNote=dictionaryReader.readElementText();
-
/*search words list*/
QString a;
int i=0;
dictionaryReader.readNextStartElement();
if(!dictionaryReader.atEnd())
a = dictionaryReader.readElementText();
- if(regWord.exactMatch(a) && (i<limit || limit==0)) {
+ if(regWord.exactMatch(removeAccents(a)) && (i<limit || limit==0)) {
bool ok=true;
Translation *tran;
- foreach(tran,translations)
- {
+ foreach(tran,translations) {
if(tran->key()==a)
ok=false; /*if key word is in the dictionary more that one */
}
return "";
}
QXmlStreamReader dictionaryReader(&dictionaryFile);
+
+
QString a;
bool match =false;
void XdxfPlugin::setPath(QString path){
this->path=path;
_settings->setValue("path",path);
+ getDictionaryInfo();
}
CommonDictInterface* XdxfPlugin::getNew(const Settings *settings) const {
XdxfPlugin *plugin = new XdxfPlugin();
- if(settings)
+ if(settings){
plugin->setPath(settings->value("path"));
+ QStringList list = settings->keys();
+ foreach(QString key, list)
+ plugin->settings()->setValue(key, settings->value(key));
+ }
return plugin;
}
return true;
}
-void XdxfPlugin::setHash(uint _hash)
-{
+void XdxfPlugin::setHash(uint _hash) {
this->_hash=_hash;
}
-uint XdxfPlugin::hash() const
-{
+uint XdxfPlugin::hash() const {
return _hash;
}
return _settings;
}
-bool XdxfPlugin::isCached()
-{
+bool XdxfPlugin::isCached() {
return false;
}
+void XdxfPlugin::setSettings(Settings *settings) {
+ _settings = settings;
+ setPath(_settings->value("path"));
+ emit settingsChanged();
+}
+
+
+void XdxfPlugin::getDictionaryInfo() {
+ QFile dictionaryFile(path);
+ if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+ qDebug()<<"Error: could not open file";
+ return;
+ }
+
+ QXmlStreamReader dictionaryReader(&dictionaryFile);
+ dictionaryReader.readNextStartElement();
+ if(dictionaryReader.name()=="xdxf") {
+ if(dictionaryReader.attributes().hasAttribute("lang_from"))
+ _langFrom = dictionaryReader.attributes().value("lang_from").toString();
+ if(dictionaryReader.attributes().hasAttribute("lang_to"))
+ _langTo = dictionaryReader.attributes().value("lang_to").toString();
+ }
+ dictionaryReader.readNextStartElement();
+ if(dictionaryReader.name()=="full_name")
+ _name=dictionaryReader.readElementText();
+ dictionaryReader.readNextStartElement();
+ if(dictionaryReader.name()=="description")
+ _infoNote=dictionaryReader.readElementText();
+
+ /*dictionaryFile.seek(0);
+
+ long wordsCount = 0;
+
+ QString line;
+ while(!dictionaryFile.atEnd()) {
+ line = dictionaryFile.readLine();
+ if(line.contains("<ar>")) {
+ wordsCount++;
+ }
+ }*/
+
+ dictionaryFile.close();
+}
+
+QString XdxfPlugin::removeAccents(QString string) {
+
+ string = string.replace(QString::fromUtf8("ł"), "l", Qt::CaseInsensitive);
+ QString normalized = string.normalized(QString::NormalizationForm_D);
+ normalized = normalized;
+ for(int i=0; i<normalized.size(); i++) {
+ if( !normalized[i].isLetterOrNumber() &&
+ !normalized[i].isSpace() &&
+ !normalized[i].isDigit()) {
+ normalized.remove(i,1);
+ }
+ }
+ return normalized;
+}
+
+QIcon* XdxfPlugin::icon() {
+ return &_icon;
+}
+
Q_EXPORT_PLUGIN2(xdxf, XdxfPlugin)