KBookmarks 5.109.0
kbookmark.h
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2000-2005 David Faure <faure@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-only
6*/
7#ifndef __kbookmark_h
8#define __kbookmark_h
9
10#include <kbookmarks_export.h>
11
12#include <QDomElement>
13#include <QList>
14#include <QMetaType>
15#include <QString>
16#include <QUrl>
17
18class QMimeData;
20class KBookmarkGroup;
21
27class KBOOKMARKS_EXPORT KBookmark
28{
29 friend class KBookmarkGroup;
30
31public:
32 enum MetaDataOverwriteMode {
33 OverwriteMetaData,
34 DontOverwriteMetaData,
35 };
36
43 class KBOOKMARKS_EXPORT List : public QList<KBookmark>
44 {
45 public:
46 List();
47
53 void populateMimeData(QMimeData *mimeData) const;
54
58 static bool canDecode(const QMimeData *mimeData);
59
63 static QStringList mimeDataTypes();
64
75 static KBookmark::List fromMimeData(const QMimeData *mimeData, QDomDocument &parentDocument);
76 };
77
84
90 explicit KBookmark(const QDomElement &elem);
91
95 static KBookmark standaloneBookmark(const QString &text, const QUrl &url, const QString &icon);
96
100 bool isGroup() const;
101
105 bool isSeparator() const;
106
112 bool isNull() const;
113
119 bool hasParent() const;
120
126 QString text() const;
131 QString fullText() const;
137 void setFullText(const QString &fullText);
141 QUrl url() const;
147 void setUrl(const QUrl &url);
148
153 QString icon() const;
154
160 void setIcon(const QString &icon);
161
166 QString description() const;
167
174 void setDescription(const QString &description);
175
180 QString mimeType() const;
181
188 void setMimeType(const QString &mimeType);
189
195 bool showInToolbar() const;
196
200 void setShowInToolbar(bool show);
201
206
212
220 QString address() const;
221
225 int positionInParent() const;
226
227 // Hard to decide. Good design would imply that each bookmark
228 // knows about its manager, so that there can be several managers.
229 // But if we say there is only one manager (i.e. set of bookmarks)
230 // per application, then KBookmarkManager::self() is much easier.
231 // KBookmarkManager * manager() const { return m_manager; }
232
236 QDomElement internalElement() const;
237
243
244 // Utility functions (internal)
245
249 static QString parentAddress(const QString &address);
250
254 static uint positionInParent(const QString &address);
255
260 static QString previousAddress(const QString &address);
261
266 static QString nextAddress(const QString &address);
267
272 static QString commonParent(const QString &A, const QString &B);
273
278 QDomNode metaData(const QString &owner, bool create) const;
279
286 QString metaDataItem(const QString &key) const;
287
295 void setMetaDataItem(const QString &key, const QString &value, MetaDataOverwriteMode mode = OverwriteMetaData);
296
304 void populateMimeData(QMimeData *mimeData) const;
305
309 bool operator==(const KBookmark &rhs) const;
310
311protected:
312 QDomElement element;
313 // Note: you can't add new member variables here.
314 // The KBookmarks are created on the fly, as wrappers
315 // around internal QDomElements. Any additional information
316 // has to be implemented as an attribute of the QDomElement.
317};
318
322class KBOOKMARKS_EXPORT KBookmarkGroup : public KBookmark
323{
324public:
332
336 KBookmarkGroup(const QDomElement &elem);
337
341 bool isOpen() const;
342
351 KBookmark previous(const KBookmark &current) const;
356 KBookmark next(const KBookmark &current) const;
357
361 int indexOf(const KBookmark &child) const;
362
368 KBookmarkGroup createNewFolder(const QString &text);
374
381
391 KBookmark addBookmark(const QString &text, const QUrl &url, const QString &icon);
392
398 bool moveBookmark(const KBookmark &bookmark, const KBookmark &after);
399
404 void deleteBookmark(const KBookmark &bk);
405
409 bool isToolbarGroup() const;
413 QDomElement findToolbar() const;
414
418 QList<QUrl> groupUrlList() const;
419
420protected:
421 QDomElement nextKnownTag(const QDomElement &start, bool goNext) const;
422
423private:
424 // Note: you can't add other member variables here, except for caching info.
425 // The KBookmarks are created on the fly, as wrappers
426 // around internal QDomElements. Any additional information
427 // has to be implemented as an attribute of the QDomElement.
428};
429
433class KBOOKMARKS_EXPORT KBookmarkGroupTraverser
434{
435protected:
436 virtual ~KBookmarkGroupTraverser();
437 void traverse(const KBookmarkGroup &);
438 virtual void visit(const KBookmark &);
439 virtual void visitEnter(const KBookmarkGroup &);
440 virtual void visitLeave(const KBookmarkGroup &);
441};
442
443#define KIO_KBOOKMARK_METATYPE_DEFINED 1
444Q_DECLARE_METATYPE(KBookmark)
445
446// needed when compiling this library with MSVC
447#if defined(Q_CC_MSVC) && defined(KF5Bookmarks_EXPORTS)
448inline uint qHash(const KBookmark &)
449{
450 qWarning("inline uint qHash(const KBookmark&) was called");
451 return 0;
452}
453#endif
454
455#endif
A class to traverse bookarm groups.
Definition kbookmark.h:434
A group of bookmarks.
Definition kbookmark.h:323
bool isToolbarGroup() const
KBookmark next(const KBookmark &current) const
Return the next sibling of a child bookmark of this group.
KBookmark first() const
Return the first child bookmark of this group.
bool isOpen() const
void deleteBookmark(const KBookmark &bk)
Delete a bookmark - it has to be one of our children ! Don't forget to use KBookmarkManager::self()->...
KBookmarkGroup()
Create an invalid group.
KBookmark previous(const KBookmark &current) const
Return the previous sibling of a child bookmark of this group.
bool moveBookmark(const KBookmark &bookmark, const KBookmark &after)
Moves bookmark after after (which should be a child of ours).
KBookmark addBookmark(const QString &text, const QUrl &url, const QString &icon)
Create a new bookmark, as the last child of this group Don't forget to use KBookmarkManager::self()->...
KBookmark createNewSeparator()
Create a new bookmark separator Don't forget to use KBookmarkManager::self()->emitChanged( parentBook...
KBookmark addBookmark(const KBookmark &bm)
Create a new bookmark, as the last child of this group Don't forget to use KBookmarkManager::self()->...
int indexOf(const KBookmark &child) const
Return the index of a child bookmark, -1 if not found.
KBookmarkGroup(const QDomElement &elem)
Create a bookmark group as specified by the given element.
QList< QUrl > groupUrlList() const
KBookmarkGroup createNewFolder(const QString &text)
Create a new bookmark folder, as the last child of this group.
This class implements the reading/writing of bookmarks in XML.
Definition kbookmarkmanager.h:52
KBookmark::List is a QList that contains bookmarks with a few convenience methods.
Definition kbookmark.h:44
static KBookmark::List fromMimeData(const QMimeData *mimeData, QDomDocument &parentDocument)
Extract a list of bookmarks from the contents of mimeData.
static QStringList mimeDataTypes()
Return the list of mimeTypes that can be decoded by fromMimeData.
static bool canDecode(const QMimeData *mimeData)
Return true if mimeData contains bookmarks.
void populateMimeData(QMimeData *mimeData) const
Adds this list of bookmark into the given QMimeData.
A class representing a bookmark.
Definition kbookmark.h:28
QString text() const
Text shown for the bookmark If bigger than 40, the text is shortened by replacing middle characters w...
KBookmarkGroup parentGroup() const
QString icon() const
void setMetaDataItem(const QString &key, const QString &value, MetaDataOverwriteMode mode=OverwriteMetaData)
Change the value of a specific metadata item, or create the given item if it doesn't exist already (o...
static QString nextAddress(const QString &address)
void updateAccessMetadata()
Updates the bookmarks access metadata Call when a user accesses the bookmark.
KBookmark()
Constructs a null bookmark, i.e.
QString description() const
bool isNull() const
bool showInToolbar() const
QDomNode metaData(const QString &owner, bool create) const
bool isGroup() const
Whether the bookmark is a group or a normal bookmark.
QString fullText() const
Text shown for the bookmark, not truncated.
static KBookmark standaloneBookmark(const QString &text, const QUrl &url, const QString &icon)
Creates a stand alone bookmark.
static QString previousAddress(const QString &address)
bool hasParent() const
KBookmarkGroup toGroup() const
Convert this to a group - do this only if isGroup() returns true.
bool isSeparator() const
Whether the bookmark is a separator.
static QString parentAddress(const QString &address)
int positionInParent() const
Return the position in the parent, i.e.
void setDescription(const QString &description)
Set the description of the bookmark.
QString mimeType() const
void setUrl(const QUrl &url)
Set the URL of the bookmark.
void setMimeType(const QString &mimeType)
Set the Mime-Type of this item.
static uint positionInParent(const QString &address)
void setFullText(const QString &fullText)
Set the text shown for the bookmark.
QString address() const
Return the "address" of this bookmark in the whole tree.
bool operator==(const KBookmark &rhs) const
Comparison operator.
KBookmark(const QDomElement &elem)
Creates the KBookmark wrapper for.
static QString commonParent(const QString &A, const QString &B)
void setIcon(const QString &icon)
Set the icon name of the bookmark.
void setShowInToolbar(bool show)
Set whether this bookmark is show in a filterd toolbar.
void populateMimeData(QMimeData *mimeData) const
Adds this bookmark into the given QMimeData.
QUrl url() const
URL contained by the bookmark.
QString metaDataItem(const QString &key) const
Get the value of a specific metadata item (owner = "http://www.kde.org").