changed the format of translation display
authorJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Fri, 20 Aug 2010 08:30:20 +0000 (10:30 +0200)
committerJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Fri, 20 Aug 2010 08:30:20 +0000 (10:30 +0200)
data/dicts/eng-thai.xdxf
data/dicts/eng-us.xdxf
trunk/src/base/gui/TranslationWidget.cpp
trunk/src/base/xsl.xsl
trunk/src/includes/CommonDictInterface.h
trunk/src/plugins/xdxf/src/TranslationXdxf.cpp
trunk/src/plugins/xdxf/src/xdxfplugin.cpp
trunk/src/plugins/xdxf/src/xdxfplugin.h
trunk/src/plugins/xdxf/tests/test.cpp

index 353129f..d519da3 100644 (file)
@@ -19,8 +19,6 @@ sib</ar>
 nueng-muen</ar>
 <ar><k>100</k>
 nueng-roy</ar>
-<ar><k>Aluminum</k>
-Aluminium to kolejne tlumaczenie z innego slownika</ar>
 <ar><k>100,000</k>
 nueng-saen</ar>
 <ar><k>101</k>
index 5b1a879..220c3e3 100644 (file)
@@ -10,7 +10,7 @@ Medium Wave</ar>
 <ar><k>Airplane</k>
 Aeroplane</ar>
 <ar><k>Aluminum</k>
-Aluminium <tr>wymowa</tr> <ex>przyklad</ex> <c c="#FF00FF"> <b> test koloru i pogrobienia </b> </c> </ar>
+Aluminium</ar>
 <ar><k>Apartment</k>
 Flatlane</ar>
 <ar><k>Appetizer</k>
@@ -302,7 +302,7 @@ Tartlane</ar>
 <ar><k>airplane</k>
 Aeroplane</ar>
 <ar><k>aluminum</k>
-Aluminium to ala ma kota a kot ma ale Aluminium to ala ma kota a kot ma alAluminium to ala ma kota a kot ma alAluminium to ala ma kota a kot ma al</ar>
+Aluminium</ar>
 <ar><k>amrtment</k>
 Medium Wave</ar>
 <ar><k>anesthesia</k>
index f1a4d8b..3b76c75 100644 (file)
@@ -69,12 +69,10 @@ void TranslationWidget::show(QStringList translations) {
         trans += t + "\n";
     }
 
+    qDebug()<<trans;
 
     trans=tr("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") + tr("\n <ar>") + trans + tr("\n </ar>");
-//    trans.replace("&","&amp;");
     trans=XslConversion(trans);
-    qDebug()<<trans;
-//    trans.replace("&amp;","&");
     textEdit->insertHtml(trans);
  //   textEdit->setPlainText(trans);
 
index ce50c46..3972b6b 100644 (file)
@@ -5,25 +5,33 @@
        <html>
        <body>
        <table border="1" WIDTH="100%">
-       <tr bgcolor="#99CCFF">
-               <th><xsl:value-of select="ar/dict[1]/key"/></th>
-       </tr>
        <xsl:for-each select="ar/dict"> 
-               <!-- <xsl:variable name="path" select="info/@path"/>-->
-               <tr bgcolor="#99FF99">
-                       <th><xsl:value-of select="info"/> <!-- <img src="{$path}"/> --></th>
-               </tr>
-               <xsl:for-each select="t">
-                       <tr>
-                       <td><xsl:apply-templates/></td>
-                       </tr>
-               </xsl:for-each> 
+               <xsl:apply-templates/>
        </xsl:for-each>
        </table>
        </body>
        </html>
 </xsl:template> 
 
+<xsl:template match="info">
+       <!-- <xsl:variable name="path" select="info/@path"/>-->
+       <tr bgcolor="#99FF99">
+       <th><xsl:value-of select="."/> <!-- <img src="{$path}"/> --></th>
+       </tr>
+</xsl:template>
+
+<xsl:template match="key">
+       <tr bgcolor="#99CCFF">
+       <th><xsl:value-of select="."/></th>             
+        </tr>
+</xsl:template> 
+
+<xsl:template match="t">
+       <tr>
+       <td><xsl:apply-templates/></td>
+        </tr>
+</xsl:template>
+
 <xsl:template match="tr">
        [<i><xsl:apply-templates/></i>]
 </xsl:template> 
