19 #include <tdefiledialog.h>
20 #include <kstringhandler.h>
21 #include <tdelocale.h>
23 #include <tqtextcodec.h>
25 #include <sys/types.h>
30 #include "kbookmarkimporter.h"
31 #include "kbookmarkimporter_opera.h"
33 void KOperaBookmarkImporter::parseOperaBookmarks( )
35 TQFile file(m_fileName);
36 if(!file.open(IO_ReadOnly)) {
40 TQTextCodec * codec = TQTextCodec::codecForName(
"UTF-8");
46 TQString url, name, type;
47 static const int g_lineLimit = 16*1024;
48 TQCString line(g_lineLimit);
50 while ( file.readLine(line.data(), g_lineLimit) >=0 ) {
54 if ( line[line.length()-1] !=
'\n' || lineno <= 2 )
57 TQString currentLine = codec->toUnicode(line).stripWhiteSpace();
59 if (currentLine.isEmpty()) {
63 else if ( type ==
"URL")
64 emit newBookmark( name, url.latin1(),
"" );
65 else if (type ==
"FOLDER" )
66 emit newFolder( name,
false,
"" );
68 type = TQString::null;
69 name = TQString::null;
72 }
else if (currentLine ==
"-") {
79 if ( tag =
"#", currentLine.startsWith( tag ) )
80 type = currentLine.remove( 0, tag.length() );
81 else if ( tag =
"NAME=", currentLine.startsWith( tag ) )
82 name = currentLine.remove(0, tag.length());
83 else if ( tag =
"URL=", currentLine.startsWith( tag ) )
84 url = currentLine.remove(0, tag.length());
90 TQString KOperaBookmarkImporter::operaBookmarksFile()
95 return p->findDefaultLocation();
98 void KOperaBookmarkImporterImpl::parse() {
100 setupSignalForwards(&importer,
this);
101 importer.parseOperaBookmarks();
104 TQString KOperaBookmarkImporterImpl::findDefaultLocation(
bool saving)
const
106 return saving ? KFileDialog::getSaveFileName(
107 TQDir::homeDirPath() +
"/.opera",
108 i18n(
"*.adr|Opera Bookmark Files (*.adr)") )
109 : KFileDialog::getOpenFileName(
110 TQDir::homeDirPath() +
"/.opera",
111 i18n(
"*.adr|Opera Bookmark Files (*.adr)") );
119 TQString generate(
const KBookmarkGroup &grp ) { traverse(grp);
return m_string; };
121 virtual void visit(
const KBookmark & );
129 OperaExporter::OperaExporter() : m_out(&m_string, IO_WriteOnly) {
130 m_out <<
"Opera Hotlist version 2.0" << endl;
131 m_out <<
"Options: encoding = utf8, version=3" << endl;
134 void OperaExporter::visit(
const KBookmark &bk ) {
136 m_out <<
"#URL" << endl;
137 m_out <<
"\tNAME=" << bk.fullText() << endl;
138 m_out <<
"\tURL=" << bk.url().url().utf8() << endl;
144 m_out <<
"#FOLDER" << endl;
145 m_out <<
"\tNAME="<< grp.fullText() << endl;
151 m_out <<
"-" << endl;
156 OperaExporter exporter;
157 TQString content = exporter.generate( parent );
158 TQFile file(m_fileName);
159 if (!file.open(IO_WriteOnly)) {
160 kdError(7043) <<
"Can't write to file " << m_fileName << endl;
163 TQTextStream fstream(&file);
164 fstream.setEncoding(TQTextStream::UnicodeUTF8);
168 #include "kbookmarkimporter_opera.moc"
A class for importing Opera bookmarks.
A class for importing Opera bookmarks.