KIO
kbookmarkdombuilder.cc
Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 Copyright (C) 2000 David Faure <faure@kde.org> 00003 Copyright (C) 2002-2003 Alexander Kellett <lypanov@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this program; see the file COPYING. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include "kbookmarkdombuilder.h" 00022 00023 #include <kbookmarkmanager.h> 00024 #include <kdebug.h> 00025 00026 KBookmarkDomBuilder::KBookmarkDomBuilder( 00027 const KBookmarkGroup &bkGroup, KBookmarkManager *manager 00028 ) { 00029 m_manager = manager; 00030 m_stack.push(bkGroup); 00031 } 00032 00033 KBookmarkDomBuilder::~KBookmarkDomBuilder() { 00034 m_list.clear(); 00035 m_stack.clear(); 00036 } 00037 00038 void KBookmarkDomBuilder::connectImporter(const QObject *importer) { 00039 connect(importer, SIGNAL( newBookmark(const QString &, const QString &, const QString &) ), 00040 SLOT( newBookmark(const QString &, const QString &, const QString &) )); 00041 connect(importer, SIGNAL( newFolder(const QString &, bool, const QString &) ), 00042 SLOT( newFolder(const QString &, bool, const QString &) )); 00043 connect(importer, SIGNAL( newSeparator() ), 00044 SLOT( newSeparator() ) ); 00045 connect(importer, SIGNAL( endFolder() ), 00046 SLOT( endFolder() ) ); 00047 } 00048 00049 void KBookmarkDomBuilder::newBookmark( 00050 const QString &text, const QString &url, const QString &additionalInfo 00051 ) { 00052 if (!m_stack.isEmpty()) { 00053 KBookmark bk = m_stack.top().addBookmark( 00054 text, 00055 KUrl( url ), // utf8 00056 QString()); 00057 // store additional info 00058 bk.internalElement().setAttribute("netscapeinfo", additionalInfo); 00059 } 00060 else 00061 kWarning() << "m_stack is empty. This should not happen when importing a valid bookmarks file!"; 00062 } 00063 00064 void KBookmarkDomBuilder::newFolder( 00065 const QString & text, bool open, const QString & additionalInfo 00066 ) { 00067 if (!m_stack.isEmpty()) { 00068 // we use a qvaluelist so that we keep pointers to valid objects in the stack 00069 KBookmarkGroup gp = m_stack.top().createNewFolder(text); 00070 m_list.append(gp); 00071 m_stack.push(m_list.last()); 00072 // store additional info 00073 QDomElement element = m_list.last().internalElement(); 00074 element.setAttribute("netscapeinfo", additionalInfo); 00075 element.setAttribute("folded", (open?"no":"yes")); 00076 } 00077 else 00078 kWarning() << "m_stack is empty. This should not happen when importing a valid bookmarks file!"; 00079 } 00080 00081 void KBookmarkDomBuilder::newSeparator() { 00082 if (!m_stack.isEmpty()) 00083 m_stack.top().createNewSeparator(); 00084 else 00085 kWarning() << "m_stack is empty. This should not happen when importing a valid bookmarks file!"; 00086 } 00087 00088 void KBookmarkDomBuilder::endFolder() { 00089 if (!m_stack.isEmpty()) 00090 m_stack.pop(); 00091 else 00092 kWarning() << "m_stack is empty. This should not happen when importing a valid bookmarks file!"; 00093 } 00094 00095 #include "kbookmarkdombuilder.moc"
KDE 4.6 API Reference