summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFurkan Uzumcu <furkanuzumcu@gmail.com>2011-10-21 17:34:20 +0200
committerAndrea Diamantini <adjam7@gmail.com>2011-10-21 17:34:20 +0200
commit2668d6425b3573368150c95c253c653d3362136f (patch)
treee10f0d74c690ffaaf5ddc0e82646f25e23aaefe6
parentMerge branch 'master' of git://anongit.kde.org/rekonq (diff)
downloadrekonq-2668d6425b3573368150c95c253c653d3362136f.tar.xz
Enable url or text drops in the tabbar
Dropping urls in the tabbar loads them in new tabs, while dropping text searches it on your default search engine. REVIEW: 102811 REVIEWED-BY: adjam
-rw-r--r--src/tabbar.cpp50
-rw-r--r--src/tabbar.h3
2 files changed, 53 insertions, 0 deletions
diff --git a/src/tabbar.cpp b/src/tabbar.cpp
index ea01ef9b..74c339e0 100644
--- a/src/tabbar.cpp
+++ b/src/tabbar.cpp
@@ -43,6 +43,7 @@
#include "websnap.h"
#include "tabhighlighteffect.h"
#include "tabpreviewpopup.h"
+#include "searchengine.h"
// KDE Includes
#include <KActionMenu>
@@ -88,6 +89,7 @@ TabBar::TabBar(QWidget *parent)
setGraphicsEffect(m_tabHighlightEffect);
setAnimatedTabHighlighting(ReKonfig::animatedTabHighlighting());
+ setAcceptDrops(true);
}
@@ -479,3 +481,51 @@ void TabBar::setAnimatedTabHighlighting(bool enabled)
}
}
}
+
+void TabBar::dropEvent(QDropEvent* event)
+{
+ if (event->mimeData()->hasUrls())
+ {
+ int urlCount = event->mimeData()->urls().count();
+ if (urlCount > 1)
+ {
+ Q_FOREACH (const QUrl url, event->mimeData()->urls())
+ rApp->loadUrl(url, Rekonq::NewTab);
+ }
+ else
+ rApp->loadUrl(event->mimeData()->urls().first(), Rekonq::NewFocusedTab);
+ }
+ else if (event->mimeData()->hasText())
+ {
+ //In case the text is a valid URL
+ if (isURLValid(event->mimeData()->text()))
+ rApp->loadUrl(KUrl(event->mimeData()->text()), Rekonq::NewFocusedTab);
+ else
+ {
+ KService::Ptr defaultSearchEngine = SearchEngine::defaultEngine();
+ if (defaultSearchEngine)
+ rApp->loadUrl(KUrl(SearchEngine::buildQuery(defaultSearchEngine, event->mimeData()->text())), Rekonq::NewFocusedTab);
+ }
+ }
+ KTabBar::dropEvent(event);
+}
+
+void TabBar::dragEnterEvent(QDragEnterEvent* event)
+{
+ if (event->mimeData()->hasUrls() || event->mimeData()->hasText())
+ event->acceptProposedAction();
+ else
+ KTabBar::dragEnterEvent(event);
+}
+
+bool TabBar::isURLValid(const QString &url)
+{
+ QString editedURL = url;
+ bool isValid = false;
+ if (editedURL.startsWith("http://") || editedURL.startsWith("https://") || editedURL.startsWith("ftp://"))
+ editedURL = editedURL.remove(QRegExp("(http|https|ftp)://"));
+ if (editedURL.contains('.') && editedURL.indexOf('.') > 0 && editedURL.indexOf('.') < editedURL.length() && !editedURL.trimmed().contains(" ")
+ && QUrl::fromUserInput(editedURL).isValid())
+ isValid = true;
+ return isValid;
+}
diff --git a/src/tabbar.h b/src/tabbar.h
index b4c816b7..1cb66592 100644
--- a/src/tabbar.h
+++ b/src/tabbar.h
@@ -88,6 +88,8 @@ protected:
virtual void mousePressEvent(QMouseEvent *event);
virtual void tabRemoved(int index);
+ void dropEvent(QDropEvent *event);
+ void dragEnterEvent(QDragEnterEvent *event);
private slots:
void cloneTab();
@@ -102,6 +104,7 @@ private slots:
void showTabPreview();
void removeAnimation(int index);
+ bool isURLValid(const QString &url);
private:
void setupHistoryActions();