You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
186 lines
5.5 KiB
186 lines
5.5 KiB
15 years ago
|
// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
|
||
|
// vim: set ts=4 sts=4 sw=4 et:
|
||
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 2002-2003 Alexander Kellett <lypanov@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License version 2 as published by the Free Software Foundation.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
12 years ago
|
#include <tdefiledialog.h>
|
||
15 years ago
|
#include <kstringhandler.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kdebug.h>
|
||
13 years ago
|
#include <tqtextcodec.h>
|
||
15 years ago
|
|
||
|
#include <sys/types.h>
|
||
|
#include <stddef.h>
|
||
|
#include <dirent.h>
|
||
|
#include <sys/stat.h>
|
||
|
|
||
|
#include "kbookmarkimporter.h"
|
||
|
#include "kbookmarkimporter_ie.h"
|
||
|
|
||
15 years ago
|
/* antlarr: KDE 4: Make them const TQString & */
|
||
|
void KIEBookmarkImporter::parseIEBookmarks_url_file( TQString filename, TQString name ) {
|
||
15 years ago
|
static const int g_lineLimit = 16*1024;
|
||
|
|
||
15 years ago
|
TQFile f(filename);
|
||
15 years ago
|
|
||
|
if(f.open(IO_ReadOnly)) {
|
||
|
|
||
15 years ago
|
TQCString s(g_lineLimit);
|
||
15 years ago
|
|
||
|
while(f.readLine(s.data(), g_lineLimit)>=0) {
|
||
|
if ( s[s.length()-1] != '\n' ) // Gosh, this line is longer than g_lineLimit. Skipping.
|
||
|
{
|
||
|
kdWarning() << "IE bookmarks contain a line longer than " << g_lineLimit << ". Skipping." << endl;
|
||
|
continue;
|
||
|
}
|
||
15 years ago
|
TQCString t = s.stripWhiteSpace();
|
||
|
TQRegExp rx( "URL=(.*)" );
|
||
15 years ago
|
if (rx.exactMatch(t)) {
|
||
14 years ago
|
emit newBookmark( name, TQString(rx.cap(1)).latin1(), TQString("") );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
f.close();
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
/* antlarr: KDE 4: Make them const TQString & */
|
||
|
void KIEBookmarkImporter::parseIEBookmarks_dir( TQString dirname, TQString foldername )
|
||
15 years ago
|
{
|
||
|
|
||
15 years ago
|
TQDir dir(dirname);
|
||
|
dir.setFilter( TQDir::Files | TQDir::Dirs );
|
||
|
dir.setSorting( TQDir::Name | TQDir::DirsFirst );
|
||
15 years ago
|
dir.setNameFilter("*.url"); // AK - possibly add ";index.ini" ?
|
||
|
dir.setMatchAllDirs(true);
|
||
|
|
||
14 years ago
|
const TQFileInfoList *list = dir.entryInfoList();
|
||
15 years ago
|
if (!list) return;
|
||
|
|
||
|
if (dirname != m_fileName)
|
||
|
emit newFolder( foldername, false, "" );
|
||
|
|
||
14 years ago
|
TQFileInfoListIterator it( *list );
|
||
15 years ago
|
TQFileInfo *fi;
|
||
15 years ago
|
|
||
|
while ( (fi = it.current()) != 0 ) {
|
||
|
++it;
|
||
|
|
||
|
if (fi->fileName() == "." || fi->fileName() == "..") continue;
|
||
|
|
||
|
if (fi->isDir()) {
|
||
|
parseIEBookmarks_dir(fi->absFilePath(), fi->fileName());
|
||
|
|
||
|
} else if (fi->isFile()) {
|
||
|
if (fi->fileName().endsWith(".url")) {
|
||
15 years ago
|
TQString name = fi->fileName();
|
||
15 years ago
|
name.truncate(name.length() - 4); // .url
|
||
|
parseIEBookmarks_url_file(fi->absFilePath(), name);
|
||
|
}
|
||
|
// AK - add index.ini
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (dirname != m_fileName)
|
||
|
emit endFolder();
|
||
|
}
|
||
|
|
||
|
|
||
|
void KIEBookmarkImporter::parseIEBookmarks( )
|
||
|
{
|
||
|
parseIEBookmarks_dir( m_fileName );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KIEBookmarkImporter::IEBookmarksDir()
|
||
15 years ago
|
{
|
||
|
static KIEBookmarkImporterImpl* p = 0;
|
||
|
if (!p)
|
||
|
p = new KIEBookmarkImporterImpl;
|
||
14 years ago
|
return p->findDefaultLocation();
|
||
15 years ago
|
}
|
||
|
|
||
|
void KIEBookmarkImporterImpl::parse() {
|
||
|
KIEBookmarkImporter importer(m_fileName);
|
||
|
setupSignalForwards(&importer, this);
|
||
|
importer.parseIEBookmarks();
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString KIEBookmarkImporterImpl::findDefaultLocation(bool) const
|
||
15 years ago
|
{
|
||
|
// notify user that they must give a new dir such
|
||
|
// as "Favourites" as otherwise it'll just place
|
||
|
// lots of .url files in the given dir and gui
|
||
|
// stuff in the exporter is ugly so that exclues
|
||
|
// the possibility of just writing to Favourites
|
||
|
// and checking if overwriting...
|
||
|
return KFileDialog::getExistingDirectory();
|
||
|
}
|
||
|
|
||
|
/////////////////////////////////////////////////
|
||
|
|
||
|
class IEExporter : private KBookmarkGroupTraverser {
|
||
|
public:
|
||
15 years ago
|
IEExporter( const TQString & );
|
||
15 years ago
|
void write( const KBookmarkGroup &grp ) { traverse(grp); };
|
||
|
private:
|
||
|
virtual void visit( const KBookmark & );
|
||
|
virtual void visitEnter( const KBookmarkGroup & );
|
||
|
virtual void visitLeave( const KBookmarkGroup & );
|
||
|
private:
|
||
15 years ago
|
TQDir m_currentDir;
|
||
15 years ago
|
};
|
||
|
|
||
15 years ago
|
static TQString ieStyleQuote( const TQString &str ) {
|
||
|
TQString s(str);
|
||
14 years ago
|
s.replace(TQRegExp("[/\\:*?\"<>|]"), "_");
|
||
15 years ago
|
return s;
|
||
|
}
|
||
|
|
||
15 years ago
|
IEExporter::IEExporter( const TQString & dname ) {
|
||
15 years ago
|
m_currentDir.setPath( dname );
|
||
|
}
|
||
|
|
||
|
void IEExporter::visit( const KBookmark &bk ) {
|
||
15 years ago
|
TQString fname = m_currentDir.path() + "/" + ieStyleQuote( bk.fullText() ) + ".url";
|
||
15 years ago
|
// kdDebug() << "visit(" << bk.text() << "), fname == " << fname << endl;
|
||
15 years ago
|
TQFile file( fname );
|
||
15 years ago
|
file.open( IO_WriteOnly );
|
||
15 years ago
|
TQTextStream ts( &file );
|
||
15 years ago
|
ts << "[InternetShortcut]\r\n";
|
||
|
ts << "URL=" << bk.url().url().utf8() << "\r\n";
|
||
|
}
|
||
|
|
||
|
void IEExporter::visitEnter( const KBookmarkGroup &grp ) {
|
||
15 years ago
|
TQString dname = m_currentDir.path() + "/" + ieStyleQuote( grp.fullText() );
|
||
15 years ago
|
// kdDebug() << "visitEnter(" << grp.text() << "), dname == " << dname << endl;
|
||
|
m_currentDir.mkdir( dname );
|
||
|
m_currentDir.cd( dname );
|
||
|
}
|
||
|
|
||
|
void IEExporter::visitLeave( const KBookmarkGroup & ) {
|
||
|
// kdDebug() << "visitLeave()" << endl;
|
||
|
m_currentDir.cdUp();
|
||
|
}
|
||
|
|
||
|
void KIEBookmarkExporterImpl::write(KBookmarkGroup parent) {
|
||
|
IEExporter exporter( m_fileName );
|
||
|
exporter.write( parent );
|
||
|
}
|
||
|
|
||
|
#include "kbookmarkimporter_ie.moc"
|