• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.2 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 
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>
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Apr 16 2013 19:16:41 by doxygen 1.8.3.1 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.10.2 API Reference

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