Added notifications and canceling to xdxf download dialog
[mdictionary] / src / plugins / xdxf / DownloadDict.h
1 #ifndef DOWNLOADDICT_H
2 #define DOWNLOADDICT_H
3
4 #include <QRegExp>
5 #include <QStringList>
6 #include <math.h>
7
8 class DownloadDict
9 {
10 public:
11     DownloadDict(QString html) {
12         QRegExp reg("<td.*>(.*)</td>");
13         reg.setMinimal(true);
14         int pos = 0;
15         QStringList tmp;
16         while ((pos = reg.indexIn(html, pos)) != -1) {
17             tmp << reg.cap(1);
18             pos += reg.matchedLength();
19         }
20         _from = tmp.at(6);
21         _to = tmp.at(7);
22         _title = tmp.at(1);
23         QString sizeStr = tmp.at(3);
24
25         _size = sizeStr.remove(',').toInt();
26
27         _size = _size / 1024 / 1024;
28
29         _size = round(_size*1000) / 1000;
30
31         QRegExp lreg("href=\"(.*)\"");
32         lreg.setMinimal(true);
33         lreg.indexIn(tmp.at(2));
34         _link = lreg.capturedTexts().at(1);
35     }
36
37     QString fromLang() const {return _from;}
38     QString toLang() const {return _to;}
39     QString title() const {return _title;}
40     float size() const {return _size;}
41     QString link() const {return _link;}
42
43     bool operator <(DownloadDict other) const {
44         if(_from < other.fromLang()) return true;
45         if(_from > other.fromLang()) return false;
46         if(_to < other.toLang()) return true;
47         return false;
48     }
49
50 private:
51     QString _from, _to, _title, _link;
52     float _size;
53 };
54
55
56 #endif // DOWNLOADDICT_H