summaryrefslogtreecommitdiffstats
path: root/xparts/src/kde/xparthost_kpart.cpp
blob: 807ada77dd0ebe7fe00dce01fe90a4f061b8d0ab (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
144
145
146
147
148
149
150
#include "xparthost_kpart.h"
#include "kbrowsersignals.h"
#include "xpart_stub.h"

#include <dcopclient.h>
#include <kapplication.h>

#include <assert.h>

#include <qxembed.h>

#include <tqdom.h>
#include <kaction.h>

#include <kdebug.h>

XPartHost_KPart::XPartHost_KPart( TQWidget *parentWidget, const char *widgetName, 
	                          TQObject *parent, const char *name )
    : KParts::ReadOnlyPart( parent, name ),
      XPartHost("parthost")
{
    m_stub = 0;
    be = 0;
    embed = new QXEmbed(parentWidget, widgetName);
    setWidget(embed);
}

XPartHost_KPart::~XPartHost_KPart()
{
    delete m_stub;
}

DCOPRef XPartHost_KPart::part()
{
    return m_part;
}

DCOPRef XPartHost_KPart::registerXPart( const DCOPRef &part )
{
    m_part = part;

    assert( m_stub == 0 );

    m_stub = new XPart_stub( part.app(), part.object() );
    m_stub->show();

    kdDebug() << "embedding window " << m_stub->windowId() << endl;
    embed->embed( static_cast<WId>( m_stub->windowId() ) );

    embed->show();
     DCOPRef ref = m_stub->queryExtension("browserextension");
     if( !ref.isNull() ) {
	 qDebug(" found browser extension ");
	 be = new KBrowserSignals( this, ref );
     }
    return DCOPRef( kapp->dcopClient()->appId(), objId() );
}


void XPartHost_KPart::createActions( const TQCString &xmlActions )
{
    qDebug("--> createActions");
    // creates a set of actions and adds them to the actionCollection
    TQDomDocument d;
    d.setContent( xmlActions );

    TQDomElement docElem = d.documentElement();

    kdDebug() << "docElement is " << docElem.tagName() << endl;

    TQDomNode n = docElem.firstChild();
    while( !n.isNull() ) {
        TQDomElement e = n.toElement();
        if( !e.isNull() ) {
            if ( e.tagName() == "Action") {
                TQString name = e.attribute("name");
                TQString type = e.attribute("type");

                if(type.isEmpty())
                    new KAction( name, 0, this, TQT_SLOT( actionActivated() ), actionCollection(), name.latin1() );
                else if( type == "toggle" )
                    new KToggleAction( name, 0, this, TQT_SLOT( actionActivated() ), actionCollection(), name.latin1() );
                kdDebug() << "action=" << name << "  type=" << type << endl;
            } else if ( e.tagName() == "XMLFile" ) {
                TQString location = e.attribute("location");
                setXMLFile(location);
            }
        }
        n = n.nextSibling();
    }
    emit actionsInitialized();
}


void XPartHost_KPart::setWindowCaption( const TQString &caption )
{
    emit KParts::ReadOnlyPart::setWindowCaption( caption );
}

void XPartHost_KPart::setStatusBarText( const TQString &text )
{
    emit KParts::ReadOnlyPart::setStatusBarText( text );
}

void XPartHost_KPart::started()
{
    emit KParts::ReadOnlyPart::started( 0 );
}

void XPartHost_KPart::completed()
{
    emit KParts::ReadOnlyPart::completed();
}

void XPartHost_KPart::canceled( const TQString &errMsg )
{
    emit KParts::ReadOnlyPart::canceled( errMsg );
}

bool XPartHost_KPart::openURL( const KURL &url )
{
    qDebug("XPartHost_KPart::openUrl()");
    return m_stub->openURL( url.url().latin1() );
}

bool XPartHost_KPart::closeURL()
{
    return m_stub->closeURL();
}


void XPartHost_KPart::actionActivated()
{
    const TQObject *o = sender();

    if( !o->inherits("KAction") ) return;

    const KAction *action = static_cast<const KAction *>(o);
    TQString name = action->text();
    int state = 0;

    if(action->inherits("KToggleAction")) {
        const KToggleAction *t = static_cast<const KToggleAction *>(action);
        state = t->isChecked();
    }

    m_stub->activateAction(name, state);
}

#include "xparthost_kpart.moc"