# kio Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kfilebookmarkhandler.cpp

    00001 /* This file is part of the KDE libraries
    00002     Copyright (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org>
    00003
    00004     library is free software; you can redistribute it and/or
    00005     modify it under the terms of the GNU Library General Public
    00006     License as published by the Free Software Foundation, version 2.
    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 <stdio.h>
    00020 #include <stdlib.h>
    00021
    00022 #include <qtextstream.h>
    00023
    00024 #include <kbookmarkimporter.h>
    00025 #include <kpopupmenu.h>
    00026 #include <ksavefile.h>
    00027 #include <kstandarddirs.h>
    00028
    00029 #include "kfiledialog.h"
    00030 #include "kfilebookmarkhandler.h"
    00031
    00032
    00033 KFileBookmarkHandler::KFileBookmarkHandler( KFileDialog *dialog )
    00034     : QObject( dialog, "KFileBookmarkHandler" ),
    00035       KBookmarkOwner(),
    00036       m_dialog( dialog ),
    00037       m_importStream( 0L )
    00038 {
    00039     m_menu = new KPopupMenu( dialog, "bookmark menu" );
    00040
    00041     QString file = locate( "data", "kfile/bookmarks.xml" );
    00042     if ( file.isEmpty() )
    00043         file = locateLocal( "data", "kfile/bookmarks.xml" );
    00044
    00045     // import old bookmarks
    00046     if ( !KStandardDirs::exists( file ) ) {
    00047         QString oldFile = locate( "data", "kfile/bookmarks.html" );
    00048         if ( !oldFile.isEmpty() )
    00049             importOldBookmarks( oldFile, file );
    00050     }
    00051
    00052     KBookmarkManager *manager = KBookmarkManager::managerForFile( file, false);
    00053     manager->setUpdate( true );
    00054     manager->setShowNSBookmarks( false );
    00055
    00056     m_bookmarkMenu = new KBookmarkMenu( manager, this, m_menu,
    00057                                         dialog->actionCollection(), true );
    00058 }
    00059
    00060 KFileBookmarkHandler::~KFileBookmarkHandler()
    00061 {
    00062     //     delete m_bookmarkMenu; ###
    00063 }
    00064
    00065 QString KFileBookmarkHandler::currentURL() const
    00066 {
    00067     return m_dialog->baseURL().url();
    00068 }
    00069
    00070 void KFileBookmarkHandler::importOldBookmarks( const QString& path,
    00071                                                const QString& destinationPath )
    00072 {
    00073     KSaveFile file( destinationPath );
    00074     if ( file.status() != 0 )
    00075         return;
    00076
    00077     m_importStream = file.textStream();
    00078     *m_importStream << "<!DOCTYPE xbel>\n<xbel>\n";
    00079
    00080     KNSBookmarkImporter importer( path );
    00081     connect( &importer,
    00082              SIGNAL( newBookmark( const QString&, const QCString&, const QString& )),
    00083              SLOT( slotNewBookmark( const QString&, const QCString&, const QString& )));
    00084     connect( &importer,
    00085              SIGNAL( newFolder( const QString&, bool, const QString& )),
    00086              SLOT( slotNewFolder( const QString&, bool, const QString& )));
    00087     connect( &importer, SIGNAL( newSeparator() ), SLOT( newSeparator() ));
    00088     connect( &importer, SIGNAL( endMenu() ), SLOT( endMenu() ));
    00089
    00090     importer.parseNSBookmarks( false );
    00091
    00092     *m_importStream << "</xbel>";
    00093
    00094     file.close();
    00095     m_importStream = 0L;
    00096 }
    00097
    00098 void KFileBookmarkHandler::slotNewBookmark( const QString& /*text*/,
    00099                                             const QCString& url,
    00100                                             const QString& additionalInfo )
    00101 {
    00102     *m_importStream << "<bookmark icon=\"" << KMimeType::iconForURL( url );
    00103     *m_importStream << "\" href=\"" << QString::fromUtf8(url) << "\">\n";
    00104     *m_importStream << "<title>" << (additionalInfo.isEmpty() ? QString::fromUtf8(url) : additionalInfo) << "</title>\n</bookmark>\n";
    00105 }
    00106
    00107 void KFileBookmarkHandler::slotNewFolder( const QString& text, bool /*open*/,
    00108                                           const QString& /*additionalInfo*/ )
    00109 {
    00110     *m_importStream << "<folder icon=\"bookmark_folder\">\n<title=\"";
    00111     *m_importStream << text << "\">\n";
    00112 }
    00113
    00114 void KFileBookmarkHandler::newSeparator()
    00115 {
    00116     *m_importStream << "<separator/>\n";
    00117 }
    00118
    00119 void KFileBookmarkHandler::endFolder()
    00120 {
    00121     *m_importStream << "</folder>\n";
    00122 }
    00123
    00124 void KFileBookmarkHandler::virtual_hook( int id, void* data )
    00125 { KBookmarkOwner::virtual_hook( id, data ); }
    00126
    00127 #include "kfilebookmarkhandler.moc"

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:13:26 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001