21 #include <tdefiledialog.h> 22 #include <kstringhandler.h> 23 #include <tdelocale.h> 25 #include <tqtextcodec.h> 27 #include <sys/types.h> 32 #include "kbookmarkimporter.h" 33 #include "kbookmarkimporter_opera.h" 35 void KOperaBookmarkImporter::parseOperaBookmarks( )
37 TQFile file(m_fileName);
38 if(!file.open(IO_ReadOnly)) {
42 TQTextCodec * codec = TQTextCodec::codecForName(
"UTF-8");
48 TQString url, name, type;
49 static const int g_lineLimit = 16*1024;
50 TQCString line(g_lineLimit);
52 while ( file.readLine(line.data(), g_lineLimit) >=0 ) {
56 if ( line[line.length()-1] !=
'\n' || lineno <= 2 )
59 TQString currentLine = codec->toUnicode(line).stripWhiteSpace();
61 if (currentLine.isEmpty()) {
65 else if ( type ==
"URL")
66 emit newBookmark( name, url.latin1(),
"" );
67 else if (type ==
"FOLDER" )
68 emit newFolder( name,
false,
"" );
70 type = TQString::null;
71 name = TQString::null;
74 }
else if (currentLine ==
"-") {
81 if ( tag =
"#", currentLine.startsWith( tag ) )
82 type = currentLine.remove( 0, tag.length() );
83 else if ( tag =
"NAME=", currentLine.startsWith( tag ) )
84 name = currentLine.remove(0, tag.length());
85 else if ( tag =
"URL=", currentLine.startsWith( tag ) )
86 url = currentLine.remove(0, tag.length());
92 TQString KOperaBookmarkImporter::operaBookmarksFile()
97 return p->findDefaultLocation();
100 void KOperaBookmarkImporterImpl::parse() {
102 setupSignalForwards(&importer,
this);
103 importer.parseOperaBookmarks();
106 TQString KOperaBookmarkImporterImpl::findDefaultLocation(
bool saving)
const 108 return saving ? KFileDialog::getSaveFileName(
109 TQDir::homeDirPath() +
"/.opera",
110 i18n(
"*.adr|Opera Bookmark Files (*.adr)") )
111 : KFileDialog::getOpenFileName(
112 TQDir::homeDirPath() +
"/.opera",
113 i18n(
"*.adr|Opera Bookmark Files (*.adr)") );
121 TQString generate(
const KBookmarkGroup &grp ) { traverse(grp);
return m_string; };
123 virtual void visit(
const KBookmark & );
131 OperaExporter::OperaExporter() : m_out(&m_string, IO_WriteOnly) {
132 m_out <<
"Opera Hotlist version 2.0" << endl;
133 m_out <<
"Options: encoding = utf8, version=3" << endl;
136 void OperaExporter::visit(
const KBookmark &bk ) {
138 m_out <<
"#URL" << endl;
139 m_out <<
"\tNAME=" << bk.fullText() << endl;
140 m_out <<
"\tURL=" << bk.url().url().utf8() << endl;
146 m_out <<
"#FOLDER" << endl;
147 m_out <<
"\tNAME="<< grp.fullText() << endl;
153 m_out <<
"-" << endl;
158 OperaExporter exporter;
159 TQString content = exporter.generate( parent );
160 TQFile file(m_fileName);
161 if (!file.open(IO_WriteOnly)) {
162 kdError(7043) <<
"Can't write to file " << m_fileName << endl;
165 TQTextStream fstream(&file);
166 fstream.setEncoding(TQTextStream::UnicodeUTF8);
170 #include "kbookmarkimporter_opera.moc" A class for importing Opera bookmarks.
A class for importing Opera bookmarks.