diff options
Diffstat (limited to 'src/urlbar')
-rw-r--r-- | src/urlbar/listitem.cpp | 24 | ||||
-rw-r--r-- | src/urlbar/listitem.h | 2 | ||||
-rw-r--r-- | src/urlbar/urlbar.cpp | 18 | ||||
-rw-r--r-- | src/urlbar/urlbar.h | 15 | ||||
-rw-r--r-- | src/urlbar/urlresolver.cpp | 12 | ||||
-rw-r--r-- | src/urlbar/webshortcutwidget.cpp | 184 | ||||
-rw-r--r-- | src/urlbar/webshortcutwidget.h | 61 |
7 files changed, 286 insertions, 30 deletions
diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index f29a0e98..d82613f1 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -63,9 +63,9 @@ ListItem::ListItem(const UrlSearchItem &item, QWidget *parent) : QWidget(parent) , m_option() , m_url(item.url) -{ +{ m_option.initFrom(this); - m_option.direction = Qt::LeftToRight; + m_option.direction = Qt::LeftToRight; // use the same application palette (hence, the same colors) // Qt docs says that using this cctor is possible & fast (qt:qpalette) @@ -98,7 +98,7 @@ void ListItem::deactivate() void ListItem::paintEvent(QPaintEvent *event) { - Q_UNUSED(event); + Q_UNUSED(event); QWidget::paintEvent(event); QPainter painter(this); @@ -473,7 +473,7 @@ KAction *EngineBar::newEngineAction(KService::Ptr engine, KService::Ptr selected { QUrl u = engine->property("Query").toUrl(); KUrl url = KUrl( u.toString( QUrl::RemovePath | QUrl::RemoveQuery ) ); - + kDebug() << "Engine NAME: " << engine->name() << " URL: " << url; KAction *a = new KAction(Application::iconManager()->iconForUrl(url), engine->name(), this); a->setCheckable(true); @@ -562,7 +562,7 @@ VisualSuggestionListItem::VisualSuggestionListItem(const UrlSearchItem &item, co new IconLabel(item.url, previewLabelIcon); } - hLayout->addWidget(previewLabelIcon); + hLayout->addWidget(previewLabelIcon); QVBoxLayout *vLayout = new QVBoxLayout; vLayout->setMargin(0); vLayout->addItem(new QSpacerItem(0,0,QSizePolicy::Expanding,QSizePolicy::MinimumExpanding)); @@ -608,31 +608,31 @@ BrowseListItem::BrowseListItem(const UrlSearchItem &item, const QString &text, Q ListItem *ListItemFactory::create(const UrlSearchItem &item, const QString &text, QWidget *parent) -{ +{ if (item.type & UrlSearchItem::Search) { kDebug() << "Search"; return new SearchListItem(item, text, parent); } - + if (item.type & UrlSearchItem::Browse) { kDebug() << "Browse"; return new BrowseListItem(item, text, parent); } - + if (item.type & UrlSearchItem::History) { kDebug() << "History"; return new PreviewListItem(item, text, parent); } - + if (item.type & UrlSearchItem::Bookmark) { kDebug() << "Bookmark"; return new PreviewListItem(item, text, parent); } - + if (item.type & UrlSearchItem::Suggestion) { kDebug() << "ITEM URL: " << item.url; @@ -641,11 +641,11 @@ ListItem *ListItemFactory::create(const UrlSearchItem &item, const QString &text kDebug() << "Suggestion"; return new SuggestionListItem(item, text, parent); } - + kDebug() << "Visual Suggestion"; return new VisualSuggestionListItem(item, text, parent); } - + kDebug() << "Undefined"; return new PreviewListItem(item, text, parent); } diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h index f5f11532..0d66a12c 100644 --- a/src/urlbar/listitem.h +++ b/src/urlbar/listitem.h @@ -63,7 +63,7 @@ public: KUrl url(); virtual QString text(); - + public slots: virtual void nextItemSubChoice(); diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index d93aeb75..f963be07 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -110,7 +110,10 @@ UrlBar::UrlBar(QWidget *parent) connect(_tab->view(), SIGNAL(iconChanged()), this, SLOT(refreshFavicon())); // bookmark icon - connect(Application::bookmarkProvider()->bookmarkManager(), SIGNAL(changed(const QString &, const QString &)), this, SLOT(onBookmarksChanged())); + connect(Application::bookmarkProvider()->bookmarkManager(), SIGNAL(changed(const QString &, const QString &)), this, SLOT(updateRightIcons())); + + // search icon + connect(Application::opensearchManager(), SIGNAL(openSearchEngineAdded(const QString &, const QString &, const QString &)), this, SLOT(updateRightIcons())); _suggestionTimer->setSingleShot(true); connect(_suggestionTimer, SIGNAL(timeout()), this, SLOT(suggest())); @@ -335,6 +338,13 @@ void UrlBar::loadFinished() connect(bt, SIGNAL(clicked(QPoint)), _tab->page(), SLOT(showSSLInfo(QPoint))); } + // show add search engine + if (_tab->hasNewSearchEngine()) + { + IconButton *bt = addRightIcon(UrlBar::SearchEngine); + connect(bt, SIGNAL(clicked(QPoint)), _tab, SLOT(showSearchEngine(QPoint))); + } + // we need to update urlbar after the right icon settings // removing this code (where setStyleSheet automatically calls update) needs adding again // an update call @@ -367,7 +377,7 @@ void UrlBar::showBookmarkInfo(const QPoint &pos) } -void UrlBar::onBookmarksChanged() +void UrlBar::updateRightIcons() { if (!_tab->isPageLoading()) { @@ -442,6 +452,10 @@ IconButton *UrlBar::addRightIcon(UrlBar::icon ic) rightIcon->setToolTip(i18n("Edit this bookmark")); } break; + case UrlBar::SearchEngine: + rightIcon->setIcon(KIcon("preferences-web-browser-shortcuts")); + rightIcon->setToolTip(i18n("Add search engine")); + break; default: kDebug() << "ERROR.. default non extant case!!"; break; diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 67a693c0..964534cb 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -79,10 +79,11 @@ public: enum icon { - KGet = 0x00000001, - RSS = 0x00000010, - SSL = 0x00000100, - BK = 0x00001000 + KGet = 0x00000001, + RSS = 0x00000010, + SSL = 0x00000100, + BK = 0x00001000, + SearchEngine = 0x00010000 }; explicit UrlBar(QWidget *parent = 0); @@ -100,15 +101,15 @@ private slots: void loadTyped(const QString &); void clearRightIcons(); - + void updateRightIcons(); + void detectTypedString(const QString &); void suggest(); void showBookmarkInfo(const QPoint &pos); - void onBookmarksChanged(); void refreshFavicon(); - + protected: void paintEvent(QPaintEvent *event); void keyPressEvent(QKeyEvent *event); diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index 57d6ca64..864eca04 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -412,16 +412,12 @@ void UrlResolver::suggestionsReceived(const QString &text, const ResponseList &s Q_FOREACH(const Response &i, suggestions) { - QString urlString = i.url; - if(urlString.isEmpty()) + QString url = i.url; + if (url.isEmpty()) { - QStringList list; - list << QL1S("kuriikwsfilter"); - urlString = KUriFilter::self()->filteredUri(i.title, list); + url = SearchEngine::buildQuery(searchEngine(), i.title); } - kDebug() << "RESPONSE URL: " << i.url; - - UrlSearchItem gItem(UrlSearchItem::Suggestion, urlString, i.title, i.description, i.image, i.image_width, i.image_height); + UrlSearchItem gItem(UrlSearchItem::Suggestion, url, i.title, i.description, i.image, i.image_width, i.image_height); sugList << gItem; } emit suggestionsReady(sugList, _typedString); diff --git a/src/urlbar/webshortcutwidget.cpp b/src/urlbar/webshortcutwidget.cpp new file mode 100644 index 00000000..843d528b --- /dev/null +++ b/src/urlbar/webshortcutwidget.cpp @@ -0,0 +1,184 @@ +/* This file is part of the KDE project + * Copyright (C) 2009 Fredy Yanardi <fyanardi@gmail.com> + * Copyright (C) 2010 Lionel Chauvin <megabigbug@yahoo.fr> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "webshortcutwidget.h" + +#include <QtCore/QTimer> +#include <QtCore/QSet> +#include <QtGui/QBoxLayout> +#include <QtGui/QLabel> +#include <QtGui/QLineEdit> +#include <QtGui/QPushButton> +#include <QtGui/QFormLayout> + + +#include <KGlobalSettings> +#include <KIcon> +#include <KLocale> +#include <KServiceTypeTrader> + +WebShortcutWidget::WebShortcutWidget(QWidget *parent) + : QDialog(parent) +{ + QVBoxLayout *mainLayout = new QVBoxLayout(); + QHBoxLayout *titleLayout = new QHBoxLayout(); + mainLayout->addLayout(titleLayout); + QLabel *iconLabel = new QLabel(this); + KIcon wsIcon("preferences-web-browser-shortcuts"); + iconLabel->setPixmap(wsIcon.pixmap(22, 22)); + titleLayout->addWidget(iconLabel); + m_searchTitleLabel = new QLabel(i18n("Add Search Engine"), this); + QFont boldFont = KGlobalSettings::generalFont(); + boldFont.setBold(true); + m_searchTitleLabel->setFont(boldFont); + titleLayout->addWidget(m_searchTitleLabel); + titleLayout->addStretch(); + + QFormLayout *formLayout = new QFormLayout(); + mainLayout->addLayout(formLayout); + + QFont smallFont = KGlobalSettings::smallestReadableFont(); + m_nameLineEdit = new QLineEdit(this); + m_nameLineEdit->setEnabled(false); + m_nameLineEdit->setFont(smallFont); + QLabel *nameLabel = new QLabel(i18n("Name:"), this); + nameLabel->setFont(smallFont); + formLayout->addRow(nameLabel, m_nameLineEdit); + + QLabel *shortcutsLabel = new QLabel(i18n("Shortcuts:"), this); + shortcutsLabel->setFont(smallFont); + m_wsLineEdit = new QLineEdit(this); + m_wsLineEdit->setMinimumWidth(100); + m_wsLineEdit->setFont(smallFont); + formLayout->addRow(shortcutsLabel, m_wsLineEdit); + connect(m_wsLineEdit, SIGNAL(textChanged(QString)), SLOT(shortcutsChanged(const QString&))); + + m_noteLabel = new QLabel(this); + m_noteLabel->setFont(boldFont); + m_noteLabel->setWordWrap(true); + formLayout->addRow(m_noteLabel); + m_noteLabel->setVisible(false); + + mainLayout->addStretch(); + + QHBoxLayout *buttonLayout = new QHBoxLayout(); + mainLayout->addLayout(buttonLayout); + buttonLayout->addStretch(); + m_okButton = new QPushButton(i18n("Ok"), this); + m_okButton->setDefault(true); + buttonLayout->addWidget(m_okButton); + connect(m_okButton, SIGNAL(clicked()), this, SLOT(okClicked())); + + QPushButton *cancelButton = new QPushButton(i18n("Cancel"), this); + buttonLayout->addWidget(cancelButton); + connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelClicked())); + + setLayout(mainLayout); + + setMinimumWidth (250); + + m_providers = KServiceTypeTrader::self()->query("SearchProvider"); + + QTimer::singleShot(0, m_wsLineEdit, SLOT(setFocus())); +} + + +void WebShortcutWidget::showAt(const QPoint &pos) +{ + adjustSize(); + + QPoint p; + p.setX(pos.x() - width()); + p.setY(pos.y() + 10); + + move(p); + QDialog::show(); +} + + +void WebShortcutWidget::show(const KUrl &url, const QString &openSearchName, const QPoint &pos) +{ + m_wsLineEdit->clear(); + m_nameLineEdit->setText(openSearchName); + m_url = url; + showAt(pos); +} + + +void WebShortcutWidget::okClicked() +{ + hide(); + emit webShortcutSet(m_url, m_nameLineEdit->text(), m_wsLineEdit->text()); +} + + +void WebShortcutWidget::cancelClicked() +{ + hide(); +} + + +void WebShortcutWidget::shortcutsChanged(const QString& newShorthands) +{ + int savedCursorPosition = m_wsLineEdit->cursorPosition(); + QString normalizedShorthands = QString(newShorthands).replace(" ", ","); + m_wsLineEdit->setText(normalizedShorthands); + m_wsLineEdit->setCursorPosition(savedCursorPosition); + + QSet<QString> shorthands = normalizedShorthands.split(",").toSet(); + QString contenderName = ""; + QString contenderWS = ""; + + Q_FOREACH (const QString &shorthand, shorthands) + { + Q_FOREACH (KService::Ptr provider, m_providers) + { + if(provider->property("Keys").toStringList().contains(shorthand)) + { + contenderName = provider->property("Name").toString(); + contenderWS = shorthand; + break; + } + } + } + + if (!contenderName.isEmpty()) + { + m_okButton->setEnabled(false); + m_noteLabel->setText(i18n("The shortcut \"%1\" is already assigned to \"%2\".", contenderWS, contenderName)); + m_noteLabel->setVisible(true); + resize(minimumSize().width(), minimumSizeHint().height()+15); + } + else + { + m_okButton->setEnabled(true); + m_noteLabel->clear(); + bool noteIsVisible = m_noteLabel->isVisible(); + m_noteLabel->setVisible(false); + if (noteIsVisible) + { + resize(minimumSize()); + } + } +} + +#include "webshortcutwidget.moc" + + diff --git a/src/urlbar/webshortcutwidget.h b/src/urlbar/webshortcutwidget.h new file mode 100644 index 00000000..02ddaf17 --- /dev/null +++ b/src/urlbar/webshortcutwidget.h @@ -0,0 +1,61 @@ +/* This file is part of the KDE project + * Copyright (C) 2009 Fredy Yanardi <fyanardi@gmail.com> + * Copyright (C) 2010 Lionel Chauvin <megabigbug@yahoo.fr> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef WEBSHORTCUTWIDGET_H +#define WEBSHORTCUTWIDGET_H + +#include <QtGui/QDialog> +#include <KUrl> +#include <KService> + +class QLabel; +class QLineEdit; + +class WebShortcutWidget : public QDialog +{ + Q_OBJECT +public: + explicit WebShortcutWidget(QWidget *parent = 0); + + void show(const KUrl &url, const QString &openSearchName, const QPoint &pos); + +private slots: + void okClicked(); + void cancelClicked(); + void shortcutsChanged(const QString& newShorthands); + +signals: + void webShortcutSet(const KUrl &url, const QString &openSearchName, const QString &webShortcut); + +private: + QLabel *m_searchTitleLabel; + QLineEdit *m_wsLineEdit; + QLineEdit *m_nameLineEdit; + QLabel *m_noteLabel; + QPushButton *m_okButton; + + KService::List m_providers; + KUrl m_url; + + void showAt(const QPoint &pos); +}; + +#endif // WEBSHORTCUTWIDGET_H + |