|
|
|
@ -39,6 +39,7 @@ |
|
|
|
|
#include <webpage.hxx> |
|
|
|
|
#include <settings.hxx> |
|
|
|
|
#include <editbookmarks.hxx> |
|
|
|
|
#include <pluginfactory.hxx> |
|
|
|
|
#include <sslclientnetworkmanager.hxx> |
|
|
|
|
#include <proxyface/proxy.hxx> |
|
|
|
|
|
|
|
|
@ -85,17 +86,37 @@ class Browser: public QMainWindow, protected Ui::Browser { |
|
|
|
|
_zoom->setPageStep(10); |
|
|
|
|
_zoom->setTickPosition(QSlider::TicksAbove); |
|
|
|
|
assert(connect(_zoom, SIGNAL(valueChanged(int)), SLOT(zoom(int)))); |
|
|
|
|
_url = new QComboBox(_toolbar); |
|
|
|
|
_url->setInsertPolicy(QComboBox::NoInsert); |
|
|
|
|
_url->setLineEdit(new ButtonLineEdit(_url)); |
|
|
|
|
if (!_kiosk) { |
|
|
|
|
QComboBox* combo(new QComboBox(_toolbar)); |
|
|
|
|
_url = combo; |
|
|
|
|
combo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength); |
|
|
|
|
combo->setInsertPolicy(QComboBox::NoInsert); |
|
|
|
|
combo->setLineEdit(new ButtonLineEdit(combo)); |
|
|
|
|
combo->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, |
|
|
|
|
QSizePolicy::Preferred)); |
|
|
|
|
combo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength); |
|
|
|
|
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()))); |
|
|
|
|
dynamic_cast<ButtonLineEdit*>(combo->lineEdit())->add |
|
|
|
|
(actionAddBookmark); |
|
|
|
|
dynamic_cast<ButtonLineEdit*>(combo->lineEdit())->add |
|
|
|
|
(actionClearLocation); |
|
|
|
|
_editbookmarks = |
|
|
|
|
std::auto_ptr<EditBookmarks>(new EditBookmarks(combo, this)); |
|
|
|
|
} else { |
|
|
|
|
QLineEdit* label(new QLineEdit(_toolbar)); |
|
|
|
|
_url = label; |
|
|
|
|
label->setReadOnly(true); |
|
|
|
|
} |
|
|
|
|
_url->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, |
|
|
|
|
QSizePolicy::Preferred)); |
|
|
|
|
_url->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength); |
|
|
|
|
_url->setEditable(!_kiosk); |
|
|
|
|
_toolbar->addWidget(_url); |
|
|
|
|
assert(connect(&_errorLog, SIGNAL(reset()), SLOT(errorReset()))); |
|
|
|
|
assert(connect(_url, SIGNAL(currentIndexChanged(const QString&)), |
|
|
|
|
SLOT(load(QString)))); |
|
|
|
|
assert(connect(&_networkManager, SIGNAL(finished(QNetworkReply*)), |
|
|
|
|
SLOT(finished(QNetworkReply*)))); |
|
|
|
|
assert(connect(&_networkManager, SIGNAL(created(QNetworkReply*)), |
|
|
|
@ -120,20 +141,6 @@ class Browser: public QMainWindow, protected Ui::Browser { |
|
|
|
|
actionNewTab->setEnabled(false); |
|
|
|
|
actionNewTab->setVisible(false); |
|
|
|
|
} else { |
|
|
|
|
assert(connect(_url->lineEdit(), SIGNAL(returnPressed()), |
|
|
|
|
SLOT(load()))); |
|
|
|
|
assert(connect(_url->lineEdit(), SIGNAL(textChanged(QString)), |
|
|
|
|
SLOT(goodUrl()))); |
|
|
|
|
|
|
|
|
|
dynamic_cast<ButtonLineEdit*>(_url->lineEdit())->add |
|
|
|
|
(actionAddBookmark); |
|
|
|
|
|
|
|
|
|
dynamic_cast<ButtonLineEdit*>(_url->lineEdit())->add |
|
|
|
|
(actionClearLocation); |
|
|
|
|
assert(connect(actionClearLocation, SIGNAL(triggered()), |
|
|
|
|
_url, SLOT(clearEditText()))); |
|
|
|
|
assert(connect(actionClearLocation, SIGNAL(triggered()), |
|
|
|
|
_url, SLOT(setFocus()))); |
|
|
|
|
} |
|
|
|
|
if (!_kiosk && _settings.flag("SaveWindowState") && _settings()) |
|
|
|
|
loadWin(urls.size()); |
|
|
|
@ -142,8 +149,6 @@ class Browser: public QMainWindow, protected Ui::Browser { |
|
|
|
|
if (!QSslSocket::supportsSsl()) |
|
|
|
|
QMessageBox::critical(this, tr("SSL Not Supported"), |
|
|
|
|
tr("SSL is not supported on your system")); |
|
|
|
|
_editbookmarks = |
|
|
|
|
std::auto_ptr<EditBookmarks>(new EditBookmarks(_url, this)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
~Browser() { |
|
|
|
@ -167,6 +172,7 @@ class Browser: public QMainWindow, protected Ui::Browser { |
|
|
|
|
QWebView* newTab() { |
|
|
|
|
QWebView* browser(new QWebView); |
|
|
|
|
browser->setPage(new WebPage(this, browser)); |
|
|
|
|
browser->page()->setPluginFactory(new PluginFactory); |
|
|
|
|
browser->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); |
|
|
|
|
browser->page()->setNetworkAccessManager(&_networkManager); |
|
|
|
|
browser->page()->setForwardUnsupportedContent(true); |
|
|
|
@ -442,7 +448,10 @@ class Browser: public QMainWindow, protected Ui::Browser { |
|
|
|
|
|
|
|
|
|
void load() { |
|
|
|
|
LOG; |
|
|
|
|
load(_url->currentText()); |
|
|
|
|
if (qobject_cast<QComboBox*>(_url)) |
|
|
|
|
load(qobject_cast<QComboBox*>(_url)->currentText()); |
|
|
|
|
else |
|
|
|
|
load(qobject_cast<QLineEdit*>(_url)->text()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void load(QString page) { |
|
|
|
@ -474,7 +483,9 @@ class Browser: public QMainWindow, protected Ui::Browser { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void on_actionAddBookmark_triggered() { |
|
|
|
|
_url->addItem(_url->currentText()); |
|
|
|
|
if (qobject_cast<QComboBox*>(_url)) |
|
|
|
|
qobject_cast<QComboBox*>(_url)->addItem |
|
|
|
|
(qobject_cast<QComboBox*>(_url)->currentText()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void on_actionEditBookmarks_triggered() { |
|
|
|
@ -508,8 +519,14 @@ class Browser: public QMainWindow, protected Ui::Browser { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void on__tabs_currentChanged(int index) { |
|
|
|
|
_url->setEditText(qobject_cast<QWebView*>(_tabs->currentWidget()) |
|
|
|
|
->url().toString()); |
|
|
|
|
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()); |
|
|
|
|
activateTab(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -593,26 +610,43 @@ class Browser: public QMainWindow, protected Ui::Browser { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void on__find_textChanged(QString) { |
|
|
|
|
_find->setStyleSheet(tr("background-color: white", "neutral find")); |
|
|
|
|
_find->changeStyleSheet(tr("background-color: white", "neutral find")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void on_actionClearLocation_triggered() { |
|
|
|
|
if (!qobject_cast<QComboBox*>(_url)) return; |
|
|
|
|
qobject_cast<QComboBox*>(_url)->clearEditText(); |
|
|
|
|
qobject_cast<QComboBox*>(_url)->setFocus(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void on_actionClearFind_triggered() { |
|
|
|
|
if (!_find) return; |
|
|
|
|
_find->clear(); |
|
|
|
|
_find->setFocus(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void on_actionFind_triggered() { |
|
|
|
|
if (!_find) { |
|
|
|
|
statusBar()->addPermanentWidget(_find = new QLineEdit); |
|
|
|
|
statusBar()->addPermanentWidget(_find = new ButtonLineEdit); |
|
|
|
|
_find->setText(qobject_cast<QWebView*>(_tabs->currentWidget()) |
|
|
|
|
->selectedText()); |
|
|
|
|
_find->addAction(actionUnFind); |
|
|
|
|
_find->addAction(actionClearFind); |
|
|
|
|
} |
|
|
|
|
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()))); |
|
|
|
|
_find->setStyleSheet(tr("background-color: white", "neutral find")); |
|
|
|
|
_find->changeStyleSheet(tr("background-color: white", "neutral find")); |
|
|
|
|
_find->setFocus(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void on_actionReverseFind_triggered() { |
|
|
|
|
if (!_find) { |
|
|
|
|
statusBar()->addPermanentWidget(_find = new QLineEdit); |
|
|
|
|
statusBar()->addPermanentWidget(_find = new ButtonLineEdit); |
|
|
|
|
_find->add(actionUnFind); |
|
|
|
|
_find->add(actionClearFind); |
|
|
|
|
_find->setText(qobject_cast<QWebView*>(_tabs->currentWidget()) |
|
|
|
|
->selectedText()); |
|
|
|
|
} |
|
|
|
@ -620,7 +654,7 @@ class Browser: public QMainWindow, protected Ui::Browser { |
|
|
|
|
disconnect(_find, SIGNAL(textEdited(QString)), this, SLOT(find())); |
|
|
|
|
assert(connect(_find, SIGNAL(returnPressed()), SLOT(rfind()))); |
|
|
|
|
assert(connect(_find, SIGNAL(textEdited(QString)), SLOT(rfind()))); |
|
|
|
|
_find->setStyleSheet(tr("background-color: white", "neutral find")); |
|
|
|
|
_find->changeStyleSheet(tr("background-color: white", "neutral find")); |
|
|
|
|
_find->setFocus(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -628,9 +662,9 @@ class Browser: public QMainWindow, protected Ui::Browser { |
|
|
|
|
if (qobject_cast<QWebView*>(_tabs->currentWidget())->findText |
|
|
|
|
(_find->text(), |
|
|
|
|
QWebPage::FindWrapsAroundDocument)) |
|
|
|
|
_find->setStyleSheet(tr("background-color: #ADA", "text found")); |
|
|
|
|
_find->changeStyleSheet(tr("background-color: #ADA", "text found")); |
|
|
|
|
else |
|
|
|
|
_find->setStyleSheet(tr("background-color: #F77", "text not found")); |
|
|
|
|
_find->changeStyleSheet(tr("background-color: #F77", "text not found")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void rfind(const QString& txt=QString()) { |
|
|
|
@ -638,9 +672,9 @@ class Browser: public QMainWindow, protected Ui::Browser { |
|
|
|
|
(_find->text(), |
|
|
|
|
QWebPage::FindWrapsAroundDocument |
|
|
|
|
|QWebPage::FindBackward)) |
|
|
|
|
_find->setStyleSheet(tr("background-color: #ADA", "text found")); |
|
|
|
|
_find->changeStyleSheet(tr("background-color: #ADA", "text found")); |
|
|
|
|
else |
|
|
|
|
_find->setStyleSheet(tr("background-color: #F77", "text not found")); |
|
|
|
|
_find->changeStyleSheet(tr("background-color: #F77", "text not found")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void on_actionUnFind_triggered() { |
|
|
|
@ -690,7 +724,10 @@ class Browser: public QMainWindow, protected Ui::Browser { |
|
|
|
|
LOG<<url.toString(); |
|
|
|
|
if (sender()!=_tabs->currentWidget()) return; |
|
|
|
|
LOG<<"signal on current tab"; |
|
|
|
|
if (_url) _url->setEditText(url.toString()); |
|
|
|
|
if (qobject_cast<QComboBox*>(_url)) |
|
|
|
|
qobject_cast<QComboBox*>(_url)->setEditText(url.toString()); |
|
|
|
|
else |
|
|
|
|
qobject_cast<QLineEdit*>(_url)->setText(url.toString()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void linkClicked(const QUrl& url) { |
|
|
|
@ -1201,15 +1238,23 @@ class Browser: public QMainWindow, protected Ui::Browser { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void badUrl() { |
|
|
|
|
if (_url && _url->lineEdit()) |
|
|
|
|
dynamic_cast<ButtonLineEdit*>(_url->lineEdit()) |
|
|
|
|
if (qobject_cast<QComboBox*>(_url)) |
|
|
|
|
dynamic_cast<ButtonLineEdit*> |
|
|
|
|
(qobject_cast<QComboBox*>(_url)->lineEdit()) |
|
|
|
|
->changeStyleSheet(tr("background-color: #F77", "invalid url")); |
|
|
|
|
else |
|
|
|
|
qobject_cast<QLineEdit*>(_url) |
|
|
|
|
->setStyleSheet(tr("background-color: #F77", "invalid url")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void goodUrl() { |
|
|
|
|
if (_url && _url->lineEdit()) |
|
|
|
|
dynamic_cast<ButtonLineEdit*>(_url->lineEdit()) |
|
|
|
|
if (qobject_cast<QComboBox*>(_url)) |
|
|
|
|
dynamic_cast<ButtonLineEdit*> |
|
|
|
|
(qobject_cast<QComboBox*>(_url)->lineEdit()) |
|
|
|
|
->changeStyleSheet(tr("background-color: white", "valid url")); |
|
|
|
|
else |
|
|
|
|
qobject_cast<QLineEdit*>(_url) |
|
|
|
|
->setStyleSheet(tr("background-color: white", "valid url")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void downloadError(QString error) { |
|
|
|
@ -1246,8 +1291,9 @@ class Browser: public QMainWindow, protected Ui::Browser { |
|
|
|
|
void saveWin() { |
|
|
|
|
LOG<<"Save Window State"; |
|
|
|
|
QStringList urls; |
|
|
|
|
for (int i(0); i<_url->count(); ++i) |
|
|
|
|
urls<<_url->itemText(i); |
|
|
|
|
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) |
|
|
|
@ -1262,7 +1308,8 @@ class Browser: public QMainWindow, protected Ui::Browser { |
|
|
|
|
QStringList urls(_settings()->value("Window/Urls").toStringList()); |
|
|
|
|
urls.sort(); |
|
|
|
|
urls.removeDuplicates(); |
|
|
|
|
_url->addItems(urls); |
|
|
|
|
if (qobject_cast<QComboBox*>(_url)) |
|
|
|
|
qobject_cast<QComboBox*>(_url)->addItems(urls); |
|
|
|
|
QStringList tabs(_settings()->value("Window/Tabs").toStringList()); |
|
|
|
|
if (!noRrestoreTabs) |
|
|
|
|
for (QStringList::iterator it(tabs.begin()); it!=tabs.end(); ++it) |
|
|
|
@ -1276,7 +1323,7 @@ class Browser: public QMainWindow, protected Ui::Browser { |
|
|
|
|
|
|
|
|
|
void activateTab() { |
|
|
|
|
iconChanged(); |
|
|
|
|
QWebHistory* history(dynamic_cast<QWebView*>(_tabs->currentWidget()) |
|
|
|
|
QWebHistory* history(qobject_cast<QWebView*>(_tabs->currentWidget()) |
|
|
|
|
->history()); |
|
|
|
|
actionForward->setEnabled(history->canGoForward()); |
|
|
|
|
actionBack->setEnabled(history->canGoBack()); |
|
|
|
@ -1293,14 +1340,18 @@ class Browser: public QMainWindow, protected Ui::Browser { |
|
|
|
|
|
|
|
|
|
class ButtonLineEdit: public QLineEdit { |
|
|
|
|
public: |
|
|
|
|
ButtonLineEdit(QWidget* p): QLineEdit(p) {} |
|
|
|
|
ButtonLineEdit(QWidget* p=0): QLineEdit(p) { |
|
|
|
|
LOG; |
|
|
|
|
} |
|
|
|
|
QToolButton* add(QAction* a) { |
|
|
|
|
LOG; |
|
|
|
|
QToolButton* b(new QToolButton(this)); |
|
|
|
|
b->setDefaultAction(a); |
|
|
|
|
add(b); |
|
|
|
|
return b; |
|
|
|
|
} |
|
|
|
|
ButtonLineEdit& add(QToolButton* b) { |
|
|
|
|
LOG; |
|
|
|
|
b->setParent(this); |
|
|
|
|
b->setStyleSheet("QToolButton { border: none; padding: 0; }"); |
|
|
|
|
b->setCursor(Qt::ArrowCursor); |
|
|
|
@ -1309,25 +1360,26 @@ class Browser: public QMainWindow, protected Ui::Browser { |
|
|
|
|
return *this; |
|
|
|
|
} |
|
|
|
|
ButtonLineEdit& changeStyleSheet(QString s) { |
|
|
|
|
LOG; |
|
|
|
|
_style = s; |
|
|
|
|
resizeEvent(0); |
|
|
|
|
return *this; |
|
|
|
|
} |
|
|
|
|
protected: |
|
|
|
|
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)); |
|
|
|
|
} |
|
|
|
|
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)); |
|
|
|
|
} |
|
|
|
|
private: |
|
|
|
|
typedef QList<QToolButton*> Buttons; |
|
|
|
|
Buttons _buttons; |
|
|
|
@ -1336,8 +1388,8 @@ class Browser: public QMainWindow, protected Ui::Browser { |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
|
|
|
|
QComboBox* _url; |
|
|
|
|
QLineEdit* _find; |
|
|
|
|
QWidget* _url; |
|
|
|
|
ButtonLineEdit* _find; |
|
|
|
|
QSlider* _zoom; |
|
|
|
|
QProgressBar* _progress; |
|
|
|
|
QString _home; |
|
|
|
|