2005-05-12 12:15:44 +00:00
|
|
|
// -*- indent-tabs-mode:nil -*-
|
2003-10-06 18:31:25 +00:00
|
|
|
// vim: set ts=4 sts=4 sw=4 et:
|
2003-08-28 18:27:21 +00:00
|
|
|
/* This file is part of the KDE project
|
|
|
|
Copyright (C) 2003 Alexander Kellett <lypanov@kde.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
2007-12-16 15:37:21 +00:00
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
the License, or (at your option) version 3.
|
2003-08-28 18:27:21 +00:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-12-16 15:37:21 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2003-08-28 18:27:21 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2007-12-16 15:37:21 +00:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>
|
2003-08-28 18:27:21 +00:00
|
|
|
*/
|
|
|
|
|
2003-09-14 18:07:31 +00:00
|
|
|
#include "exporters.h"
|
|
|
|
|
2003-08-28 18:27:21 +00:00
|
|
|
#include <kdebug.h>
|
|
|
|
#include <klocale.h>
|
|
|
|
|
2007-05-09 22:23:52 +00:00
|
|
|
#include <QtCore/QFile>
|
|
|
|
#include <QtCore/QTextStream>
|
2003-08-28 18:27:21 +00:00
|
|
|
|
2009-11-17 15:46:55 +00:00
|
|
|
HTMLExporter::HTMLExporter()
|
2005-07-28 14:59:42 +00:00
|
|
|
: m_out(&m_string, QIODevice::WriteOnly) {
|
2003-10-19 12:20:20 +00:00
|
|
|
}
|
2003-08-25 20:56:36 +00:00
|
|
|
|
2005-06-14 02:57:24 +00:00
|
|
|
void HTMLExporter::write(const KBookmarkGroup &grp, const QString &filename, bool showAddress) {
|
2003-10-11 13:39:50 +00:00
|
|
|
QFile file(filename);
|
2005-07-28 14:59:42 +00:00
|
|
|
if (!file.open(QIODevice::WriteOnly)) {
|
2006-02-06 15:07:10 +00:00
|
|
|
kError(7043) << "Can't write to file " << filename << endl;
|
2003-10-11 13:39:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
QTextStream tstream(&file);
|
2006-04-04 18:51:37 +00:00
|
|
|
tstream.setCodec("UTF-8");
|
2005-06-14 02:57:24 +00:00
|
|
|
tstream << toString(grp, showAddress);
|
2003-08-28 18:27:21 +00:00
|
|
|
}
|
|
|
|
|
2005-06-14 02:57:24 +00:00
|
|
|
QString HTMLExporter::toString(const KBookmarkGroup &grp, bool showAddress)
|
2003-08-28 18:27:21 +00:00
|
|
|
{
|
2005-06-14 02:57:24 +00:00
|
|
|
m_showAddress = showAddress;
|
2003-10-11 13:39:50 +00:00
|
|
|
traverse(grp);
|
2005-06-14 02:25:41 +00:00
|
|
|
return "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
|
|
|
|
"<html><head><title>"+i18n("My Bookmarks")+"</title>\n"
|
|
|
|
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"
|
|
|
|
"</head>\n"
|
|
|
|
"<body>\n"
|
|
|
|
"<div>"
|
2003-10-19 12:20:20 +00:00
|
|
|
+ m_string +
|
2005-06-14 02:25:41 +00:00
|
|
|
"</div>\n"
|
|
|
|
"</body>\n</html>\n";
|
2003-08-25 20:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLExporter::visit(const KBookmark &bk) {
|
2007-08-03 06:40:12 +00:00
|
|
|
// kDebug() << "visit(" << bk.text() << ")";
|
2005-06-14 02:25:41 +00:00
|
|
|
if(bk.isSeparator())
|
|
|
|
{
|
|
|
|
m_out << bk.fullText() << "<br>"<<endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-14 02:57:24 +00:00
|
|
|
if(m_showAddress)
|
|
|
|
{
|
|
|
|
m_out << bk.fullText() <<"<br>"<< endl;
|
2005-09-24 12:02:49 +00:00
|
|
|
m_out << "<i><div style =\"margin-left: 1em\">" << bk.url().url().toUtf8() << "</div></i>";
|
2005-06-14 02:57:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-09-24 12:02:49 +00:00
|
|
|
m_out << "<a href=\"" << bk.url().url().toUtf8() << "\">";
|
2005-06-14 02:57:24 +00:00
|
|
|
m_out << bk.fullText() << "</a><br>" << endl;
|
|
|
|
}
|
2005-06-14 02:25:41 +00:00
|
|
|
}
|
2003-08-25 20:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLExporter::visitEnter(const KBookmarkGroup &grp) {
|
2007-08-03 06:40:12 +00:00
|
|
|
// kDebug() << "visitEnter(" << grp.text() << ")";
|
2005-06-14 02:25:41 +00:00
|
|
|
m_out << "<b>" << grp.fullText() << "</b><br>" << endl;
|
|
|
|
m_out << "<div style=\"margin-left: 2em\">"<< endl;
|
2009-11-17 15:46:55 +00:00
|
|
|
}
|
2003-08-25 20:56:36 +00:00
|
|
|
|
|
|
|
void HTMLExporter::visitLeave(const KBookmarkGroup &) {
|
2007-08-03 06:40:12 +00:00
|
|
|
// kDebug() << "visitLeave()";
|
2005-06-14 02:25:41 +00:00
|
|
|
m_out << "</div>" << endl;
|
2003-08-25 20:56:36 +00:00
|
|
|
}
|
|
|
|
|