21 #include "kbookmarkimporter_kde1.h"
22 #include <tdefiledialog.h>
23 #include <kstringhandler.h>
24 #include <tdelocale.h>
26 #include <kcharsets.h>
27 #include <tqtextcodec.h>
29 #include <sys/types.h>
37 void KBookmarkImporter::import(
const TQString & path )
39 TQDomElement elem = m_pDoc->documentElement();
40 Q_ASSERT(!elem.isNull());
41 scanIntern( elem, path );
44 void KBookmarkImporter::scanIntern( TQDomElement & parentElem,
const TQString & _path )
46 kdDebug(7043) <<
"KBookmarkImporter::scanIntern " << _path << endl;
49 TQString canonical = dir.canonicalPath();
51 if ( m_lstParsedDirs.contains(canonical) )
53 kdWarning() <<
"Directory " << canonical <<
" already parsed" << endl;
57 m_lstParsedDirs.append( canonical );
61 dp = opendir( TQFile::encodeName(_path) );
66 while ( ( ep = readdir( dp ) ) != 0L )
68 if ( strcmp( ep->d_name,
"." ) != 0 && strcmp( ep->d_name,
".." ) != 0 )
71 file.setPath( TQString( _path ) +
'/' + TQFile::decodeName(ep->d_name) );
73 KMimeType::Ptr res = KMimeType::findByURL( file, 0,
true );
76 if ( res->name() ==
"inode/directory" )
80 TQDomElement groupElem = m_pDoc->createElement(
"folder" );
81 parentElem.appendChild( groupElem );
82 TQDomElement textElem = m_pDoc->createElement(
"title" );
83 groupElem.appendChild( textElem );
84 textElem.appendChild( m_pDoc->createTextNode( TDEIO::decodeFileName( ep->d_name ) ) );
85 if ( TDEIO::decodeFileName( ep->d_name ) ==
"Toolbar" )
86 groupElem.setAttribute(
"toolbar",
"yes");
87 scanIntern( groupElem, file.path() );
89 else if ( (res->name() ==
"application/x-desktop")
90 || (res->name() ==
"media/builtin-mydocuments")
91 || (res->name() ==
"media/builtin-mycomputer")
92 || (res->name() ==
"media/builtin-mynetworkplaces")
93 || (res->name() ==
"media/builtin-printers")
94 || (res->name() ==
"media/builtin-trash")
95 || (res->name() ==
"media/builtin-webbrowser") )
97 KSimpleConfig cfg( file.path(), true );
98 cfg.setDesktopGroup();
99 TQString type = cfg.readEntry(
"Type" );
101 if ( type ==
"Link" )
102 parseBookmark( parentElem, ep->d_name, cfg, 0 );
104 kdWarning(7043) <<
" Not a link ? Type=" << type << endl;
106 else if ( res->name() ==
"text/plain")
109 KSimpleConfig cfg( file.path(), true );
110 TQStringList grp = cfg.groupList().grep(
"internetshortcut",
false );
111 if ( grp.count() == 0 )
113 cfg.setGroup( *grp.begin() );
115 TQString url = cfg.readPathEntry(
"URL");
117 parseBookmark( parentElem, ep->d_name, cfg, *grp.begin() );
119 kdWarning(7043) <<
"Invalid bookmark : found mimetype='" << res->name() <<
"' for file='" << file.path() <<
"'!" << endl;
126 void KBookmarkImporter::parseBookmark( TQDomElement & parentElem, TQCString _text,
127 KSimpleConfig& _cfg,
const TQString &_group )
129 if ( !_group.isEmpty() )
130 _cfg.setGroup( _group );
132 _cfg.setDesktopGroup();
134 TQString url = _cfg.readPathEntry(
"URL" );
135 TQString icon = _cfg.readEntry(
"Icon" );
136 if (icon.right( 4 ) ==
".xpm" )
137 icon.truncate( icon.length() - 4 );
139 TQString text = TDEIO::decodeFileName( TQString::fromLocal8Bit(_text) );
140 if ( text.length() > 8 && text.right( 8 ) ==
".desktop" )
141 text.truncate( text.length() - 8 );
142 if ( text.length() > 7 && text.right( 7 ) ==
".kdelnk" )
143 text.truncate( text.length() - 7 );
145 TQDomElement elem = m_pDoc->createElement(
"bookmark" );
146 parentElem.appendChild( elem );
147 elem.setAttribute(
"href", url );
151 elem.setAttribute(
"icon", icon );
152 TQDomElement textElem = m_pDoc->createElement(
"title" );
153 elem.appendChild( textElem );
154 textElem.appendChild( m_pDoc->createTextNode( text ) );
155 kdDebug(7043) <<
"KBookmarkImporter::parseBookmark text=" << text << endl;