summaryrefslogtreecommitdiffstats
path: root/quanta/parts/kafka/domtreeview.cpp
blob: 5e1757e30eb3613cc1240d783d06417a05cab8f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/***************************************************************************
                               domtreeview.cpp
                             -------------------

    copyright            : (C) 2001 - The Kafka Team
    email                : kde-kafka@master.kde.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "kafkacommon.h"
#ifdef HEAVY_DEBUG

#include <kdebug.h>
#include <tdehtml_part.h>
#include <klocale.h>
#include <tqstring.h>
#include <tqlayout.h>
#include <dom/dom_text.h>

#include "domtreeview.moc"

DOMTreeView::DOMTreeView(TQWidget *parent, TDEHTMLPart *currentpart, const char * name) : TDEListView(parent, name)
{
    setCaption(name);
    setRootIsDecorated(true);
    addColumn(i18n( "Name" ));
    addColumn(i18n( "Value (limited to 20 char)" ));
    addColumn(i18n( "Length" ));
    addColumn(i18n( "ID" ));
    addColumn("");
    setSorting(-1);
    part = currentpart;
    connect(part, TQT_SIGNAL(nodeActivated(const DOM::Node &)), this, TQT_SLOT(showTree(const DOM::Node &)));
    connect(this, TQT_SIGNAL(clicked(TQListViewItem *)), this, TQT_SLOT(slotItemClicked(TQListViewItem *)));
    m_nodedict.setAutoDelete(true);
    title = "";
    titleItem = new TQListViewItem(static_cast<TQListView *>(this), title, "");
}

DOMTreeView::~DOMTreeView()
{
    disconnect(part);
}

void DOMTreeView::setTitle(const TQString &str)
{
  title = str;
  titleItem->setText(1, title);
}

void DOMTreeView::showTree(const DOM::Node &pNode)
{

//    if(pNode.isNull() || document != pNode.ownerDocument())
//    {
	clear();
	m_itemdict.clear();
	m_nodedict.clear();
	if(pNode.isNull())
	    return;
	if(pNode.firstChild() == 0)
		return;
	else if(pNode.ownerDocument().isNull())
	{
	    document = pNode.ownerDocument();
	    recursive(0, pNode);
	}
	else
	{
	    document = pNode.ownerDocument();
	    recursive(0, pNode.ownerDocument());
	}
	titleItem = new TQListViewItem(static_cast<TQListView *>(this), title, "");
//    }
    setCurrentItem(m_itemdict[pNode.handle()]);
    ensureItemVisible(m_itemdict[pNode.handle()]);
}

void DOMTreeView::recursive(const DOM::Node &pNode, const DOM::Node &node)
{
    TQListViewItem *cur_item;
    int len;
    if(pNode.ownerDocument() != document)
    {
	TQString val = node.nodeValue().string();
	if ( val.length() > 20 )
	    val.truncate( 20 );
	cur_item = new TQListViewItem(static_cast<TQListView *>(this), node.nodeName().string(), val);
	document = pNode.ownerDocument();
    }
    else {
	TQString val = node.nodeValue().string();
	if ( val.length() > 20 )
	    val.truncate( 20 );
	if(node.nodeType() == DOM::Node::TEXT_NODE)
	    len = (static_cast<DOM::CharacterData>(node)).length();
	else
	    len = 0;
	cur_item = new TQListViewItem(m_itemdict[pNode.handle()], node.nodeName().string(), val, TQString::number(len), TQString::number(node.elementId()) );
	unsigned long i;
	TQListViewItem *tmp = new TQListViewItem(cur_item, "properties");
	for(i = 0; i < node.attributes().length(); i++)
	{
		new TQListViewItem(tmp, node.attributes().item(i).nodeName().string(),
			node.attributes().item(i).nodeValue().string());
	}
    }

    if(node.handle())
    {
	m_itemdict.insert(node.handle(), cur_item);
	m_nodedict.insert(cur_item, new DOM::Node(node));
    }

    DOM::Node cur_child = node.lastChild();
    while(!cur_child.isNull())
    {
	recursive(node, cur_child);
	cur_child = cur_child.previousSibling();
    }
}

void DOMTreeView::slotItemClicked(TQListViewItem *cur_item)
{
    DOM::Node *handle = m_nodedict[cur_item];
    if(handle) {
	emit part->setActiveNode(*handle);
        //kdDebug() << handle->toHTML() << endl;
    }
}

KafkaDOMTreeDialog::KafkaDOMTreeDialog(TQWidget *parent, TDEHTMLPart *part, const char* name, bool modal, WFlags fl )
	: TQDialog(parent, name, modal, fl)
{
	setSizePolicy( TQSizePolicy( (TQSizePolicy::SizeType)5, (TQSizePolicy::SizeType)1, 0, 0, sizePolicy().hasHeightForWidth() ) );
	DialogLayout = new TQGridLayout( this, 1, 1, 11, 6, "DialogLayout");
	domview = new DOMTreeView(this, part, name);
	domview->setTitle(i18n( "Debugging KafkaWidget DOM Tree " ));
        DialogLayout->addWidget(domview, 1,1);

}

KafkaDOMTreeDialog::~KafkaDOMTreeDialog()
{

}

#endif