Falkon Develop
Cross-platform Qt-based web browser
bookmarkitem.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2014 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "bookmarkitem.h"
19#include "iconprovider.h"
20
22 : m_type(type)
23 , m_parent(parent)
24 , m_visitCount(0)
25 , m_expanded(false)
26 , m_sidebarExpanded(false)
27{
28 if (m_parent) {
29 parent->addChild(this);
30 }
31}
32
34{
35 qDeleteAll(m_children);
36}
37
39{
40 return m_type;
41}
42
44{
45 m_type = type;
46}
47
49{
50 return m_type == Folder;
51}
52
54{
55 return m_type == Url;
56}
57
59{
60 return m_type == Separator;
61}
62
64{
65 return m_parent;
66}
67
68QList<BookmarkItem*> BookmarkItem::children() const
69{
70 return m_children;
71}
72
74{
75 // Cache icon for 20 seconds
76 const int iconCacheTime = 20 * 1000;
77
78 switch (m_type) {
79 case Url:
80 if ((!m_iconTime.isValid()) || (m_iconTime.elapsed() > iconCacheTime)) {
81 m_icon = IconProvider::iconForUrl(m_url);
82 m_iconTime.restart();
83 }
84 return m_icon;
85 case Folder:
86 return IconProvider::standardIcon(QStyle::SP_DirIcon);
87 default:
88 return {};
89 }
90}
91
92void BookmarkItem::setIcon(const QIcon &icon)
93{
94 m_icon = icon;
95}
96
98{
99 return QString::fromUtf8(m_url.toEncoded());
100}
101
103{
104 return m_url;
105}
106
107void BookmarkItem::setUrl(const QUrl &url)
108{
109 m_url = url;
110}
111
112QString BookmarkItem::title() const
113{
114 return m_title;
115}
116
117void BookmarkItem::setTitle(const QString &title)
118{
119 m_title = title;
120}
121
123{
124 return m_description;
125}
126
127void BookmarkItem::setDescription(const QString &description)
128{
129 m_description = description;
130}
131
133{
134 return m_keyword;
135}
136
137void BookmarkItem::setKeyword(const QString &keyword)
138{
139 m_keyword = keyword;
140}
141
143{
144 return m_visitCount;
145}
146
148{
149 m_visitCount = count;
150}
151
153{
154 m_visitCount++;
155}
156
158{
159 return m_type == Root ? true : m_expanded;
160}
161
162void BookmarkItem::setExpanded(bool expanded)
163{
164 m_expanded = expanded;
165}
166
168{
169 return m_type == Root ? true : m_sidebarExpanded;
170}
171
173{
174 m_sidebarExpanded = expanded;
175}
176
178{
179 if (child->m_parent) {
180 child->m_parent->removeChild(child);
181 }
182
183 child->m_parent = this;
184
185 if (index < 0) {
186 m_children.append(child);
187 }
188 else {
189 m_children.insert(index, child);
190 }
191}
192
194{
195 child->m_parent = nullptr;
196 m_children.removeOne(child);
197}
198
200{
201 if (string == QLatin1String("url")) {
202 return Url;
203 }
204
205 if (string == QLatin1String("folder")) {
206 return Folder;
207 }
208
209 if (string == QLatin1String("separator")) {
210 return Separator;
211 }
212
213 return Invalid;
214}
215
217{
218 switch (type) {
219 case Url:
220 return QSL("url");
221
222 case Folder:
223 return QSL("folder");
224
225 case Separator:
226 return QSL("separator");
227
228 default:
229 return QSL("invalid");
230 }
231}
void setVisitCount(int count)
bool isExpanded() const
QString keyword() const
bool isFolder() const
void addChild(BookmarkItem *child, int index=-1)
void setDescription(const QString &description)
QString urlString() const
bool isSeparator() const
void removeChild(BookmarkItem *child)
QString description() const
QUrl url() const
void setSidebarExpanded(bool expanded)
static Type typeFromString(const QString &string)
void setKeyword(const QString &keyword)
void setIcon(const QIcon &icon)
static QString typeToString(Type type)
int visitCount() const
BookmarkItem(Type type, BookmarkItem *parent=nullptr)
void updateVisitCount()
bool isUrl() const
BookmarkItem * parent() const
QList< BookmarkItem * > children() const
QString title() const
void setType(Type type)
void setUrl(const QUrl &url)
void setExpanded(bool expanded)
bool isSidebarExpanded() const
Type type() const
void setTitle(const QString &title)
static QIcon iconForUrl(const QUrl &url, bool allowNull=false)
static QIcon standardIcon(QStyle::StandardPixmap icon)
#define QSL(x)
Definition: qzcommon.h:40