index d52a21f..6c2b46f 100644 (file)
@@ -45,6 +45,8 @@ class CommonDictInterface : public QObject {
   public:
     CommonDictInterface(QObject *parent = 0):QObject(parent) {}
 
+    virtual ~CommonDictInterface() {}
+
     //! returns source language code iso 639-2
     virtual QString langFrom() const = 0;
 
index 190e255..ec28e52 100644 (file)
@@ -39,11 +39,8 @@ QString TranslationXdxf::dictionaryInfo() const {
 
 QString TranslationXdxf::toHtml() const {
     QString result("");
-//    qDebug()<<xdxfPlugin->search(_key);
-    result+="<dict>" + _dictionaryInfo + "<key>" + _key + "</key>"  +xdxfPlugin->search(_key) + "</dict>";
+    result+="<dict>" + _dictionaryInfo + xdxfPlugin->search(_key) + "</dict>";
     result.replace("&","&amp;");
-
-//    qDebug()<<result;
     return result;
 }
 
index b734e26..3e30d16 100644 (file)
@@ -45,6 +45,11 @@ XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
     _icon = QIcon(":/icons/xdxf.png");
 }
 
+XdxfPlugin::~XdxfPlugin()
+{
+    db.removeDatabase(_type+path);
+}
+
 QString XdxfPlugin::langFrom() const {   
     return _langFrom;
 }
@@ -186,13 +191,10 @@ QString XdxfPlugin::searchCache(QString key) {
     }
 
     QSqlQuery cur(db);
-//    cur.prepare("select translation from dict where word like ? limit 1");
     cur.prepare("select translation from dict where word like ?");
     cur.addBindValue(key);
     cur.exec();
-//  if(cur.next())
     while(cur.next())
-//      result = cur.value(0).toString();
         result += cur.value(0).toString();
     db.close();
     return result;
@@ -242,7 +244,8 @@ QString XdxfPlugin::searchFile(QString key) {
             }
             if(temp.at(0)==QChar('\n'))
                 temp.remove(0,1);
-            resultString+=tr("<t>") + temp + tr("</t>");    //.replace("\n","")
+            resultString+=tr("<key>") + a +tr("</key>");
+            resultString+=tr("<t>") + temp + tr("</t>");
             match=false;
         }
         this->thread()->yieldCurrentThread();
