code clean
[mdictionary] / src / plugins / google / GooglePlugin.cpp
index 38aac6c..3c3ff11 100644 (file)
     Copyright 2010 Comarch S.A.
 
 *******************************************************************************/
+/*!
+    \file GooglePlugin.cpp
+    \brief Implementation of google plugin's main class.
 
-/*! \file GooglePlugin.cpp
     \author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
 */
 
@@ -39,7 +41,8 @@ GooglePlugin::GooglePlugin(QObject *parent): CommonDictInterface(parent),
     _settings->setValue("type","google");
     _settings->setValue("connection_accepted","true");
     _dictDialog = new GoogleDictDialog(this,this);
-    _icon = QIcon("/usr/share/mdictionary/google.png");
+    _iconPath = "/usr/share/mdictionary/google.png";
+    _icon = QIcon(_iconPath);
 
     stopped = false;
     initLanguages();
@@ -53,9 +56,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");
     }
@@ -150,6 +151,10 @@ QIcon* GooglePlugin::icon() {
     return &_icon;
 }
 
+QString GooglePlugin::iconPath(){
+    return _iconPath;
+}
+
 
 CommonDictInterface* GooglePlugin::getNew(const Settings* settings) const {
     GooglePlugin *plugin = new GooglePlugin();
@@ -160,7 +165,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("");
 }
 
@@ -174,8 +179,10 @@ QList<Translation*> GooglePlugin::searchWordList(QString word, int ) {
     QList<Translation*> translations;
     if(isAvailable()) {
         QString error("");
-        word.replace("*","");   /*remove wildcard*/
-        word.replace("?","");
+        char wrongChar[]={"*?&<>"};
+        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"),
                                               _settings->value("lang_to"));
@@ -198,9 +205,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") {
@@ -223,7 +229,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;
@@ -287,9 +292,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+"\"";
     }
@@ -300,7 +304,6 @@ QString GooglePlugin::jsonParse(QString result) {
             result+=words.at(i)->at(j)+", ";
         result.remove(result.size()-2,2);
     }
-    //qDebug()<<"PO"<<result;
     return result;
 }