Bug 250623 - Support for bookmarklets
Summary: Support for bookmarklets
Status: RESOLVED FIXED
Alias: None
Product: rekonq
Classification: Applications
Component: general (show other bugs)
Version: 0.5.0
Platform: Arch Linux Linux
: NOR wishlist
Target Milestone: 0.7
Assignee: Yoann Laissus
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-09 04:13 UTC by Shane
Modified: 2010-09-18 06:29 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Shane 2010-09-09 04:13:58 UTC
Version:           0.5.0 (using KDE 4.5.0) 
OS:                Linux

Does rekonq support bookmarklets?

I use Google reader a lot and there is a bookmarklet to share articles. In Firefox and Chrome I can drag it to the bookmark toolbar and then simply click it when I want to share an article. In rekonq I can only drag this button to the address bar which runs a Google search for the Javasrcipt.

In Opera I can save the bookmarklet link as a bookmark and then select the link from the bookmarks menu to share. This method also does not work in rekonq. It runs the Google search.

Can you please try to implement support for bookmarklets. I really like rekonq and I don't want to go back to a non-KDE browser.

Reproducible: Always

Steps to Reproduce:
1. Drag bookmarklet to bookmarks toolbar

or

1. Save bookmarklet link as bookmark
2. Select bookmarklet from bookmarks to activate bookmarklet.

Actual Results:  
Bookmarklet cannot be dropped in bookmarks toolbar. If added manually it runs a Google search instead.

Expected Results:  
Bookmarklet should be added to the toolbar and clicking it should activate bookmarklet action (e.g. share article with Google reader)
Comment 1 Yoann Laissus 2010-09-18 01:44:21 UTC
commit ef2d5465aee86115cca6343cbaeacca4ed699b12
Author: Yoann Laissus <yoann.laissus@gmail.com>
Date:   Wed Sep 15 23:41:49 2010 +0200

    - Bookmarklet support
    - text/uri-list drops in the BK toolbar
    - Don't allow other drag than bookmarks in the BK panel (for the moment)
    - A little cleanup
    
    BUG: 250623