@@ -269,17 +272,17 @@ void XdxfPlugin::setPath(QString path){
 
 CommonDictInterface* XdxfPlugin::getNew(const Settings *settings) const {
     XdxfPlugin *plugin = new XdxfPlugin();
+    static int a=0;
     if(settings){
         plugin->setPath(settings->value("path"));
-
         QStringList list = settings->keys();
         foreach(QString key, list)
             plugin->settings()->setValue(key, settings->value(key));
 
-
+        a=a+1;
         plugin->db_name = plugin->_settings->value("type")
                + plugin->_settings->value("path");
- //       if(!plugin->db.connectionName().isEmpty() || settings->value("generateCache")=="true")
+//        if(!plugin->db.connectionName().isEmpty() || settings->value("generateCache")=="true")
             plugin->db = QSqlDatabase::addDatabase("QSQLITE", plugin->db_name);
 
         if(settings->value("cached").isEmpty() &&
@@ -287,7 +290,6 @@ CommonDictInterface* XdxfPlugin::getNew(const Settings *settings) const {
             plugin->makeCache("");
         }
     }
-
     plugin->getDictionaryInfo();
     return  plugin;
 }
@@ -357,10 +359,12 @@ void XdxfPlugin::getDictionaryInfo() {
 
     QString format = "png";
     QString initialPath = QDir::currentPath() + tr("/xdxf.") + format;
-//    qDebug()<<initialPath;
-//    qDebug()<<QPixmap(":/icons/xdxf.png").save(initialPath,format.toAscii());
+//  qDebug()<<initialPath;
+//  QPixmap test(":/icons/xdxf.png");
+//  qDebug()<<QPixmap(test).save(initialPath,format.toAscii());
+//  qDebug()<<QPixmap("/home/jakub/star.jpg").save(initialPath,format.toAscii());
 
-    _infoNote="<info path=\""+initialPath+"\">"+"\n" + _name + "(" + _type + ")"  + "</info>";
+    _infoNote="<info path=\""+initialPath+"\">"+"\n" + _name + " [" + _langFrom + "-" + _langTo + "] "+ "(" + _type + ")"  + "</info>";
 
 
 
@@ -486,7 +490,7 @@ bool XdxfPlugin::makeCache(QString dir) {
             }
             if(temp.at(0)==QChar('\n'))
                 temp.remove(0,1);
-            temp=tr("<t>") + temp+ tr("</t>");  //.replace("\n","")
+            temp=tr("<key>") + a + tr("</key>") + tr("<t>") + temp+ tr("</t>");
             match=false;
             cur.prepare("insert into dict values(?,?)");
             cur.addBindValue(a);
index 38cd88a..f964251 100644 (file)
@@ -42,6 +42,8 @@ class XdxfPlugin : public CommonDictInterface
 public:
     XdxfPlugin(QObject *parent=0);
 
+    virtual ~XdxfPlugin();
+
     //! returns source language code iso 639-2
     QString langFrom() const;
 
@@ -58,7 +60,7 @@ public:
     QString infoNote() const;
 
     /*! returns DictDialog object that creates dialogs
-        for adding new dictionary and change plugin settings
+        for adding new dictionary and change plugin tings
       */
     DictDialog* dictDialog();
 
index 4e43c2e..8500794 100644 (file)
@@ -40,9 +40,9 @@ void XdxfTest::searchFile() {
     settings->setValue("path","../tests/dict.xdxf");
     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
 
-    QCOMPARE(xdxfPlugin->search("."), QString("<t>kropka</t>"));
-    QCOMPARE(xdxfPlugin->search("1"), QString("<t>one</t>"));
-    QCOMPARE(xdxfPlugin->search("test"), QString("<t><c c=\"FF00FF\">kro</c>test01<pos>krowa</pos></t>"));
+    QCOMPARE(xdxfPlugin->search("."), QString("<key>.</key><t>kropka</t>"));
+    QCOMPARE(xdxfPlugin->search("1"), QString("<key>1</key><t>one</t>"));
+    QCOMPARE(xdxfPlugin->search("test"), QString("<key>test</key><t><c c=\"FF00FF\">kro</c>test01<pos>krowa</pos></t>"));
 }
 
 void XdxfTest::makeCache()
@@ -53,6 +53,7 @@ void XdxfTest::makeCache()
     settings->setValue("generateCache", "true");
     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
     QCOMPARE(xdxfPlugin->settings()->value("cached"),tr("true"));
+    delete xdxfPlugin;
 }
 
 void XdxfTest::searchCache() {
@@ -63,9 +64,11 @@ void XdxfTest::searchCache() {
     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
 
     QCOMPARE(xdxfPlugin->settings()->value("cached"),tr("true"));
-    QCOMPARE(xdxfPlugin->search("."), QString("<t>kropka</t>"));
-    QCOMPARE(xdxfPlugin->search("1"), QString("<t>one</t>"));
-    QCOMPARE(xdxfPlugin->search("test"), QString("<t><c c=\"FF00FF\">kro</c>test01<pos>krowa</pos></t>"));
+    QCOMPARE(xdxfPlugin->search("."), QString("<key>.</key><t>kropka</t>"));
+    QCOMPARE(xdxfPlugin->search("1"), QString("<key>1</key><t>one</t>"));
+    QCOMPARE(xdxfPlugin->search("test"), QString("<key>test</key><t><c c=\"FF00FF\">kro</c>test01<pos>krowa</pos></t>"));
+
+    delete xdxfPlugin;
 }
 
 void XdxfTest::searchWordListCache(){
@@ -107,6 +110,8 @@ void XdxfTest::searchWordListCache(){
 
     QList<Translation*> te11 = xdxfPlugin->searchWordList("h**?*?**e");
         QCOMPARE(te11.at(0)->key(), QString("house"));
+
+    delete xdxfPlugin;
 }
 
 void XdxfTest::searchWordListFile() {
@@ -149,6 +154,7 @@ void XdxfTest::searchWordListFile() {
     QList<Translation*> te11 = xdxfPlugin->searchWordList("h**?*?**e");
         QCOMPARE(te11.at(0)->key(), QString("house"));
 
+    delete xdxfPlugin;
 }
 
 void XdxfTest::stop() {
@@ -163,6 +169,8 @@ void XdxfTest::stop() {
     QFuture<QList<Translation*> > future = QtConcurrent::run(xdxfPlugin, &CommonDictInterface::searchWordList, string, 10);
     QList<Translation*> te5 = future.result();
     QCOMPARE(te5.size(), 9);
+
+    delete xdxfPlugin;
 }
 
 
@@ -174,6 +182,8 @@ void XdxfTest::langFrom() {
     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
 
     QCOMPARE(xdxfPlugin->langFrom(), QString("ENG"));
+
+    delete xdxfPlugin;
 }
 
 QTEST_MAIN(XdxfTest)