You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1569 lines
57 KiB
1569 lines
57 KiB
15 years ago
|
/*! @file
|
||
|
|
||
|
@id $Id: browser.hxx 15 2010-06-03 14:17:27Z marc $
|
||
|
*/
|
||
|
// 1 2 3 4 5 6 7 8
|
||
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||
|
|
||
|
#ifndef BROWSER_HXX
|
||
|
#define BROWSER_HXX
|
||
|
|
||
|
#include <ui_browser.h>
|
||
|
#include <QtGui/QMainWindow>
|
||
|
#include <QtGui/QLineEdit>
|
||
|
#include <QtGui/QProgressBar>
|
||
14 years ago
|
#include <QtGui/QComboBox>
|
||
13 years ago
|
#include <QtGui/QToolButton>
|
||
15 years ago
|
#include <QtGui/QSlider>
|
||
|
#include <QtGui/QMessageBox>
|
||
14 years ago
|
#include <QtGui/QPrinter>
|
||
|
#include <QtGui/QPrintDialog>
|
||
|
#include <QtGui/QPrintPreviewDialog>
|
||
14 years ago
|
#include <QtWebKit/QWebPage>
|
||
|
#include <QtWebKit/QWebView>
|
||
|
#include <QtWebKit/QWebFrame>
|
||
15 years ago
|
#include <QtWebKit/QWebHistory>
|
||
|
#include <QtNetwork/QNetworkReply>
|
||
|
#include <QtNetwork/QSslError>
|
||
|
#include <QtNetwork/QNetworkProxy>
|
||
14 years ago
|
#include <QtCore/QProcess>
|
||
|
#include <QtCore/QDir>
|
||
|
#include <QtGui/QFileDialog>
|
||
15 years ago
|
|
||
14 years ago
|
#include <smartcardauth.hxx>
|
||
14 years ago
|
#include <logincertificate.hxx>
|
||
14 years ago
|
#include <errorlog.hxx>
|
||
14 years ago
|
#include <downloadmanager.hxx>
|
||
14 years ago
|
#include <authentication.hxx>
|
||
|
#include <webpage.hxx>
|
||
14 years ago
|
#include <settings.hxx>
|
||
13 years ago
|
#include <editbookmarks.hxx>
|
||
13 years ago
|
#include <pluginfactory.hxx>
|
||
13 years ago
|
#include <temporaryfile.hxx>
|
||
|
#include <saveorrun.hxx>
|
||
14 years ago
|
#include <sslclientnetworkmanager.hxx>
|
||
14 years ago
|
#include <proxyface/proxy.hxx>
|
||
14 years ago
|
|
||
15 years ago
|
#include <stdexcept>
|
||
|
#include <cassert>
|
||
|
|
||
14 years ago
|
#include <QtCore/QDebug>
|
||
|
#ifndef LOG
|
||
14 years ago
|
#define LOG qDebug()<<__PRETTY_FUNCTION__
|
||
14 years ago
|
#endif
|
||
15 years ago
|
|
||
|
class Browser: public QMainWindow, protected Ui::Browser {
|
||
|
|
||
|
Q_OBJECT;
|
||
|
|
||
|
public:
|
||
|
|
||
14 years ago
|
Browser(const QString& actlib, const QStringList& urls = QStringList(),
|
||
|
QSettings* settings=0,
|
||
|
Settings::MimeTypes mimeTypes = Settings::MimeTypes(),
|
||
13 years ago
|
bool kiosk = false, bool login = true, bool quirks=true):
|
||
|
_url(0), _find(new ButtonLineEdit),
|
||
14 years ago
|
_kiosk(kiosk),
|
||
14 years ago
|
_settings(mimeTypes, this, settings, !kiosk),
|
||
14 years ago
|
_errorLog(this), _logincertificate(this),
|
||
14 years ago
|
_proxy("http://swisssign.com", this),
|
||
13 years ago
|
_showErrorLog(0),
|
||
13 years ago
|
_startUrl(urls.size()),
|
||
13 years ago
|
_quirks(quirks), _search(new ButtonLineEdit),
|
||
|
_searchEngines(new QComboBox) {
|
||
14 years ago
|
LOG<<urls;
|
||
13 years ago
|
_home = "about:blank";
|
||
|
if (urls.size()) _home = urls.at(0);
|
||
|
setupUi(this);
|
||
|
show();
|
||
14 years ago
|
try {
|
||
14 years ago
|
_networkManager.scAuth(new SmartCardAuth(actlib, this, login));
|
||
14 years ago
|
} catch (const std::exception& x) {
|
||
|
LOG<<"No SmartCard Support:"<<x.what();
|
||
|
}
|
||
13 years ago
|
statusBar()->addPermanentWidget(_find);
|
||
|
_find->add(actionUnFind);
|
||
|
_find->add(actionClearFind);
|
||
|
_find->hide();
|
||
14 years ago
|
statusBar()->addPermanentWidget(_progress = new QProgressBar());
|
||
14 years ago
|
_progress -> setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||
13 years ago
|
statusBar()->addPermanentWidget(new QLabel("-"));
|
||
14 years ago
|
statusBar()->addPermanentWidget(_zoom = new QSlider(Qt::Horizontal));
|
||
13 years ago
|
statusBar()->addPermanentWidget(new QLabel("+"));
|
||
14 years ago
|
_zoom->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||
|
_zoom->setMinimum(10);
|
||
|
_zoom->setMaximum(190);
|
||
|
_zoom->setValue(100);
|
||
|
_zoom->setSingleStep(1);
|
||
|
_zoom->setPageStep(10);
|
||
14 years ago
|
_zoom->setTickPosition(QSlider::TicksAbove);
|
||
14 years ago
|
assert(connect(_zoom, SIGNAL(valueChanged(int)), SLOT(zoom(int))));
|
||
13 years ago
|
if (!_quirks) {
|
||
|
_toolbar->addAction(actionReload);
|
||
|
_toolbar->addAction(actionStop);
|
||
|
}
|
||
13 years ago
|
if (!_kiosk) {
|
||
|
QComboBox* combo(new QComboBox(_toolbar));
|
||
|
_url = combo;
|
||
|
combo->setInsertPolicy(QComboBox::NoInsert);
|
||
|
combo->setLineEdit(new ButtonLineEdit(combo));
|
||
13 years ago
|
combo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
|
||
13 years ago
|
combo->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
|
||
|
QSizePolicy::Preferred));
|
||
|
combo->setEditable(!_kiosk);
|
||
|
assert(connect(combo, SIGNAL(currentIndexChanged(const QString&)),
|
||
|
SLOT(load(QString))));
|
||
|
assert(connect(combo->lineEdit(), SIGNAL(returnPressed()),
|
||
|
SLOT(load())));
|
||
|
assert(connect(combo->lineEdit(), SIGNAL(textChanged(QString)),
|
||
|
SLOT(goodUrl())));
|
||
13 years ago
|
if (_quirks) {
|
||
|
dynamic_cast<ButtonLineEdit*>(combo->lineEdit())->add
|
||
|
(actionStop);
|
||
13 years ago
|
dynamic_cast<ButtonLineEdit*>(combo->lineEdit())->add
|
||
13 years ago
|
(actionReload);
|
||
|
}
|
||
|
if (!_quirks) {
|
||
|
dynamic_cast<ButtonLineEdit*>(combo->lineEdit())->add
|
||
|
(actionAddBookmark);
|
||
|
dynamic_cast<ButtonLineEdit*>(combo->lineEdit())->add
|
||
|
(actionClearLocation);
|
||
|
}
|
||
13 years ago
|
_editbookmarks =
|
||
|
std::auto_ptr<EditBookmarks>(new EditBookmarks(combo, this));
|
||
|
} else {
|
||
|
QLineEdit* label(new QLineEdit(_toolbar));
|
||
|
_url = label;
|
||
|
label->setReadOnly(true);
|
||
13 years ago
|
_url->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
|
||
|
QSizePolicy::Minimum));
|
||
13 years ago
|
}
|
||
14 years ago
|
_toolbar->addWidget(_url);
|
||
13 years ago
|
QFrame* searchFrame(new QFrame);
|
||
|
searchFrame->setBackgroundRole(QPalette::Base);
|
||
|
searchFrame->setAutoFillBackground(true);
|
||
|
QHBoxLayout* layout(new QHBoxLayout);
|
||
|
layout->addWidget(_searchEngines);
|
||
|
_searchEngines->setStyleSheet(tr("background-color: white",
|
||
|
"search engines combobox"));
|
||
|
layout->addWidget(_search);
|
||
|
searchFrame->setLayout(layout);
|
||
|
_toolbar->addWidget(searchFrame);
|
||
13 years ago
|
_search->add(actionSearch);
|
||
|
if (!_quirks) _search->add(actionClearSearch);
|
||
|
_search->setSizePolicy(QSizePolicy(QSizePolicy::Fixed,
|
||
|
QSizePolicy::Minimum));
|
||
|
assert(connect(_search, SIGNAL(returnPressed()),
|
||
|
SLOT(on_actionSearch_triggered())));
|
||
|
if (_quirks) {
|
||
|
_toolbar->addAction(actionAddBookmark);
|
||
|
_toolbar->addAction(actionHome);
|
||
|
}
|
||
14 years ago
|
assert(connect(&_errorLog, SIGNAL(reset()), SLOT(errorReset())));
|
||
14 years ago
|
assert(connect(&_networkManager, SIGNAL(finished(QNetworkReply*)),
|
||
|
SLOT(finished(QNetworkReply*))));
|
||
14 years ago
|
assert(connect(&_networkManager, SIGNAL(created(QNetworkReply*)),
|
||
|
&_downloadManager, SLOT(add(QNetworkReply*))));
|
||
|
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())));
|
||
14 years ago
|
assert(connect(&_downloadManager, SIGNAL(error(QString)),
|
||
|
SLOT(downloadError(QString))));
|
||
13 years ago
|
assert(connect(&_downloadManager, SIGNAL(metaDataChanged(QNetworkReply*)),
|
||
|
SLOT(metaDataChanged(QNetworkReply*))));
|
||
13 years ago
|
assert(connect(&_settings, SIGNAL(newSettings()), SLOT(newSettings())));
|
||
|
newSettings();
|
||
14 years ago
|
on_actionNewTab_triggered();
|
||
14 years ago
|
|
||
13 years ago
|
if (!settings || _kiosk) {
|
||
|
actionSettings->setVisible(false);
|
||
|
actionEditBookmarks->setVisible(false);
|
||
|
}
|
||
15 years ago
|
if (_kiosk) {
|
||
14 years ago
|
actionNew->setEnabled(false);
|
||
|
actionNew->setVisible(false);
|
||
|
actionNewTab->setEnabled(false);
|
||
|
actionNewTab->setVisible(false);
|
||
13 years ago
|
actionCloseTab->setVisible(false);
|
||
15 years ago
|
}
|
||
13 years ago
|
if (!_kiosk && !_startUrl && _settings.flag("SaveWindowState")
|
||
|
&& _settings())
|
||
|
loadWin();
|
||
14 years ago
|
if (urls.size()) load(urls.at(0));
|
||
|
for (int i(1); i<urls.size(); ++i) load(urls.at(i), newTab());
|
||
14 years ago
|
if (!QSslSocket::supportsSsl())
|
||
|
QMessageBox::critical(this, tr("SSL Not Supported"),
|
||
|
tr("SSL is not supported on your system"));
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
~Browser() {
|
||
|
LOG;
|
||
14 years ago
|
for (DownloadProcesses::iterator it(_downloadProcesses.begin());
|
||
|
it!=_downloadProcesses.end(); ++it) {
|
||
13 years ago
|
LOG<<"cleanup:"<<it->second->fileName();
|
||
14 years ago
|
it->second->setAutoRemove(_settings.flag("CloseApps"));
|
||
|
delete it->second;
|
||
|
it->second = 0;
|
||
13 years ago
|
if (_settings.flag("CloseApps")) {
|
||
|
it->first->terminate();
|
||
|
delete it->first;
|
||
|
}
|
||
14 years ago
|
}
|
||
14 years ago
|
}
|
||
15 years ago
|
|
||
14 years ago
|
//! Whitelisting
|
||
15 years ago
|
bool check(QUrl page) {
|
||
|
return true;
|
||
|
}
|
||
14 years ago
|
|
||
|
QWebView* newTab() {
|
||
|
QWebView* browser(new QWebView);
|
||
14 years ago
|
browser->setPage(new WebPage(this, browser));
|
||
13 years ago
|
browser->page()->setPluginFactory(new PluginFactory);
|
||
14 years ago
|
browser->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
|
||
|
browser->page()->setNetworkAccessManager(&_networkManager);
|
||
|
browser->page()->setForwardUnsupportedContent(true);
|
||
|
_url->setFocus();
|
||
|
// QWebView
|
||
|
assert(connect(browser, SIGNAL(urlChanged(const QUrl&)),
|
||
|
SLOT(urlChanged(const QUrl&))));
|
||
|
assert(connect(browser, SIGNAL(linkClicked(const QUrl&)),
|
||
|
SLOT(linkClicked(const QUrl&))));
|
||
|
assert(connect(browser, SIGNAL(iconChanged()),
|
||
|
SLOT(iconChanged())));
|
||
|
assert(connect(browser, SIGNAL(titleChanged(const QString&)),
|
||
|
SLOT(titleChanged(const QString&))));
|
||
|
assert(connect(browser, SIGNAL(statusBarMessage(const QString&)),
|
||
|
SLOT(statusBarMessage(const QString&))));
|
||
|
assert(connect(browser, SIGNAL(loadProgress(int)),
|
||
|
SLOT(loadProgress(int))));
|
||
|
assert(connect(browser, SIGNAL(loadStarted()),
|
||
|
SLOT(loadStarted())));
|
||
|
assert(connect(browser, SIGNAL(loadFinished(bool)),
|
||
|
SLOT(loadFinished(bool))));
|
||
|
// QWebPage WebAction
|
||
|
assert(connect(browser->pageAction(QWebPage::OpenLink),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredOpenLink(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::OpenLinkInNewWindow),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredOpenLinkInNewWindow(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::OpenFrameInNewWindow),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredOpenFrameInNewWindow(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::DownloadLinkToDisk),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredDownloadLinkToDisk(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::CopyLinkToClipboard),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredCopyLinkToClipboard(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::OpenImageInNewWindow),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredOpenImageInNewWindow(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::DownloadImageToDisk),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredDownloadImageToDisk(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::CopyImageToClipboard),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredCopyImageToClipboard(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::Back),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredBack(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::Forward),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredForward(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::Stop),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredStop(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::Reload),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredReload(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::Cut),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredCut(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::Copy),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredCopy(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::Paste),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredPaste(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::Undo),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredUndo(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::Redo),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredRedo(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::MoveToNextChar),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredMoveToNextChar(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::MoveToPreviousChar),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredMoveToPreviousChar(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::MoveToNextWord),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredMoveToNextWord(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::MoveToPreviousWord),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredMoveToPreviousWord(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::MoveToNextLine),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredMoveToNextLine(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::MoveToPreviousLine),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredMoveToPreviousLine(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::MoveToStartOfLine),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredMoveToStartOfLine(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::MoveToEndOfLine),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredMoveToEndOfLine(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::MoveToStartOfBlock),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredMoveToStartOfBlock(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::MoveToEndOfBlock),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredMoveToEndOfBlock(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::MoveToStartOfDocument),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredMoveToStartOfDocument(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::MoveToEndOfDocument),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredMoveToEndOfDocument(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::SelectNextChar),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredSelectNextChar(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::SelectPreviousChar),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredSelectPreviousChar(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::SelectNextWord),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredSelectNextWord(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::SelectPreviousWord),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredSelectPreviousWord(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::SelectNextLine),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredSelectNextLine(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::SelectPreviousLine),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredSelectPreviousLine(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::SelectStartOfLine),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredSelectStartOfLine(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::SelectEndOfLine),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredSelectEndOfLine(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::SelectStartOfBlock),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredSelectStartOfBlock(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::SelectEndOfBlock),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredSelectEndOfBlock(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::SelectStartOfDocument),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredSelectStartOfDocument(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::SelectEndOfDocument),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredSelectEndOfDocument(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::DeleteStartOfWord),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredDeleteStartOfWord(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::DeleteEndOfWord),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredDeleteEndOfWord(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::SetTextDirectionDefault),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredSetTextDirectionDefault(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::SetTextDirectionLeftToRight),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredSetTextDirectionLeftToRight(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::SetTextDirectionRightToLeft),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredSetTextDirectionRightToLeft(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::ToggleBold),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredToggleBold(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::ToggleItalic),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredToggleItalic(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::ToggleUnderline),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredToggleUnderline(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::InspectElement),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredInspectElement(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::InsertParagraphSeparator),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredInsertParagraphSeparator(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::InsertLineSeparator),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredInsertLineSeparator(bool))));
|
||
|
assert(connect(browser->pageAction(QWebPage::SelectAll),
|
||
|
SIGNAL(triggered(bool)),
|
||
|
SLOT(triggeredSelectAll(bool))));
|
||
|
// QWebPage
|
||
|
assert(connect(browser->page(), SIGNAL(contentsChanged()),
|
||
|
SLOT(contentsChanged())));
|
||
|
assert(connect(browser->page(),
|
||
|
SIGNAL(databaseQuotaExceeded(QWebFrame*, QString)),
|
||
|
SLOT(databaseQuotaExceeded(QWebFrame*, QString))));
|
||
|
assert(connect(browser->page(),
|
||
|
SIGNAL(downloadRequested(const QNetworkRequest&)),
|
||
|
SLOT(downloadRequested(const QNetworkRequest&))));
|
||
|
assert(connect(browser->page(), SIGNAL(frameCreated(QWebFrame*)),
|
||
|
SLOT(frameCreated(QWebFrame*))));
|
||
|
assert(connect(browser->page(),
|
||
|
SIGNAL(geometryChangeRequested(const QRect&)),
|
||
|
SLOT(geometryChangeRequested(const QRect&))));
|
||
|
// assert(connect(browser->page(), SIGNAL(linkClicked(const QUrl&)),
|
||
|
// SLOT(linkClicked(const QUrl&))));
|
||
|
assert(connect(browser->page(),
|
||
|
SIGNAL(linkHovered(const QString&, const QString&,
|
||
|
const QString&)),
|
||
|
SLOT(linkHovered(const QString&, const QString&,
|
||
|
const QString&))));
|
||
|
// assert(connect(browser->page(), SIGNAL(loadFinished(bool)),
|
||
|
// SLOT(loadFinished(bool))));
|
||
|
// assert(connect(browser->page(), SIGNAL(loadProgress(int)),
|
||
|
// SLOT(loadProgress(int))));
|
||
|
// assert(connect(browser->page(), SIGNAL(loadStarted()),
|
||
|
// SLOT(loadStarted())));
|
||
|
assert(connect(browser->page(),
|
||
|
SIGNAL(menuBarVisibilityChangeRequested(bool)),
|
||
|
SLOT(menuBarVisibilityChangeRequested(bool))));
|
||
|
assert(connect(browser->page(), SIGNAL(microFocusChanged()),
|
||
|
SLOT(microFocusChanged())));
|
||
|
assert(connect(browser->page(), SIGNAL(printRequested(QWebFrame*)),
|
||
|
SLOT(printRequested(QWebFrame*))));
|
||
|
assert(connect(browser->page(), SIGNAL(repaintRequested(const QRect&)),
|
||
|
SLOT(repaintRequested(const QRect&))));
|
||
|
assert(connect(browser->page(),
|
||
|
SIGNAL(restoreFrameStateRequested(QWebFrame*)),
|
||
|
SLOT(restoreFrameStateRequested(QWebFrame*))));
|
||
|
assert(connect(browser->page(),
|
||
|
SIGNAL(saveFrameStateRequested(QWebFrame*,
|
||
|
QWebHistoryItem*)),
|
||
|
SLOT(saveFrameStateRequested(QWebFrame*,
|
||
|
QWebHistoryItem*))));
|
||
|
assert(connect(browser->page(),
|
||
|
SIGNAL(scrollRequested(int, int, const QRect&)),
|
||
|
SLOT(scrollRequested(int, int, const QRect&))));
|
||
|
assert(connect(browser->page(), SIGNAL(selectionChanged()),
|
||
|
SLOT(selectionChanged())));
|
||
|
// assert(connect(browser->page(), SIGNAL(statusBarMessage(const QString&)),
|
||
|
// SLOT(statusBarMessage(const QString&))));
|
||
|
assert(connect(browser->page(),
|
||
|
SIGNAL(statusBarVisibilityChangeRequested(bool)),
|
||
|
SLOT(statusBarVisibilityChangeRequested(bool))));
|
||
|
assert(connect(browser->page(),
|
||
|
SIGNAL(toolBarVisibilityChangeRequested(bool)),
|
||
|
SLOT(toolBarVisibilityChangeRequested(bool))));
|
||
13 years ago
|
// assert(connect(browser->page(),
|
||
|
// SIGNAL(unsupportedContent(QNetworkReply*)),
|
||
|
// SLOT(unsupportedContent(QNetworkReply*))));
|
||
14 years ago
|
assert(connect(browser->page(), SIGNAL(windowCloseRequested()),
|
||
|
SLOT(windowCloseRequested())));
|
||
|
// QNetworkAccessManager
|
||
|
assert(connect(browser->page()->networkAccessManager(),
|
||
|
SIGNAL(authenticationRequired(QNetworkReply*,
|
||
|
QAuthenticator*)),
|
||
|
SLOT(authenticationRequired(QNetworkReply*,
|
||
|
QAuthenticator*))));
|
||
|
assert(connect(browser->page()->networkAccessManager(),
|
||
|
SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&,
|
||
|
QAuthenticator*)),
|
||
|
SLOT(proxyAuthenticationRequired(const QNetworkProxy&,
|
||
|
QAuthenticator*))));
|
||
|
assert(connect(browser->page()->networkAccessManager(),
|
||
|
SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)),
|
||
|
SLOT(sslErrors(QNetworkReply*, const QList<QSslError>&))));
|
||
13 years ago
|
_tabs->setCurrentIndex(_tabs->addTab(browser, tr("New Tab")));
|
||
14 years ago
|
_tabs->setTabsClosable(_tabs->count()>1);
|
||
14 years ago
|
return browser;
|
||
|
}
|
||
|
|
||
|
protected:
|
||
|
|
||
|
void closeEvent(QCloseEvent *event) {
|
||
|
LOG;
|
||
13 years ago
|
if (!_kiosk && !_startUrl && _settings.flag("SaveWindowState")
|
||
|
&& _settings())
|
||
14 years ago
|
saveWin();
|
||
|
QMainWindow::closeEvent(event);
|
||
13 years ago
|
QApplication::exit(0);
|
||
14 years ago
|
}
|
||
|
|
||
|
private Q_SLOTS:
|
||
|
|
||
|
void load() {
|
||
|
LOG;
|
||
13 years ago
|
if (qobject_cast<QComboBox*>(_url))
|
||
|
load(qobject_cast<QComboBox*>(_url)->currentText());
|
||
|
else
|
||
|
load(qobject_cast<QLineEdit*>(_url)->text());
|
||
14 years ago
|
}
|
||
|
|
||
|
void load(QString page) {
|
||
|
_settings.replaceSearchEngine(page);
|
||
|
if (QUrl(page).scheme()=="") page = "http://"+page;
|
||
|
load(QUrl(page));
|
||
|
}
|
||
|
|
||
|
void load(QUrl page, QWebView* view=0) {
|
||
|
LOG<<page.toString();
|
||
|
statusBar()->showMessage(tr("Checking: %1").arg(page.toString()));
|
||
|
if (!check(page)) {
|
||
|
LOG<<"########## BLACK LISTED IGNORED ##########";
|
||
|
statusBar()->showMessage(tr("Forbidden: %1").arg(page.toString()));
|
||
|
QMessageBox::warning(this, tr("Access Denied"),
|
||
|
tr("<p>Access denied due to security"
|
||
|
" considerations.</p><p>You are not"
|
||
|
" allowed to connect to %1.")
|
||
|
.arg(page.toString()));
|
||
|
return;
|
||
|
}
|
||
|
statusBar()->showMessage(tr("Reading: %1").arg(page.toString()));
|
||
|
if (!page.isValid()) {
|
||
|
statusBar()->showMessage(tr("Illegal URL: %1").arg(page.errorString()));
|
||
|
return;
|
||
|
}
|
||
|
if (!view) view=qobject_cast<QWebView*>(_tabs->currentWidget());
|
||
|
view->load(page);
|
||
|
}
|
||
|
|
||
13 years ago
|
void newSettings() {
|
||
|
_searchEngines->clear();
|
||
|
for (Settings::SearchEngines::const_iterator
|
||
|
it(_settings.searchEngines().begin());
|
||
|
it!=_settings.searchEngines().end(); it++)
|
||
|
if (QFile(":/icons/"+it.key()).exists())
|
||
|
_searchEngines->addItem(QIcon(":/icons/"+it.key()), "", it.value());
|
||
|
else
|
||
|
_searchEngines->addItem(it.key(), it.value());
|
||
|
if (_searchEngines->count()==0)
|
||
|
_searchEngines->addItem(QIcon(":/icons/gg"), tr("gg"),
|
||
|
tr("http://www.google.com/search?hl=%2&q=%1"));
|
||
|
}
|
||
|
|
||
14 years ago
|
void on_actionAddBookmark_triggered() {
|
||
13 years ago
|
QComboBox* url(qobject_cast<QComboBox*>(_url));
|
||
|
if (_url) {
|
||
|
url->addItem(url->currentText());
|
||
|
QAction* a(_bookmarks->addAction(url->currentText()));
|
||
|
a->setData(url->currentText());
|
||
|
connect(a, SIGNAL(triggered(bool)), SLOT(loadFromHistory()));
|
||
|
}
|
||
14 years ago
|
}
|
||
|
|
||
13 years ago
|
void on_actionEditBookmarks_triggered() {
|
||
|
_editbookmarks->show();
|
||
|
}
|
||
|
|
||
14 years ago
|
void zoom(int i) {
|
||
14 years ago
|
LOG<<i;
|
||
|
statusBar()->showMessage(tr("Zoom: %1%").arg(i));
|
||
|
qobject_cast<QWebView*>(_tabs->currentWidget())->setZoomFactor(i/100.0);
|
||
14 years ago
|
}
|
||
14 years ago
|
|
||
|
void loadFromHistory() {
|
||
|
load(qobject_cast<QAction*>(sender())->data().toString());
|
||
|
}
|
||
14 years ago
|
|
||
|
void on_actionHome_activated() {
|
||
|
LOG;
|
||
|
load(_home);
|
||
|
}
|
||
|
|
||
|
void on_actionNew_triggered() {
|
||
|
LOG;
|
||
|
QStringList args(QCoreApplication::arguments());
|
||
|
QString prg(args.takeFirst());
|
||
13 years ago
|
statusBar()->showMessage(tr("opening new window"), 5000);
|
||
14 years ago
|
QProcess::startDetached(prg, args);
|
||
|
}
|
||
|
|
||
|
void on_actionNewTab_triggered() {
|
||
|
newTab();
|
||
|
}
|
||
|
|
||
13 years ago
|
void on_actionCloseTab_triggered() {
|
||
|
on__tabs_tabCloseRequested(_tabs->currentIndex());
|
||
|
}
|
||
|
|
||
14 years ago
|
void on__tabs_currentChanged(int index) {
|
||
13 years ago
|
if (qobject_cast<QComboBox*>(_url))
|
||
|
qobject_cast<QComboBox*>(_url)->setEditText
|
||
|
(qobject_cast<QWebView*>(_tabs->currentWidget())
|
||
|
->url().toString());
|
||
|
else
|
||
|
qobject_cast<QLineEdit*>(_url)->setText
|
||
|
(qobject_cast<QWebView*>(_tabs->currentWidget())
|
||
|
->url().toString());
|
||
14 years ago
|
activateTab();
|
||
|
}
|
||
|
|
||
|
void on__tabs_tabCloseRequested(int index) {
|
||
|
_tabs->removeTab(index);
|
||
|
_tabs->setTabsClosable(_tabs->count()>1);
|
||
|
}
|
||
|
|
||
|
void on_actionPrintPreview_triggered() {
|
||
|
QPrintPreviewDialog preview(&_printer, this);
|
||
|
connect(&preview, SIGNAL(paintRequested(QPrinter*)),
|
||
|
qobject_cast<QWebView*>(_tabs->currentWidget()),
|
||
|
SLOT(print(QPrinter*)));
|
||
|
preview.exec();
|
||
|
}
|
||
|
|
||
|
void on_actionInstantPrint_triggered() {
|
||
|
qobject_cast<QWebView*>(_tabs->currentWidget())->print(&_printer);
|
||
|
}
|
||
|
|
||
|
void on_actionPrint_triggered() {
|
||
|
QPrintDialog dialog(&_printer, this);
|
||
|
dialog.setWindowTitle(tr("Print Document"));
|
||
|
if (dialog.exec()!=QDialog::Accepted) return;
|
||
|
on_actionInstantPrint_triggered();
|
||
|
}
|
||
|
|
||
|
void on_actionClose_triggered() {
|
||
|
LOG;
|
||
|
close();
|
||
|
}
|
||
|
|
||
|
void on_actionBack_triggered() {
|
||
|
LOG;
|
||
|
qobject_cast<QWebView*>(_tabs->currentWidget())->history()->back();
|
||
|
}
|
||
|
|
||
|
void on_actionBack_hovered() {
|
||
|
LOG;
|
||
|
if (!qobject_cast<QWebView*>(_tabs->currentWidget())->history()
|
||
|
->backItem().isValid())
|
||
|
return;
|
||
|
actionBack->setStatusTip
|
||
|
(tr("%1 - %2", "statusbar actionBack_hovered %1=url %2=title")
|
||
|
.arg(qobject_cast<QWebView*>(_tabs->currentWidget())->history()
|
||
|
->backItem().url().toString())
|
||
|
.arg(qobject_cast<QWebView*>(_tabs->currentWidget())->history()
|
||
|
->backItem().title()));
|
||
|
actionBack->showStatusText(this);
|
||
|
}
|
||
|
|
||
|
void on_actionForward_triggered() {
|
||
|
LOG;
|
||
|
qobject_cast<QWebView*>(_tabs->currentWidget())->history()->forward();
|
||
|
}
|
||
|
|
||
|
void on_actionForward_hovered() {
|
||
|
LOG;
|
||
|
if (!qobject_cast<QWebView*>(_tabs->currentWidget())->history()
|
||
|
->forwardItem().isValid())
|
||
|
return;
|
||
|
actionForward->setStatusTip
|
||
|
(tr("%1 - %2", "statusbar actionForward_hovered %1=url %2=title")
|
||
|
.arg(qobject_cast<QWebView*>(_tabs->currentWidget())->history()
|
||
|
->forwardItem().url().toString())
|
||
|
.arg(qobject_cast<QWebView*>(_tabs->currentWidget())->history()
|
||
|
->forwardItem().title()));
|
||
|
actionForward->showStatusText(this);
|
||
|
}
|
||
|
|
||
|
void on_actionReload_triggered() {
|
||
|
LOG;
|
||
|
qobject_cast<QWebView*>(_tabs->currentWidget())->reload();
|
||
|
}
|
||
|
|
||
|
void on_actionStop_triggered() {
|
||
|
LOG;
|
||
|
for (int i(0); i<_tabs->count(); ++i)
|
||
|
qobject_cast<QWebView*>(_tabs->widget(i))->stop();
|
||
|
_downloadManager.abort();
|
||
|
}
|
||
|
|
||
13 years ago
|
void on_actionClearLocation_triggered() {
|
||
|
if (!qobject_cast<QComboBox*>(_url)) return;
|
||
|
qobject_cast<QComboBox*>(_url)->clearEditText();
|
||
|
qobject_cast<QComboBox*>(_url)->setFocus();
|
||
|
}
|
||
|
|
||
|
void on_actionClearFind_triggered() {
|
||
|
_find->clear();
|
||
|
_find->setFocus();
|
||
14 years ago
|
}
|
||
|
|
||
14 years ago
|
void on_actionFind_triggered() {
|
||
13 years ago
|
if (_find->isHidden()) {
|
||
14 years ago
|
_find->setText(qobject_cast<QWebView*>(_tabs->currentWidget())
|
||
|
->selectedText());
|
||
13 years ago
|
_find->show();
|
||
14 years ago
|
}
|
||
|
disconnect(_find, SIGNAL(returnPressed()), this, SLOT(rfind()));
|
||
|
disconnect(_find, SIGNAL(textEdited(QString)), this, SLOT(rfind()));
|
||
|
assert(connect(_find, SIGNAL(returnPressed()), SLOT(find())));
|
||
|
assert(connect(_find, SIGNAL(textEdited(QString)), SLOT(find())));
|
||
13 years ago
|
_find->changeStyleSheet(tr("background-color: white", "neutral find"));
|
||
14 years ago
|
_find->setFocus();
|
||
|
}
|
||
|
|
||
|
void on_actionReverseFind_triggered() {
|
||
13 years ago
|
if (_find->isHidden()) {
|
||
14 years ago
|
_find->setText(qobject_cast<QWebView*>(_tabs->currentWidget())
|
||
|
->selectedText());
|
||
13 years ago
|
_find->show();
|
||
14 years ago
|
}
|
||
|
disconnect(_find, SIGNAL(returnPressed()), this, SLOT(find()));
|
||
|
disconnect(_find, SIGNAL(textEdited(QString)), this, SLOT(find()));
|
||
|
assert(connect(_find, SIGNAL(returnPressed()), SLOT(rfind())));
|
||
|
assert(connect(_find, SIGNAL(textEdited(QString)), SLOT(rfind())));
|
||
13 years ago
|
_find->changeStyleSheet(tr("background-color: white", "neutral find"));
|
||
14 years ago
|
_find->setFocus();
|
||
|
}
|
||
|
|
||
|
void find(const QString& txt=QString()) {
|
||
14 years ago
|
if (qobject_cast<QWebView*>(_tabs->currentWidget())->findText
|
||
|
(_find->text(),
|
||
|
QWebPage::FindWrapsAroundDocument))
|
||
13 years ago
|
_find->changeStyleSheet(tr("background-color: #ADA", "text found"));
|
||
14 years ago
|
else
|
||
13 years ago
|
_find->changeStyleSheet(tr("background-color: #F77", "text not found"));
|
||
14 years ago
|
}
|
||
|
|
||
|
void rfind(const QString& txt=QString()) {
|
||
14 years ago
|
if(qobject_cast<QWebView*>(_tabs->currentWidget())->findText
|
||
|
(_find->text(),
|
||
|
QWebPage::FindWrapsAroundDocument
|
||
|
|QWebPage::FindBackward))
|
||
13 years ago
|
_find->changeStyleSheet(tr("background-color: #ADA", "text found"));
|
||
14 years ago
|
else
|
||
13 years ago
|
_find->changeStyleSheet(tr("background-color: #F77", "text not found"));
|
||
14 years ago
|
}
|
||
|
|
||
|
void on_actionUnFind_triggered() {
|
||
13 years ago
|
_find->hide();
|
||
|
}
|
||
|
|
||
|
void on_actionSearch_triggered() {
|
||
13 years ago
|
load(_searchEngines->itemData(_searchEngines->currentIndex()).toString()
|
||
13 years ago
|
.arg(_search->text())
|
||
|
.arg(QLocale::system().name().left(2)));
|
||
|
}
|
||
|
|
||
|
void on_actionClearSearch_triggered() {
|
||
|
_search->clear();
|
||
14 years ago
|
}
|
||
14 years ago
|
|
||
14 years ago
|
void on_actionProxy_triggered() {
|
||
|
_proxy.show();
|
||
|
}
|
||
|
|
||
14 years ago
|
void on_actionLoginCertificate_triggered() {
|
||
|
_logincertificate.show();
|
||
|
}
|
||
|
|
||
14 years ago
|
void on_actionErrorLog_triggered() {
|
||
|
_errorLog.show();
|
||
|
}
|
||
14 years ago
|
|
||
|
void on_actionAbout_triggered() {
|
||
14 years ago
|
QMessageBox::about(this, tr("About"),
|
||
|
tr("%8\n"
|
||
14 years ago
|
"Version: %1\n"
|
||
|
"Builddate: %2\n"
|
||
|
"Libraries:\n"
|
||
14 years ago
|
"%3\n"
|
||
14 years ago
|
"%4\n"
|
||
|
"qt-%5 (%6)\n"
|
||
|
"openssl-%7")
|
||
14 years ago
|
.arg(VERSION)
|
||
|
.arg(BUILDDATE)
|
||
14 years ago
|
.arg(QString::fromStdString(proxy::version()))
|
||
14 years ago
|
.arg(QString::fromStdString(pcsc::version()))
|
||
|
.arg(qVersion())
|
||
14 years ago
|
.arg(QT_VERSION_STR)
|
||
14 years ago
|
.arg(SHLIB_VERSION_NUMBER)
|
||
|
.arg(QApplication::applicationName()));
|
||
14 years ago
|
}
|
||
|
|
||
|
void on_actionSettings_triggered() {
|
||
|
_settings.show();
|
||
|
}
|
||
|
|
||
13 years ago
|
void on_actionSaveWindowState_triggered() {
|
||
|
saveWin();
|
||
|
}
|
||
|
|
||
|
void on_actionLoadWindowState_triggered() {
|
||
|
loadWin();
|
||
|
}
|
||
|
|
||
|
void saveWin() {
|
||
|
LOG<<"Save Window State";
|
||
|
if (!_settings()) return;
|
||
|
QStringList urls;
|
||
|
if (qobject_cast<QComboBox*>(_url))
|
||
|
for (int i(0); i<qobject_cast<QComboBox*>(_url)->count(); ++i)
|
||
|
urls<<qobject_cast<QComboBox*>(_url)->itemText(i);
|
||
|
_settings()->setValue("Window/Urls", urls);
|
||
|
QStringList tabs;
|
||
|
for (int i(0); i<_tabs->count(); ++i)
|
||
|
tabs<<qobject_cast<QWebView*>(_tabs->widget(i))->url().toString();
|
||
|
_settings()->setValue("Window/Tabs", tabs);
|
||
|
_settings()->setValue("Window/CurrentTab", _tabs->currentIndex());
|
||
|
_settings()->setValue("Window/Geometry", saveGeometry());
|
||
|
_settings()->setValue("Window/WindowState", saveState());
|
||
|
}
|
||
|
|
||
|
void loadWin() {
|
||
|
LOG;
|
||
|
QStringList urls(_settings()->value("Window/Urls").toStringList());
|
||
|
urls.sort();
|
||
|
urls.removeDuplicates();
|
||
13 years ago
|
if (qobject_cast<QComboBox*>(_url)) {
|
||
|
qobject_cast<QComboBox*>(_url)->clear();
|
||
13 years ago
|
qobject_cast<QComboBox*>(_url)->addItems(urls);
|
||
13 years ago
|
}
|
||
|
_bookmarks->clear();
|
||
|
for (QStringList::iterator it(urls.begin()); it!=urls.end(); ++it) {
|
||
|
QAction* a(_bookmarks->addAction(*it));
|
||
|
a->setData(*it);
|
||
|
connect(a, SIGNAL(triggered(bool)), SLOT(loadFromHistory()));
|
||
|
}
|
||
13 years ago
|
QStringList tabs(_settings()->value("Window/Tabs").toStringList());
|
||
13 years ago
|
int oldCnt(_tabs->count());
|
||
13 years ago
|
for (QStringList::iterator it(tabs.begin()); it!=tabs.end(); ++it) {
|
||
|
LOG<<"-------------------------------------------------------------";
|
||
|
load(*it, newTab());
|
||
|
LOG<<"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
|
||
|
}
|
||
13 years ago
|
for (int i(0); i<oldCnt && _tabs->count()>1; ++i) _tabs->removeTab(0);
|
||
13 years ago
|
_tabs->setTabsClosable(_tabs->count()>1);
|
||
|
_tabs->setCurrentIndex(_settings()->value("Window/CurrentTab").toInt());
|
||
|
restoreGeometry(_settings()->value("Window/Geometry").toByteArray());
|
||
|
restoreState(_settings()->value("Window/WindowState").toByteArray());
|
||
|
}
|
||
|
|
||
14 years ago
|
//@name QWebView slots
|
||
|
//@{
|
||
|
|
||
|
void urlChanged(const QUrl& url) {
|
||
|
LOG<<url.toString();
|
||
|
if (sender()!=_tabs->currentWidget()) return;
|
||
|
LOG<<"signal on current tab";
|
||
13 years ago
|
if (qobject_cast<QComboBox*>(_url))
|
||
|
qobject_cast<QComboBox*>(_url)->setEditText(url.toString());
|
||
|
else
|
||
|
qobject_cast<QLineEdit*>(_url)->setText(url.toString());
|
||
14 years ago
|
}
|
||
|
|
||
|
void linkClicked(const QUrl& url) {
|
||
|
LOG<<url.toString();
|
||
|
load(url, qobject_cast<QWebView*>(sender()));
|
||
|
}
|
||
|
|
||
|
void iconChanged() {
|
||
|
LOG;
|
||
|
QWebView* view(qobject_cast<QWebView*>(sender()));
|
||
|
int index = _tabs->indexOf(view);
|
||
|
if (index<0) return;
|
||
|
QIcon icon(QWebSettings::iconForUrl(view->url()));
|
||
|
if (icon.isNull()) {
|
||
|
LOG<<"Icon for URL is Null"<<view->url();
|
||
|
QPixmap pixmap(QWebSettings::webGraphic
|
||
|
(QWebSettings::DefaultFrameIconGraphic));
|
||
|
if (!pixmap.isNull()) icon = pixmap;
|
||
|
} else icon = icon.pixmap(16, 16);
|
||
|
if (icon.isNull()) LOG<<"Icon is still null";
|
||
|
_tabs->setTabIcon(index, icon);
|
||
|
}
|
||
|
|
||
|
void titleChanged(const QString& text) {
|
||
|
LOG<<text;
|
||
|
_tabs->setTabText(_tabs->indexOf(qobject_cast<QWidget*>(sender())),
|
||
|
trUtf8("%1").arg(text));
|
||
|
}
|
||
|
|
||
|
void statusBarMessage(const QString& text) {
|
||
|
LOG<<text;
|
||
|
if (text.size()) statusBar()->showMessage(tr("Info: %1").arg(text));
|
||
|
}
|
||
|
|
||
|
void loadProgress(int i) {
|
||
|
LOG<<i;
|
||
|
}
|
||
|
|
||
|
void loadStarted() {
|
||
|
LOG;
|
||
|
}
|
||
|
|
||
|
void loadFinished(bool ok) {
|
||
|
LOG<<(ok?"success":"error");
|
||
13 years ago
|
QSize sz(qobject_cast<QWebView*>(_tabs->currentWidget())->size());
|
||
|
qobject_cast<QWebView*>(_tabs->currentWidget())->resize(0,0);
|
||
|
qobject_cast<QWebView*>(_tabs->currentWidget())->resize(sz);
|
||
14 years ago
|
if (ok) {
|
||
|
statusBar()->showMessage(tr("done."));
|
||
|
goodUrl();
|
||
|
}
|
||
14 years ago
|
activateTab();
|
||
|
}
|
||
|
|
||
|
//@}
|
||
|
|
||
|
//@name QWebPage WebAction slots
|
||
|
//@{
|
||
|
|
||
|
void triggeredOpenLink(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredOpenLinkInNewWindow(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredOpenFrameInNewWindow(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredDownloadLinkToDisk(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredCopyLinkToClipboard(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredOpenImageInNewWindow(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredDownloadImageToDisk(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredCopyImageToClipboard(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredBack(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredForward(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredStop(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredReload(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredCut(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredCopy(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredPaste(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredUndo(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredRedo(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredMoveToNextChar(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredMoveToPreviousChar(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredMoveToNextWord(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredMoveToPreviousWord(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredMoveToNextLine(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredMoveToPreviousLine(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredMoveToStartOfLine(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredMoveToEndOfLine(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredMoveToStartOfBlock(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredMoveToEndOfBlock(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredMoveToStartOfDocument(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredMoveToEndOfDocument(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredSelectNextChar(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredSelectPreviousChar(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredSelectNextWord(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredSelectPreviousWord(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredSelectNextLine(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredSelectPreviousLine(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredSelectStartOfLine(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredSelectEndOfLine(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredSelectStartOfBlock(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredSelectEndOfBlock(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredSelectStartOfDocument(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredSelectEndOfDocument(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredDeleteStartOfWord(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredDeleteEndOfWord(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredSetTextDirectionDefault(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredSetTextDirectionLeftToRight(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredSetTextDirectionRightToLeft(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredToggleBold(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredToggleItalic(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredToggleUnderline(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredInspectElement(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredInsertParagraphSeparator(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredInsertLineSeparator(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
void triggeredSelectAll(bool) {
|
||
|
LOG<<qobject_cast<QAction*>(sender())->data().toString();
|
||
|
}
|
||
|
|
||
|
//@}
|
||
|
|
||
|
//@name QWebPage slots
|
||
|
//@{
|
||
|
|
||
|
void contentsChanged() {
|
||
|
LOG;
|
||
|
}
|
||
|
|
||
|
void databaseQuotaExceeded(QWebFrame* frame, QString databaseName) {
|
||
|
LOG<<databaseName;
|
||
|
}
|
||
|
|
||
|
void downloadRequested(const QNetworkRequest& request) {
|
||
|
LOG;
|
||
|
}
|
||
|
|
||
|
void frameCreated(QWebFrame* frame) {
|
||
|
LOG;
|
||
|
}
|
||
|
|
||
|
void geometryChangeRequested(const QRect& geom) {
|
||
|
LOG;
|
||
|
}
|
||
|
|
||
|
// void linkClicked(const QUrl& url) {
|
||
|
// LOG<<url.toString();
|
||
|
// }
|
||
|
|
||
|
void linkHovered(const QString& link, const QString& title,
|
||
|
const QString& textContent) {
|
||
|
LOG<<link<<title<<textContent;
|
||
|
statusBar()->showMessage(tr("%1", "statusbar for hovered link %1=url")
|
||
|
.arg(link));
|
||
|
}
|
||
|
|
||
|
// void loadFinished(bool ok) {
|
||
|
// LOG<<(ok?"succeess":"error");
|
||
|
// }
|
||
|
|
||
|
// void loadProgress(int progress) {
|
||
|
// LOG<<progress;
|
||
|
// }
|
||
|
|
||
|
// void loadStarted() {
|
||
|
// LOG;
|
||
|
// }
|
||
|
|
||
|
void menuBarVisibilityChangeRequested(bool visible) {
|
||
|
LOG;
|
||
|
}
|
||
|
|
||
|
void microFocusChanged() {
|
||
|
LOG;
|
||
|
}
|
||
|
|
||
|
void printRequested(QWebFrame* frame) {
|
||
|
LOG;
|
||
|
}
|
||
|
|
||
|
void repaintRequested(const QRect& dirtyRect) {
|
||
|
//LOG;
|
||
|
}
|
||
|
|
||
|
void restoreFrameStateRequested(QWebFrame* frame) {
|
||
|
LOG;
|
||
|
}
|
||
|
|
||
|
void saveFrameStateRequested(QWebFrame* frame, QWebHistoryItem* item) {
|
||
|
LOG;
|
||
|
}
|
||
|
|
||
|
void scrollRequested(int dx, int dy, const QRect& rectToScroll) {
|
||
|
LOG;
|
||
|
}
|
||
|
|
||
|
void selectionChanged() {
|
||
|
LOG;
|
||
|
}
|
||
|
|
||
|
// void statusBarMessage(const QString& text) {
|
||
|
// LOG;
|
||
|
// }
|
||
|
|
||
|
void statusBarVisibilityChangeRequested(bool visible) {
|
||
|
LOG;
|
||
|
}
|
||
|
|
||
|
void toolBarVisibilityChangeRequested(bool visible) {
|
||
|
LOG;
|
||
|
}
|
||
|
|
||
|
//@name handle downloads
|
||
|
//@{
|
||
|
|
||
|
void unsupportedContent(QNetworkReply* reply) {
|
||
|
LOG<<reply->header(QNetworkRequest::ContentTypeHeader).toString();
|
||
14 years ago
|
LOG<<"Status:"<<_downloadManager.networkError(reply->error());
|
||
13 years ago
|
QList<QNetworkReply::RawHeaderPair> rh(reply->rawHeaderPairs());
|
||
|
for(QList<QNetworkReply::RawHeaderPair>::iterator it(rh.begin());
|
||
|
it!=rh.end(); ++it) {
|
||
|
LOG<<"RawHeader:"<<it->first<<it->second;
|
||
|
}
|
||
14 years ago
|
if (reply->isFinished())
|
||
|
handleContent(reply);
|
||
|
else
|
||
|
assert(connect(reply, SIGNAL(finished()), SLOT(downloadFinished())));
|
||
14 years ago
|
}
|
||
|
|
||
|
void downloadFinished() {
|
||
14 years ago
|
LOG;
|
||
14 years ago
|
QNetworkReply *reply(qobject_cast<QNetworkReply*>(sender()));
|
||
14 years ago
|
handleContent(reply);
|
||
|
}
|
||
|
|
||
13 years ago
|
//! check and handle content that is defined in settings
|
||
|
void metaDataChanged(QNetworkReply* reply) {
|
||
|
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
|
||
|
(_settings.mimetype
|
||
|
(reply->header(QNetworkRequest::ContentTypeHeader).toString(),
|
||
|
filename));
|
||
|
if (!type.isEmpty()) unsupportedContent(reply);
|
||
|
}
|
||
|
|
||
14 years ago
|
void handleContent(QNetworkReply* reply) {
|
||
14 years ago
|
LOG<<"Location:"<<reply->header(QNetworkRequest::LocationHeader)
|
||
|
.toString();
|
||
|
LOG<<"Content-Type:"<<reply->header(QNetworkRequest::ContentTypeHeader)
|
||
|
.toString();
|
||
14 years ago
|
LOG<<"Content-Disposition:"<<reply->rawHeader("Content-Disposition");
|
||
14 years ago
|
LOG<<"Status:"<<_downloadManager.networkError(reply->error());
|
||
14 years ago
|
LOG<<"URL:"<<reply->url().toString();
|
||
|
LOG<<"File:"<<reply->url().toLocalFile();
|
||
|
LOG<<"Path:"<<reply->url().path();
|
||
14 years ago
|
if (reply->error()!=QNetworkReply::NoError) {
|
||
|
LOG<<"Error:"<<_downloadManager.networkError(reply->error());
|
||
|
return;
|
||
|
}
|
||
14 years ago
|
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;
|
||
14 years ago
|
QStringList type
|
||
|
(_settings.mimetype
|
||
|
(reply->header(QNetworkRequest::ContentTypeHeader).toString(),
|
||
|
filename));
|
||
|
if (!type.isEmpty()) {
|
||
|
filename.replace(QRegExp("^(.*)\\."+type.at(0)+"$"),
|
||
14 years ago
|
"\\1"); // remove extension
|
||
13 years ago
|
run(reply, filename+"."+type.at(0), type.at(1));
|
||
14 years ago
|
} else {
|
||
13 years ago
|
SaveOrRunDialog choice(_kiosk, this);
|
||
|
choice.setup(filename,
|
||
|
reply->header(QNetworkRequest::ContentTypeHeader)
|
||
|
.toString(),
|
||
|
reply->url().host());
|
||
|
if (choice.exec()==QDialog::Accepted) {
|
||
13 years ago
|
if (choice.save()) {
|
||
13 years ago
|
QFile file(choice.sor()->filename());
|
||
13 years ago
|
file.open(QIODevice::WriteOnly);
|
||
|
file.write(reply->readAll());
|
||
|
file.close();
|
||
|
} else if (choice.run()) {
|
||
13 years ago
|
run(reply, filename, choice.sor()->program()+" %1");
|
||
13 years ago
|
} else {
|
||
|
// ...
|
||
|
}
|
||
13 years ago
|
}
|
||
14 years ago
|
}
|
||
|
}
|
||
|
|
||
13 years ago
|
void run(QNetworkReply* reply, QString filename, QString command) {
|
||
|
TemporaryFile *file(new TemporaryFile
|
||
|
(QDir::tempPath()+QDir::separator()
|
||
|
+filename));
|
||
|
file->open();
|
||
13 years ago
|
reply->seek(0);
|
||
13 years ago
|
file->write(reply->readAll());
|
||
|
file->close();
|
||
|
LOG<<"Stored as:"<<file->fileName();
|
||
|
statusBar()->showMessage(tr("launching application ..."), 5000);
|
||
|
QProcess* process(new QProcess);
|
||
|
_downloadProcesses[process] = file;
|
||
|
assert(connect(process, SIGNAL(finished(int, QProcess::ExitStatus)),
|
||
|
SLOT(processFinished())));
|
||
|
QStringList args(command.split(" ")
|
||
|
.replaceInStrings("%1", file->fileName()));
|
||
|
QString prg(args.takeFirst());
|
||
|
LOG<<"Running:"<<prg<<args.join(" ");
|
||
|
process->start(prg, args);
|
||
|
}
|
||
|
|
||
14 years ago
|
void processFinished() {
|
||
14 years ago
|
LOG;
|
||
13 years ago
|
if (_downloadProcesses.find(qobject_cast<QProcess*>(sender()))
|
||
|
== _downloadProcesses.end()) return;
|
||
|
if (_downloadProcesses[qobject_cast<QProcess*>(sender())])
|
||
|
_downloadProcesses[qobject_cast<QProcess*>(sender())]
|
||
|
->setAutoRemove(true);
|
||
14 years ago
|
delete _downloadProcesses[qobject_cast<QProcess*>(sender())];
|
||
14 years ago
|
_downloadProcesses.erase(qobject_cast<QProcess*>(sender()));
|
||
|
}
|
||
|
|
||
|
//@}
|
||
|
|
||
|
void windowCloseRequested() {
|
||
|
LOG;
|
||
|
}
|
||
|
|
||
|
//@}
|
||
|
|
||
|
//@name DownloadManager signals
|
||
|
//@{
|
||
|
|
||
|
void progress(qint64 done, qint64 total) {
|
||
|
_progress->setMaximum(total);
|
||
|
_progress->setValue(done);
|
||
|
}
|
||
|
|
||
|
void started() {
|
||
13 years ago
|
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||
13 years ago
|
if (_quirks) {
|
||
|
actionStop->setEnabled(true);
|
||
|
} else {
|
||
|
actionStop->setVisible(true);
|
||
|
actionReload->setVisible(false);
|
||
|
}
|
||
14 years ago
|
_progress->setRange(0, 0);
|
||
|
_progress->setValue(0);
|
||
14 years ago
|
_progress->setEnabled(true);
|
||
14 years ago
|
_progress->show();
|
||
|
}
|
||
|
|
||
|
void finished() {
|
||
|
LOG;
|
||
13 years ago
|
QApplication::restoreOverrideCursor();
|
||
13 years ago
|
if (_quirks) {
|
||
|
actionStop->setEnabled(false);
|
||
|
} else {
|
||
|
actionStop->setVisible(false);
|
||
|
actionReload->setVisible(true);
|
||
|
}
|
||
14 years ago
|
_progress->setRange(0, 1);
|
||
|
_progress->setValue(1);
|
||
|
_progress->setEnabled(false);
|
||
14 years ago
|
}
|
||
|
|
||
14 years ago
|
void finished(QNetworkReply *r) {
|
||
|
LOG;
|
||
|
if (r->error()!=QNetworkReply::NoError &&
|
||
|
r->error()!=QNetworkReply::OperationCanceledError) {
|
||
|
statusBar()->showMessage(DownloadManager::networkError(r->error()));
|
||
|
badUrl();
|
||
14 years ago
|
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();
|
||
14 years ago
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void errorReset() {
|
||
|
LOG;
|
||
|
_showErrorLog->hide();
|
||
|
}
|
||
|
|
||
|
void badUrl() {
|
||
13 years ago
|
if (qobject_cast<QComboBox*>(_url))
|
||
|
dynamic_cast<ButtonLineEdit*>
|
||
|
(qobject_cast<QComboBox*>(_url)->lineEdit())
|
||
13 years ago
|
->changeStyleSheet(tr("background-color: #F77", "invalid url"));
|
||
13 years ago
|
else
|
||
|
qobject_cast<QLineEdit*>(_url)
|
||
|
->setStyleSheet(tr("background-color: #F77", "invalid url"));
|
||
14 years ago
|
}
|
||
|
|
||
|
void goodUrl() {
|
||
13 years ago
|
if (qobject_cast<QComboBox*>(_url))
|
||
|
dynamic_cast<ButtonLineEdit*>
|
||
|
(qobject_cast<QComboBox*>(_url)->lineEdit())
|
||
13 years ago
|
->changeStyleSheet(tr("background-color: white", "valid url"));
|
||
13 years ago
|
else
|
||
|
qobject_cast<QLineEdit*>(_url)
|
||
|
->setStyleSheet(tr("background-color: white", "valid url"));
|
||
14 years ago
|
}
|
||
|
|
||
14 years ago
|
void downloadError(QString error) {
|
||
|
_errorLog.append(error);
|
||
|
}
|
||
|
|
||
14 years ago
|
//@}
|
||
|
|
||
|
//@name QNetworkAccessManager signals
|
||
|
//@{
|
||
|
|
||
|
void authenticationRequired(QNetworkReply* reply,
|
||
|
QAuthenticator* authenticator) {
|
||
14 years ago
|
LOG<<reply->url().toString()<<authenticator->realm();
|
||
14 years ago
|
statusBar()->showMessage(tr("authentication required"));
|
||
|
Authentication auth(authenticator, this);
|
||
14 years ago
|
if (auth.exec()==QDialog::Rejected) reply->abort();
|
||
14 years ago
|
}
|
||
|
|
||
|
void proxyAuthenticationRequired(const QNetworkProxy& proxy,
|
||
|
QAuthenticator* authenticator) {
|
||
|
LOG;
|
||
|
}
|
||
|
|
||
|
void sslErrors(QNetworkReply* reply, const QList<QSslError>& errors) {
|
||
|
LOG;
|
||
|
statusBar()->showMessage(tr("ssl error"));
|
||
|
}
|
||
|
|
||
|
//@}
|
||
|
|
||
|
private:
|
||
|
|
||
|
void activateTab() {
|
||
|
iconChanged();
|
||
13 years ago
|
QWebHistory* history(qobject_cast<QWebView*>(_tabs->currentWidget())
|
||
14 years ago
|
->history());
|
||
|
actionForward->setEnabled(history->canGoForward());
|
||
|
actionBack->setEnabled(history->canGoBack());
|
||
|
_history->clear();
|
||
|
QList<QWebHistoryItem> items(history->items());
|
||
|
for (int i = 0; i < items.size(); ++i) {
|
||
|
QAction* a(_history->addAction(items[i].title()));
|
||
|
a->setData(items[i].url());
|
||
|
connect(a, SIGNAL(triggered(bool)), SLOT(loadFromHistory()));
|
||
|
}
|
||
14 years ago
|
}
|
||
|
|
||
13 years ago
|
private:
|
||
|
|
||
|
class ButtonLineEdit: public QLineEdit {
|
||
|
public:
|
||
13 years ago
|
ButtonLineEdit(QWidget* p=0): QLineEdit(p) {
|
||
|
LOG;
|
||
|
}
|
||
13 years ago
|
QToolButton* add(QAction* a) {
|
||
13 years ago
|
LOG;
|
||
13 years ago
|
QToolButton* b(new QToolButton(this));
|
||
|
b->setDefaultAction(a);
|
||
|
add(b);
|
||
|
return b;
|
||
|
}
|
||
|
ButtonLineEdit& add(QToolButton* b) {
|
||
13 years ago
|
LOG;
|
||
13 years ago
|
b->setParent(this);
|
||
|
b->setStyleSheet("QToolButton { border: none; padding: 0; }");
|
||
|
b->setCursor(Qt::ArrowCursor);
|
||
|
_buttons.push_back(b);
|
||
|
resizeEvent(0);
|
||
|
return *this;
|
||
|
}
|
||
|
ButtonLineEdit& changeStyleSheet(QString s) {
|
||
13 years ago
|
LOG;
|
||
13 years ago
|
_style = s;
|
||
|
resizeEvent(0);
|
||
|
return *this;
|
||
|
}
|
||
|
protected:
|
||
13 years ago
|
void resizeEvent(QResizeEvent*) {
|
||
|
QSize sz;
|
||
|
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
||
|
for (Buttons::iterator it(_buttons.begin());
|
||
|
it!=_buttons.end(); ++it) {
|
||
|
if (sz.isEmpty()) sz = (*it)->sizeHint();
|
||
|
else sz.setWidth(sz.width()+(*it)->sizeHint().width());
|
||
|
(*it)->move(rect().right() - frameWidth - sz.width(),
|
||
|
(rect().bottom() + 1 - (*it)->sizeHint().height())/2);
|
||
|
}
|
||
|
setStyleSheet(QString("QLineEdit { padding-right: %1px; %2 }")
|
||
|
.arg(sz.width() + frameWidth + 1)
|
||
|
.arg(_style));
|
||
|
}
|
||
13 years ago
|
private:
|
||
|
typedef QList<QToolButton*> Buttons;
|
||
|
Buttons _buttons;
|
||
|
QString _style;
|
||
|
};
|
||
|
|
||
15 years ago
|
private:
|
||
|
|
||
13 years ago
|
QWidget* _url;
|
||
|
ButtonLineEdit* _find;
|
||
15 years ago
|
QSlider* _zoom;
|
||
|
QProgressBar* _progress;
|
||
|
QString _home;
|
||
|
bool _kiosk;
|
||
14 years ago
|
QPrinter _printer;
|
||
14 years ago
|
SslClientAuthNetworkAccessManager _networkManager;
|
||
14 years ago
|
DownloadManager _downloadManager;
|
||
13 years ago
|
typedef std::map<QProcess*, TemporaryFile*> DownloadProcesses;
|
||
14 years ago
|
DownloadProcesses _downloadProcesses;
|
||
14 years ago
|
Settings _settings;
|
||
14 years ago
|
ErrorLog _errorLog;
|
||
14 years ago
|
LoginCertificate _logincertificate;
|
||
14 years ago
|
gui::Proxy _proxy;
|
||
14 years ago
|
QPushButton* _showErrorLog;
|
||
13 years ago
|
std::auto_ptr<EditBookmarks> _editbookmarks;
|
||
13 years ago
|
bool _startUrl;
|
||
13 years ago
|
bool _quirks;
|
||
|
ButtonLineEdit* _search;
|
||
13 years ago
|
QComboBox* _searchEngines;
|
||
15 years ago
|
};
|
||
|
#endif
|