Warning, file /frameworks/kbookmarks/src/kbookmarkdombuilder.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 This file is part of the KDE project 0003 SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org> 0004 SPDX-FileCopyrightText: 2002-2003 Alexander Kellett <lypanov@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #include "kbookmarkdombuilder.h" 0010 #include "kbookmarks_debug.h" 0011 #include <kbookmarkmanager.h> 0012 0013 KBookmarkDomBuilder::KBookmarkDomBuilder(const KBookmarkGroup &bkGroup, KBookmarkManager *manager) 0014 { 0015 m_manager = manager; 0016 m_stack.push(bkGroup); 0017 } 0018 0019 KBookmarkDomBuilder::~KBookmarkDomBuilder() 0020 { 0021 m_list.clear(); 0022 m_stack.clear(); 0023 } 0024 0025 void KBookmarkDomBuilder::connectImporter(const QObject *importer) 0026 { 0027 // clang-format off 0028 connect(importer, SIGNAL(newBookmark(QString,QString,QString)), SLOT(newBookmark(QString,QString,QString))); 0029 connect(importer, SIGNAL(newFolder(QString,bool,QString)), SLOT(newFolder(QString,bool,QString))); 0030 // clang-format on 0031 connect(importer, SIGNAL(newSeparator()), SLOT(newSeparator())); 0032 connect(importer, SIGNAL(endFolder()), SLOT(endFolder())); 0033 } 0034 0035 void KBookmarkDomBuilder::newBookmark(const QString &text, const QString &url, const QString &additionalInfo) 0036 { 0037 if (!m_stack.isEmpty()) { 0038 KBookmark bk = m_stack.top().addBookmark(text, QUrl(url), QString()); 0039 // store additional info 0040 bk.internalElement().setAttribute(QStringLiteral("netscapeinfo"), additionalInfo); 0041 } else { 0042 qCWarning(KBOOKMARKS_LOG) << "m_stack is empty. This should not happen when importing a valid bookmarks file!"; 0043 } 0044 } 0045 0046 void KBookmarkDomBuilder::newFolder(const QString &text, bool open, const QString &additionalInfo) 0047 { 0048 if (!m_stack.isEmpty()) { 0049 // we use a qvaluelist so that we keep pointers to valid objects in the stack 0050 KBookmarkGroup gp = m_stack.top().createNewFolder(text); 0051 m_list.append(gp); 0052 m_stack.push(m_list.last()); 0053 // store additional info 0054 QDomElement element = m_list.last().internalElement(); 0055 element.setAttribute(QStringLiteral("netscapeinfo"), additionalInfo); 0056 element.setAttribute(QStringLiteral("folded"), open ? QStringLiteral("no") : QStringLiteral("yes")); 0057 } else { 0058 qCWarning(KBOOKMARKS_LOG) << "m_stack is empty. This should not happen when importing a valid bookmarks file!"; 0059 } 0060 } 0061 0062 void KBookmarkDomBuilder::newSeparator() 0063 { 0064 if (!m_stack.isEmpty()) { 0065 m_stack.top().createNewSeparator(); 0066 } else { 0067 qCWarning(KBOOKMARKS_LOG) << "m_stack is empty. This should not happen when importing a valid bookmarks file!"; 0068 } 0069 } 0070 0071 void KBookmarkDomBuilder::endFolder() 0072 { 0073 if (!m_stack.isEmpty()) { 0074 m_stack.pop(); 0075 } else { 0076 qCWarning(KBOOKMARKS_LOG) << "m_stack is empty. This should not happen when importing a valid bookmarks file!"; 0077 } 0078 } 0079 0080 #include "moc_kbookmarkdombuilder.cpp"