2 * abby Copyright (C) 2009 Toni Gundogdu.
3 * This file is part of abby.
5 * abby is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * abby is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <QMessageBox>
26 ScanDialog::ScanDialog(QWidget
*parent
)
31 mgr
= createManager();
32 itemsTree
->setColumnHidden(1, true);
36 ScanDialog::onScan() {
37 QString lnk
= linkEdit
->text();
44 scanButton
->setEnabled(false);
45 buttonBox
->setEnabled(false);
47 QNetworkRequest
req(lnk
);
48 req
.setRawHeader("User-Agent", "Mozilla/5.0");
53 ScanDialog::replyFinished(QNetworkReply
* reply
) {
54 if (reply
->error() == QNetworkReply::NoError
) {
56 reply
->attribute(QNetworkRequest::RedirectionTargetAttribute
);
59 redirect(tmp
.toUrl(), redirectUrl
);
61 if (!redirectUrl
.isEmpty()) {
62 QNetworkRequest
req(redirectUrl
);
63 req
.setRawHeader("User-Agent", "Mozilla/5.0");
68 scanHTML(reply
->readAll());
74 mb
.setText("Network error occurred");
75 mb
.setInformativeText(reply
->errorString());
76 mb
.setStandardButtons(QMessageBox::Ok
);
77 mb
.setDefaultButton(QMessageBox::Ok
);
78 mb
.setIcon(QMessageBox::Critical
);
82 scanButton
->setEnabled(true);
83 buttonBox
->setEnabled(true);
87 ScanDialog::scanHTML(QString html
) {
90 QNetworkAccessManager
*
91 ScanDialog::createManager() {
92 QNetworkAccessManager
*p
= new QNetworkAccessManager(this);
94 connect(p
, SIGNAL(finished(QNetworkReply
*)),
95 this, SLOT(replyFinished(QNetworkReply
*)));
101 ScanDialog::redirect(const QUrl
& to
, const QUrl
& from
) const {
103 if (!to
.isEmpty() && to
!= from
)
109 ScanDialog::writeSettings() {
111 s
.beginGroup("ScanDialog");
112 s
.setValue("size", size());
117 ScanDialog::readSettings() {
119 s
.beginGroup("ScanDialog");
120 resize( s
.value("size", QSize(514,295)).toSize() );