Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / apps / keditbookmarks / exporters.cpp
blobb401320c047a656f71a0c1fac981e8d3a61356b9
1 // -*- indent-tabs-mode:nil -*-
2 // vim: set ts=4 sts=4 sw=4 et:
3 /* This file is part of the KDE project
4 Copyright (C) 2003 Alexander Kellett <lypanov@kde.org>
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License, or (at your option) version 3.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>
20 #include "exporters.h"
22 #include <kdebug.h>
23 #include <klocale.h>
24 #include <kapplication.h>
26 #include <QtCore/QFile>
27 //Added by qt3to4:
28 #include <QtCore/QTextStream>
30 HTMLExporter::HTMLExporter()
31 : m_out(&m_string, QIODevice::WriteOnly) {
34 void HTMLExporter::write(const KBookmarkGroup &grp, const QString &filename, bool showAddress) {
35 QFile file(filename);
36 if (!file.open(QIODevice::WriteOnly)) {
37 kError(7043) << "Can't write to file " << filename << endl;
38 return;
40 QTextStream tstream(&file);
41 tstream.setCodec("UTF-8");
42 tstream << toString(grp, showAddress);
45 QString HTMLExporter::toString(const KBookmarkGroup &grp, bool showAddress)
47 m_showAddress = showAddress;
48 traverse(grp);
49 return "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
50 "<html><head><title>"+i18n("My Bookmarks")+"</title>\n"
51 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"
52 "</head>\n"
53 "<body>\n"
54 "<div>"
55 + m_string +
56 "</div>\n"
57 "</body>\n</html>\n";
60 void HTMLExporter::visit(const KBookmark &bk) {
61 // kDebug() << "visit(" << bk.text() << ")";
62 if(bk.isSeparator())
64 m_out << bk.fullText() << "<br>"<<endl;
66 else
68 if(m_showAddress)
70 m_out << bk.fullText() <<"<br>"<< endl;
71 m_out << "<i><div style =\"margin-left: 1em\">" << bk.url().url().toUtf8() << "</div></i>";
73 else
75 m_out << "<a href=\"" << bk.url().url().toUtf8() << "\">";
76 m_out << bk.fullText() << "</a><br>" << endl;
81 void HTMLExporter::visitEnter(const KBookmarkGroup &grp) {
82 // kDebug() << "visitEnter(" << grp.text() << ")";
83 m_out << "<b>" << grp.fullText() << "</b><br>" << endl;
84 m_out << "<div style=\"margin-left: 2em\">"<< endl;
87 void HTMLExporter::visitLeave(const KBookmarkGroup &) {
88 // kDebug() << "visitLeave()";
89 m_out << "</div>" << endl;