xdxf code refactoring
[mdictionary] / trunk / src / plugins / xdxf / src / xdxfplugin.cpp
index b734e26..55b8a84 100644 (file)
@@ -19,6 +19,9 @@
 
 *******************************************************************************/
 
+/*! \file xdxfplugin.cpp
+*/
+
 #include "xdxfplugin.h"
 #include <QDebug>
 #include <QFile>
@@ -45,6 +48,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 +194,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 +247,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 +275,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 +293,6 @@ CommonDictInterface* XdxfPlugin::getNew(const Settings *settings) const {
             plugin->makeCache("");
         }
     }
-
     plugin->getDictionaryInfo();
     return  plugin;
 }
@@ -357,10 +362,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 +493,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);