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

kio/bookmarks

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

kio/bookmarks

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

kio/bookmarks

Skip menu "kio/bookmarks"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kio/bookmarks by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |