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