• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • 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 
00021 #include "kjavaappletviewer.h"
00022 
00023 #include "kjavaappletwidget.h"
00024 #include "kjavaappletserver.h"
00025 
00026 #include <stdio.h>
00027 
00028 #ifdef KDE_USE_FINAL
00029 #undef Always
00030 #endif
00031 #include <QtCore/QDir>
00032 #include <QtCore/QPair>
00033 #include <QtCore/QTimer>
00034 #include <QtCore/QPointer>
00035 #include <QtGui/QLabel>
00036 #include <QtGui/QTableWidget>
00037 #include <QtDBus/QtDBus>
00038 
00039 #include <kauthorized.h>
00040 #include <klibloader.h>
00041 #include <kaboutdata.h>
00042 #include <klocale.h>
00043 #include <kstatusbar.h>
00044 #include <kiconloader.h>
00045 #include <kdebug.h>
00046 #include <kconfig.h>
00047 #include <kio/authinfo.h>
00048 
00049 
00050 K_EXPORT_COMPONENT_FACTORY (kjavaappletviewer, KJavaAppletViewerFactory)
00051 
00052 KComponentData *KJavaAppletViewerFactory::s_componentData = 0;
00053 KIconLoader *KJavaAppletViewerFactory::s_iconLoader = 0;
00054 
00055 KJavaAppletViewerFactory::KJavaAppletViewerFactory () {
00056     s_componentData = new KComponentData("kjava");
00057     s_iconLoader = new KIconLoader(s_componentData->componentName(), s_componentData->dirs());
00058 }
00059 
00060 KJavaAppletViewerFactory::~KJavaAppletViewerFactory () {
00061     delete s_iconLoader;
00062     delete s_componentData;
00063 }
00064 
00065 KParts::Part *KJavaAppletViewerFactory::createPartObject
00066   (QWidget *wparent,
00067    QObject *parent, const char *, const QStringList & args) {
00068     return new KJavaAppletViewer (wparent, parent, args);
00069 }
00070 
00071 //-----------------------------------------------------------------------------
00072 
00073 class KJavaServerMaintainer;
00074 
00075 class KJavaServerMaintainer {
00076 public:
00077     KJavaServerMaintainer () { }
00078     ~KJavaServerMaintainer ();
00079 
00080     KJavaAppletContext * getContext (QObject*, const QString &);
00081     void releaseContext (QObject*, const QString &);
00082     void setServer (KJavaAppletServer * s);
00083     QPointer <KJavaAppletServer> server;
00084 private:
00085     typedef QMap <QPair <QObject*, QString>, QPair <KJavaAppletContext*, int> >
00086             ContextMap;
00087     ContextMap m_contextmap;
00088 };
00089 K_GLOBAL_STATIC(KJavaServerMaintainer, serverMaintainer)
00090 
00091 KJavaServerMaintainer::~KJavaServerMaintainer () {
00092     delete server;
00093 }
00094 
00095 KJavaAppletContext * KJavaServerMaintainer::getContext (QObject * w, const QString & doc) {
00096     QPair<QObject*,QString> key = qMakePair (w, doc);
00097     ContextMap::iterator it = m_contextmap.find (key);
00098     if (it != m_contextmap.end ()) {
00099         ++((*it).second);
00100         return (*it).first;
00101     }
00102     KJavaAppletContext* const context = new KJavaAppletContext ();
00103     m_contextmap.insert (key, qMakePair(context, 1));
00104     return context;
00105 }
00106 
00107 void KJavaServerMaintainer::releaseContext (QObject * w, const QString & doc) {
00108     ContextMap::iterator it = m_contextmap.find (qMakePair (w, doc));
00109     if (it != m_contextmap.end () && --(*it).second <= 0) {
00110         kDebug(6100) << "KJavaServerMaintainer::releaseContext";
00111         (*it).first->deleteLater ();
00112         m_contextmap.erase (it);
00113     }
00114 }
00115 
00116 inline void KJavaServerMaintainer::setServer (KJavaAppletServer * s) {
00117     if (!server)
00118         server = s;
00119 }
00120 
00121 //-----------------------------------------------------------------------------
00122 
00123 AppletParameterDialog::AppletParameterDialog (KJavaAppletWidget * parent)
00124     : KDialog(parent), m_appletWidget (parent)
00125 {
00126     setObjectName( "paramdialog" );
00127     setCaption( i18n ("Applet Parameters") );
00128     setButtons( KDialog::Close );
00129     setDefaultButton( KDialog::Close );
00130     showButtonSeparator( true );
00131     setModal( true );
00132 
00133     KJavaApplet* const applet = parent->applet ();
00134     table = new QTableWidget (30, 2, this);
00135     table->setMinimumSize (QSize (600, 400));
00136     table->setColumnWidth (0, 200);
00137     table->setColumnWidth (1, 340);
00138     QTableWidgetItem* const header1 = new QTableWidgetItem(i18n ("Parameter"));
00139     QTableWidgetItem* const header2 = new QTableWidgetItem(i18n ("Value"));
00140     table->setHorizontalHeaderItem(1, header1);
00141     table->setHorizontalHeaderItem(2, header2);
00142     QTableWidgetItem * tit = new QTableWidgetItem(i18n("Class"));
00143     tit->setFlags( tit->flags()^Qt::ItemIsEditable );
00144     table->setItem (0, 0, tit);
00145     tit = new QTableWidgetItem(applet->appletClass());
00146     tit->setFlags( tit->flags()|Qt::ItemIsEditable );
00147     table->setItem (0, 1, tit);
00148     tit = new QTableWidgetItem (i18n ("Base URL"));
00149     tit->setFlags( tit->flags()^Qt::ItemIsEditable );
00150     table->setItem (1, 0, tit);
00151     tit = new QTableWidgetItem(applet->baseURL());
00152     tit->setFlags( tit->flags()|Qt::ItemIsEditable );
00153     table->setItem (1, 1, tit);
00154     tit = new QTableWidgetItem(i18n ("Archives"));
00155     tit->setFlags( tit->flags()^Qt::ItemIsEditable );
00156     table->setItem (2, 0, tit);
00157     tit = new QTableWidgetItem(applet->archives());
00158     tit->setFlags( tit->flags()|Qt::ItemIsEditable );
00159     table->setItem (2, 1, tit);
00160     QMap<QString,QString>::const_iterator it = applet->getParams().begin();
00161     const QMap<QString,QString>::const_iterator itEnd = applet->getParams().end();
00162     for (int count = 2; it != itEnd; ++it) {
00163         tit = new QTableWidgetItem (it.key ());
00164         tit->setFlags( tit->flags()|Qt::ItemIsEditable );
00165         table->setItem (++count, 0, tit);
00166         tit = new QTableWidgetItem(it.value());
00167         tit->setFlags( tit->flags()|Qt::ItemIsEditable );
00168         table->setItem (count, 1, tit);
00169     }
00170     setMainWidget (table);
00171     connect(this,SIGNAL(closeClicked()),this,SLOT(slotClose()));
00172 }
00173 
00174 void AppletParameterDialog::slotClose () {
00175     table->setRangeSelected(QTableWidgetSelectionRange(0, 0, 0, 0), true);
00176     KJavaApplet* const applet = m_appletWidget->applet ();
00177     applet->setAppletClass (table->item (0, 1)->text ());
00178     applet->setBaseURL (table->item (1, 1)->text ());
00179     applet->setArchives (table->item (2, 1)->text ());
00180     const int lim = table->rowCount();
00181     for (int i = 3; i < lim; ++i) {
00182         if (table->item (i, 0) && table->item (i, 1) && !table->item (i, 0)->text ().isEmpty ())
00183             applet->setParameter (table->item (i, 0)->text (),
00184                                   table->item (i, 1)->text ());
00185     }
00186     hide ();
00187 }
00188 //-----------------------------------------------------------------------------
00189 
00190 class CoverWidget : public QWidget {
00191     KJavaAppletWidget * m_appletwidget;
00192 public:
00193     CoverWidget (QWidget *);
00194     ~CoverWidget () {}
00195     KJavaAppletWidget * appletWidget () const;
00196 protected:
00197     void resizeEvent (QResizeEvent * e);
00198 };
00199 
00200 inline CoverWidget::CoverWidget (QWidget * parent)
00201  : QWidget (parent )
00202 {
00203     setObjectName( "KJavaAppletViewer Widget");
00204     m_appletwidget = new KJavaAppletWidget (this);
00205     setFocusProxy (m_appletwidget);
00206 }
00207 
00208 inline KJavaAppletWidget * CoverWidget::appletWidget () const {
00209     return m_appletwidget;
00210 }
00211 
00212 void CoverWidget::resizeEvent (QResizeEvent * e) {
00213     m_appletwidget->resize (e->size().width(), e->size().height());
00214 }
00215 
00216 //-----------------------------------------------------------------------------
00217 
00218 class StatusBarIcon : public QLabel {
00219 public:
00220     StatusBarIcon (QWidget * parent) : QLabel (parent) {
00221         setPixmap ( KJavaAppletViewerFactory::iconLoader()->loadIcon("java", KIconLoader::Small) );
00222     }
00223 protected:
00224     void mousePressEvent (QMouseEvent *) {
00225         serverMaintainer->server->showConsole ();
00226     }
00227 };
00228 
00229 //-----------------------------------------------------------------------------
00230 
00231 KJavaAppletViewer::KJavaAppletViewer (QWidget * wparent,
00232                  QObject * parent, const QStringList & args)
00233  : KParts::ReadOnlyPart (parent),
00234    m_browserextension (new KJavaAppletViewerBrowserExtension (this)),
00235    m_liveconnect (new KJavaAppletViewerLiveConnectExtension (this)),
00236    m_statusbar (new KParts::StatusBarExtension (this)),
00237    m_statusbar_icon (0L),
00238    m_closed (true)
00239 {
00240     m_view = new CoverWidget (wparent);
00241     QString classname, classid, codebase, khtml_codebase, src_param;
00242     QString appletname;
00243     int width = -1;
00244     int height = -1;
00245     KJavaApplet* const applet = m_view->appletWidget()->applet ();
00246     QStringList::const_iterator it = args.begin();
00247     const QStringList::const_iterator itEnd = args.end();
00248     for ( ; it != itEnd; ++it) {
00249         const int equalPos = (*it).indexOf("=");
00250         if (equalPos > 0) {
00251             const QString name = (*it).left (equalPos).toUpper ();
00252             QString value = (*it).right ((*it).length () - equalPos - 1);
00253             if (value.at(0)=='\"')
00254                 value = value.right (value.length () - 1);
00255             if (value.at (value.length () - 1) == '\"')
00256                 value.truncate (value.length () - 1);
00257             kDebug(6100) << "name=" << name << " value=" << value;
00258             if (!name.isEmpty()) {
00259                 const QString name_lower = name.toLower ();
00260                 if (name == "__KHTML__PLUGINBASEURL") {
00261                     baseurl = KUrl (KUrl (value), QString (".")).url ();
00262                 } else if (name == "__KHTML__CODEBASE")
00263                     khtml_codebase = value;
00264                 else if (name_lower == QLatin1String("codebase") ||
00265                          name_lower == QLatin1String("java_codebase")) {
00266                     if (!value.isEmpty ())
00267                         codebase = value;
00268                 } else if (name == "__KHTML__CLASSID")
00269                 //else if (name.toLower()==QLatin1String("classid"))
00270                     classid = value;
00271                 else if (name_lower == QLatin1String("code") ||
00272                          name_lower == QLatin1String("java_code"))
00273                     classname = value;
00274                 else if (name_lower == QLatin1String("src"))
00275                     src_param = value;
00276                 else if (name_lower == QLatin1String("archive") ||
00277                          name_lower == QLatin1String("java_archive") ||
00278                          name_lower.startsWith ("cache_archive"))
00279                     applet->setArchives (value);
00280                 else if (name_lower == QLatin1String("name"))
00281                     appletname = value;
00282                 else if (name_lower == QLatin1String("width"))
00283                     width = value.toInt();
00284                 else if (name_lower == QLatin1String("height"))
00285                     height = value.toInt();
00286                 if (!name.startsWith ("__KHTML__")) {
00287                     applet->setParameter (name, value);
00288                 }
00289             }
00290         }
00291     }
00292     if (!classid.isEmpty ()) {
00293         applet->setParameter ("CLSID", classid);
00294         kDebug(6100) << "classid=" << classid << classid.startsWith("clsid:");
00295         if (classid.startsWith ("clsid:"))
00296             // codeBase contains the URL to the plugin page
00297             khtml_codebase = baseurl;
00298         else if (classname.isEmpty () && classid.startsWith ("java:"))
00299             classname = classid.mid(5);
00300     }
00301     if (classname.isEmpty ())
00302         classname = src_param;
00303     else if (!src_param.isEmpty ())
00304         applet->setParameter (QString ("SRC"), src_param);
00305     if (codebase.isEmpty ())
00306         codebase = khtml_codebase;
00307     if (baseurl.isEmpty ()) {
00308         // not embedded in khtml
00309         QString pwd = QDir().absolutePath ();
00310         if (!pwd.endsWith ( QString(QDir::separator ())))
00311             pwd += QDir::separator ();
00312         baseurl = KUrl (KUrl (pwd), codebase).url ();
00313     }
00314     if (width > 0 && height > 0) {
00315         m_view->resize (width, height);
00316         applet->setSize( QSize( width, height ) );
00317     }
00318     if (appletname.isEmpty())
00319         appletname = classname;
00320     applet->setAppletName (appletname);
00321     applet->setBaseURL (baseurl);
00322     // check codebase first
00323     const KUrl kbaseURL( baseurl );
00324     const KUrl newURL(kbaseURL, codebase);
00325     if (KAuthorized::authorizeUrlAction("redirect", KUrl(baseurl), newURL))
00326         applet->setCodeBase (newURL.url());
00327     applet->setAppletClass (classname);
00328     KJavaAppletContext* const cxt = serverMaintainer->getContext (parent, baseurl);
00329     applet->setAppletContext (cxt);
00330 
00331     KJavaAppletServer* const server = cxt->getServer ();
00332 
00333     serverMaintainer->setServer (server);
00334 
00335     if (!server->usingKIO ()) {
00336         /* if this page needs authentication */
00337         KIO::AuthInfo info;
00338         info.url = baseurl;
00339         info.verifyPath = true;
00340         QByteArray params;
00341         { QDataStream stream(&params, QIODevice::WriteOnly); stream << info; }
00342 
00343         // make the call
00344         QDBusReply<QByteArray> reply =
00345             QDBusInterface("org.kde.kded", "/modules/kpasswdserver", "org.kde.KPasswdServer").
00346             call ("checkAuthInfo", params, qlonglong(m_view->topLevelWidget()->winId()));
00347 
00348         if (!reply.isValid()) {
00349             kWarning() << "Can't communicate with kded_kpasswdserver!";
00350         } else {
00351             KIO::AuthInfo authResult;
00352             QDataStream stream2(reply.value());
00353             stream2 >> authResult;
00354             applet->setUser (authResult.username);
00355             applet->setPassword (authResult.password);
00356             applet->setAuthName (authResult.realmValue);
00357         }
00358     }
00359 
00360     /* install event filter for close events */
00361     if (wparent)
00362         wparent->topLevelWidget ()->installEventFilter (this);
00363 
00364     setComponentData (KJavaAppletViewerFactory::componentData());
00365     KParts::Part::setWidget (m_view);
00366 
00367     connect (applet->getContext(), SIGNAL(appletLoaded()), this, SLOT(appletLoaded()));
00368     connect (applet->getContext(), SIGNAL(showDocument(const QString&, const QString&)), m_browserextension, SLOT(showDocument(const QString&, const QString&)));
00369     connect (applet->getContext(), SIGNAL(showStatus(const QString &)), this, SLOT(infoMessage(const QString &)));
00370     connect (applet, SIGNAL(jsEvent (const QStringList &)), m_liveconnect, SLOT(jsEvent (const QStringList &)));
00371 }
00372 
00373 CoverWidget * KJavaAppletViewer::view () const
00374 {
00375    return m_view;
00376 }
00377 
00378 
00379 bool KJavaAppletViewer::eventFilter (QObject *o, QEvent *e) {
00380     if (m_liveconnect->jsSessions () > 0) {
00381         switch (e->type()) {
00382             case QEvent::Destroy:
00383             case QEvent::Close:
00384             case QEvent::Quit:
00385                 return true;
00386             default:
00387                 break;
00388         }
00389     }
00390     return KParts::ReadOnlyPart::eventFilter(o,e);
00391 }
00392 
00393 KJavaAppletViewer::~KJavaAppletViewer () {
00394     m_view = 0L;
00395     serverMaintainer->releaseContext (parent(), baseurl);
00396     if (m_statusbar_icon) {
00397         m_statusbar->removeStatusBarItem (m_statusbar_icon);
00398         delete m_statusbar_icon;
00399     }
00400 }
00401 
00402 bool KJavaAppletViewer::openUrl (const KUrl & url) {
00403     if (!m_view) return false;
00404     m_closed = false;
00405     KJavaAppletWidget* const w = m_view->appletWidget ();
00406     KJavaApplet* const applet = w->applet ();
00407     if (applet->isCreated ())
00408         applet->stop ();
00409     if (applet->appletClass ().isEmpty ()) {
00410         // preview without setting a class?
00411         if (applet->baseURL ().isEmpty ()) {
00412             applet->setAppletClass (url.fileName ());
00413             applet->setBaseURL (url.upUrl ().url ());
00414         } else
00415             applet->setAppletClass (url.url ());
00416         AppletParameterDialog (w).exec ();
00417         applet->setSize (w->sizeHint());
00418     }
00419     if (!m_statusbar_icon) {
00420         KStatusBar *sb = m_statusbar->statusBar();
00421         if (sb) {
00422             m_statusbar_icon = new StatusBarIcon (sb);
00423             m_statusbar->addStatusBarItem (m_statusbar_icon, 0, false);
00424         }
00425     }
00426     // delay showApplet if size is unknown and m_view not shown
00427     if (applet->size().width() > 0 || m_view->isVisible())
00428         w->showApplet ();
00429     else
00430         QTimer::singleShot (10, this, SLOT (delayedCreateTimeOut ()));
00431     if (!applet->failed ())
00432         emit started (0L);
00433     return url.isValid ();
00434 }
00435 
00436 bool KJavaAppletViewer::closeUrl () {
00437     kDebug(6100) << "closeUrl";
00438     m_closed = true;
00439     KJavaApplet* const applet = m_view->appletWidget ()->applet ();
00440     if (applet->isCreated ())
00441         applet->stop ();
00442     applet->getContext()->getServer()->endWaitForReturnData();
00443     return true;
00444 }
00445 
00446 bool KJavaAppletViewer::appletAlive () const {
00447     return !m_closed && m_view &&
00448            m_view->appletWidget ()->applet () &&
00449            m_view->appletWidget ()->applet ()->isAlive ();
00450 }
00451 
00452 bool KJavaAppletViewer::openFile () {
00453     return false;
00454 }
00455 
00456 void KJavaAppletViewer::delayedCreateTimeOut () {
00457     KJavaAppletWidget* const w = m_view->appletWidget ();
00458     if (!w->applet ()->isCreated () && !m_closed)
00459         w->showApplet ();
00460 }
00461 
00462 void KJavaAppletViewer::appletLoaded () {
00463     if (!m_view) return;
00464     KJavaApplet* const applet = m_view->appletWidget ()->applet ();
00465     if (applet->isAlive() || applet->failed())
00466         emit completed();
00467 }
00468 
00469 void KJavaAppletViewer::infoMessage (const QString & msg) {
00470     m_browserextension->infoMessage(msg);
00471 }
00472 
00473 KAboutData* KJavaAppletViewer::createAboutData () {
00474     return new KAboutData("KJavaAppletViewer", 0, ki18n("KDE Java Applet Plugin"), "1.0");
00475 }
00476 
00477 //---------------------------------------------------------------------
00478 
00479 KJavaAppletViewerBrowserExtension::KJavaAppletViewerBrowserExtension (KJavaAppletViewer * parent)
00480   : KParts::BrowserExtension (parent )
00481 {
00482     setObjectName( "KJavaAppletViewer Browser Extension" );
00483 }
00484 
00485 void KJavaAppletViewerBrowserExtension::urlChanged (const QString & url) {
00486     emit setLocationBarUrl (url);
00487 }
00488 
00489 void KJavaAppletViewerBrowserExtension::setLoadingProgress (int percentage) {
00490     emit loadingProgress (percentage);
00491 }
00492 
00493 void KJavaAppletViewerBrowserExtension::setBrowserArguments (const KParts::BrowserArguments & /*args*/) {
00494 }
00495 
00496 void KJavaAppletViewerBrowserExtension::saveState (QDataStream & stream) {
00497     KJavaApplet* const applet = static_cast<KJavaAppletViewer*>(parent())->view()->appletWidget ()->applet ();
00498     stream << applet->appletClass();
00499     stream << applet->baseURL();
00500     stream << applet->archives();
00501     stream << applet->getParams().size ();
00502     QMap<QString,QString>::const_iterator it = applet->getParams().begin();
00503     const QMap<QString,QString>::const_iterator itEnd = applet->getParams().end();
00504     for ( ; it != itEnd; ++it) {
00505         stream << it.key ();
00506         stream << it.value ();
00507     }
00508 }
00509 
00510 void KJavaAppletViewerBrowserExtension::restoreState (QDataStream & stream) {
00511     KJavaAppletWidget* const w = static_cast<KJavaAppletViewer*>(parent())->view()->appletWidget();
00512     KJavaApplet* const applet = w->applet ();
00513     QString key, val;
00514     int paramcount;
00515     stream >> val;
00516     applet->setAppletClass (val);
00517     stream >> val;
00518     applet->setBaseURL (val);
00519     stream >> val;
00520     applet->setArchives (val);
00521     stream >> paramcount;
00522     for (int i = 0; i < paramcount; ++i) {
00523         stream >> key;
00524         stream >> val;
00525         applet->setParameter (key, val);
00526         kDebug(6100) << "restoreState key:" << key << " val:" << val;
00527     }
00528     applet->setSize (w->sizeHint ());
00529     if (w->isVisible())
00530         w->showApplet ();
00531 }
00532 
00533 void KJavaAppletViewerBrowserExtension::showDocument (const QString & doc,
00534                                                       const QString & frame) {
00535     const KUrl url (doc);
00536     KParts::BrowserArguments browserArgs;
00537     browserArgs.frameName = frame;
00538     emit openUrlRequest(url, KParts::OpenUrlArguments(), browserArgs);
00539 }
00540 
00541 //-----------------------------------------------------------------------------
00542 
00543 KJavaAppletViewerLiveConnectExtension::KJavaAppletViewerLiveConnectExtension(KJavaAppletViewer * parent)
00544     : KParts::LiveConnectExtension (parent ), m_viewer (parent)
00545 {
00546     setObjectName( "KJavaAppletViewer LiveConnect Extension" );
00547 }
00548 
00549 bool KJavaAppletViewerLiveConnectExtension::get (
00550         const unsigned long objid, const QString & name,
00551         KParts::LiveConnectExtension::Type & type,
00552         unsigned long & rid, QString & value)
00553 {
00554     if (!m_viewer->appletAlive ())
00555         return false;
00556     QStringList args, ret_args;
00557     KJavaApplet* const applet = m_viewer->view ()->appletWidget ()->applet ();
00558     args.append (QString::number (applet->appletId ()));
00559     args.append (QString::number ((int) objid));
00560     args.append (name);
00561     m_jssessions++;
00562     const bool ret = applet->getContext()->getMember (args, ret_args);
00563     m_jssessions--;
00564     if (!ret || ret_args.count() != 3) return false;
00565     bool ok;
00566     int itype = ret_args[0].toInt (&ok);
00567     if (!ok || itype < 0) return false;
00568     type = (KParts::LiveConnectExtension::Type) itype;
00569     rid = ret_args[1].toInt (&ok);
00570     if (!ok) return false;
00571     value = ret_args[2];
00572     return true;
00573 }
00574 
00575 bool KJavaAppletViewerLiveConnectExtension::put(const unsigned long objid, const QString & name, const QString & value)
00576 {
00577     if (!m_viewer->appletAlive ())
00578         return false;
00579     QStringList args;
00580     KJavaApplet* const applet = m_viewer->view ()->appletWidget ()->applet ();
00581     args.append (QString::number (applet->appletId ()));
00582     args.append (QString::number ((int) objid));
00583     args.append (name);
00584     args.append (value);
00585     ++m_jssessions;
00586     const bool ret = applet->getContext()->putMember (args);
00587     --m_jssessions;
00588     return ret;
00589 }
00590 
00591 bool KJavaAppletViewerLiveConnectExtension::call( const unsigned long objid, const QString & func, const QStringList & fargs, KParts::LiveConnectExtension::Type & type, unsigned long & retobjid, QString & value )
00592 {
00593     if (!m_viewer->appletAlive ())
00594         return false;
00595     KJavaApplet* const applet = m_viewer->view ()->appletWidget ()->applet ();
00596     QStringList args, ret_args;
00597     args.append (QString::number (applet->appletId ()));
00598     args.append (QString::number ((int) objid));
00599     args.append (func);
00600     {
00601         QStringList::const_iterator it = fargs.begin();
00602         const QStringList::const_iterator itEnd = fargs.end();
00603     for ( ; it != itEnd; ++it)
00604             args.append(*it);
00605     }
00606 
00607     ++m_jssessions;
00608     const bool ret = applet->getContext()->callMember (args, ret_args);
00609     --m_jssessions;
00610     if (!ret || ret_args.count () != 3) return false;
00611     bool ok;
00612     const int itype = ret_args[0].toInt (&ok);
00613     if (!ok || itype < 0) return false;
00614     type = (KParts::LiveConnectExtension::Type) itype;
00615     retobjid = ret_args[1].toInt (&ok);
00616     if (!ok) return false;
00617     value = ret_args[2];
00618     return true;
00619 }
00620 
00621 void KJavaAppletViewerLiveConnectExtension::unregister(const unsigned long objid)
00622 {
00623     if (!m_viewer->view () || !m_viewer->view ())
00624         return;
00625     KJavaApplet* const applet = m_viewer->view ()->appletWidget ()->applet ();
00626     if (!applet || objid == 0) {
00627         // typically a gc after a function call on the applet,
00628         // no need to send to the jvm
00629         return;
00630     }
00631     QStringList args;
00632     args.append (QString::number (applet->appletId ()));
00633     args.append (QString::number ((int) objid));
00634     applet->getContext()->derefObject (args);
00635 }
00636 
00637 void KJavaAppletViewerLiveConnectExtension::jsEvent (const QStringList & args) {
00638     if (args.count () < 2 || !m_viewer->appletAlive ())
00639         return;
00640     bool ok;
00641     QStringList::ConstIterator it = args.begin();
00642     const QStringList::ConstIterator itEnd = args.end();
00643     const unsigned long objid = (*it).toInt(&ok);
00644     ++it;
00645     const QString event = (*it);
00646     ++it;
00647     KParts::LiveConnectExtension::ArgList arglist;
00648 
00649     for (; it != itEnd; ++it) {
00650         // take a deep breath here
00651         const QStringList::ConstIterator prev = it++;
00652     arglist.push_back(KParts::LiveConnectExtension::ArgList::value_type((KParts::LiveConnectExtension::Type) (*prev).toInt(), (*it)));
00653     }
00654     emit partEvent (objid, event, arglist);
00655 }
00656 
00657 int KJavaAppletViewerLiveConnectExtension::m_jssessions = 0;
00658 
00659 //-----------------------------------------------------------------------------
00660 
00661 #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

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
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
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