kbookmarkdombuilder.cc

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