qDebug() << "Database error: " << db.lastError().text() << endl;
return ;
}
+ translation->setBookmark(true);
QSqlQuery cur(db);
cur.prepare("insert into bookmarks values (?,?)");
cur.addBindValue(translation->key());
trans += t + "\n";
}
- // qDebug()<<trans;
+// qDebug()<<trans;
trans=tr("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") + tr("\n <ar>") + trans + tr("\n </ar>");
trans=XslConversion(trans);
textEdit->insertHtml(trans);
+
+ qDebug()<<trans;
+
// textEdit->setPlainText(trans);
textEdit->repaint(this->rect());
<xsl:template match="info">
<!-- <xsl:variable name="path" select="info/@path"/>-->
<tr bgcolor="#99FF99">
- <th><xsl:value-of select="."/> <!-- <img src="{$path}"/> --></th>
+ <th>
+ <xsl:if test="@bookmark = 'true'">
+ BOOKMARK:
+ </xsl:if>
+ <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>
+ <th><xsl:value-of select="."/></th>
+ </tr>
</xsl:template>
<xsl:template match="t">
return _dictionaryInfo;
}
-QString TranslationXdxf::toHtml() const {
+QString TranslationXdxf::toHtml() const {
QString result("");
-
if(!xdxfPlugin)
return result;
- result+="<dict>" + _dictionaryInfo + xdxfPlugin->search(_key) + "</dict>";
- result.replace("&","&");
-
- return result;
+ result=result + "<dict>" + "<info";
+ if(isBookmark())
+ result+= " bookmark=\"true\" ";
+ else
+ result+= " bookmark=\"false\" ";
+ result+= _dictionaryInfo + "</info>" + xdxfPlugin->search(_key) + "</dict>";
+ return result.replace("&","&");
}
void TranslationXdxf::setKey(QString _key) {
//! sets information about dictionary
void setDictionaryInfo(QString);
+ //! \retrun whether given translation is taken from bookmarks
+ bool isBookmark() const {
+ return _bookmark;
+ }
//! returns coresponding dict object
uint dict() const {return _dictHash;}
#include "xdxfplugin.h"
#include <QDebug>
-#include <QFile>
-#include <QXmlStreamReader>
-#include <QtPlugin>
-#include "TranslationXdxf.h"
-#include "../../../includes/settings.h"
XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
_langFrom(tr("")), _langTo(tr("")),_name(tr("")),
XdxfPlugin::~XdxfPlugin()
{
- qDebug()<<"/n /n destruktor";
- if(!db.connectionName().isEmpty())
- db.removeDatabase(_type+path);
+// QString connection(db.connectionName());
+// db.close();
+// QSqlDatabase::removeDatabase(connection);
+
+ delete _settings;
}
QString XdxfPlugin::langFrom() const {
_infoNote, this));
}
db.close();
- return translations.toList();
+ return translations.toList();
}
QList<Translation*> XdxfPlugin::searchWordListFile(QString word, int limit) {
cur.exec();
while(cur.next())
result += cur.value(0).toString();
+
db.close();
+
return result;
}
QFile dictionaryFile(path);
QString resultString("");
if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
- qDebug()<<"Error: could not open file";
+ qDebug()<<"Error: could not open file when search";
return "";
}
QXmlStreamReader reader(&dictionaryFile);
-
-
-
QString a;
bool match =false;
a=a+1;
plugin->db_name = plugin->_settings->value("type")
- + plugin->_settings->value("path");
-// if(!plugin->db.connectionName().isEmpty() || settings->value("generateCache")=="true")
- plugin->db = QSqlDatabase::addDatabase("QSQLITE", plugin->db_name);
+ + plugin->_settings->value("path");
+ plugin->db = QSqlDatabase::addDatabase("QSQLITE", plugin->db_name);
if(settings->value("cached").isEmpty() &&
settings->value("generateCache") == "true") {
// qDebug()<<QPixmap(test).save(initialPath,format.toAscii());
// qDebug()<<QPixmap("/home/jakub/star.jpg").save(initialPath,format.toAscii());
- _infoNote="<info path=\""+initialPath+"\">"+"\n" + _name + " [" + _langFrom + "-" + _langTo + "] "+ "(" + _type + ")" + "</info>";
-
-
+ _infoNote="path=\""+initialPath+"\">"+"\n" + _name + " [" + _langFrom + "-" + _langTo + "] "+ "(" + _type + ")";
dictionaryFile.close();
}
_settings->setValue("cache_path", cachePathN);
_settings->setValue("cached", "true");
+
db.close();
return true;
}
#ifndef XDXFPLUGIN_H
#define XDXFPLUGIN_H
-#include "../../../includes/CommonDictInterface.h"
+
#include <QObject>
#include <QDialog>
#include <QRegExp>
#include <QSqlQuery>
#include <QSqlDatabase>
#include <QSqlError>
+#include <QFile>
+#include <QXmlStreamReader>
+#include <QtPlugin>
+
+#include "../../../includes/CommonDictInterface.h"
+#include "../../../includes/settings.h"
#include "XdxfDictDialog.h"
#include "XdxfCachingDialog.h"
+#include "TranslationXdxf.h"
class TranslationXdxf;
Q_INTERFACES(CommonDictInterface)
public:
XdxfPlugin(QObject *parent=0);
-
- virtual ~XdxfPlugin();
+ ~XdxfPlugin();
//! returns source language code iso 639-2
QString langFrom() const;
*/
DictDialog* dictDialog();
-
//! returns new, clean copy of plugin with setting set as in Settings*
CommonDictInterface* getNew(const Settings*) const;
QList<Translation*> searchWordListFile(QString word, int limit=0);
QString searchFile(QString key);
QString searchCache(QString key);
+ //! scan dictionary file to get information about it
+ void getDictionaryInfo();
+
int countWords();
bool makeCache(QString dir);
QString _type;
//! information about dictionary
QString _infoNote;
- QDialog *_loadDialog;
- QDialog *_settingsDialog;
//! path to dictionary file
QString path;
uint _hash;
//! number of words in dicrionary
long _wordsCount;
- //! scan dictionary file to get information about it
- void getDictionaryInfo();
volatile bool stopped;
Settings *_settings;
CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
QString string("*");
- QFuture<QList<Translation*> > future = QtConcurrent::run(xdxfPlugin, &CommonDictInterface::searchWordList, string, 10);
+ QFuture<QList<Translation*> > future = QtConcurrent::run(xdxfPlugin,
+ &CommonDictInterface::searchWordList, string, 10);
QList<Translation*> te5 = future.result();
QCOMPARE(te5.size(), 9);
delete xdxfPlugin;
}
+void XdxfTest::timeCache()
+{
+ QTime timer;
+ QDate date;
+ QFile File("../tests/time.xml");
+ if(!File.open(QFile::ReadWrite | QFile::Text)) {
+ qDebug()<<"Error: could not open file";
+ return;
+ }
+ QTextStream out(&File);
+ while(!out.atEnd())
+ out.seek(out.pos()+1);
+
+ timer.start();
+ XdxfPlugin xdxfPluginB(this);
+ Settings *settings=new Settings;
+ settings->setValue("path","../../../../../../dict.xdxf");
+ settings->setValue("generateCache", "true");
+ CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+
+ out<<"\n<date>" + date.currentDate().toString("dd.MM.yyyy") +" ";
+ out<<timer.currentTime().toString(Qt::TextDate) + "</date>";
+ out<<"\n<type> Cache </type> <time>" << timer.elapsed();
+ out<<"</time>";
+
+ timer.start();
+ xdxfPlugin->search("Bantu");
+ out<<"\n<type> SearchCache-begin </type> <time>" << timer.elapsed();
+ out<< "</time>";
+
+ timer.start();
+ xdxfPlugin->search("level");
+ out<<"\n<type> SearchCache-midle </type> <time>" << timer.elapsed();
+ out<< "</time>";
+
+ timer.start();
+ xdxfPlugin->search("zoril");
+ out<<"\n<type> SearchCache-end </type> <time>" << timer.elapsed();
+ out<< "</time>";
+
+ timer.start();
+ xdxfPlugin->searchWordList("level");
+ out<<"\n<type> SearchWorlListCache </type> <time>" << timer.elapsed();
+ out<< "</time>";
+
+ File.close();
+}
+
+void XdxfTest::timeFile()
+{
+ QTime timer;
+ QDate date;
+ QFile File("../tests/time.xml");
+ if(!File.open(QFile::ReadWrite | QFile::Text)) {
+ qDebug()<<"Error: could not open file";
+ return;
+ }
+ QTextStream out(&File);
+ while(!out.atEnd())
+ out.seek(out.pos()+1);
+
+ XdxfPlugin xdxfPluginB(this);
+ Settings *settings=new Settings;
+ settings->setValue("path","../../../../../../dict.xdxf");
+ CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+
+ timer.start();
+ xdxfPlugin->search("Bantu");
+ out<<"\n<type> SearchFile-begin </type> <time>" << timer.elapsed();
+ out << "</time>";
+
+ timer.start();
+ xdxfPlugin->search("level");
+ out<<"\n<type> SearchFile-midle </type> <time>" << timer.elapsed();
+ out << "</time>";
+
+ timer.start();
+ xdxfPlugin->search("zoril");
+ out<<"\n<type> SearchFile-end </type> <time>" << timer.elapsed();
+ out << "</time>";
+
+ timer.start();
+ xdxfPlugin->searchWordList("level");
+ out<<"\n<type> SearchWordListFile </type> <time>" << timer.elapsed();
+ out<< "</time>\n";
+
+ File.close();
+}
+
+
QTEST_MAIN(XdxfTest)
//#include "testqstring.moc"
#include <QtConcurrentRun>
#include <QFuture>
#include "../src/xdxfplugin.h"
+#include <QTime>
+#include <QDate>
+#include <QTextStream>
class XdxfTest: public QObject
{
void makeCache();
void searchCache();
void searchWordListCache();
+ void timeCache();
+ void timeFile();
};