summaryrefslogtreecommitdiff
path: root/src/urlbar/urlbar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/urlbar/urlbar.cpp')
-rw-r--r--src/urlbar/urlbar.cpp33
1 files changed, 31 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();