2011-09-23 22:06:21 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2013-02-08 18:44:26 +01:00
|
|
|
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
|
2011-09-23 22:06:21 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2011-04-15 20:46:51 +02:00
|
|
|
#include "bookmarkicon.h"
|
2013-02-10 12:28:53 +01:00
|
|
|
#include "bookmarksmodel.h"
|
|
|
|
#include "bookmarkswidget.h"
|
2011-04-15 20:46:51 +02:00
|
|
|
#include "mainapplication.h"
|
2012-01-21 23:19:38 +01:00
|
|
|
#include "tabbedwebview.h"
|
|
|
|
#include "locationbar.h"
|
2012-02-05 16:00:23 +01:00
|
|
|
#include "pluginproxy.h"
|
|
|
|
#include "speeddial.h"
|
2011-04-15 20:46:51 +02:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QStyle>
|
2012-08-31 15:19:07 +02:00
|
|
|
#include <QContextMenuEvent>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2013-02-08 18:44:26 +01:00
|
|
|
BookmarkIcon::BookmarkIcon(QWidget* parent)
|
2011-04-15 20:46:51 +02:00
|
|
|
: ClickableLabel(parent)
|
|
|
|
, m_bookmarksModel(0)
|
2012-02-05 16:00:23 +01:00
|
|
|
, m_speedDial(mApp->plugins()->speedDial())
|
2013-02-10 12:28:53 +01:00
|
|
|
, m_view(0)
|
2011-04-15 20:46:51 +02:00
|
|
|
{
|
2011-09-11 19:15:06 +02:00
|
|
|
setObjectName("locationbar-bookmarkicon");
|
2011-04-15 20:46:51 +02:00
|
|
|
setCursor(Qt::PointingHandCursor);
|
|
|
|
setToolTip(tr("Bookmark this Page"));
|
|
|
|
setFocusPolicy(Qt::ClickFocus);
|
|
|
|
|
|
|
|
m_bookmarksModel = mApp->bookmarksModel();
|
|
|
|
connect(m_bookmarksModel, SIGNAL(bookmarkAdded(BookmarksModel::Bookmark)), this, SLOT(bookmarkAdded(BookmarksModel::Bookmark)));
|
|
|
|
connect(m_bookmarksModel, SIGNAL(bookmarkDeleted(BookmarksModel::Bookmark)), this, SLOT(bookmarkDeleted(BookmarksModel::Bookmark)));
|
2012-02-05 16:00:23 +01:00
|
|
|
connect(m_speedDial, SIGNAL(pagesChanged()), this, SLOT(speedDialChanged()));
|
2013-02-10 12:28:53 +01:00
|
|
|
connect(this, SIGNAL(clicked(QPoint)), this, SLOT(iconClicked()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarkIcon::setWebView(WebView* view)
|
|
|
|
{
|
|
|
|
m_view = view;
|
2011-04-15 20:46:51 +02:00
|
|
|
}
|
|
|
|
|
2012-02-05 16:00:23 +01:00
|
|
|
void BookmarkIcon::checkBookmark(const QUrl &url, bool forceCheck)
|
2011-04-15 20:46:51 +02:00
|
|
|
{
|
2012-02-05 16:00:23 +01:00
|
|
|
if (!forceCheck && m_lastUrl == url) {
|
2011-04-15 20:46:51 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-15 20:46:51 +02:00
|
|
|
|
2012-02-05 16:00:23 +01:00
|
|
|
if (m_bookmarksModel->isBookmarked(url) || !m_speedDial->pageForUrl(url).url.isEmpty()) {
|
2011-04-15 20:46:51 +02:00
|
|
|
setBookmarkSaved();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-04-15 20:46:51 +02:00
|
|
|
setBookmarkDisabled();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-15 20:46:51 +02:00
|
|
|
|
|
|
|
m_lastUrl = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarkIcon::bookmarkDeleted(const BookmarksModel::Bookmark &bookmark)
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (bookmark.url == m_lastUrl) {
|
2012-02-05 16:00:23 +01:00
|
|
|
checkBookmark(m_lastUrl, true);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-15 20:46:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarkIcon::bookmarkAdded(const BookmarksModel::Bookmark &bookmark)
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (bookmark.url == m_lastUrl) {
|
2012-02-05 16:00:23 +01:00
|
|
|
checkBookmark(m_lastUrl, true);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-15 20:46:51 +02:00
|
|
|
}
|
2011-09-11 19:15:06 +02:00
|
|
|
|
2012-02-05 16:00:23 +01:00
|
|
|
void BookmarkIcon::speedDialChanged()
|
|
|
|
{
|
|
|
|
checkBookmark(m_lastUrl, true);
|
|
|
|
}
|
|
|
|
|
2013-02-10 12:28:53 +01:00
|
|
|
void BookmarkIcon::iconClicked()
|
|
|
|
{
|
|
|
|
if (!m_view) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BookmarksWidget* widget = new BookmarksWidget(m_view, parentWidget());
|
|
|
|
widget->showAt(parentWidget());
|
|
|
|
}
|
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
void BookmarkIcon::setBookmarkSaved()
|
|
|
|
{
|
2012-06-26 11:49:39 +02:00
|
|
|
setProperty("bookmarked", QVariant(true));
|
2011-09-11 19:15:06 +02:00
|
|
|
style()->unpolish(this);
|
|
|
|
style()->polish(this);
|
|
|
|
setToolTip(tr("Edit this bookmark"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarkIcon::setBookmarkDisabled()
|
|
|
|
{
|
2012-06-26 11:49:39 +02:00
|
|
|
setProperty("bookmarked", QVariant(false));
|
2011-09-11 19:15:06 +02:00
|
|
|
style()->unpolish(this);
|
|
|
|
style()->polish(this);
|
|
|
|
setToolTip(tr("Bookmark this Page"));
|
|
|
|
}
|
2011-12-27 18:50:52 +01:00
|
|
|
|
2012-03-05 11:30:18 +01:00
|
|
|
void BookmarkIcon::contextMenuEvent(QContextMenuEvent* ev)
|
|
|
|
{
|
|
|
|
// Prevent propagating to LocationBar
|
|
|
|
ev->accept();
|
|
|
|
}
|
|
|
|
|
2011-12-27 19:10:53 +01:00
|
|
|
void BookmarkIcon::mousePressEvent(QMouseEvent* ev)
|
2011-12-27 18:50:52 +01:00
|
|
|
{
|
|
|
|
ClickableLabel::mousePressEvent(ev);
|
|
|
|
|
|
|
|
// Prevent propagating to LocationBar
|
|
|
|
ev->accept();
|
|
|
|
}
|