source: trunk/Taper/src/taperview.cpp@ 6619

Last change on this file since 6619 was 4307, checked in by merck, 20 years ago
new project
File size: 3.5 KB
Line 
1/***************************************************************************
2 * Copyright (C) 2004 by Martin Merck *
3 * merck@astro.uni-wuerzburg.de *
4 * *
5 * This software is part of the MAGIC software. *
6 ***************************************************************************/
7
8#include "taperview.h"
9
10#include <qpainter.h>
11#include <qlayout.h>
12
13#include <kurl.h>
14
15#include <ktrader.h>
16#include <klibloader.h>
17#include <kmessagebox.h>
18#include <krun.h>
19#include <klocale.h>
20
21TaperView::TaperView(QWidget *parent)
22 : QWidget(parent),
23 DCOPObject("TaperIface")
24{
25 // setup our layout manager to automatically add our widgets
26 QHBoxLayout *top_layout = new QHBoxLayout(this);
27 top_layout->setAutoAdd(true);
28
29 // we want to look for all components that satisfy our needs. the
30 // trader will actually search through *all* registered KDE
31 // applications and components -- not just KParts. So we have to
32 // specify two things: a service type and a constraint
33 //
34 // the service type is like a mime type. we say that we want all
35 // applications and components that can handle HTML -- 'text/html'
36 //
37 // however, by itself, this will return such things as Netscape..
38 // not what we wanted. so we constrain it by saying that the
39 // string 'KParts/ReadOnlyPart' must be found in the ServiceTypes
40 // field. with this, only components of the type we want will be
41 // returned.
42 KTrader::OfferList offers = KTrader::self()->query("text/html", "'KParts/ReadOnlyPart' in ServiceTypes");
43
44 KLibFactory *factory = 0;
45 // in theory, we only care about the first one.. but let's try all
46 // offers just in case the first can't be loaded for some reason
47 KTrader::OfferList::Iterator it(offers.begin());
48 for( ; it != offers.end(); ++it)
49 {
50 KService::Ptr ptr = (*it);
51
52 // we now know that our offer can handle HTML and is a part.
53 // since it is a part, it must also have a library... let's try to
54 // load that now
55 factory = KLibLoader::self()->factory( ptr->library() );
56 if (factory)
57 {
58 m_html = static_cast<KParts::ReadOnlyPart *>(factory->create(this, ptr->name(), "KParts::ReadOnlyPart"));
59 break;
60 }
61 }
62
63 // if our factory is invalid, then we never found our component
64 // and we might as well just exit now
65 if (!factory)
66 {
67 KMessageBox::error(this, i18n("Could not find a suitable HTML component"));
68 return;
69 }
70
71 connect(m_html, SIGNAL(setWindowCaption(const QString&)),
72 this, SLOT(slotSetTitle(const QString&)));
73 connect(m_html, SIGNAL(setStatusBarText(const QString&)),
74 this, SLOT(slotOnURL(const QString&)));
75
76}
77
78TaperView::~TaperView()
79{
80}
81
82void TaperView::print(QPainter *p, int height, int width)
83{
84 // do the actual printing, here
85 // p->drawText(etc..)
86}
87
88QString TaperView::currentURL()
89{
90 return m_html->url().url();
91}
92
93void TaperView::openURL(QString url)
94{
95 openURL(KURL(url));
96}
97
98void TaperView::openURL(const KURL& url)
99{
100 m_html->openURL(url);
101}
102
103void TaperView::slotOnURL(const QString& url)
104{
105 emit signalChangeStatusbar(url);
106}
107
108void TaperView::slotSetTitle(const QString& title)
109{
110 emit signalChangeCaption(title);
111}
112#include "taperview.moc"
Note: See TracBrowser for help on using the repository browser.