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_ie.h"
34 void KIEBookmarkImporter::parseIEBookmarks_url_file( TQString filename, TQString name ) {
35 static const int g_lineLimit = 16*1024;
39 if(f.open(IO_ReadOnly)) {
41 TQCString s(g_lineLimit);
43 while(f.readLine(s.data(), g_lineLimit)>=0) {
44 if ( s[s.length()-1] !=
'\n' )
46 kdWarning() <<
"IE bookmarks contain a line longer than " << g_lineLimit <<
". Skipping." << endl;
49 TQCString t = s.stripWhiteSpace();
50 TQRegExp rx(
"URL=(.*)" );
51 if (rx.exactMatch(t)) {
52 emit newBookmark( name, TQString(rx.cap(1)).latin1(), TQString(
"") );
61 void KIEBookmarkImporter::parseIEBookmarks_dir( TQString dirname, TQString foldername )
65 dir.setFilter( TQDir::Files | TQDir::Dirs );
66 dir.setSorting( TQDir::Name | TQDir::DirsFirst );
67 dir.setNameFilter(
"*.url");
68 dir.setMatchAllDirs(
true);
70 const TQFileInfoList *list = dir.entryInfoList();
73 if (dirname != m_fileName)
74 emit newFolder( foldername,
false,
"" );
76 TQFileInfoListIterator it( *list );
79 while ( (fi = it.current()) != 0 ) {
82 if (fi->fileName() ==
"." || fi->fileName() ==
"..")
continue;
85 parseIEBookmarks_dir(fi->absFilePath(), fi->fileName());
87 }
else if (fi->isFile()) {
88 if (fi->fileName().endsWith(
".url")) {
89 TQString name = fi->fileName();
90 name.truncate(name.length() - 4);
91 parseIEBookmarks_url_file(fi->absFilePath(), name);
97 if (dirname != m_fileName)
102 void KIEBookmarkImporter::parseIEBookmarks( )
104 parseIEBookmarks_dir( m_fileName );
107 TQString KIEBookmarkImporter::IEBookmarksDir()
112 return p->findDefaultLocation();
115 void KIEBookmarkImporterImpl::parse() {
117 setupSignalForwards(&importer,
this);
118 importer.parseIEBookmarks();
121 TQString KIEBookmarkImporterImpl::findDefaultLocation(
bool)
const
129 return KFileDialog::getExistingDirectory();
136 IEExporter(
const TQString & );
139 virtual void visit(
const KBookmark & );
146 static TQString ieStyleQuote(
const TQString &str ) {
148 s.replace(TQRegExp(
"[/\\:*?\"<>|]"),
"_");
152 IEExporter::IEExporter(
const TQString & dname ) {
153 m_currentDir.setPath( dname );
156 void IEExporter::visit(
const KBookmark &bk ) {
157 TQString fname = m_currentDir.path() +
"/" + ieStyleQuote( bk.fullText() ) +
".url";
159 TQFile file( fname );
160 file.open( IO_WriteOnly );
161 TQTextStream ts( &file );
162 ts <<
"[InternetShortcut]\r\n";
163 ts <<
"URL=" << bk.url().url().utf8() <<
"\r\n";
167 TQString dname = m_currentDir.path() +
"/" + ieStyleQuote( grp.fullText() );
169 m_currentDir.mkdir( dname );
170 m_currentDir.cd( dname );
179 IEExporter exporter( m_fileName );
180 exporter.write( parent );
183 #include "kbookmarkimporter_ie.moc"
A class for importing IE bookmarks.
A class for importing IE bookmarks.