khtml Library API Documentation

kjavaappletcontext.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 "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 // This file was using 6002, but kdebug.areas didn't know about that number 00034 #define DEBUGAREA 6100 00035 00036 typedef QMap< int, QGuardedPtr<KJavaApplet> > AppletMap; 00037 00038 // For future expansion 00039 class KJavaAppletContextPrivate 00040 { 00041 friend class KJavaAppletContext; 00042 private: 00043 AppletMap applets; 00044 }; 00045 00046 // Static Factory Functions 00047 int KJavaAppletContext::contextCount = 0; 00048 00049 /* Class Implementation 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 //arg[1] should be appletID 00163 //arg[2] should be new width 00164 //arg[3] should be new height 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 QString errorDetail(arg[1]); 00231 errorDetail.replace(QRegExp(":\\s*"), ":\n"); 00232 KMessageBox::detailedError(0L, i18n("Java error while loading applet."), errorDetail); 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>
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 Sat Jun 12 15:09:58 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003