From ef2d5465aee86115cca6343cbaeacca4ed699b12 Mon Sep 17 00:00:00 2001 From: Yoann Laissus Date: Wed, 15 Sep 2010 23:41:49 +0200 Subject: - 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 --- src/bookmarks/bookmarkstoolbar.cpp | 57 ++++++++++++++++++++---------------- src/bookmarks/bookmarkstreemodel.cpp | 2 +- src/filterurljob.cpp | 6 ++++ 3 files changed, 39 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/bookmarks/bookmarkstoolbar.cpp b/src/bookmarks/bookmarkstoolbar.cpp index 4eff2e52..60b59a3f 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(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(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(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(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(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 8d702fb9..f13cee42 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 b27df74c..c5ffa607 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 -- cgit v1.2.1 From c985ba7e684cf99b4d16f1c2ed1cb4ca126fa5ac Mon Sep 17 00:00:00 2001 From: Yoann Laissus Date: Wed, 15 Sep 2010 23:48:08 +0200 Subject: Add a comment --- src/filterurljob.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/filterurljob.cpp b/src/filterurljob.cpp index c5ffa607..c0632752 100644 --- a/src/filterurljob.cpp +++ b/src/filterurljob.cpp @@ -58,14 +58,15 @@ KUrl FilterUrlJob::url() void FilterUrlJob::run() { - // this should let rekonq filtering URI info and supporting - // the beautiful KDE web browsing shortcuts - + // Bookmarklets handling if (_urlString.startsWith("javascript:")) { _url = KUrl(_urlString); return; } + + // this should let rekonq filtering URI info and supporting + // the beautiful KDE web browsing shortcuts KUriFilterData data(_urlString); data.setCheckForExecutables(false); // if true, queries like "rekonq" or "dolphin" are considered as executables -- cgit v1.2.1