File indexing completed on 2025-03-09 05:13:03
0001 /* This file is part of the KDE project 0002 Copyright (C) 2000 David Faure <faure@kde.org> 0003 Copyright (C) 2002-2003 Alexander Kellett <lypanov@kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This program is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this program; see the file COPYING. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #include "kbookmarkdombuilder.h" 0022 #include "kbookmarks_debug.h" 0023 #include <kbookmarkmanager.h> 0024 0025 KBookmarkDomBuilder::KBookmarkDomBuilder( 0026 const KBookmarkGroup &bkGroup, KBookmarkManager *manager 0027 ) 0028 { 0029 m_manager = manager; 0030 m_stack.push(bkGroup); 0031 } 0032 0033 KBookmarkDomBuilder::~KBookmarkDomBuilder() 0034 { 0035 m_list.clear(); 0036 m_stack.clear(); 0037 } 0038 0039 void KBookmarkDomBuilder::connectImporter(const QObject *importer) 0040 { 0041 connect(importer, SIGNAL(newBookmark(QString,QString,QString)), 0042 SLOT(newBookmark(QString,QString,QString))); 0043 connect(importer, SIGNAL(newFolder(QString,bool,QString)), 0044 SLOT(newFolder(QString,bool,QString))); 0045 connect(importer, SIGNAL(newSeparator()), 0046 SLOT(newSeparator())); 0047 connect(importer, SIGNAL(endFolder()), 0048 SLOT(endFolder())); 0049 } 0050 0051 void KBookmarkDomBuilder::newBookmark( 0052 const QString &text, const QString &url, const QString &additionalInfo 0053 ) 0054 { 0055 if (!m_stack.isEmpty()) { 0056 KBookmark bk = m_stack.top().addBookmark( 0057 text, 0058 QUrl(url), 0059 QString()); 0060 // store additional info 0061 bk.internalElement().setAttribute(QStringLiteral("netscapeinfo"), additionalInfo); 0062 } else { 0063 qCWarning(KBOOKMARKS_LOG) << "m_stack is empty. This should not happen when importing a valid bookmarks file!"; 0064 } 0065 } 0066 0067 void KBookmarkDomBuilder::newFolder( 0068 const QString &text, bool open, const QString &additionalInfo 0069 ) 0070 { 0071 if (!m_stack.isEmpty()) { 0072 // we use a qvaluelist so that we keep pointers to valid objects in the stack 0073 KBookmarkGroup gp = m_stack.top().createNewFolder(text); 0074 m_list.append(gp); 0075 m_stack.push(m_list.last()); 0076 // store additional info 0077 QDomElement element = m_list.last().internalElement(); 0078 element.setAttribute(QStringLiteral("netscapeinfo"), additionalInfo); 0079 element.setAttribute(QStringLiteral("folded"), open ? QStringLiteral("no") : QStringLiteral("yes")); 0080 } else { 0081 qCWarning(KBOOKMARKS_LOG) << "m_stack is empty. This should not happen when importing a valid bookmarks file!"; 0082 } 0083 } 0084 0085 void KBookmarkDomBuilder::newSeparator() 0086 { 0087 if (!m_stack.isEmpty()) { 0088 m_stack.top().createNewSeparator(); 0089 } else { 0090 qCWarning(KBOOKMARKS_LOG) << "m_stack is empty. This should not happen when importing a valid bookmarks file!"; 0091 } 0092 } 0093 0094 void KBookmarkDomBuilder::endFolder() 0095 { 0096 if (!m_stack.isEmpty()) { 0097 m_stack.pop(); 0098 } else { 0099 qCWarning(KBOOKMARKS_LOG) << "m_stack is empty. This should not happen when importing a valid bookmarks file!"; 0100 } 0101 } 0102 0103 #include "moc_kbookmarkdombuilder.cpp"