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

KHTML

  • sources
  • kde-4.14
  • kdelibs
  • 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 
37 typedef QMap< int, QPointer<KJavaApplet> > AppletMap;
38 
39 // For future expansion
40 class KJavaAppletContextPrivate
41 {
42 friend class KJavaAppletContext;
43 private:
44  AppletMap applets;
45 };
46 
47 // Static Factory Functions
48 int KJavaAppletContext::contextCount = 0;
49 
50 /* Class Implementation
51  */
52 KJavaAppletContext::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 
65 KJavaAppletContext::~KJavaAppletContext()
66 {
67  server->destroyContext( id );
68  KJavaAppletServer::freeJavaServer();
69  delete d;
70 }
71 
72 int KJavaAppletContext::contextId()
73 {
74  return id;
75 }
76 
77 void KJavaAppletContext::setContextId( int _id )
78 {
79  id = _id;
80 }
81 
82 void KJavaAppletContext::registerApplet( KJavaApplet* applet )
83 {
84  static int appletId = 0;
85 
86  applet->setAppletId( ++appletId );
87  d->applets.insert( appletId, applet );
88 }
89 
90 bool 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 
108 void KJavaAppletContext::destroy( KJavaApplet* applet )
109 {
110  const int appletId = applet->appletId();
111  d->applets.remove( appletId );
112 
113  server->destroyApplet( id, appletId );
114 }
115 
116 void KJavaAppletContext::init( KJavaApplet* applet )
117 {
118  server->initApplet( id, applet->appletId() );
119 }
120 
121 void KJavaAppletContext::start( KJavaApplet* applet )
122 {
123  server->startApplet( id, applet->appletId() );
124 }
125 
126 void KJavaAppletContext::stop( KJavaApplet* applet )
127 {
128  server->stopApplet( id, applet->appletId() );
129 }
130 
131 void KJavaAppletContext::processCmd( QString cmd, QStringList args )
132 {
133  received( cmd, args );
134 }
135 
136 void 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 
243 void 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 
254 bool KJavaAppletContext::getMember(QStringList & args, QStringList & ret_args) {
255  args.push_front( QString::number(id) );
256  return server->getMember( args, ret_args );
257 }
258 
259 bool KJavaAppletContext::putMember( QStringList & args ) {
260  args.push_front( QString::number(id) );
261  return server->putMember( args );
262 }
263 
264 bool KJavaAppletContext::callMember(QStringList & args, QStringList &ret_args) {
265  args.push_front( QString::number(id) );
266  return server->callMember( args, ret_args );
267 }
268 
269 void KJavaAppletContext::derefObject( QStringList & args ) {
270  args.push_front( QString::number(id) );
271  server->derefObject( args );
272 }
273 
274 #include <kjavaappletcontext.moc>
KJavaAppletContext::appletLoaded
void appletLoaded()
Signals the KHTML Part an applet is loaded.
kjavaappletserver.h
kdebug.h
KJavaAppletContext::javaProcessExited
void javaProcessExited(int)
Definition: kjavaappletcontext.cpp:243
KJavaApplet::resizeAppletWidget
void resizeAppletWidget(int width, int height)
Interface for applets to resize themselves.
Definition: kjavaapplet.cpp:148
KJavaAppletContext::contextCount
static int contextCount
Definition: kjavaappletcontext.h:126
KJavaAppletContext::received
void received(const QString &cmd, const QStringList &arg)
Definition: kjavaappletcontext.cpp:136
KJavaAppletContext::setContextId
void setContextId(int id)
Sets the ID of this context.
Definition: kjavaappletcontext.cpp:77
KJavaApplet::appletName
QString & appletName()
Get the name the applet should be called in its context.
Definition: kjavaapplet.cpp:175
d
#define d
Definition: khtmlfind.cpp:42
KJavaAppletServer::createContext
void createContext(int contextId, KJavaAppletContext *context)
Create an applet context with the specified id.
Definition: kjavaappletserver.cpp:316
KJavaApplet::appletClass
QString & appletClass()
Get the name of the Class file the applet should run.
Definition: kjavaapplet.cpp:88
KJavaAppletContext::stop
void stop(KJavaApplet *)
Sends a message to stop the applet.
Definition: kjavaappletcontext.cpp:126
QMap
KJavaApplet::appletId
int appletId()
Returns the unique ID this applet is given.
Definition: kjavaapplet.cpp:202
DEBUGAREA
#define DEBUGAREA
Definition: kjavaappletcontext.cpp:35
kjavaapplet.h
KJavaApplet::setAppletId
void setAppletId(int id)
Set the applet ID.
Definition: kjavaapplet.cpp:207
QList::push_front
void push_front(const T &value)
kError
static QDebug kError(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KJavaAppletServer::stopApplet
void stopApplet(int contextId, int appletId)
Stop the specified applet.
Definition: kjavaappletserver.cpp:427
QString::remove
QString & remove(int position, int n)
KJavaApplet::getWindowName
QString & getWindowName()
Get the window title this applet should use.
Definition: kjavaapplet.cpp:170
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
klocale.h
KJavaAppletContext::start
void start(KJavaApplet *)
Sends a message to start the applet.
Definition: kjavaappletcontext.cpp:121
KJavaAppletContext::server
KJavaAppletServer * server
Definition: kjavaappletcontext.h:129
QRegExp
KJavaApplet::setFailed
void setFailed()
Definition: kjavaapplet.cpp:267
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
QString::number
QString number(int n, int base)
QList::count
int count(const T &value) const
KJavaApplet::jsData
void jsData(const QStringList &args)
JavaScript coming from Java.
Definition: kjavaapplet.h:237
KJavaApplet
Definition: kjavaapplet.h:50
KJavaAppletContext::destroy
void destroy(KJavaApplet *)
Sends a message to destroy the applet.
Definition: kjavaappletcontext.cpp:108
kjavaprocess.h
KJavaAppletServer::initApplet
void initApplet(int contextId, int appletId)
This should be called by the KJavaAppletWidget.
Definition: kjavaappletserver.cpp:397
QList::empty
bool empty() const
KJavaAppletContext::putMember
bool putMember(QStringList &args)
Definition: kjavaappletcontext.cpp:259
QList::pop_front
void pop_front()
KJavaApplet::authName
const QString & authName() const
Definition: kjavaapplet.h:222
KJavaAppletServer::derefObject
void derefObject(QStringList &args)
Definition: kjavaappletserver.cpp:773
QObject
KJavaApplet::archives
QString & archives()
Get the list of Archives that should be searched for class files and other resources.
Definition: kjavaapplet.cpp:143
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QList::first
T & first()
QString
KJavaAppletContext::derefObject
void derefObject(QStringList &args)
Definition: kjavaappletcontext.cpp:269
QStringList
KJavaAppletServer::putMember
bool putMember(QStringList &args)
Definition: kjavaappletserver.cpp:752
KJavaAppletServer::getMember
bool getMember(QStringList &args, QStringList &ret_args)
Definition: kjavaappletserver.cpp:742
KJavaApplet::baseURL
QString & baseURL()
get the Base URL of the document embedding the applet
Definition: kjavaapplet.cpp:113
ok
KGuiItem ok()
KJavaAppletContext::showDocument
void showDocument(const QString &url, const QString &target)
Signals the KHTML Part to show a url in a given target.
KJavaAppletServer::destroyContext
void destroyContext(int contextId)
Destroy the applet context with the specified id.
Definition: kjavaappletserver.cpp:328
KJavaApplet::size
QSize size()
Get the size of the applet.
Definition: kjavaapplet.cpp:133
KJavaApplet::user
const QString & user() const
Definition: kjavaapplet.h:210
KJavaAppletContext::init
void init(KJavaApplet *)
Sends a message to initialize the applet.
Definition: kjavaappletcontext.cpp:116
KJavaAppletContext::getMember
bool getMember(QStringList &args, QStringList &ret_args)
LiveConnect functions.
Definition: kjavaappletcontext.cpp:254
KJavaApplet::codeBase
QString & codeBase()
Get the codebase of the applet classes.
Definition: kjavaapplet.cpp:123
QLatin1String
KJavaAppletContext::~KJavaAppletContext
~KJavaAppletContext()
Definition: kjavaappletcontext.cpp:65
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
KJavaAppletContext::contextId
int contextId()
Returns the ID of this context.
Definition: kjavaappletcontext.cpp:72
kWarning
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KJavaAppletContext::processCmd
void processCmd(QString cmd, QStringList args)
use this for applet call backs, the AppletServer calls this directly.
Definition: kjavaappletcontext.cpp:131
KJavaAppletServer::startApplet
void startApplet(int contextId, int appletId)
Start the specified applet.
Definition: kjavaappletserver.cpp:417
KJavaAppletContext::KJavaAppletContext
KJavaAppletContext()
Definition: kjavaappletcontext.cpp:52
KJavaAppletContext::callMember
bool callMember(QStringList &args, QStringList &ret_args)
Definition: kjavaappletcontext.cpp:264
KJavaAppletContext
Definition: kjavaappletcontext.h:45
AppletMap
QMap< int, QPointer< KJavaApplet > > AppletMap
Definition: kjavaappletcontext.cpp:37
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
KJavaAppletContext::create
bool create(KJavaApplet *)
Sends a message to create the applet.
Definition: kjavaappletcontext.cpp:90
KJavaAppletContext::showStatus
void showStatus(const QString &txt)
Signals the KHMTL Part to show this as the status message.
kmessagebox.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KJavaApplet::getParams
QMap< QString, QString > & getParams()
Get a reference to the Parameters and their values.
Definition: kjavaapplet.cpp:103
KJavaAppletContext::registerApplet
void registerApplet(KJavaApplet *)
registers applet
Definition: kjavaappletcontext.cpp:82
KJavaApplet::password
const QString & password() const
Definition: kjavaapplet.h:216
KJavaAppletServer::allocateJavaServer
static KJavaAppletServer * allocateJavaServer()
A factory method that returns the default server.
Definition: kjavaappletserver.cpp:178
KJavaApplet::INITIALIZED
Definition: kjavaapplet.h:61
kjavaappletcontext.h
KJavaAppletServer::destroyApplet
void destroyApplet(int contextId, int appletId)
Destroy an applet in the specified context with the specified id.
Definition: kjavaappletserver.cpp:407
KJavaAppletServer::javaProcess
KJavaProcess * javaProcess()
Definition: kjavaappletserver.h:135
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:26:19 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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