TEMPLATE = subdirs
-SUBDIRS = src
+SUBDIRS = src
CONFIG += ordered
include (mdictionary.pri)
check.CONFIG += recursive
-check.recurse = src
+check.recurse = src
QMAKE_EXTRA_TARGETS += check
//! \returns dictionary type (xdxf, google translate, etc)
virtual QString type() const = 0;
- //! \returns information about dictionary in html (name, authors, etc)
+ //! returns information about dictionary (name, authors, etc)
virtual QString infoNote() const = 0;
/*! \returns DictDialog object that creates dialogs
return this->key()==translation->key();
}
- //! \return parsed raw format into html
- virtual QString toHtml() const = 0;
+ //! \return parsed raw format into xml
+ virtual QString toXml() const = 0;
//! \return whether given translation is taken from bookmarks
virtual int isBookmark() const {
return _key;
}
- //! \return parsed raw format into html
- QString toHtml() const {
+ //! \return parsed raw format into xml
+ QString toXml() const {
if(!_key.size() || !_bookmarks)
return "";
cur.prepare("insert into bookmarks values (?,?,?)");
cur.addBindValue(translation->key());
cur.addBindValue(removeAccents(translation->key()));
- cur.addBindValue(translation->toHtml());
+ cur.addBindValue(translation->toXml());
cur.exec();
}
QList<Translation*> searchWordList(QString word);
/*! Searches for final translation of a given word
- \return word translation list in text format xml or html to be formatted
+ \return word translation list in text format xml to be formatted
and displayed
\param word word to search for
*/
_listAvailable = false;
}
-
void History::setMaxSize(int size) {
if(maxSize() <= 0) return;
if(size > _maxSize) {
/*! \return translation text for corresponding Translation object */
QString toHtml() const {
QString trans;
- trans = _tr->toHtml();
+ trans = _tr->toXml();
return trans;
}
loadDicts(_configPath);
connect(&_resultWatcher, SIGNAL(finished()), this, SLOT(translationReady()));
- connect(&_htmlResultWatcher, SIGNAL(finished()), this,
- SLOT(htmlTranslationReady()));
+ connect(&_xmlResultWatcher, SIGNAL(finished()), this,
+ SLOT(xmlTranslationReady()));
connect(&_bookmarkWatcher, SIGNAL(finished()), this,
SLOT(bookmarksListReady()));
connect(&_bookmarkSearchWatcher, SIGNAL(finished()), this,
foreach(CommonDictInterface* dict, _dicts.keys())
dict->stop();
stopped = true;
- _innerHtmlResult.cancel();
+ _innerXmlResult.cancel();
_innerResult.cancel();
Q_EMIT searchCanceled();
}
-QStringList Backbone::htmls() {
- return _htmlResult;
+QStringList Backbone::xmls() {
+ return _xmlResult;
}
-void Backbone::searchHtml(QList<Translation *> translations) {
- _htmlResult.clear();
+void Backbone::searchXml(QList<Translation *> translations) {
+ _xmlResult.clear();
QList<TranslationPtr> dummy;
stopped = false;
foreach(Translation* tr, translations) {
if(containsDict(tr->dict()) || !tr->dict())
dummy.append(TranslationPtr(tr));
- /* foreach(CommonDictInterface* dict, activeDicts()) {
- Translation* trans = dict->getTranslationFor(tr->key());
- if(trans)
- dummy.append(TranslationPtr(trans));
- } */
}
if(translations.size()>0) {
Translation *tr = translations.at(0);
}
}
- _innerHtmlResult = QtConcurrent::mapped(dummy,
+ _innerXmlResult = QtConcurrent::mapped(dummy,
&TranslationPtr::toHtml);
- _htmlResultWatcher.setFuture(_innerHtmlResult);
+ _xmlResultWatcher.setFuture(_innerXmlResult);
}
-void Backbone::htmlTranslationReady() {
+void Backbone::xmlTranslationReady() {
- QFutureIterator<QString> it(_innerHtmlResult);
+ QFutureIterator<QString> it(_innerXmlResult);
QSet<QString> uniqe;
while(it.hasNext())
uniqe.insert(it.next());
- _htmlResult.clear();
- _htmlResult = uniqe.toList();
+ _xmlResult.clear();
+ _xmlResult = uniqe.toList();
if(!stopped)
- Q_EMIT htmlReady();
+ Q_EMIT xmlReady();
}
- GUI calls result()
Final translation:
- - GUI calls searchHtml()
- - Backbone starts toHtml for each translation object in separate threads
- - Backbone sets FutureWatcher to be notified after last toHtml returns
+ - GUI calls searchXml()
+ - Backbone starts toXml for each translation object in separate threads
+ - Backbone sets FutureWatcher to be notified after last toXml returns
- Backbone fetches translation from Future<...> objects and calls
- htmlReady()
- - Gui calls htmlResult()
+ xmlReady()
+ - Gui calls xmlResult()
*/
class Backbone : public QObject
//! \return maximum number of words that plugin could find
int searchLimit() const;
- //! \return final translation (after searching for html)
- QStringList htmls();
+ //! \return final translation (after searching for xml)
+ QStringList xmls();
/*! maximum number of translations that each plugin may return; it must be
public static because of QtConcurent::mapped restrictions about
/*! Fired by FutureWatcher when search result is ready, fetch Future to
final result
*/
- void htmlTranslationReady();
+ void xmlTranslationReady();
/*! Removes a given dictionary
\param dict dictionary to be deleted
/*! Saves plugins new state/configuration after each change */
void dictUpdated();
- /*! Performs search for final translation (html/xml) from a list
+ /*! Performs search for final translation (xml) form
\param list of Translation* to be searched for
*/
- void searchHtml(QList<Translation*>);
+ void searchXml(QList<Translation*>);
/*! adds bookmarks to given translations (translation object is fetched and
//! emitted when there are search results ready to fetch
void ready();
- //! emitted when html result is ready to fetch
- void htmlReady();
+ //! emitted when xml result is ready to fetch
+ void xmlReady();
//! thrown when searches are stopped
void searchCanceled();
QFuture<QList<Translation*> > _innerResult; //Res of concurrent word search
- QFuture<QString> _innerHtmlResult; // Result of html search
+ QFuture<QString> _innerXmlResult; // Result of xml search
QFuture<QList<Translation*> > _innerBookmarks; //Res of search in bookmarks
QFuture<QList<Translation*> > _innerListBookmarks; //Res of search in bookmarks
- QFuture<QStringList> _innerHtmlBookmarks; //Html result of bookmarks search
+ QFuture<QStringList> _innerXmlBookmarks; //Xml result of bookmarks search
QMultiHash<QString, Translation*> _result; //Final result of word search
- QStringList _htmlResult; // Final result of html search
+ QStringList _xmlResult; // Final result of xml search
QList<Translation*> _bookmarksResult; // Final result of search in bookmarks
QFutureWatcher<QList<Translation*> > _resultWatcher;
QFutureWatcher<QList<Translation*> > _bookmarkWatcher;
QFutureWatcher<QList<Translation*> > _bookmarkSearchWatcher;
- QFutureWatcher<QString> _htmlResultWatcher;
+ QFutureWatcher<QString> _xmlResultWatcher;
QString _pluginPath;
hideWelcomeScreen();
#endif
- Q_EMIT showTranslation(backbone->htmls());
+ Q_EMIT showTranslation(backbone->xmls());
#ifdef Q_WS_MAEMO_5
notifyManager->screenChanged();
#endif
backbone, SLOT(search(QString)));
connect(this, SIGNAL(searchTranslations(QList<Translation*>)),
- backbone, SLOT(searchHtml(QList<Translation*>)));
+ backbone, SLOT(searchXml(QList<Translation*>)));
connect(this, SIGNAL(stopSearching()),
backbone, SLOT(stopSearching()));
connect(backbone, SIGNAL(ready()),
this, SIGNAL(setIdle()));
- connect(backbone, SIGNAL(htmlReady()),
+ connect(backbone, SIGNAL(xmlReady()),
this, SIGNAL(setIdle()));
connect(backbone, SIGNAL(ready()),
this, SLOT(wordListReady()));
- connect(backbone, SIGNAL(htmlReady()),
+ connect(backbone, SIGNAL(xmlReady()),
this, SLOT(translationsReady()));
connect(backbone, SIGNAL(searchCanceled()),
//! Displays translation of a word found in dictionaries
/*!
- Displays many translations of word, formatted as html.
+ Displays many translations of word, formatted as xml.
*/
class TranslationWidget : public QScrollArea {
Q_OBJECT
langToComboBox = new QComboBox;
int i=0;
+ int j=0;
int actualLangTo=0;
int actualLangFrom=0;
foreach(QString langs, GooglePlugin::languages.keys()){
if(langs==_langTo)
- actualLangTo=i;
+ actualLangTo=j;
if(langs==_langFrom)
actualLangFrom=i;
- langToComboBox->addItem(langs);
+ if(langs!="Detect langlage"){
+ langToComboBox->addItem(langs);
+ j++;
+ }
langFromComboBox->addItem(langs);
i++;
}
//! \returns dictionary type (xdxf, google translate, etc)
QString type() const;
- //! \returns information about dictionary in html (name, authors, etc)
+ //! returns information about dictionary (name, authors, etc)
QString infoNote() const;
//! sets the language to which the translation is done
return _key;
}
-QString TranslationGoogle::toHtml() const {
+QString TranslationGoogle::toXml() const {
QString result("");
if(!googlePlugin)
return result;
else
result+="bookmark=\"false\" >";
+ //qDebug()<<"trans: "<<_trans;
+
if(_trans!="")
return result+=_dictionaryInfo+ "</info>"+_trans +"</dict>";
QList<Translation*> translations=googlePlugin->searchWordList(_key);
+ //qDebug()<<"test: "<<translations.size();
if(translations.size()>0 && translations.at(0))
- return translations.at(0)->toHtml();
+ return translations.at(0)->toXml();
return "";
}
//! \return word to be translated
QString key() const;
- //! \return parsed raw format into html
- QString toHtml() const;
+ //! \return parsed raw format into xml
+ QString toXml() const;
/*! sets the word for which we want to find a translation
\param word for which we want to find a translation */
return _key;
}
-QString TranslationXdxf::toHtml() const {
+QString TranslationXdxf::toXml() const {
QString result("");
if(!xdxfPlugin)
return result;
//! \return word to be translated
QString key() const;
- //! \return parsed raw format into html
- QString toHtml() const;
+ //! \return parsed raw format into xml
+ QString toXml() const;
/*! sets the word for which we want to find a translation
\param word for which we want to find a translation */
QList<Translation*> XdxfPlugin::searchWordListCache(QString word, int limit) {
- int i=0;
QSet<Translation*> translations;
QString cacheFilePath = _settings->value("cache_path");
cur.addBindValue(limit);
cur.exec();
- bool in = false;
- while(cur.next() && (i<limit || limit==0 ) ) {
- in = true;
- bool ok=true;
- Translation *tran;
- foreach(tran,translations) {
- if(tran->key().toLower()==cur.value(0).toString().toLower())
- ok=false;
- }
- if(ok) { /*add key word to list*/
- translations.insert(new TranslationXdxf(
- cur.value(0).toString().toLower(),
- _dictionaryInfo, this));
- i++;
- }
+ while(cur.next() && (translations.size()<limit || limit==0)) {
+ translations.insert(new TranslationXdxf(
+ cur.value(0).toString(),
+ _dictionaryInfo, this));
}
db.close();
return translations.toList();
readKey = reader.readElementText();
if((regWord.exactMatch(readKey)
|| regWord.exactMatch(removeAccents(readKey)))
- && (i<limit || limit==0)) {
- bool ok=true;
- Translation *tran;
- foreach(tran,translations) {
- if(tran->key().toLower()==readKey.toLower())
- ok=false; /*if key is in the dictionary more that one */
- }
- if(ok) { /*add key word to list*/
- translations<<(new TranslationXdxf(readKey.toLower(),
- _dictionaryInfo,this));
- i++;
- }
- if(i>=limit && limit!=0)
+ && (i<limit || limit==0) && !reader.atEnd()) {
+ // qDebug()<<readKey;
+ translations<<(new TranslationXdxf(readKey.toLower(),
+ _dictionaryInfo,this));
+ if(translations.size()==limit && limit!=0)
break;
}
}
void XdxfPlugin::stop() {
+ //qDebug()<<"stop";
stopped=true;
}
reader.readNextStartElement();
if(reader.name()=="full_name")
_name=reader.readElementText();
+ else
+ qDebug()<<"no full_name";
reader.readNextStartElement();
if(reader.name()=="description")
_infoNote=reader.readElementText();
+ else
+ qDebug()<<"no description";
_dictionaryInfo= _name + " [" + _langFrom + "-"
+ _langTo + "]";
XdxfCachingDialog d(_dictDialog->lastDialogParent());
- qDebug()<<_dictDialog->lastDialogParent();
+// qDebug()<<_dictDialog->lastDialogParent();
connect(&d, SIGNAL(cancelCaching()),
this, SLOT(stop()));
-
connect(this, SIGNAL(updateCachingProgress(int,int)),
&d, SLOT(updateCachingProgress(int,int)));
temp="<key>" + readKey + "</key>" + "<t>" + temp+ "</t>";
match=false;
cur.prepare("insert into dict values(?,?,?)");
- cur.addBindValue(readKey);
- cur.addBindValue(removeAccents(readKey));
+ cur.addBindValue(readKey.toLower());
+ cur.addBindValue(removeAccents(readKey).toLower());
cur.addBindValue(temp);
cur.exec();
counter++;
Q_EMIT notify(Notify::Warning,
QString(tr("Database caching error, please try again.")));
db.close();
+ _settings->setValue("cache_path", cachePathN);
+ if(stopped)
+ clean();
+ _settings->setValue("cache_path","");
return false;
}
_settings->setValue("cache_path", cachePathN);
_settings->setValue("cached", "true");
-
disconnect(&d, SIGNAL(cancelCaching()),
this, SLOT(stop()));
-
disconnect(this, SIGNAL(updateCachingProgress(int,int)),
&d, SLOT(updateCachingProgress(int,int)));
-
db.close();
return true;
}
-
void XdxfPlugin::clean() {
if(QFile::exists(_settings->value("cache_path"))) {
QFile(_settings->value("cache_path")).remove();
#include <QFile>
#include <QXmlStreamReader>
#include <QtPlugin>
+#include <QHash>
#include "../../include/CommonDictInterface.h"
#include "../../include/settings.h"
//! \returns dictionary type (xdxf, google translate, etc)
QString type() const;
- //! \returns information about dictionary in html (name, authors, etc)
+ //! returns information about dictionary in xml (name, authors, etc)
QString infoNote() const;
/*! \returns DictDialog object that creates dialogs
../../src/include/CommonDictInterface.h \
../../src/plugins/google/TranslationGoogle.h \
../../src/plugins/google/GoogleDictDialog.h \
- ../../src/plugins/google/GoogleSettingsDialog.h
+ ../../src/plugins/google/GoogleDialog.h
SOURCES += test.cpp \
../../src/plugins/google/GooglePlugin.cpp \
../../src/plugins/google/TranslationGoogle.cpp \
../../src/plugins/google/GoogleDictDialog.cpp \
- ../../src/plugins/google/GoogleSettingsDialog.cpp
+ ../../src/plugins/google/GoogleDialog.cpp
+
+
+
target.path = .
target.commands = ./GooglePluginTests
#include <QtTest/QtTest>
#include "../../src/plugins/google/GooglePlugin.h"
+#include "../../src/plugins/google/TranslationGoogle.h"
+#include "../../src/plugins/google/GoogleDictDialog.h"
+#include "../../src/plugins/google/GoogleDialog.h"
class GoogleTest: public QObject
../../src/include/DictDialog.h \
../../src/include/CommonDictInterface.h \
../../src/plugins/xdxf/XdxfDictDialog.h \
- ../../src/plugins/xdxf/XdxfLoadDialog.h \
- ../../src/plugins/xdxf/XdxfSettingsDialog.h \
+ ../../src/plugins/xdxf/XdxfDialog.h \
../../src/plugins/xdxf/XdxfCachingDialog.h
SOURCES += test.cpp \
../../src/plugins/xdxf/xdxfplugin.cpp \
../../src/plugins/xdxf/TranslationXdxf.cpp \
- ../../src/plugins/xdxf/XdxfLoadDialog.cpp \
+ ../../src/plugins/xdxf/XdxfDialog.cpp \
../../src/plugins/xdxf/XdxfDictDialog.cpp \
../../src/plugins/xdxf/XdxfCachingDialog.cpp \
- ../../src/plugins/xdxf/XdxfSettingsDialog.cpp
+
target.path = .
target.commands = ./xdxfPluginTests
QList<Translation*> te4 = xdxfPlugin->searchWordList("ho*SE", 10);
QCOMPARE(te4.at(0)->key(), QString("house"));
+ qDebug()<<"\n\n\n";
QList<Translation*> te5 = xdxfPlugin->searchWordList("*");
- QCOMPARE(te5.size(), 9);
+ qDebug()<<"\n\n\n";
+ QCOMPARE(te5.size(), 9);
+
QList<Translation*> te6 = xdxfPlugin->searchWordList("*", 8);
QCOMPARE(te6.size(), 8);
class TranslationMock : public Translation
{
public:
+
+ ~TranslationMock () {}
QString _key, _translation;
QString key() const {return _key;}
- QString toHtml() const {return _translation;}
+ QString toXml() const {return _translation;}
};
#endif // TRANSLATIONMOCK_H