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

tdeio/bookmarks

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

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.