kjavaappletcontext.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "kjavaappletcontext.h"
00023 #include "kjavaappletserver.h"
00024 #include "kjavaapplet.h"
00025 #include <klocale.h>
00026 #include <kmessagebox.h>
00027 #include <kdebug.h>
00028 #include <qmap.h>
00029 #include <qguardedptr.h>
00030 #include <qstringlist.h>
00031 #include <qregexp.h>
00032
00033
00034 #define DEBUGAREA 6100
00035
00036 typedef QMap< int, QGuardedPtr<KJavaApplet> > AppletMap;
00037
00038
00039 class KJavaAppletContextPrivate
00040 {
00041 friend class KJavaAppletContext;
00042 private:
00043 AppletMap applets;
00044 };
00045
00046
00047 int KJavaAppletContext::contextCount = 0;
00048
00049
00050
00051 KJavaAppletContext::KJavaAppletContext()
00052 : QObject()
00053 {
00054 d = new KJavaAppletContextPrivate;
00055 server = KJavaAppletServer::allocateJavaServer();
00056
00057 id = contextCount;
00058 server->createContext( id, this );
00059
00060 contextCount++;
00061 }
00062
00063 KJavaAppletContext::~KJavaAppletContext()
00064 {
00065 server->destroyContext( id );
00066 KJavaAppletServer::freeJavaServer();
00067 delete d;
00068 }
00069
00070 int KJavaAppletContext::contextId()
00071 {
00072 return id;
00073 }
00074
00075 void KJavaAppletContext::setContextId( int _id )
00076 {
00077 id = _id;
00078 }
00079
00080 void KJavaAppletContext::registerApplet( KJavaApplet* applet )
00081 {
00082 static int appletId = 0;
00083
00084 applet->setAppletId( ++appletId );
00085 d->applets.insert( appletId, applet );
00086 }
00087
00088 bool KJavaAppletContext::create( KJavaApplet* applet )
00089 {
00090 return server->createApplet( id, applet->appletId(),
00091 applet->appletName(),
00092 applet->appletClass(),
00093 applet->baseURL(),
00094 applet->user(),
00095 applet->password(),
00096 applet->authName(),
00097 applet->codeBase(),
00098 applet->archives(),
00099 applet->size(),
00100 applet->getParams(),
00101 applet->getWindowName() );
00102
00103
00104 }
00105
00106 void KJavaAppletContext::destroy( KJavaApplet* applet )
00107 {
00108 int appletId = applet->appletId();
00109 d->applets.remove( appletId );
00110
00111 server->destroyApplet( id, appletId );
00112 }
00113
00114 void KJavaAppletContext::init( KJavaApplet* applet )
00115 {
00116 server->initApplet( id, applet->appletId() );
00117 }
00118
00119 void KJavaAppletContext::start( KJavaApplet* applet )
00120 {
00121 server->startApplet( id, applet->appletId() );
00122 }
00123
00124 void KJavaAppletContext::stop( KJavaApplet* applet )
00125 {
00126 server->stopApplet( id, applet->appletId() );
00127 }
00128
00129 void KJavaAppletContext::processCmd( QString cmd, QStringList args )
00130 {
00131 received( cmd, args );
00132 }
00133
00134 void KJavaAppletContext::received( const QString& cmd, const QStringList& arg )
00135 {
00136 kdDebug(6100) << "KJavaAppletContext::received, cmd = >>" << cmd << "<<" << endl;
00137 kdDebug(6100) << "arg count = " << arg.count() << endl;
00138
00139 if ( cmd == QString::fromLatin1("showstatus")
00140 && arg.count() > 0 )
00141 {
00142 QString tmp = arg[0];
00143 tmp.replace(QRegExp("[\n\r]"), "");
00144 kdDebug(6100) << "status message = " << tmp << endl;
00145 emit showStatus( tmp );
00146 }
00147 else if ( cmd == QString::fromLatin1( "showurlinframe" )
00148 && arg.count() > 1 )
00149 {
00150 kdDebug(6100) << "url = " << arg[0] << ", frame = " << arg[1] << endl;
00151 emit showDocument( arg[0], arg[1] );
00152 }
00153 else if ( cmd == QString::fromLatin1( "showdocument" )
00154 && arg.count() > 0 )
00155 {
00156 kdDebug(6100) << "url = " << arg[0] << endl;
00157 emit showDocument( arg[0], "_top" );
00158 }
00159 else if ( cmd == QString::fromLatin1( "resizeapplet" )
00160 && arg.count() > 2 )
00161 {
00162
00163
00164
00165 bool ok;
00166 int appletID = arg[0].toInt( &ok );
00167 int width = arg[1].toInt( &ok );
00168 int height = arg[2].toInt( &ok );
00169
00170 if( !ok )
00171 {
00172 kdError(DEBUGAREA) << "could not parse out parameters for resize" << endl;
00173 }
00174 else
00175 {
00176 KJavaApplet* tmp = d->applets[appletID];
00177 if (tmp)
00178 tmp->resizeAppletWidget( width, height );
00179 }
00180 }
00181 else if (cmd.startsWith(QString::fromLatin1("audioclip_"))) {
00182 kdDebug(DEBUGAREA) << "process Audio command (not yet implemented): " << cmd << " " << arg[0] << endl;
00183 }
00184 else if ( cmd == QString::fromLatin1( "JS_Event" )
00185 && arg.count() > 2 )
00186 {
00187 bool ok;
00188 int appletID = arg[0].toInt(&ok);
00189 KJavaApplet * applet;
00190 if (ok && (applet = d->applets[appletID]))
00191 {
00192 QStringList js_args(arg);
00193 js_args.pop_front();
00194 applet->jsData(js_args);
00195 }
00196 else
00197 kdError(DEBUGAREA) << "parse JS event " << arg[0] << " " << arg[1] << endl;
00198 }
00199 else if ( cmd == QString::fromLatin1( "AppletStateNotification" ) )
00200 {
00201 bool ok;
00202 int appletID = arg[0].toInt(&ok);
00203 if (ok)
00204 {
00205 KJavaApplet * applet = d->applets[appletID];
00206 if ( applet )
00207 {
00208 int newState = arg[1].toInt(&ok);
00209 if (ok)
00210 {
00211 applet->stateChange(newState);
00212 if (newState == KJavaApplet::INITIALIZED) {
00213 kdDebug(DEBUGAREA) << "emit appletLoaded" << endl;
00214 emit appletLoaded();
00215 }
00216 } else
00217 kdError(DEBUGAREA) << "AppletStateNotification: status is not numerical" << endl;
00218 } else
00219 kdWarning(DEBUGAREA) << "AppletStateNotification: No such Applet with ID=" << arg[0] << endl;
00220 } else
00221 kdError(DEBUGAREA) << "AppletStateNotification: Applet ID is not numerical" << endl;
00222 }
00223 else if ( cmd == QString::fromLatin1( "AppletFailed" ) ) {
00224 bool ok;
00225 int appletID = arg[0].toInt(&ok);
00226 if (ok)
00227 {
00228 KJavaApplet * applet = d->applets[appletID];
00229
00230
00231
00232
00233
00234 if (applet)
00235 applet->setFailed();
00236 emit appletLoaded();
00237 }
00238 }
00239 }
00240
00241 bool KJavaAppletContext::appletsLoaded() const {
00242 AppletMap::const_iterator it = d->applets.begin();
00243 for (; it != d->applets.end(); it++) {
00244 if (!(*it).isNull()) {
00245 if (!(*it)->isAlive() && !(*it)->failed()) {
00246 return false;
00247 }
00248 }
00249 }
00250 return true;
00251 }
00252
00253 bool KJavaAppletContext::getMember(QStringList & args, QStringList & ret_args) {
00254 args.push_front( QString::number(id) );
00255 return server->getMember( args, ret_args );
00256 }
00257
00258 bool KJavaAppletContext::putMember( QStringList & args ) {
00259 args.push_front( QString::number(id) );
00260 return server->putMember( args );
00261 }
00262
00263 bool KJavaAppletContext::callMember(QStringList & args, QStringList &ret_args) {
00264 args.push_front( QString::number(id) );
00265 return server->callMember( args, ret_args );
00266 }
00267
00268 void KJavaAppletContext::derefObject( QStringList & args ) {
00269 args.push_front( QString::number(id) );
00270 server->derefObject( args );
00271 }
00272
00273 #include <kjavaappletcontext.moc>
This file is part of the documentation for khtml Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Apr 21 18:45:04 2004 by
doxygen 1.3.6-20040222 written by
Dimitri van Heesch, © 1997-2003