#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:
_from = tmp.at(6);
_to = tmp.at(7);
_title = tmp.at(1);
- _size = tmp.at(3);
+ QString sizeStr = tmp.at(3);
+
+ _size = sizeStr.remove(',').toInt();
+
+ _size = _size / 1024 / 1024;
+
+ _size = round(_size*1000) / 1000;
+
- QRegExp lreg("href=\"(.*)\"");
+
+ 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
- QString size() const {return _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;
}
void XdxfDictDownloader::downloadComplete() {
++<<<<<<< HEAD
+ 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);
void XdxfDictDownloader::dictListReceived(QNetworkReply *reply) {
+ if(aborted) return;
progressDialog->accept();
- delete progressDialog;
+
+ 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))
#include <QNetworkReply>
#include <DownloadDict.h>
#include "XdxfDictDownloadProgressDialog.h"
+#include "../../include/Notify.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();
+ ~XdxfDictDownloader();
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);
+ void notify(Notify::NotifyType, QString);
private Q_SLOTS:
void dictListReceived(QNetworkReply*);