KBookmarks

kbookmark.cpp
1 // -*- c-basic-offset:4; indent-tabs-mode:nil -*-
2 /* This file is part of the KDE libraries
3  Copyright (C) 2000 David Faure <[email protected]>
4  Copyright (C) 2003 Alexander Kellett <[email protected]>
5  Copyright (C) 2008 Norbert Frese <[email protected]>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License version 2 as published by the Free Software Foundation.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "kbookmark.h"
23 #include <QStack>
24 #include <QCoreApplication>
25 #include <QMimeDatabase>
26 #include "kbookmarks_debug.h"
27 #include <KStringHandler>
28 #include <kurlmimedata.h>
29 #include <kbookmarkmanager.h>
30 
31 #include <QDateTime>
32 #include <QMimeData>
33 
34 namespace {
35 namespace Strings {
36 QString metaDataKDEOwner() { return QStringLiteral("http://www.kde.org"); }
37 QString metaDataFreedesktopOwner() { return QStringLiteral("http://freedesktop.org"); }
38 QString metaDataMimeOwner() { return QStringLiteral("http://www.freedesktop.org/standards/shared-mime-info"); }
39 
40 QString xbelMimeType() { return QStringLiteral("application/x-xbel"); }
41 }
42 }
43 
45 
46 static QDomNode cd(QDomNode node, const QString &name, bool create)
47 {
48  QDomNode subnode = node.namedItem(name);
49  if (create && subnode.isNull()) {
50  subnode = node.ownerDocument().createElement(name);
51  node.appendChild(subnode);
52  }
53  return subnode;
54 }
55 
56 static QDomNode cd_or_create(const QDomNode &node, const QString &name)
57 {
58  return cd(node, name, true);
59 }
60 
61 static QDomText get_or_create_text(QDomNode node)
62 {
63  QDomNode subnode = node.firstChild();
64  if (subnode.isNull()) {
65  subnode = node.ownerDocument().createTextNode(QLatin1String(""));
66  node.appendChild(subnode);
67  }
68  return subnode.toText();
69 }
70 
71 static QDomNode findMetadata(const QString &forOwner, QDomNode &parent, bool create)
72 {
73  const bool forOwnerIsKDE = (forOwner == Strings::metaDataKDEOwner());
74 
75  QDomElement metadataElement;
76  for (QDomNode _node = parent.firstChild(); !_node.isNull(); _node = _node.nextSibling()) {
77  QDomElement elem = _node.toElement();
78  if (!elem.isNull() && elem.tagName() == QLatin1String("metadata")) {
79  const QString owner = elem.attribute(QStringLiteral("owner"));
80  if (owner == forOwner) {
81  return elem;
82  }
83  if (owner.isEmpty() && forOwnerIsKDE) {
84  metadataElement = elem;
85  }
86  }
87  }
88  if (create && metadataElement.isNull()) {
89  metadataElement = parent.ownerDocument().createElement(QStringLiteral("metadata"));
90  parent.appendChild(metadataElement);
91  metadataElement.setAttribute(QStringLiteral("owner"), forOwner);
92 
93  } else if (!metadataElement.isNull() && forOwnerIsKDE) {
94  // i'm not sure if this is good, we shouln't take over foreign metatdata
95  metadataElement.setAttribute(QStringLiteral("owner"), Strings::metaDataKDEOwner());
96  }
97  return metadataElement;
98 }
99 
101 
103  : KBookmark(QDomElement())
104 {
105 }
106 
108  : KBookmark(elem)
109 {
110 }
111 
113 {
114  return element.attribute(QStringLiteral("folded")) == QLatin1String("no"); // default is: folded
115 }
116 
117 KBookmark KBookmarkGroup::first() const
118 {
119  return KBookmark(nextKnownTag(element.firstChildElement(), true));
120 }
121 
122 KBookmark KBookmarkGroup::previous(const KBookmark &current) const
123 {
124  return KBookmark(nextKnownTag(current.element.previousSiblingElement(), false));
125 }
126 
127 KBookmark KBookmarkGroup::next(const KBookmark &current) const
128 {
129  return KBookmark(nextKnownTag(current.element.nextSiblingElement(), true));
130 }
131 
132 int KBookmarkGroup::indexOf(const KBookmark &child) const
133 {
134  int counter = 0;
135  for (KBookmark bk = first(); !bk.isNull(); bk = next(bk), ++counter) {
136  if (bk.element == child.element) {
137  return counter;
138  }
139  }
140  return -1;
141 }
142 
143 QDomElement KBookmarkGroup::nextKnownTag(const QDomElement &start, bool goNext) const
144 {
145  for (QDomElement elem = start; !elem.isNull();) {
146  QString tag = elem.tagName();
147  if (tag == QLatin1String("folder") || tag == QLatin1String("bookmark")
148  || tag == QLatin1String("separator")) {
149  return elem;
150  }
151  if (goNext) {
152  elem = elem.nextSiblingElement();
153  } else {
154  elem = elem.previousSiblingElement();
155  }
156  }
157  return QDomElement();
158 }
159 
161 {
162  if (isNull()) {
163  return KBookmarkGroup();
164  }
165  QDomDocument doc = element.ownerDocument();
166  QDomElement groupElem = doc.createElement(QStringLiteral("folder"));
167  element.appendChild(groupElem);
168  QDomElement textElem = doc.createElement(QStringLiteral("title"));
169  groupElem.appendChild(textElem);
170  textElem.appendChild(doc.createTextNode(text));
171  return KBookmarkGroup(groupElem);
172 
173 }
174 
176 {
177  if (isNull()) {
178  return KBookmark();
179  }
180  QDomDocument doc = element.ownerDocument();
181  Q_ASSERT(!doc.isNull());
182  QDomElement sepElem = doc.createElement(QStringLiteral("separator"));
183  element.appendChild(sepElem);
184  return KBookmark(sepElem);
185 }
186 
187 bool KBookmarkGroup::moveBookmark(const KBookmark &item, const KBookmark &after)
188 {
189  QDomNode n;
190  if (!after.isNull()) {
191  n = element.insertAfter(item.element, after.element);
192  } else { // first child
193  if (element.firstChild().isNull()) { // Empty element -> set as real first child
194  n = element.insertBefore(item.element, QDomElement());
195  }
196 
197  // we have to skip everything up to the first valid child
198  QDomElement firstChild = nextKnownTag(element.firstChild().toElement(), true);
199  if (!firstChild.isNull()) {
200  if (firstChild == item.element) { // item is already the first child, done
201  return true;
202  }
203  n = element.insertBefore(item.element, firstChild);
204  } else {
205  // No real first child -> append after the <title> etc.
206  n = element.appendChild(item.element);
207  }
208  }
209  return (!n.isNull());
210 }
211 
212 KBookmark KBookmarkGroup::addBookmark(const KBookmark &bm)
213 {
214  element.appendChild(bm.internalElement());
215  return bm;
216 }
217 
218 KBookmark KBookmarkGroup::addBookmark(const QString &text, const QUrl &url, const QString &icon)
219 {
220  if (isNull()) {
221  return KBookmark();
222  }
223  QDomDocument doc = element.ownerDocument();
224  QDomElement elem = doc.createElement(QStringLiteral("bookmark"));
225  elem.setAttribute(QStringLiteral("href"), url.toString(QUrl::FullyEncoded));
226 
227  QDomElement textElem = doc.createElement(QStringLiteral("title"));
228  elem.appendChild(textElem);
229  textElem.appendChild(doc.createTextNode(text));
230 
231  KBookmark newBookmark = addBookmark(KBookmark(elem));
232 
233  // as icons are moved to metadata, we have to use the KBookmark API for this
234  newBookmark.setIcon(icon);
235  return newBookmark;
236 }
237 
238 void KBookmarkGroup::deleteBookmark(const KBookmark &bk)
239 {
240  element.removeChild(bk.element);
241 }
242 
244 {
245  return (element.attribute(QStringLiteral("toolbar")) == QLatin1String("yes"));
246 }
247 
249 {
250  if (element.attribute(QStringLiteral("toolbar")) == QLatin1String("yes")) {
251  return element;
252  }
253  for (QDomElement e = element.firstChildElement(QStringLiteral("folder")); !e.isNull();
254  e = e.nextSiblingElement(QStringLiteral("folder")) ) {
255  QDomElement result = KBookmarkGroup(e).findToolbar();
256  if (!result.isNull()) {
257  return result;
258  }
259  }
260  return QDomElement();
261 }
262 
264 {
265  QList<QUrl> urlList;
266  for (KBookmark bm = first(); !bm.isNull(); bm = next(bm)) {
267  if (bm.isSeparator() || bm.isGroup()) {
268  continue;
269  }
270  urlList << bm.url();
271  }
272  return urlList;
273 }
274 
276 
277 KBookmark::KBookmark()
278 {
279 }
280 
281 KBookmark::KBookmark(const QDomElement &elem) : element(elem)
282 {
283 }
284 
285 bool KBookmark::isGroup() const
286 {
287  QString tag = element.tagName();
288  return (tag == QLatin1String("folder")
289  || tag == QLatin1String("xbel")); // don't forget the toplevel group
290 }
291 
292 bool KBookmark::isSeparator() const
293 {
294  return (element.tagName() == QLatin1String("separator"));
295 }
296 
297 bool KBookmark::isNull() const
298 {
299  return element.isNull();
300 }
301 
302 bool KBookmark::hasParent() const
303 {
304  QDomElement parent = element.parentNode().toElement();
305  return !parent.isNull();
306 }
307 
308 QString KBookmark::text() const
309 {
310  return KStringHandler::csqueeze(fullText());
311 }
312 
313 QString KBookmark::fullText() const
314 {
315  if (isSeparator()) {
316  return QCoreApplication::translate("KBookmark", "--- separator ---", "Bookmark separator");
317  }
318 
319  QString text = element.namedItem(QStringLiteral("title")).toElement().text();
320  text.replace(QLatin1Char('\n'), QLatin1Char(' ')); // #140673
321  return text;
322 }
323 
324 void KBookmark::setFullText(const QString &fullText)
325 {
326  QDomNode titleNode = element.namedItem(QStringLiteral("title"));
327  if (titleNode.isNull()) {
328  titleNode = element.ownerDocument().createElement(QStringLiteral("title"));
329  element.appendChild(titleNode);
330  }
331 
332  if (titleNode.firstChild().isNull()) {
333  QDomText domtext = titleNode.ownerDocument().createTextNode(QLatin1String(""));
334  titleNode.appendChild(domtext);
335  }
336 
337  QDomText domtext = titleNode.firstChild().toText();
338  domtext.setData(fullText);
339 }
340 
341 QUrl KBookmark::url() const
342 {
343  return QUrl(element.attribute(QStringLiteral("href")));
344 }
345 
346 void KBookmark::setUrl(const QUrl &url)
347 {
348  element.setAttribute(QStringLiteral("href"), url.toString());
349 }
350 
351 QString KBookmark::icon() const
352 {
353  QDomNode metaDataNode = metaData(Strings::metaDataFreedesktopOwner(), false);
354  QDomElement iconElement = cd(metaDataNode, QStringLiteral("bookmark:icon"), false).toElement();
355 
356  QString icon = iconElement.attribute(QStringLiteral("name"));
357 
358  // migration code
359  if (icon.isEmpty()) {
360  icon = element.attribute(QStringLiteral("icon"));
361  }
362  if (icon == QLatin1String("www")) { // common icon for kde3 bookmarks
363  return QStringLiteral("internet-web-browser");
364  }
365  // end migration code
366 
367  if (icon == QLatin1String("bookmark_folder")) {
368  return QStringLiteral("folder-bookmarks");
369  }
370  if (icon.isEmpty()) {
371  // Default icon depends on URL for bookmarks, and is default directory
372  // icon for groups.
373  if (isGroup()) {
374  icon = QStringLiteral("folder-bookmarks");
375  } else {
376  if (isSeparator()) {
377  icon = QStringLiteral("edit-clear"); // whatever
378  } else {
379  // get icon from mimeType
380  QMimeDatabase db;
381  QMimeType mime;
382  QString _mimeType = mimeType();
383  if (!_mimeType.isEmpty()) {
384  mime = db.mimeTypeForName(_mimeType);
385  } else {
386  mime = db.mimeTypeForUrl(url());
387  }
388  if (mime.isValid()) {
389  icon = mime.iconName();
390  }
391  }
392  }
393  }
394  return icon;
395 }
396 
397 void KBookmark::setIcon(const QString &icon)
398 {
399  QDomNode metaDataNode = metaData(Strings::metaDataFreedesktopOwner(), true);
400  QDomElement iconElement = cd_or_create(metaDataNode, QStringLiteral("bookmark:icon")).toElement();
401  iconElement.setAttribute(QStringLiteral("name"), icon);
402 
403  // migration code
404  if (!element.attribute(QStringLiteral("icon")).isEmpty()) {
405  element.removeAttribute(QStringLiteral("icon"));
406  }
407 }
408 
409 QString KBookmark::description() const
410 {
411  if (isSeparator()) {
412  return QString();
413  }
414 
415  QString description = element.namedItem(QStringLiteral("desc")).toElement().text();
416  description.replace(QLatin1Char('\n'), QLatin1Char(' ')); // #140673
417  return description;
418 }
419 
420 void KBookmark::setDescription(const QString &description)
421 {
422  QDomNode descNode = element.namedItem(QStringLiteral("desc"));
423  if (descNode.isNull()) {
424  descNode = element.ownerDocument().createElement(QStringLiteral("desc"));
425  element.appendChild(descNode);
426  }
427 
428  if (descNode.firstChild().isNull()) {
429  QDomText domtext = descNode.ownerDocument().createTextNode(QString());
430  descNode.appendChild(domtext);
431  }
432 
433  QDomText domtext = descNode.firstChild().toText();
434  domtext.setData(description);
435 }
436 
437 QString KBookmark::mimeType() const
438 {
439  QDomNode metaDataNode = metaData(Strings::metaDataMimeOwner(), false);
440  QDomElement mimeTypeElement = cd(metaDataNode, QStringLiteral("mime:mime-type"), false).toElement();
441  return mimeTypeElement.attribute(QStringLiteral("type"));
442 }
443 
444 void KBookmark::setMimeType(const QString &mimeType)
445 {
446  QDomNode metaDataNode = metaData(Strings::metaDataMimeOwner(), true);
447  QDomElement iconElement = cd_or_create(metaDataNode, QStringLiteral("mime:mime-type")).toElement();
448  iconElement.setAttribute(QStringLiteral("type"), mimeType);
449 }
450 
451 bool KBookmark::showInToolbar() const
452 {
453  if (element.hasAttribute(QStringLiteral("showintoolbar"))) {
454  bool show = element.attribute(QStringLiteral("showintoolbar")) == QLatin1String("yes");
455  const_cast<QDomElement *>(&element)->removeAttribute(QStringLiteral("showintoolbar"));
456  const_cast<KBookmark *>(this)->setShowInToolbar(show);
457  }
458  return metaDataItem(QStringLiteral("showintoolbar")) == QLatin1String("yes");
459 }
460 
461 void KBookmark::setShowInToolbar(bool show)
462 {
463  setMetaDataItem(QStringLiteral("showintoolbar"), show ? QStringLiteral("yes") : QStringLiteral("no"));
464 }
465 
466 KBookmarkGroup KBookmark::parentGroup() const
467 {
468  return KBookmarkGroup(element.parentNode().toElement());
469 }
470 
471 KBookmarkGroup KBookmark::toGroup() const
472 {
473  Q_ASSERT(isGroup());
474  return KBookmarkGroup(element);
475 }
476 
477 QString KBookmark::address() const
478 {
479  if (element.tagName() == QLatin1String("xbel")) {
480  return QLatin1String(""); // not QString() !
481  } else {
482  // Use keditbookmarks's DEBUG_ADDRESSES flag to debug this code :)
483  if (element.parentNode().isNull()) {
484  Q_ASSERT(false);
485  return QStringLiteral("ERROR"); // Avoid an infinite loop
486  }
487  KBookmarkGroup group = parentGroup();
488  QString parentAddress = group.address();
489  int pos = group.indexOf(*this);
490  Q_ASSERT(pos != -1);
491  return parentAddress + QLatin1Char('/') + QString::number(pos);
492  }
493 }
494 
495 int KBookmark::positionInParent() const
496 {
497  return parentGroup().indexOf(*this);
498 }
499 
500 QDomElement KBookmark::internalElement() const
501 {
502  return element;
503 }
504 
505 KBookmark KBookmark::standaloneBookmark(const QString &text, const QUrl &url, const QString &icon)
506 {
507  QDomDocument doc(QStringLiteral("xbel"));
508  QDomElement elem = doc.createElement(QStringLiteral("xbel"));
509  doc.appendChild(elem);
510  KBookmarkGroup grp(elem);
511  grp.addBookmark(text, url, icon);
512  return grp.first();
513 }
514 
515 QString KBookmark::commonParent(const QString &first, const QString &second)
516 {
517  QString A = first;
518  QString B = second;
519  QString error(QStringLiteral("ERROR"));
520  if (A == error || B == error) {
521  return error;
522  }
523 
524  A += QLatin1Char('/');
525  B += QLatin1Char('/');
526 
527  int lastCommonSlash = 0;
528  int lastPos = A.length() < B.length() ? A.length() : B.length();
529  for (int i = 0; i < lastPos; ++i) {
530  if (A[i] != B[i]) {
531  return A.left(lastCommonSlash);
532  }
533  if (A[i] == QLatin1Char('/')) {
534  lastCommonSlash = i;
535  }
536  }
537  return A.left(lastCommonSlash);
538 }
539 
540 void KBookmark::updateAccessMetadata()
541 {
542  // qCDebug(KBOOKMARKS_LOG) << "KBookmark::updateAccessMetadata " << address() << " " << url();
543 
544  const uint timet = QDateTime::currentDateTimeUtc().toSecsSinceEpoch();
545  setMetaDataItem(QStringLiteral("time_added"), QString::number(timet), DontOverwriteMetaData);
546  setMetaDataItem(QStringLiteral("time_visited"), QString::number(timet));
547 
548  QString countStr = metaDataItem(QStringLiteral("visit_count")); // TODO use spec'ed name
549  bool ok;
550  int currentCount = countStr.toInt(&ok);
551  if (!ok) {
552  currentCount = 0;
553  }
554  currentCount++;
555  setMetaDataItem(QStringLiteral("visit_count"), QString::number(currentCount));
556 
557  // TODO - time_modified
558 }
559 
560 QString KBookmark::parentAddress(const QString &address)
561 {
562  return address.left(address.lastIndexOf(QLatin1Char('/')));
563 }
564 
565 uint KBookmark::positionInParent(const QString &address)
566 {
567  return address.midRef(address.lastIndexOf(QLatin1Char('/')) + 1).toInt();
568 }
569 
570 QString KBookmark::previousAddress(const QString &address)
571 {
572  uint pp = positionInParent(address);
573  return pp > 0
574  ? parentAddress(address) + QLatin1Char('/') + QString::number(pp - 1)
575  : QString();
576 }
577 
578 QString KBookmark::nextAddress(const QString &address)
579 {
580  return parentAddress(address) + QLatin1Char('/') +
581  QString::number(positionInParent(address) + 1);
582 }
583 
584 QDomNode KBookmark::metaData(const QString &owner, bool create) const
585 {
586  QDomNode infoNode = cd(internalElement(), QStringLiteral("info"), create);
587  if (infoNode.isNull()) {
588  return QDomNode();
589  }
590  return findMetadata(owner, infoNode, create);
591 }
592 
593 QString KBookmark::metaDataItem(const QString &key) const
594 {
595  QDomNode metaDataNode = metaData(Strings::metaDataKDEOwner(), false);
596  for (QDomElement e = metaDataNode.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) {
597  if (e.tagName() == key) {
598  return e.text();
599  }
600  }
601  return QString();
602 }
603 
604 void KBookmark::setMetaDataItem(const QString &key, const QString &value, MetaDataOverwriteMode mode)
605 {
606  QDomNode metaDataNode = metaData(Strings::metaDataKDEOwner(), true);
607  QDomNode item = cd_or_create(metaDataNode, key);
608  QDomText text = get_or_create_text(item);
609  if (mode == DontOverwriteMetaData && !text.data().isEmpty()) {
610  return;
611  }
612 
613  text.setData(value);
614 }
615 
616 bool KBookmark::operator==(const KBookmark &rhs) const
617 {
618  return element == rhs.element;
619 }
620 
622 
623 KBookmarkGroupTraverser::~KBookmarkGroupTraverser()
624 {
625 }
626 
627 void KBookmarkGroupTraverser::traverse(const KBookmarkGroup &root)
628 {
630  stack.push(root);
631  KBookmark bk = root.first();
632  for (;;) {
633  if (bk.isNull()) {
634  if (stack.count() == 1) { // only root is on the stack
635  return;
636  }
637  if (!stack.isEmpty()) {
638  visitLeave(stack.top());
639  bk = stack.pop();
640  }
641  bk = stack.top().next(bk);
642  } else if (bk.isGroup()) {
643  KBookmarkGroup gp = bk.toGroup();
644  visitEnter(gp);
645  bk = gp.first();
646  stack.push(gp);
647  } else {
648  visit(bk);
649  bk = stack.top().next(bk);
650  }
651  }
652 }
653 
654 void KBookmarkGroupTraverser::visit(const KBookmark &)
655 {
656 }
657 
658 void KBookmarkGroupTraverser::visitEnter(const KBookmarkGroup &)
659 {
660 }
661 
662 void KBookmarkGroupTraverser::visitLeave(const KBookmarkGroup &)
663 {
664 }
665 
666 void KBookmark::populateMimeData(QMimeData *mimeData) const
667 {
668  KBookmark::List bookmarkList;
669  bookmarkList.append(*this);
670  bookmarkList.populateMimeData(mimeData);
671 }
672 
673 KBookmark::List::List() : QList<KBookmark>()
674 {
675 }
676 
678 {
679  QList<QUrl> urls;
680 
681  QDomDocument doc(QStringLiteral("xbel"));
682  QDomElement elem = doc.createElement(QStringLiteral("xbel"));
683  doc.appendChild(elem);
684 
685  for (const_iterator it = begin(), end = this->end(); it != end; ++it) {
686  urls.append((*it).url());
687  elem.appendChild((*it).internalElement().cloneNode(true /* deep */));
688  }
689 
690  // This sets text/uri-list and text/plain into the mimedata
691  mimeData->setUrls(urls);
692 
693  mimeData->setData(Strings::xbelMimeType(), doc.toByteArray());
694 }
695 
697 {
698  return mimeData->hasFormat(Strings::xbelMimeType()) || mimeData->hasUrls();
699 }
700 
702 {
703  return QStringList() << Strings::xbelMimeType() << KUrlMimeData::mimeDataTypes();
704 }
705 
707 {
708  KBookmark::List bookmarks;
709  const QByteArray payload = mimeData->data(Strings::xbelMimeType());
710  if (!payload.isEmpty()) {
711  doc.setContent(payload);
712  QDomElement elem = doc.documentElement();
713  const QDomNodeList children = elem.childNodes();
714  bookmarks.reserve(children.count());
715  for (int childno = 0; childno < children.count(); childno++) {
716  bookmarks.append(KBookmark(children.item(childno).toElement()));
717  }
718  return bookmarks;
719  }
720  const QList<QUrl> urls = KUrlMimeData::urlsFromMimeData(mimeData);
721  bookmarks.reserve(urls.size());
722  for (int i = 0; i < urls.size(); ++i) {
723  const QUrl url = urls.at(i);
724  bookmarks.append(KBookmark::standaloneBookmark(url.toDisplayString(), url, QString()/*TODO icon*/));
725  }
726  return bookmarks;
727 }
728 
bool moveBookmark(const KBookmark &bookmark, const KBookmark &after)
Moves bookmark after after (which should be a child of ours).
Definition: kbookmark.cpp:187
QDomNode item(int index) const const
QByteArray data(const QString &mimeType) const const
QString toDisplayString(QUrl::FormattingOptions options) const const
KBookmark previous(const KBookmark &current) const
Return the prevous sibling of a child bookmark of this group.
Definition: kbookmark.cpp:122
FullyEncoded
QDomNode appendChild(const QDomNode &newChild)
QString attribute(const QString &name, const QString &defValue) const const
void populateMimeData(QMimeData *mimeData) const
Adds this list of bookmark into the given QMimeData.
Definition: kbookmark.cpp:677
QString data() const const
virtual bool hasFormat(const QString &mimeType) const const
void reserve(int alloc)
QDomNode insertAfter(const QDomNode &newChild, const QDomNode &refChild)
void deleteBookmark(const KBookmark &bk)
Delete a bookmark - it has to be one of our children ! Don&#39;t forget to use KBookmarkManager::self()->...
Definition: kbookmark.cpp:238
bool isToolbarGroup() const
Definition: kbookmark.cpp:243
void push(const T &t)
const T & at(int i) const const
QString translate(const char *context, const char *sourceText, const char *disambiguation, int n)
KCOREADDONS_EXPORT QList< QUrl > urlsFromMimeData(const QMimeData *mimeData, DecodeOptions decodeOptions=PreferKdeUrls, MetaDataMap *metaData=nullptr)
KBookmark createNewSeparator()
Create a new bookmark separator Don&#39;t forget to use KBookmarkManager::self()->emitChanged( parentBook...
Definition: kbookmark.cpp:175
QDomElement findToolbar() const
Definition: kbookmark.cpp:248
bool isEmpty() const const
QDomElement nextSiblingElement(const QString &tagName) const const
QDomElement previousSiblingElement(const QString &tagName) const const
QDomElement documentElement() const const
QDomNodeList childNodes() const const
QString toString(QUrl::FormattingOptions options) const const
int size() const const
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
bool isNull() const const
QDomElement toElement() const const
void setData(const QString &v)
int indexOf(const KBookmark &child) const
Return the index of a child bookmark, -1 if not found.
Definition: kbookmark.cpp:132
int count() const const
QString number(int n, int base)
void append(const T &value)
KBookmarkGroup()
Create an invalid group.
Definition: kbookmark.cpp:102
QDomDocument ownerDocument() const const
QMimeType mimeTypeForUrl(const QUrl &url) const const
void setAttribute(const QString &name, const QString &value)
KBookmark addBookmark(const KBookmark &bm)
Create a new bookmark, as the last child of this group Don&#39;t forget to use KBookmarkManager::self()->...
Definition: kbookmark.cpp:212
int toInt(bool *ok, int base) const const
bool isEmpty() const const
static QStringList mimeDataTypes()
Return the list of mimeTypes that can be decoded by fromMimeData.
Definition: kbookmark.cpp:701
A group of bookmarks.
Definition: kbookmark.h:327
KCOREADDONS_EXPORT QString csqueeze(const QString &str, int maxlen=40)
KBookmark::List is a QList that contains bookmarks with a few convenience methods.
Definition: kbookmark.h:47
QMimeType mimeTypeForName(const QString &nameOrAlias) const const
QDomText createTextNode(const QString &value)
QDomNode namedItem(const QString &name) const const
bool isValid() const const
QStringRef midRef(int position, int n) const const
bool isNull() const const
QString & replace(int position, int n, QChar after)
static bool canDecode(const QMimeData *mimeData)
Return true if mimeData contains bookmarks.
Definition: kbookmark.cpp:696
QDomNode firstChild() const const
bool hasUrls() const const
QDomNode parentNode() const const
qint64 toSecsSinceEpoch() const const
QDomElement firstChildElement(const QString &tagName) const const
int length() const const
bool isOpen() const
Definition: kbookmark.cpp:112
QString left(int n) const const
KCOREADDONS_EXPORT QStringList mimeDataTypes()
QString tagName() const const
void setData(const QString &mimeType, const QByteArray &data)
QDomElement createElement(const QString &tagName)
QList< QUrl > groupUrlList() const
Definition: kbookmark.cpp:263
QDomText toText() const const
static KBookmark::List fromMimeData(const QMimeData *mimeData, QDomDocument &parentDocument)
Extract a list of bookmarks from the contents of mimeData.
Definition: kbookmark.cpp:706
KBookmark next(const KBookmark &current) const
Return the next sibling of a child bookmark of this group.
Definition: kbookmark.cpp:127
QDomNode insertBefore(const QDomNode &newChild, const QDomNode &refChild)
KBookmark first() const
Return the first child bookmark of this group.
Definition: kbookmark.cpp:117
QDateTime currentDateTimeUtc()
void setUrls(const QList< QUrl > &urls)
KBookmarkGroup createNewFolder(const QString &text)
Create a new bookmark folder, as the last child of this group.
Definition: kbookmark.cpp:160
QByteArray toByteArray(int indent) const const
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
T & top()
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Jul 14 2020 22:40:02 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.