KBookmarks

kbookmarkdombuilder.cpp
1 /*
2  This file is part of the KDE project
3  SPDX-FileCopyrightText: 2000 David Faure <[email protected]>
4  SPDX-FileCopyrightText: 2002-2003 Alexander Kellett <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "kbookmarkdombuilder.h"
10 #include "kbookmarks_debug.h"
11 #include <kbookmarkmanager.h>
12 
13 KBookmarkDomBuilder::KBookmarkDomBuilder(
14  const KBookmarkGroup &bkGroup, KBookmarkManager *manager
15 )
16 {
17  m_manager = manager;
18  m_stack.push(bkGroup);
19 }
20 
21 KBookmarkDomBuilder::~KBookmarkDomBuilder()
22 {
23  m_list.clear();
24  m_stack.clear();
25 }
26 
27 void KBookmarkDomBuilder::connectImporter(const QObject *importer)
28 {
29  connect(importer, SIGNAL(newBookmark(QString,QString,QString)),
30  SLOT(newBookmark(QString,QString,QString)));
31  connect(importer, SIGNAL(newFolder(QString,bool,QString)),
32  SLOT(newFolder(QString,bool,QString)));
33  connect(importer, SIGNAL(newSeparator()),
34  SLOT(newSeparator()));
35  connect(importer, SIGNAL(endFolder()),
36  SLOT(endFolder()));
37 }
38 
39 void KBookmarkDomBuilder::newBookmark(
40  const QString &text, const QString &url, const QString &additionalInfo
41 )
42 {
43  if (!m_stack.isEmpty()) {
44  KBookmark bk = m_stack.top().addBookmark(
45  text,
46  QUrl(url),
47  QString());
48  // store additional info
49  bk.internalElement().setAttribute(QStringLiteral("netscapeinfo"), additionalInfo);
50  } else {
51  qCWarning(KBOOKMARKS_LOG) << "m_stack is empty. This should not happen when importing a valid bookmarks file!";
52  }
53 }
54 
55 void KBookmarkDomBuilder::newFolder(
56  const QString &text, bool open, const QString &additionalInfo
57 )
58 {
59  if (!m_stack.isEmpty()) {
60  // we use a qvaluelist so that we keep pointers to valid objects in the stack
61  KBookmarkGroup gp = m_stack.top().createNewFolder(text);
62  m_list.append(gp);
63  m_stack.push(m_list.last());
64  // store additional info
65  QDomElement element = m_list.last().internalElement();
66  element.setAttribute(QStringLiteral("netscapeinfo"), additionalInfo);
67  element.setAttribute(QStringLiteral("folded"), open ? QStringLiteral("no") : QStringLiteral("yes"));
68  } else {
69  qCWarning(KBOOKMARKS_LOG) << "m_stack is empty. This should not happen when importing a valid bookmarks file!";
70  }
71 }
72 
73 void KBookmarkDomBuilder::newSeparator()
74 {
75  if (!m_stack.isEmpty()) {
76  m_stack.top().createNewSeparator();
77  } else {
78  qCWarning(KBOOKMARKS_LOG) << "m_stack is empty. This should not happen when importing a valid bookmarks file!";
79  }
80 }
81 
82 void KBookmarkDomBuilder::endFolder()
83 {
84  if (!m_stack.isEmpty()) {
85  m_stack.pop();
86  } else {
87  qCWarning(KBOOKMARKS_LOG) << "m_stack is empty. This should not happen when importing a valid bookmarks file!";
88  }
89 }
90 
91 #include "moc_kbookmarkdombuilder.cpp"
This class implements the reading/writing of bookmarks in XML.
void setAttribute(const QString &name, const QString &value)
A group of bookmarks.
Definition: kbookmark.h:316
KBookmarkGroup createNewFolder(const QString &text)
Create a new bookmark folder, as the last child of this group.
Definition: kbookmark.cpp:149
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Aug 8 2020 22:38:56 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.