2011-09-23 22:06:21 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-05 11:01:57 +01:00
|
|
|
* Copyright (C) 2010-2014 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/>.
|
|
|
|
* ============================================================ */
|
2014-02-09 12:22:49 +01:00
|
|
|
#include "bookmarksicon.h"
|
2013-02-10 12:28:53 +01:00
|
|
|
#include "bookmarkswidget.h"
|
2014-02-09 12:18:52 +01:00
|
|
|
#include "bookmarks.h"
|
2011-04-15 20:46:51 +02:00
|
|
|
#include "mainapplication.h"
|
2014-02-09 12:18:52 +01:00
|
|
|
#include "webview.h"
|
2012-01-21 23:19:38 +01:00
|
|
|
#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
|
|
|
|
2014-02-09 12:22:49 +01:00
|
|
|
BookmarksIcon::BookmarksIcon(QWidget* parent)
|
2011-04-15 20:46:51 +02:00
|
|
|
: ClickableLabel(parent)
|
2013-02-10 12:28:53 +01:00
|
|
|
, m_view(0)
|
2014-02-09 12:18:52 +01:00
|
|
|
, m_bookmark(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);
|
|
|
|
|
2014-02-09 12:18:52 +01:00
|
|
|
connect(mApp->bookmarks(), SIGNAL(bookmarkAdded(BookmarkItem*)), this, SLOT(bookmarksChanged()));
|
|
|
|
connect(mApp->bookmarks(), SIGNAL(bookmarkRemoved(BookmarkItem*)), this, SLOT(bookmarksChanged()));
|
|
|
|
connect(mApp->bookmarks(), SIGNAL(bookmarkChanged(BookmarkItem*)), this, SLOT(bookmarksChanged()));
|
2015-01-27 11:01:52 +01:00
|
|
|
#if QTWEBENGINE_DISABLED
|
2014-02-09 12:18:52 +01:00
|
|
|
connect(mApp->plugins()->speedDial(), SIGNAL(pagesChanged()), this, SLOT(speedDialChanged()));
|
2015-01-27 11:01:52 +01:00
|
|
|
#endif
|
2014-02-09 12:18:52 +01:00
|
|
|
|
2013-02-10 12:28:53 +01:00
|
|
|
connect(this, SIGNAL(clicked(QPoint)), this, SLOT(iconClicked()));
|
|
|
|
}
|
|
|
|
|
2014-02-09 12:22:49 +01:00
|
|
|
void BookmarksIcon::setWebView(WebView* view)
|
2013-02-10 12:28:53 +01:00
|
|
|
{
|
|
|
|
m_view = view;
|
2011-04-15 20:46:51 +02:00
|
|
|
}
|
|
|
|
|
2014-02-09 12:22:49 +01:00
|
|
|
void BookmarksIcon::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
|
|
|
|
2014-02-09 12:18:52 +01:00
|
|
|
QList<BookmarkItem*> items = mApp->bookmarks()->searchBookmarks(url);
|
|
|
|
m_bookmark = items.isEmpty() ? 0 : items.first();
|
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
if (m_bookmark /*|| !mApp->plugins()->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;
|
|
|
|
}
|
|
|
|
|
2014-02-09 12:22:49 +01:00
|
|
|
void BookmarksIcon::bookmarksChanged()
|
2011-04-15 20:46:51 +02:00
|
|
|
{
|
2014-02-09 12:18:52 +01:00
|
|
|
checkBookmark(m_lastUrl, true);
|
2011-04-15 20:46:51 +02:00
|
|
|
}
|
2011-09-11 19:15:06 +02:00
|
|
|
|
2014-02-09 12:22:49 +01:00
|
|
|
void BookmarksIcon::speedDialChanged()
|
2012-02-05 16:00:23 +01:00
|
|
|
{
|
|
|
|
checkBookmark(m_lastUrl, true);
|
|
|
|
}
|
|
|
|
|
2014-02-09 12:22:49 +01:00
|
|
|
void BookmarksIcon::iconClicked()
|
2013-02-10 12:28:53 +01:00
|
|
|
{
|
2014-09-25 18:47:32 +02:00
|
|
|
if (!m_view) {
|
2013-02-10 12:28:53 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-09 12:18:52 +01:00
|
|
|
BookmarksWidget* widget = new BookmarksWidget(m_view, m_bookmark, parentWidget());
|
2013-02-10 12:28:53 +01:00
|
|
|
widget->showAt(parentWidget());
|
|
|
|
}
|
|
|
|
|
2014-02-09 12:22:49 +01:00
|
|
|
void BookmarksIcon::setBookmarkSaved()
|
2011-09-11 19:15:06 +02:00
|
|
|
{
|
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"));
|
|
|
|
}
|
|
|
|
|
2014-02-09 12:22:49 +01:00
|
|
|
void BookmarksIcon::setBookmarkDisabled()
|
2011-09-11 19:15:06 +02:00
|
|
|
{
|
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
|
|
|
|
2014-02-09 12:22:49 +01:00
|
|
|
void BookmarksIcon::contextMenuEvent(QContextMenuEvent* ev)
|
2012-03-05 11:30:18 +01:00
|
|
|
{
|
|
|
|
// Prevent propagating to LocationBar
|
|
|
|
ev->accept();
|
|
|
|
}
|
|
|
|
|
2014-02-09 12:22:49 +01:00
|
|
|
void BookmarksIcon::mousePressEvent(QMouseEvent* ev)
|
2011-12-27 18:50:52 +01:00
|
|
|
{
|
|
|
|
ClickableLabel::mousePressEvent(ev);
|
|
|
|
|
|
|
|
// Prevent propagating to LocationBar
|
|
|
|
ev->accept();
|
|
|
|
}
|