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()
00051 {
00052     d = new KJavaAppletPrivate;
00053 
00054     d->UIwidget = _parent;
00055     d->state = UNKNOWN;
00056     d->failed = false;
00057 
00058     if( _context )
00059         setAppletContext( _context );
00060 
00061     d->reallyExists = false;
00062 }
00063 
00064 KJavaApplet::~KJavaApplet()
00065 {
00066     if ( d->reallyExists )
00067         context->destroy( this );
00068 
00069     delete d;
00070 }
00071 
00072 bool KJavaApplet::isCreated()
00073 {
00074     return d->reallyExists;
00075 }
00076 
00077 void KJavaApplet::setAppletContext( KJavaAppletContext* _context )
00078 {
00079     context = _context;
00080     context->registerApplet( this );
00081 }
00082 
00083 void KJavaApplet::setAppletClass( const QString& _className )
00084 {
00085     d->className = _className;
00086 }
00087 
00088 QString& KJavaApplet::appletClass()
00089 {
00090     return d->className;
00091 }
00092 
00093 QString& KJavaApplet::parameter( const QString& name )
00094 {
00095     return params[ name ];
00096 }
00097 
00098 void KJavaApplet::setParameter( const QString& name, const QString& value )
00099 {
00100     params.insert( name, value );
00101 }
00102 
00103 QMap<QString,QString>& KJavaApplet::getParams()
00104 {
00105     return params;
00106 }
00107 
00108 void KJavaApplet::setBaseURL( const QString& baseURL )
00109 {
00110     d->baseURL = baseURL;
00111 }
00112 
00113 QString& KJavaApplet::baseURL()
00114 {
00115     return d->baseURL;
00116 }
00117 
00118 void KJavaApplet::setCodeBase( const QString& codeBase )
00119 {
00120     d->codeBase = codeBase;
00121 }
00122 
00123 QString& KJavaApplet::codeBase()
00124 {
00125     return d->codeBase;
00126 }
00127 
00128 void KJavaApplet::setSize( QSize size )
00129 {
00130     d->size = size;
00131 }
00132 
00133 QSize KJavaApplet::size()
00134 {
00135     return d->size;
00136 }
00137 
00138 void KJavaApplet::setArchives( const QString& _archives )
00139 {
00140     d->archives = _archives;
00141 }
00142 
00143 QString& KJavaApplet::archives()
00144 {
00145     return d->archives;
00146 }
00147 
00148 void KJavaApplet::resizeAppletWidget( int width, int height )
00149 {
00150     kdDebug(6100) << "KJavaApplet, id = " << id << ", ::resizeAppletWidget to " << width << ", " << height << endl;
00151 
00152     if( d->UIwidget )
00153         d->UIwidget->resize( width, height );
00154 }
00155 
00156 void KJavaApplet::setAppletName( const QString& name )
00157 {
00158     d->appName = name;
00159 }
00160 
00161 void KJavaApplet::setWindowName( const QString& title )
00162 {
00163     d->windowName = title;
00164 }
00165 
00166 QString& KJavaApplet::getWindowName()
00167 {
00168     return d->windowName;
00169 }
00170 
00171 QString& KJavaApplet::appletName()
00172 {
00173     return d->appName;
00174 }
00175 
00176 void KJavaApplet::create( )
00177 {
00178     if (  !context->create( this ) )
00179         setFailed();
00180     d->reallyExists = true;
00181 }
00182 
00183 void KJavaApplet::init()
00184 {
00185     context->init( this );
00186 }
00187 
00188 void KJavaApplet::start()
00189 {
00190     context->start( this );
00191 }
00192 
00193 void KJavaApplet::stop()
00194 {
00195     context->stop( this );
00196 }
00197 
00198 int KJavaApplet::appletId()
00199 {
00200     return id;
00201 }
00202 
00203 void KJavaApplet::setAppletId( int _id )
00204 {
00205     id = _id;
00206 }
00207 
00208 void KJavaApplet::stateChange( const int newStateInt ) {
00209     AppletState newState = (AppletState)newStateInt;
00210     bool ok = false;
00211     if (d->failed) {
00212         return;
00213     }
00214     switch ( newState ) {
00215         case CLASS_LOADED:
00216             ok = (d->state == UNKNOWN);
00217             break;
00218         case INSTANCIATED:
00219             if (ok) {
00220                 showStatus(i18n("Initializing Applet \"%1\"...").arg(appletName()));
00221             }
00222             ok = (d->state == CLASS_LOADED);
00223             break;
00224         case INITIALIZED:
00225             ok = (d->state == INSTANCIATED);
00226             if (ok) { 
00227                 showStatus(i18n("Starting Applet \"%1\"...").arg(appletName()));
00228                 start();
00229             }
00230             break;
00231         case STARTED:
00232             ok = (d->state == INITIALIZED || d->state == STOPPED);
00233             if (ok) {    
00234                 showStatus(i18n("Applet \"%1\" started").arg(appletName()));
00235             }
00236             break;
00237         case STOPPED:
00238             ok = (d->state == INITIALIZED || d->state == STARTED);
00239             if (ok) {    
00240                 showStatus(i18n("Applet \"%1\" stopped").arg(appletName()));
00241             }
00242             break;
00243         case DESTROYED:
00244             ok = true;
00245             break;
00246         default:
00247             break;
00248     }
00249     if (ok) {
00250         d->state = newState;
00251     } else {
00252         kdError(6100) << "KJavaApplet::stateChange : don't want to switch from state "
00253             << d->state << " to " << newState << endl;
00254     } 
00255 }
00256 
00257 void KJavaApplet::showStatus(const QString &msg) {
00258     QStringList args;
00259     args << msg;
00260     context->processCmd("showstatus", args); 
00261 }
00262 
00263 void KJavaApplet::setFailed() {
00264     d->failed = true;
00265 }
00266 
00267 bool KJavaApplet::isAlive() const {
00268    return (
00269         !d->failed 
00270         && d->state >= INSTANCIATED
00271         && d->state < STOPPED
00272    ); 
00273 }
00274 
00275 KJavaApplet::AppletState KJavaApplet::state() const {
00276     return d->state;
00277 }
00278 
00279 bool KJavaApplet::failed() const {
00280     return d->failed;
00281 }
00282 
00283 #include "kjavaapplet.moc"
KDE Logo
This file is part of the documentation for khtml Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Aug 4 05:28:56 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2003