// Created by Bartosz Szatkowski
#include "backbone.h"
-
+#include <QDebug>
Backbone::Backbone(QObject *parent)
: QObject(parent)
{
searchLimitv = 10;
+ loadPlugins();
}
void Backbone::addDictionary(CommonDictInterface* dict) {
dicts[dict] = 1;
+<<<<<<< HEAD
+ connect(dict, SIGNAL(finalTranslation(QList<Translation*>)),
+ this, SLOT(translation(QList<Translation*>)),
+ Qt::QueuedConnection);
+=======
//connect(dict, SIGNAL(finalTranslation()),
// this, SLOT(translation()),
// Qt::UniqueConnection);
+>>>>>>> 22b7c270de4fcb536e0325485e69952ea88ebff7
}
void Backbone::translation(QList<Translation *> trans) {
activeSearchNum--;
foreach(Translation* t, trans)
+ {
_result.insert(t->key(), t);
+ qDebug()<<t->key();
+ }
if(activeSearchNum < 1)
Q_EMIT ready();
void Backbone::loadPlugins() {
- QObject *pl = QPluginLoader("xdxf.so").instance();
- if(!pl)
+ QPluginLoader loader("xdxf.so");
+ if(!loader.load())
+ {
+ qDebug()<<loader.errorString();
return;
+ }
+ QObject *pl = loader.instance();
+
+ qDebug()<<"loaded";
CommonDictInterface *plugin = qobject_cast<CommonDictInterface*>(pl);
plugins.append(plugin);
addDictionary(plugin);
this->backbone = backbone;
ui->setupUi(this);
- setAttribute(Qt::WA_Maemo5StackedWindow);
+ // setAttribute(Qt::WA_Maemo5StackedWindow);
searchBarWidget = new SearchBarWidget(backbone);
wordListWidget = new WordListWidget(backbone);
this->backbone = backbone;
- setAttribute(Qt::WA_Maemo5StackedWindow);
+ //setAttribute(Qt::WA_Maemo5StackedWindow);
setWindowFlags(windowFlags() | Qt::Window);
initializeUI();
wordListModel = new QStringListModel();
+ connect(backbone, SIGNAL(ready()),
+ this, SLOT(showSearchResults()));
+
setModel(wordListModel);
}
#include <QtGui/QApplication>
#include "MainWindow.h"
#include "../backbone/backbone.h"
+#include "../../includes/translation.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
+
+ qRegisterMetaType<Translation*>("Translation*");
+ qRegisterMetaType<QList<Translation*> >("QList<Translation*>");
Backbone* backbone = new Backbone;
MainWindow* w = new MainWindow(backbone);
w->show();
// Created by Bartosz Szatkowski
-
#ifndef COMMONDICTINTERFACE_H
#define COMMONDICTINTERFACE_H
class Settings;
-
//! Interface for dict engines plugins
class CommonDictInterface : public QObject {
Q_OBJECT
public:
+ CommonDictInterface(QObject *parent = 0):QObject(parent) {}
+
//! returns source language code iso 639-2
- virtual QString langFrom() const = 0;
+ virtual QString langFrom() const = 0;
//! returns destination language code iso 639-2
virtual QString langTo() const = 0;
virtual QString name() const = 0;
//! returns dictionary type (xdxf, google translate, etc)
- virtual QString type() const = 0;
+ virtual QString type() const = 0;
//! returns information about dictionary in html (name, authors, etc)
- virtual QString infoNote() const = 0;
+ virtual QString infoNote() const = 0;
//! return dialog that creates new dictionary and fills necesary options
//! QDialog should returns Setting* object after being showed
- virtual QDialog* loadDialog() = 0;
+ virtual QDialog* loadDialog() = 0;
//! return dialog with dictionary settings
virtual QDialog* settingsDialog() = 0;
//! return new, clean copy of plugin with setting set as in Settings*
virtual CommonDictInterface* getNew(const Settings*) const = 0;
- //! returns whether plugin can start searching
+ //! returns whether plugin can start searching
virtual bool isAvailable() const = 0;
+ //! returns the actual translation of a word given in key
+ virtual QString search(QString key) = 0;
+
//! \returns unique value (unique for every dictionary not plugin
virtual uint hash() const = 0;
public Q_SLOTS:
- /*! performes search in dictionary
+ /*! performs search in dictionary
\param word word to search in dictionary
\param limit limit on number of results
- After finishing search it have to emit
+ After finishing search it have to emit
\see CommonDictInterface:finalTranslation finalTranslation
*/
- virtual void search(QString word, int limit) = 0;
+ virtual void searchWordList(QString word, int limit) = 0;
//! stop current operation
- virtual void stop() = 0;
+ virtual void stop() = 0;
Q_SIGNALS:
- //! emit list of finded Translations
+ //! emit list of found Translations
void finalTranslation(QList<Translation*>);
//! emited after dictionary is ready to use afer being loaded
};
Q_DECLARE_INTERFACE(CommonDictInterface, "CommonDictInterface/0.1");
+
#endif
#include <QString>
#include "CommonDictInterface.h"
-//! Plugin specific configuration
+class CommonDictInterface;
+
+//! Plugin specific configuration
class Settings {
public:
//! \retrun value fo given key
virtual void setType(const CommonDictInterface*) = 0;
};
-#endif
+#endif // SETTINGS_H
#include <QString>
#include <QMetaType>
+
//! Keeping raw form of translation to be parsed only when needed
class Translation {
public:
};
Q_DECLARE_METATYPE(Translation*);
+Q_DECLARE_METATYPE(QList<Translation*>);
#endif
--- /dev/null
+#include "TranslationXdxf.h"
+
+TranslationXdxf::TranslationXdxf() {
+}
+
+TranslationXdxf::TranslationXdxf(QString _key, QString _dictionaryInfo, XdxfPlugin *xdxfPlugin): _key(_key),_dictionaryInfo(_dictionaryInfo) {
+ this->xdxfPlugin=xdxfPlugin;
+}
+
+QString TranslationXdxf::key() const {
+ return _key;
+}
+
+QString TranslationXdxf::dictionaryInfo() const {
+ return _dictionaryInfo;
+}
+
+QString TranslationXdxf::toHtml() const {
+ return xdxfPlugin->search(_key);
+}
+
+void TranslationXdxf::setKey(QString _key) {
+ this->_key=_key;
+}
+
+void TranslationXdxf::setDictionaryInfo(QString _dictionaryInfo) {
+ this->_dictionaryInfo=_dictionaryInfo;
+}
+
--- /dev/null
+#ifndef TRANSLATIONXDXF_H
+#define TRANSLATIONXDXF_H
+
+#include <QString>
+#include "../../../../includes/translation.h"
+#include "xdxfplugin.h"
+
+class XdxfPlugin;
+
+class TranslationXdxf : public Translation
+{
+public:
+ TranslationXdxf();
+ TranslationXdxf(QString _key,QString _dictionaryInfo, XdxfPlugin *xdxfPlugin);
+
+ //! \return word to be translated
+ QString key() const;
+
+ //! \returns dictionary information (plugin name, languages, <logo> etc)\
+ //! to be displayed in translation table header
+ QString dictionaryInfo() const;
+
+ //! \return parsed raw format into html
+ QString toHtml() const;
+
+ void setKey(QString);
+ void setDictionaryInfo(QString);
+
+
+private:
+ QString _key;
+ QString _dictionaryInfo;
+ XdxfPlugin *xdxfPlugin;
+
+};
+
+#endif // TRANSLATIONXDXF_H
+
--- /dev/null
+#-------------------------------------------------
+#
+# Project created by QtCreator 2010-08-03T09:33:52
+#
+#-------------------------------------------------
+
+QT += core xml gui
+
+
+TARGET = XdxfPlugin
+TEMPLATE = lib
+
+SOURCES += \
+ xdxfplugin.cpp \
+ TranslationXdxf.cpp
+
+
+HEADERS += \
+ xdxfplugin.h \
+ ../../../../includes/translation.h \
+ ../../../../includes/settings.h \
+ ../../../../includes/CommonDictInterface.h \
+ TranslationXdxf.h
--- /dev/null
+#include "xdxfplugin.h"
+#include <QDebug>
+#include <QFile>
+#include <QXmlStreamReader>
+#include <QtPlugin>
+
+XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
+ _langFrom(tr("")), _langTo(tr("")),_name(tr("")),
+ _type(tr("xdxf")), _infoNote(tr("")) {
+ path="dict.xdxf";
+}
+
+QString XdxfPlugin::langFrom() const {
+ return _langFrom;
+}
+
+QString XdxfPlugin::langTo() const {
+ return _langTo;
+}
+
+QString XdxfPlugin::name() const {
+ return _name;
+}
+
+QString XdxfPlugin::type() const {
+ return _type;
+}
+
+QString XdxfPlugin::infoNote() const {
+ return _infoNote;
+}
+
+void XdxfPlugin::searchWordList(QString word, int limit) {
+ QRegExp regWord(word);
+ QList<Translation*> translations;
+ regWord.setPatternSyntax(QRegExp::Wildcard);
+ QFile dictionaryFile(path);
+ if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+ return; //blad otwarcia pliku
+ }
+ 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();
+ QString a;
+ int i=0;
+ while(!dictionaryReader.atEnd() && !stopped){
+ dictionaryReader.readNextStartElement();
+ if(dictionaryReader.name()=="ar"){
+ while(dictionaryReader.name()!="k" && !dictionaryReader.atEnd())
+ dictionaryReader.readNextStartElement();
+ a = dictionaryReader.readElementText();
+ if(regWord.exactMatch(a) && i<limit) {
+ translations.append(new TranslationXdxf(a,_infoNote,this));
+ i++;
+ if(i>=limit)
+ break;
+ }
+ }
+ }
+ stopped=false;
+ emit finalTranslation(translations);
+ dictionaryFile.close();
+}
+
+QString XdxfPlugin::search(QString key) {
+ QFile dictionaryFile(path);
+ if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+ return ""; //blad otwarcia pliku
+ }
+ QXmlStreamReader dictionaryReader(&dictionaryFile);
+
+ QString a;
+ bool match =false;
+ while (!dictionaryReader.atEnd()) {
+ dictionaryReader.readNext();
+ if(dictionaryReader.tokenType() == QXmlStreamReader::StartElement) {
+ if(dictionaryReader.name()=="k") {
+ a = dictionaryReader.readElementText();
+ if(a==key)
+ match = true;
+ }
+ }
+ else if(dictionaryReader.tokenType() == QXmlStreamReader::Characters)
+ if(match) {
+ dictionaryFile.close();
+ return dictionaryReader.text().toString().replace("\n","");
+
+ }
+ }
+ return "";
+}
+
+void XdxfPlugin::stop() {
+ stopped=true;
+}
+
+QDialog* XdxfPlugin::loadDialog() {
+ path="dict.xdxf";
+}
+
+QDialog* XdxfPlugin::settingsDialog() {
+ ;
+}
+
+CommonDictInterface* XdxfPlugin::getNew(const Settings*) const {
+ ;
+}
+
+bool XdxfPlugin::isAvailable() const {
+ return true;
+}
+
+uint XdxfPlugin::hash() const
+{
+ return 1;
+}
+
+Q_EXPORT_PLUGIN2(xdxf, XdxfPlugin)
--- /dev/null
+#ifndef XDXFPLUGIN_H
+#define XDXFPLUGIN_H
+
+#include "../../../../includes/CommonDictInterface.h"
+#include <QObject>
+#include <QDialog>
+#include <QRegExp>
+#include "TranslationXdxf.h"
+
+class XdxfPlugin : public CommonDictInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(CommonDictInterface)
+public:
+ XdxfPlugin(QObject *parent=0);
+
+ //! returns source language code iso 639-2
+ QString langFrom() const;
+
+ //! returns destination language code iso 639-2
+ QString langTo() const;
+
+ //! returns dictionary name (like "old english" or so
+ QString name() const;
+
+ //! returns dictionary type (xdxf, google translate, etc)
+ QString type() const;
+
+ //! returns information about dictionary in html (name, authors, etc)
+ QString infoNote() const;
+
+ //! return dialog that creates new dictionary and fills necesary options
+ //! QDialog should returns Setting* object after being showed
+ QDialog* loadDialog();
+
+ //! return dialog with dictionary settings
+ QDialog* settingsDialog();
+
+ //! return new, clean copy of plugin with setting set as in Settings*
+ CommonDictInterface* getNew(const Settings*) const;
+
+ //! returns whether plugin can start searching
+ bool isAvailable() const;
+
+ QString search(QString key);
+
+ uint hash() const;
+
+public Q_SLOTS:
+ /*! performs search in dictionary
+ \param word word to search in dictionary
+ \param limit limit on number of results
+
+ After finishing search it have to emit
+ \see CommonDictInterface:finalTranslation finalTranslation
+ */
+
+ void searchWordList(QString word, int limit);
+
+ //! stop current operation
+ void stop();
+
+private:
+ bool isCached();
+ QString _langFrom;
+ QString _langTo;
+ QString _name;
+ QString _type;
+ QString _infoNote;
+ QDialog *_loadDialog;
+ QDialog *_settingsDialog;
+ QString path;
+ bool stopped; /*volatile*/
+};
+
+#endif // XDXFPLUGIN_H
+
+