khtml Library API Documentation

kjavaapplet.cpp

00001 /* This file is part of the KDE project
00002  *
00003  * Copyright (C) 2000 Richard Moore <rich@kde.org>
00004  *               2000 Wynn Wilkes <wynnw@caldera.com>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public License
00017  * along with this library; see the file COPYING.LIB.  If not, write to
00018  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019  * Boston, MA 02111-1307, USA.
00020  */
00021 
00022 #include "kjavaappletwidget.h"
00023 #include "kjavaappletcontext.h"
00024 
00025 #include <klocale.h>
00026 #include <kdebug.h>
00027 
00028 
00029 
00030 class KJavaAppletPrivate
00031 {
00032 public:
00033    bool    reallyExists;
00034    QString className;
00035    QString appName;
00036    QString baseURL;
00037    QString codeBase;
00038    QString archives;
00039    QSize   size;
00040    QString windowName;
00041    KJavaApplet::AppletState state;
00042    bool    failed;
00043 
00044    KJavaAppletWidget* UIwidget;
00045 };
00046 
00047 
00048 KJavaApplet::KJavaApplet( KJavaAppletWidget* _parent,
00049                           KJavaAppletContext* _context )
00050     : params(), liveconnect( new KJavaLiveConnect( _context, this ) )
00051 {
00052     d = new KJavaAppletPrivate;
00053 
00054     d->UIwidget = _parent;
00055     d->state = UNKNOWN;
00056     d->failed = false;
00057 
00058     if( _context )
00059         context = _context;
00060     else
00061         context = new KJavaAppletContext();
00062 
00063     d->reallyExists = false;
00064     context->registerApplet(this);
00065 }
00066 
00067 KJavaApplet::~KJavaApplet()
00068 {
00069     if ( d->reallyExists )
00070         context->destroy( this );
00071 
00072     delete d;
00073     delete liveconnect;
00074 }
00075 
00076 bool KJavaApplet::isCreated()
00077 {
00078     return d->reallyExists;
00079 }
00080 
00081 void KJavaApplet::setAppletClass( const QString& _className )
00082 {
00083     d->className = _className;
00084 }
00085 
00086 QString& KJavaApplet::appletClass()
00087 {
00088     return d->className;
00089 }
00090 
00091 QString& KJavaApplet::parameter( const QString& name )
00092 {
00093     return params[ name ];
00094 }
00095 
00096 void KJavaApplet::setParameter( const QString& name, const QString& value )
00097 {
00098     params.insert( name, value );
00099 }
00100 
00101 QMap<QString,QString>& KJavaApplet::getParams()
00102 {
00103     return params;
00104 }
00105 
00106 void KJavaApplet::setBaseURL( const QString& baseURL )
00107 {
00108     d->baseURL = baseURL;
00109 }
00110 
00111 QString& KJavaApplet::baseURL()
00112 {
00113     return d->baseURL;
00114 }
00115 
00116 void KJavaApplet::setCodeBase( const QString& codeBase )
00117 {
00118     d->codeBase = codeBase;
00119 }
00120 
00121 QString& KJavaApplet::codeBase()
00122 {
00123     return d->codeBase;
00124 }
00125 
00126 void KJavaApplet::setSize( QSize size )
00127 {
00128     d->size = size;
00129 }
00130 
00131 QSize KJavaApplet::size()
00132 {
00133     return d->size;
00134 }
00135 
00136 void KJavaApplet::setArchives( const QString& _archives )
00137 {
00138     d->archives = _archives;
00139 }
00140 
00141 QString& KJavaApplet::archives()
00142 {
00143     return d->archives;
00144 }
00145 
00146 void KJavaApplet::resizeAppletWidget( int width, int height )
00147 {
00148     kdDebug(6100) << "KJavaApplet, id = " << id << ", ::resizeAppletWidget to " << width << ", " << height << endl;
00149 
00150     if( d->UIwidget )
00151         d->UIwidget->resize( width, height );
00152 }
00153 
00154 void KJavaApplet::setAppletName( const QString& name )
00155 {
00156     d->appName = name;
00157 }
00158 
00159 void KJavaApplet::setWindowName( const QString& title )
00160 {
00161     d->windowName = title;
00162 }
00163 
00164 QString& KJavaApplet::getWindowName()
00165 {
00166     return d->windowName;
00167 }
00168 
00169 QString& KJavaApplet::appletName()
00170 {
00171     return d->appName;
00172 }
00173 
00174 void KJavaApplet::create( )
00175 {
00176     context->create( this );
00177     d->reallyExists = true;
00178 }
00179 
00180 void KJavaApplet::init()
00181 {
00182     context->init( this );
00183 }
00184 
00185 void KJavaApplet::start()
00186 {
00187     context->start( this );
00188 }
00189 
00190 void KJavaApplet::stop()
00191 {
00192     context->stop( this );
00193 }
00194 
00195 int KJavaApplet::appletId()
00196 {
00197     return id;
00198 }
00199 
00200 void KJavaApplet::setAppletId( int _id )
00201 {
00202     id = _id;
00203 }
00204 
00205 KJavaLiveConnect::KJavaLiveConnect(KJavaAppletContext* c, KJavaApplet* a) 
00206     : KParts::LiveConnectExtension(0), context(c), applet(a) {
00207 }
00208 
00209 bool KJavaLiveConnect::get(const unsigned long objid, const QString & field, KParts::LiveConnectExtension::Type & type, unsigned long & rid, QString & value )
00210 {
00211     if (!applet->isAlive())
00212         return false;
00213     int itype;
00214     bool ret = context->getMember(applet, objid, field, itype, rid, value);
00215     type = (KParts::LiveConnectExtension::Type) itype;
00216     return ret;
00217 }
00218 
00219 bool KJavaLiveConnect::put(const unsigned long objid, const QString & name, const QString & value)
00220 {
00221     if (!applet->isAlive())
00222         return false;
00223     return context->putMember(applet, objid, name, value);
00224 }
00225 
00226 bool KJavaLiveConnect::call( const unsigned long objid, const QString & func, const QStringList & args, KParts::LiveConnectExtension::Type & type, unsigned long & retobjid, QString & value )
00227 {
00228     if (!applet->isAlive())
00229         return false;
00230     int itype;
00231     bool ret = context->callMember(applet, objid, func, args, itype, retobjid, value);
00232     type = (KParts::LiveConnectExtension::Type) itype;
00233     return ret;
00234 }
00235 
00236 void KJavaLiveConnect::unregister(const unsigned long objid)
00237 {
00238     context->derefObject(applet, objid);
00239 }
00240 
00241 void KJavaApplet::stateChange( const int newStateInt ) {
00242     AppletState newState = (AppletState)newStateInt;
00243     bool ok = false;
00244     if (d->failed) {
00245         return;
00246     }
00247     switch ( newState ) {
00248         case CLASS_LOADED:
00249             ok = (d->state == UNKNOWN);
00250             break;
00251         case INSTANCIATED:
00252             if (ok) {
00253                 // FIXME enable after 3.1
00254                 //showStatus(i18n("Java Applet \"$1\" loaded").arg(appletName()));
00255             }
00256             ok = (d->state == CLASS_LOADED);
00257             break;
00258         case INITIALIZED:
00259             ok = (d->state == INSTANCIATED);
00260             if (ok) { 
00261                 // FIXME enable after 3.1
00262                 //showStatus(i18n("Java Applet \"%1\" initialized").arg(appletName()));
00263                 start();
00264             }
00265             break;
00266         case STARTED:
00267             ok = (d->state == INITIALIZED || d->state == STOPPED);
00268             if (ok) {    
00269                 // FIXME enable after 3.1
00270                 //showStatus(i18n("Java Applet \"%1\" started").arg(appletName()));
00271             }
00272             break;
00273         case STOPPED:
00274             ok = (d->state == INITIALIZED || d->state == STARTED);
00275             if (ok) {    
00276                 // FIXME enable after 3.1
00277                 //showStatus(i18n("Java Applet \"%1\" stopped").arg(appletName()));
00278             }
00279             break;
00280         case DESTROYED:
00281             ok = true;
00282             break;
00283         default:
00284             break;
00285     }
00286     if (ok) {
00287         d->state = newState;
00288     } else {
00289         kdError(6100) << "KJavaApplet::stateChange : don't want to switch from state "
00290             << d->state << " to " << newState << endl;
00291     } 
00292 }
00293 
00294 void KJavaApplet::showStatus(const QString &msg) {
00295     QStringList args;
00296     args << msg;
00297     context->processCmd("showstatus", args); 
00298 }
00299 
00300 void KJavaApplet::setFailed() {
00301     d->failed = true;
00302 }
00303 
00304 bool KJavaApplet::isAlive() const {
00305    return (
00306         !d->failed 
00307         && d->state >= INSTANCIATED
00308         && d->state < DESTROYED
00309    ); 
00310 }
00311 
00312 KJavaApplet::AppletState KJavaApplet::state() const {
00313     return d->state;
00314 }
00315 
00316 bool KJavaApplet::failed() const {
00317     return d->failed;
00318 }
00319 
00320 #include "kjavaapplet.moc"
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:22:39 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001