summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/urlbar/urlbar.cpp33
-rw-r--r--src/urlbar/urlbar.h2
2 files changed, 33 insertions, 2 deletions
diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp
index e3f216d8..04e48d1b 100644
--- a/src/urlbar/urlbar.cpp
+++ b/src/urlbar/urlbar.cpp
@@ -46,6 +46,7 @@
#include "bookmarkwidget.h"
#include "iconmanager.h"
#include "favoritewidget.h"
+#include "searchengine.h"
// KDE Includes
#include <KCompletionBox>
@@ -482,8 +483,17 @@ void UrlBar::contextMenuEvent(QContextMenuEvent* event)
menu.addAction(a);
// Paste & Go
- a = new KAction(i18n("Paste && Go"), this);
- connect(a, SIGNAL(triggered(bool)), this, SLOT(pasteAndGo()));
+ const QString clipboardText = rApp->clipboard()->text();
+ if (isValidURL(clipboardText) || clipboardText.isEmpty())
+ {
+ a = new KAction(i18n("Paste && Go"), this);
+ connect(a, SIGNAL(triggered(bool)), this, SLOT(pasteAndGo()));
+ }
+ else
+ {
+ a = new KAction(i18n("Paste && Search"), this);
+ connect(a, SIGNAL(triggered(bool)), this, SLOT(pasteAndSearch()));
+ }
a->setEnabled(clipboardFilled);
menu.addAction(a);
@@ -504,6 +514,17 @@ void UrlBar::contextMenuEvent(QContextMenuEvent* event)
}
+bool UrlBar::isValidURL(QString url)
+{
+ bool isValid = false;
+ if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("ftp://"))
+ url = url.remove(QRegExp("(http|https|ftp)://"));
+ if (url.contains('.') && url.indexOf('.') > 0 && url.indexOf('.') < url.length() && !url.trimmed().contains(" ") && QUrl::fromUserInput(url).isValid())
+ isValid = true;
+ return isValid;
+}
+
+
IconButton *UrlBar::addRightIcon(UrlBar::icon ic)
{
IconButton *rightIcon = new IconButton(this);
@@ -696,6 +717,14 @@ void UrlBar::pasteAndGo()
}
+void UrlBar::pasteAndSearch()
+{
+ KService::Ptr defaultEngine = SearchEngine::defaultEngine();
+ if (defaultEngine)
+ activated(KUrl(SearchEngine::buildQuery(defaultEngine, rApp->clipboard()->text())));
+}
+
+
void UrlBar::delSlot()
{
del();
diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h
index 7059725b..a9ce301d 100644
--- a/src/urlbar/urlbar.h
+++ b/src/urlbar/urlbar.h
@@ -116,7 +116,9 @@ private Q_SLOTS:
void refreshFavicon();
void pasteAndGo();
+ void pasteAndSearch();
void delSlot();
+ bool isValidURL(QString url);
protected:
void paintEvent(QPaintEvent *event);