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

kio/bookmarks

  • kio
  • bookmarks
kbookmarkimporter_ie.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) 2002-2003 Alexander Kellett <lypanov@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 <kfiledialog.h>
22 #include <kstringhandler.h>
23 #include <klocale.h>
24 #include <kdebug.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 
32 #include "kbookmarkimporter.h"
33 #include "kbookmarkimporter_ie.h"
34 
35 /* antlarr: KDE 4: Make them const TQString & */
36 void KIEBookmarkImporter::parseIEBookmarks_url_file( TQString filename, TQString name ) {
37  static const int g_lineLimit = 16*1024;
38 
39  TQFile f(filename);
40 
41  if(f.open(IO_ReadOnly)) {
42 
43  TQCString s(g_lineLimit);
44 
45  while(f.readLine(s.data(), g_lineLimit)>=0) {
46  if ( s[s.length()-1] != '\n' ) // Gosh, this line is longer than g_lineLimit. Skipping.
47  {
48  kdWarning() << "IE bookmarks contain a line longer than " << g_lineLimit << ". Skipping." << endl;
49  continue;
50  }
51  TQCString t = s.stripWhiteSpace();
52  TQRegExp rx( "URL=(.*)" );
53  if (rx.exactMatch(t)) {
54  emit newBookmark( name, TQString(rx.cap(1)).latin1(), TQString("") );
55  }
56  }
57 
58  f.close();
59  }
60 }
61 
62 /* antlarr: KDE 4: Make them const TQString & */
63 void KIEBookmarkImporter::parseIEBookmarks_dir( TQString dirname, TQString foldername )
64 {
65 
66  TQDir dir(dirname);
67  dir.setFilter( TQDir::Files | TQDir::Dirs );
68  dir.setSorting( TQDir::Name | TQDir::DirsFirst );
69  dir.setNameFilter("*.url"); // AK - possibly add ";index.ini" ?
70  dir.setMatchAllDirs(true);
71 
72  const TQFileInfoList *list = dir.entryInfoList();
73  if (!list) return;
74 
75  if (dirname != m_fileName)
76  emit newFolder( foldername, false, "" );
77 
78  TQFileInfoListIterator it( *list );
79  TQFileInfo *fi;
80 
81  while ( (fi = it.current()) != 0 ) {
82  ++it;
83 
84  if (fi->fileName() == "." || fi->fileName() == "..") continue;
85 
86  if (fi->isDir()) {
87  parseIEBookmarks_dir(fi->absFilePath(), fi->fileName());
88 
89  } else if (fi->isFile()) {
90  if (fi->fileName().endsWith(".url")) {
91  TQString name = fi->fileName();
92  name.truncate(name.length() - 4); // .url
93  parseIEBookmarks_url_file(fi->absFilePath(), name);
94  }
95  // AK - add index.ini
96  }
97  }
98 
99  if (dirname != m_fileName)
100  emit endFolder();
101 }
102 
103 
104 void KIEBookmarkImporter::parseIEBookmarks( )
105 {
106  parseIEBookmarks_dir( m_fileName );
107 }
108 
109 TQString KIEBookmarkImporter::IEBookmarksDir()
110 {
111  static KIEBookmarkImporterImpl* p = 0;
112  if (!p)
113  p = new KIEBookmarkImporterImpl;
114  return p->findDefaultLocation();
115 }
116 
117 void KIEBookmarkImporterImpl::parse() {
118  KIEBookmarkImporter importer(m_fileName);
119  setupSignalForwards(&importer, this);
120  importer.parseIEBookmarks();
121 }
122 
123 TQString KIEBookmarkImporterImpl::findDefaultLocation(bool) const
124 {
125  // notify user that they must give a new dir such
126  // as "Favourites" as otherwise it'll just place
127  // lots of .url files in the given dir and gui
128  // stuff in the exporter is ugly so that exclues
129  // the possibility of just writing to Favourites
130  // and checking if overwriting...
131  return KFileDialog::getExistingDirectory();
132 }
133 
135 
136 class IEExporter : private KBookmarkGroupTraverser {
137 public:
138  IEExporter( const TQString & );
139  void write( const KBookmarkGroup &grp ) { traverse(grp); };
140 private:
141  virtual void visit( const KBookmark & );
142  virtual void visitEnter( const KBookmarkGroup & );
143  virtual void visitLeave( const KBookmarkGroup & );
144 private:
145  TQDir m_currentDir;
146 };
147 
148 static TQString ieStyleQuote( const TQString &str ) {
149  TQString s(str);
150  s.replace(TQRegExp("[/\\:*?\"<>|]"), "_");
151  return s;
152 }
153 
154 IEExporter::IEExporter( const TQString & dname ) {
155  m_currentDir.setPath( dname );
156 }
157 
158 void IEExporter::visit( const KBookmark &bk ) {
159  TQString fname = m_currentDir.path() + "/" + ieStyleQuote( bk.fullText() ) + ".url";
160  // kdDebug() << "visit(" << bk.text() << "), fname == " << fname << endl;
161  TQFile file( fname );
162  file.open( IO_WriteOnly );
163  TQTextStream ts( &file );
164  ts << "[InternetShortcut]\r\n";
165  ts << "URL=" << bk.url().url().utf8() << "\r\n";
166 }
167 
168 void IEExporter::visitEnter( const KBookmarkGroup &grp ) {
169  TQString dname = m_currentDir.path() + "/" + ieStyleQuote( grp.fullText() );
170  // kdDebug() << "visitEnter(" << grp.text() << "), dname == " << dname << endl;
171  m_currentDir.mkdir( dname );
172  m_currentDir.cd( dname );
173 }
174 
175 void IEExporter::visitLeave( const KBookmarkGroup & ) {
176  // kdDebug() << "visitLeave()" << endl;
177  m_currentDir.cdUp();
178 }
179 
180 void KIEBookmarkExporterImpl::write(KBookmarkGroup parent) {
181  IEExporter exporter( m_fileName );
182  exporter.write( parent );
183 }
184 
185 #include "kbookmarkimporter_ie.moc"
KIEBookmarkImporterImpl
A class for importing IE bookmarks.
Definition: kbookmarkimporter_ie.h:65
KBookmarkGroup
A group of bookmarks.
Definition: kbookmark.h:199
KIEBookmarkImporter
A class for importing IE bookmarks.
Definition: kbookmarkimporter_ie.h:36
KBookmarkGroupTraverser
Definition: kbookmark.h:318

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.6
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |