2014-02-06 17:07:19 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
|
|
|
* Copyright (C) 2014 David Rosca <nowrep@gmail.com>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
* ============================================================ */
|
|
|
|
#include "bookmarkitem.h"
|
2014-02-10 16:03:29 +01:00
|
|
|
#include "iconprovider.h"
|
2014-02-06 17:07:19 +01:00
|
|
|
|
2014-02-07 22:48:30 +01:00
|
|
|
BookmarkItem::BookmarkItem(BookmarkItem::Type type, BookmarkItem* parent)
|
2014-02-06 17:07:19 +01:00
|
|
|
: m_type(type)
|
|
|
|
, m_parent(parent)
|
2014-02-09 13:34:52 +01:00
|
|
|
, m_visitCount(0)
|
2014-02-06 17:07:19 +01:00
|
|
|
, m_expanded(false)
|
2014-02-09 11:02:51 +01:00
|
|
|
, m_sidebarExpanded(false)
|
2014-02-06 17:07:19 +01:00
|
|
|
{
|
|
|
|
if (m_parent) {
|
|
|
|
parent->addChild(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BookmarkItem::~BookmarkItem()
|
|
|
|
{
|
|
|
|
qDeleteAll(m_children);
|
|
|
|
}
|
|
|
|
|
|
|
|
BookmarkItem::Type BookmarkItem::type() const
|
|
|
|
{
|
|
|
|
return m_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarkItem::setType(BookmarkItem::Type type)
|
|
|
|
{
|
|
|
|
m_type = type;
|
|
|
|
}
|
|
|
|
|
2014-02-08 18:28:01 +01:00
|
|
|
bool BookmarkItem::isFolder() const
|
|
|
|
{
|
|
|
|
return m_type == Folder;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BookmarkItem::isUrl() const
|
|
|
|
{
|
|
|
|
return m_type == Url;
|
|
|
|
}
|
|
|
|
|
2014-02-08 20:01:07 +01:00
|
|
|
bool BookmarkItem::isSeparator() const
|
2014-02-08 18:28:01 +01:00
|
|
|
{
|
|
|
|
return m_type == Separator;
|
|
|
|
}
|
|
|
|
|
2014-02-07 22:48:30 +01:00
|
|
|
BookmarkItem* BookmarkItem::parent() const
|
2014-02-06 17:07:19 +01:00
|
|
|
{
|
2014-02-10 16:03:29 +01:00
|
|
|
return m_parent;
|
2014-02-06 17:07:19 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 22:48:30 +01:00
|
|
|
QList<BookmarkItem*> BookmarkItem::children() const
|
2014-02-06 17:07:19 +01:00
|
|
|
{
|
|
|
|
return m_children;
|
|
|
|
}
|
|
|
|
|
2016-12-28 20:26:03 +01:00
|
|
|
QIcon BookmarkItem::icon()
|
2014-02-10 16:03:29 +01:00
|
|
|
{
|
2016-12-28 20:26:03 +01:00
|
|
|
// Cache icon for 20 seconds
|
|
|
|
const int iconCacheTime = 20 * 1000;
|
|
|
|
|
2014-02-10 16:03:29 +01:00
|
|
|
switch (m_type) {
|
|
|
|
case Url:
|
2016-12-28 20:26:03 +01:00
|
|
|
if (m_iconTime.isNull() || m_iconTime.elapsed() > iconCacheTime) {
|
|
|
|
m_icon = IconProvider::iconForUrl(m_url);
|
|
|
|
m_iconTime.restart();
|
2014-02-10 16:03:29 +01:00
|
|
|
}
|
|
|
|
return m_icon;
|
|
|
|
case Folder:
|
2014-03-07 18:03:42 +01:00
|
|
|
return IconProvider::standardIcon(QStyle::SP_DirIcon);
|
2014-02-10 16:03:29 +01:00
|
|
|
default:
|
|
|
|
return QIcon();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-11 10:24:10 +01:00
|
|
|
void BookmarkItem::setIcon(const QIcon &icon)
|
|
|
|
{
|
|
|
|
m_icon = icon;
|
|
|
|
}
|
|
|
|
|
2014-02-09 15:44:38 +01:00
|
|
|
QString BookmarkItem::urlString() const
|
|
|
|
{
|
|
|
|
return QString::fromUtf8(m_url.toEncoded());
|
|
|
|
}
|
|
|
|
|
2014-02-06 17:07:19 +01:00
|
|
|
QUrl BookmarkItem::url() const
|
|
|
|
{
|
|
|
|
return m_url;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarkItem::setUrl(const QUrl &url)
|
|
|
|
{
|
|
|
|
m_url = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString BookmarkItem::title() const
|
|
|
|
{
|
|
|
|
return m_title;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarkItem::setTitle(const QString &title)
|
|
|
|
{
|
|
|
|
m_title = title;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString BookmarkItem::description() const
|
|
|
|
{
|
|
|
|
return m_description;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarkItem::setDescription(const QString &description)
|
|
|
|
{
|
|
|
|
m_description = description;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString BookmarkItem::keyword() const
|
|
|
|
{
|
|
|
|
return m_keyword;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarkItem::setKeyword(const QString &keyword)
|
|
|
|
{
|
|
|
|
m_keyword = keyword;
|
|
|
|
}
|
|
|
|
|
2014-02-09 13:34:52 +01:00
|
|
|
int BookmarkItem::visitCount() const
|
|
|
|
{
|
|
|
|
return m_visitCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarkItem::setVisitCount(int count)
|
|
|
|
{
|
|
|
|
m_visitCount = count;
|
|
|
|
}
|
|
|
|
|
2014-03-01 13:02:57 +01:00
|
|
|
void BookmarkItem::updateVisitCount()
|
|
|
|
{
|
|
|
|
m_visitCount++;
|
|
|
|
}
|
|
|
|
|
2014-02-06 17:07:19 +01:00
|
|
|
bool BookmarkItem::isExpanded() const
|
|
|
|
{
|
|
|
|
return m_type == Root ? true : m_expanded;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarkItem::setExpanded(bool expanded)
|
|
|
|
{
|
|
|
|
m_expanded = expanded;
|
|
|
|
}
|
2014-02-09 11:02:51 +01:00
|
|
|
|
|
|
|
bool BookmarkItem::isSidebarExpanded() const
|
|
|
|
{
|
|
|
|
return m_type == Root ? true : m_sidebarExpanded;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarkItem::setSidebarExpanded(bool expanded)
|
|
|
|
{
|
|
|
|
m_sidebarExpanded = expanded;
|
|
|
|
}
|
2014-02-06 17:07:19 +01:00
|
|
|
|
2014-02-07 22:48:30 +01:00
|
|
|
void BookmarkItem::addChild(BookmarkItem* child, int index)
|
2014-02-06 17:07:19 +01:00
|
|
|
{
|
|
|
|
if (child->m_parent) {
|
|
|
|
child->m_parent->removeChild(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
child->m_parent = this;
|
|
|
|
|
2014-02-07 22:48:30 +01:00
|
|
|
if (index < 0) {
|
2014-02-06 17:07:19 +01:00
|
|
|
m_children.append(child);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_children.insert(index, child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-07 22:48:30 +01:00
|
|
|
void BookmarkItem::removeChild(BookmarkItem* child)
|
2014-02-06 17:07:19 +01:00
|
|
|
{
|
|
|
|
child->m_parent = 0;
|
|
|
|
m_children.removeOne(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
BookmarkItem::Type BookmarkItem::typeFromString(const QString &string)
|
|
|
|
{
|
|
|
|
if (string == QLatin1String("url")) {
|
|
|
|
return Url;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (string == QLatin1String("folder")) {
|
|
|
|
return Folder;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (string == QLatin1String("separator")) {
|
|
|
|
return Separator;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString BookmarkItem::typeToString(BookmarkItem::Type type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case Url:
|
|
|
|
return QString("url");
|
|
|
|
|
|
|
|
case Folder:
|
|
|
|
return QString("folder");
|
|
|
|
|
|
|
|
case Separator:
|
|
|
|
return QString("separator");
|
|
|
|
|
|
|
|
default:
|
|
|
|
return QString("invalid");
|
|
|
|
}
|
|
|
|
}
|