diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bookmarks/bookmarkstoolbar.cpp | 57 | ||||
-rw-r--r-- | src/bookmarks/bookmarkstreemodel.cpp | 2 | ||||
-rw-r--r-- | src/filterurljob.cpp | 7 | ||||
-rw-r--r-- | src/newtabpage.cpp | 4 | ||||
-rw-r--r-- | src/previewselectorbar.cpp | 6 | ||||
-rw-r--r-- | src/websnap.cpp | 11 | ||||
-rw-r--r-- | src/websnap.h | 13 |
7 files changed, 58 insertions, 42 deletions
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<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 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..c0632752 100644 --- a/src/filterurljob.cpp +++ b/src/filterurljob.cpp @@ -58,6 +58,13 @@ KUrl FilterUrlJob::url() void FilterUrlJob::run() { + // 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); diff --git a/src/newtabpage.cpp b/src/newtabpage.cpp index e579e7b9..f5c9c186 100644 --- a/src/newtabpage.cpp +++ b/src/newtabpage.cpp @@ -238,7 +238,7 @@ QWebElement NewTabPage::loadingPreview(int index, const KUrl &url) // 2) to "auto-destroy" snaps on tab closing :) QWebFrame *frame = qobject_cast<QWebFrame *>(parent()); WebSnap *snap = new WebSnap(url, frame); - connect(snap, SIGNAL(snapDone(bool)), frame->page(), SLOT(updateImage(bool))); + connect(snap, SIGNAL(snapDone(bool)), frame->page(), SLOT(updateImage(bool)), Qt::UniqueConnection); return prev; } @@ -247,7 +247,6 @@ QWebElement NewTabPage::validPreview(int index, const KUrl &url, const QString & { QWebElement prev = markup(".thumbnail"); QString previewPath = QL1S("file://") + WebSnap::imagePathFromUrl(url); - QString iString = QVariant(index).toString(); prev.findFirst(".preview img").setAttribute("src" , previewPath); prev.findFirst("a").setAttribute("href", url.toMimeDataString()); // NOTE ? @@ -256,7 +255,6 @@ QWebElement NewTabPage::validPreview(int index, const KUrl &url, const QString & setupPreview(prev, index); showControls(prev); - return prev; } diff --git a/src/previewselectorbar.cpp b/src/previewselectorbar.cpp index 209a0a92..1b3d3380 100644 --- a/src/previewselectorbar.cpp +++ b/src/previewselectorbar.cpp @@ -31,6 +31,7 @@ // Self Includes #include "rekonq.h" +#include "websnap.h" // Local Include #include "application.h" @@ -126,6 +127,11 @@ void PreviewSelectorBar::clicked() KUrl url = page->mainFrame()->url(); QStringList names = ReKonfig::previewNames(); QStringList urls = ReKonfig::previewUrls(); + //cleanup the previous image from the cache (useful to refresh the snapshot) + QFile::remove(WebSnap::imagePathFromUrl(urls.at(m_previewIndex))); + page->mainFrame()->setScrollBarValue(Qt::Vertical, 0); + QPixmap preview = WebSnap::renderPagePreview(*page); + preview.save(WebSnap::imagePathFromUrl(url)); urls.replace(m_previewIndex, url.toMimeDataString()); names.replace(m_previewIndex, page->mainFrame()->title()); diff --git a/src/websnap.cpp b/src/websnap.cpp index afa08c64..54cf1053 100644 --- a/src/websnap.cpp +++ b/src/websnap.cpp @@ -38,7 +38,6 @@ // Qt Includes #include <QtCore/QSize> -#include <QtCore/QTimer> #include <QtCore/QFile> #include <QtGui/QPainter> @@ -61,7 +60,7 @@ WebSnap::WebSnap(const KUrl& url, QObject *parent) connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(saveResult(bool))); - QTimer::singleShot(0, this, SLOT(load())); + QMetaObject::invokeMethod(this, "load", Qt::QueuedConnection); } @@ -184,9 +183,9 @@ QPixmap WebSnap::renderPagePreview(const QWebPage &page, int w, int h) QString WebSnap::imagePathFromUrl(const KUrl &url) { QUrl temp = QUrl(url.url()); - QString name = temp.toString(QUrl::RemoveScheme | QUrl::RemoveUserInfo | QUrl::StripTrailingSlash); - name.remove(QRegExp(QL1S("[&+=_?./-]"))); - return KStandardDirs::locateLocal("cache", QString("thumbs/") + name + ".png", true); + QByteArray name = temp.toEncoded(QUrl::RemoveScheme | QUrl::RemoveUserInfo | QUrl::StripTrailingSlash); + + return KStandardDirs::locateLocal("cache", QString("thumbs/") + name.toBase64() + ".png", true); } @@ -194,7 +193,7 @@ void WebSnap::saveResult(bool ok) { if (ok) { - QPixmap image = renderPagePreview(m_page, WIDTH, HEIGHT); + QPixmap image = renderPagePreview(m_page, defaultWidth, defaultHeight); QString path = imagePathFromUrl(m_url); QFile::remove(path); image.save(path); diff --git a/src/websnap.h b/src/websnap.h index 5bad952d..e5b550fc 100644 --- a/src/websnap.h +++ b/src/websnap.h @@ -43,11 +43,6 @@ // Forward Declarations class QPixmap; -// Defines -#define WIDTH 200 -#define HEIGHT 150 - - /** * This class is used in many classes of rekonq to produce an image * based on the site corresponding to the url passed as argument. @@ -63,6 +58,7 @@ class QPixmap; * - NewTabPage class: to show the favorites page "preview" (given an url, you show AND save an image) * */ + class REKONQ_TESTS_EXPORT WebSnap : public QObject { Q_OBJECT @@ -88,7 +84,7 @@ public: * * @return the pixmap snapped from the page */ - static QPixmap renderPagePreview(const QWebPage &page, int w = WIDTH, int h = HEIGHT); + static QPixmap renderPagePreview(const QWebPage &page, int w = defaultWidth, int h = defaultHeight); // static QPixmap renderVisiblePagePreview(const QWebPage &page, int w = WIDTH, int h = HEIGHT); TODO: try to make this method work => more previews for the urlbar @@ -101,7 +97,7 @@ public: * * @return the pixmap snapped from the page */ - static QPixmap renderClosingPagePreview(const QWebPage &page, int w = WIDTH, int h = HEIGHT); + static QPixmap renderClosingPagePreview(const QWebPage &page, int w = defaultWidth, int h = defaultHeight); /** * Snaps a pixmap of size w * h from a page for tab preview @@ -139,6 +135,9 @@ signals: void snapDone(bool ok); private: + // Constants + static const int defaultWidth = 200; + static const int defaultHeight = 150; QWebPage m_page; KUrl m_url; |