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
|
=begin
This is the main view class for %{APPNAME}. Most of the non-menu,
non-toolbar, and non-statusbar (e.g., non frame) GUI code should go
here.
This %{APPNAMELC} uses an HTML component as an example.
@short Main view
@author %{AUTHOR} <%{EMAIL}>
@version %{VERSION}
=end
class %{APPNAMESC}View < Qt::Widget
#
# Use this signal to change the content of the statusbar
#
Q_SIGNALS 'signalChangeStatusbar(const TQString&)'
#
# Use this signal to change the content of the caption
#
Q_SIGNALS 'signalChangeCaption(const TQString&)'
Q_SLOTS 'slotOnURL(const TQString&)',
'slotSetTitle(const TQString&)'
def initialize(parent)
super(parent)
# keep a reference to the DCOP Interface so it doesn't get gc'd
@dcop = %{APPNAMESC}Iface.new(self)
# setup our layout manager to automatically add our widgets
top_layout = Qt::HBoxLayout.new(self)
top_layout.setAutoAdd(true)
# we want to look for all components that satisfy our needs. the
# trader will actually search through *all* registered KDE
# applications and components -- not just KParts. So we have to
# specify two things: a service type and a constraint
#
# the service type is like a mime type. we say that we want all
# applications and components that can handle HTML -- 'text/html'
#
# however, by itself, this will return such things as Netscape..
# not what we wanted. so we constrain it by saying that the
# string 'KParts/ReadOnlyPart' must be found in the ServiceTypes
# field. with this, only components of the type we want will be
# returned.
offers = KDE::Trader.self().query("text/html", "'KParts/ReadOnlyPart' in ServiceTypes")
factory = nil
# in theory, we only care about the first one.. but let's try all
# offers just in when the first can't be loaded for some reason
offers.each do |ptr|
# we now know that our offer can handle HTML and is a part.
# since it is a part, it must also have a library... let's try to
# load that now
factory = KDE::LibLoader.self().factory( ptr.library() )
if ! factory.nil?
@html = factory.create(self, ptr.name(), "KParts::ReadOnlyPart")
break
end
end
# if our factory is invalid, then we never found our component
# and we might as well just exit now
if factory.nil?
KDE::MessageBox.error(self, i18n("Could not find a suitable HTML component"))
return
end
connect(@html, SIGNAL('setWindowCaption(const TQString&)'),
self, SLOT('slotSetTitle(const TQString&)'))
connect(@html, SIGNAL('setStatusBarText(const TQString&)'),
self, SLOT('slotOnURL(const TQString&)'))
end
def print(p, height, width)
# do the actual printing, here
# p.drawText(etc..)
end
def currentURL()
return @html.url().url()
end
def openURL(url)
@html.openURL(KDE::URL.new(url))
end
def slotOnURL(url)
emit signalChangeStatusbar(url)
end
def slotSetTitle(title)
emit signalChangeCaption(title)
end
end
|