KIO
kbookmarkdombuilder.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 ),
00056 QString());
00057
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
00069 KBookmarkGroup gp = m_stack.top().createNewFolder(text);
00070 m_list.append(gp);
00071 m_stack.push(m_list.last());
00072
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"