summaryrefslogtreecommitdiffstats
path: root/src/modules/objects/class_tbrowser.cpp
blob: c61546672e6588940a37a4f2900040c71a7f521e (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
//mdm:
//   File : class_tbrowser.cpp
//   Creation date : Fri Jan 28 14:21:48 CEST 2005
//   by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor)
//
//   This file is part of the KVirc irc client distribution
//   Copyright (C) 1999-2005 Szymon Stefanek (pragma at kvirc dot net)
//
//   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 opinion) any later version.
//
//   This program is distributed in the HOPE that it will be USEFUL,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//   See the GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program. If not, write to the Free Software Foundation,
//   Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//

#include <tqtextbrowser.h>
#include "class_tbrowser.h"
#include "kvi_error.h"
#include "kvi_debug.h"

#include "kvi_locale.h"
#include "kvi_iconmanager.h"

/*
	@doc: textbrowser
	@keyterms:
		textbrowser browser widget class,
	@title:
		textbrowser class
	@type:
		class
	@short:
		Provides a class that can display html pages.
	@inherits:
		[class]widget[/class]
	@description:
		Provides a class that can display html pages with hypertext navigation.
	@functions:
		!fn: $setSource(<file_name:string>)
		With this you can display the page at szFile location (szFile include the path).
		!fn: $backward()
		Changes the document displayed to the previous document in the list of documents built by navigating links.
		!fn: $forward()
		Changes the document displayed to the next document in the list of documents built by navigating links.
		!fn: $home()
		Changes the document displayed to be the first document the browser displayed.
		!fn: $reload()
		Reloads the current set source.
		!fn: $linkClickedEvent(<link_href:string>)
		Triggered when a link is clicked by the user. The default implementation of this function
		emits the "linkClicked" signal.
	@signals:
		!sg: $linkClicked(<link_href:string>)
		This signal is emitted by the default implementation of the [classfnc]$linkClickedEvent[/classfnc]() function.
*/

KVSO_BEGIN_REGISTERCLASS(KviKvsObject_textbrowser,"textbrowser","multilineedit")
	KVSO_REGISTER_HANDLER(KviKvsObject_textbrowser,"setSource",function_setSource)
	KVSO_REGISTER_HANDLER(KviKvsObject_textbrowser,"forward",function_forward)
	KVSO_REGISTER_HANDLER(KviKvsObject_textbrowser,"backward",function_backward)
	KVSO_REGISTER_HANDLER(KviKvsObject_textbrowser,"home",function_home)
	KVSO_REGISTER_HANDLER(KviKvsObject_textbrowser,"reload",function_reload)
	KVSO_REGISTER_HANDLER(KviKvsObject_textbrowser,"linkClickedEvent",function_linkClickedEvent)
KVSO_END_REGISTERCLASS(KviKvsObject_textbrowser)

KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_textbrowser,KviKvsObject_mledit)

KVSO_END_CONSTRUCTOR(KviKvsObject_textbrowser)


KVSO_BEGIN_DESTRUCTOR(KviKvsObject_textbrowser)

KVSO_END_CONSTRUCTOR(KviKvsObject_textbrowser)

bool KviKvsObject_textbrowser::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams)
{
	TQTextBrowser * tb = new TQTextBrowser(parentScriptWidget(), name());
	setObject(tb, true);
	connect(tb,TQT_SIGNAL(anchorClicked(const TQString &,const TQString &)),this,TQT_SLOT(anchorClicked(const TQString &,const TQString &)));
	return true;
}

bool KviKvsObject_textbrowser::function_setSource(KviKvsObjectFunctionCall *c)
{
	TQString szFile;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("file_name",KVS_PT_STRING,0,szFile)
	KVSO_PARAMETERS_END(c)
	if(!TQFile::exists(szFile))
	{
		c->warning(__tr2qs("I can't find the specified file '%Q'."),&szFile);
		return true;
	}

	if (widget()) ((TQTextBrowser *)widget())->setSource(szFile);
	return true;
}

bool KviKvsObject_textbrowser::function_forward(KviKvsObjectFunctionCall *c)
{
	if (widget()) ((TQTextBrowser *)widget())->forward();
	return true;
}

bool KviKvsObject_textbrowser::function_backward(KviKvsObjectFunctionCall *c)
{
	if (widget()) ((TQTextBrowser *)widget())->backward();
	return true;
}

bool KviKvsObject_textbrowser::function_home(KviKvsObjectFunctionCall *c)
{
	if (widget()) ((TQTextBrowser *)widget())->home();
	return true;
}

bool KviKvsObject_textbrowser::function_reload(KviKvsObjectFunctionCall *c)
{
	if (widget()) ((TQTextBrowser *)widget())->reload();
	return true;
}

void KviKvsObject_textbrowser::anchorClicked(const TQString &szName,const TQString &szLink)
{
	KviKvsVariantList parms(new KviKvsVariant(szLink));
	callFunction(this,"linkClickedEvent",0,&parms);
}

bool KviKvsObject_textbrowser::function_linkClickedEvent(KviKvsObjectFunctionCall *c)
{
	emitSignal("linkClicked",c,c->params());
	return true;
}

#include "m_class_tbrowser.moc"