libkonq Library API Documentation

kbookmarkimporter_ie.cc

00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2002 Alexander Kellett <lypanov@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00016    Boston, MA 02111-1307, USA.
00017 */
00018 
00019 #include "kbookmarkimporter_ie.h"
00020 #include <kfiledialog.h>
00021 #include <kstringhandler.h>
00022 #include <klocale.h>
00023 #include <kdebug.h>
00024 #include <qtextcodec.h>
00025 
00026 #include <sys/types.h>
00027 #include <stddef.h>
00028 #include <dirent.h>
00029 #include <sys/stat.h>
00030 
00031 // TODO - what sort of url's can we get???
00032 // QTextCodec * codec = QTextCodec::codecForName("UTF-8");
00033 // Q_ASSERT(codec);
00034 // if (!codec) return;
00035 
00036 #define LINELIMIT 4096
00037 
00038 void KIEBookmarkImporter::parseIEBookmarks_url_file( QString filename, QString name ) {
00039 
00040     QFile f(filename);
00041 
00042     if(f.open(IO_ReadOnly)) {
00043 
00044         QCString s(4096);
00045 
00046         while(f.readLine(s.data(), LINELIMIT)>=0) {
00047             if ( s[s.length()-1] != '\n' ) // Gosh, this line is longer than LINELIMIT. Skipping.
00048             {
00049                kdWarning() << "IE bookmarks contain a line longer than " << LINELIMIT << ". Skipping." << endl;
00050                continue;
00051             }
00052             QCString t = s.stripWhiteSpace();
00053             QRegExp rx( "URL=(.*)" );
00054             if (rx.exactMatch(t)) {
00055                emit newBookmark( name, rx.cap(1).latin1(), QString("") );
00056             }
00057         }
00058 
00059         f.close();
00060     }
00061 }
00062 
00063 void KIEBookmarkImporter::parseIEBookmarks_dir( QString dirname, QString name )
00064 {
00065 
00066    QDir d(dirname);
00067    d.setFilter( QDir::Files | QDir::Dirs );
00068    d.setSorting( QDir::Name | QDir::DirsFirst );
00069    d.setNameFilter("*.url"); // AK - possibly add ";index.ini" ?
00070    d.setMatchAllDirs(TRUE);
00071 
00072    const QFileInfoList *list = d.entryInfoList();
00073    if (!list) return;
00074 
00075    if (dirname != m_fileName) 
00076       emit newFolder( name, false, "" );
00077 
00078    QFileInfoListIterator it( *list );
00079    QFileInfo *fi;
00080 
00081    while ( (fi = it.current()) != 0 ) {
00082       ++it;
00083 
00084       if (fi->fileName() == "." || fi->fileName() == "..") continue;
00085 
00086       if (fi->isDir()) {
00087          parseIEBookmarks_dir(fi->absFilePath(), fi->fileName());
00088 
00089       } else if (fi->isFile()) {
00090          if (fi->fileName().endsWith(".url")) {
00091             QString name = fi->fileName();
00092             name.truncate(name.length() - 4); // .url
00093             parseIEBookmarks_url_file(fi->absFilePath(), name);
00094          }
00095          // AK - add index.ini
00096       }
00097    }
00098 
00099    if (dirname != m_fileName) 
00100       emit endFolder();
00101 }
00102 
00103 
00104 void KIEBookmarkImporter::parseIEBookmarks( )
00105 {
00106     parseIEBookmarks_dir( m_fileName );
00107 }
00108 
00109 QString KIEBookmarkImporter::IEBookmarksDir( )
00110 {
00111     // TODO - add suggestive paths to kfile dialog somehow?
00112     // e.g /mnt/windows/blha blah blah
00113     return KFileDialog::getExistingDirectory( );
00114 }
00115 
00116 #include "kbookmarkimporter_ie.moc"
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Thu Jan 29 23:03:28 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001