diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2010-04-15 23:59:35 +0200 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2010-04-15 23:59:35 +0200 |
commit | cc6d332afeb2ed940bcd3ca6bc307916b3ddf953 (patch) | |
tree | df470b3f9d62a4034b27cf37df93e3cfe38f60b3 | |
parent | Merge commit 'refs/merge-requests/124' of git://gitorious.org/rekonq/mainline... (diff) | |
parent | introduce search listitem (diff) | |
download | rekonq-cc6d332afeb2ed940bcd3ca6bc307916b3ddf953.tar.xz |
Merge commit 'refs/merge-requests/77' of git://gitorious.org/rekonq/mainline into m77
-rw-r--r-- | src/data/rekonq.desktop | 2 | ||||
-rw-r--r-- | src/urlbar/completionwidget.cpp | 35 | ||||
-rw-r--r-- | src/urlbar/completionwidget.h | 4 | ||||
-rw-r--r-- | src/urlbar/listitem.cpp | 404 | ||||
-rw-r--r-- | src/urlbar/listitem.h | 149 | ||||
-rw-r--r-- | src/urlbar/urlbar.cpp | 2 | ||||
-rw-r--r-- | src/urlbar/urlresolver.cpp | 58 | ||||
-rw-r--r-- | src/urlbar/urlresolver.h | 19 |
8 files changed, 512 insertions, 161 deletions
diff --git a/src/data/rekonq.desktop b/src/data/rekonq.desktop index 1d2a60ec..df564c47 100644 --- a/src/data/rekonq.desktop +++ b/src/data/rekonq.desktop @@ -6,6 +6,7 @@ Name[de]=rekonq Name[en_GB]=rekonq Name[es]=rekonq Name[ga]=rekonq +Name[lt]=rekonq Name[nds]=Rekonq Name[pl]=rekonq Name[pt]=rekonq @@ -20,6 +21,7 @@ GenericName[de]=WebKit-basierter Webbrowser für KDE GenericName[en_GB]=Webkit KDE Browser GenericName[es]=Navegador Webkit para KDE GenericName[ga]=Brabhsálaí Webkit KDE +GenericName[lt]=Webkit KDE naršyklė GenericName[nds]=Webkit-KDE-Kieker GenericName[pl]=Przeglądarka Webkit dla KDE GenericName[pt]=Navegador do KDE usando o WebKit diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index 311694b3..42824af9 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -59,18 +59,18 @@ CompletionWidget::CompletionWidget( QWidget *parent) } -void CompletionWidget::insertSearchList(const UrlSearchList &list) +void CompletionWidget::insertSearchList(const UrlSearchList &list, const QString& text) { _list = list; int i = 0; foreach(UrlSearchItem item, _list) { - ListItem *suggestion = new ListItem(item); - suggestion->setBackgroundRole(i%2 ? QPalette::AlternateBase : QPalette::Base); + ListItem *suggestion = ListItemFactory::create(item, text); + suggestion->setBackgroundRole(i%2 ? QPalette::AlternateBase: QPalette::Base); connect(suggestion, SIGNAL(itemClicked(ListItem *, Qt::MouseButton)), this, SLOT(itemChosen(ListItem *, Qt::MouseButton))); - suggestion->setObjectName( QString::number(i) ); + connect(this, SIGNAL(nextItemSubChoice()), suggestion, SLOT(nextItemSubChoice())); + suggestion->setObjectName( QString::number(i++) ); layout()->addWidget( suggestion ); - i++; } } @@ -88,8 +88,9 @@ void CompletionWidget::sizeAndPosition() void CompletionWidget::popup() { + down(); sizeAndPosition(); - if (!isVisible()) + if (!isVisible()) show(); } @@ -195,17 +196,23 @@ bool CompletionWidget::eventFilter( QObject *o, QEvent *e ) ev->accept(); return true; } + else if (ev->modifiers() & Qt::ControlModifier) + { + emit nextItemSubChoice(); + ev->accept(); + return true; + } break; - + case Qt::Key_Enter: case Qt::Key_Return: - hide(); - if(_currentIndex >= 0) - emit chosenUrl(_list.at(_currentIndex).url, Rekonq::CurrentTab); - else - emit loadTypedUrl(); - ev->accept(); - return true; + hide(); + if(_currentIndex >= 0) + emit chosenUrl(_list.at(_currentIndex).url, Rekonq::CurrentTab); + else + emit loadTypedUrl(); + ev->accept(); + return true; break; } } diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h index 57a8bed0..25b6f5eb 100644 --- a/src/urlbar/completionwidget.h +++ b/src/urlbar/completionwidget.h @@ -47,7 +47,7 @@ class CompletionWidget : public QFrame public: CompletionWidget(QWidget *parent); - void insertSearchList(const UrlSearchList &list); + void insertSearchList(const UrlSearchList &list, const QString& text); void popup(); void clear(); @@ -59,6 +59,7 @@ private slots: signals: void chosenUrl(const KUrl &, Rekonq::OpenType); + void nextItemSubChoice(); void loadTypedUrl(); private: @@ -70,6 +71,7 @@ private: UrlSearchList _list; int _currentIndex; + QString *_searchEngine; }; #endif // COMPLETION_WIDGET_H diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index 18e8352d..ef09d4f3 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -36,7 +36,10 @@ #include <KIcon> #include <KStandardDirs> #include <KDebug> -#include <KUrl> +#include <QActionGroup> +#include <KConfigGroup> +#include <KIcon> + // Qt Includes #include <QHBoxLayout> @@ -45,111 +48,203 @@ #include <QSizePolicy> #include <QPixmap> #include <QStylePainter> -#include <QFile> #include <QMouseEvent> +#include <QWebSettings> +#include <QFile> ListItem::ListItem(const UrlSearchItem &item, QWidget *parent) : QWidget(parent) + , m_option() + , m_url(item.url) { setAutoFillBackground(true); + + m_option.initFrom(this); + m_option.direction = Qt::LeftToRight; + + QPalette p(palette()); + p.setColor(QPalette::Base, Qt::white); // TODO: choose the correct color - QPalette p = palette(); - p.setColor(QPalette::Base, Qt::white); // TODO: choose the correct color p.setColor(QPalette::AlternateBase, QColor(247,247,247)); // TODO: choose the correct color setPalette(p); - - // ---------------------------------------- - + QHBoxLayout *hLayout = new QHBoxLayout; - - QLabel *previewLabelIcon = new QLabel; - previewLabelIcon->setFixedSize(45,33); - hLayout->addWidget(previewLabelIcon); + hLayout->setSpacing(4); + setLayout(hLayout); - // pixmap should ever exists - QPixmap pixmapIcon = Application::icon(item.url).pixmap(16); - - QString path = KStandardDirs::locateLocal("cache", QString("thumbs/") + guessNameFromUrl(item.url) + ".png", true); - if(QFile::exists(path)) - { - QLabel *previewLabel = new QLabel(previewLabelIcon); - previewLabel->setFrameStyle(QFrame::StyledPanel | QFrame::Raised); - QPixmap preview; - preview.load(path); - - previewLabel->setFixedSize(38,29); - previewLabel->setPixmap(preview.scaled(38,29, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); - } + deactivate(); +} - QLabel *iconLabel = new QLabel(previewLabelIcon); - iconLabel->setPixmap(pixmapIcon); - iconLabel->move(27, 16); - - //title and url - QVBoxLayout *vLayout = new QVBoxLayout; - hLayout->addLayout(vLayout); - - QLabel *titleLabel = new QLabel("<b>" + item.title + "</b>"); - titleLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - - QLabel *urlLabel = new QLabel("<i>" + item.url.url() + "</i>"); - urlLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - - vLayout->addWidget(titleLabel); - vLayout->addWidget(urlLabel); - //type icon +ListItem::~ListItem() +{ + disconnect(); +} + - if (item.type & UrlSearchItem::Browse) - { - insertIcon(hLayout, "applications-internet"); - } + +void ListItem::activate() +{ + m_option.state |= QStyle::State_Selected; + update(); +} + + +void ListItem::deactivate() +{ + m_option.state &= ~QStyle::State_Selected; + update(); +} + + +void ListItem::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); - if (item.type & UrlSearchItem::Search) - { - insertIcon(hLayout, "edit-find"); - } - - if (item.type & UrlSearchItem::Bookmark) + if( m_option.state.testFlag(QStyle::State_Selected) || m_option.state.testFlag(QStyle::State_MouseOver)) { - insertIcon(hLayout, "rating"); + QPainter painter(this); + m_option.rect=QRect(QPoint(),size()); + style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &m_option, &painter, this); } + + QWidget::paintEvent(event); +} - if (item.type & UrlSearchItem::History) - { - insertIcon(hLayout, "view-history"); - } - setLayout(hLayout); - - _option.initFrom(this); - _option.direction = Qt::LeftToRight; - - deactivate(); +void ListItem::enterEvent(QEvent *e) +{ + m_option.state |= QStyle::State_MouseOver; + update(); + QWidget::enterEvent(e); } -ListItem::~ListItem() +void ListItem::leaveEvent(QEvent *e) { - disconnect(); + m_option.state &= ~QStyle::State_MouseOver; + update(); + QWidget::enterEvent(e); +} + + +void ListItem::mousePressEvent(QMouseEvent *e) +{ + emit itemClicked(this, e->button()); + QWidget::mousePressEvent(e); +} + + +KUrl ListItem::url() +{ + return m_url; +} + +void ListItem::nextItemSubChoice() +{ + //will be override } -void ListItem::insertIcon(QLayout *layout, QString icon) +TypeIcon::TypeIcon(int type, QWidget *parent) +:QLabel(parent) +{ + setMinimumWidth(40); + QHBoxLayout *hLayout = new QHBoxLayout; + hLayout->setMargin(0); + hLayout->setAlignment(Qt::AlignRight); + setLayout(hLayout); + + if (type & UrlSearchItem::Search) hLayout->addWidget(getIcon("edit-find")); + if (type & UrlSearchItem::Browse) hLayout->addWidget(getIcon("applications-internet")); + if (type & UrlSearchItem::Bookmark) hLayout->addWidget(getIcon("rating")); + if (type & UrlSearchItem::History) hLayout->addWidget(getIcon("view-history")); +} + + +QLabel *TypeIcon::getIcon(QString icon) { QLabel *iconLabel = new QLabel; - QPixmap pixmap = KIcon(icon).pixmap(18); + iconLabel->setFixedSize(16,16); + QPixmap pixmap = KIcon(icon).pixmap(16); iconLabel->setPixmap(pixmap); - iconLabel->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum); - layout->addWidget(iconLabel); + return iconLabel; +} + + + +ItemIcon::ItemIcon(QString icon, QWidget *parent) +:QLabel(parent) +{ + QPixmap pixmapIcon = KIcon(QWebSettings::iconForUrl(icon)).pixmap(16); + if (pixmapIcon.isNull()) + { + pixmapIcon = KIcon("text-html").pixmap(16); + } + + setFixedSize(16,16); + setPixmap(pixmapIcon); +} + + +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) +{ + QString t = text; + t = t.replace(QRegExp("("+textToUnderline+")", Qt::CaseInsensitive), "<u>\\1</u>"); + return t; +} + + +//-------------------------------------------------------------------------------------------- + + +PreviewListItem::PreviewListItem(const UrlSearchItem &item, const QString &text, QWidget *parent) +:ListItem(item, parent) +{ + QLabel *previewLabelIcon = new QLabel; + previewLabelIcon->setFixedSize(45,33); + new ItemPreview(item.url.url(), 38, 29, previewLabelIcon); + ItemIcon* icon = new ItemIcon(item.url.url(), previewLabelIcon); + icon->move(27, 16); + layout()->addWidget(previewLabelIcon); + + QVBoxLayout *vLayout = new QVBoxLayout; + vLayout->setMargin(0); + ((QHBoxLayout *)layout())->addLayout(vLayout); + vLayout->addWidget(new ItemText(item.title, text)); + vLayout->addWidget(new ItemText("<i>" + item.url.url() + "</i>", text)); + layout()->addWidget(new TypeIcon(item.type)); +} + + +ItemPreview::ItemPreview(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); + if(QFile::exists(path)) + { + QPixmap preview; + preview.load(path); + setPixmap(preview.scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + } } //TODO: REMOVE DUPLICATE CODE WITH PREVIEWIMAGE -QString ListItem::guessNameFromUrl(KUrl url) +QString ItemPreview::guessNameFromUrl(QUrl url) { - QString name = url.url();// toString( QUrl::RemoveScheme | QUrl::RemoveUserInfo | QUrl::StripTrailingSlash ); + QString name = url.toString( QUrl::RemoveScheme | QUrl::RemoveUserInfo | QUrl::StripTrailingSlash ); // TODO learn Regular Expressions :) // and implement something better here.. @@ -165,52 +260,173 @@ QString ListItem::guessNameFromUrl(KUrl url) return name; } +//-------------------------------------------------------------------------------------------- +QString SearchListItem::m_currentEngine = ""; -void ListItem::activate() +SearchListItem::SearchListItem(const UrlSearchItem &item, const QString &text, QWidget *parent) + :ListItem(item, parent) + ,m_text(text) { - _option.state |= QStyle::State_Selected; - update(); + if (m_currentEngine == "") m_currentEngine = EngineBar::defaultEngine(); + + m_iconLabel = new ItemIcon("edit-find", this); //TODO: get the default engine icon + m_titleLabel = new ItemText(searchItemTitle(m_currentEngine, text), text); + m_engineBar = new EngineBar(text, m_currentEngine, this); + + layout()->addWidget(m_iconLabel); + layout()->addWidget(m_titleLabel); + layout()->addWidget(new QLabel("Engines: ")); + layout()->addWidget(m_engineBar); + layout()->addWidget(new TypeIcon(item.type)); + + connect(m_engineBar, SIGNAL(searchEngineChanged(QString, QString)), this, SLOT(changeSearchEngine(QString, QString))); } -void ListItem::deactivate() +QString SearchListItem::searchItemTitle(QString engine, QString text) { - _option.state &= ~QStyle::State_Selected; - update(); + return QString("Search "+ engine +" for <u>"+text+"</u>"); } -void ListItem::paintEvent(QPaintEvent *event) +void SearchListItem::changeSearchEngine(QString url, QString engine) { - Q_UNUSED(event); + m_titleLabel->setText(searchItemTitle(engine,m_text)); + m_iconLabel->setPixmap(Application::icon(url).pixmap(16)); + m_url = KUrl(url); + m_currentEngine = engine; +} + + +void SearchListItem::nextItemSubChoice() +{ + m_engineBar->selectNextEngine(); +} + + +EngineBar::EngineBar(QString text, QString selectedEngine, QWidget *parent) +:KToolBar(parent) +{ + setIconSize(QSize(16,16)); + setToolButtonStyle(Qt::ToolButtonIconOnly); + + m_engineGroup = new QActionGroup(this); + m_engineGroup->setExclusive(true); + + KConfig config("kuriikwsfilterrc"); //Share with konqueror + KConfigGroup cg = config.group("General"); + QStringList favoriteEngines; + favoriteEngines << "wikipedia" << "google"; //defaults + favoriteEngines = cg.readEntry("FavoriteSearchEngines", favoriteEngines); + QString defaultEngine = cg.readEntry("DefaultSearchEngine", "google"); + KService::Ptr service; + + service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(defaultEngine)); + m_engineGroup->addAction(newEngineAction(service, selectedEngine, text)); - if( _option.state.testFlag(QStyle::State_Selected) || _option.state.testFlag(QStyle::State_MouseOver) ) + Q_FOREACH(const QString &engine, favoriteEngines) { - QPainter painter(this); - _option.rect = QRect(QPoint(),size()); - style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &_option, &painter, this); + if(!engine.isEmpty()) + { + service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(engine)); + if(service && service->desktopEntryName()!=defaultEngine) + { + m_engineGroup->addAction(newEngineAction(service, selectedEngine, text)); + } + } } + + addActions(m_engineGroup->actions()); } -void ListItem::enterEvent(QEvent *e) +QString EngineBar::defaultEngine() +{ + KConfig config("kuriikwsfilterrc"); //Share with konqueror + KConfigGroup cg = config.group("General"); + QString d = cg.readEntry("DefaultSearchEngine", "google"); + KService::Ptr service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(d)); + return service->name(); +} + + +KAction *EngineBar::newEngineAction(KService::Ptr service, QString selectedEngine, QString text) { - _option.state |= QStyle::State_MouseOver; - update(); - QWidget::enterEvent(e); + QString url = service->property("Query").toString(); + url = url.replace("\\{@}",text); + KAction *a = new KAction(Application::icon(url), service->name(), this); + a->setCheckable(true); + if (service->name()==selectedEngine) a->setChecked(true); + a->setData(QStringList() << url << service->name()); + connect(a, SIGNAL(triggered(bool)), this, SLOT(changeSearchEngine())); + + return a; } -void ListItem::leaveEvent(QEvent *e) +void EngineBar::changeSearchEngine() { - _option.state &= ~QStyle::State_MouseOver; - update(); - QWidget::enterEvent(e); + KAction *a = qobject_cast<KAction*>(sender()); + QStringList list = a->data().toStringList(); + emit searchEngineChanged(list.first(), list.last()); } -void ListItem::mousePressEvent(QMouseEvent *e) +void EngineBar::selectNextEngine() { - emit itemClicked(this, e->button()); - QWidget::mousePressEvent(e); + QList<QAction *> e = m_engineGroup->actions(); + int i = 0; + while(i<e.count() && !e.at(i)->isChecked()) + { + i++; + } + + if (i+1 == e.count()) + { + e.at(0)->setChecked(true); + e.at(0)->trigger(); + } + else + { + e.at(i+1)->setChecked(true); + e.at(i+1)->trigger(); + } } + + +//-------------------------------------------------------------------------------------------- + + +BrowseListItem::BrowseListItem(const UrlSearchItem &item, const QString &text, QWidget *parent) +:ListItem(item, parent) +{ + QString url = text; + layout()->addWidget(new ItemIcon(item.url.url())); + layout()->addWidget(new ItemText("Browse <i>http://" + url.remove("http://") + "</i>", text)); + layout()->addWidget(new TypeIcon(item.type)); +} + + +//-------------------------------------------------------------------------------------------- + + +ListItem *ListItemFactory::create(const UrlSearchItem &item, const QString &text, QWidget *parent) +{ + ListItem *newItem; + + if (item.type & UrlSearchItem::Browse) + { + newItem = new BrowseListItem(item, text, parent); + } + else if (item.type & UrlSearchItem::Search) + { + newItem = new SearchListItem(item, text, parent); + } + else + { + newItem = new PreviewListItem(item, text, parent); + } + + return newItem; +} + diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h index 18ec8a33..6a6c433f 100644 --- a/src/urlbar/listitem.h +++ b/src/urlbar/listitem.h @@ -23,19 +23,25 @@ * * ============================================================ */ - #ifndef LISTITEM_H #define LISTITEM_H +// KDE Includes +#include <KToolBar> +#include <KAction> +#include <KService> + +// Local Includes +#include "urlresolver.h" // Qt Includes #include <QWidget> #include <QLayout> #include <QStyleOptionViewItemV4> +#include <QLabel> // Forward Declarations class UrlSearchItem; -class KUrl; class ListItem : public QWidget @@ -44,11 +50,16 @@ class ListItem : public QWidget public: ListItem(const UrlSearchItem &item, QWidget *parent = 0); - ~ListItem(); + virtual ~ListItem(); void activate(); void deactivate(); + KUrl url(); + +public slots: + virtual void nextItemSubChoice(); + signals: void itemClicked(ListItem *item, Qt::MouseButton); @@ -59,11 +70,135 @@ protected: virtual void mousePressEvent(QMouseEvent *e); private: - QString guessNameFromUrl(KUrl url); - void insertIcon(QLayout *layout, QString icon); + QStyleOptionViewItemV4 m_option; + +protected: + KUrl m_url; +}; + + +class TypeIcon : public QLabel +{ + Q_OBJECT + + 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); +}; + + +class ItemText : public QLabel +{ + Q_OBJECT + + public: + ItemText(QString text, QString underlined, QWidget *parent = 0); + QString underlineText(QString text, QString textToUnderline); +}; + + +//------------------------------------------------------------------------------------------------- + +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(); + + private: + KAction *newEngineAction(KService::Ptr service, QString selectedEngine, QString text); + + QActionGroup *m_engineGroup; +}; + + +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; +}; + + +//------------------------------------------------------------------------------------------------- + +class PreviewListItem : public ListItem +{ + Q_OBJECT + + 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); + + private: + static QString guessNameFromUrl(QUrl url); +}; + +//------------------------------------------------------------------------------------------------- + +class BrowseListItem : public ListItem +{ + Q_OBJECT - QStyleOptionViewItemV4 _option; + public: + BrowseListItem(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); + protected: + +}; + +//------------------------------------------------------------------------------------------------- + +class ListItemFactory +{ + public: + static ListItem *create(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); + }; -#endif // LISTITEM_H +#endif
\ No newline at end of file diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 051277e2..4abd4622 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -216,7 +216,7 @@ void UrlBar::suggestUrls(const QString &text) if(list.count() > 0) { _box->clear(); - _box->insertSearchList(list); + _box->insertSearchList(list, text); _box->popup(); } } diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index 4ff6b461..fd4cdfcb 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -60,7 +60,7 @@ bool UrlSearchItem::operator==(UrlSearchItem i) } UrlResolver::UrlResolver(const QString &typedUrl) - : _urlString( typedUrl.trimmed() ) + : _urlString(typedUrl.trimmed()) { } @@ -78,19 +78,15 @@ UrlSearchList UrlResolver::orderedSearchItems() if(isHttp()) { list << qurlFromUserInputResolution(); - list << webSearchesResolution(); - } - else - { - list << webSearchesResolution(); - list << qurlFromUserInputResolution(); } + + list << webSearchesResolution(); if (_urlString.length()>2) { int firstResults = list.count(); int checkPoint = 9 - firstResults; - + UrlSearchList historyList = historyResolution(); int historyResults = historyList.count(); @@ -136,7 +132,12 @@ UrlSearchList UrlResolver::orderedSearchItems() bool UrlResolver::isHttp() { - QString r = "[\\d\\w-.]+\\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|"\ + QString ipv4 = "^0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])"\ + "\\.0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])"; + + QString ipv6 = "^([0-9a-fA-F]{4}|0)(\\:([0-9a-fA-F]{4}|0)){7}"; + + QString address = "[\\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]|"\ @@ -144,9 +145,11 @@ bool UrlResolver::isHttp() "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:"); + 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); } ////////////////////////////////////////////////////////////////////////// @@ -156,19 +159,8 @@ bool UrlResolver::isHttp() // STEP 1 = QUrl from User Input (easily the best solution... ) UrlSearchList UrlResolver::qurlFromUserInputResolution() { - UrlSearchList list; - - QString url2 = _urlString; - 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; + UrlSearchItem gItem(UrlSearchItem::Browse, KUrl(_urlString), QString()); + return UrlSearchList() << gItem; } @@ -176,14 +168,12 @@ UrlSearchList UrlResolver::qurlFromUserInputResolution() UrlSearchList UrlResolver::webSearchesResolution() { UrlSearchList list; - - KUrl url1(_urlString); - if(url1.isRelative()) + + if(KUrl(_urlString).isRelative()) { - // KUriFilter has the worst performance possible here and let this trick unusable - KUrl gUrl( QString("gg:") + _urlString ); - QString gTitle = i18n("Search Google for %1", _urlString); - UrlSearchItem gItem(UrlSearchItem::Search, gUrl, gTitle ); + 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); list << gItem; } @@ -200,7 +190,7 @@ UrlSearchList UrlResolver::historyResolution() QStringList historyResults = historyCompletion->substringCompletion(_urlString); Q_FOREACH(const QString &s, historyResults) { - UrlSearchItem it(UrlSearchItem::History, KUrl(s), Application::historyManager()->titleForHistoryUrl(s) ); //, QString("view-history")); + UrlSearchItem it(UrlSearchItem::History, KUrl(s), Application::historyManager()->titleForHistoryUrl(s)); list << it; } @@ -217,7 +207,7 @@ UrlSearchList UrlResolver::bookmarksResolution() QStringList bookmarkResults = bookmarkCompletion->substringCompletion(_urlString); Q_FOREACH(const QString &s, bookmarkResults) { - UrlSearchItem it(UrlSearchItem::Bookmark, KUrl(s), Application::bookmarkProvider()->titleForBookmarkUrl(s) ); //, QString("rating") ); + UrlSearchItem it(UrlSearchItem::Bookmark, KUrl(s), Application::bookmarkProvider()->titleForBookmarkUrl(s)); list << it; } diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h index 3c082e00..610b1fd0 100644 --- a/src/urlbar/urlresolver.h +++ b/src/urlbar/urlresolver.h @@ -27,7 +27,6 @@ #ifndef URL_RESOLVER_H #define URL_RESOLVER_H - // KDE Includes #include <KUrl> @@ -43,21 +42,21 @@ class UrlSearchItem enum types { - Search = 0x00000001, - Browse = 0x00000010, - History = 0x00000100, - Bookmark = 0x00001000, - Suggestion = 0x00010000, + Search = 0x00000001, + Browse = 0x00000010, + History = 0x00000100, + Bookmark = 0x00001000, }; int type; KUrl url; QString title; + QString icon; - UrlSearchItem(const int &_type, const KUrl &_url, const QString &_title = QString()) - : type(_type), url(_url), title(_title) + UrlSearchItem(const int &_type, const KUrl &_url, const QString &_title = QString(), const QString &_icon = QString()) + : type(_type), url(_url), title(_title), icon(_icon) {}; - + bool operator==(UrlSearchItem i); }; @@ -75,7 +74,7 @@ public: UrlSearchList orderedSearchItems(); private: - QString _urlString; + QString _urlString; //TODO: give a better name UrlSearchList webSearchesResolution(); UrlSearchList historyResolution(); |