34 #include <qtextcodec.h> 35 #include <qtextdocument.h> 36 #include <QtGui/QApplication> 43 QTextCodec * codec = m_utf8 ? QTextCodec::codecForName(
"UTF-8") : QTextCodec::codecForLocale();
48 if(f.open(QIODevice::ReadOnly)) {
50 static const int g_lineLimit = 16*1024;
51 QByteArray s(g_lineLimit,0);
53 while(f.readLine(s.data(), g_lineLimit) >= 1 && !s.contains(
"<DL>")) {
57 while(
int size = f.readLine(s.data(), g_lineLimit)>=1) {
58 if ( size == g_lineLimit )
60 kWarning() <<
"Netscape bookmarks contain a line longer than " << g_lineLimit <<
". Skipping.";
63 QByteArray t = s.trimmed();
65 if (t.left(4).toUpper() ==
"<HR>") {
67 t = t.mid(4).trimmed();
73 if(t.left(12).toUpper() ==
"<DT><A HREF=" ||
74 t.left(16).toUpper() ==
"<DT><H3><A HREF=") {
76 int firstQuotes = t.indexOf(
'"')+1;
77 int secondQuotes = t.indexOf(
'"', firstQuotes);
78 if (firstQuotes != -1 && secondQuotes != -1)
80 QByteArray
link = t.mid(firstQuotes, secondQuotes-firstQuotes);
81 int endTag = t.indexOf(
'>', secondQuotes+1);
83 int closeTag = t.indexOf(
'<', endTag + 1);
85 QByteArray
name = t.mid(endTag + 1, closeTag - endTag - 1);
87 QByteArray additionalInfo = t.mid( secondQuotes+1, endTag-secondQuotes-1 );
90 codec->toUnicode(link),
94 else if(t.left(7).toUpper() ==
"<DT><H3") {
95 int endTag = t.indexOf(
'>', 7);
96 QByteArray
name = t.mid(endTag+1);
97 name = name.left(name.indexOf(
'<'));
99 QByteArray additionalInfo = t.mid( 8, endTag-8 );
100 bool folded = (additionalInfo.left(6) ==
"FOLDED");
101 if (folded) additionalInfo.remove(0,7);
107 else if(t.left(8).toUpper() ==
"</DL><P>") {
122 i18n(
"*.html|HTML Files (*.html)"),
123 QApplication::activeWindow() );
126 i18n(
"*.html|HTML Files (*.html)"),
127 QApplication::activeWindow() );
131 return QDir::homePath() +
"/.netscape/bookmarks.html";
144 QString errorMsg = QString(
"Could not find %1. Netscape is probably not installed. " 155 if (!file.open(QIODevice::WriteOnly)) {
160 QTextStream fstream(&file);
161 fstream.setCodec(m_utf8 ? QTextCodec::codecForName(
"UTF-8") : QTextCodec::codecForLocale());
164 = m_utf8 ?
"UTF-8" : QString::fromLatin1(QTextCodec::codecForLocale()->
name()).toUpper();
166 fstream <<
"<!DOCTYPE NETSCAPE-Bookmark-file-1>" << endl
167 <<
i18n(
"<!-- This file was generated by Konqueror -->") << endl
168 <<
"<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=" 169 << charset <<
"\">" << endl
170 <<
"<TITLE>" <<
i18n(
"Bookmarks") <<
"</TITLE>" << endl
171 <<
"<H1>" <<
i18n(
"Bookmarks") <<
"</H1>" << endl
173 << folderAsString(parent)
174 <<
"</DL><P>" << endl;
179 QTextStream fstream(&str, QIODevice::WriteOnly);
182 if (bk.isSeparator()) {
183 fstream <<
"<HR>" << endl;
187 QString text = Qt::escape(bk.fullText());
190 fstream <<
"<DT><H3 " 191 << (!bk.toGroup().isOpen() ?
"FOLDED " :
"")
192 << bk.internalElement().attribute(
"netscapeinfo") <<
">" 193 << text <<
"</H3>" << endl
195 << folderAsString(bk.toGroup())
196 <<
"</DL><P>" << endl;
201 fstream <<
"<DT><A HREF=\"" << bk.url().url() <<
"\"" 202 << bk.internalElement().attribute(
"netscapeinfo") <<
">" 203 << text <<
"</A>" << endl;
QString i18n(const char *text)
void endFolder()
Tell the outside world that we're going down one menu.
const char * name(StandardAction id)
static QDebug kError(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
static quint32 f(DES_KEY *key, quint32 r, char *subkey)
virtual void write(const KBookmarkGroup &parent)
static QString getOpenFileName(const KUrl &startDir=KUrl(), const QString &filter=QString(), QWidget *parent=0, const QString &caption=QString())
Creates a modal file dialog and return the selected filename or an empty string if none was chosen...
void newBookmark(const QString &text, const QString &url, const QString &additionalInfo)
Notify about a new bookmark Use "html" for the icon.
CopyJob * link(const KUrl &src, const KUrl &destDir, JobFlags flags=DefaultFlags)
Create a link.
static QString getSaveFileName(const KUrl &startDir=KUrl(), const QString &filter=QString(), QWidget *parent=0, const QString &caption=QString())
Creates a modal file dialog and returns the selected filename or an empty string if none was chosen...
QString folderAsString(const KBookmarkGroup &parent) const
static QString resolveEntities(const QString &text)
void newSeparator()
Notify about a new separator.
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KBookmark next(const KBookmark ¤t) const
Return the next sibling of a child bookmark of this group.
KBookmark first() const
Return the first child bookmark of this group.
static void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
virtual QString findDefaultLocation(bool forSaving=false) const
void newFolder(const QString &text, bool open, const QString &additionalInfo)
Notify about a new folder Use "bookmark_folder" for the icon.