You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
289 lines
6.2 KiB
289 lines
6.2 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
*
|
||
|
* Copyright (C) 2000 Richard Moore <rich@kde.org>
|
||
|
* 2000 Wynn Wilkes <wynnw@caldera.com>
|
||
|
*
|
||
|
* This library is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Library General Public
|
||
|
* License as published by the Free Software Foundation; either
|
||
|
* version 2 of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* This library is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* Library General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Library General Public License
|
||
|
* along with this library; see the file COPYING.LIB. If not, write to
|
||
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "kjavaappletwidget.h"
|
||
|
#include "kjavaappletcontext.h"
|
||
|
|
||
|
#include <klocale.h>
|
||
|
#include <kdebug.h>
|
||
12 years ago
|
#include <tdeparts/browserextension.h>
|
||
15 years ago
|
|
||
|
|
||
|
|
||
|
class KJavaAppletPrivate
|
||
|
{
|
||
|
public:
|
||
|
bool reallyExists;
|
||
15 years ago
|
TQString className;
|
||
|
TQString appName;
|
||
|
TQString baseURL;
|
||
|
TQString codeBase;
|
||
|
TQString archives;
|
||
|
TQSize size;
|
||
|
TQString windowName;
|
||
15 years ago
|
KJavaApplet::AppletState state;
|
||
|
bool failed;
|
||
|
|
||
|
KJavaAppletWidget* UIwidget;
|
||
|
};
|
||
|
|
||
|
|
||
|
KJavaApplet::KJavaApplet( KJavaAppletWidget* _parent,
|
||
|
KJavaAppletContext* _context )
|
||
|
: params()
|
||
|
{
|
||
|
d = new KJavaAppletPrivate;
|
||
|
|
||
|
d->UIwidget = _parent;
|
||
|
d->state = UNKNOWN;
|
||
|
d->failed = false;
|
||
|
|
||
|
if( _context )
|
||
|
setAppletContext( _context );
|
||
|
|
||
|
d->reallyExists = false;
|
||
|
}
|
||
|
|
||
|
KJavaApplet::~KJavaApplet()
|
||
|
{
|
||
|
if ( d->reallyExists )
|
||
|
context->destroy( this );
|
||
|
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
|
bool KJavaApplet::isCreated()
|
||
|
{
|
||
|
return d->reallyExists;
|
||
|
}
|
||
|
|
||
|
void KJavaApplet::setAppletContext( KJavaAppletContext* _context )
|
||
|
{
|
||
|
context = _context;
|
||
|
context->registerApplet( this );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KJavaApplet::setAppletClass( const TQString& _className )
|
||
15 years ago
|
{
|
||
|
d->className = _className;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString& KJavaApplet::appletClass()
|
||
15 years ago
|
{
|
||
|
return d->className;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString& KJavaApplet::parameter( const TQString& name )
|
||
15 years ago
|
{
|
||
|
return params[ name ];
|
||
|
}
|
||
|
|
||
15 years ago
|
void KJavaApplet::setParameter( const TQString& name, const TQString& value )
|
||
15 years ago
|
{
|
||
|
params.insert( name, value );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQMap<TQString,TQString>& KJavaApplet::getParams()
|
||
15 years ago
|
{
|
||
|
return params;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KJavaApplet::setBaseURL( const TQString& baseURL )
|
||
15 years ago
|
{
|
||
|
d->baseURL = baseURL;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString& KJavaApplet::baseURL()
|
||
15 years ago
|
{
|
||
|
return d->baseURL;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KJavaApplet::setCodeBase( const TQString& codeBase )
|
||
15 years ago
|
{
|
||
|
d->codeBase = codeBase;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString& KJavaApplet::codeBase()
|
||
15 years ago
|
{
|
||
|
return d->codeBase;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KJavaApplet::setSize( TQSize size )
|
||
15 years ago
|
{
|
||
|
d->size = size;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQSize KJavaApplet::size()
|
||
15 years ago
|
{
|
||
|
return d->size;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KJavaApplet::setArchives( const TQString& _archives )
|
||
15 years ago
|
{
|
||
|
d->archives = _archives;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString& KJavaApplet::archives()
|
||
15 years ago
|
{
|
||
|
return d->archives;
|
||
|
}
|
||
|
|
||
|
void KJavaApplet::resizeAppletWidget( int width, int height )
|
||
|
{
|
||
|
kdDebug(6100) << "KJavaApplet, id = " << id << ", ::resizeAppletWidget to " << width << ", " << height << endl;
|
||
|
|
||
15 years ago
|
TQStringList sl;
|
||
|
sl.push_back( TQString::number( 0 ) ); // applet itself has id 0
|
||
|
sl.push_back( TQString( "eval" ) ); // evaluate next script
|
||
|
sl.push_back( TQString::number( KParts::LiveConnectExtension::TypeString ) );
|
||
|
sl.push_back( TQString( "this.setAttribute('WIDTH',%1);this.setAttribute('HEIGHT',%2)" ).arg( width ).arg( height ) );
|
||
15 years ago
|
jsData( sl );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KJavaApplet::setAppletName( const TQString& name )
|
||
15 years ago
|
{
|
||
|
d->appName = name;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KJavaApplet::setWindowName( const TQString& title )
|
||
15 years ago
|
{
|
||
|
d->windowName = title;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString& KJavaApplet::getWindowName()
|
||
15 years ago
|
{
|
||
|
return d->windowName;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString& KJavaApplet::appletName()
|
||
15 years ago
|
{
|
||
|
return d->appName;
|
||
|
}
|
||
|
|
||
|
void KJavaApplet::create( )
|
||
|
{
|
||
|
if ( !context->create( this ) )
|
||
|
setFailed();
|
||
|
d->reallyExists = true;
|
||
|
}
|
||
|
|
||
|
void KJavaApplet::init()
|
||
|
{
|
||
|
context->init( this );
|
||
|
}
|
||
|
|
||
|
void KJavaApplet::start()
|
||
|
{
|
||
|
context->start( this );
|
||
|
}
|
||
|
|
||
|
void KJavaApplet::stop()
|
||
|
{
|
||
|
context->stop( this );
|
||
|
}
|
||
|
|
||
|
int KJavaApplet::appletId()
|
||
|
{
|
||
|
return id;
|
||
|
}
|
||
|
|
||
|
void KJavaApplet::setAppletId( int _id )
|
||
|
{
|
||
|
id = _id;
|
||
|
}
|
||
|
|
||
|
void KJavaApplet::stateChange( const int newStateInt ) {
|
||
|
AppletState newState = (AppletState)newStateInt;
|
||
|
bool ok = false;
|
||
|
if (d->failed) {
|
||
|
return;
|
||
|
}
|
||
|
switch ( newState ) {
|
||
|
case CLASS_LOADED:
|
||
|
ok = (d->state == UNKNOWN);
|
||
|
break;
|
||
|
case INSTANCIATED:
|
||
|
if (ok) {
|
||
14 years ago
|
showStatus(i18n("Initializing Applet \"%1\"...").arg(appletName()));
|
||
15 years ago
|
}
|
||
|
ok = (d->state == CLASS_LOADED);
|
||
|
break;
|
||
|
case INITIALIZED:
|
||
|
ok = (d->state == INSTANCIATED);
|
||
|
if (ok) {
|
||
14 years ago
|
showStatus(i18n("Starting Applet \"%1\"...").arg(appletName()));
|
||
15 years ago
|
start();
|
||
|
}
|
||
|
break;
|
||
|
case STARTED:
|
||
|
ok = (d->state == INITIALIZED || d->state == STOPPED);
|
||
|
if (ok) {
|
||
14 years ago
|
showStatus(i18n("Applet \"%1\" started").arg(appletName()));
|
||
15 years ago
|
}
|
||
|
break;
|
||
|
case STOPPED:
|
||
|
ok = (d->state == INITIALIZED || d->state == STARTED);
|
||
|
if (ok) {
|
||
14 years ago
|
showStatus(i18n("Applet \"%1\" stopped").arg(appletName()));
|
||
15 years ago
|
}
|
||
|
break;
|
||
|
case DESTROYED:
|
||
|
ok = true;
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
if (ok) {
|
||
|
d->state = newState;
|
||
|
} else {
|
||
|
kdError(6100) << "KJavaApplet::stateChange : don't want to switch from state "
|
||
|
<< d->state << " to " << newState << endl;
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void KJavaApplet::showStatus(const TQString &msg) {
|
||
15 years ago
|
TQStringList args;
|
||
15 years ago
|
args << msg;
|
||
|
context->processCmd("showstatus", args);
|
||
|
}
|
||
|
|
||
|
void KJavaApplet::setFailed() {
|
||
|
d->failed = true;
|
||
|
}
|
||
|
|
||
|
bool KJavaApplet::isAlive() const {
|
||
|
return (
|
||
|
!d->failed
|
||
|
&& d->state >= INSTANCIATED
|
||
|
&& d->state < STOPPED
|
||
|
);
|
||
|
}
|
||
|
|
||
|
KJavaApplet::AppletState KJavaApplet::state() const {
|
||
|
return d->state;
|
||
|
}
|
||
|
|
||
|
bool KJavaApplet::failed() const {
|
||
|
return d->failed;
|
||
|
}
|
||
|
|
||
|
#include "kjavaapplet.moc"
|