Copyright 2010 Comarch S.A.
*******************************************************************************/
+/*!
+ \file StarDictPlugin.cpp
+ \brief Implementation of stardict plugin's main class.
-/*! \file stardictplugin.cpp
+ \author Jakub Jaszczynski
*/
#include "StarDictPlugin.h"
-
+/**/
uint qHash(const TranslationStarDict &key) {
return qHash(key.key());
}
this, SIGNAL(notify(Notify::NotifyType,QString)));
_settings->setValue("type","stardict");
- _icon = QIcon("/usr/share/mdictionary/stardict.png");
- _wordsCount = -1;
+ _iconPath = "/usr/share/mdictionary/stardict.png";
+ _icon = QIcon(_iconPath);
stopped = false;
+ _settings->setValue("strip_accents","true");
+
initAccents();
+
}
QTranslator *translator = new QTranslator(this);
if(!translator->load(":/stardict/translations/" + locale)) {
- translator->load(":/stardicts/translations/en_US");
+ translator->load(":/stardict/translations/en_US");
}
QCoreApplication::installTranslator(translator);
}
QString idxPath = settings()->value("idxFileName");
StarDictReader * reader = StarDictReaderFactory::createReader(idxPath);
QString fkey;
- qint64 offset = 0, len = 0;
- QRegExp keyword(word, Qt::CaseInsensitive, QRegExp::Wildcard);
+ qint64 offset = 0,
+ len = 0;
if( word.indexOf("*")==-1 && word.indexOf("?")==-1 &&
word.indexOf("_")==-1 && word.indexOf("%")==-1)
word+="*";
-
+ QRegExp keyword(word, Qt::CaseInsensitive, QRegExp::Wildcard);
if((settings()->value("idxoffsetbits") == "32") ||
(settings()->value("idxoffsetbits") == ""))
is32b = true;
+
if(!err)
return QList<Translation*>();
offset = reader->readInt64BigEndian();
len = reader->readInt32BigEndian();
- if(keyword.exactMatch(fkey)) {
+ if(keyword.exactMatch(fkey) ) {
TranslationStarDict tran(fkey, infoNote(), this);
- qDebug() << "off/len" << offset << len;
int id = translations.indexOf(tran);
if(id == -1) {
tran.add(offset, len);
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++)
QString StarDictPlugin::interpret(QByteArray::iterator it,
- QByteArray::iterator end, QChar mode,QString key, bool last) {
+ QByteArray::iterator end, QChar mode,QString key, bool) {
QString result;
- qDebug()<<"****** mode: "<<mode;
- if(mode == 'm'){
- result += "<key>" + key + "</key>";
- result += QString::fromUtf8(read(it++, end));
- }
- else if(mode == 'l'){
+ if(mode == 'm'
+ || mode == 'l'
+ || mode == 'g'
+ || mode == 't'
+ || mode == 'y'
+ || mode == 'k'
+ || mode == 'w'
+ || mode == 'h'
+ || mode == 'r'){
result += "<key>" + key + "</key>";
- result += QString::fromUtf8(read(it++, end));
+ result += "<t>" + QString::fromUtf8(read(it++, end)) + "</t>";
}
- else if(mode == 'g'){
- result += "<key>" + key + "</key>";
- result += QString::fromUtf8(read(it++, end));
- /* delete "small" tag from translation*/
+ if(mode == 'g'){
+ /* delete "small" tag from g translation*/
int indexOfSmall=result.indexOf("<small>");
while(indexOfSmall!=-1){
int indexOfEndSmall= result.indexOf("</small>");
indexOfSmall=result.indexOf("<small>");
}
}
- else if(mode == 't'){
- result += "<key>" + key + "</key>";
- result += QString::fromUtf8(read(it++, end));
- }
- else if(mode == 'x'){
+ if(mode == 'x'){
result += QString::fromUtf8(read(it++, end));
result.replace("</k>","</key><t>");
result.replace("<k>","</t><key>");
if(result.contains("<t>"))
result+="</t>";
}
- else if(mode == 'y') {
- result += "<key>" + key + "</key>";
- result += QString::fromUtf8(read(it++, end));
- }
- else if(mode == 'k'){
- result += "<key>" + key + "</key>";
- result += QString::fromUtf8(read(it++, end));
- }
- else if(mode == 'w'){
- result += "<key>" + key + "</key>";
- result += QString::fromUtf8(read(it++, end));
- }
- else if(mode == 'h'){
- result += "<key>" + key + "</key>";
- result += QString::fromUtf8(read(it++, end));
- }
- else if(mode == 'r'){
- result += "<key>" + key + "</key>";
- result += QString::fromUtf8(read(it++, end));
- }
-
-// Dont know whether mDictionary would ever handle binary stardict format
+// W & P 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)
/*
}
} else
result += read(it++, end);
} */
-
- qDebug()<<"wynik "<<result;
return result;
}
}
-
QString StarDictPlugin::search(QString key, qint64 offset, qint32 len) {
QString dictPath = settings()->value("dictFileName");
StarDictReader *reader = StarDictReaderFactory::createReader(dictPath);
}
-bool StarDictPlugin::isCached() {
- return false;
-}
-
-
bool StarDictPlugin::setSettings(const Settings *sett) {
if(sett) {
foreach(QString key, sett->keys())
return &_icon;
}
-
-int StarDictPlugin::countWords() {
- return 0;
+QString StarDictPlugin::iconPath(){
+ return _iconPath;
}
-
-
-void StarDictPlugin::clean() {
-
-}
-
-
Q_EXPORT_PLUGIN2(stardict, StarDictPlugin)