change comment's and fix bug (xslt transform)
authorjakub <jakub.jaszczynski@comarch.com>
Fri, 19 Nov 2010 14:23:34 +0000 (15:23 +0100)
committerjakub <jakub.jaszczynski@comarch.com>
Fri, 19 Nov 2010 14:23:34 +0000 (15:23 +0100)
13 files changed:
src/include/settings.h
src/mdictionary/gui/TranslationWidget.cpp
src/mdictionary/gui/TranslationWidget.h
src/plugins/google/GoogleDialog.cpp
src/plugins/google/GoogleDialog.h
src/plugins/google/GoogleDictDialog.cpp
src/plugins/google/GoogleDictDialog.h
src/plugins/google/GooglePlugin.cpp
src/plugins/google/GooglePlugin.h
src/plugins/google/TranslationGoogle.h
src/plugins/stardict/StarDictPlugin.cpp
src/plugins/xdxf/XdxfDialog.cpp
src/plugins/xdxf/XdxfDictDownloader.cpp

index 96e227f..70ee7d9 100644 (file)
@@ -45,9 +45,10 @@ class Settings {
         _settings = QHash<QString, QString>(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)) {
index 7312d32..ca4356f 100644 (file)
@@ -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("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") + QString("\n <ar>")
-           + trans + QString("\n </ar>");
-
-    trans=checkTranslation(trans);
-    qDebug()<<"\n\n trans"<<trans;
-    trans=XslConversion(trans);
+    QString trans= createTranslation(translations);
 
     QString head = "<html><head>";
-    head += "<link rel=\"stylesheet\" type=\"text/css\" " ;
-    head += "href=\"/usr/share/mdictionary/css/" "style.css";
-    head += "\" /></head><body ondragstart=\"return false\">";
-    trans = head + trans;
+    head += "<link rel=\"stylesheet\" type=\"text/css\" "
+            "href=\"/usr/share/mdictionary/css/" "style.css"
+            "\" /></head><body ondragstart=\"return false\">";
+    trans = head + trans + "</body></html>";
 
-    trans+= "</body></html>";
     trans.replace("$STAR$", "/usr/share/mdictionary/staron.png");
 
- //   qDebug()<<"\n\n trans"<<trans;
     webkit->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("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") + QString("\n <ar>")
+               + trans + QString("\n </ar>");
+
+        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<trans.size()){
         if(pos==trans.indexOf("<key>",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<trans.size()){
+        if(trans.at(pos)=='<')
+            count++;
+        else if(trans.at(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(pos<trans.size()){
@@ -177,91 +207,69 @@ QString TranslationWidget::checkTranslation(QString trans){
     return trans;
 }
 
+
 #ifdef Q_WS_MAEMO_5
 void TranslationWidget::initButtons() {
-
         int x = width() - showButtonsButton->sizeHint().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();
index 3f34f55..b0e4f7c 100644 (file)
@@ -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;
index 2810b0e..45bf724 100644 (file)
@@ -18,8 +18,8 @@
     Copyright 2010 Comarch S.A.
 
 *******************************************************************************/
-
-/*! \file GoogleSettingsDialog.cpp
+/*!
+    \file GoogleSettingsDialog.cpp
     \author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
 */
 
@@ -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;
 }
index fb6e4ac..e935583 100644 (file)
@@ -18,7 +18,6 @@
     Copyright 2010 Comarch S.A.
 
 *******************************************************************************/
-
 /*!
     \file GoogleDialog.cpp
     \author Mateusz Półrola <mateusz.polrola@gmail.com>
@@ -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
index bd6bd37..6c7c0c3 100644 (file)
@@ -18,8 +18,8 @@
     Copyright 2010 Comarch S.A.
 
 *******************************************************************************/
-
-/*! \file GoogleDictDialog.cpp
+/*!
+    \file GoogleDictDialog.cpp
     \author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
 */
 
@@ -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());
-    }
 }
 
index 584509c..d3aa406 100644 (file)
@@ -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:
index d5e0683..ee25c53 100644 (file)
@@ -18,8 +18,8 @@
     Copyright 2010 Comarch S.A.
 
 *******************************************************************************/
-
-/*! \file GooglePlugin.cpp
+/*!
+    \file GooglePlugin.cpp
     \author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
 */
 
@@ -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<Translation*> GooglePlugin::searchWordList(QString word, int ) {
     if(isAvailable()) {
         QString error("");
         char wrongChar[]={"*?&<>"};
-        for(unsigned int a=0;a<sizeof(wrongChar);a++){    /*remove wrong char*/
+        for(unsigned int a=0;a<sizeof(wrongChar);a++)    /*remove wrong char*/
             word.replace(wrongChar[a],"");
-        }
 
         QString url=QString("/translate_a/t?client=t&sl=%1&tl=%2").arg(
                                               _settings->value("lang_from"),
@@ -201,9 +198,8 @@ QList<Translation*> 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<Translation*> GooglePlugin::searchWordList(QString word, int ) {
 
 
 QString GooglePlugin::jsonParse(QString result) {
-    //qDebug()<<"Json"<<result;
     int pos=0,pos2=0,index=0,size=0;
     QString returnLang;
     QString translation;
@@ -290,9 +285,8 @@ QString GooglePlugin::jsonParse(QString result) {
     }
     returnLang=list1.at(index*2+1);
     if(partOfSpeach.size()==0){
-        if(translation.toLower()==original.toLower()){
+        if(translation.toLower()==original.toLower())
             return QString(""); // word doesn't exist";
-        }
         else
             return "\""+translation+"\"";
     }
@@ -303,7 +297,6 @@ QString GooglePlugin::jsonParse(QString result) {
             result+=words.at(i)->at(j)+", ";
         result.remove(result.size()-2,2);
     }
-    //qDebug()<<"PO"<<result;
     return result;
 }
 
index 4f84f07..cfc2ebf 100644 (file)
@@ -18,9 +18,8 @@
     Copyright 2010 Comarch S.A.
 
 *******************************************************************************/
-
-/*! \file GooglePlugin.h
-
+/*!
+    \file GooglePlugin.h
     \author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
 */
 
@@ -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*
index 4eb41cc..187262a 100644 (file)
@@ -18,8 +18,8 @@
     Copyright 2010 Comarch S.A.
 
 *******************************************************************************/
-
-/*! \file TranslationGoogle.h
+/*!
+    \file TranslationGoogle.h
     \author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
 */
 
@@ -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;}
index b2de6bb..e9036ef 100644 (file)
@@ -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:     "<<mode;
-
+//    qDebug()<<"****** mode:     "<<mode;
     if(mode == 'm' ||
             mode == 'l' ||
             mode == 'g' ||
@@ -225,8 +224,6 @@ QString StarDictPlugin::interpret(QByteArray::iterator it,
         } else
             result += read(it++, end);
     } */
-
-    qDebug()<<"wynik  "<<result;
     return result;
 }
 
index 1a4c986..070a0bf 100644 (file)
@@ -182,8 +182,6 @@ void XdxfDialog::initializeUI() {
     #else
         if(type==New) {
             infoLabel->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
index 9a1ecbd..2e3517c 100644 (file)
 #include <QDebug>
 #include <QProcess>
 #include <bzlib.h>
-#ifndef Q_WS_MAEMO_5
-#include <libtar.h>
-#endif
 #include <stdio.h>
 #include <fcntl.h>
 
+#ifndef Q_WS_MAEMO_5
+    #include <libtar.h>
+#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;
     }