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

KHTML

kjavaappletviewer.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002  *
00003  * Copyright (C) 2003 Koos Vriezen <koos.vriezen@xs4all.nl>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public License
00016  * along with this library; see the file COPYING.LIB.  If not, write to
00017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019  */
00020 #include <stdio.h>
00021 
00022 #ifdef KDE_USE_FINAL
00023 #undef Always
00024 #endif
00025 #include <qdir.h>
00026 #include <qtable.h>
00027 #include <qpair.h>
00028 #include <qtimer.h>
00029 #include <qguardedptr.h>
00030 #include <qlabel.h>
00031 
00032 #include <klibloader.h>
00033 #include <kaboutdata.h>
00034 #include <kstaticdeleter.h>
00035 #include <klocale.h>
00036 #include <kstatusbar.h>
00037 #include <kiconloader.h>
00038 #include <kapplication.h>
00039 #include <kdebug.h>
00040 #include <kconfig.h>
00041 #include <kio/authinfo.h>
00042 #include <dcopclient.h>
00043 
00044 #include "kjavaappletwidget.h"
00045 #include "kjavaappletviewer.h"
00046 #include "kjavaappletserver.h"
00047 
00048 
00049 K_EXPORT_COMPONENT_FACTORY (kjavaappletviewer, KJavaAppletViewerFactory)
00050 
00051 KInstance *KJavaAppletViewerFactory::s_instance = 0;
00052 
00053 KJavaAppletViewerFactory::KJavaAppletViewerFactory () {
00054     s_instance = new KInstance ("kjava");
00055 }
00056 
00057 KJavaAppletViewerFactory::~KJavaAppletViewerFactory () {
00058     delete s_instance;
00059 }
00060 
00061 KParts::Part *KJavaAppletViewerFactory::createPartObject
00062   (QWidget *wparent, const char *wname,
00063    QObject *parent, const char * name, const char *, const QStringList & args) {
00064     return new KJavaAppletViewer (wparent, wname, parent, name, args);
00065 }
00066 
00067 //-----------------------------------------------------------------------------
00068 
00069 class KJavaServerMaintainer;
00070 static KJavaServerMaintainer * serverMaintainer = 0;
00071 
00072 class KJavaServerMaintainer {
00073 public:
00074     KJavaServerMaintainer () { }
00075     ~KJavaServerMaintainer ();
00076 
00077     KJavaAppletContext * getContext (QObject*, const QString &);
00078     void releaseContext (QObject*, const QString &);
00079     void setServer (KJavaAppletServer * s);
00080     QGuardedPtr <KJavaAppletServer> server;
00081 private:
00082     typedef QMap <QPair <QObject*, QString>, QPair <KJavaAppletContext*, int> >
00083             ContextMap;
00084     ContextMap m_contextmap;
00085 };
00086 
00087 KJavaServerMaintainer::~KJavaServerMaintainer () {
00088     delete server;
00089 }
00090 
00091 KJavaAppletContext * KJavaServerMaintainer::getContext (QObject * w, const QString & doc) {
00092     ContextMap::key_type key = qMakePair (w, doc);
00093     ContextMap::iterator it = m_contextmap.find (key);
00094     if (it != m_contextmap.end ()) {
00095         ++((*it).second);
00096         return (*it).first;
00097     }
00098     KJavaAppletContext* const context = new KJavaAppletContext ();
00099     m_contextmap.insert (key, qMakePair(context, 1));
00100     return context;
00101 }
00102 
00103 void KJavaServerMaintainer::releaseContext (QObject * w, const QString & doc) {
00104     ContextMap::iterator it = m_contextmap.find (qMakePair (w, doc));
00105     if (it != m_contextmap.end () && --(*it).second <= 0) {
00106         kdDebug(6100) << "KJavaServerMaintainer::releaseContext" << endl;
00107         (*it).first->deleteLater ();
00108         m_contextmap.remove (it);
00109     }
00110 }
00111 
00112 inline void KJavaServerMaintainer::setServer (KJavaAppletServer * s) {
00113     if (!server)
00114         server = s;
00115 }
00116 
00117 static KStaticDeleter <KJavaServerMaintainer> serverMaintainerDeleter;
00118 
00119 //-----------------------------------------------------------------------------
00120 
00121 AppletParameterDialog::AppletParameterDialog (KJavaAppletWidget * parent)
00122     : KDialogBase (parent, "paramdialog", true, i18n ("Applet Parameters"),
00123                    KDialogBase::Close, KDialogBase::Close, true),
00124       m_appletWidget (parent) {
00125     KJavaApplet* const applet = parent->applet ();
00126     table = new QTable (30, 2, this);
00127     table->setMinimumSize (QSize (600, 400));
00128     table->setColumnWidth (0, 200);
00129     table->setColumnWidth (1, 340);
00130     QHeader* const header = table->horizontalHeader();
00131     header->setLabel (0, i18n ("Parameter"));
00132     header->setLabel (1, i18n ("Value"));
00133     QTableItem * tit = new QTableItem (table, QTableItem::Never, i18n("Class"));
00134     table->setItem (0, 0, tit);
00135     tit = new QTableItem(table, QTableItem::Always, applet->appletClass());
00136     table->setItem (0, 1, tit);
00137     tit = new QTableItem (table, QTableItem::Never, i18n ("Base URL"));
00138     table->setItem (1, 0, tit);
00139     tit = new QTableItem(table, QTableItem::Always, applet->baseURL());
00140     table->setItem (1, 1, tit);
00141     tit = new QTableItem (table, QTableItem::Never, i18n ("Archives"));
00142     table->setItem (2, 0, tit);
00143     tit = new QTableItem(table, QTableItem::Always, applet->archives());
00144     table->setItem (2, 1, tit);
00145     QMap<QString,QString>::const_iterator it = applet->getParams().begin();
00146     const QMap<QString,QString>::const_iterator itEnd = applet->getParams().end();
00147     for (int count = 2; it != itEnd; ++it) {
00148         tit = new QTableItem (table, QTableItem::Always, it.key ());
00149         table->setItem (++count, 0, tit);
00150         tit = new QTableItem(table, QTableItem::Always, it.data ());
00151         table->setItem (count, 1, tit);
00152     }
00153     setMainWidget (table);
00154 }
00155 
00156 void AppletParameterDialog::slotClose () {
00157     table->selectCells (0, 0, 0, 0);
00158     KJavaApplet* const applet = m_appletWidget->applet ();
00159     applet->setAppletClass (table->item (0, 1)->text ());
00160     applet->setBaseURL (table->item (1, 1)->text ());
00161     applet->setArchives (table->item (2, 1)->text ());
00162     const int lim = table->numRows();
00163     for (int i = 3; i < lim; ++i) {
00164         if (table->item (i, 0) && table->item (i, 1) && !table->item (i, 0)->text ().isEmpty ())
00165             applet->setParameter (table->item (i, 0)->text (),
00166                                   table->item (i, 1)->text ());
00167     }
00168     hide ();
00169 }
00170 //-----------------------------------------------------------------------------
00171 
00172 class CoverWidget : public QWidget {
00173     KJavaAppletWidget * m_appletwidget;
00174 public:
00175     CoverWidget (QWidget *);
00176     ~CoverWidget () {}
00177     KJavaAppletWidget * appletWidget () const;
00178 protected:
00179     void resizeEvent (QResizeEvent * e);
00180 };
00181 
00182 inline CoverWidget::CoverWidget (QWidget * parent)
00183  : QWidget (parent, "KJavaAppletViewer Widget")
00184 {
00185     m_appletwidget = new KJavaAppletWidget (this);
00186     setFocusProxy (m_appletwidget);
00187 }
00188 
00189 inline KJavaAppletWidget * CoverWidget::appletWidget () const {
00190     return m_appletwidget;
00191 }
00192 
00193 void CoverWidget::resizeEvent (QResizeEvent * e) {
00194     m_appletwidget->resize (e->size().width(), e->size().height());
00195 }
00196 
00197 //-----------------------------------------------------------------------------
00198 
00199 class StatusBarIcon : public QLabel {
00200 public:
00201     StatusBarIcon (QWidget * parent) : QLabel (parent) {
00202         setPixmap (SmallIcon (QString ("java"), KJavaAppletViewerFactory::instance ()));
00203     }
00204 protected:
00205     void mousePressEvent (QMouseEvent *) {
00206         serverMaintainer->server->showConsole ();
00207     }
00208 };
00209 
00210 //-----------------------------------------------------------------------------
00211 
00212 KJavaAppletViewer::KJavaAppletViewer (QWidget * wparent, const char *,
00213                  QObject * parent, const char * name, const QStringList & args)
00214  : KParts::ReadOnlyPart (parent, name),
00215    m_browserextension (new KJavaAppletViewerBrowserExtension (this)),
00216    m_liveconnect (new KJavaAppletViewerLiveConnectExtension (this)),
00217    m_statusbar (new KParts::StatusBarExtension (this)),
00218    m_statusbar_icon (0L),
00219    m_closed (true)
00220 {
00221     if (!serverMaintainer) {
00222         serverMaintainerDeleter.setObject (serverMaintainer,
00223                                            new KJavaServerMaintainer);
00224     }
00225     m_view = new CoverWidget (wparent);
00226     QString classname, classid, codebase, khtml_codebase, src_param;
00227     int width = -1;
00228     int height = -1;
00229     KJavaApplet* const applet = m_view->appletWidget()->applet ();
00230     QStringList::const_iterator it = args.begin();
00231     const QStringList::const_iterator itEnd = args.end();
00232     for ( ; it != itEnd; ++it) {
00233         const int equalPos = (*it).find("=");
00234         if (equalPos > 0) {
00235             const QString name = (*it).left (equalPos).upper ();
00236             QString value = (*it).right ((*it).length () - equalPos - 1);
00237             if (value.at(0)=='\"')
00238                 value = value.right (value.length () - 1);
00239             if (value.at (value.length () - 1) == '\"')
00240                 value.truncate (value.length () - 1);
00241             kdDebug(6100) << "name=" << name << " value=" << value << endl;
00242             if (!name.isEmpty()) {
00243                 const QString name_lower = name.lower ();
00244                 if (name == "__KHTML__PLUGINBASEURL") {
00245                     baseurl = KURL (KURL (value), QString (".")).url ();
00246                 } else if (name == "__KHTML__CODEBASE")
00247                     khtml_codebase = value;
00248                 else if (name_lower == QString::fromLatin1("codebase") ||
00249                          name_lower == QString::fromLatin1("java_codebase")) {
00250                     if (!value.isEmpty ())
00251                         codebase = value;
00252                 } else if (name == "__KHTML__CLASSID")
00253                 //else if (name.lower()==QString::fromLatin1("classid"))
00254                     classid = value;
00255                 else if (name_lower == QString::fromLatin1("code") ||
00256                          name_lower == QString::fromLatin1("java_code"))
00257                     classname = value;
00258                 else if (name_lower == QString::fromLatin1("src"))
00259                     src_param = value;
00260                 else if (name_lower == QString::fromLatin1("archive") ||
00261                          name_lower == QString::fromLatin1("java_archive") ||
00262                          name_lower.startsWith ("cache_archive"))
00263                     applet->setArchives (value);
00264                 else if (name_lower == QString::fromLatin1("name"))
00265                     applet->setAppletName (value);
00266                 else if (name_lower == QString::fromLatin1("width"))
00267                     width = value.toInt();
00268                 else if (name_lower == QString::fromLatin1("height"))
00269                     height = value.toInt();
00270                 if (!name.startsWith ("__KHTML__")) {
00271                     applet->setParameter (name, value);
00272                 }
00273             }
00274         }
00275     }
00276     if (!classid.isEmpty ()) {
00277         applet->setParameter ("CLSID", classid);
00278         kdDebug(6100) << "classid=" << classid << classid.startsWith("clsid:")<< endl;
00279         if (classid.startsWith ("clsid:"))
00280             // codeBase contains the URL to the plugin page
00281             khtml_codebase = baseurl;
00282         else if (classname.isEmpty () && classid.startsWith ("java:"))
00283             classname = classid.mid(5);
00284     }
00285     if (classname.isEmpty ())
00286         classname = src_param;
00287     else if (!src_param.isEmpty ())
00288         applet->setParameter (QString ("SRC"), src_param);
00289     if (codebase.isEmpty ())
00290         codebase = khtml_codebase;
00291     if (baseurl.isEmpty ()) {
00292         // not embeded in khtml
00293         QString pwd = QDir().absPath ();
00294         if (!pwd.endsWith (QChar (QDir::separator ())))
00295             pwd += QDir::separator ();
00296         baseurl = KURL (KURL (pwd), codebase).url ();
00297     }
00298     if (width > 0 && height > 0) {
00299         m_view->resize (width, height);
00300         applet->setSize( QSize( width, height ) );
00301     }
00302     applet->setBaseURL (baseurl);
00303     // check codebase first
00304     const KURL kbaseURL( baseurl );
00305     const KURL newURL(kbaseURL, codebase);
00306     if (kapp->authorizeURLAction("redirect", KURL(baseurl), newURL))
00307         applet->setCodeBase (newURL.url());
00308     applet->setAppletClass (classname);
00309     KJavaAppletContext* const cxt = serverMaintainer->getContext (parent, baseurl);
00310     applet->setAppletContext (cxt);
00311 
00312     KJavaAppletServer* const server = cxt->getServer ();
00313 
00314     serverMaintainer->setServer (server);
00315 
00316     if (!server->usingKIO ()) {
00317         /* if this page needs authentication */
00318         KIO::AuthInfo info;
00319         QString errorMsg;
00320         QCString replyType;
00321         QByteArray params;
00322         QByteArray reply;
00323         KIO::AuthInfo authResult;
00324 
00325         //(void) dcopClient(); // Make sure to have a dcop client.
00326         info.url = baseurl;
00327         info.verifyPath = true;
00328 
00329         QDataStream stream(params, IO_WriteOnly);
00330         stream << info << m_view->topLevelWidget()->winId();
00331 
00332         if (!kapp->dcopClient ()->call( "kded", "kpasswdserver", "checkAuthInfo(KIO::AuthInfo, long int)", params, replyType, reply ) ) {
00333             kdWarning() << "Can't communicate with kded_kpasswdserver!" << endl;
00334         } else if ( replyType == "KIO::AuthInfo" ) {
00335             QDataStream stream2( reply, IO_ReadOnly );
00336             stream2 >> authResult;
00337             applet->setUser (authResult.username);
00338             applet->setPassword (authResult.password);
00339             applet->setAuthName (authResult.realmValue);
00340         }
00341     }
00342 
00343     /* install event filter for close events */
00344     if (wparent)
00345         wparent->topLevelWidget ()->installEventFilter (this);
00346 
00347     setInstance (KJavaAppletViewerFactory::instance ());
00348     KParts::Part::setWidget (m_view);
00349 
00350     connect (applet->getContext(), SIGNAL(appletLoaded()), this, SLOT(appletLoaded()));
00351     connect (applet->getContext(), SIGNAL(showDocument(const QString&, const QString&)), m_browserextension, SLOT(showDocument(const QString&, const QString&)));
00352     connect (applet->getContext(), SIGNAL(showStatus(const QString &)), this, SLOT(infoMessage(const QString &)));
00353     connect (applet, SIGNAL(jsEvent (const QStringList &)), m_liveconnect, SLOT(jsEvent (const QStringList &)));
00354 }
00355 
00356 bool KJavaAppletViewer::eventFilter (QObject *o, QEvent *e) {
00357     if (m_liveconnect->jsSessions () > 0) {
00358         switch (e->type()) {
00359             case QEvent::Destroy:
00360             case QEvent::Close:
00361             case QEvent::Quit:
00362                 return true;
00363             default:
00364                 break;
00365         }
00366     }
00367     return KParts::ReadOnlyPart::eventFilter(o,e);
00368 }
00369 
00370 KJavaAppletViewer::~KJavaAppletViewer () {
00371     m_view = 0L;
00372     serverMaintainer->releaseContext (parent(), baseurl);
00373     if (m_statusbar_icon) {
00374         m_statusbar->removeStatusBarItem (m_statusbar_icon);
00375         delete m_statusbar_icon;
00376     }
00377 }
00378 
00379 bool KJavaAppletViewer::openURL (const KURL & url) {
00380     if (!m_view) return false;
00381     m_closed = false;
00382     KJavaAppletWidget* const w = m_view->appletWidget ();
00383     KJavaApplet* const applet = w->applet ();
00384     if (applet->isCreated ())
00385         applet->stop ();
00386     if (applet->appletClass ().isEmpty ()) {
00387         // preview without setting a class?
00388         if (applet->baseURL ().isEmpty ()) {
00389             applet->setAppletClass (url.fileName ());
00390             applet->setBaseURL (url.upURL ().url ());
00391         } else
00392             applet->setAppletClass (url.url ());
00393         AppletParameterDialog (w).exec ();
00394         applet->setSize (w->sizeHint());
00395     }
00396     if (!m_statusbar_icon) {
00397         KStatusBar *sb = m_statusbar->statusBar();
00398         if (sb) {
00399             m_statusbar_icon = new StatusBarIcon (sb);
00400             m_statusbar->addStatusBarItem (m_statusbar_icon, 0, false);
00401         }
00402     }
00403     // delay showApplet if size is unknown and m_view not shown
00404     if (applet->size().width() > 0 || m_view->isVisible())
00405         w->showApplet ();
00406     else
00407         QTimer::singleShot (10, this, SLOT (delayedCreateTimeOut ()));
00408     if (!applet->failed ())
00409         emit started (0L);
00410     return url.isValid ();
00411 }
00412 
00413 bool KJavaAppletViewer::closeURL () {
00414     kdDebug(6100) << "closeURL" << endl;
00415     m_closed = true;
00416     KJavaApplet* const applet = m_view->appletWidget ()->applet ();
00417     if (applet->isCreated ())
00418         applet->stop ();
00419     applet->getContext()->getServer()->endWaitForReturnData();
00420     return true;
00421 }
00422 
00423 bool KJavaAppletViewer::appletAlive () const {
00424     return !m_closed && m_view &&
00425            m_view->appletWidget ()->applet () &&
00426            m_view->appletWidget ()->applet ()->isAlive ();
00427 }
00428 
00429 bool KJavaAppletViewer::openFile () {
00430     return false;
00431 }
00432 
00433 void KJavaAppletViewer::delayedCreateTimeOut () {
00434     KJavaAppletWidget* const w = m_view->appletWidget ();
00435     if (!w->applet ()->isCreated () && !m_closed)
00436         w->showApplet ();
00437 }
00438 
00439 void KJavaAppletViewer::appletLoaded () {
00440     if (!m_view) return;
00441     KJavaApplet* const applet = m_view->appletWidget ()->applet ();
00442     if (applet->isAlive() || applet->failed())
00443         emit completed();
00444 }
00445 
00446 void KJavaAppletViewer::infoMessage (const QString & msg) {
00447     m_browserextension->infoMessage(msg);
00448 }
00449 
00450 KAboutData* KJavaAppletViewer::createAboutData () {
00451     return new KAboutData("KJavaAppletViewer", I18N_NOOP("KDE Java Applet Plugin"), "1.0");
00452 }
00453 
00454 //---------------------------------------------------------------------
00455 
00456 KJavaAppletViewerBrowserExtension::KJavaAppletViewerBrowserExtension (KJavaAppletViewer * parent)
00457   : KParts::BrowserExtension (parent, "KJavaAppletViewer Browser Extension") {
00458 }
00459 
00460 void KJavaAppletViewerBrowserExtension::urlChanged (const QString & url) {
00461     emit setLocationBarURL (url);
00462 }
00463 
00464 void KJavaAppletViewerBrowserExtension::setLoadingProgress (int percentage) {
00465     emit loadingProgress (percentage);
00466 }
00467 
00468 void KJavaAppletViewerBrowserExtension::setURLArgs (const KParts::URLArgs & /*args*/) {
00469 }
00470 
00471 void KJavaAppletViewerBrowserExtension::saveState (QDataStream & stream) {
00472     KJavaApplet* const applet = static_cast<KJavaAppletViewer*>(parent())->view()->appletWidget ()->applet ();
00473     stream << applet->appletClass();
00474     stream << applet->baseURL();
00475     stream << applet->archives();
00476     stream << applet->getParams().size ();
00477     QMap<QString,QString>::const_iterator it = applet->getParams().begin();
00478     const QMap<QString,QString>::const_iterator itEnd = applet->getParams().end();
00479     for ( ; it != itEnd; ++it) {
00480         stream << it.key ();
00481         stream << it.data ();
00482     }
00483 }
00484 
00485 void KJavaAppletViewerBrowserExtension::restoreState (QDataStream & stream) {
00486     KJavaAppletWidget* const w = static_cast<KJavaAppletViewer*>(parent())->view()->appletWidget();
00487     KJavaApplet* const applet = w->applet ();
00488     QString key, val;
00489     int paramcount;
00490     stream >> val;
00491     applet->setAppletClass (val);
00492     stream >> val;
00493     applet->setBaseURL (val);
00494     stream >> val;
00495     applet->setArchives (val);
00496     stream >> paramcount;
00497     for (int i = 0; i < paramcount; ++i) {
00498         stream >> key;
00499         stream >> val;
00500         applet->setParameter (key, val);
00501         kdDebug(6100) << "restoreState key:" << key << " val:" << val << endl;
00502     }
00503     applet->setSize (w->sizeHint ());
00504     if (w->isVisible())
00505         w->showApplet ();
00506 }
00507 
00508 void KJavaAppletViewerBrowserExtension::showDocument (const QString & doc,
00509                                                       const QString & frame) {
00510     const KURL url (doc);
00511     KParts::URLArgs args;
00512     args.frameName = frame;
00513     emit openURLRequest (url, args);
00514 }
00515 
00516 //-----------------------------------------------------------------------------
00517 
00518 KJavaAppletViewerLiveConnectExtension::KJavaAppletViewerLiveConnectExtension(KJavaAppletViewer * parent)
00519     : KParts::LiveConnectExtension (parent, "KJavaAppletViewer LiveConnect Extension"), m_viewer (parent) {
00520 }
00521 
00522 bool KJavaAppletViewerLiveConnectExtension::get (
00523         const unsigned long objid, const QString & name,
00524         KParts::LiveConnectExtension::Type & type,
00525         unsigned long & rid, QString & value)
00526 {
00527     if (!m_viewer->appletAlive ())
00528         return false;
00529     QStringList args, ret_args;
00530     KJavaApplet* const applet = m_viewer->view ()->appletWidget ()->applet ();
00531     args.append (QString::number (applet->appletId ()));
00532     args.append (QString::number ((int) objid));
00533     args.append (name);
00534     m_jssessions++;
00535     const bool ret = applet->getContext()->getMember (args, ret_args);
00536     m_jssessions--;
00537     if (!ret || ret_args.count() != 3) return false;
00538     bool ok;
00539     int itype = ret_args[0].toInt (&ok);
00540     if (!ok || itype < 0) return false;
00541     type = (KParts::LiveConnectExtension::Type) itype;
00542     rid = ret_args[1].toInt (&ok);
00543     if (!ok) return false;
00544     value = ret_args[2];
00545     return true;
00546 }
00547 
00548 bool KJavaAppletViewerLiveConnectExtension::put(const unsigned long objid, const QString & name, const QString & value)
00549 {
00550     if (!m_viewer->appletAlive ())
00551         return false;
00552     QStringList args;
00553     KJavaApplet* const applet = m_viewer->view ()->appletWidget ()->applet ();
00554     args.append (QString::number (applet->appletId ()));
00555     args.append (QString::number ((int) objid));
00556     args.append (name);
00557     args.append (value);
00558     ++m_jssessions;
00559     const bool ret = applet->getContext()->putMember (args);
00560     --m_jssessions;
00561     return ret;
00562 }
00563 
00564 bool KJavaAppletViewerLiveConnectExtension::call( const unsigned long objid, const QString & func, const QStringList & fargs, KParts::LiveConnectExtension::Type & type, unsigned long & retobjid, QString & value )
00565 {
00566     if (!m_viewer->appletAlive ())
00567         return false;
00568     KJavaApplet* const applet = m_viewer->view ()->appletWidget ()->applet ();
00569     QStringList args, ret_args;
00570     args.append (QString::number (applet->appletId ()));
00571     args.append (QString::number ((int) objid));
00572     args.append (func);
00573     args.append (QString::number ((int) fargs.size ()));
00574     {
00575         QStringList::const_iterator it = fargs.begin();
00576         const QStringList::const_iterator itEnd = fargs.end();
00577     for ( ; it != itEnd; ++it)
00578             args.append(*it);
00579     }
00580 
00581     ++m_jssessions;
00582     const bool ret = applet->getContext()->callMember (args, ret_args);
00583     --m_jssessions;
00584     if (!ret || ret_args.count () != 3) return false;
00585     bool ok;
00586     const int itype = ret_args[0].toInt (&ok);
00587     if (!ok || itype < 0) return false;
00588     type = (KParts::LiveConnectExtension::Type) itype;
00589     retobjid = ret_args[1].toInt (&ok);
00590     if (!ok) return false;
00591     value = ret_args[2];
00592     return true;
00593 }
00594 
00595 void KJavaAppletViewerLiveConnectExtension::unregister(const unsigned long objid)
00596 {
00597     if (!m_viewer->view () || !m_viewer->view ())
00598         return;
00599     KJavaApplet* const applet = m_viewer->view ()->appletWidget ()->applet ();
00600     if (!applet || objid == 0) {
00601         // typically a gc after a function call on the applet,
00602         // no need to send to the jvm
00603         return;
00604     }
00605     QStringList args;
00606     args.append (QString::number (applet->appletId ()));
00607     args.append (QString::number ((int) objid));
00608     applet->getContext()->derefObject (args);
00609 }
00610 
00611 void KJavaAppletViewerLiveConnectExtension::jsEvent (const QStringList & args) {
00612     if (args.count () < 2 || !m_viewer->appletAlive ())
00613         return;
00614     bool ok;
00615     QStringList::ConstIterator it = args.begin();
00616     const QStringList::ConstIterator itEnd = args.end();
00617     const unsigned long objid = (*it).toInt(&ok);
00618     ++it;
00619     const QString event = (*it);
00620     ++it;
00621     KParts::LiveConnectExtension::ArgList arglist;
00622 
00623     for (; it != itEnd; ++it) {
00624         // take a deep breath here
00625         const QStringList::ConstIterator prev = it++;
00626     arglist.push_back(KParts::LiveConnectExtension::ArgList::value_type((KParts::LiveConnectExtension::Type) (*prev).toInt(), (*it)));
00627     }
00628     emit partEvent (objid, event, arglist);
00629 }
00630 
00631 int KJavaAppletViewerLiveConnectExtension::m_jssessions = 0;
00632 
00633 //-----------------------------------------------------------------------------
00634 
00635 #include "kjavaappletviewer.moc"

KHTML

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

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
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