diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/adblock/adblockmanager.cpp | 30 | ||||
-rw-r--r-- | src/adblock/adblockmanager.h | 2 | ||||
-rw-r--r-- | src/bookmarks/bookmarksmanager.cpp | 50 | ||||
-rw-r--r-- | src/bookmarks/bookmarksmanager.h | 4 | ||||
-rw-r--r-- | src/mainview.cpp | 28 | ||||
-rw-r--r-- | src/mainview.h | 2 | ||||
-rw-r--r-- | src/mainwindow.cpp | 8 | ||||
-rw-r--r-- | src/networkaccessmanager.cpp | 17 | ||||
-rw-r--r-- | src/networkaccessmanager.h | 6 | ||||
-rw-r--r-- | src/settings/adblockwidget.cpp | 2 | ||||
-rw-r--r-- | src/urlbar/completionwidget.cpp | 23 | ||||
-rw-r--r-- | src/urlbar/completionwidget.h | 5 | ||||
-rw-r--r-- | src/urlbar/lineedit.cpp | 2 | ||||
-rw-r--r-- | src/urlbar/listitem.cpp | 3 | ||||
-rw-r--r-- | src/urlbar/listitem.h | 2 | ||||
-rw-r--r-- | src/urlbar/urlbar.cpp | 115 | ||||
-rw-r--r-- | src/urlbar/urlbar.h | 19 | ||||
-rw-r--r-- | src/urlbar/urlresolver.cpp | 51 | ||||
-rw-r--r-- | src/urlbar/urlresolver.h | 1 | ||||
-rw-r--r-- | src/webview.cpp | 88 | ||||
-rw-r--r-- | src/webview.h | 10 |
22 files changed, 312 insertions, 158 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5fa7cf4e..cad555b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ PROJECT( rekonq ) # Informations to update before to release this package. # rekonq info -SET(REKONQ_VERSION "0.4.57" ) +SET(REKONQ_VERSION "0.4.58" ) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/version.h ) diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index 71412d5d..0a139bdc 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -148,7 +148,7 @@ void AdBlockManager::loadRules(const QStringList &rules) } -QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) +QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *page) { if (!_isAdblockEnabled) return 0; @@ -179,6 +179,20 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) kDebug() << "****ADBLOCK: BLACK RULE Matched: ***********"; kDebug() << "Filter exp: " << filter.pattern(); kDebug() << "UrlString: " << urlString; + + QWebElement document = page->mainFrame()->documentElement(); + QWebElementCollection elements = document.findAll("*"); + foreach (QWebElement el, elements) + { + if(filter.match( el.attribute("src") ) ) + { + kDebug() << "MATCHES ATTRIBUTE!!!!!"; + el.setStyleProperty(QLatin1String("visibility"), QLatin1String("hidden")); + el.setStyleProperty(QLatin1String("width"), QLatin1String("0")); + el.setStyleProperty(QLatin1String("height"), QLatin1String("0")); + } + } + AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this); return reply; } @@ -199,17 +213,21 @@ void AdBlockManager::applyHidingRules(WebPage *page) if (!_isHideAdsEnabled) return; + + QWebElement document = page->mainFrame()->documentElement(); + // HIDE RULES foreach(const QString &filter, _hideList) { - QWebElement document = page->mainFrame()->documentElement(); QWebElementCollection elements = document.findAll(filter); - foreach (QWebElement element, elements) + foreach (QWebElement el, elements) { - kDebug() << "Hide element: " << element.localName(); - element.setStyleProperty(QLatin1String("visibility"), QLatin1String("hidden")); - element.removeFromDocument(); + if(el.isNull()) + continue; + kDebug() << "Hide element: " << el.localName(); + el.setStyleProperty(QLatin1String("visibility"), QLatin1String("hidden")); + el.removeFromDocument(); } } } diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h index c0bd2b70..9b1cc915 100644 --- a/src/adblock/adblockmanager.h +++ b/src/adblock/adblockmanager.h @@ -131,7 +131,7 @@ public: AdBlockManager(QObject *parent = 0); ~AdBlockManager(); - QNetworkReply *block(const QNetworkRequest &request); + QNetworkReply *block(const QNetworkRequest &request, WebPage *page); void applyHidingRules(WebPage *page); void addSubscription(const QString &title, const QString &location); diff --git a/src/bookmarks/bookmarksmanager.cpp b/src/bookmarks/bookmarksmanager.cpp index 89e39ef8..9c3201e6 100644 --- a/src/bookmarks/bookmarksmanager.cpp +++ b/src/bookmarks/bookmarksmanager.cpp @@ -294,7 +294,7 @@ KAction *BookmarkProvider::fillBookmarkBar(const KBookmark &bookmark) } else { - m_completion->addItem(bookmark.url().path()); + m_completion->addItem(bookmark.url().url()); return new KBookmarkAction(bookmark, m_owner, this); } } @@ -309,3 +309,51 @@ KCompletion *BookmarkProvider::completionObject() const { return m_completion; } + + + + + +QString BookmarkProvider::titleForBookmarkUrl(QString url) +{ + QString title = ""; + KBookmarkGroup bookGroup = Application::bookmarkProvider()->rootGroup(); + if (bookGroup.isNull()) + { + return title; + } + + KBookmark bookmark = bookGroup.first(); + while (!bookmark.isNull() && title.isEmpty()) + { + title = titleForBookmarkUrl(bookmark, url); + bookmark = bookGroup.next(bookmark); + } + + return title; +} + + +QString BookmarkProvider::titleForBookmarkUrl(const KBookmark &bookmark, QString url) +{ + QString title = ""; + if (bookmark.isGroup()) + { + KBookmarkGroup group = bookmark.toGroup(); + KBookmark bm = group.first(); + while (!bm.isNull() && title.isEmpty()) + { + title = titleForBookmarkUrl(bm, url); // it is .bookfolder + bm = group.next(bm); + } + } + else if(!bookmark.isSeparator() && bookmark.url()==url) + { + title = bookmark.fullText(); + } + + return title; +} + + + diff --git a/src/bookmarks/bookmarksmanager.h b/src/bookmarks/bookmarksmanager.h index 18ff3ef0..ace06e95 100644 --- a/src/bookmarks/bookmarksmanager.h +++ b/src/bookmarks/bookmarksmanager.h @@ -219,6 +219,8 @@ public: */ KCompletion *completionObject() const; + QString titleForBookmarkUrl(QString url); + signals: /** * @short This signal is emitted when an url has to be loaded @@ -245,8 +247,10 @@ public slots: */ void slotBookmarksChanged(const QString &group, const QString &caller); + private: KAction *fillBookmarkBar(const KBookmark &bookmark); + QString titleForBookmarkUrl(const KBookmark &bookmark, QString url); KBookmarkManager *m_manager; BookmarkOwner *m_owner; diff --git a/src/mainview.cpp b/src/mainview.cpp index 6643becb..a00325fb 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -275,41 +275,31 @@ void MainView::currentChanged(int index) m_currentTabIndex = index; if (oldTab) - { - // disconnecting webview from urlbar - disconnect(oldTab->view(), SIGNAL(loadProgress(int)), urlBar(), SLOT(updateProgress(int))); - disconnect(oldTab->view(), SIGNAL(loadFinished(bool)), urlBar(), SLOT(loadFinished(bool))); - disconnect(oldTab->view(), SIGNAL(urlChanged(const QUrl &)), urlBar(), SLOT(setUrl(const QUrl &))); - + { // disconnecting webpage from mainview disconnect(oldTab->page(), SIGNAL(statusBarMessage(const QString&)), this, SIGNAL(showStatusBarMessage(const QString&))); disconnect(oldTab->page(), SIGNAL(linkHovered(const QString&, const QString&, const QString&)), this, SIGNAL(linkHovered(const QString&))); } - - // connecting webview with urlbar - connect(tab->view(), SIGNAL(loadProgress(int)), urlBar(), SLOT(updateProgress(int))); - connect(tab->view(), SIGNAL(loadFinished(bool)), urlBar(), SLOT(loadFinished(bool))); - connect(tab->view(), SIGNAL(urlChanged(const QUrl &)), urlBar(), SLOT(setUrl(const QUrl &))); connect(tab->page(), SIGNAL(statusBarMessage(const QString&)), this, SIGNAL(showStatusBarMessage(const QString&))); connect(tab->page(), SIGNAL(linkHovered(const QString&, const QString&, const QString&)), this, SIGNAL(linkHovered(const QString&))); - emit setCurrentTitle(tab->view()->title()); - urlBar()->setUrl(tab->view()->url()); - urlBar()->setProgress(tab->progress()); - + emit currentTitle(tab->view()->title()); + urlBar()->setCurrentTab(tab); + // clean up "status bar" emit showStatusBarMessage( QString() ); // notify UI to eventually switch stop/reload button - if(urlBar()->isLoading()) - emit browserTabLoading(true); - else + int progr = tab->progress(); + if(progr == 0) emit browserTabLoading(false); + else + emit browserTabLoading(true); // update zoom slider if(!Application::instance()->mainWindowList().isEmpty()) @@ -613,7 +603,7 @@ void MainView::webViewTitleChanged(const QString &title) } if (currentIndex() == index) { - emit setCurrentTitle(tabTitle); + emit currentTitle(tabTitle); } Application::historyManager()->updateHistoryEntry(view->url(), tabTitle); } diff --git a/src/mainview.h b/src/mainview.h index 061ad1aa..fc10c2d9 100644 --- a/src/mainview.h +++ b/src/mainview.h @@ -105,7 +105,7 @@ signals: void lastTabClosed(); // current tab signals - void setCurrentTitle(const QString &url); + void currentTitle(const QString &url); void showStatusBarMessage(const QString &message, Rekonq::Notify status = Rekonq::Info); void linkHovered(const QString &link); void browserTabLoading(bool); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 6efd58ed..6701ea2e 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -215,7 +215,7 @@ void MainWindow::postLaunch() connect(m_view, SIGNAL(linkHovered(const QString&)), this, SLOT(notifyMessage(const QString&))); // --------- connect signals and slots - connect(m_view, SIGNAL(setCurrentTitle(const QString &)), this, SLOT(updateWindowTitle(const QString &))); + connect(m_view, SIGNAL(currentTitle(const QString &)), this, SLOT(updateWindowTitle(const QString &))); connect(m_view, SIGNAL(printRequested(QWebFrame *)), this, SLOT(printRequested(QWebFrame *))); // (shift +) ctrl + tab switching @@ -751,7 +751,7 @@ void MainWindow::privateBrowsing(bool enable) if (button == KMessageBox::Continue) { settings->setAttribute(QWebSettings::PrivateBrowsingEnabled, true); - m_view->urlBar()->setBackgroundColor(Qt::lightGray); // palette().color(QPalette::Active, QPalette::Background)); + m_view->urlBar()->setPrivateMode(true); } else { @@ -761,8 +761,8 @@ void MainWindow::privateBrowsing(bool enable) else { settings->setAttribute(QWebSettings::PrivateBrowsingEnabled, false); - m_view->urlBar()->setBackgroundColor(palette().color(QPalette::Active, QPalette::Base)); - + m_view->urlBar()->setPrivateMode(false); + m_lastSearch.clear(); m_view->clear(); m_view->reloadAllTabs(); diff --git a/src/networkaccessmanager.cpp b/src/networkaccessmanager.cpp index 77597cef..99337206 100644 --- a/src/networkaccessmanager.cpp +++ b/src/networkaccessmanager.cpp @@ -32,10 +32,15 @@ // Local Includes #include "application.h" #include "adblockmanager.h" +#include "webpage.h" + +// KDE Includes #include <KDebug> + NetworkAccessManager::NetworkAccessManager(QObject *parent) : AccessManager(parent) + , _parentPage( qobject_cast<WebPage *>(parent) ) { } @@ -48,16 +53,16 @@ QNetworkReply *NetworkAccessManager::createRequest(Operation op, const QNetworkR { case QNetworkAccessManager::HeadOperation: kDebug() << "HEAD OPERATION"; - if(outgoingData) - { - QByteArray outgoingDataByteArray = outgoingData->peek(1024 * 1024); - kDebug() << outgoingDataByteArray; - } +// if(outgoingData) +// { +// QByteArray outgoingDataByteArray = outgoingData->peek(1024 * 1024); +// kDebug() << outgoingDataByteArray; +// } break; case QNetworkAccessManager::GetOperation: kDebug() << "GET OPERATION"; - reply = Application::adblockManager()->block(req); + reply = Application::adblockManager()->block(req, _parentPage); if (reply) return reply; break; diff --git a/src/networkaccessmanager.h b/src/networkaccessmanager.h index 5e55c1e6..352f67d6 100644 --- a/src/networkaccessmanager.h +++ b/src/networkaccessmanager.h @@ -31,6 +31,7 @@ // Local Includes #include "rekonqprivate_export.h" +#include "webpage.h" // KDE Includes #include <kio/accessmanager.h> @@ -44,10 +45,13 @@ class REKONQ_TESTS_EXPORT NetworkAccessManager : public AccessManager Q_OBJECT public: - NetworkAccessManager(QObject *parent = 0); + NetworkAccessManager(QObject *parent); protected: virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &req, QIODevice *outgoingData = 0); + +private: + WebPage *_parentPage; }; #endif // NETWORKACCESSMANAGER_H diff --git a/src/settings/adblockwidget.cpp b/src/settings/adblockwidget.cpp index 39df2c36..2f431c1e 100644 --- a/src/settings/adblockwidget.cpp +++ b/src/settings/adblockwidget.cpp @@ -166,7 +166,7 @@ void AdBlockWidget::save() n = listWidget->count(); for(int i = 0; i < n; ++i) { - QListWidgetItem *item = listWidget->takeItem(i); + QListWidgetItem *item = listWidget->item(i); localRules << item->text(); } localGroup.writeEntry( "local-rules" , localRules ); diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index 42abcb73..3a54f890 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -72,7 +72,7 @@ void CompletionWidget::insertSearchList(const UrlSearchList &list) { UrlSearchItem item = list.at(i); ListItem *suggestion = new ListItem(item); - connect(suggestion, SIGNAL(itemClicked(ListItem *)), this, SLOT(itemChosen(ListItem *))); + connect(suggestion, SIGNAL(itemClicked(ListItem *, Qt::MouseButton)), this, SLOT(itemChosen(ListItem *, Qt::MouseButton))); suggestion->setObjectName( QString::number(i) ); layout()->addWidget( suggestion ); } @@ -82,7 +82,14 @@ void CompletionWidget::insertSearchList(const UrlSearchList &list) void CompletionWidget::sizeAndPosition() { // size - setFixedHeight(layout()->count() * 44 ); + int h = 34; + ListItem *widget; + for(int i = 0; i < layout()->count(); ++i) + { + widget = findChild<ListItem *>( QString::number(i) ); + h = qMax(widget->sizeHint().height(), h); + } + setFixedHeight(layout()->count() * (h + 10) ); setFixedWidth( _parent->width() ); // position @@ -206,9 +213,10 @@ bool CompletionWidget::eventFilter( QObject *o, QEvent *e ) } break; + case Qt::Key_Enter: case Qt::Key_Return: hide(); - emit chosenUrl(currentUrl().url()); + emit chosenUrl(currentUrl().url(), Rekonq::CurrentTab); ev->accept(); return true; break; @@ -235,8 +243,11 @@ void CompletionWidget::setVisible( bool visible ) } -void CompletionWidget::itemChosen(ListItem *item) +void CompletionWidget::itemChosen(ListItem *item, Qt::MouseButton button) { - emit chosenUrl(_list.at(layout()->indexOf(item)).url); + if(button == Qt::MidButton) + emit chosenUrl(_list.at(layout()->indexOf(item)).url, Rekonq::NewCurrentTab); + else + emit chosenUrl(_list.at(layout()->indexOf(item)).url, Rekonq::CurrentTab); hide(); -}
\ No newline at end of file +} diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h index 7b474bd8..64d33189 100644 --- a/src/urlbar/completionwidget.h +++ b/src/urlbar/completionwidget.h @@ -29,6 +29,7 @@ // Local Includes +#include "application.h" #include "urlresolver.h" #include "listitem.h" @@ -60,10 +61,10 @@ public: KUrl currentUrl(); private slots: - void itemChosen(ListItem *item); + void itemChosen(ListItem *item, Qt::MouseButton = Qt::LeftButton); signals: - void chosenUrl(const QString&); + void chosenUrl(const QString&, Rekonq::OpenType); private: void sizeAndPosition(); diff --git a/src/urlbar/lineedit.cpp b/src/urlbar/lineedit.cpp index f3c93e8e..ac92b858 100644 --- a/src/urlbar/lineedit.cpp +++ b/src/urlbar/lineedit.cpp @@ -42,7 +42,7 @@ LineEdit::LineEdit(QWidget* parent) setMinimumWidth(200); setFocusPolicy(Qt::WheelFocus); setHandleSignals(true); - setClearButtonShown(true); + setClearButtonShown(false); } diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index 92951cb7..d9837c7e 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -44,6 +44,7 @@ #include <QPixmap> #include <QStylePainter> #include <QFile> +#include <QMouseEvent> ListItem::ListItem(const UrlSearchItem &item, QWidget *parent) : QWidget(parent), @@ -167,7 +168,7 @@ void ListItem::leaveEvent(QEvent *e) void ListItem::mousePressEvent(QMouseEvent *e) { - emit itemClicked(this); + emit itemClicked(this, e->button()); QWidget::mousePressEvent(e); } diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h index 6aa3f1e9..ac476d4b 100644 --- a/src/urlbar/listitem.h +++ b/src/urlbar/listitem.h @@ -44,7 +44,7 @@ public: void deactivate(); signals: - void itemClicked(ListItem *item); + void itemClicked(ListItem *item, Qt::MouseButton); protected: virtual void paintEvent(QPaintEvent *event); diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 54a0a02d..a04d6534 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -50,14 +50,13 @@ #include <QTimer> #include <QVBoxLayout> -QColor UrlBar::s_defaultBaseColor; - UrlBar::UrlBar(QWidget *parent) : KComboBox(true, parent) , m_lineEdit(new LineEdit) - , m_progress(0) , m_box(new CompletionWidget(this)) + , _tab(0) + , _privateMode(false) { //cosmetic setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); @@ -72,11 +71,6 @@ UrlBar::UrlBar(QWidget *parent) p.setColor(QPalette::Base, Qt::transparent); m_lineEdit->setPalette(p); - if (!s_defaultBaseColor.isValid()) - { - s_defaultBaseColor = palette().color(QPalette::Base); - } - setLineEdit(m_lineEdit); // clear the URL bar @@ -85,7 +79,7 @@ UrlBar::UrlBar(QWidget *parent) connect(this, SIGNAL(returnPressed(const QString&)), SLOT(activated(const QString&))); installEventFilter(m_box); - connect(m_box, SIGNAL(chosenUrl(const QString&)), SLOT(activated(const QString&))); + connect(m_box, SIGNAL(chosenUrl(const QString&, Rekonq::OpenType)), SLOT(activated(const QString&, Rekonq::OpenType))); } @@ -123,13 +117,6 @@ void UrlBar::setUrl(const QUrl& url) } -void UrlBar::setProgress(int progress) -{ - m_progress = progress; - update(); -} - - void UrlBar::updateUrl() { // Don't change my typed url... @@ -171,7 +158,7 @@ void UrlBar::updateUrl() } -void UrlBar::activated(const QString& urlString) +void UrlBar::activated(const QString& urlString, Rekonq::OpenType type) { disconnect(this, SIGNAL(editTextChanged(const QString &)), this, SLOT(suggestUrls(const QString &))); @@ -180,30 +167,25 @@ void UrlBar::activated(const QString& urlString) clearFocus(); setUrl(urlString); - Application::instance()->loadUrl(m_currentUrl); -} - - -void UrlBar::loadFinished(bool) -{ - // reset progress bar after small delay - m_progress = 0; - QTimer::singleShot(200, this, SLOT(update())); -} - - -void UrlBar::updateProgress(int progress) -{ - m_progress = progress; - update(); + Application::instance()->loadUrl(m_currentUrl, type); } void UrlBar::paintEvent(QPaintEvent *event) { + QColor backgroundColor; + if( _privateMode ) + { + backgroundColor = QColor(192, 192, 192); // gray + } + else + { + backgroundColor = Application::palette().color(QPalette::Base); + } + // set background color of UrlBar QPalette p = palette(); - p.setColor(QPalette::Base, s_defaultBaseColor); + p.setColor(QPalette::Base, backgroundColor); setPalette(p); KComboBox::paintEvent(event); @@ -221,11 +203,20 @@ void UrlBar::paintEvent(QPaintEvent *event) { loadingColor = QColor(116, 192, 250); } - painter.setBrush(generateGradient(loadingColor, height())); + int progr = _tab->progress(); + + backgroundColor.setAlpha(0); + backgroundColor.setAlpha(200); + QLinearGradient gradient(0, 0, width(), height() ); + gradient.setColorAt(0, loadingColor); + gradient.setColorAt(((double)progr)/100, backgroundColor); + + painter.setBrush( gradient ); painter.setPen(Qt::transparent); + QRect backgroundRect = m_lineEdit->frameGeometry(); - int mid = backgroundRect.width() * m_progress / 100; + int mid = backgroundRect.width() * progr / 100; QRect progressRect(backgroundRect.x(), backgroundRect.y(), mid, backgroundRect.height()); painter.drawRect(progressRect); painter.end(); @@ -239,41 +230,8 @@ QSize UrlBar::sizeHint() const } -QLinearGradient UrlBar::generateGradient(const QColor &color, int height) -{ - QColor base = s_defaultBaseColor; - base.setAlpha(0); - QColor barColor = color; - barColor.setAlpha(200); - QLinearGradient gradient(0, 0, 0, height); - gradient.setColorAt(0, base); - gradient.setColorAt(0.25, barColor.lighter(120)); - gradient.setColorAt(0.5, barColor); - gradient.setColorAt(0.75, barColor.lighter(120)); - gradient.setColorAt(1, base); - return gradient; -} - - -void UrlBar::setBackgroundColor(QColor c) -{ - s_defaultBaseColor = c; - update(); -} - - -bool UrlBar::isLoading() -{ - if(m_progress == 0) - { - return false; - } - return true; -} - void UrlBar::keyPressEvent(QKeyEvent *event) { - // this handles the Modifiers + Return key combinations QString currentText = m_lineEdit->text().trimmed(); if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) @@ -338,3 +296,22 @@ void UrlBar::focusInEvent(QFocusEvent *event) KComboBox::focusInEvent(event); } + + +void UrlBar::setCurrentTab(WebTab *tab) +{ + if(_tab) + disconnect(_tab->view(), SIGNAL(urlChanged(const QUrl &)), this, SLOT(setUrl(const QUrl &))); + _tab = tab; + connect(_tab->view(), SIGNAL(urlChanged(const QUrl &)), this, SLOT(setUrl(const QUrl &))); + + // update it now (the first time) + setUrl( _tab->url() ); + update(); +} + + +void UrlBar::setPrivateMode(bool on) +{ + _privateMode = on; +} diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index ef53d63a..991b9038 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -34,6 +34,7 @@ // Local Includes #include "lineedit.h" #include "completionwidget.h" +#include "webtab.h" // KDE Includes #include <KUrl> @@ -59,18 +60,16 @@ public: void selectAll() const; KUrl url() const; QSize sizeHint() const; - void setBackgroundColor(QColor); - bool isLoading(); - void setProgress(int progress); + void setCurrentTab(WebTab *); + void setPrivateMode(bool on); + public slots: void setUrl(const QUrl &url); - void updateProgress(int progress); void updateUrl(); private slots: - void activated(const QString& url); - void loadFinished(bool); + void activated(const QString& url, Rekonq::OpenType = Rekonq::CurrentTab); void suggestUrls(const QString &editedText); protected: @@ -79,17 +78,13 @@ protected: virtual void focusInEvent(QFocusEvent *event); private: - static QLinearGradient generateGradient(const QColor &color, int height); - - static QColor s_defaultBaseColor; - LineEdit *m_lineEdit; KUrl m_currentUrl; - int m_progress; CompletionWidget *m_box; - KUrl m_suggestedUrl; + WebTab *_tab; + bool _privateMode; }; #endif diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index b2bf50af..cb61ad95 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -70,8 +70,17 @@ UrlSearchList UrlResolver::orderedSearchItems() UrlSearchList list; - list << qurlFromUserInputResolution(); - list << webSearchesResolution(); + if(isHttp()) + { + list << qurlFromUserInputResolution(); + list << webSearchesResolution(); + } + else + { + list << webSearchesResolution(); + list << qurlFromUserInputResolution(); + } + int firstResults = list.count(); int checkPoint = 9 - firstResults; @@ -93,6 +102,21 @@ UrlSearchList UrlResolver::orderedSearchItems() } +bool UrlResolver::isHttp() +{ + QString r = "[\\d\\w-.]+\\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|"\ + "c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|"\ + "h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|"\ + "m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|"\ + "s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|"\ + "y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|"\ + "pro)"; + + return (QRegExp(r, Qt::CaseInsensitive).indexIn(_urlString) != -1) + || _urlString.startsWith("http:") + || _urlString.startsWith("https:"); +} + ////////////////////////////////////////////////////////////////////////// // PRIVATE ENGINES @@ -108,10 +132,12 @@ UrlSearchList UrlResolver::qurlFromUserInputResolution() { QByteArray ba = urlFromUserInput.toEncoded(); if(!ba.isEmpty()) - { - QString str(ba); - UrlSearchItem it(str); - list << it; + { + QString gUrl = QString(ba); + QString gTitle = i18n("Browse"); + UrlSearchItem gItem(gUrl, gTitle, QString("") ); + list << gItem; + } } @@ -125,7 +151,7 @@ UrlSearchList UrlResolver::webSearchesResolution() UrlSearchList list; QString url1 = _urlString; - if(KUrl(url1).isRelative() && !url1.contains('.')) + if(KUrl(url1).isRelative()) { // KUriFilter has the worst performance possible here and let this trick unusable QString gUrl = QString("http://www.google.com/search?q=%1&ie=UTF-8&oe=UTF-8").arg(url1); @@ -133,10 +159,10 @@ UrlSearchList UrlResolver::webSearchesResolution() UrlSearchItem gItem(gUrl, gTitle, QString("http://www.google.com") ); list << gItem; - QString wUrl = QString("http://en.wikipedia.org/wiki/Special:Search?search=%1&go=Go").arg(url1); - QString wTitle = i18n("Search Wikipedia for ") + url1; - UrlSearchItem wItem(wUrl, wTitle, QString("http://wikipedia.org") ); - list << wItem; +// QString wUrl = QString("http://en.wikipedia.org/wiki/Special:Search?search=%1&go=Go").arg(url1); +// QString wTitle = i18n("Search Wikipedia for ") + url1; +// UrlSearchItem wItem(wUrl, wTitle, QString("http://wikipedia.org") ); +// list << wItem; } return list; @@ -169,9 +195,10 @@ UrlSearchList UrlResolver::bookmarksResolution() QStringList bookmarkResults = bookmarkCompletion->substringCompletion(_urlString); Q_FOREACH(const QString &s, bookmarkResults) { - UrlSearchItem it( s, QString(), QString("rating") ); + UrlSearchItem it( s, Application::bookmarkProvider()->titleForBookmarkUrl(s), QString("rating") ); list << it; } + return list; } diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h index 0a880150..4231aaab 100644 --- a/src/urlbar/urlresolver.h +++ b/src/urlbar/urlresolver.h @@ -67,6 +67,7 @@ private: UrlSearchList historyResolution(); UrlSearchList qurlFromUserInputResolution(); UrlSearchList bookmarksResolution(); + bool isHttp(); }; #endif // URL_RESOLVER_H diff --git a/src/webview.cpp b/src/webview.cpp index 80d44d10..294b7c85 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -62,7 +62,10 @@ WebView::WebView(QWidget* parent) : KWebView(parent, false) - , m_mousePos( QPoint(0,0) ) + , _mousePos( QPoint(0,0) ) + , _scrollTimer( new QTimer(this) ) + , _VScrollSpeed(0) + , _HScrollSpeed(0) { WebPage *page = new WebPage(this); setPage(page); @@ -80,6 +83,10 @@ WebView::WebView(QWidget* parent) // loadUrl signal connect(this, SIGNAL(loadUrl(const KUrl &, const Rekonq::OpenType &)), Application::instance(), SLOT(loadUrl(const KUrl &, const Rekonq::OpenType &))); + + // scrolling timer + connect(_scrollTimer, SIGNAL(timeout()), this, SLOT(scrollFrameChanged())); + _scrollTimer->setInterval(50); } @@ -330,7 +337,7 @@ void WebView::mousePressEvent(QMouseEvent *event) void WebView::mouseMoveEvent(QMouseEvent *event) { - m_mousePos = event->pos(); + _mousePos = event->pos(); if (Application::instance()->mainWindow()->isFullScreen()) { if (event->pos().y()>=0 && event->pos().y()<=4) @@ -348,7 +355,7 @@ void WebView::mouseMoveEvent(QMouseEvent *event) QPoint WebView::mousePos() { - return m_mousePos; + return _mousePos; } @@ -404,16 +411,61 @@ void WebView::openLinkInNewTab() void WebView::keyPressEvent(QKeyEvent *event) { - if ((event->modifiers() == Qt::ControlModifier) && (event->key() == Qt::Key_C)) + if ( event->modifiers() == Qt::ControlModifier ) { - triggerPageAction(KWebPage::Copy); - return; - } + if ( event->key() == Qt::Key_C ) + { + triggerPageAction(KWebPage::Copy); + return; + } - if ((event->modifiers() == Qt::ControlModifier) && (event->key() == Qt::Key_A)) + if ( event->key() == Qt::Key_A ) + { + triggerPageAction(KWebPage::SelectAll); + return; + } + } + + if ( event->modifiers() == Qt::ShiftModifier ) { - triggerPageAction(KWebPage::SelectAll); - return; + kDebug() << "scrolling.."; + if( event->key() == Qt::Key_Up ) + { + _VScrollSpeed -= 1; + _scrollTimer->start(); + return; + } + + if( event->key() == Qt::Key_Down ) + { + _VScrollSpeed += 1; + _scrollTimer->start(); + return; + } + + if( event->key() == Qt::Key_Right ) + { + _HScrollSpeed += 1; + _scrollTimer->start(); + return; + } + + if( event->key() == Qt::Key_Left ) + { + _HScrollSpeed -= 1; + _scrollTimer->start(); + return; + } + + if(_scrollTimer->isActive()) + { + _scrollTimer->stop(); + } + else + { + if(_VScrollSpeed || _HScrollSpeed) + _scrollTimer->start(); + } } KWebView::keyPressEvent(event); @@ -433,3 +485,19 @@ void WebView::loadUrlInNewTab(const KUrl &url) { emit loadUrl(url, Rekonq::SettingOpenTab); } + + +void WebView::scrollFrameChanged() +{ + // do the scrolling + page()->currentFrame()->scroll( _HScrollSpeed, _VScrollSpeed ); + + // check if we reached the end + int y = page()->currentFrame()->scrollPosition().y(); + if (y == 0 || y == page()->currentFrame()->scrollBarMaximum(Qt::Vertical)) + _VScrollSpeed = 0; + + int x = page()->currentFrame()->scrollPosition().x(); + if (x == 0 || x == page()->currentFrame()->scrollBarMaximum(Qt::Horizontal)) + _HScrollSpeed = 0; +} diff --git a/src/webview.h b/src/webview.h index b0700e8f..59105267 100644 --- a/src/webview.h +++ b/src/webview.h @@ -30,8 +30,6 @@ // Local Includes #include "rekonqprivate_export.h" - -// Local Includes #include "application.h" // KDE Includes @@ -70,11 +68,17 @@ private slots: void viewImage(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers); void inspect(); + void scrollFrameChanged(); + signals: void loadUrl(const KUrl &, const Rekonq::OpenType &); private: - QPoint m_mousePos; + QPoint _mousePos; + + QTimer *_scrollTimer; + int _VScrollSpeed; + int _HScrollSpeed; }; #endif |