libkonq Library API Documentation

kbookmarkimporter_opera.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_opera.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 #define LINELIMIT 4096
00032 
00033 // TODO - what sort of url's can we get???
00034 // QTextCodec * codec = QTextCodec::codecForName("UTF-8");
00035 // Q_ASSERT(codec);
00036 // if (!codec)
00037 //   return;
00038 
00039 void KOperaBookmarkImporter::parseOperaBookmarks( )
00040 {
00041    QString URL = QString::null;
00042    QString NAME = QString::null;
00043    QString TYPE = QString::null;
00044 
00045    QFile f(m_fileName);
00046 
00047    if(f.open(IO_ReadOnly)) {
00048 
00049       QCString s(4096);
00050 
00051       int lineno = 0;
00052 
00053       while(f.readLine(s.data(), LINELIMIT)>=0) {
00054 
00055         lineno++;
00056 
00057         if ( s[s.length()-1] != '\n' ) // Gosh, this line is longer than LINELIMIT. Skipping.
00058         {
00059             kdWarning() << "IE bookmarks contain a line longer than " << LINELIMIT << ". Skipping." << endl;
00060             continue;
00061         }
00062         if (lineno <= 2) continue; // skip first two header lines
00063 
00064         QString currentLine = s.stripWhiteSpace();
00065         // kdWarning() << currentLine << endl;
00066 
00067         if ( currentLine == "" ) {
00068 
00069            if ( TYPE != QString::null 
00070              && TYPE == "URL" 
00071            ) {
00072               emit newBookmark( NAME, URL.latin1(), QString("") );
00073               TYPE = QString::null;
00074               NAME = QString::null;
00075               URL = QString::null;
00076            } else if ( 
00077                 TYPE != QString::null
00078              && TYPE == "FOLDER" ) 
00079            {
00080               emit newFolder( NAME, false, "" ); 
00081               TYPE = QString::null;
00082               NAME = QString::null;
00083               URL = QString::null;
00084            }
00085            
00086         } else if (currentLine == "-") {
00087            emit endFolder();
00088 
00089         } else {
00090            QString tag;
00091 
00092            if ( tag = "#", currentLine.startsWith( tag ) ) {
00093               TYPE = currentLine.remove( 0, tag.length() );
00094               // kdWarning() << "TYPE == " << TYPE << endl;
00095 
00096            } else 
00097            if ( tag = "NAME=", currentLine.startsWith( tag ) ) {
00098               NAME = currentLine.remove( 0, tag.length() );
00099               // convertEntities?
00100               // kdWarning() << "NAME == " << NAME << endl;
00101 
00102            } else 
00103            if ( tag = "URL=", currentLine.startsWith( tag ) ) {
00104               URL = currentLine.remove( 0, tag.length() );
00105               // kdWarning() << "URL == " << URL << endl;
00106            }
00107         }
00108      }
00109    }
00110 
00111 }
00112 
00113 QString KOperaBookmarkImporter::operaBookmarksFile( )
00114 {
00115     return KFileDialog::getOpenFileName( QDir::homeDirPath() + "/.opera", 
00116                                          i18n("*.adr|Opera bookmark files (*.adr)") );
00117 }
00118 
00119 #include "kbookmarkimporter_opera.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