• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/bookmarks
 

tdeio/bookmarks

  • tdeio
  • bookmarks
kbookmarkimporter_kde1.cpp
1/* This file is part of the KDE libraries
2 Copyright (C) 2000 David Faure <faure@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*/
18
19#include "kbookmarkimporter_kde1.h"
20#include <tdefiledialog.h>
21#include <kstringhandler.h>
22#include <tdelocale.h>
23#include <kdebug.h>
24#include <kcharsets.h>
25#include <tqtextcodec.h>
26
27#include <sys/types.h>
28#include <stddef.h>
29#include <dirent.h>
30#include <sys/stat.h>
31#include <assert.h>
32
34
35void KBookmarkImporter::import( const TQString & path )
36{
37 TQDomElement elem = m_pDoc->documentElement();
38 Q_ASSERT(!elem.isNull());
39 scanIntern( elem, path );
40}
41
42void KBookmarkImporter::scanIntern( TQDomElement & parentElem, const TQString & _path )
43{
44 kdDebug(7043) << "KBookmarkImporter::scanIntern " << _path << endl;
45 // Substitute all symbolic links in the path
46 TQDir dir( _path );
47 TQString canonical = dir.canonicalPath();
48
49 if ( m_lstParsedDirs.contains(canonical) )
50 {
51 kdWarning() << "Directory " << canonical << " already parsed" << endl;
52 return;
53 }
54
55 m_lstParsedDirs.append( canonical );
56
57 DIR *dp;
58 struct dirent *ep;
59 dp = opendir( TQFile::encodeName(_path) );
60 if ( dp == 0L )
61 return;
62
63 // Loop thru all directory entries
64 while ( ( ep = readdir( dp ) ) != 0L )
65 {
66 if ( strcmp( ep->d_name, "." ) != 0 && strcmp( ep->d_name, ".." ) != 0 )
67 {
68 KURL file;
69 file.setPath( TQString( _path ) + '/' + TQFile::decodeName(ep->d_name) );
70
71 KMimeType::Ptr res = KMimeType::findByURL( file, 0, true );
72 //kdDebug(7043) << " - " << file.url() << " -> " << res->name() << endl;
73
74 if ( res->name() == "inode/directory" )
75 {
76 // We could use KBookmarkGroup::createNewFolder, but then it
77 // would notify about the change, so we'd need a flag, etc.
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() );
86 }
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") )
94 {
95 KSimpleConfig cfg( file.path(), true );
96 cfg.setDesktopGroup();
97 TQString type = cfg.readEntry( "Type" );
98 // Is it really a bookmark file ?
99 if ( type == "Link" )
100 parseBookmark( parentElem, ep->d_name, cfg, 0 /* desktop group */ );
101 else
102 kdWarning(7043) << " Not a link ? Type=" << type << endl;
103 }
104 else if ( res->name() == "text/plain")
105 {
106 // maybe its an IE Favourite..
107 KSimpleConfig cfg( file.path(), true );
108 TQStringList grp = cfg.groupList().grep( "internetshortcut", false );
109 if ( grp.count() == 0 )
110 continue;
111 cfg.setGroup( *grp.begin() );
112
113 TQString url = cfg.readPathEntry("URL");
114 if (!url.isEmpty() )
115 parseBookmark( parentElem, ep->d_name, cfg, *grp.begin() );
116 } else
117 kdWarning(7043) << "Invalid bookmark : found mimetype='" << res->name() << "' for file='" << file.path() << "'!" << endl;
118 }
119 }
120
121 closedir( dp );
122}
123
124void KBookmarkImporter::parseBookmark( TQDomElement & parentElem, TQCString _text,
125 KSimpleConfig& _cfg, const TQString &_group )
126{
127 if ( !_group.isEmpty() )
128 _cfg.setGroup( _group );
129 else
130 _cfg.setDesktopGroup();
131
132 TQString url = _cfg.readPathEntry( "URL" );
133 TQString icon = _cfg.readEntry( "Icon" );
134 if (icon.right( 4 ) == ".xpm" ) // prevent warnings
135 icon.truncate( icon.length() - 4 );
136
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 );
142
143 TQDomElement elem = m_pDoc->createElement( "bookmark" );
144 parentElem.appendChild( elem );
145 elem.setAttribute( "href", url );
146 //if ( icon != "www" ) // No need to save the default
147 // Hmm, after all, it makes KBookmark::pixmapFile faster,
148 // and it shows a nice feature to those reading the file
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;
154}

tdeio/bookmarks

Skip menu "tdeio/bookmarks"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeio/bookmarks

Skip menu "tdeio/bookmarks"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/bookmarks by doxygen 1.9.4
This website is maintained by Timothy Pearson.