1 /* This file is part of the KDE project
3 * Copyright (C) 2000 Richard Moore <rich@kde.org>
4 * 2000 Wynn Wilkes <wynnw@caldera.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
22 #include "kjavaappletwidget.h"
23 #include "kjavaappletcontext.h"
27 #include <kparts/browserextension.h>
31 class KJavaAppletPrivate
43 KJavaApplet::AppletState state
;
45 KJavaAppletWidget
* UIwidget
;
49 KJavaApplet::KJavaApplet( KJavaAppletWidget
* _parent
,
50 KJavaAppletContext
* _context
)
51 : d(new KJavaAppletPrivate
), params()
54 d
->UIwidget
= _parent
;
59 setAppletContext( _context
);
61 d
->reallyExists
= false;
64 KJavaApplet::~KJavaApplet()
66 if ( d
->reallyExists
)
67 context
->destroy( this );
72 bool KJavaApplet::isCreated()
74 return d
->reallyExists
;
77 void KJavaApplet::setAppletContext( KJavaAppletContext
* _context
)
80 context
->registerApplet( this );
83 void KJavaApplet::setAppletClass( const QString
& _className
)
85 d
->className
= _className
;
88 QString
& KJavaApplet::appletClass()
93 QString
& KJavaApplet::parameter( const QString
& name
)
95 return params
[ name
];
98 void KJavaApplet::setParameter( const QString
& name
, const QString
& value
)
100 params
.insert( name
, value
);
103 QMap
<QString
,QString
>& KJavaApplet::getParams()
108 void KJavaApplet::setBaseURL( const QString
& baseURL
)
110 d
->baseURL
= baseURL
;
113 QString
& KJavaApplet::baseURL()
118 void KJavaApplet::setCodeBase( const QString
& codeBase
)
120 d
->codeBase
= codeBase
;
123 QString
& KJavaApplet::codeBase()
128 void KJavaApplet::setSize( QSize size
)
133 QSize
KJavaApplet::size()
138 void KJavaApplet::setArchives( const QString
& _archives
)
140 d
->archives
= _archives
;
143 QString
& KJavaApplet::archives()
148 void KJavaApplet::resizeAppletWidget( int width
, int height
)
150 kDebug(6100) << "KJavaApplet, id = " << id
<< ", ::resizeAppletWidget to " << width
<< ", " << height
;
153 sl
.push_back( QString::number( 0 ) ); // applet itself has id 0
154 sl
.push_back( QString( "eval" ) ); // evaluate next script
155 sl
.push_back( QString::number( KParts::LiveConnectExtension::TypeString
) );
156 sl
.push_back( QString( "this.setAttribute('WIDTH',%1);this.setAttribute('HEIGHT',%2)" ).arg( width
).arg( height
) );
160 void KJavaApplet::setAppletName( const QString
& name
)
165 void KJavaApplet::setWindowName( const QString
& title
)
167 d
->windowName
= title
;
170 QString
& KJavaApplet::getWindowName()
172 return d
->windowName
;
175 QString
& KJavaApplet::appletName()
180 void KJavaApplet::create( )
182 if ( !context
->create( this ) )
184 d
->reallyExists
= true;
187 void KJavaApplet::init()
189 context
->init( this );
192 void KJavaApplet::start()
194 context
->start( this );
197 void KJavaApplet::stop()
199 context
->stop( this );
202 int KJavaApplet::appletId()
207 void KJavaApplet::setAppletId( int _id
)
212 void KJavaApplet::stateChange( const int newStateInt
) {
213 AppletState newState
= (AppletState
)newStateInt
;
218 switch ( newState
) {
220 ok
= (d
->state
== UNKNOWN
);
224 showStatus(i18n("Initializing Applet \"%1\"...", appletName()));
226 ok
= (d
->state
== CLASS_LOADED
);
229 ok
= (d
->state
== INSTANCIATED
);
231 showStatus(i18n("Starting Applet \"%1\"...", appletName()));
236 ok
= (d
->state
== INITIALIZED
|| d
->state
== STOPPED
);
238 showStatus(i18n("Applet \"%1\" started", appletName()));
242 ok
= (d
->state
== INITIALIZED
|| d
->state
== STARTED
);
244 showStatus(i18n("Applet \"%1\" stopped", appletName()));
256 kError(6100) << "KJavaApplet::stateChange : don't want to switch from state "
257 << d
->state
<< " to " << newState
<< endl
;
261 void KJavaApplet::showStatus(const QString
&msg
) {
264 context
->processCmd("showstatus", args
);
267 void KJavaApplet::setFailed() {
271 bool KJavaApplet::isAlive() const {
274 && d
->state
>= INSTANCIATED
275 && d
->state
< STOPPED
279 KJavaApplet::AppletState
KJavaApplet::state() const {
283 bool KJavaApplet::failed() const {
287 #include "kjavaapplet.moc"