3
#include "%{APPNAMELC}view.h"
11
#include <klibloader.h>
12
#include <kmessagebox.h>
16
%{APPNAME}View::%{APPNAME}View(QWidget *parent)
18
DCOPObject("%{APPNAME}Iface")
20
// setup our layout manager to automatically add our widgets
21
QHBoxLayout *top_layout = new QHBoxLayout(this);
22
top_layout->setAutoAdd(true);
24
// we want to look for all components that satisfy our needs. the
25
// trader will actually search through *all* registered KDE
26
// applications and components -- not just KParts. So we have to
27
// specify two things: a service type and a constraint
29
// the service type is like a mime type. we say that we want all
30
// applications and components that can handle HTML -- 'text/html'
32
// however, by itself, this will return such things as Netscape..
33
// not what we wanted. so we constrain it by saying that the
34
// string 'KParts/ReadOnlyPart' must be found in the ServiceTypes
35
// field. with this, only components of the type we want will be
37
KTrader::OfferList offers = KTrader::self()->query("text/html", "'KParts/ReadOnlyPart' in ServiceTypes");
39
KLibFactory *factory = 0;
40
// in theory, we only care about the first one.. but let's try all
41
// offers just in case the first can't be loaded for some reason
42
KTrader::OfferList::Iterator it(offers.begin());
43
for( ; it != offers.end(); ++it)
45
KService::Ptr ptr = (*it);
47
// we now know that our offer can handle HTML and is a part.
48
// since it is a part, it must also have a library... let's try to
50
factory = KLibLoader::self()->factory( ptr->library() );
53
m_html = static_cast<KParts::ReadOnlyPart *>(factory->create(this, ptr->name(), "KParts::ReadOnlyPart"));
58
// if our factory is invalid, then we never found our component
59
// and we might as well just exit now
62
KMessageBox::error(this, i18n("Could not find a suitable HTML component"));
66
connect(m_html, SIGNAL(setWindowCaption(const QString&)),
67
this, SLOT(slotSetTitle(const QString&)));
68
connect(m_html, SIGNAL(setStatusBarText(const QString&)),
69
this, SLOT(slotOnURL(const QString&)));
73
%{APPNAME}View::~%{APPNAME}View()
77
void %{APPNAME}View::print(QPainter *p, int height, int width)
79
// do the actual printing, here
83
QString %{APPNAME}View::currentURL()
85
return m_html->url().url();
88
void %{APPNAME}View::openURL(QString url)
93
void %{APPNAME}View::openURL(const KURL& url)
98
void %{APPNAME}View::slotOnURL(const QString& url)
100
emit signalChangeStatusbar(url);
103
void %{APPNAME}View::slotSetTitle(const QString& title)
105
emit signalChangeCaption(title);
107
#include "%{APPNAMELC}view.moc"