KBookmarks

kbookmark.h
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2000-2005 David Faure <[email protected]>
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 <QString>
13 #include <QUrl>
14 #include <QList>
15 #include <QMetaType>
16 #include <QDomElement>
17 
18 class QMimeData;
19 class KBookmarkManager;
20 class KBookmarkGroup;
21 
22 class KBOOKMARKS_EXPORT KBookmark
23 {
24  friend class KBookmarkGroup;
25 public:
26  enum MetaDataOverwriteMode {
27  OverwriteMetaData, DontOverwriteMetaData
28  };
29 
36  class KBOOKMARKS_EXPORT List : public QList<KBookmark>
37  {
38  public:
39  List();
40 
46  void populateMimeData(QMimeData *mimeData) const;
47 
51  static bool canDecode(const QMimeData *mimeData);
52 
56  static QStringList mimeDataTypes();
57 
68  static KBookmark::List fromMimeData(const QMimeData *mimeData, QDomDocument &parentDocument);
69  };
70 
76  KBookmark();
77 
83  explicit KBookmark(const QDomElement &elem);
84 
88  static KBookmark standaloneBookmark(const QString &text, const QUrl &url, const QString &icon);
89 
93  bool isGroup() const;
94 
98  bool isSeparator() const;
99 
105  bool isNull() const;
106 
112  bool hasParent() const;
113 
119  QString text() const;
124  QString fullText() const;
130  void setFullText(const QString &fullText);
134  QUrl url() const;
140  void setUrl(const QUrl &url);
141 
146  QString icon() const;
147 
153  void setIcon(const QString &icon);
154 
159  QString description() const;
160 
167  void setDescription(const QString &description);
168 
173  QString mimeType() const;
174 
181  void setMimeType(const QString &mimeType);
182 
188  bool showInToolbar() const;
189 
193  void setShowInToolbar(bool show);
194 
198  KBookmarkGroup parentGroup() const;
199 
204  KBookmarkGroup toGroup() const;
205 
213  QString address() const;
214 
218  int positionInParent() const;
219 
220  // Hard to decide. Good design would imply that each bookmark
221  // knows about its manager, so that there can be several managers.
222  // But if we say there is only one manager (i.e. set of bookmarks)
223  // per application, then KBookmarkManager::self() is much easier.
224  //KBookmarkManager * manager() const { return m_manager; }
225 
229  QDomElement internalElement() const;
230 
235  void updateAccessMetadata();
236 
237  // Utility functions (internal)
238 
242  static QString parentAddress(const QString &address);
243 
247  static uint positionInParent(const QString &address);
248 
253  static QString previousAddress(const QString &address);
254 
259  static QString nextAddress(const QString &address);
260 
265  static QString commonParent(const QString &A, const QString &B);
266 
271  QDomNode metaData(const QString &owner, bool create) const;
272 
279  QString metaDataItem(const QString &key) const;
280 
288  void setMetaDataItem(const QString &key, const QString &value, MetaDataOverwriteMode mode = OverwriteMetaData);
289 
297  void populateMimeData(QMimeData *mimeData) const;
298 
302  bool operator==(const KBookmark &rhs) const;
303 
304 protected:
305  QDomElement element;
306  // Note: you can't add new member variables here.
307  // The KBookmarks are created on the fly, as wrappers
308  // around internal QDomElements. Any additional information
309  // has to be implemented as an attribute of the QDomElement.
310 
311 };
312 
316 class KBOOKMARKS_EXPORT KBookmarkGroup : public KBookmark
317 {
318 public:
325  KBookmarkGroup();
326 
330  KBookmarkGroup(const QDomElement &elem);
331 
335  bool isOpen() const;
336 
340  KBookmark first() const;
345  KBookmark previous(const KBookmark &current) const;
350  KBookmark next(const KBookmark &current) const;
351 
355  int indexOf(const KBookmark &child) const;
356 
362  KBookmarkGroup createNewFolder(const QString &text);
367  KBookmark createNewSeparator();
368 
374  KBookmark addBookmark(const KBookmark &bm);
375 
385  KBookmark addBookmark(const QString &text, const QUrl &url, const QString &icon);
386 
392  bool moveBookmark(const KBookmark &bookmark, const KBookmark &after);
393 
398  void deleteBookmark(const KBookmark &bk);
399 
403  bool isToolbarGroup() const;
407  QDomElement findToolbar() const;
408 
412  QList<QUrl> groupUrlList() const;
413 
414 protected:
415  QDomElement nextKnownTag(const QDomElement &start, bool goNext) const;
416 
417 private:
418 
419  // Note: you can't add other member variables here, except for caching info.
420  // The KBookmarks are created on the fly, as wrappers
421  // around internal QDomElements. Any additional information
422  // has to be implemented as an attribute of the QDomElement.
423 };
424 
425 class KBOOKMARKS_EXPORT KBookmarkGroupTraverser
426 {
427 protected:
428  virtual ~KBookmarkGroupTraverser();
429  void traverse(const KBookmarkGroup &);
430  virtual void visit(const KBookmark &);
431  virtual void visitEnter(const KBookmarkGroup &);
432  virtual void visitLeave(const KBookmarkGroup &);
433 };
434 
435 #define KIO_KBOOKMARK_METATYPE_DEFINED 1
436 Q_DECLARE_METATYPE(KBookmark)
437 
438 // needed when compiling this library with MSVC
439 #if defined(Q_CC_MSVC) && defined(KF5Bookmarks_EXPORTS)
440 inline uint qHash(const KBookmark&)
441 {
442  qWarning("inline uint qHash(const KBookmark&) was called");
443  return 0;
444 }
445 #endif
446 
447 #endif
This class implements the reading/writing of bookmarks in XML.
bool operator==(const QList< T > &other) const const
A group of bookmarks.
Definition: kbookmark.h:316
KBookmark::List is a QList that contains bookmarks with a few convenience methods.
Definition: kbookmark.h:36
KCALENDARCORE_EXPORT uint qHash(const KCalendarCore::Period &key)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Aug 6 2020 22:39:25 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.