usr/lib/mdictionary/plugins/eng-thai.xdxf
usr/share/mdictionary/xdxf.png
usr/share/mdictionary/css/
-usr/share/applications/hildon/mdictionary.desktop
+usr/share/applications/mdictionary.desktop
TEMPLATE = subdirs
-SUBDIRS = src
+SUBDIRS = src
CONFIG += ordered
include (mdictionary.pri)
check.CONFIG += recursive
-check.recurse = src
+check.recurse = src
QMAKE_EXTRA_TARGETS += check
void Bookmarks::add(Translation* translation) {
if (!translation)
return ;
- checkAndCreateDb();
+ checkAndCreateDb();
QSqlDatabase db = getDbCnx();
if(!db.isOpen() && !db.open()) {
qDebug() << "Database error: " << db.lastError().text() << endl;
cur.exec();
}
+void Bookmarks::add(QString key,QString removeAccentKey,QString value){
+ checkAndCreateDb();
+ QSqlDatabase db = getDbCnx();
+ if(!db.isOpen() && !db.open()) {
+ qDebug() << "Database error: " << db.lastError().text() << endl;
+ return ;
+ }
+ QSqlQuery cur(db);
+ cur.prepare("insert into bookmarks values (?,?,?)");
+ cur.addBindValue(key);
+ cur.addBindValue(removeAccentKey);
+ cur.addBindValue(value);
+ cur.exec();
+}
+
void Bookmarks::remove(Translation* translation) {
if (!translation)
*/
void add(Translation* translation);
+ void add(QString key,QString removeAccentKey,QString value);
+
/*! Removes word and corresponding translation cache from bookmarks list
\param translation translation to be removed
*/
QString trans;
trans = _tr->toXml();
return trans;
-
}
};
return _xmlResult;
}
+void Backbone::addBookmark(QList<Translation*> translations) {
+ if(translations.size()>0) {
+ Translation *tr = translations.at(0);
+ foreach(CommonDictInterface* dict, activeDicts()) {
+ Translation* trans = dict->getTranslationFor(tr->key());
+ if(trans) {
+ translations.append(trans);
+ }
+ }
+ }
+
+ Translation* translation;
+ QHash<QString,QString> trans;
+ foreach(translation,translations){
+ translation->setBookmark(true);
+ trans.insert(translation->toXml(),translation->key());
+
+ }
+
+ foreach(QString value,trans.keys()){
+ QString key= trans.value(value);
+ _bookmarks.add(key,key,value);
+ }
+
+ // Translation* translation;
+ // foreach(translation, translations)
+ // _bookmarks.add(translation);
+ // emit bookmarkReady();
+}
void Backbone::searchXml(QList<Translation *> translations) {
#include <QDebug>
#include <QSettings>
#include <QFutureWatcher>
+#include <QMultiMap>
#include "../../include/CommonDictInterface.h"
#include "../../include/settings.h"
#include "../../include/translation.h"
added to bookmarks data base (key and translation stored in db))
\param translations list of Translation objects to be stored in db
*/
- void addBookmark(QList<Translation*> translations) {
- Translation* translation;
- foreach(translation, translations)
- _bookmarks.add(translation);
- }
+ void addBookmark(QList<Translation*> translations);
/*! Removes bookmarks to given translations
_bookmarkSearchWatcher.setFuture(_innerBookmarks);
}
-
-
/*! Sets settings for backbone: history_size, search_limit,
searching backends (search_bookmarks, search_dictionaries)
\param settings settings object with options set
*/
void setSettings(Settings* settings);
-
/*! \return corresponding settings object with history_size, search_limit,
searching backends (search_bookmarks, search_dictionaries)
*/
*/
void notify(Notify::NotifyType, QString);
+ void bookmarkReady();
+
private Q_SLOTS:
void bookmarksListReady();
connect(backbone, SIGNAL(closeOk()),
this, SLOT(close()));
+
+
+ //connect(wordListWidget, SIGNAL(addBookmark(QList<Translation*>)),
+ // this, SIGNAL(setBusy()));
+
+ //connect(backbone, SIGNAL(bookmarkReady()),
+ // this, SIGNAL(setIdle()));
}
void MainWindow::connectSearchBar() {
_langFrom=GooglePlugin::languages.key("en");
}
-
-
initializeUI();
connect(confirmButton, SIGNAL(clicked()),
stopped = false;
initLanguages();
- http = new QHttp(this);
+ http = new QHttp();
connect(http, SIGNAL(done(bool)), this, SLOT(done()));
+ threa=new QThread();
+ http->moveToThread(threa);
+ threa->start();
}
void GooglePlugin::retranslate() {
wait=true; /* bool - change in slot done (initiate by http) */
stopped=false; /* bool - change in slot stop (initiate in gui) */
+ int lastState=0;
http->request(head, data);
- while(wait && (error=="" || error=="Unknown error") && !stopped)
+ while(wait && (error=="" || error=="Unknown error") && !stopped){
error=http->errorString();
-
+ if(lastState!=http->state()) {
+ lastState=http->state();
+ if(lastState==0){
+ done();
+ }
+ }
+ }
if(error!="" && error!="Unknown error") {
if(!noNetworkErrorShowed) {
noNetworkErrorShowed = true;
QString GooglePlugin::jsonParse(QString result) {
+ //qDebug()<<"Json"<<result;
int pos=0,pos2=0,index=0,size=0;
QString returnLang;
QString translation;
result+=words.at(i)->at(j)+", ";
result.remove(result.size()-2,2);
}
+ //qDebug()<<"PO"<<result;
return result;
}
volatile bool wait;
QHttp *http;
GoogleDictDialog *_dictDialog;
+ QThread *threa;
};
#endif // GOOGLEPLUGIN_H
return result;
result="<dict> <info path=\"/usr/share/mdictionary/google.png\" ";
if(isBookmark())
- result+="bookmark=\"true\" >";
+ result+=" bookmark=\"true\" > \n";
else
- result+="bookmark=\"false\" >";
-
- //qDebug()<<"trans: "<<_trans;
+ result+=" bookmark=\"false\" > \n";
if(_trans!="")
return result+=_dictionaryInfo+ "</info>"+_trans +"</dict>";
-
QList<Translation*> translations=googlePlugin->searchWordList(_key);
- //qDebug()<<"test: "<<translations.size();
- if(translations.size()>0 && translations.at(0))
+ if(translations.size()>0 && translations.at(0)){
+ if(isBookmark())
+ translations.at(0)->setBookmark(true);
return translations.at(0)->toXml();
+ }
return "";
}
//! \return whether given translation is taken from bookmarks
int isBookmark() const {
return _bookmark;
- }
+ }
//! \returns corresponding dict object
uint dict() const {return _dictHash;}
--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*!
+ \file DictsModel.cpp
+ \author Mateusz Półrola <mateusz.polrola@comarch.pl>
+*/
+
+#include "DictsModel.h"
+
+
+DictsModel::DictsModel(QList<DownloadDict> dicts, QObject *parent) :
+ QAbstractItemModel(parent)
+{
+ this->dicts = dicts;
+
+ qSort(this->dicts);
+}
+
+
+int DictsModel::rowCount(const QModelIndex &) const {
+ return dicts.count();
+}
+
+int DictsModel::columnCount(const QModelIndex &) const {
+ return 4;
+}
+
+QVariant DictsModel::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid())
+ return QVariant();
+
+ if (index.row() >= dicts.count())
+ return QVariant();
+
+ if (role == Qt::DisplayRole) {
+ switch(index.column()) {
+ case 0:
+ return dicts.at(index.row()).fromLang();
+ case 1:
+ return dicts.at(index.row()).toLang();
+ case 2:
+ return dicts.at(index.row()).title();
+ case 3:
+ return QString::number(dicts.at(index.row()).size(), 'g', 2) +
+ QString (" MB");
+ }
+ }
+
+ if (role == Qt::UserRole) {
+ return dicts.at(index.row()).link();
+ }
+ return QVariant();
+}
+
+QVariant DictsModel::headerData(int section, Qt::Orientation orientation,
+ int role) const
+{
+ if (role != Qt::DisplayRole)
+ return QVariant();
+
+ if (orientation == Qt::Horizontal) {
+ switch(section) {
+ case 0:
+ return tr("From");
+ case 1:
+ return tr("To");
+ case 2:
+ return tr("Name");
+ case 3:
+ return tr("Size");
+ }
+ }
+ return QVariant();
+}
+
+QModelIndex DictsModel::index(int row, int column, const QModelIndex &) const {
+ return createIndex(row, column, row);
+}
+
+QModelIndex DictsModel::parent(const QModelIndex &) const {
+ return QModelIndex();
+}
--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*!
+ \file DictsModel.h
+ \author Mateusz Półrola <mateusz.polrola@comarch.pl>
+*/
+
+#ifndef DICTSMODEL_H
+#define DICTSMODEL_H
+
+
+#include <QAbstractItemModel>
+#include "DownloadDict.h"
+
+
+/*!
+ Item model for informations about xdxf dictionaries.
+ Contains informations about languages of dictionary, it's name, size and
+ download link. Download link is stored as UserRole, and not displayed in views
+ using this model.
+*/
+class DictsModel : public QAbstractItemModel
+{
+ Q_OBJECT
+public:
+ /*!
+ Constructor
+ \param dicts list of DownloadDict objects, each such object describes
+ one dictionary
+ */
+ DictsModel(QList<DownloadDict> dicts, QObject *parent);
+
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+
+ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
+ QModelIndex parent(const QModelIndex &child) const;
+
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const;
+
+private:
+ QList<DownloadDict> dicts;
+};
+
+#endif // DICTSMODEL_H
--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*!
+ \file DictsProxyModel.h
+ \author Mateusz Półrola <mateusz.polrola@gmail.com>
+ */
+
+#ifndef DICTSPROXYMODEL_H
+#define DICTSPROXYMODEL_H
+
+#include <QSortFilterProxyModel>
+#include <QDebug>
+
+
+/*!
+ Proxy model used for filtering and sorting informations about xdxf dictionaries.
+It allow to filter dictionaries based on their langages
+*/
+class DictsProxyModel : public QSortFilterProxyModel
+{
+ Q_OBJECT
+public:
+ DictsProxyModel(QObject *parent = 0): QSortFilterProxyModel(parent){
+
+ }
+
+ /*! Returns currently setted language used to filter dictionaries based on dictionarie's language from*/
+ QString from() { return _from;}
+
+ /*! Returns currently setted language used to filter dictionaries based on dictionarie's language to*/
+ QString to() {return _to;}
+
+
+ /*! Sets currently setted language used to filter dictionaries based on dictionarie's language from*/
+ void setFrom(QString from) { _from = from; invalidateFilter(); }
+
+ /*! Sets currently setted language used to filter dictionaries based on dictionarie's language to*/
+ void setTo(QString to) {_to = to; invalidateFilter();}
+
+protected:
+ /*! Filtering passed row*/
+ bool filterAcceptsRow(int source_row, const QModelIndex&) const {
+ QString sourceFrom = sourceModel()->data(
+ sourceModel()->index(source_row, 0)).toString();
+ QString sourceTo = sourceModel()->data(
+ sourceModel()->index(source_row, 1)).toString();
+
+ return ((_from.isEmpty() || sourceFrom == _from) &&
+ (_to.isEmpty() || sourceTo == _to));
+ }
+
+ /*! Sorting, if sort column is set to column containing size of dictionary, string containing size of it is converted to fload and compared to other dict size*/
+ bool lessThan(const QModelIndex &left, const QModelIndex &right) const {
+ if(sortColumn() == 3) {
+ QString l = left.model()->data(left).toString();
+ l.remove(" MB");
+
+ QString r = right.model()->data(right).toString();
+ r.remove(" MB");
+
+ float lNumber = l.toFloat();
+ float rNumber = r.toFloat();
+
+ return (lNumber < rNumber);
+ }
+ else
+ QSortFilterProxyModel::lessThan(left, right);
+ }
+
+private:
+ QString _from;
+ QString _to;
+
+};
+
+#endif // DICTSPROXYMODEL_H
--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*! \file DownloadDict.h
+\brief Represenation of dictionary html entry on XDXF webpage
+
+\author Bartosz Szatkowski <bulislaw@linux.com>
+*/
+
+#ifndef DOWNLOADDICT_H
+#define DOWNLOADDICT_H
+
+#include <QRegExp>
+#include <QStringList>
+#include <math.h>
+
+/**
+ Each dictionary is representing as one html line at XDXF webpage,
+ each entry contains lang from, lang to, file name, file size, link, etc info
+ about dictionary. DownloadDict cut this description and then it may be
+ presented to the user and downloaded
+*/
+class DownloadDict
+{
+public:
+
+ /** Cuts html entry to class
+
+ Html entry looks like <tr><td>...</td><td>...</tr> some of the fields
+ dosn't matters for now so Iam ignoring it.
+
+ \param html html entry (line describing a dict) to be cut
+ */
+ DownloadDict(QString html) {
+ QRegExp reg("<td.*>(.*)</td>");
+ reg.setMinimal(true);
+ int pos = 0;
+ QStringList tmp;
+ while ((pos = reg.indexIn(html, pos)) != -1) {
+ tmp << reg.cap(1);
+ pos += reg.matchedLength();
+ }
+ _from = tmp.at(6);
+ _to = tmp.at(7);
+ _title = tmp.at(1);
+ QString sizeStr = tmp.at(3);
+
+ _size = sizeStr.remove(',').toInt();
+
+ _size = _size / 1024 / 1024;
+
+ _size = round(_size*1000) / 1000;
+
+
+ QRegExp lreg("href=\"(.*)\""); // Cutting link to file
+ lreg.setMinimal(true);
+ lreg.indexIn(tmp.at(2));
+ _link = lreg.capturedTexts().at(1);
+ }
+
+ //! \return dictionary source language
+ QString fromLang() const {return _from;}
+
+ //! \return dictionary destination language
+ QString toLang() const {return _to;}
+
+ //! \return dictionary title
+ QString title() const {return _title;}
+
+ //! \return dictionary archive size
+ float size() const {return _size;}
+
+
+ //! \return link to dictionary archive
+ QString link() const {return _link;}
+
+ //! Compares dict by from lang then to lang \return 1 if this is before other
+ bool operator <(DownloadDict other) const {
+ if(_from < other.fromLang()) return true;
+ if(_from > other.fromLang()) return false;
+ if(_to < other.toLang()) return true;
+ return false;
+ }
+
+private:
+ QString _from, _to, _title, _link;
+ float _size;
+};
+
+
+#endif // DOWNLOADDICT_H
--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*!
+ \file HttpDownloader.h
+ \author Bartosz Szatkowski <bulislaw@linux.com>
+ */
+
+
+#include "HttpDownloader.h"
+
+HttpDownloader::HttpDownloader(QObject *parent) {
+ http = new QHttp();
+ //connect(http, SIGNAL(requestFinished(int, bool)), this,
+ // SLOT(getPageFinished()));
+
+ manager = new QNetworkAccessManager;
+ connect(manager, SIGNAL(finished(QNetworkReply*)),
+ SLOT(downloadFinished(QNetworkReply*)));
+
+ //connect(http, SIGNAL())
+}
+
+
+void HttpDownloader::download(QUrl url, QString file) {
+ destFile = file;
+ QNetworkRequest request(url);
+ // Following line is crucial becouse sourceforge wont redirect correctly
+ // if no user-agent is supplied
+ request.setRawHeader("User-Agent", "Wget/1.12 (linux-gnu)");
+ currentReply = manager->get(request);
+ connect(currentReply, SIGNAL(downloadProgress(qint64,qint64)),
+ this, SIGNAL(progress(qint64,qint64)));
+
+}
+
+void HttpDownloader::downloadFinished(QNetworkReply *reply) {
+
+ disconnect(reply, SIGNAL(downloadProgress(qint64,qint64)),
+ this, SIGNAL(progress(qint64,qint64)));
+ if(reply->error() != QNetworkReply::NoError) {
+ Q_EMIT error(reply->errorString());
+ return;
+ }
+
+ QUrl r = reply->attribute(QNetworkRequest::RedirectionTargetAttribute)
+ .toUrl();
+
+ if(r.isValid()) {
+ // Following redirect
+ QNetworkRequest req;
+ req.setRawHeader("User-Agent", "Wget/1.12 (linux-gnu)");
+ req.setUrl(r);
+ currentReply = manager->get(req);
+ connect(currentReply, SIGNAL(downloadProgress(qint64,qint64)),
+ this, SIGNAL(progress(qint64,qint64)));
+ }
+ else {
+ QFile resultFile(destFile);
+ resultFile.open(QFile::WriteOnly);
+ resultFile.write(reply->readAll());
+ resultFile.close();
+ Q_EMIT finished();
+ }
+}
+
+
+void HttpDownloader::kill() {
+ http->abort();
+}
--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*!
+ \file HttpDownloader.h
+ \author Bartosz Szatkowski <bulislaw@linux.com>
+ */
+
+#ifndef HTTPDOWNLOADER_H
+#define HTTPDOWNLOADER_H
+
+#include <QObject>
+#include <QHttp>
+#include <QNetworkAccessManager>
+#include <QUrl>
+#include <QNetworkRequest>
+#include <QNetworkReply>
+#include <QFile>
+#include <QDebug>
+
+class HttpDownloader : public QObject {
+ Q_OBJECT
+public:
+ HttpDownloader(QObject *parent = 0);
+ void download(const QUrl, const QString);
+ void kill();
+
+private Q_SLOTS:
+ void downloadFinished(QNetworkReply *);
+
+Q_SIGNALS:
+ void finished();
+ void error(QString);
+ void progress(qint64,qint64);
+
+private:
+ QHttp *http;
+ QNetworkAccessManager *manager;
+ QString destFile;
+ QNetworkReply* currentReply;
+
+
+};
+
+#endif // HTTPDOWNLOADER_H
public Q_SLOTS:
void reject();
+ void updateCachingProgress(int, int);
Q_SIGNALS:
//! signal emitted when user cancels caching of a dictionary
void cancelCaching();
-private Q_SLOTS:
- void updateCachingProgress(int, int);
private:
QLabel* cachingLabel;
if(type == New) {
connect(browseButton, SIGNAL(clicked()),
this, SLOT(selectFile()));
+
+ connect(downloadButton, SIGNAL(clicked()),
+ this, SLOT(downloadFile()));
+
+ connect(&XdxfPlugin::dictDownloader, SIGNAL(fileDownloaded(QString)),
+ this, SLOT(fileDownloaded(QString)));
}
connect(confirmButton, SIGNAL(clicked()),
}
+void XdxfDialog::fileDownloaded(QString name) {
+ infoLabel->setText(tr("Dictionary file: %1").arg(XdxfPlugin::dictDownloader.downloadedFile()));
+ _dictionaryFilePath = XdxfPlugin::dictDownloader.downloadedFile();
+ updateGeometry();
+}
+
void XdxfDialog::initializeUI() {
mainVerticalLayout = new QVBoxLayout;
setWindowTitle(tr("Add new XDXF dictionary"));
browseLayout = new QHBoxLayout;
+
+ QVBoxLayout* buttonLayout = new QVBoxLayout;
browseButton = new QPushButton(tr("Browse"));
+ browseButton->setMaximumWidth(150);
+
+ downloadButton = new QPushButton(tr("Download"));
+ downloadButton->setMaximumWidth(150);
+
+ infoLayout = new QHBoxLayout;
infoLabel->setText(tr("Dictionary file: not selected"));
- browseLayout->addWidget(infoLabel, 0, Qt::AlignLeft);
- browseLayout->addWidget(browseButton, 0, Qt::AlignRight);
+ browseLayout->addWidget(infoLabel,0,Qt::AlignLeft);
+ browseLayout->addLayout(buttonLayout);
+ buttonLayout->addWidget(browseButton,0,Qt::AlignLeft);
+ buttonLayout->addWidget(downloadButton,0,Qt::AlignLeft);
mainVerticalLayout->addLayout(browseLayout);
}
cacheCheckBox = new QCheckBox(tr("Optimize"));
cacheCheckBox->setToolTip(cacheToolTip);
cacheLayout->addWidget(cacheCheckBox);
+
#ifdef Q_WS_MAEMO_5
cacheInfoToolButton = new QToolButton;
cacheInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
#else
if(type==New) {
- infoLabel->setMinimumWidth(200);
+ 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);
setLayout(layout);
#ifndef Q_WS_MAEMO_5
- setMinimumSize(400,200);
+ setMinimumSize(385,200);
#else
setMinimumHeight(350);
#endif
}
}
+void XdxfDialog::downloadFile() {
+ XdxfPlugin::dictDownloader.download(this);
+}
+
void XdxfDialog::saveSettings() {
_settings = new Settings;
if(plugin) {
private Q_SLOTS:
//! displays dialog to browse and select file
void selectFile();
+ void downloadFile();
void setGenerateCache(bool);
void setAccents(bool);
+ void fileDownloaded(QString);
#ifdef Q_WS_MAEMO_5
//! on maemo shows information about checkboxes
QLabel* infoLabel;
QPushButton* browseButton;
+ QPushButton* downloadButton;
QHBoxLayout* browseLayout;
-
+ QHBoxLayout* infoLayout;
QCheckBox* cacheCheckBox;
QCheckBox* accentsCheckBox;
*******************************************************************************/
/*! \file XdxfDictDialog.cpp
+ \author Mateusz Półrola <mateusz.polrola@comarch.pl>
*/
-//Created by Mateusz Półrola
+
#include "XdxfDictDialog.h"
#include "xdxfplugin.h"
*******************************************************************************/
/*! \file XdxfDictDialog.h
*/
-//Created by Mateusz Półrola
+
#ifndef XDXFDICTDIALOG_H
#define XDXFDICTDIALOG_H
*/
void changeSettings(QWidget *parent);
+ /*!
+ Returns last parent of this dialog
+ */
QWidget* lastDialogParent();
+ /*!
+ Sets last parent of this dialog
+ */
void setLastDialogParent(QWidget*);
private:
--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*!
+ \file XdxfDictDownloadProgressDialog.cpp
+ \author Mateusz Półrola <mateusz.polrola@comarch.com>
+ */
+
+#include "XdxfDictDownloadProgressDialog.h"
+
+XdxfDictDownloadProgressDialog::XdxfDictDownloadProgressDialog(QWidget*parent):
+ QDialog(parent) {
+ verticalLayout = new QVBoxLayout(this);
+ setLayout(verticalLayout);
+
+ downloadProgressBar = new QProgressBar(this);
+ downloadProgressBar->setMinimum(0);
+ downloadProgressBar->setMaximum(0);
+ downloadProgressBar->setTextVisible(true);
+
+ cancelButton = new QPushButton(tr("Cancel"),this);
+
+ connect(cancelButton, SIGNAL(clicked()),
+ this, SIGNAL(cancelDownloading()));
+
+
+ #ifndef Q_WS_MAEMO_5
+ downloadLabel = new QLabel(this);
+ verticalLayout->addWidget(downloadLabel, 0, Qt::AlignCenter);
+ #endif
+
+ verticalLayout->addWidget(downloadProgressBar);
+ verticalLayout->addWidget(cancelButton);
+
+ setModal(true);
+
+ #ifndef Q_WS_MAEMO_5
+ setMinimumWidth(350);
+ #endif
+}
+
+void XdxfDictDownloadProgressDialog::show() {
+ downloadProgressBar->setMaximum(0);
+ QDialog::show();
+}
+
+void XdxfDictDownloadProgressDialog::setText(QString text) {
+ setWindowTitle(text);
+ #ifndef Q_WS_MAEMO_5
+ downloadLabel->setText(text);
+ #endif
+}
+
+void XdxfDictDownloadProgressDialog::updateProgress(float progress) {
+ if(downloadProgressBar->maximum() == 0) {
+ downloadProgressBar->setMaximum(100);
+ }
+ downloadProgressBar->setValue(progress*100);
+}
+
+void XdxfDictDownloadProgressDialog::reject() {
+ #ifndef Q_WS_MAEMO_5
+ Q_EMIT cancelDownloading();
+ #else
+ return;
+ #endif
+}
--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*!
+ \file XdxfDictDownloadProgressDialog.h
+ \author Mateusz Półrola <mateusz.polrola@comarch.com>
+ */
+
+#ifndef XDXFDICTDOWNLOADPROGRESSDIALOG_H
+#define XDXFDICTDOWNLOADPROGRESSDIALOG_H
+
+#include <QDialog>
+#include <QtGui>
+
+/*!
+ Shows downloading progress bar. Currently it displays "busy bar".
+ User can cancel current download by pressing cancel button
+ */
+class XdxfDictDownloadProgressDialog : public QDialog {
+ Q_OBJECT
+public:
+ XdxfDictDownloadProgressDialog(QWidget *parent = 0);
+
+public Q_SLOTS:
+ //! Reimplemented to block rejecting on maemo. User must cancel.
+ void reject();
+
+ //! Set text which will be displayed to user as info about current download
+ void setText(QString);
+
+ void updateProgress(float progress);
+
+ void show();
+
+Q_SIGNALS:
+ //! signal emitted when user cancels downloading of a dictionary
+ void cancelDownloading();
+
+
+private:
+ QLabel* downloadLabel;
+ QProgressBar* downloadProgressBar;
+ QPushButton* cancelButton;
+ QVBoxLayout* verticalLayout;
+};
+
+#endif // XDXFDICTDOWNLOADPROGRESSDIALOG_H
--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*!
+ \file XdxfDictDownloader.cpp
+ \author Mateusz Półrola <mateusz.polrola@comarch.com>
+ */
+
+#include "XdxfDictDownloader.h"
+#include "XdxfDictDownloadProgressDialog.h"
+#include <QDebug>
+
+#include <bzlib.h>
+#include <libtar.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+typedef void BZFILE;
+
+
+
+XdxfDictDownloader::XdxfDictDownloader(QObject *parent) :
+ QObject(parent) {
+ parentDialog = 0;
+ manager = new QNetworkAccessManager(this);
+
+ connect(manager, SIGNAL(finished(QNetworkReply*)),
+ this, SLOT(dictListReceived(QNetworkReply*)));
+
+
+ progressDialog = 0;
+ connect(&http, SIGNAL(finished()), this, SLOT(processFinished()));
+ connect(&http, SIGNAL(error(QString)),
+ this, SLOT(downloadingError(QString)));
+ connect(&http, SIGNAL(progress(qint64,qint64)),
+ this, SLOT(updateDownloadProgress(qint64,qint64)));
+
+}
+
+void XdxfDictDownloader::download(QWidget *parent) {
+ parentDialog = parent;
+ aborted = false;
+
+ manager->get(QNetworkRequest(QUrl("http://xdxf.revdanica.com/down/")));
+
+ progressDialog = new XdxfDictDownloadProgressDialog(parent);
+
+ connect(progressDialog, SIGNAL(cancelDownloading()),
+ this, SLOT(breakDownloading()));
+ connect(this, SIGNAL(downloadProgress(float)),
+ progressDialog, SLOT(updateProgress(float)));
+
+ progressDialog->setText(tr("Downloading dictionaries list"));
+ progressDialog->show();
+}
+
+QString XdxfDictDownloader::downloadedFile() {
+ return _downloadedFile;
+}
+
+void XdxfDictDownloader::updateDownloadProgress(qint64 downloaded,
+ qint64 total) {
+ Q_EMIT downloadProgress(float(downloaded) / float(total));
+}
+
+void XdxfDictDownloader::downloadingError(QString error) {
+ breakDownloading();
+ Q_EMIT notify(Notify::Error, error);
+}
+
+void XdxfDictDownloader::breakDownloading() {
+ //if user cancel downloading we kill all running processes, hide progress dialog and set flag that user cancel downloading.
+ aborted = true;
+ http.kill();
+
+ if(progressDialog && progressDialog->isVisible()) {
+ progressDialog->accept();
+ }
+
+}
+
+void XdxfDictDownloader::processFinished() {
+ //first check if user cancel downloading
+ if(aborted) return;
+
+ if(!extract("/tmp/" + _fileName)) {
+ Q_EMIT notify(Notify::Error,
+ "Error while extracting dictionary archive");
+ return;
+ }
+ downloadComplete();
+}
+
+void XdxfDictDownloader::downloadComplete() {
+ if(aborted) return;
+ // Downloaded tar file name is different than extracted folder so we need
+ // some clean directory to identify extracted files
+ QDir dir("/tmp/mdict");
+ QString dictDirName = dir.entryList().at(2);
+
+ // Dict is in /tmp/mdict/<extracted directory>/dict.xdxf
+ QFile dictFile("/tmp/mdict/" + dictDirName + "/dict.xdxf");
+ dictFile.copy(QDir::homePath() + "/.mdictionary/" + dictDirName + ".xdxf");
+ QFile::remove("/tmp/" + _fileName);
+ QFile::remove("/tmp/" + _fileName.replace(QRegExp(".bz2$"), ""));
+
+ _downloadedFile = QDir::homePath() + "/.mdictionary/" + dictDirName + ".xdxf";
+
+ progressDialog->accept();
+ delete progressDialog;
+ progressDialog = 0;
+
+ emit fileDownloaded(_downloadedFile);
+}
+
+void XdxfDictDownloader::dictListReceived(QNetworkReply *reply) {
+ progressDialog->accept();
+ if(aborted) return;
+
+
+ if(reply->error() != QNetworkReply::NoError) {
+ Q_EMIT notify(Notify::Error, reply->errorString());
+ return;
+ }
+
+ QString page(QString::fromUtf8(reply->readAll()));
+
+ // You can look at http://xdxf.revdanica.com/down/, we need to get table
+ // with dictionaries entries following regexp match its begining
+ QRegExp regOuter("<td>Icon</td><td>Name</td><td>Archive filename</td><td>Archive file size</td><td>Dict file size</td><td>Number of articles</td><td>From</td><td>To</td><td>Submitted by</td><td>Submition date</td></tr>(.*)</table>");
+ regOuter.setMinimal(true);
+ if(!regOuter.indexIn(page))
+ return;
+
+ // Cutting each entry and creating coresponded DownloadDict object
+ page = regOuter.capturedTexts().at(1);
+ QRegExp regInner("<tr>.*</tr>");
+ regInner.setMinimal(true);
+ int pos = 0;
+
+ while ((pos = regInner.indexIn(page, pos)) != -1) {
+ DownloadDict temp = DownloadDict(regInner.cap(0));
+ if(!temp.fromLang().isEmpty())
+ dicts.append(temp);
+ pos += regInner.matchedLength();
+ }
+
+ XdxfDictSelectDialog selectDialog(dicts, parentDialog);
+
+ if(selectDialog.exec()==QDialog::Accepted) {
+
+ progressDialog->setText(tr("Downloading dictionary"));
+ progressDialog->show();
+
+ QString url = selectDialog.link();
+
+ _fileName = url.split('/').last();
+
+ QProcess clean;
+ clean.start("rm -rf /tmp/mdict");
+ clean.waitForFinished(-1);
+ clean.start("mkdir /tmp/mdict");
+ clean.waitForFinished(-1);
+
+ http.download(QUrl(url), "/tmp/" + _fileName);
+ }
+}
+
+bool XdxfDictDownloader::extract(QString file) {
+ // Extracting bz2
+ FILE * archive = fopen(file.toStdString().c_str(), "rb");
+ if (archive == 0)
+ return false;
+ int err;
+ BZFILE * afterbzFile = BZ2_bzReadOpen(&err, archive, 0, 0, 0, 0);
+ if(err != BZ_OK) {
+ BZ2_bzReadClose(&err, afterbzFile);
+ return false;
+ }
+
+ FILE * tarfile = fopen(file.replace(QRegExp(".bz2$"), "").
+ toStdString().c_str(), "w");
+
+ int bufflen = 100;
+ char buff[bufflen];
+ while(err == BZ_OK) {
+ int len = BZ2_bzRead(&err, afterbzFile, buff, bufflen);
+ if(fwrite(buff, 1, len, tarfile) != len)
+ return false;
+ }
+ BZ2_bzReadClose(&err, afterbzFile);
+ fclose(tarfile);
+ fclose(archive);
+
+ // Extracting tar
+ TAR *t;
+ char * tarfname = new char[file.replace(QRegExp(".bz2%"), "").size()+1];
+ strcpy(tarfname, file.replace(QRegExp(".bz2%"), "").toStdString().c_str());
+
+ err = tar_open(&t, tarfname, 0, O_RDONLY, 0, 0);
+ if(err == -1)
+ return false;
+
+ err = tar_extract_all(t, "/tmp/mdict/");
+ if(err == -1) {
+ return false;
+ }
+ tar_close(t);
+
+ return true;
+}
+
+
--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*!
+ \file XdxfDictDownloader.h
+ \author Mateusz Półrola <mateusz.polrola@comarch.pl>
+ */
+
+#ifndef XDXFDICTDOWNLOADER_H
+#define XDXFDICTDOWNLOADER_H
+
+#include <QObject>
+#include "XdxfDictSelectDialog.h"
+#include <QTimer>
+#include <QNetworkAccessManager>
+#include <QNetworkReply>
+#include <DownloadDict.h>
+#include "XdxfDictDownloadProgressDialog.h"
+#include "../../include/Notify.h"
+#include "HttpDownloader.h"
+#include <string.h>
+#include <errno.h>
+
+/** XdxfDictDownloader is responsible for getting dict list from XDXF website
+ and other actions necessary to download and add dictionary
+
+ When user want to add dictionary he may choose "browse" or "download",
+ after selecting "download" XDXFDictDownloader would present him list of
+ dictionaries and when he select one downloading would be started. Next
+ step is to extract archive and move file to ~/.mdictionary
+*/
+class XdxfDictDownloader : public QObject {
+ Q_OBJECT
+public:
+ XdxfDictDownloader(QObject *parent = 0);
+ //! \return name of downloaded file
+ QString downloadedFile();
+
+public Q_SLOTS:
+ //! downloads dictionaries list from xdxf website
+ void download(QWidget* parent);
+
+Q_SIGNALS:
+ //! emmited when file download precess is complete
+ void fileDownloaded(QString);
+ //! emitted to inform user about errors and warnings
+ void notify(Notify::NotifyType, QString);
+
+ void downloadProgress(float);
+
+private Q_SLOTS:
+ //! obtained list of dictionaries from website
+ void dictListReceived(QNetworkReply*);
+
+ //! one of system processes finished
+ void processFinished();
+
+ //! user cancel downloading
+ void breakDownloading();
+
+ void downloadingError(QString);
+
+ void updateDownloadProgress(qint64, qint64);
+
+private:
+ //! dict is downloaded and unpacked
+ void downloadComplete();
+ QList<DownloadDict> dicts;
+ QWidget* parentDialog;
+ QString _downloadedFile;
+ XdxfDictDownloadProgressDialog* progressDialog;
+ QStringList commands;
+ int currentCommand;
+ QProcess* process;
+ QString _fileName;
+ bool downloadError;
+ bool aborted;
+ QNetworkAccessManager *manager;
+ bool extract(QString file);
+ HttpDownloader http;
+};
+
+#endif // XDXFDICTDOWNLOADER_H
--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*!
+ \file XdxfDictSelectDialog.cpp
+ \author Mateusz Półrola <mateusz.polrola@comarch.com>
+ */
+
+#include "XdxfDictSelectDialog.h"
+
+XdxfDictSelectDialog::XdxfDictSelectDialog(QList<DownloadDict> dicts,
+ QWidget *parent) :
+ QDialog(parent) {
+
+
+ setWindowTitle(tr("Select dictionary"));
+
+ layout = new QVBoxLayout;
+ setLayout(layout);
+
+ checkBoxLayout = new QHBoxLayout;
+ layout->addLayout(checkBoxLayout);
+
+ langFrom = new QComboBox;
+ langTo = new QComboBox;
+
+ langFrom->setInsertPolicy(QComboBox::InsertAlphabetically);
+ langTo->setInsertPolicy(QComboBox::InsertAlphabetically);
+
+ langFromLabel = new QLabel(tr("From "));
+ langToLabel = new QLabel(tr("To "));
+
+ checkBoxLayout->addWidget(langFromLabel);
+ checkBoxLayout->addWidget(langFrom, 10);
+ checkBoxLayout->addWidget(langToLabel);
+ checkBoxLayout->addWidget(langTo, 10);
+
+ model = new DictsModel(dicts, this);
+
+ proxyModel = new DictsProxyModel;
+ proxyModel->setDynamicSortFilter(true);
+ proxyModel->setSourceModel(model);
+
+
+ treeView = new QTreeView;
+ treeView->setModel(proxyModel);
+ treeView->setRootIsDecorated(false);
+ treeView->setExpandsOnDoubleClick(false);
+
+ treeView->setSortingEnabled(true);
+ treeView->sortByColumn(0, Qt::AscendingOrder);
+
+ treeView->setWordWrap(true);
+
+ #ifndef Q_WS_MAEMO_5
+ treeView->resizeColumnToContents(0);
+ treeView->resizeColumnToContents(1);
+ treeView->setColumnWidth(2, 300);
+ treeView->resizeColumnToContents(3);
+ #else
+ treeView->setColumnWidth(0, 150);
+ treeView->setColumnWidth(1, 150);
+ treeView->setColumnWidth(2, 300);
+ treeView->setColumnWidth(3, 150);
+ #endif
+
+
+ layout->addWidget(treeView);
+
+
+ connect(langFrom, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(refreshDictList()));
+
+ connect(langTo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(refreshDictList()));
+
+ connect(treeView, SIGNAL(activated(QModelIndex)),
+ this, SLOT(itemClicked(QModelIndex)));
+
+ #ifndef Q_WS_MAEMO_5
+ setMinimumSize(800,500);
+ #else
+ setMinimumHeight(350);
+ #endif
+
+ initializeDicts();
+}
+
+
+void XdxfDictSelectDialog::initializeDicts() {
+
+ //scan of all languages of dictionaries, using QSet to get only distinct languages
+ QSet<QString> languagesFrom;
+ QSet<QString> languagesTo;
+
+ for(int i=0; i < model->rowCount(QModelIndex()); i++) {
+ languagesFrom.insert(
+ model->data(model->index(i, 0, QModelIndex())).toString());
+ languagesTo.insert(
+ model->data(model->index(i, 1, QModelIndex())).toString());
+ }
+
+ //removes one dictionary which from and to languages are empty....
+ //bug in site with dictionaries
+ languagesFrom.remove(QString());
+ languagesTo.remove(QString());
+
+ //sorting of found languages
+ QList<QString> langFromList = languagesFrom.toList();
+ qSort(langFromList);
+
+ QList<QString> langToList = languagesTo.toList();
+ qSort(langToList);
+
+ //and adding them to combobox, first item in each combobox is "Any"
+ langFrom->addItem(tr("Any"));
+ for(int i=0; i < langFromList.count(); i++) {
+ langFrom->addItem(langFromList.at(i));
+ }
+
+ langTo->addItem(tr("Any"));
+ for(int i=0; i < langToList.count(); i++) {
+ langTo->addItem(langToList.at(i));
+ }
+}
+
+void XdxfDictSelectDialog::refreshDictList() {
+ //if selected language is "Any"(index 0), from filter string is set to empty string, proxy model uses empty string as special case and don't filter by this field.
+ if(langTo->currentIndex() == 0)
+ proxyModel->setTo(QString());
+ else
+ proxyModel->setTo(langTo->currentText());
+
+ if(langFrom->currentIndex() == 0)
+ proxyModel->setFrom(QString());
+ else
+ proxyModel->setFrom(langFrom->currentText());
+}
+
+void XdxfDictSelectDialog::itemClicked(QModelIndex index) {
+ _link = index.model()->data(index, Qt::UserRole).toString();
+ accept();
+}
--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*!
+ \file XdxfDictSelectDialog.h
+ \author Mateusz Półrola <mateusz.polrola@comarch.com>
+ */
+
+#ifndef XDXFDICTSELECTDIALOG_H
+#define XDXFDICTSELECTDIALOG_H
+
+#include <QDialog>
+#include <QtGui>
+#include "DownloadDict.h"
+#include "DictsModel.h"
+#include "DictsProxyModel.h"
+
+
+/*!
+ Shows dialog with list of dictionaries and informations about them, allowing user to filter data based on dictionaries languages, and to select one of them.
+ */
+class XdxfDictSelectDialog : public QDialog {
+ Q_OBJECT
+public:
+ /*!
+ Constructor
+ \param dicts list of DownloadDict objects describing dictionaries.
+ */
+ XdxfDictSelectDialog(QList<DownloadDict> dicts,
+ QWidget *parent = 0);
+
+ /*!
+ Returns download link of dictionary selected by user. This string is set
+ only when user select any dictionary (dialog was accepted), otherwise it
+ is empty.
+ */
+ QString link() { return _link;}
+
+private:
+ QTreeView* treeView;
+ DictsModel* model;
+ //used by treeView to allow filtering and sorting
+ DictsProxyModel *proxyModel;
+ QVBoxLayout* layout;
+ QHBoxLayout* checkBoxLayout;
+ QComboBox* langFrom;
+ QComboBox* langTo;
+ QLabel* langFromLabel;
+ QLabel* langToLabel;
+
+private Q_SLOTS:
+ //creates items for comboboxes and creates model with dicts info
+ void initializeDicts();
+
+ //filters dicts after filtering settings change
+ void refreshDictList();
+
+ //accept dialog and sets download link of clicked dictionary
+ void itemClicked(QModelIndex);
+
+private:
+ QList<DownloadDict>* dictList;
+ QString _link;
+};
+
+#endif // XDXFDICTSELECTDIALOG_H
<!DOCTYPE TS>
<TS version="2.0" language="en_US">
<context>
+ <name>DictsModel</name>
+ <message>
+ <location filename="DictsModel.cpp" line="84"/>
+ <source>From</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="DictsModel.cpp" line="86"/>
+ <source>To</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="DictsModel.cpp" line="88"/>
+ <source>Name</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="DictsModel.cpp" line="90"/>
+ <source>Size</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
<name>XdxfCachingDialog</name>
<message>
<location filename="XdxfCachingDialog.cpp" line="35"/>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="74"/>
+ <location filename="XdxfDialog.cpp" line="86"/>
<source>Add new XDXF dictionary</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="77"/>
+ <location filename="XdxfDialog.cpp" line="91"/>
<source>Browse</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="78"/>
+ <location filename="XdxfDialog.cpp" line="94"/>
+ <source>Download</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="XdxfDialog.cpp" line="97"/>
<source>Dictionary file: not selected</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="86"/>
+ <location filename="XdxfDialog.cpp" line="108"/>
<source>XDXF Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="88"/>
+ <location filename="XdxfDialog.cpp" line="110"/>
<source>Plugin: </source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="89"/>
+ <location filename="XdxfDialog.cpp" line="111"/>
<source>From: </source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="90"/>
+ <location filename="XdxfDialog.cpp" line="112"/>
<source>To: </source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="91"/>
+ <location filename="XdxfDialog.cpp" line="113"/>
<source>Description: </source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="97"/>
+ <location filename="XdxfDialog.cpp" line="119"/>
<source>Strip accents</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="107"/>
+ <location filename="XdxfDialog.cpp" line="129"/>
<source>Optimize</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="153"/>
+ <location filename="XdxfDialog.cpp" line="175"/>
<source>Add</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="156"/>
+ <location filename="XdxfDialog.cpp" line="178"/>
<source>Save settings</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="210"/>
+ <location filename="XdxfDialog.cpp" line="232"/>
<source>Select dictionary file</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="212"/>
+ <location filename="XdxfDialog.cpp" line="234"/>
<source>XDXF Files (*.xdxf)</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="217"/>
+ <location filename="XdxfDialog.cpp" line="71"/>
+ <location filename="XdxfDialog.cpp" line="239"/>
<source>Dictionary file: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="246"/>
+ <location filename="XdxfDialog.cpp" line="272"/>
<source>File path is not set</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
+ <name>XdxfDictDownloadProgressDialog</name>
+ <message>
+ <location filename="XdxfDictDownloadProgressDialog.cpp" line="39"/>
+ <source>Cancel</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
+ <name>XdxfDictDownloader</name>
+ <message>
+ <location filename="XdxfDictDownloader.cpp" line="57"/>
+ <source>Downloading dictionaries list</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="XdxfDictDownloader.cpp" line="85"/>
+ <source>Error while downloading or processing dictionary</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="XdxfDictDownloader.cpp" line="155"/>
+ <source>Downloading dictionary</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
+ <name>XdxfDictSelectDialog</name>
+ <message>
+ <location filename="XdxfDictSelectDialog.cpp" line="34"/>
+ <source>Select dictionary</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="XdxfDictSelectDialog.cpp" line="48"/>
+ <source>From </source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="XdxfDictSelectDialog.cpp" line="49"/>
+ <source>To </source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="XdxfDictSelectDialog.cpp" line="134"/>
+ <location filename="XdxfDictSelectDialog.cpp" line="139"/>
+ <source>Any</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
<name>XdxfPlugin</name>
<message>
- <location filename="xdxfplugin.cpp" line="108"/>
- <location filename="xdxfplugin.cpp" line="206"/>
- <location filename="xdxfplugin.cpp" line="523"/>
+ <location filename="xdxfplugin.cpp" line="127"/>
+ <location filename="xdxfplugin.cpp" line="225"/>
+ <location filename="xdxfplugin.cpp" line="542"/>
<source>Cache database cannot be opened for %1 dictionary. Searching in XDXF file. You may want to recache.</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="xdxfplugin.cpp" line="157"/>
- <location filename="xdxfplugin.cpp" line="237"/>
+ <location filename="xdxfplugin.cpp" line="176"/>
+ <location filename="xdxfplugin.cpp" line="256"/>
<source>XDXF file cannot be read for %1</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="xdxfplugin.cpp" line="365"/>
+ <location filename="xdxfplugin.cpp" line="384"/>
<source>XDXF file is in wrong format</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="xdxfplugin.cpp" line="407"/>
+ <location filename="xdxfplugin.cpp" line="426"/>
<source>XDXF dictionary cannot be read from file</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="xdxfplugin.cpp" line="455"/>
- <location filename="xdxfplugin.cpp" line="514"/>
+ <location filename="xdxfplugin.cpp" line="474"/>
+ <location filename="xdxfplugin.cpp" line="533"/>
<source>XDXF file cannot be read for %1 dictionary</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="xdxfplugin.cpp" line="605"/>
+ <location filename="xdxfplugin.cpp" line="624"/>
<source>Database caching error, please try again.</source>
<translation type="unfinished"></translation>
</message>
<!DOCTYPE TS>
<TS version="2.0" language="pl_PL">
<context>
+ <name>DictsModel</name>
+ <message>
+ <location filename="DictsModel.cpp" line="84"/>
+ <source>From</source>
+ <translation>Z</translation>
+ </message>
+ <message>
+ <location filename="DictsModel.cpp" line="86"/>
+ <source>To</source>
+ <translation>Na</translation>
+ </message>
+ <message>
+ <location filename="DictsModel.cpp" line="88"/>
+ <source>Name</source>
+ <translation>Nazwa</translation>
+ </message>
+ <message>
+ <location filename="DictsModel.cpp" line="90"/>
+ <source>Size</source>
+ <translation>Rozmiar</translation>
+ </message>
+</context>
+<context>
<name>XdxfCachingDialog</name>
<message>
<location filename="XdxfCachingDialog.cpp" line="35"/>
<translation>Usuń akcenty (wyszukiwanie trwa dłużej, ale szukane słowo nie musi być wpisane dokładnie)</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="74"/>
+ <location filename="XdxfDialog.cpp" line="86"/>
<source>Add new XDXF dictionary</source>
<translation>Dodaj nowy słownik XDXF</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="77"/>
+ <location filename="XdxfDialog.cpp" line="91"/>
<source>Browse</source>
<translation>Przeglądaj</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="78"/>
+ <location filename="XdxfDialog.cpp" line="94"/>
+ <source>Download</source>
+ <translation>Pobierz</translation>
+ </message>
+ <message>
+ <location filename="XdxfDialog.cpp" line="97"/>
<source>Dictionary file: not selected</source>
<translation>Plik ze słownikiem nie został wybrany</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="86"/>
+ <location filename="XdxfDialog.cpp" line="108"/>
<source>XDXF Settings</source>
<translation>Ustawienia XDXF</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="88"/>
+ <location filename="XdxfDialog.cpp" line="110"/>
<source>Plugin: </source>
- <translation type="unfinished"></translation>
+ <translation></translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="89"/>
+ <location filename="XdxfDialog.cpp" line="111"/>
<source>From: </source>
<translation>Z: </translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="90"/>
+ <location filename="XdxfDialog.cpp" line="112"/>
<source>To: </source>
<translation>Na: </translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="91"/>
+ <location filename="XdxfDialog.cpp" line="113"/>
<source>Description: </source>
<translation>Opis: </translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="97"/>
+ <location filename="XdxfDialog.cpp" line="119"/>
<source>Strip accents</source>
<translation>Usuń akcenty</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="107"/>
+ <location filename="XdxfDialog.cpp" line="129"/>
<source>Optimize</source>
<translation>Optymalizuj</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="153"/>
+ <location filename="XdxfDialog.cpp" line="175"/>
<source>Add</source>
<translation>Dodaj</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="156"/>
+ <location filename="XdxfDialog.cpp" line="178"/>
<source>Save settings</source>
<translation>Zapisz ustawienia</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="210"/>
+ <location filename="XdxfDialog.cpp" line="232"/>
<source>Select dictionary file</source>
<translation>Wybierz plik ze słownikiem</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="212"/>
+ <location filename="XdxfDialog.cpp" line="234"/>
<source>XDXF Files (*.xdxf)</source>
<translation>Pliki XDXF (*.xdxf)</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="217"/>
+ <location filename="XdxfDialog.cpp" line="71"/>
+ <location filename="XdxfDialog.cpp" line="239"/>
<source>Dictionary file: %1</source>
<translation>Plik ze słownikiem: %1</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="246"/>
+ <location filename="XdxfDialog.cpp" line="272"/>
<source>File path is not set</source>
<translation>Ścieżka do pliku nie jest ustawiona</translation>
</message>
</context>
<context>
+ <name>XdxfDictDownloadProgressDialog</name>
+ <message>
+ <location filename="XdxfDictDownloadProgressDialog.cpp" line="39"/>
+ <source>Cancel</source>
+ <translation>Anuluj</translation>
+ </message>
+</context>
+<context>
+ <name>XdxfDictDownloader</name>
+ <message>
+ <location filename="XdxfDictDownloader.cpp" line="57"/>
+ <source>Downloading dictionaries list</source>
+ <translation>Pobieranie listy słowników</translation>
+ </message>
+ <message>
+ <location filename="XdxfDictDownloader.cpp" line="85"/>
+ <source>Error while downloading or processing dictionary</source>
+ <translation>Błąd podczas poierania lub przetwarzania słownika</translation>
+ </message>
+ <message>
+ <location filename="XdxfDictDownloader.cpp" line="155"/>
+ <source>Downloading dictionary</source>
+ <translation>Pobieranie słownika</translation>
+ </message>
+</context>
+<context>
+ <name>XdxfDictSelectDialog</name>
+ <message>
+ <location filename="XdxfDictSelectDialog.cpp" line="34"/>
+ <source>Select dictionary</source>
+ <translation>Wybierz słownik</translation>
+ </message>
+ <message>
+ <location filename="XdxfDictSelectDialog.cpp" line="48"/>
+ <source>From </source>
+ <translation>Z </translation>
+ </message>
+ <message>
+ <location filename="XdxfDictSelectDialog.cpp" line="49"/>
+ <source>To </source>
+ <translation>Na </translation>
+ </message>
+ <message>
+ <location filename="XdxfDictSelectDialog.cpp" line="134"/>
+ <location filename="XdxfDictSelectDialog.cpp" line="139"/>
+ <source>Any</source>
+ <translation>Dowolny</translation>
+ </message>
+</context>
+<context>
<name>XdxfPlugin</name>
<message>
- <location filename="xdxfplugin.cpp" line="108"/>
- <location filename="xdxfplugin.cpp" line="206"/>
- <location filename="xdxfplugin.cpp" line="523"/>
+ <location filename="xdxfplugin.cpp" line="127"/>
+ <location filename="xdxfplugin.cpp" line="225"/>
+ <location filename="xdxfplugin.cpp" line="542"/>
<source>Cache database cannot be opened for %1 dictionary. Searching in XDXF file. You may want to recache.</source>
<translation>Nie można otworzyć bazy danych dla słownika %1. Szukanie w pliku XDXF. Możesz spróbować ponownie włączyć optymalizację.</translation>
</message>
<message>
- <location filename="xdxfplugin.cpp" line="157"/>
- <location filename="xdxfplugin.cpp" line="237"/>
+ <location filename="xdxfplugin.cpp" line="176"/>
+ <location filename="xdxfplugin.cpp" line="256"/>
<source>XDXF file cannot be read for %1</source>
<translation>Nie można odczytać pliku XDXF dla %1</translation>
</message>
<message>
- <location filename="xdxfplugin.cpp" line="365"/>
+ <location filename="xdxfplugin.cpp" line="384"/>
<source>XDXF file is in wrong format</source>
<translation>Niewłaściwy format pliku XDXF</translation>
</message>
<message>
- <location filename="xdxfplugin.cpp" line="407"/>
+ <location filename="xdxfplugin.cpp" line="426"/>
<source>XDXF dictionary cannot be read from file</source>
<translation>Nie można odczytać słownika XDXF z pliku</translation>
</message>
<message>
- <location filename="xdxfplugin.cpp" line="455"/>
- <location filename="xdxfplugin.cpp" line="514"/>
+ <location filename="xdxfplugin.cpp" line="474"/>
+ <location filename="xdxfplugin.cpp" line="533"/>
<source>XDXF file cannot be read for %1 dictionary</source>
<translation>Nie mozna odczytać pliku XDXF dla słownika %1</translation>
</message>
<message>
- <location filename="xdxfplugin.cpp" line="605"/>
+ <location filename="xdxfplugin.cpp" line="624"/>
<source>Database caching error, please try again.</source>
<translation>Błąd optymalizacji, proszę spróbować ponownie.</translation>
</message>
TARGET = xdxf
-
include(../plugin.pri)
-
QT = core \
gui \
xml \
- sql
-
+ sql \
+ network
+LIBS += -ltar \
+ -lbz2
maemo5:QT += maemo5
-
-SOURCES += \
- xdxfplugin.cpp \
+SOURCES += xdxfplugin.cpp \
TranslationXdxf.cpp \
XdxfDictDialog.cpp \
XdxfCachingDialog.cpp \
- XdxfDialog.cpp
-
-
-HEADERS += \
- xdxfplugin.h \
+ XdxfDialog.cpp \
+ XdxfDictDownloader.cpp \
+ XdxfDictSelectDialog.cpp \
+ XdxfDictDownloadProgressDialog.cpp \
+ DictsModel.cpp \
+ HttpDownloader.cpp
+HEADERS += xdxfplugin.h \
TranslationXdxf.h \
../../include/DictDialog.h \
XdxfDictDialog.h \
../../include/settings.h \
../../include/CommonDictInterface.h \
XdxfCachingDialog.h \
- XdxfDialog.h
-
-RESOURCES += \
- xdxf.qrc
-
+ XdxfDialog.h \
+ XdxfDictDownloader.h \
+ XdxfDictSelectDialog.h \
+ XdxfDictDownloadProgressDialog.h \
+ DownloadDict.h \
+ DictsModel.h \
+ DictsProxyModel.h \
+ HttpDownloader.h
+RESOURCES += xdxf.qrc
TRANSLATIONS += pl_PL.ts \
- en_US.ts
-
-unix {
- INSTALLS += dicts plugin-icon
-
- dicts.path = $$PLUGINS_DIR
- dicts.files += ../../../data/dicts/eng-us.xdxf
- dicts.files += ../../../data/dicts/eng-thai.xdxf
-
- plugin-icon.path = $$DATA_DIR
- plugin-icon.files += xdxf.png
+ en_US.ts
+unix {
+ INSTALLS += dicts \
+ plugin-icon
+ dicts.path = $$PLUGINS_DIR
+ dicts.files += ../../../data/dicts/eng-us.xdxf
+ dicts.files += ../../../data/dicts/eng-thai.xdxf
+ plugin-icon.path = $$DATA_DIR
+ plugin-icon.files += xdxf.png
}
-
-check.commands = echo 'No check here'
+check.commands = echo \
+ 'No check here'
QMAKE_EXTRA_TARGETS += check
#include "xdxfplugin.h"
#include <QDebug>
#include "../../include/Notify.h"
+#include "DownloadDict.h"
+#include "XdxfDictDownloader.h"
+
+XdxfDictDownloader XdxfPlugin::dictDownloader;
+
+bool XdxfPlugin::dictDownloaderInitialized = false;
+
XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
_langFrom(""), _langTo(""),_name(""), _infoNote("") {
+
+ //DownloadDict a("<tr><td><img src=\"buf/comn_sdict05_bulg_comp/icon16.png\" alt=\"icon\" /></td><td align=\"center\">English-Bulgarian computer dictionary</td><td align=\"center\"><a href=\"http://downloads.sourceforge.net/xdxf/comn_sdict05_bulg_comp.tar.bz2\" target=\"_blank\">comn_sdict05_bulg_comp.tar.bz2</a></td><td align=\"right\">13,889</td><td align=\"right\">55,094</td><td align=\"right\">523</td><td align=\"center\">English</td><td align=\"center\">Bulgarian</td><td align=\"center\"><a href=\"http://xdxf.revdanica.com/\">Common XDXF</a></td><td align=\"center\">2006-04-23 23:34:40</td></tr>");
+ //dictDownloader.download(0);
+
+
_settings = new Settings();
_dictDialog = new XdxfDictDialog(this, this);
this, SIGNAL(notify(Notify::NotifyType,QString)));
+ if(!dictDownloaderInitialized) {
+ connect(&dictDownloader, SIGNAL(notify(Notify::NotifyType,QString)),
+ this, SIGNAL(notify(Notify::NotifyType,QString)));
+ dictDownloaderInitialized = true;
+ }
+
+
_settings->setValue("type","xdxf");
_icon = QIcon("/usr/share/mdictionary/xdxf.png");
_wordsCount = -1;
#include "XdxfDictDialog.h"
#include "XdxfCachingDialog.h"
#include "TranslationXdxf.h"
+#include "XdxfDictDownloader.h"
class TranslationXdxf;
*/
void clean();
-
+ static XdxfDictDownloader dictDownloader;
public Q_SLOTS:
/*! performs search in a dictionary
private:
+ static bool dictDownloaderInitialized;
+
+
/*! \returns true or false depending on whether the dictionary is cached
or not
*/