diff --git a/src/bookmarks/bookmarkstoolbar.cpp b/src/bookmarks/bookmarkstoolbar.cpp
index 4eff2e5..60b59a3 100644
--- a/src/bookmarks/bookmarkstoolbar.cpp
+++ b/src/bookmarks/bookmarkstoolbar.cpp
@@ -278,33 +278,25 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event)
         else if (event->type() == QEvent::DragEnter)
         {
             QDragEnterEvent *dragEvent = static_cast<QDragEnterEvent*>(event);
-            if (dragEvent->mimeData()->hasFormat("application/rekonq-bookmark"))
+            if (dragEvent->mimeData()->hasFormat("application/rekonq-bookmark") || dragEvent->mimeData()->hasFormat("text/uri-list"))
             {
-                QByteArray addresses = dragEvent->mimeData()->data("application/rekonq-bookmark");
-                KBookmark bookmark = Application::bookmarkProvider()->bookmarkManager()->findByAddress(QString::fromLatin1(addresses.data()));
+                QFrame* dropIndicatorWidget = new QFrame(toolBar());
+                dropIndicatorWidget->setFrameShape(QFrame::VLine);
+                m_dropAction = toolBar()->insertWidget(toolBar()->actionAt(dragEvent->pos()), dropIndicatorWidget);
 
-                if (!bookmark.isNull())
-                {
-                    QFrame* dropIndicatorWidget = new QFrame(toolBar());
-                    dropIndicatorWidget->setFrameShape(QFrame::VLine);
-                    m_dropAction = toolBar()->insertWidget(toolBar()->actionAt(dragEvent->pos()), dropIndicatorWidget);
-
-                    dragEvent->accept();
-                }
+                dragEvent->accept();
             }
         }
         else if (event->type() == QEvent::DragMove)
         {
             QDragMoveEvent *dragEvent = static_cast<QDragMoveEvent*>(event);
-            if (dragEvent->mimeData()->hasFormat("application/rekonq-bookmark"))
+            if (dragEvent->mimeData()->hasFormat("application/rekonq-bookmark") || dragEvent->mimeData()->hasFormat("text/uri-list"))
             {
-                QByteArray addresses = dragEvent->mimeData()->data("application/rekonq-bookmark");
-                KBookmark bookmark = Application::bookmarkProvider()->bookmarkManager()->findByAddress(QString::fromLatin1(addresses.data()));
                 QAction *overAction = toolBar()->actionAt(dragEvent->pos());
                 KBookmarkActionInterface *overActionBK = dynamic_cast<KBookmarkActionInterface*>(overAction);
                 QWidget *widgetAction = toolBar()->widgetForAction(overAction);
 
-                if (!bookmark.isNull() && overAction != m_dropAction && overActionBK && widgetAction && m_dropAction)
+                if (overAction != m_dropAction && overActionBK && widgetAction && m_dropAction)
                 {
                     toolBar()->removeAction(m_dropAction);
 
@@ -338,10 +330,26 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event)
         else if (event->type() == QEvent::Drop)
         {
             QDropEvent *dropEvent = static_cast<QDropEvent*>(event);
-            QByteArray addresses = dropEvent->mimeData()->data("application/rekonq-bookmark");
-            KBookmark bookmark = Application::bookmarkProvider()->bookmarkManager()->findByAddress(QString::fromLatin1(addresses.data()));
+            KBookmark bookmark;
+            QUrl url;
+            QString title;
 
-            if (!dropEvent->mimeData()->hasFormat("application/rekonq-bookmark") && !bookmark.isNull())
+            if (dropEvent->mimeData()->hasFormat("application/rekonq-bookmark"))
+            {
+                QByteArray addresses = dropEvent->mimeData()->data("application/rekonq-bookmark");
+                bookmark =  Application::bookmarkProvider()->bookmarkManager()->findByAddress(QString::fromLatin1(addresses.data()));
+                if (bookmark.isNull())
+                    return QObject::eventFilter(watched, event);
+
+                url = bookmark.url();
+                title = bookmark.fullText();
+            }
+            else if (dropEvent->mimeData()->hasFormat("text/uri-list"))
+            {
+                title = dropEvent->mimeData()->text();
+                url = dropEvent->mimeData()->urls().at(0).toString();
+            }
+            else
             {
                 return QObject::eventFilter(watched, event);
             }
@@ -366,11 +374,12 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event)
                 KBookmarkActionInterface *destBookmarkAction = dynamic_cast<KBookmarkActionInterface *>(destAction);
                 QWidget *widgetAction = toolBar()->widgetForAction(destAction);
 
-                if (destBookmarkAction && !destBookmarkAction->bookmark().isNull()
-                    && widgetAction && bookmark.address() != destBookmarkAction->bookmark().address())
+                if (destBookmarkAction && !destBookmarkAction->bookmark().isNull() && widgetAction
+                    && bookmark.address() != destBookmarkAction->bookmark().address())
                 {
                     KBookmark destBookmark = destBookmarkAction->bookmark();
                     root.deleteBookmark(bookmark);
+                    bookmark = root.addBookmark(title, url);
 
                     if ((dropEvent->pos().x() - widgetAction->pos().x()) > (widgetAction->width() / 2))
                     {
@@ -380,20 +389,18 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event)
                     {
                         root.moveBookmark(bookmark, destBookmark.parentGroup().previous(destBookmark));
                     }
+
                     Application::bookmarkProvider()->bookmarkManager()->emitChanged();
                 }
             }
             else
             {
                 root.deleteBookmark(bookmark);
-                if (QCursor::pos().x() < toolBar()->widgetForAction(toolBar()->actions().first())->pos().x())
+                bookmark = root.addBookmark(title, url);
+                if (dropEvent->pos().x() < toolBar()->widgetForAction(toolBar()->actions().first())->pos().x())
                 {
                     root.moveBookmark(bookmark, KBookmark());
                 }
-                else
-                {
-                    root.addBookmark(bookmark);
-                }
 
                 Application::bookmarkProvider()->bookmarkManager()->emitChanged();
             }
diff --git a/src/bookmarks/bookmarkstreemodel.cpp b/src/bookmarks/bookmarkstreemodel.cpp
index 8d702fb..f13cee4 100644
--- a/src/bookmarks/bookmarkstreemodel.cpp
+++ b/src/bookmarks/bookmarkstreemodel.cpp
@@ -268,7 +268,7 @@ QVariant BookmarksTreeModel::data(const QModelIndex &index, int role) const
 
 QStringList BookmarksTreeModel::mimeTypes() const
 {
-    return KBookmark::List::mimeDataTypes();
+    return QStringList("application/rekonq-bookmark");
 }
 
 
diff --git a/src/filterurljob.cpp b/src/filterurljob.cpp
index b27df74..c5ffa60 100644
--- a/src/filterurljob.cpp
+++ b/src/filterurljob.cpp
@@ -60,6 +60,12 @@ void FilterUrlJob::run()
 {
     // this should let rekonq filtering URI info and supporting
     // the beautiful KDE web browsing shortcuts
+
+    if (_urlString.startsWith("javascript:"))
+    {
+        _url = KUrl(_urlString);
+        return;
+    }
     KUriFilterData data(_urlString);
     data.setCheckForExecutables(false); // if true, queries like "rekonq" or "dolphin" are considered as executables
Comment 2 Shane 2010-09-18 06:29:33 UTC
Yoann!  Thank you so, so much for this fix! I shared this bug report using the bookmarklet. Awesome!