summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFurkan Uzumcu <furkanuzumcu@gmail.com>2011-09-18 23:32:47 +0200
committerAndrea Diamantini <adjam7@gmail.com>2011-09-18 23:32:47 +0200
commit3ed265b387092e2f112ea1c9933501b3bf64d551 (patch)
tree29596f3ea223ad6a42dd45b6479bd481e2f1272d
parentshow notifyPopup at right edge if find- or zoombar is visible (diff)
downloadrekonq-3ed265b387092e2f112ea1c9933501b3bf64d551.tar.xz
Change "Paste & Go" action's text to "Paste & Search" if the content
of the clipboard is not an URL REVIEW: 102441 REVIEWED-BY: adjam
-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);