• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KHTML

kjavaapplet.cpp

Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  */
00021 
00022 #include "kjavaappletwidget.h"
00023 #include "kjavaappletcontext.h"
00024 
00025 #include <klocale.h>
00026 #include <kdebug.h>
00027 #include <kparts/browserextension.h>
00028 
00029 
00030 
00031 class KJavaAppletPrivate
00032 {
00033 public:
00034    bool    reallyExists;
00035    bool    failed;
00036    QString className;
00037    QString appName;
00038    QString baseURL;
00039    QString codeBase;
00040    QString archives;
00041    QSize   size;
00042    QString windowName;
00043    KJavaApplet::AppletState state;
00044 
00045    KJavaAppletWidget* UIwidget;
00046 };
00047 
00048 
00049 KJavaApplet::KJavaApplet( KJavaAppletWidget* _parent,
00050                           KJavaAppletContext* _context )
00051     : d(new KJavaAppletPrivate), params()
00052 {
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     kDebug(6100) << "KJavaApplet, id = " << id << ", ::resizeAppletWidget to " << width << ", " << height;
00151 
00152     QStringList sl;
00153     sl.push_back( QString::number( 0 ) ); // applet itself has id 0
00154     sl.push_back( QString( "eval" ) );    // evaluate next script
00155     sl.push_back( QString::number( KParts::LiveConnectExtension::TypeString ) );
00156     sl.push_back( QString( "this.setAttribute('WIDTH',%1);this.setAttribute('HEIGHT',%2)" ).arg( width ).arg( height ) );
00157     jsData( sl );
00158 }
00159 
00160 void KJavaApplet::setAppletName( const QString& name )
00161 {
00162     d->appName = name;
00163 }
00164 
00165 void KJavaApplet::setWindowName( const QString& title )
00166 {
00167     d->windowName = title;
00168 }
00169 
00170 QString& KJavaApplet::getWindowName()
00171 {
00172     return d->windowName;
00173 }
00174 
00175 QString& KJavaApplet::appletName()
00176 {
00177     return d->appName;
00178 }
00179 
00180 void KJavaApplet::create( )
00181 {
00182     if (  !context->create( this ) )
00183         setFailed();
00184     d->reallyExists = true;
00185 }
00186 
00187 void KJavaApplet::init()
00188 {
00189     context->init( this );
00190 }
00191 
00192 void KJavaApplet::start()
00193 {
00194     context->start( this );
00195 }
00196 
00197 void KJavaApplet::stop()
00198 {
00199     context->stop( this );
00200 }
00201 
00202 int KJavaApplet::appletId()
00203 {
00204     return id;
00205 }
00206 
00207 void KJavaApplet::setAppletId( int _id )
00208 {
00209     id = _id;
00210 }
00211 
00212 void KJavaApplet::stateChange( const int newStateInt ) {
00213     AppletState newState = (AppletState)newStateInt;
00214     bool ok = false;
00215     if (d->failed) {
00216         return;
00217     }
00218     switch ( newState ) {
00219         case CLASS_LOADED:
00220             ok = (d->state == UNKNOWN);
00221             break;
00222         case INSTANCIATED:
00223             if (ok) {
00224                 showStatus(i18n("Initializing Applet \"%1\"...", appletName()));
00225             }
00226             ok = (d->state == CLASS_LOADED);
00227             break;
00228         case INITIALIZED:
00229             ok = (d->state == INSTANCIATED);
00230             if (ok) { 
00231                 showStatus(i18n("Starting Applet \"%1\"...", appletName()));
00232                 start();
00233             }
00234             break;
00235         case STARTED:
00236             ok = (d->state == INITIALIZED || d->state == STOPPED);
00237             if (ok) {    
00238                 showStatus(i18n("Applet \"%1\" started", appletName()));
00239             }
00240             break;
00241         case STOPPED:
00242             ok = (d->state == INITIALIZED || d->state == STARTED);
00243             if (ok) {    
00244                 showStatus(i18n("Applet \"%1\" stopped", appletName()));
00245             }
00246             break;
00247         case DESTROYED:
00248             ok = true;
00249             break;
00250         default:
00251             break;
00252     }
00253     if (ok) {
00254         d->state = newState;
00255     } else {
00256         kError(6100) << "KJavaApplet::stateChange : don't want to switch from state "
00257             << d->state << " to " << newState << endl;
00258     } 
00259 }
00260 
00261 void KJavaApplet::showStatus(const QString &msg) {
00262     QStringList args;
00263     args << msg;
00264     context->processCmd("showstatus", args); 
00265 }
00266 
00267 void KJavaApplet::setFailed() {
00268     d->failed = true;
00269 }
00270 
00271 bool KJavaApplet::isAlive() const {
00272    return (
00273         !d->failed 
00274         && d->state >= INSTANCIATED
00275         && d->state < STOPPED
00276    ); 
00277 }
00278 
00279 KJavaApplet::AppletState KJavaApplet::state() const {
00280     return d->state;
00281 }
00282 
00283 bool KJavaApplet::failed() const {
00284     return d->failed;
00285 }
00286 
00287 #include "kjavaapplet.moc"

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal