~ubuntu-branches/ubuntu/warty/kdebase/warty

« back to all changes in this revision

Viewing changes to konqueror/keditbookmarks/exporters.cpp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-09-16 04:51:45 UTC
  • Revision ID: james.westby@ubuntu.com-20040916045145-9vr63kith3k1cpza
Tags: upstream-3.2.2
ImportĀ upstreamĀ versionĀ 3.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode:cperl; cperl-indent-level:4; cperl-continued-statement-offset:4; indent-tabs-mode:nil -*-
 
2
// vim: set ts=4 sts=4 sw=4 et:
 
3
/* This file is part of the KDE project
 
4
   Copyright (C) 2003 Alexander Kellett <lypanov@kde.org>
 
5
 
 
6
   This program is free software; you can redistribute it and/or
 
7
   modify it under the terms of the GNU General Public
 
8
   License version 2 as published by the Free Software Foundation.
 
9
 
 
10
   This program 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
   General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU General Public License
 
16
   along with this program; see the file COPYING.  If not, write to
 
17
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
18
   Boston, MA 02111-1307, USA.
 
19
*/
 
20
 
 
21
#include "exporters.h"
 
22
 
 
23
#include <kdebug.h>
 
24
#include <klocale.h>
 
25
#include <kapplication.h>
 
26
 
 
27
#include <qfile.h>
 
28
 
 
29
HTMLExporter::HTMLExporter() 
 
30
    : m_out(&m_string, IO_WriteOnly) {
 
31
    m_level = 0;
 
32
}
 
33
 
 
34
void HTMLExporter::write(const KBookmarkGroup &grp, const QString &filename) {
 
35
    QFile file(filename);
 
36
    if (!file.open(IO_WriteOnly)) {
 
37
        kdError(7043) << "Can't write to file " << filename << endl;
 
38
        return;
 
39
    }
 
40
    QTextStream tstream(&file);
 
41
    tstream.setEncoding(QTextStream::UnicodeUTF8);
 
42
    tstream << toString(grp);
 
43
}
 
44
 
 
45
QString HTMLExporter::toString(const KBookmarkGroup &grp)
 
46
{
 
47
    traverse(grp);
 
48
    return "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
 
49
           "<HTML><HEAD><TITLE>My Bookmarks</TITLE>\n"
 
50
           "<META http-equiv=\"Content-Type\" content=\"text/html; charset=utf8\" />"
 
51
           "</HEAD>\n"
 
52
           "<BODY>\n"
 
53
         + m_string +
 
54
           "</BODY></HTML>\n";
 
55
}
 
56
 
 
57
void HTMLExporter::visit(const KBookmark &bk) {
 
58
    // kdDebug() << "visit(" << bk.text() << ")" << endl;
 
59
    m_out << "<A href=\"" << bk.url().url().utf8() << "\">";
 
60
    m_out << bk.fullText() << "</A><BR>" << endl;
 
61
}
 
62
 
 
63
void HTMLExporter::visitEnter(const KBookmarkGroup &grp) {
 
64
    // kdDebug() << "visitEnter(" << grp.text() << ")" << endl;
 
65
    m_out << "<H3>" << grp.fullText() << "</H3>" << endl;
 
66
    m_out << "<P style=\"margin-left: " 
 
67
          << (m_level * 3) << "em\">" << endl;
 
68
    m_level++;
 
69
 
70
 
 
71
void HTMLExporter::visitLeave(const KBookmarkGroup &) {
 
72
    // kdDebug() << "visitLeave()" << endl;
 
73
    m_out << "</P>" << endl;
 
74
    m_level--;
 
75
    if (m_level != 0)
 
76
        m_out << "<P style=\"left-margin: " 
 
77
              << (m_level * 3) << "em\">" << endl;
 
78
}
 
79