diff options
-rw-r--r-- | src/urlbar/completionwidget.cpp | 19 | ||||
-rw-r--r-- | src/urlbar/completionwidget.h | 1 | ||||
-rw-r--r-- | src/urlbar/listitem.cpp | 86 | ||||
-rw-r--r-- | src/urlbar/listitem.h | 142 | ||||
-rw-r--r-- | src/urlbar/urlbar.cpp | 22 | ||||
-rw-r--r-- | src/urlbar/urlbar.h | 3 | ||||
-rw-r--r-- | src/urlbar/urlresolver.cpp | 56 | ||||
-rw-r--r-- | src/urlbar/urlresolver.h | 7 |
8 files changed, 194 insertions, 142 deletions
diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index 42824af9..83e99f9d 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -45,8 +45,8 @@ #include <QKeyEvent> -CompletionWidget::CompletionWidget( QWidget *parent) - :QFrame( parent, Qt::ToolTip) +CompletionWidget::CompletionWidget(QWidget *parent) + : QFrame( parent, Qt::ToolTip) , _parent(parent) , _currentIndex(-1) { @@ -206,12 +206,12 @@ bool CompletionWidget::eventFilter( QObject *o, QEvent *e ) case Qt::Key_Enter: case Qt::Key_Return: - hide(); - if(_currentIndex >= 0) - emit chosenUrl(_list.at(_currentIndex).url, Rekonq::CurrentTab); - else - emit loadTypedUrl(); + + // need this to let ListItem magic work.. + ListItem *child = findChild<ListItem *>( QString::number(_currentIndex) ); + emit chosenUrl( child->url(), Rekonq::CurrentTab); ev->accept(); + hide(); return true; break; } @@ -233,6 +233,7 @@ void CompletionWidget::setVisible( bool visible ) Application::instance()->removeEventFilter(this); } + QFrame::setVisible(visible); } @@ -240,8 +241,8 @@ void CompletionWidget::setVisible( bool visible ) void CompletionWidget::itemChosen(ListItem *item, Qt::MouseButton button) { if(button == Qt::MidButton) - emit chosenUrl(_list.at(layout()->indexOf(item)).url, Rekonq::NewCurrentTab); + emit chosenUrl( item->url(), Rekonq::NewCurrentTab); else - emit chosenUrl(_list.at(layout()->indexOf(item)).url, Rekonq::CurrentTab); + emit chosenUrl( item->url(), Rekonq::CurrentTab); hide(); } diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h index 25b6f5eb..125e186a 100644 --- a/src/urlbar/completionwidget.h +++ b/src/urlbar/completionwidget.h @@ -60,7 +60,6 @@ private slots: signals: void chosenUrl(const KUrl &, Rekonq::OpenType); void nextItemSubChoice(); - void loadTypedUrl(); private: void sizeAndPosition(); diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index ef09d4f3..7d1d39b2 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -40,7 +40,6 @@ #include <KConfigGroup> #include <KIcon> - // Qt Includes #include <QHBoxLayout> #include <QVBoxLayout> @@ -147,8 +146,11 @@ void ListItem::nextItemSubChoice() } +// --------------------------------------------------------------- + + TypeIcon::TypeIcon(int type, QWidget *parent) -:QLabel(parent) + : QLabel(parent) { setMinimumWidth(40); QHBoxLayout *hLayout = new QHBoxLayout; @@ -173,9 +175,11 @@ QLabel *TypeIcon::getIcon(QString icon) } +// --------------------------------------------------------------- + -ItemIcon::ItemIcon(QString icon, QWidget *parent) -:QLabel(parent) +ItemIcon::ItemIcon(const QString &icon, QWidget *parent) + : QLabel(parent) { QPixmap pixmapIcon = KIcon(QWebSettings::iconForUrl(icon)).pixmap(16); if (pixmapIcon.isNull()) @@ -188,18 +192,16 @@ ItemIcon::ItemIcon(QString icon, QWidget *parent) } -ItemText::ItemText(QString text, QString underlined, QWidget *parent) -:QLabel(underlineText(text,underlined), parent) -{ - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); -} +// --------------------------------------------------------------- -QString ItemText::underlineText(QString text, QString textToUnderline) +ItemText::ItemText(const QString &text, const QString &textToPointOut, QWidget *parent) + : QLabel(parent) { QString t = text; - t = t.replace(QRegExp("("+textToUnderline+")", Qt::CaseInsensitive), "<u>\\1</u>"); - return t; + t = t.replace(QRegExp("(" + textToPointOut + ")", Qt::CaseInsensitive), "<b>\\1</b>"); + setText(t); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); } @@ -207,7 +209,7 @@ QString ItemText::underlineText(QString text, QString textToUnderline) PreviewListItem::PreviewListItem(const UrlSearchItem &item, const QString &text, QWidget *parent) -:ListItem(item, parent) + : ListItem(item, parent) { QLabel *previewLabelIcon = new QLabel; previewLabelIcon->setFixedSize(45,33); @@ -225,13 +227,16 @@ PreviewListItem::PreviewListItem(const UrlSearchItem &item, const QString &text, } -ItemPreview::ItemPreview(QString url, int width, int height, QWidget *parent) -:QLabel(parent) +// --------------------------------------------------------------- + + +ItemPreview::ItemPreview(const QString &url, int width, int height, QWidget *parent) + : QLabel(parent) { setFixedSize(width, height); setFrameStyle(QFrame::StyledPanel | QFrame::Raised); - QString path = KStandardDirs::locateLocal("cache", QString("thumbs/") + guessNameFromUrl(url) + ".png", true); + QString path = KStandardDirs::locateLocal("cache", QString("thumbs/") + guessNameFromUrl( QUrl(url) ) + ".png", true); if(QFile::exists(path)) { QPixmap preview; @@ -260,12 +265,16 @@ QString ItemPreview::guessNameFromUrl(QUrl url) return name; } -//-------------------------------------------------------------------------------------------- + +// --------------------------------------------------------------- + + QString SearchListItem::m_currentEngine = ""; + SearchListItem::SearchListItem(const UrlSearchItem &item, const QString &text, QWidget *parent) - :ListItem(item, parent) - ,m_text(text) + : ListItem(item, parent) + , m_text(text) { if (m_currentEngine == "") m_currentEngine = EngineBar::defaultEngine(); @@ -273,6 +282,9 @@ SearchListItem::SearchListItem(const UrlSearchItem &item, const QString &text, Q m_titleLabel = new ItemText(searchItemTitle(m_currentEngine, text), text); m_engineBar = new EngineBar(text, m_currentEngine, this); + // without this it will not work :) + m_url = m_engineBar->url(); + layout()->addWidget(m_iconLabel); layout()->addWidget(m_titleLabel); layout()->addWidget(new QLabel("Engines: ")); @@ -292,8 +304,9 @@ QString SearchListItem::searchItemTitle(QString engine, QString text) void SearchListItem::changeSearchEngine(QString url, QString engine) { m_titleLabel->setText(searchItemTitle(engine,m_text)); - m_iconLabel->setPixmap(Application::icon(url).pixmap(16)); - m_url = KUrl(url); + m_iconLabel->setPixmap(Application::icon( KUrl(url) ).pixmap(16)); + QString url2 = url.replace("\\{@}",m_text); + m_url = KUrl(url2); m_currentEngine = engine; } @@ -304,9 +317,9 @@ void SearchListItem::nextItemSubChoice() } -EngineBar::EngineBar(QString text, QString selectedEngine, QWidget *parent) -:KToolBar(parent) -{ +EngineBar::EngineBar(const QString &text, const QString &selectedEngine, QWidget *parent) + : KToolBar(parent) +{ setIconSize(QSize(16,16)); setToolButtonStyle(Qt::ToolButtonIconOnly); @@ -322,7 +335,12 @@ EngineBar::EngineBar(QString text, QString selectedEngine, QWidget *parent) KService::Ptr service; service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(defaultEngine)); - m_engineGroup->addAction(newEngineAction(service, selectedEngine, text)); + m_engineGroup->addAction(newEngineAction(service, selectedEngine)); + + // set url; + QString url = service->property("Query").toString(); + url = url.replace("\\{@}",text); + m_url = KUrl(url); Q_FOREACH(const QString &engine, favoriteEngines) { @@ -331,7 +349,7 @@ EngineBar::EngineBar(QString text, QString selectedEngine, QWidget *parent) service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(engine)); if(service && service->desktopEntryName()!=defaultEngine) { - m_engineGroup->addAction(newEngineAction(service, selectedEngine, text)); + m_engineGroup->addAction(newEngineAction(service, selectedEngine)); } } } @@ -350,13 +368,14 @@ QString EngineBar::defaultEngine() } -KAction *EngineBar::newEngineAction(KService::Ptr service, QString selectedEngine, QString text) +KAction *EngineBar::newEngineAction(KService::Ptr service, QString selectedEngine) { - QString url = service->property("Query").toString(); - url = url.replace("\\{@}",text); - KAction *a = new KAction(Application::icon(url), service->name(), this); + KAction *a = new KAction(Application::icon(m_url), service->name(), this); a->setCheckable(true); if (service->name()==selectedEngine) a->setChecked(true); + + QString url = service->property("Query").toString(); + a->setData(QStringList() << url << service->name()); connect(a, SIGNAL(triggered(bool)), this, SLOT(changeSearchEngine())); @@ -394,11 +413,11 @@ void EngineBar::selectNextEngine() } -//-------------------------------------------------------------------------------------------- +// --------------------------------------------------------------- BrowseListItem::BrowseListItem(const UrlSearchItem &item, const QString &text, QWidget *parent) -:ListItem(item, parent) + : ListItem(item, parent) { QString url = text; layout()->addWidget(new ItemIcon(item.url.url())); @@ -407,7 +426,7 @@ BrowseListItem::BrowseListItem(const UrlSearchItem &item, const QString &text, Q } -//-------------------------------------------------------------------------------------------- +// --------------------------------------------------------------- ListItem *ListItemFactory::create(const UrlSearchItem &item, const QString &text, QWidget *parent) @@ -429,4 +448,3 @@ ListItem *ListItemFactory::create(const UrlSearchItem &item, const QString &text return newItem; } - diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h index 6a6c433f..e355160a 100644 --- a/src/urlbar/listitem.h +++ b/src/urlbar/listitem.h @@ -23,17 +23,19 @@ * * ============================================================ */ + #ifndef LISTITEM_H #define LISTITEM_H + +// Local Includes +#include "urlresolver.h" + // KDE Includes #include <KToolBar> #include <KAction> #include <KService> -// Local Includes -#include "urlresolver.h" - // Qt Includes #include <QWidget> #include <QLayout> @@ -77,128 +79,146 @@ protected: }; +// ------------------------------------------------------------------------- + + class TypeIcon : public QLabel { Q_OBJECT - public: - TypeIcon(int type, QWidget *parent = 0); - private: - QLabel *getIcon(QString icon); +public: + TypeIcon(int type, QWidget *parent = 0); + +private: + QLabel *getIcon(QString icon); }; +// ------------------------------------------------------------------------- + + class ItemIcon : public QLabel { Q_OBJECT - public: - ItemIcon(QString icon, QWidget *parent = 0); +public: + ItemIcon(const QString &icon, QWidget *parent = 0); }; +// ------------------------------------------------------------------------- + + class ItemText : public QLabel { Q_OBJECT - public: - ItemText(QString text, QString underlined, QWidget *parent = 0); - QString underlineText(QString text, QString textToUnderline); +public: + ItemText(const QString &text, const QString &textToPointOut, QWidget *parent = 0); }; -//------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------- + class EngineBar : public KToolBar { Q_OBJECT - public: - EngineBar(QString text, QString selectedEngine, QWidget *parent = 0); - static QString defaultEngine(); - void selectNextEngine(); - - signals: - void searchEngineChanged(QString url, QString engine); - - private slots: - void changeSearchEngine(); +public: + EngineBar(const QString &text, const QString &selectedEngine, QWidget *parent = 0); + static QString defaultEngine(); + void selectNextEngine(); + KUrl url() { return m_url; }; - private: - KAction *newEngineAction(KService::Ptr service, QString selectedEngine, QString text); +signals: + void searchEngineChanged(QString url, QString engine); + +private slots: + void changeSearchEngine(); + +private: + KAction *newEngineAction(KService::Ptr service, QString selectedEngine); - QActionGroup *m_engineGroup; + QActionGroup *m_engineGroup; + KUrl m_url; }; +// ------------------------------------------------------------------------- + + class SearchListItem : public ListItem { Q_OBJECT - public: - SearchListItem(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); - - public slots: - virtual void nextItemSubChoice(); - - protected: - - - private slots: - void changeSearchEngine(QString url, QString engine); - - private: - QString searchItemTitle(QString engine, QString text); - ItemText* m_titleLabel; - ItemIcon* m_iconLabel; - EngineBar* m_engineBar; - QString m_text; - static QString m_currentEngine; +public: + SearchListItem(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); + +public slots: + virtual void nextItemSubChoice(); + +private slots: + void changeSearchEngine(QString url, QString engine); + +private: + QString searchItemTitle(QString engine, QString text); + ItemText* m_titleLabel; + ItemIcon* m_iconLabel; + EngineBar* m_engineBar; + QString m_text; + + static QString m_currentEngine; }; -//------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------- + class PreviewListItem : public ListItem { Q_OBJECT - public: - PreviewListItem(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); +public: + PreviewListItem(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); }; +// ------------------------------------------------------------------------- + + class ItemPreview : public QLabel { Q_OBJECT - public: - ItemPreview(QString url,int width, int height, QWidget *parent = 0); +public: + ItemPreview(const QString &url, int width, int height, QWidget *parent = 0); - private: - static QString guessNameFromUrl(QUrl url); +private: + static QString guessNameFromUrl(QUrl url); }; -//------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------- + class BrowseListItem : public ListItem { Q_OBJECT - public: - BrowseListItem(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); - protected: - +public: + BrowseListItem(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); }; + //------------------------------------------------------------------------------------------------- + class ListItemFactory { - public: - static ListItem *create(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); - +public: + static ListItem *create(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); }; -#endif
\ No newline at end of file +#endif diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 4abd4622..4e7310bf 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -72,7 +72,9 @@ UrlBar::UrlBar(QWidget *parent) // suggestions installEventFilter(_box); connect(_box, SIGNAL(chosenUrl(const KUrl &, Rekonq::OpenType)), SLOT(activated(const KUrl &, Rekonq::OpenType))); - connect(_box, SIGNAL(loadTypedUrl()), this, SLOT(activated())); + + // load typed urls + connect(this, SIGNAL(returnPressed(const QString &)), this, SLOT(loadTyped(const QString &))); } @@ -104,16 +106,8 @@ void UrlBar::activated(const KUrl& url, Rekonq::OpenType type) disconnect(this, SIGNAL(textChanged(const QString &)), this, SLOT(suggestUrls(const QString &))); clearFocus(); - KUrl loadingUrl; - - if(url.isEmpty()) - loadingUrl = KUrl(text()); - else - loadingUrl = url; - - setUrl(loadingUrl); - - Application::instance()->loadUrl(loadingUrl, type); + setUrl(url); + Application::instance()->loadUrl(url, type); } @@ -278,3 +272,9 @@ void UrlBar::loadFinished() update(); } + + +void UrlBar::loadTyped(const QString &text) +{ + activated(KUrl(text)); +} diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 684a205e..804188f7 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -60,11 +60,12 @@ public: void setPrivateMode(bool on); private slots: - void activated(const KUrl& url = KUrl(), Rekonq::OpenType = Rekonq::CurrentTab); + void activated(const KUrl& url, Rekonq::OpenType = Rekonq::CurrentTab); void suggestUrls(const QString &editedText); void setQUrl(const QUrl &url); void loadFinished(); + void loadTyped(const QString &); protected: virtual void paintEvent(QPaintEvent *event); diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index fd4cdfcb..5b4b1625 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -45,8 +45,10 @@ #include <QByteArray> #include <QUrl> +// defines #define MAX_ELEMENTS 9 + // NOTE default kurifilter plugin list (at least in my box) // 1. "kshorturifilter" // 2. "kurisearchfilter" @@ -54,13 +56,15 @@ // 4 ."kuriikwsfilter" // 5. "fixhosturifilter" + bool UrlSearchItem::operator==(UrlSearchItem i) { return url==i.url; } + UrlResolver::UrlResolver(const QString &typedUrl) - : _urlString(typedUrl.trimmed()) + : _typedString(typedUrl.trimmed()) { } @@ -75,15 +79,17 @@ UrlSearchList UrlResolver::orderedSearchItems() UrlSearchList list; - if(isHttp()) - { - list << qurlFromUserInputResolution(); - } +// if(isHttp()) +// { +// list << qurlFromUserInputResolution(); +// } list << webSearchesResolution(); - if (_urlString.length()>2) + if (_typedString.length() >= 2) { + list << qurlFromUserInputResolution(); + int firstResults = list.count(); int checkPoint = 9 - firstResults; @@ -145,13 +151,14 @@ bool UrlResolver::isHttp() "y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|"\ "pro)"; - return _urlString.startsWith("http://") - || _urlString.startsWith("https://") - || (QRegExp(address, Qt::CaseInsensitive).indexIn(_urlString) != -1) - || (QRegExp(ipv4, Qt::CaseInsensitive).indexIn(_urlString) != -1) - || (QRegExp(ipv6, Qt::CaseInsensitive).indexIn(_urlString) != -1); + return _typedString.startsWith("http://") + || _typedString.startsWith("https://") + || (QRegExp(address, Qt::CaseInsensitive).indexIn(_typedString) != -1) + || (QRegExp(ipv4, Qt::CaseInsensitive).indexIn(_typedString) != -1) + || (QRegExp(ipv6, Qt::CaseInsensitive).indexIn(_typedString) != -1); } + ////////////////////////////////////////////////////////////////////////// // PRIVATE ENGINES @@ -159,8 +166,18 @@ bool UrlResolver::isHttp() // STEP 1 = QUrl from User Input (easily the best solution... ) UrlSearchList UrlResolver::qurlFromUserInputResolution() { - UrlSearchItem gItem(UrlSearchItem::Browse, KUrl(_urlString), QString()); - return UrlSearchList() << gItem; + UrlSearchList list; + QString url2 = _typedString; + QUrl urlFromUserInput = QUrl::fromUserInput(url2); + if(urlFromUserInput.isValid()) + { + KUrl gUrl(urlFromUserInput); + QString gTitle = i18n("Browse"); + UrlSearchItem gItem(UrlSearchItem::Browse, gUrl, gTitle); + list << gItem; + } + + return list; } @@ -169,11 +186,9 @@ UrlSearchList UrlResolver::webSearchesResolution() { UrlSearchList list; - if(KUrl(_urlString).isRelative()) - { - QString gUrl = QString("http://www.google.com/search?q=%1&ie=UTF-8&oe=UTF-8").arg(_urlString); - QString gTitle = i18n("Search Google for ") + _urlString; - UrlSearchItem gItem(UrlSearchItem::Search, KUrl(), gTitle); + if(KUrl(_typedString).isRelative()) + { + UrlSearchItem gItem(UrlSearchItem::Search, KUrl(), QString() ); // others will find this url.. list << gItem; } @@ -187,7 +202,7 @@ UrlSearchList UrlResolver::historyResolution() UrlSearchList list; KCompletion *historyCompletion = Application::historyManager()->completionObject(); - QStringList historyResults = historyCompletion->substringCompletion(_urlString); + QStringList historyResults = historyCompletion->substringCompletion(_typedString); Q_FOREACH(const QString &s, historyResults) { UrlSearchItem it(UrlSearchItem::History, KUrl(s), Application::historyManager()->titleForHistoryUrl(s)); @@ -204,13 +219,12 @@ UrlSearchList UrlResolver::bookmarksResolution() UrlSearchList list; KCompletion *bookmarkCompletion = Application::bookmarkProvider()->completionObject(); - QStringList bookmarkResults = bookmarkCompletion->substringCompletion(_urlString); + QStringList bookmarkResults = bookmarkCompletion->substringCompletion(_typedString); Q_FOREACH(const QString &s, bookmarkResults) { UrlSearchItem it(UrlSearchItem::Bookmark, KUrl(s), Application::bookmarkProvider()->titleForBookmarkUrl(s)); list << it; } - return list; } diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h index 610b1fd0..22a9de4f 100644 --- a/src/urlbar/urlresolver.h +++ b/src/urlbar/urlresolver.h @@ -51,10 +51,9 @@ class UrlSearchItem int type; KUrl url; QString title; - QString icon; - UrlSearchItem(const int &_type, const KUrl &_url, const QString &_title = QString(), const QString &_icon = QString()) - : type(_type), url(_url), title(_title), icon(_icon) + UrlSearchItem(const int &_type, const KUrl &_url, const QString &_title = QString()) + : type(_type), url(_url), title(_title) {}; bool operator==(UrlSearchItem i); @@ -74,7 +73,7 @@ public: UrlSearchList orderedSearchItems(); private: - QString _urlString; //TODO: give a better name + QString _typedString; UrlSearchList webSearchesResolution(); UrlSearchList historyResolution(); |