~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to languages/cpp/app_templates/kapp/appview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%{CPP_TEMPLATE}
 
2
 
 
3
#include "%{APPNAMELC}view.h"
 
4
 
 
5
#include <qpainter.h>
 
6
#include <qlayout.h>
 
7
 
 
8
#include <kurl.h>
 
9
 
 
10
#include <ktrader.h>
 
11
#include <klibloader.h>
 
12
#include <kmessagebox.h>
 
13
#include <krun.h>
 
14
#include <klocale.h>
 
15
 
 
16
%{APPNAME}View::%{APPNAME}View(QWidget *parent)
 
17
    : QWidget(parent),
 
18
      DCOPObject("%{APPNAME}Iface")
 
19
{
 
20
    // setup our layout manager to automatically add our widgets
 
21
    QHBoxLayout *top_layout = new QHBoxLayout(this);
 
22
    top_layout->setAutoAdd(true);
 
23
 
 
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
 
28
    //
 
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'
 
31
    //
 
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
 
36
    // returned.
 
37
    KTrader::OfferList offers = KTrader::self()->query("text/html", "'KParts/ReadOnlyPart' in ServiceTypes");
 
38
 
 
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)
 
44
    {
 
45
        KService::Ptr ptr = (*it);
 
46
 
 
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
 
49
        // load that now
 
50
        factory = KLibLoader::self()->factory( ptr->library() );
 
51
        if (factory)
 
52
        {
 
53
            m_html = static_cast<KParts::ReadOnlyPart *>(factory->create(this, ptr->name(), "KParts::ReadOnlyPart"));
 
54
            break;
 
55
        }
 
56
    }
 
57
 
 
58
    // if our factory is invalid, then we never found our component
 
59
    // and we might as well just exit now
 
60
    if (!factory)
 
61
    {
 
62
        KMessageBox::error(this, i18n("Could not find a suitable HTML component"));
 
63
        return;
 
64
    }
 
65
 
 
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&)));
 
70
 
 
71
}
 
72
 
 
73
%{APPNAME}View::~%{APPNAME}View()
 
74
{
 
75
}
 
76
 
 
77
void %{APPNAME}View::print(QPainter *p, int height, int width)
 
78
{
 
79
    // do the actual printing, here
 
80
    // p->drawText(etc..)
 
81
}
 
82
 
 
83
QString %{APPNAME}View::currentURL()
 
84
{
 
85
    return m_html->url().url();
 
86
}
 
87
 
 
88
void %{APPNAME}View::openURL(QString url)
 
89
{
 
90
    openURL(KURL(url));
 
91
}
 
92
 
 
93
void %{APPNAME}View::openURL(const KURL& url)
 
94
{
 
95
    m_html->openURL(url);
 
96
}
 
97
 
 
98
void %{APPNAME}View::slotOnURL(const QString& url)
 
99
{
 
100
    emit signalChangeStatusbar(url);
 
101
}
 
102
 
 
103
void %{APPNAME}View::slotSetTitle(const QString& title)
 
104
{
 
105
    emit signalChangeCaption(title);
 
106
}
 
107
#include "%{APPNAMELC}view.moc"