From 8ef1fe7254cfa683e0d3377bd8832ce12410c7dc Mon Sep 17 00:00:00 2001 From: jakub Date: Fri, 19 Nov 2010 15:23:34 +0100 Subject: [PATCH] change comment's and fix bug (xslt transform) --- src/include/settings.h | 7 +- src/mdictionary/gui/TranslationWidget.cpp | 135 +++++++++++++++-------------- src/mdictionary/gui/TranslationWidget.h | 1 + src/plugins/google/GoogleDialog.cpp | 33 +++---- src/plugins/google/GoogleDialog.h | 2 - src/plugins/google/GoogleDictDialog.cpp | 12 ++- src/plugins/google/GoogleDictDialog.h | 13 ++- src/plugins/google/GooglePlugin.cpp | 19 ++-- src/plugins/google/GooglePlugin.h | 10 +-- src/plugins/google/TranslationGoogle.h | 12 +-- src/plugins/stardict/StarDictPlugin.cpp | 5 +- src/plugins/xdxf/XdxfDialog.cpp | 2 - src/plugins/xdxf/XdxfDictDownloader.cpp | 13 +-- 13 files changed, 127 insertions(+), 137 deletions(-) diff --git a/src/include/settings.h b/src/include/settings.h index 96e227f..70ee7d9 100644 --- a/src/include/settings.h +++ b/src/include/settings.h @@ -45,9 +45,10 @@ class Settings { _settings = QHash(set->_settings); } - /*! \returns value fo a given key - \param key name of a given setting - \return value of a given setting + /*! + \returns value fo a given key + \param key name of a given setting + \return value of a given setting */ QString value(const QString key) const { if(!_settings.contains(key)) { diff --git a/src/mdictionary/gui/TranslationWidget.cpp b/src/mdictionary/gui/TranslationWidget.cpp index 7312d32..ca4356f 100644 --- a/src/mdictionary/gui/TranslationWidget.cpp +++ b/src/mdictionary/gui/TranslationWidget.cpp @@ -41,7 +41,6 @@ TranslationWidget::TranslationWidget(QWidget *parent): setWindowFlags(windowFlags() | Qt::Window); #endif - initializeUI(); setWindowTitle("mDictionary"); @@ -70,41 +69,45 @@ void TranslationWidget::show(QStringList translations) { initButtons(); #endif - // webkit->repaint(this->rect()); - // update(this->rect()); - - QString trans; - QString t; - - foreach(t, translations) { - trans += t + "\n"; - } - - - trans=QString("") + QString("\n ") - + trans + QString("\n "); - - trans=checkTranslation(trans); - qDebug()<<"\n\n trans"<"; - trans = head + trans; + head += ""; + trans = head + trans + ""; - trans+= ""; trans.replace("$STAR$", "/usr/share/mdictionary/staron.png"); - // qDebug()<<"\n\n trans"<setHtml(trans, QUrl().fromLocalFile("/")); - //webkit->repaint(this->rect()); - //update(this->rect()); +} + - // Q_EMIT updateSize(); +QString TranslationWidget::createTranslation(QStringList translations) { + QString trans; + if(!translations.size()) + return QString("Empty translation"); + int element=-1; + do{ + int a=0; + foreach(QString t, translations){ + if(a!=element) + trans += t + "\n"; + a++; + } + trans=QString("") + QString("\n ") + + trans + QString("\n "); + + trans=checkTranslation(trans); + trans=XslConversion(trans); + element++; + if(element>translations.size()) + return QString("Empty translation"); + } while(trans==""); // trans=="" only when XslConversation have a error; + return trans; } + QString TranslationWidget::XslConversion(QString translation) { QXmlQuery myQuery(QXmlQuery::XSLT20); @@ -115,12 +118,14 @@ QString TranslationWidget::XslConversion(QString translation) return result; } + QString TranslationWidget::checkTranslation(QString trans){ /*check all "&"*/ int pos=0; int pos2; int count=0; + /*check "<" and ">" in key */ while(pos!=-1){ pos=trans.indexOf("&",pos+1); pos2=trans.indexOf("amp;",pos); @@ -142,13 +147,11 @@ QString TranslationWidget::checkTranslation(QString trans){ trans.insert(pos+1,"amp;"); } - - /*check all "<" and ">" in key */ + /*check "<" and ">" in key */ pos=0; count=0; while(pos",pos)){ - qDebug()<<"key"; count++; pos+=4; } @@ -159,8 +162,35 @@ QString TranslationWidget::checkTranslation(QString trans){ pos++; } + /*checking unclosed tag's*/ + pos=0; + count=0; + while(pos') + count--; + if(count==-1){ // remove ">" + trans.remove(pos,1); + count=0; + } + pos++; + } + pos=trans.size()-1; + count=0; + while(pos>-1){ + if(trans.at(pos)=='>') + count++; + else if(trans.at(pos)=='<') + count--; + if(count==-1){ // remove "<" + trans.remove(pos,1); + count=0; + } + pos--; + } - /*check all """ and "'" */ + /*check """ and "'" */ pos=0; count=0; while(possizeHint().width(); int y = height() - showButtonsButton->sizeHint().height(); showButtonsButton->move(QPoint(x,y)); showButtonsButton->show(); - - x = width() - zoomOutButton->sizeHint().width(); y = height() - 2*zoomOutButton->sizeHint().height(); zoomOutButton->move(QPoint(x, height())); - zoomOutButtonAnimation = - new QPropertyAnimation(zoomOutButton, "pos", this); - + zoomOutButtonAnimation = new QPropertyAnimation(zoomOutButton, + "pos", this); zoomOutButtonAnimation->setStartValue(QPoint(x, height())); zoomOutButtonAnimation->setEndValue(QPoint(x,y)); zoomOutButtonAnimation->setDuration(200); zoomOutButtonAnimation->setEasingCurve(QEasingCurve::InOutBack); - - x = width() - zoomInButton->sizeHint().width(); y = height() - 3*zoomInButton->sizeHint().height(); zoomInButton->move(QPoint(x, height())); - zoomInButtonAnimation = - new QPropertyAnimation(zoomInButton, "pos", this); - + zoomInButtonAnimation = new QPropertyAnimation(zoomInButton, + "pos", this); zoomInButtonAnimation->setStartValue(QPoint(x, height())); zoomInButtonAnimation->setEndValue(QPoint(x,y)); zoomInButtonAnimation->setDuration(400); zoomInButtonAnimation->setEasingCurve(QEasingCurve::InOutBack); - - x = 0; y = height() - copyButton->sizeHint().height(); copyButton->move(QPoint(x, height())); - - copyButtonAnimation = - new QPropertyAnimation(copyButton, "pos", this); - + copyButtonAnimation = new QPropertyAnimation(copyButton, "pos", this); copyButtonAnimation->setStartValue(QPoint(x, height())); copyButtonAnimation->setEndValue(QPoint(x,y)); copyButtonAnimation->setDuration(200); copyButtonAnimation->setEasingCurve(QEasingCurve::InOutBack); - - x = 0; y = height() - 2*copyButton->sizeHint().height(); selectAllButton->move(QPoint(x, height())); - - selectAllButtonAnimation = - new QPropertyAnimation(selectAllButton, "pos", this); - + selectAllButtonAnimation = new QPropertyAnimation(selectAllButton, + "pos", this); selectAllButtonAnimation->setStartValue(QPoint(x, height())); selectAllButtonAnimation->setEndValue(QPoint(x,y)); selectAllButtonAnimation->setDuration(400); selectAllButtonAnimation->setEasingCurve(QEasingCurve::InOutBack); - - x = 0; y = height() - 3*copyButton->sizeHint().height(); searchButton->move(QPoint(x, height())); - - searchButtonAnimation = - new QPropertyAnimation(searchButton, "pos", this); - + searchButtonAnimation = new QPropertyAnimation(searchButton, + "pos", this); searchButtonAnimation->setStartValue(QPoint(x, height())); searchButtonAnimation->setEndValue(QPoint(x,y)); searchButtonAnimation->setDuration(600); searchButtonAnimation->setEasingCurve(QEasingCurve::InOutBack); - - - buttonsAnimation = new QParallelAnimationGroup(this); buttonsAnimation->addAnimation(zoomInButtonAnimation); buttonsAnimation->addAnimation(zoomOutButtonAnimation); @@ -277,7 +285,6 @@ void TranslationWidget::initButtons() { #endif void TranslationWidget::initializeUI() { - webkit = new TranslationView(this); Settings* set = guiinterface->settings(); qreal fac = set->value("zoom").toFloat(); diff --git a/src/mdictionary/gui/TranslationWidget.h b/src/mdictionary/gui/TranslationWidget.h index 3f34f55..b0e4f7c 100644 --- a/src/mdictionary/gui/TranslationWidget.h +++ b/src/mdictionary/gui/TranslationWidget.h @@ -73,6 +73,7 @@ private Q_SLOTS: private: QString XslConversion(QString translation); QString checkTranslation(QString trans); + QString createTranslation(QStringList translations); QToolButton* zoomInToolButton; QToolButton* zoomOutToolButton; TranslationView *webkit; diff --git a/src/plugins/google/GoogleDialog.cpp b/src/plugins/google/GoogleDialog.cpp index 2810b0e..45bf724 100644 --- a/src/plugins/google/GoogleDialog.cpp +++ b/src/plugins/google/GoogleDialog.cpp @@ -18,8 +18,8 @@ Copyright 2010 Comarch S.A. *******************************************************************************/ - -/*! \file GoogleSettingsDialog.cpp +/*! + \file GoogleSettingsDialog.cpp \author Jakub Jaszczynski */ @@ -62,6 +62,10 @@ GoogleDialog::GoogleDialog(GooglePlugin *plugin, void GoogleDialog::initializeUI() { + int i=0,j=0; + int actualLangTo=0; + int actualLangFrom=0; + setWindowTitle(tr("Google Plugin Settings")); langFromLabel = new QLabel(tr("From:")); @@ -70,16 +74,14 @@ void GoogleDialog::initializeUI() { verticalLayout = new QVBoxLayout; setLayout(verticalLayout); - langLayout = new QVBoxLayout; langsFormLayout = new QFormLayout; changeLangLayout = new QHBoxLayout; - #ifdef Q_WS_MAEMO_5 setMinimumHeight(370); changeLangButton=new QPushButton( - QIcon::fromTheme("general_refresh"), ""); + QIcon::fromTheme("general_refresh"), ""); #else changeLangButton=new QPushButton( QIcon::fromTheme("object-flip-vertical"),""); @@ -91,23 +93,16 @@ void GoogleDialog::initializeUI() { tr("To: ") + _langTo); verticalLayout->addWidget(infoLabel); - #ifdef Q_WS_MAEMO_5 connectInfoLabel = new QLabel(tr("Google plugin makes use of Internet " "connection, so it may cost You.")); connectInfoLabel->setWordWrap(true); - verticalLayout->addWidget(connectInfoLabel); #endif langFromComboBox = new QComboBox; 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=j; @@ -127,7 +122,6 @@ void GoogleDialog::initializeUI() { langLayout->addLayout(langsFormLayout); langsFormLayout->addRow(langFromLabel, langFromComboBox); - langsFormLayout->addRow(langToLabel, langToComboBox); changeLangLayout->addLayout(langLayout); @@ -146,22 +140,22 @@ void GoogleDialog::initializeUI() { verticalLayout->addWidget(confirmButton); setModal(true); - setMinimumSize(sizeHint()); setMaximumSize(sizeHint()); } + void GoogleDialog::langFromChanged(int index) { _langFrom=langFromComboBox->itemText(index); } + void GoogleDialog::langToChanged(int index) { _langTo=langToComboBox->itemText(index); } -void GoogleDialog::changeLangButtonClicked() { - //int tempIndexTo=langToComboBox->currentIndex(); +void GoogleDialog::changeLangButtonClicked() { int indexTo=langToComboBox->findText(langFromComboBox->currentText()); int indexFrom=langFromComboBox->findText(langToComboBox->currentText()); @@ -169,17 +163,15 @@ void GoogleDialog::changeLangButtonClicked() { langToComboBox->setCurrentIndex(indexTo); langFromComboBox->setCurrentIndex(indexFrom); } - - // langToComboBox->setCurrentIndex(langFromComboBox->currentIndex()); - //langFromComboBox->setCurrentIndex(tempIndexTo); } + void GoogleDialog::accept() { saveSettings(); - QDialog::accept(); } + void GoogleDialog::saveSettings() { _settings = new Settings; if(plugin) { @@ -193,6 +185,7 @@ void GoogleDialog::saveSettings() { GooglePlugin::languages.value(_langFrom)); } + Settings* GoogleDialog::getSettings() { return _settings; } diff --git a/src/plugins/google/GoogleDialog.h b/src/plugins/google/GoogleDialog.h index fb6e4ac..e935583 100644 --- a/src/plugins/google/GoogleDialog.h +++ b/src/plugins/google/GoogleDialog.h @@ -18,7 +18,6 @@ Copyright 2010 Comarch S.A. *******************************************************************************/ - /*! \file GoogleDialog.cpp \author Mateusz Półrola @@ -62,7 +61,6 @@ public: GoogleDialogType type = New, QWidget* parent = 0); - //! \returns settings of plugin /*! After acceptance of dialog this method returns plugin's settings based on diff --git a/src/plugins/google/GoogleDictDialog.cpp b/src/plugins/google/GoogleDictDialog.cpp index bd6bd37..6c7c0c3 100644 --- a/src/plugins/google/GoogleDictDialog.cpp +++ b/src/plugins/google/GoogleDictDialog.cpp @@ -18,8 +18,8 @@ Copyright 2010 Comarch S.A. *******************************************************************************/ - -/*! \file GoogleDictDialog.cpp +/*! + \file GoogleDictDialog.cpp \author Jakub Jaszczynski */ @@ -31,16 +31,15 @@ GoogleDictDialog::GoogleDictDialog(GooglePlugin *plugin, QObject *parent) : this->plugin = plugin; } + Settings* GoogleDictDialog::addNewDictionary(QWidget *parent) { GoogleDialog d(0, GoogleDialog::New, parent); connect(&d, SIGNAL(notify(Notify::NotifyType,QString)), this, SIGNAL(notify(Notify::NotifyType,QString))); - if(d.exec() == QDialog::Accepted) { + if(d.exec() == QDialog::Accepted) return d.getSettings(); - } - return 0; } @@ -50,8 +49,7 @@ void GoogleDictDialog::changeSettings(QWidget * parent) { connect(&d, SIGNAL(notify(Notify::NotifyType,QString)), this, SIGNAL(notify(Notify::NotifyType,QString))); - if(d.exec() == QDialog::Accepted) { + if(d.exec() == QDialog::Accepted) plugin->setSettings(d.getSettings()); - } } diff --git a/src/plugins/google/GoogleDictDialog.h b/src/plugins/google/GoogleDictDialog.h index 584509c..d3aa406 100644 --- a/src/plugins/google/GoogleDictDialog.h +++ b/src/plugins/google/GoogleDictDialog.h @@ -18,7 +18,6 @@ Copyright 2010 Comarch S.A. *******************************************************************************/ - /*! \file GoogleDictDialog.h \brief Class launches dialog which generates a new dictionary, or changes settings @@ -40,15 +39,15 @@ class GoogleDictDialog : public DictDialog public: explicit GoogleDictDialog(GooglePlugin* plugin, QObject *parent = 0); /*! - Shows "add new google dictionary" dialog and returns settings of a new dict - \param parent parent widget on which dialog will be displayed - */ + Shows "add new google dictionary" dialog and returns settings of a new dict + \param parent parent widget on which dialog will be displayed + */ Settings* addNewDictionary(QWidget *parent); /*! - Shows "settings" dialog and saves new settings in plugin - \param parent parent widget on which dialog will be displayed - */ + Shows "settings" dialog and saves new settings in plugin + \param parent parent widget on which dialog will be displayed + */ void changeSettings(QWidget *parent); private: diff --git a/src/plugins/google/GooglePlugin.cpp b/src/plugins/google/GooglePlugin.cpp index d5e0683..ee25c53 100644 --- a/src/plugins/google/GooglePlugin.cpp +++ b/src/plugins/google/GooglePlugin.cpp @@ -18,8 +18,8 @@ Copyright 2010 Comarch S.A. *******************************************************************************/ - -/*! \file GooglePlugin.cpp +/*! + \file GooglePlugin.cpp \author Jakub Jaszczynski */ @@ -53,9 +53,7 @@ GooglePlugin::GooglePlugin(QObject *parent): CommonDictInterface(parent), void GooglePlugin::retranslate() { QString locale = QLocale::system().name(); - QTranslator *translator = new QTranslator(this); - if(!translator->load(":/google/translations/" + locale)) { translator->load(":/google/translations/en_US"); } @@ -160,7 +158,7 @@ CommonDictInterface* GooglePlugin::getNew(const Settings* settings) const { QString GooglePlugin::search(QString) { - qDebug() << "function is not used in this plugin"; + qDebug() << "function is not used in google plugin"; return QString(""); } @@ -175,9 +173,8 @@ QList GooglePlugin::searchWordList(QString word, int ) { if(isAvailable()) { QString error(""); char wrongChar[]={"*?&<>"}; - for(unsigned int a=0;avalue("lang_from"), @@ -201,9 +198,8 @@ QList GooglePlugin::searchWordList(QString word, int ) { error=http->errorString(); if(lastState!=http->state()) { lastState=http->state(); - if(lastState==0){ + if(lastState==0) done(); - } } } if(error!="" && error!="Unknown error") { @@ -226,7 +222,6 @@ QList GooglePlugin::searchWordList(QString word, int ) { QString GooglePlugin::jsonParse(QString result) { - //qDebug()<<"Json"<at(j)+", "; result.remove(result.size()-2,2); } - //qDebug()<<"PO"< */ @@ -71,9 +70,10 @@ public: //! sets the language from which the translation is done void setLangFrom(QString langFrom); - /*! \returns DictDialog object that creates dialogs + /*! + \returns DictDialog object that creates dialogs for adding new dictionaries and changing plugin things - */ + */ DictDialog* dictDialog(); //! \returns new, clean copy of plugin with settings set as in Settings* diff --git a/src/plugins/google/TranslationGoogle.h b/src/plugins/google/TranslationGoogle.h index 4eb41cc..187262a 100644 --- a/src/plugins/google/TranslationGoogle.h +++ b/src/plugins/google/TranslationGoogle.h @@ -18,8 +18,8 @@ Copyright 2010 Comarch S.A. *******************************************************************************/ - -/*! \file TranslationGoogle.h +/*! + \file TranslationGoogle.h \author Jakub Jaszczynski */ @@ -45,8 +45,10 @@ public: //! \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 */ + /*! + sets the word for which we want to find a translation + \param word for which we want to find a translation + */ void setKey(QString); //! sets information about dictionary @@ -55,7 +57,7 @@ public: //! \return whether given translation is taken from bookmarks int isBookmark() const { return _bookmark; - } + } //! \returns corresponding dict object uint dict() const {return _dictHash;} diff --git a/src/plugins/stardict/StarDictPlugin.cpp b/src/plugins/stardict/StarDictPlugin.cpp index b2de6bb..e9036ef 100644 --- a/src/plugins/stardict/StarDictPlugin.cpp +++ b/src/plugins/stardict/StarDictPlugin.cpp @@ -162,8 +162,7 @@ QByteArray StarDictPlugin::read(QByteArray::iterator it, QString StarDictPlugin::interpret(QByteArray::iterator it, QByteArray::iterator end, QChar mode,QString key, bool last) { QString result; - qDebug()<<"****** mode: "<setMinimumWidth(250); - setMinimumSize(sizeHint().width()*1.5, sizeHint().height()*1.2); - setMaximumSize(sizeHint().width()*1.7, sizeHint().height()*1.5); scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); } #endif diff --git a/src/plugins/xdxf/XdxfDictDownloader.cpp b/src/plugins/xdxf/XdxfDictDownloader.cpp index 9a1ecbd..2e3517c 100644 --- a/src/plugins/xdxf/XdxfDictDownloader.cpp +++ b/src/plugins/xdxf/XdxfDictDownloader.cpp @@ -28,14 +28,17 @@ #include #include #include -#ifndef Q_WS_MAEMO_5 -#include -#endif #include #include +#ifndef Q_WS_MAEMO_5 + #include +#endif + + typedef void BZFILE; + XdxfDictDownloader::XdxfDictDownloader(QObject *parent) : QObject(parent) { parentDialog = 0; @@ -174,7 +177,6 @@ void XdxfDictDownloader::dictListReceived(QNetworkReply *reply) { progressDialog->show(); QString url = selectDialog.link(); - _fileName = url.split('/').last(); QProcess clean; @@ -223,7 +225,8 @@ bool XdxfDictDownloader::extract(QString file) { if(err == -1) return false; - err = tar_extract_all(t,"/tmp/mdict/"); + char text[]={"/tmp/mdict/"}; + err = tar_extract_all(t,text); if(err == -1) { return false; } -- 1.7.9.5