31 return BookmarksExporter::tr(
"HTML File") +
QL1S(
" (bookmarks.html)");
36 const QString defaultPath = QDir::homePath() + QLatin1String(
"/bookmarks.html");
37 const QString filter = BookmarksExporter::tr(
"HTML Bookmarks") +
QL1S(
" (.html)");
38 m_path =
QzTools::getSaveFileName(QStringLiteral(
"HtmlExporter"), parent, BookmarksExporter::tr(
"Choose file..."), defaultPath, filter);
46 if (!file.open(QFile::WriteOnly | QFile::Truncate)) {
47 setError(BookmarksExporter::tr(
"Cannot open file for writing!"));
51 QTextStream stream(&file);
52 stream.setEncoding(QStringConverter::Utf8);
54 stream <<
"<!DOCTYPE NETSCAPE-Bookmark-file-1>" << Qt::endl;
55 stream <<
"<!-- This is an automatically generated file." << Qt::endl;
56 stream <<
" It will be read and overwritten." << Qt::endl;
57 stream <<
" DO NOT EDIT! -->" << Qt::endl;
58 stream << R
"(<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">)" << Qt::endl;
59 stream << "<TITLE>Bookmarks</TITLE>" << Qt::endl;
60 stream <<
"<H1>Bookmarks</H1>" << Qt::endl;
62 writeBookmark(root, stream, 0);
66void HtmlExporter::writeBookmark(
BookmarkItem* item, QTextStream &stream,
int level)
71 indent.fill(QLatin1Char(
' '), level * 4);
73 switch (item->
type()) {
75 stream << indent <<
"<DT><A HREF=\"" << item->
urlString() <<
"\">" << item->
title() <<
"</A>" << Qt::endl;
79 stream << indent <<
"<HR>" << Qt::endl;
83 stream << indent <<
"<DT><H3>" << item->
title() <<
"</H3>" << Qt::endl;
84 stream << indent <<
"<DL><p>" << Qt::endl;
86 const auto children = item->
children();
88 writeBookmark(child, stream, level + 1);
91 stream << indent <<
"</DL><p>" << Qt::endl;
96 stream << indent <<
"<DL><p>" << Qt::endl;
98 const auto children = item->
children();
100 writeBookmark(child, stream, level + 1);
103 stream << indent <<
"</DL><p>" << Qt::endl;
QString urlString() const
QList< BookmarkItem * > children() const
void setError(const QString &error)
QString name() const override
HtmlExporter(QObject *parent=nullptr)
QString getPath(QWidget *parent) override
bool exportBookmarks(BookmarkItem *root) override