kio
kfilebookmarkhandler.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021
00022 #include <kbookmarkimporter.h>
00023 #include <kbookmarkdombuilder.h>
00024 #include <kpopupmenu.h>
00025 #include <kstandarddirs.h>
00026
00027 #include "kfiledialog.h"
00028 #include "kfilebookmarkhandler.h"
00029
00030 KFileBookmarkHandler::KFileBookmarkHandler( KFileDialog *dialog )
00031 : QObject( dialog, "KFileBookmarkHandler" ),
00032 KBookmarkOwner(),
00033 m_dialog( dialog )
00034 {
00035 m_menu = new KPopupMenu( dialog, "bookmark menu" );
00036
00037 QString file = locate( "data", "kfile/bookmarks.xml" );
00038 if ( file.isEmpty() )
00039 file = locateLocal( "data", "kfile/bookmarks.xml" );
00040
00041 KBookmarkManager *manager = KBookmarkManager::managerForFile( file, false);
00042
00043
00044 if ( !KStandardDirs::exists( file ) ) {
00045 QString oldFile = locate( "data", "kfile/bookmarks.html" );
00046 if ( !oldFile.isEmpty() )
00047 importOldBookmarks( oldFile, manager );
00048 }
00049
00050 manager->setUpdate( true );
00051 manager->setShowNSBookmarks( false );
00052
00053 m_bookmarkMenu = new KBookmarkMenu( manager, this, m_menu,
00054 dialog->actionCollection(), true );
00055 }
00056
00057 KFileBookmarkHandler::~KFileBookmarkHandler()
00058 {
00059 delete m_bookmarkMenu;
00060 }
00061
00062 QString KFileBookmarkHandler::currentURL() const
00063 {
00064 return m_dialog->baseURL().url();
00065 }
00066
00067 void KFileBookmarkHandler::importOldBookmarks( const QString& path,
00068 KBookmarkManager *manager )
00069 {
00070 KBookmarkDomBuilder *builder = new KBookmarkDomBuilder( manager->root(), manager );
00071 KNSBookmarkImporter importer( path );
00072 builder->connectImporter( &importer );
00073 importer.parseNSBookmarks();
00074 delete builder;
00075 manager->save();
00076 }
00077
00078 void KFileBookmarkHandler::virtual_hook( int id, void* data )
00079 { KBookmarkOwner::virtual_hook( id, data ); }
00080
00081 #include "kfilebookmarkhandler.moc"