moved more to qbrowserlib, added download manager functions; refs #167
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
#define __SWISSWEBWIDGET_HXX__
|
||||
|
||||
#include <qbrowserlib/ui_swisswebwidget.h>
|
||||
#include <qbrowserlib/downloadmanager.hxx>
|
||||
#include <qbrowserlib/errorlog.hxx>
|
||||
|
||||
#include <QtGui/QMainWindow>
|
||||
#include <QtGui/QToolBar>
|
||||
@@ -43,9 +45,11 @@ namespace qbrowserlib {
|
||||
class SwissWebWidget: public QWidget, private Ui::SwissWebWidget {
|
||||
|
||||
Q_OBJECT;
|
||||
|
||||
|
||||
//..............................................................properties
|
||||
CREATE_QT_PROPERTY(QUrl, homeUrl);
|
||||
|
||||
//................................................................methods
|
||||
public:
|
||||
|
||||
SwissWebWidget(QWidget* p=0): QWidget(p) {
|
||||
@@ -87,12 +91,103 @@ namespace qbrowserlib {
|
||||
_webview->load(_homeUrl);
|
||||
}
|
||||
|
||||
void progress(qint64 total, qint64 done) {
|
||||
TRC;
|
||||
_progress->setMaximum(total);
|
||||
_progress->setValue(done);
|
||||
}
|
||||
|
||||
void started() {
|
||||
TRC;
|
||||
_abort->setVisible(true);
|
||||
_reload->setVisible(false);
|
||||
_progress->setRange(0, 0);
|
||||
_progress->setValue(0);
|
||||
_progress->setEnabled(true);
|
||||
_progress->show();
|
||||
}
|
||||
|
||||
void finished() {
|
||||
TRC;
|
||||
_abort->setVisible(false);
|
||||
_reload->setVisible(true);
|
||||
_progress->setRange(0, 1);
|
||||
_progress->setValue(1);
|
||||
_progress->setEnabled(false);
|
||||
}
|
||||
|
||||
void finished(QNetworkReply *r) {
|
||||
TRC;
|
||||
if (r->error()!=QNetworkReply::NoError &&
|
||||
r->error()!=QNetworkReply::OperationCanceledError) {
|
||||
// statusBar()->showMessage
|
||||
// (qbrowserlib::DownloadManager::networkError(r->error()));
|
||||
// badUrl();
|
||||
// if (!_showErrorLog) {
|
||||
// statusBar()->addPermanentWidget
|
||||
// ((_showErrorLog = new QPushButton(QIcon(":/icons/error"),
|
||||
// tr("errors", "show error log"))));
|
||||
// assert(connect(_showErrorLog, SIGNAL(clicked(bool)),
|
||||
// actionErrorLog, SLOT(trigger())));
|
||||
// }
|
||||
// _showErrorLog->show();
|
||||
}
|
||||
}
|
||||
|
||||
void metaDataChanged(QNetworkReply* reply) {
|
||||
TRC;
|
||||
QString filename
|
||||
(QString::fromUtf8(reply->rawHeader("Content-Disposition")));
|
||||
if (filename.contains
|
||||
(QRegExp("^\\s*attachment\\s*;\\s*filename\\s*=\\s*\"[^\"]+\""))) {
|
||||
LOG<<"From Content-Disposition";
|
||||
filename = filename.replace
|
||||
(QRegExp("^\\s*attachment\\s*;\\s*filename\\s*=\\s*\"([^\"]+)\".*"),
|
||||
"\\1");
|
||||
} else {
|
||||
LOG<<"From path";
|
||||
filename =
|
||||
QFileInfo(!reply->url().toLocalFile().isEmpty()
|
||||
?reply->url().toLocalFile()
|
||||
:reply->url().path()).fileName();
|
||||
}
|
||||
LOG<<"Filename:"<<filename;
|
||||
QStringList type
|
||||
(qbrowserlib::Settings::instance().mimetype
|
||||
(reply->header(QNetworkRequest::ContentTypeHeader).toString(),
|
||||
filename));
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
void connects() {
|
||||
_downloadmanager+=_webview->page()->networkAccessManager();
|
||||
assert(connect(_webview->page()->networkAccessManager(),
|
||||
SIGNAL(finished(QNetworkReply*)),
|
||||
SLOT(finished(QNetworkReply*))));
|
||||
assert(connect(_url, SIGNAL(returnPressed()), SLOT(load())));
|
||||
assert(connect(_home, SIGNAL(pressed()), SLOT(goHome())));
|
||||
assert(connect(_abort, SIGNAL(pressed()),
|
||||
&_downloadmanager, SLOT(abort())));
|
||||
assert(connect(&_downloadmanager, SIGNAL(progress(qint64, qint64)),
|
||||
SLOT(progress(qint64, qint64))));
|
||||
assert(connect(&_downloadmanager, SIGNAL(started()),
|
||||
SLOT(started())));
|
||||
assert(connect(&_downloadmanager, SIGNAL(finished()),
|
||||
SLOT(finished())));
|
||||
assert(connect(&_downloadmanager, SIGNAL(error(QString)),
|
||||
&qbrowserlib::ErrorLog::instance(),
|
||||
SLOT(append(QString))));
|
||||
assert(connect(&_downloadmanager,
|
||||
SIGNAL(metaDataChanged(QNetworkReply*)),
|
||||
SLOT(metaDataChanged(QNetworkReply*))));
|
||||
}
|
||||
|
||||
//..............................................................variables
|
||||
protected:
|
||||
|
||||
void connects() {
|
||||
connect(_url, SIGNAL(returnPressed()), SLOT(load()));
|
||||
connect(_home, SIGNAL(pressed()), SLOT(goHome()));
|
||||
}
|
||||
qbrowserlib::DownloadManager _downloadmanager;
|
||||
QPushButton _showErrorLog;
|
||||
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user