35 #include <qtextcodec.h>
36 #include <qtextdocument.h>
37 #include <QtGui/QApplication>
44 QTextCodec * codec = m_utf8 ? QTextCodec::codecForName(
"UTF-8") : QTextCodec::codecForLocale();
49 if(f.open(QIODevice::ReadOnly)) {
51 static const int g_lineLimit = 16*1024;
52 QByteArray s(g_lineLimit,0);
54 while(f.readLine(s.data(), g_lineLimit) >= 1 && !s.contains(
"<DL>")) {
58 while(
int size = f.readLine(s.data(), g_lineLimit)>=1) {
59 if ( size == g_lineLimit )
61 kWarning() <<
"Netscape bookmarks contain a line longer than " << g_lineLimit <<
". Skipping.";
64 QByteArray t = s.trimmed();
65 if(t.left(12).toUpper() ==
"<DT><A HREF=" ||
66 t.left(16).toUpper() ==
"<DT><H3><A HREF=") {
68 int firstQuotes = t.indexOf(
'"')+1;
69 int secondQuotes = t.indexOf(
'"', firstQuotes);
70 if (firstQuotes != -1 && secondQuotes != -1)
72 QByteArray
link = t.mid(firstQuotes, secondQuotes-firstQuotes);
73 int endTag = t.indexOf(
'>', secondQuotes+1);
75 int closeTag = t.indexOf(
'<', endTag + 1);
77 QByteArray
name = t.mid(endTag + 1, closeTag - endTag - 1);
79 QByteArray additionalInfo = t.mid( secondQuotes+1, endTag-secondQuotes-1 );
82 codec->toUnicode(link),
86 else if(t.left(7).toUpper() ==
"<DT><H3") {
87 int endTag = t.indexOf(
'>', 7);
88 QByteArray
name = t.mid(endTag+1);
89 name = name.left(name.indexOf(
'<'));
91 QByteArray additionalInfo = t.mid( 8, endTag-8 );
92 bool folded = (additionalInfo.left(6) ==
"FOLDED");
93 if (folded) additionalInfo.remove(0,7);
99 else if(t.left(4).toUpper() ==
"<HR>")
101 else if(t.left(8).toUpper() ==
"</DL><P>")
115 i18n(
"*.html|HTML Files (*.html)"),
116 QApplication::activeWindow() );
119 i18n(
"*.html|HTML Files (*.html)"),
120 QApplication::activeWindow() );
124 return QDir::homePath() +
"/.netscape/bookmarks.html";
137 QString errorMsg =
QString(
"Could not find %1. Netscape is probably not installed. "
145 QFile::encodeName(
m_fileName +
".beforekde"));
150 if (!file.open(QIODevice::WriteOnly)) {
155 QTextStream fstream(&file);
156 fstream.setCodec(m_utf8 ? QTextCodec::codecForName(
"UTF-8") : QTextCodec::codecForLocale());
159 = m_utf8 ?
"UTF-8" : QString::fromLatin1(QTextCodec::codecForLocale()->
name()).toUpper();
161 fstream <<
"<!DOCTYPE NETSCAPE-Bookmark-file-1>" << endl
162 <<
i18n(
"<!-- This file was generated by Konqueror -->") << endl
163 <<
"<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset="
164 << charset <<
"\">" << endl
165 <<
"<TITLE>" <<
i18n(
"Bookmarks") <<
"</TITLE>" << endl
166 <<
"<H1>" <<
i18n(
"Bookmarks") <<
"</H1>" << endl
169 <<
"</DL><P>" << endl;
174 QTextStream fstream(&str, QIODevice::WriteOnly);
177 if (bk.isSeparator()) {
178 fstream <<
"<HR>" << endl;
182 QString text = Qt::escape(bk.fullText());
185 fstream <<
"<DT><H3 "
186 << (!bk.toGroup().isOpen() ?
"FOLDED " :
"")
187 << bk.internalElement().attribute(
"netscapeinfo") <<
">"
188 << text <<
"</H3>" << endl
191 <<
"</DL><P>" << endl;
196 fstream <<
"<DT><A HREF=\"" << bk.url().url() <<
"\""
197 << bk.internalElement().attribute(
"netscapeinfo") <<
">"
198 << text <<
"</A>" << endl;