From 967fff0fe94f86eb1499b18c86eba472709c5dd7 Mon Sep 17 00:00:00 2001 From: Jakub Jaszczynski Date: Fri, 8 Oct 2010 12:30:46 +0200 Subject: [PATCH] change in interpreter --- src/mdictionary/gui/TranslationWidget.cpp | 76 +++++++++++++++++++++++- src/mdictionary/gui/TranslationWidget.h | 1 + src/plugins/stardict/StarDictPlugin.cpp | 58 ++++++++++++------ src/plugins/stardict/StarDictPlugin.h | 1 - src/plugins/stardict/StarDictReaderFactory.cpp | 8 +-- 5 files changed, 117 insertions(+), 27 deletions(-) diff --git a/src/mdictionary/gui/TranslationWidget.cpp b/src/mdictionary/gui/TranslationWidget.cpp index 468087b..cf796c7 100644 --- a/src/mdictionary/gui/TranslationWidget.cpp +++ b/src/mdictionary/gui/TranslationWidget.cpp @@ -80,10 +80,13 @@ void TranslationWidget::show(QStringList translations) { trans += t + "\n"; } + trans=QString("") + QString("\n ") + trans + QString("\n "); - qDebug()<40) + while(1); + } + + /*check all "<" and ">" */ + 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); + } + else if(pos2==-1 && pos!=-1){ + qDebug()<<"pos2=-1"; + trans.remove(pos,1); + } + else { + qDebug()<<"pos i pos2 = -1"; + break; + } + qDebug()<<"count"<') + count--; + else if(trans.at(pos)=='\"' && count==0) + trans.replace(pos,1,"""); + else if(trans.at(pos)=='\'' && count==0) + trans.replace(pos,1,"'"); + pos++; + } + return trans; +} #ifdef Q_WS_MAEMO_5 void TranslationWidget::initButtons() { diff --git a/src/mdictionary/gui/TranslationWidget.h b/src/mdictionary/gui/TranslationWidget.h index 9954fcd..3f34f55 100644 --- a/src/mdictionary/gui/TranslationWidget.h +++ b/src/mdictionary/gui/TranslationWidget.h @@ -72,6 +72,7 @@ private Q_SLOTS: private: QString XslConversion(QString translation); + QString checkTranslation(QString trans); QToolButton* zoomInToolButton; QToolButton* zoomOutToolButton; TranslationView *webkit; diff --git a/src/plugins/stardict/StarDictPlugin.cpp b/src/plugins/stardict/StarDictPlugin.cpp index 14691e7..2f19bcc 100644 --- a/src/plugins/stardict/StarDictPlugin.cpp +++ b/src/plugins/stardict/StarDictPlugin.cpp @@ -144,9 +144,13 @@ QList StarDictPlugin::searchWordList(QString word, int limit) { QByteArray StarDictPlugin::read(QByteArray::iterator it, QByteArray::iterator end, int bytes) { QByteArray ret; - if(bytes == 0 && it != end) - while(*it != '\0') + + if(bytes == 0 && it != end){ + while(*it != '\0' && it != end) ret.append(*it++); + if(it == end) qDebug()<<"end"; + else qDebug()<<"000"; + } else for(int i = 0; i < bytes && it != end; i++) ret.append(*it++); @@ -157,16 +161,22 @@ QByteArray StarDictPlugin::read(QByteArray::iterator it, QString StarDictPlugin::interpret(QByteArray::iterator it, QByteArray::iterator end, QChar mode,QString key, bool last) { QString result; - if(mode == 'm') + if(mode == 'm'){ + result += "" + key + ""; result += QString::fromUtf8(read(it++, end)); - else if(mode == 'l') + } + else if(mode == 'l'){ + result += "" + key + ""; result += QString::fromUtf8(read(it++, end)); + } else if(mode == 'g'){ result += "" + key + ""; result += QString::fromUtf8(read(it++, end)); } - else if(mode == 't') + else if(mode == 't'){ + result += "" + key + ""; result += QString::fromUtf8(read(it++, end)); + } else if(mode == 'x'){ result += QString::fromUtf8(read(it++, end)); result.replace("",""); @@ -176,18 +186,28 @@ QString StarDictPlugin::interpret(QByteArray::iterator it, result.remove(pos,4); result+=""; } - else if(mode == 'y') + else if(mode == 'y') { + result += "" + key + ""; result += QString::fromUtf8(read(it++, end)); - else if(mode == 'k') + } + else if(mode == 'k'){ + result += "" + key + ""; result += QString::fromUtf8(read(it++, end)); - else if(mode == 'w') + } + else if(mode == 'w'){ + result += "" + key + ""; result += QString::fromUtf8(read(it++, end)); - else if(mode == 'h') + } + else if(mode == 'h'){ + result += "" + key + ""; result += QString::fromUtf8(read(it++, end)); - else if(mode == 'r') + } + else if(mode == 'r'){ + result += "" + key + ""; result += QString::fromUtf8(read(it++, end)); - + } else if(mode == 'W') { + result += "" + key + ""; if(!last) { QByteArray tmp ; tmp.append(*(it++)); @@ -198,6 +218,7 @@ QString StarDictPlugin::interpret(QByteArray::iterator it, } else result += read(it++, end); } else if(mode == 'P') { + result += "" + key + ""; if(!last) { QByteArray tmp ; tmp.append(*(it++)); @@ -211,7 +232,6 @@ QString StarDictPlugin::interpret(QByteArray::iterator it, return result; } - QString StarDictPlugin::format(QByteArray raw, QString mode,QString key) { QString result; if(mode == "") { @@ -231,11 +251,14 @@ QString StarDictPlugin::format(QByteArray raw, QString mode,QString key) { QString StarDictPlugin::search(QString key, qint64 offset, qint32 len) { - if(!dictReader) - return ""; - QByteArray raw = dictReader->readString(offset, len); + QString dictPath = settings()->value("dictFileName"); + StarDictReader *reader = StarDictReaderFactory::createReader(dictPath); + + QByteArray raw = reader->readString(offset, len); qDebug()<<"mod"<value("sametypesequence"); - return format(raw, settings()->value("sametypesequence"),key); + QString result= format(raw, settings()->value("sametypesequence"),key); + delete reader; + return result; } @@ -266,8 +289,6 @@ CommonDictInterface* StarDictPlugin::getNew(const Settings *settings) const { disconnect(plugin, SIGNAL(notify(Notify::NotifyType,QString)), this, SIGNAL(notify(Notify::NotifyType,QString))); plugin->getDictionaryInfo(); - plugin->dictReader = StarDictReaderFactory:: - createReader(settings->value("dictFileName")); return plugin; } else { @@ -326,7 +347,6 @@ bool StarDictPlugin::getDictionaryInfo() { } _name = settings()->value("bookname"); - return true; } diff --git a/src/plugins/stardict/StarDictPlugin.h b/src/plugins/stardict/StarDictPlugin.h index c8efbae..782d783 100644 --- a/src/plugins/stardict/StarDictPlugin.h +++ b/src/plugins/stardict/StarDictPlugin.h @@ -183,7 +183,6 @@ private: Settings *_settings; StarDictDialog* _dictDialog; Settings* _ifoFileSettings; - StarDictReader * dictReader; /*! Reads and process (converting to qstring) data from StarDict dictionary file (*.dict[.dz]) diff --git a/src/plugins/stardict/StarDictReaderFactory.cpp b/src/plugins/stardict/StarDictReaderFactory.cpp index 3ae2242..fc32175 100644 --- a/src/plugins/stardict/StarDictReaderFactory.cpp +++ b/src/plugins/stardict/StarDictReaderFactory.cpp @@ -29,13 +29,9 @@ StarDictReader* StarDictReaderFactory::createReader(QString filename) { if(filename.endsWith(".gz", Qt::CaseInsensitive) || - filename.endsWith(".dz", Qt::CaseInsensitive)) { - qDebug() << "compressed"; + filename.endsWith(".dz", Qt::CaseInsensitive)) return new CompressedReader(filename); - } - else { - qDebug() << "uncompressed"; + else return new UncompressedReader(filename); - } } -- 1.7.9.5