trans=QString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") + QString("\n <ar>")
+ trans + QString("\n </ar>");
- //qDebug()<<"\n\n\n\n\n\n\n\n\n before"<<trans;
trans=checkTranslation(trans);
- //qDebug()<<"\n\n after"<<trans;
trans=XslConversion(trans);
+ qDebug()<<"\n\n trans"<<trans;
+
QString head = "<html><head>";
head += "<link rel=\"stylesheet\" type=\"text/css\" " ;
head += "href=\"/usr/share/mdictionary/css/" "style.css";
/*check all "&"*/
int pos=0;
int pos2;
+ int count=0;
+
while(pos!=-1){
pos=trans.indexOf("&",pos+1);
pos2=trans.indexOf("amp;",pos);
continue;
if(pos!=-1)
trans.insert(pos+1,"amp;");
- if(pos>40)
- while(1);
}
- /*check all "<" and ">" */
+
+ /*check all "<" and ">" in key */
pos=0;
- int count=0;
- while(pos!=-1){
- pos=trans.indexOf("<",pos+1);
- pos2=trans.indexOf(">",pos+1);
- if(pos!=-1 && pos2!=-1){
- if(trans.at(pos2-1)!='/' && trans.at(pos+1)!='/')
- count++;
- if(trans.at(pos+1)=='/')
- count--;
- }
- /* else if(pos==-1 && pos2!=-1){
- qDebug()<<"pos=-1";
- trans.remove(pos2,1);
+ count=0;
+ while(pos<trans.size()){
+ if(pos==trans.indexOf("<key>",pos)){
+ qDebug()<<"key";
+ count++;
+ pos+=4;
}
- else if(pos2==-1 && pos!=-1){
- qDebug()<<"pos2=-1";
+ else if(pos==trans.indexOf("</key>",pos))
+ count--;
+ else if(count==1 && (trans.at(pos)=='<' || trans.at(pos)=='>' ))
trans.remove(pos,1);
- }
- else {
- qDebug()<<"pos i pos2 = -1";
- break;
- }
- qDebug()<<"count"<<count;
-*/
+ pos++;
}
+
/*check all """ and "'" */
pos=0;
count=0;
QList<Translation*> translations;
if(isAvailable()) {
QString error("");
- word.replace("*",""); /*remove wildcard*/
- word.replace("?","");
+ char wrongChar[]={"*?&<>"};
+ for(unsigned int a=0;a<sizeof(wrongChar);a++){ /*remove wrong char*/
+ word.replace(wrongChar[a],"");
+ }
+
QString url=QString("/translate_a/t?client=t&sl=%1&tl=%2").arg(
_settings->value("lang_from"),
_settings->value("lang_to"));
QChar CompressedReader::readChar() {
- char c[2]={0};
+ char c[4]={0};
+ QString cha;
+
gzread(_file, c, 1);
- QString cha(QString::fromUtf8(c));
- if(!cha.at(0).isLetter() && c[0]!=0){
- gzread(_file, c, 1);
- cha=QString::fromUtf8(c);
+ if(((unsigned char)c[0])>127){
+ gzread(_file, c+1, 1);
+ if(((unsigned char)c[1])>127 && ((unsigned char)c[1])<192){
+ gzread(_file, c+2, 1);
+ if(((unsigned char)c[2])>127 && ((unsigned char)c[2])<192)
+ gzread(_file, c+3, 1);
+ }
}
+
+ cha=QString::fromUtf8(c);
return cha.at(0);
}
qint32 CompressedReader::readInt32BigEndian() {
qint32 value;
gzread(_file, (void*)(&value), 4);
-
return qFromBigEndian(value);
}
qint64 CompressedReader::readInt64BigEndian() {
qint64 value;
gzread(_file, (void*)(&value), 8);
-
return value;
}
QString CompressedReader::readKeyword() {
QString result;
QChar c;
- c = readChar();
+ c = readChar();
while(c != '\0') {
result += c;
c = readChar();
}
-
return result;
}
foreach(QString key, plugin->settings()->keys())
_settings->setValue(key, plugin->settings()->value(key));
}
- //else {
- _settings->setValue("path", _dictionaryFilePath);
- _settings->setValue("ifoFileName", _dictName + ".ifo");
- _settings->setValue("idxFileName", _dictName + ".idx");
- if (QFile::exists(_dictName + ".dict.dz") == true) {
- _settings->setValue("dictFileName", _dictName + ".dict.dz");
- }
- else {
- _settings->setValue("dictFileName", _dictName + ".dict");
- }
- if (QFile::exists(_dictName + ".syn") == true) {
- _settings->setValue("synFileName", _dictName + ".syn");
- }
- //}
+ _settings->setValue("path", _dictionaryFilePath);
+ _settings->setValue("ifoFileName", _dictName + ".ifo");
+ _settings->setValue("idxFileName", _dictName + ".idx");
+ if (QFile::exists(_dictName + ".dict.dz") == true) {
+ _settings->setValue("dictFileName", _dictName + ".dict.dz");
+ }
+ else {
+ _settings->setValue("dictFileName", _dictName + ".dict");
+ }
+
+ if (QFile::exists(_dictName + ".syn") == true) {
+ _settings->setValue("synFileName", _dictName + ".syn");
+ }
+
if(_accents)
_settings->setValue("strip_accents", "true");
else
Settings* StarDictDialog::addNewDictionary(QWidget *parent) {
StarDialog d(0, StarDialog::New, parent);
-
setLastDialogParent(parent);
connect(&d, SIGNAL(notify(Notify::NotifyType,QString)),
void StarDictDialog::changeSettings(QWidget * parent) {
StarDialog d(plugin, StarDialog::Change, parent);
-
setLastDialogParent(parent);
connect(&d, SIGNAL(notify(Notify::NotifyType,QString)),
#include "StarDictPlugin.h"
+
uint qHash(const TranslationStarDict &key) {
return qHash(key.key());
}
+
StarDictPlugin::StarDictPlugin(QObject *parent) : CommonDictInterface(parent),
_langFrom(""), _langTo(""),_name(""), _infoNote("") {
_settings = new Settings();
connect(_dictDialog, SIGNAL(notify(Notify::NotifyType,QString)),
this, SIGNAL(notify(Notify::NotifyType,QString)));
-
_settings->setValue("type","stardict");
_icon = QIcon("/usr/share/mdictionary/stardict.png");
_wordsCount = -1;
initAccents();
}
+
void StarDictPlugin::retranslate() {
QString locale = QLocale::system().name();
-
QTranslator *translator = new QTranslator(this);
- if(!translator->load(":/xdxf/translations/" + locale)) {
- translator->load(":/xdxf/translations/en_US");
+ if(!translator->load(":/stardict/translations/" + locale)) {
+ translator->load(":/stardicts/translations/en_US");
}
QCoreApplication::installTranslator(translator);
}
QList<Translation*> StarDictPlugin::searchWordList(QString word, int limit) {
- qDebug() << "StarDict searachWordList" << word;
QList<TranslationStarDict> translations;
bool is32b = false;
- if(settings()->value("idxoffsetbits") == "32" ||
- settings()->value("idxoffsetbits") == "")
- is32b = true;
-
bool err = 0;
int wordcount = settings()->value("wordcount").toInt(&err);
- if(!err)
- return QList<Translation*>();
-
+ int counter = 0;
+ int counterLimit = 0;
QString idxPath = settings()->value("idxFileName");
StarDictReader * reader = StarDictReaderFactory::createReader(idxPath);
QString fkey;
qint64 offset = 0, len = 0;
QRegExp keyword(word, Qt::CaseInsensitive, QRegExp::Wildcard);
- int counter = 0;
- int counterLimit = 0;
+ if( word.indexOf("*")==-1 && word.indexOf("?")==-1 &&
+ word.indexOf("_")==-1 && word.indexOf("%")==-1)
+ word+="*";
+
+
+ if((settings()->value("idxoffsetbits") == "32") ||
+ (settings()->value("idxoffsetbits") == ""))
+ is32b = true;
+ if(!err)
+ return QList<Translation*>();
+
stopped=false;
while(counter < wordcount && (counterLimit<limit || limit==0) && !stopped) {
counter++;
len = reader->readInt32BigEndian();
if(keyword.exactMatch(fkey)) {
- qDebug()<<"InfoNote"<<infoNote();
TranslationStarDict tran(fkey, infoNote(), this);
qDebug() << "off/len" << offset << len;
int id = translations.indexOf(tran);
QListIterator<TranslationStarDict> it(translations);
while(it.hasNext())
ret.push_back(new TranslationStarDict(it.next()));
-
-
return ret;
}
if(bytes == 0 && it != end){
while(*it != '\0' && it != end)
ret.append(*it++);
- if(it == end) qDebug()<<"end";
- else qDebug()<<"000";
+ if(it == end)
+ qDebug()<<"end";
+ else
+ qDebug()<<"000";
}
else
for(int i = 0; i < bytes && it != end; i++)
result += QString::fromUtf8(read(it++, end));
}
+
// Dont know whether mDictionary would ever handle binary stardict format
-// to be honest dont see any kind of adventages (can't find any binary dict)
+// to be honest dont see any kind of adventages (can't find any binary dict)
/*
}
else if(mode == 'W') {
return result;
}
+
QString StarDictPlugin::format(QByteArray raw, QString mode,QString key) {
QString result;
if(mode == "") {
QString StarDictPlugin::search(QString key, qint64 offset, qint32 len) {
QString dictPath = settings()->value("dictFileName");
StarDictReader *reader = StarDictReaderFactory::createReader(dictPath);
-
QByteArray raw = reader->readString(offset, len);
- qDebug()<<"mod"<<settings()->value("sametypesequence");
QString result= format(raw, settings()->value("sametypesequence"),key);
+
delete reader;
return result;
}
-
void StarDictPlugin::stop() {
- qDebug()<<"zatrzymanie programu";
stopped=true;
}
setLastDialogParent(_dictDialog->lastDialogParent());
if(settings && plugin->setSettings(settings)) {
- disconnect(plugin, SIGNAL(notify(Notify::NotifyType,QString)),
- this, SIGNAL(notify(Notify::NotifyType,QString)));
+ disconnect( plugin, SIGNAL(notify(Notify::NotifyType,QString)),
+ this, SIGNAL(notify(Notify::NotifyType,QString)));
plugin->getDictionaryInfo();
return plugin;
}
else {
- disconnect(plugin, SIGNAL(notify(Notify::NotifyType,QString)),
- this, SIGNAL(notify(Notify::NotifyType,QString)));
+ disconnect( plugin, SIGNAL(notify(Notify::NotifyType,QString)),
+ this, SIGNAL(notify(Notify::NotifyType,QString)));
delete plugin;
return 0;
}
QFile file(settings()->value("ifoFileName"));
if(!QFile::exists(_settings->value("ifoFileName"))
|| !file.open(QFile::ReadOnly | QFile::Text)) {
- Q_EMIT notify(Notify::Warning,
+ Q_EMIT notify(Notify::Warning,
QString(tr("StarDict dictionary cannot be read from file")));
qDebug()<<"Error: could not open the file";
return false;
}
-
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine();
settings()->setValue(list.at(0),list.at(1));
}
}
-
_name = settings()->value("bookname");
return true;
}
else
result+= _dictionaryInfo +"</info>";
- /*przeformatowanie zwracanego stringu na oczekiwany format*/
+ /*conwert returned string to XML format*/
result+=starDictPlugin->search(_key, offsets.at(i), lengths.at(i));
result+= "</dict>";
- //qDebug()<<"trans"<<result;
}
return result;
}
}
QChar UncompressedReader::readChar() {
- char c[2]={0};
+ char c[4]={0};
+ QString cha;
+
_stream.readRawData(c,1);
- QString cha(QString::fromUtf8(c));
- if(!cha.at(0).isLetter() && c[0]!=0){
+ if(((unsigned char)c[0])>127){
_stream.readRawData(c+1,1);
- cha=QString::fromUtf8(c);
+ if(((unsigned char)c[1])>127 && ((unsigned char)c[1])<192){
+ _stream.readRawData(c+2,1);
+ if(((unsigned char)c[2])>127 && ((unsigned char)c[2])<192)
+ _stream.readRawData(c+3,1);
+ }
}
+
+ cha=QString::fromUtf8(c);
return cha.at(0);
}
qint32 value;
_stream>>value;
_stream.setByteOrder(QDataStream::LittleEndian);
-
return value;
}