Added downloading of html site with dicts
authorMateusz Półrola <mateusz.polrola@comarch.pl>
Tue, 28 Sep 2010 09:07:11 +0000 (11:07 +0200)
committerMateusz Półrola <mateusz.polrola@comarch.pl>
Tue, 28 Sep 2010 09:07:11 +0000 (11:07 +0200)
src/plugins/xdxf/DownloadDict.h
src/plugins/xdxf/XdxfDictDownloader.cpp
src/plugins/xdxf/XdxfDictDownloader.h

index dfe708a..4442501 100644 (file)
@@ -6,9 +6,27 @@
 class DownloadDict
 {
 public:
-    DownloadDict(QString html);
-    QString fromLang() {return _from;};
-    QString toLang() {return _to;};
+    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);
+        _size = tmp.at(3);
+        QRegExp lreg("href=\"(.*)\"");
+        lreg.setMinimal(true);
+        lreg.indexIn(tmp.at(2));
+        _link = lreg.capturedTexts().at(1);
+    }
+
+    QString fromLang() {return _from;}
+    QString toLang() {return _to;}
     QString title() {return _title;}
     QString size() {return _size;}
     QString link() {return _link;}
@@ -18,25 +36,4 @@ private:
 };
 
 
-DownloadDict::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);
-    _size = tmp.at(3);
-    QRegExp lreg("href=\"(.*)\"");
-    lreg.setMinimal(true);
-    lreg.indexIn(tmp.at(2));
-    _link = lreg.capturedTexts().at(1);
-
-
-}
-
 #endif // DOWNLOADDICT_H
index e0e99ba..b7acba9 100644 (file)
@@ -24,6 +24,7 @@
 #include "XdxfDictDownloader.h"
 #include "XdxfDictDownloadProgressDialog.h"
 
+
 XdxfDictDownloader::XdxfDictDownloader(QObject *parent) :
     QObject(parent)
 {
@@ -31,6 +32,20 @@ XdxfDictDownloader::XdxfDictDownloader(QObject *parent) :
 
 
 void XdxfDictDownloader::download(QWidget *parent) {
-    XdxfDictDownloadProgressDialog progress(parent);
-    //XdxfDictSelectDialog selectDialog(parent);
+
+    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
+
+    connect(manager, SIGNAL(finished(QNetworkReply*)),
+            this, SLOT(dictListReceived(QNetworkReply*)));
+
+    manager->get(QNetworkRequest(QUrl("http://xdxf.revdanica.com/down/")));
+
+    XdxfDictSelectDialog selectDialog(parent);
+
+    selectDialog.exec();
+}
+
+
+void XdxfDictDownloader::dictListReceived(QNetworkReply *reply) {
+
 }
index da82b23..ca88865 100644 (file)
@@ -27,6 +27,9 @@
 #include <QObject>
 #include "XdxfDictSelectDialog.h"
 #include <QTimer>
+#include <QNetworkAccessManager>
+#include <QNetworkReply>
+#include <DownloadDict.h>
 
 class XdxfDictDownloader : public QObject
 {
@@ -37,6 +40,11 @@ public:
 public Q_SLOTS:
     void download(QWidget* parent);
 
+private Q_SLOTS:
+    void dictListReceived(QNetworkReply*);
+
+private:
+    QList<DownloadDict> dicts;
 
 };