• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • khtml
  • java
kjavaappletcontext.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 *
3 * Copyright (C) 2000 Richard Moore <rich@kde.org>
4 * 2000 Wynn Wilkes <wynnw@caldera.com>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22#include "kjavaappletcontext.h"
23#include "kjavaappletserver.h"
24#include "kjavaprocess.h"
25#include "kjavaapplet.h"
26#include <klocale.h>
27#include <kmessagebox.h>
28#include <kdebug.h>
29#include <QtCore/QMap>
30#include <QtCore/QPointer>
31#include <QtCore/QStringList>
32#include <QtCore/QRegExp>
33
34// This file was using 6002, but kdebug.areas didn't know about that number
35#define DEBUGAREA 6100
36
37typedef QMap< int, QPointer<KJavaApplet> > AppletMap;
38
39// For future expansion
40class KJavaAppletContextPrivate
41{
42friend class KJavaAppletContext;
43private:
44 AppletMap applets;
45};
46
47// Static Factory Functions
48int KJavaAppletContext::contextCount = 0;
49
50/* Class Implementation
51 */
52KJavaAppletContext::KJavaAppletContext()
53 : QObject(),
54 d(new KJavaAppletContextPrivate)
55{
56 server = KJavaAppletServer::allocateJavaServer();
57 connect(server->javaProcess(), SIGNAL(exited(int)), this, SLOT(javaProcessExited(int)));
58
59 id = contextCount;
60 server->createContext( id, this );
61
62 ++contextCount;
63}
64
65KJavaAppletContext::~KJavaAppletContext()
66{
67 server->destroyContext( id );
68 KJavaAppletServer::freeJavaServer();
69 delete d;
70}
71
72int KJavaAppletContext::contextId()
73{
74 return id;
75}
76
77void KJavaAppletContext::setContextId( int _id )
78{
79 id = _id;
80}
81
82void KJavaAppletContext::registerApplet( KJavaApplet* applet )
83{
84 static int appletId = 0;
85
86 applet->setAppletId( ++appletId );
87 d->applets.insert( appletId, applet );
88}
89
90bool KJavaAppletContext::create( KJavaApplet* applet )
91{
92 return server->createApplet( id, applet->appletId(),
93 applet->appletName(),
94 applet->appletClass(),
95 applet->baseURL(),
96 applet->user(),
97 applet->password(),
98 applet->authName(),
99 applet->codeBase(),
100 applet->archives(),
101 applet->size(),
102 applet->getParams(),
103 applet->getWindowName() );
104
105
106}
107
108void KJavaAppletContext::destroy( KJavaApplet* applet )
109{
110 const int appletId = applet->appletId();
111 d->applets.remove( appletId );
112
113 server->destroyApplet( id, appletId );
114}
115
116void KJavaAppletContext::init( KJavaApplet* applet )
117{
118 server->initApplet( id, applet->appletId() );
119}
120
121void KJavaAppletContext::start( KJavaApplet* applet )
122{
123 server->startApplet( id, applet->appletId() );
124}
125
126void KJavaAppletContext::stop( KJavaApplet* applet )
127{
128 server->stopApplet( id, applet->appletId() );
129}
130
131void KJavaAppletContext::processCmd( QString cmd, QStringList args )
132{
133 received( cmd, args );
134}
135
136void KJavaAppletContext::received( const QString& cmd, const QStringList& arg )
137{
138 kDebug(6100) << "KJavaAppletContext::received, cmd = >>" << cmd << "<<";
139 kDebug(6100) << "arg count = " << arg.count();
140
141 if ( cmd == QLatin1String("showstatus")
142 && !arg.empty() )
143 {
144 QString tmp = arg.first();
145 tmp.remove(QRegExp("[\n\r]"));
146 kDebug(6100) << "status message = " << tmp;
147 emit showStatus( tmp );
148 }
149 else if ( cmd == QLatin1String( "showurlinframe" )
150 && arg.count() > 1 )
151 {
152 kDebug(6100) << "url = " << arg[0] << ", frame = " << arg[1];
153 emit showDocument( arg[0], arg[1] );
154 }
155 else if ( cmd == QLatin1String( "showdocument" )
156 && !arg.empty() )
157 {
158 kDebug(6100) << "url = " << arg.first();
159 emit showDocument( arg.first(), "_top" );
160 }
161 else if ( cmd == QLatin1String( "resizeapplet" )
162 && arg.count() > 2 )
163 {
164 //arg[1] should be appletID
165 //arg[2] should be new width
166 //arg[3] should be new height
167 bool ok;
168 const int appletID = arg[0].toInt( &ok );
169 const int width = arg[1].toInt( &ok );
170 const int height = arg[2].toInt( &ok );
171
172 if( !ok )
173 {
174 kError(DEBUGAREA) << "could not parse out parameters for resize" << endl;
175 }
176 else
177 {
178 KJavaApplet* const tmp = d->applets[appletID];
179 if (tmp)
180 tmp->resizeAppletWidget( width, height );
181 }
182 }
183 else if (cmd.startsWith(QLatin1String("audioclip_"))) {
184 kDebug(DEBUGAREA) << "process Audio command (not yet implemented): " << cmd << " " << arg[0];
185 }
186 else if ( cmd == QLatin1String( "JS_Event" )
187 && arg.count() > 2 )
188 {
189 bool ok;
190 const int appletID = arg.first().toInt(&ok);
191 KJavaApplet * applet;
192 if (ok && (applet = d->applets[appletID]))
193 {
194 QStringList js_args(arg);
195 js_args.pop_front();
196 applet->jsData(js_args);
197 }
198 else
199 kError(DEBUGAREA) << "parse JS event " << arg[0] << " " << arg[1] << endl;
200 }
201 else if ( cmd == QLatin1String( "AppletStateNotification" ) )
202 {
203 bool ok;
204 const int appletID = arg.first().toInt(&ok);
205 if (ok)
206 {
207 KJavaApplet* const applet = d->applets[appletID];
208 if ( applet )
209 {
210 const int newState = arg[1].toInt(&ok);
211 if (ok)
212 {
213 applet->stateChange(newState);
214 if (newState == KJavaApplet::INITIALIZED) {
215 kDebug(DEBUGAREA) << "emit appletLoaded";
216 emit appletLoaded();
217 }
218 } else
219 kError(DEBUGAREA) << "AppletStateNotification: status is not numerical" << endl;
220 } else
221 kWarning(DEBUGAREA) << "AppletStateNotification: No such Applet with ID=" << arg[0];
222 } else
223 kError(DEBUGAREA) << "AppletStateNotification: Applet ID is not numerical" << endl;
224 }
225 else if ( cmd == QLatin1String( "AppletFailed" ) ) {
226 bool ok;
227 const int appletID = arg.first().toInt(&ok);
228 if (ok)
229 {
230 KJavaApplet* const applet = d->applets[appletID];
231 /*
232 QString errorDetail(arg[1]);
233 errorDetail.replace(QRegExp(":\\s*"), ":\n");
234 KMessageBox::detailedError(0L, i18n("Java error while loading applet."), errorDetail);
235 */
236 if (applet)
237 applet->setFailed();
238 emit appletLoaded();
239 }
240 }
241}
242
243void KJavaAppletContext::javaProcessExited(int) {
244 AppletMap::iterator it = d->applets.begin();
245 const AppletMap::iterator itEnd = d->applets.end();
246 for (; it != itEnd; ++it)
247 if (!(*it).isNull() && (*it)->isCreated() && !(*it)->failed()) {
248 (*it)->setFailed();
249 if ((*it)->state() < KJavaApplet::INITIALIZED)
250 emit appletLoaded();
251 }
252}
253
254bool KJavaAppletContext::getMember(QStringList & args, QStringList & ret_args) {
255 args.push_front( QString::number(id) );
256 return server->getMember( args, ret_args );
257}
258
259bool KJavaAppletContext::putMember( QStringList & args ) {
260 args.push_front( QString::number(id) );
261 return server->putMember( args );
262}
263
264bool KJavaAppletContext::callMember(QStringList & args, QStringList &ret_args) {
265 args.push_front( QString::number(id) );
266 return server->callMember( args, ret_args );
267}
268
269void KJavaAppletContext::derefObject( QStringList & args ) {
270 args.push_front( QString::number(id) );
271 server->derefObject( args );
272}
273
274#include <kjavaappletcontext.moc>
KJavaAppletContext
Definition: kjavaappletcontext.h:46
KJavaAppletContext::showDocument
void showDocument(const QString &url, const QString &target)
Signals the KHTML Part to show a url in a given target.
KJavaAppletContext::start
void start(KJavaApplet *)
Sends a message to start the applet.
Definition: kjavaappletcontext.cpp:121
KJavaAppletContext::putMember
bool putMember(QStringList &args)
Definition: kjavaappletcontext.cpp:259
KJavaAppletContext::contextCount
static int contextCount
Definition: kjavaappletcontext.h:126
KJavaAppletContext::~KJavaAppletContext
~KJavaAppletContext()
Definition: kjavaappletcontext.cpp:65
KJavaAppletContext::callMember
bool callMember(QStringList &args, QStringList &ret_args)
Definition: kjavaappletcontext.cpp:264
KJavaAppletContext::destroy
void destroy(KJavaApplet *)
Sends a message to destroy the applet.
Definition: kjavaappletcontext.cpp:108
KJavaAppletContext::javaProcessExited
void javaProcessExited(int)
Definition: kjavaappletcontext.cpp:243
KJavaAppletContext::create
bool create(KJavaApplet *)
Sends a message to create the applet.
Definition: kjavaappletcontext.cpp:90
KJavaAppletContext::registerApplet
void registerApplet(KJavaApplet *)
registers applet
Definition: kjavaappletcontext.cpp:82
KJavaAppletContext::appletLoaded
void appletLoaded()
Signals the KHTML Part an applet is loaded.
KJavaAppletContext::KJavaAppletContext
KJavaAppletContext()
Definition: kjavaappletcontext.cpp:52
KJavaAppletContext::derefObject
void derefObject(QStringList &args)
Definition: kjavaappletcontext.cpp:269
KJavaAppletContext::contextId
int contextId()
Returns the ID of this context.
Definition: kjavaappletcontext.cpp:72
KJavaAppletContext::setContextId
void setContextId(int id)
Sets the ID of this context.
Definition: kjavaappletcontext.cpp:77
KJavaAppletContext::init
void init(KJavaApplet *)
Sends a message to initialize the applet.
Definition: kjavaappletcontext.cpp:116
KJavaAppletContext::received
void received(const QString &cmd, const QStringList &arg)
Definition: kjavaappletcontext.cpp:136
KJavaAppletContext::processCmd
void processCmd(QString cmd, QStringList args)
use this for applet call backs, the AppletServer calls this directly.
Definition: kjavaappletcontext.cpp:131
KJavaAppletContext::stop
void stop(KJavaApplet *)
Sends a message to stop the applet.
Definition: kjavaappletcontext.cpp:126
KJavaAppletContext::getMember
bool getMember(QStringList &args, QStringList &ret_args)
LiveConnect functions.
Definition: kjavaappletcontext.cpp:254
KJavaAppletContext::server
KJavaAppletServer * server
Definition: kjavaappletcontext.h:129
KJavaAppletContext::showStatus
void showStatus(const QString &txt)
Signals the KHMTL Part to show this as the status message.
KJavaAppletServer::javaProcess
KJavaProcess * javaProcess()
Definition: kjavaappletserver.h:135
KJavaAppletServer::freeJavaServer
static void freeJavaServer()
When you are done using your reference to the AppletServer, you must dereference it by calling freeJa...
Definition: kjavaappletserver.cpp:190
KJavaAppletServer::callMember
bool callMember(QStringList &args, QStringList &ret_args)
Definition: kjavaappletserver.cpp:763
KJavaAppletServer::createContext
void createContext(int contextId, KJavaAppletContext *context)
Create an applet context with the specified id.
Definition: kjavaappletserver.cpp:316
KJavaAppletServer::allocateJavaServer
static KJavaAppletServer * allocateJavaServer()
A factory method that returns the default server.
Definition: kjavaappletserver.cpp:178
KJavaAppletServer::derefObject
void derefObject(QStringList &args)
Definition: kjavaappletserver.cpp:773
KJavaAppletServer::putMember
bool putMember(QStringList &args)
Definition: kjavaappletserver.cpp:752
KJavaAppletServer::createApplet
bool createApplet(int contextId, int appletId, const QString &name, const QString &clazzName, const QString &baseURL, const QString &user, const QString &password, const QString &authname, const QString &codeBase, const QString &jarFile, QSize size, const QMap< QString, QString > &params, const QString &windowTitle)
Create an applet in the specified context with the specified id.
Definition: kjavaappletserver.cpp:339
KJavaAppletServer::destroyApplet
void destroyApplet(int contextId, int appletId)
Destroy an applet in the specified context with the specified id.
Definition: kjavaappletserver.cpp:407
KJavaAppletServer::initApplet
void initApplet(int contextId, int appletId)
This should be called by the KJavaAppletWidget.
Definition: kjavaappletserver.cpp:397
KJavaAppletServer::startApplet
void startApplet(int contextId, int appletId)
Start the specified applet.
Definition: kjavaappletserver.cpp:417
KJavaAppletServer::stopApplet
void stopApplet(int contextId, int appletId)
Stop the specified applet.
Definition: kjavaappletserver.cpp:427
KJavaAppletServer::getMember
bool getMember(QStringList &args, QStringList &ret_args)
Definition: kjavaappletserver.cpp:742
KJavaAppletServer::destroyContext
void destroyContext(int contextId)
Destroy the applet context with the specified id.
Definition: kjavaappletserver.cpp:328
KJavaApplet
Definition: kjavaapplet.h:51
KJavaApplet::authName
const QString & authName() const
Definition: kjavaapplet.h:222
KJavaApplet::resizeAppletWidget
void resizeAppletWidget(int width, int height)
Interface for applets to resize themselves.
Definition: kjavaapplet.cpp:148
KJavaApplet::password
const QString & password() const
Definition: kjavaapplet.h:216
KJavaApplet::user
const QString & user() const
Definition: kjavaapplet.h:210
KJavaApplet::archives
QString & archives()
Get the list of Archives that should be searched for class files and other resources.
Definition: kjavaapplet.cpp:143
KJavaApplet::getWindowName
QString & getWindowName()
Get the window title this applet should use.
Definition: kjavaapplet.cpp:170
KJavaApplet::appletClass
QString & appletClass()
Get the name of the Class file the applet should run.
Definition: kjavaapplet.cpp:88
KJavaApplet::jsData
void jsData(const QStringList &args)
JavaScript coming from Java.
Definition: kjavaapplet.h:237
KJavaApplet::appletId
int appletId()
Returns the unique ID this applet is given.
Definition: kjavaapplet.cpp:202
KJavaApplet::size
QSize size()
Get the size of the applet.
Definition: kjavaapplet.cpp:133
KJavaApplet::setFailed
void setFailed()
Definition: kjavaapplet.cpp:267
KJavaApplet::baseURL
QString & baseURL()
get the Base URL of the document embedding the applet
Definition: kjavaapplet.cpp:113
KJavaApplet::INITIALIZED
@ INITIALIZED
Definition: kjavaapplet.h:61
KJavaApplet::stateChange
void stateChange(const int newState)
called from the protocol engine changes the status according to the one on the java side.
Definition: kjavaapplet.cpp:212
KJavaApplet::appletName
QString & appletName()
Get the name the applet should be called in its context.
Definition: kjavaapplet.cpp:175
KJavaApplet::getParams
QMap< QString, QString > & getParams()
Get a reference to the Parameters and their values.
Definition: kjavaapplet.cpp:103
KJavaApplet::codeBase
QString & codeBase()
Get the codebase of the applet classes.
Definition: kjavaapplet.cpp:123
KJavaApplet::setAppletId
void setAppletId(int id)
Set the applet ID.
Definition: kjavaapplet.cpp:207
QMap
QObject
kDebug
#define kDebug
kWarning
#define kWarning
kdebug.h
d
#define d
Definition: khtmlfind.cpp:42
kjavaapplet.h
AppletMap
QMap< int, QPointer< KJavaApplet > > AppletMap
Definition: kjavaappletcontext.cpp:37
DEBUGAREA
#define DEBUGAREA
Definition: kjavaappletcontext.cpp:35
kjavaappletcontext.h
kjavaappletserver.h
kjavaprocess.h
klocale.h
kmessagebox.h
ok
KGuiItem ok()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal