19 #include "kbookmarkimporter_kde1.h"
20 #include <tdefiledialog.h>
21 #include <kstringhandler.h>
22 #include <tdelocale.h>
24 #include <kcharsets.h>
25 #include <tqtextcodec.h>
27 #include <sys/types.h>
35 void KBookmarkImporter::import(
const TQString & path )
37 TQDomElement elem = m_pDoc->documentElement();
38 Q_ASSERT(!elem.isNull());
39 scanIntern( elem, path );
42 void KBookmarkImporter::scanIntern( TQDomElement & parentElem,
const TQString & _path )
44 kdDebug(7043) <<
"KBookmarkImporter::scanIntern " << _path << endl;
47 TQString canonical = dir.canonicalPath();
49 if ( m_lstParsedDirs.contains(canonical) )
51 kdWarning() <<
"Directory " << canonical <<
" already parsed" << endl;
55 m_lstParsedDirs.append( canonical );
59 dp = opendir( TQFile::encodeName(_path) );
64 while ( ( ep = readdir( dp ) ) != 0L )
66 if ( strcmp( ep->d_name,
"." ) != 0 && strcmp( ep->d_name,
".." ) != 0 )
69 file.setPath( TQString( _path ) +
'/' + TQFile::decodeName(ep->d_name) );
71 KMimeType::Ptr res = KMimeType::findByURL( file, 0,
true );
74 if ( res->name() ==
"inode/directory" )
78 TQDomElement groupElem = m_pDoc->createElement(
"folder" );
79 parentElem.appendChild( groupElem );
80 TQDomElement textElem = m_pDoc->createElement(
"title" );
81 groupElem.appendChild( textElem );
82 textElem.appendChild( m_pDoc->createTextNode( TDEIO::decodeFileName( ep->d_name ) ) );
83 if ( TDEIO::decodeFileName( ep->d_name ) ==
"Toolbar" )
84 groupElem.setAttribute(
"toolbar",
"yes");
85 scanIntern( groupElem, file.path() );
87 else if ( (res->name() ==
"application/x-desktop")
88 || (res->name() ==
"media/builtin-mydocuments")
89 || (res->name() ==
"media/builtin-mycomputer")
90 || (res->name() ==
"media/builtin-mynetworkplaces")
91 || (res->name() ==
"media/builtin-printers")
92 || (res->name() ==
"media/builtin-trash")
93 || (res->name() ==
"media/builtin-webbrowser") )
95 KSimpleConfig cfg( file.path(),
true );
96 cfg.setDesktopGroup();
97 TQString type = cfg.readEntry(
"Type" );
100 parseBookmark( parentElem, ep->d_name, cfg, 0 );
102 kdWarning(7043) <<
" Not a link ? Type=" << type << endl;
104 else if ( res->name() ==
"text/plain")
107 KSimpleConfig cfg( file.path(),
true );
108 TQStringList grp = cfg.groupList().grep(
"internetshortcut",
false );
109 if ( grp.count() == 0 )
111 cfg.setGroup( *grp.begin() );
113 TQString url = cfg.readPathEntry(
"URL");
115 parseBookmark( parentElem, ep->d_name, cfg, *grp.begin() );
117 kdWarning(7043) <<
"Invalid bookmark : found mimetype='" << res->name() <<
"' for file='" << file.path() <<
"'!" << endl;
124 void KBookmarkImporter::parseBookmark( TQDomElement & parentElem, TQCString _text,
125 KSimpleConfig& _cfg,
const TQString &_group )
127 if ( !_group.isEmpty() )
128 _cfg.setGroup( _group );
130 _cfg.setDesktopGroup();
132 TQString url = _cfg.readPathEntry(
"URL" );
133 TQString icon = _cfg.readEntry(
"Icon" );
134 if (icon.right( 4 ) ==
".xpm" )
135 icon.truncate( icon.length() - 4 );
137 TQString text = TDEIO::decodeFileName( TQString::fromLocal8Bit(_text) );
138 if ( text.length() > 8 && text.right( 8 ) ==
".desktop" )
139 text.truncate( text.length() - 8 );
140 if ( text.length() > 7 && text.right( 7 ) ==
".kdelnk" )
141 text.truncate( text.length() - 7 );
143 TQDomElement elem = m_pDoc->createElement(
"bookmark" );
144 parentElem.appendChild( elem );
145 elem.setAttribute(
"href", url );
149 elem.setAttribute(
"icon", icon );
150 TQDomElement textElem = m_pDoc->createElement(
"title" );
151 elem.appendChild( textElem );
152 textElem.appendChild( m_pDoc->createTextNode( text ) );
153 kdDebug(7043) <<
"KBookmarkImporter::parseBookmark text=" << text << endl;