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

KHTML

  • sources
  • kde-4.12
  • kdelibs
  • khtml
  • java
kjavaapplet.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 "kjavaappletwidget.h"
23 #include "kjavaappletcontext.h"
24 
25 #include <klocale.h>
26 #include <kdebug.h>
27 #include <kparts/browserextension.h>
28 
29 
30 
31 class KJavaAppletPrivate
32 {
33 public:
34  bool reallyExists;
35  bool failed;
36  QString className;
37  QString appName;
38  QString baseURL;
39  QString codeBase;
40  QString archives;
41  QSize size;
42  QString windowName;
43  KJavaApplet::AppletState state;
44 
45  KJavaAppletWidget* UIwidget;
46 };
47 
48 
49 KJavaApplet::KJavaApplet( KJavaAppletWidget* _parent,
50  KJavaAppletContext* _context )
51  : d(new KJavaAppletPrivate), params()
52 {
53 
54  d->UIwidget = _parent;
55  d->state = UNKNOWN;
56  d->failed = false;
57 
58  if( _context )
59  setAppletContext( _context );
60 
61  d->reallyExists = false;
62 }
63 
64 KJavaApplet::~KJavaApplet()
65 {
66  if ( d->reallyExists )
67  context->destroy( this );
68 
69  delete d;
70 }
71 
72 bool KJavaApplet::isCreated()
73 {
74  return d->reallyExists;
75 }
76 
77 void KJavaApplet::setAppletContext( KJavaAppletContext* _context )
78 {
79  context = _context;
80  context->registerApplet( this );
81 }
82 
83 void KJavaApplet::setAppletClass( const QString& _className )
84 {
85  d->className = _className;
86 }
87 
88 QString& KJavaApplet::appletClass()
89 {
90  return d->className;
91 }
92 
93 QString& KJavaApplet::parameter( const QString& name )
94 {
95  return params[ name ];
96 }
97 
98 void KJavaApplet::setParameter( const QString& name, const QString& value )
99 {
100  params.insert( name, value );
101 }
102 
103 QMap<QString,QString>& KJavaApplet::getParams()
104 {
105  return params;
106 }
107 
108 void KJavaApplet::setBaseURL( const QString& baseURL )
109 {
110  d->baseURL = baseURL;
111 }
112 
113 QString& KJavaApplet::baseURL()
114 {
115  return d->baseURL;
116 }
117 
118 void KJavaApplet::setCodeBase( const QString& codeBase )
119 {
120  d->codeBase = codeBase;
121 }
122 
123 QString& KJavaApplet::codeBase()
124 {
125  return d->codeBase;
126 }
127 
128 void KJavaApplet::setSize( QSize size )
129 {
130  d->size = size;
131 }
132 
133 QSize KJavaApplet::size()
134 {
135  return d->size;
136 }
137 
138 void KJavaApplet::setArchives( const QString& _archives )
139 {
140  d->archives = _archives;
141 }
142 
143 QString& KJavaApplet::archives()
144 {
145  return d->archives;
146 }
147 
148 void KJavaApplet::resizeAppletWidget( int width, int height )
149 {
150  kDebug(6100) << "KJavaApplet, id = " << id << ", ::resizeAppletWidget to " << width << ", " << height;
151 
152  QStringList sl;
153  sl.push_back( QString::number( 0 ) ); // applet itself has id 0
154  sl.push_back( QString( "eval" ) ); // evaluate next script
155  sl.push_back( QString::number( KParts::LiveConnectExtension::TypeString ) );
156  sl.push_back( QString( "this.setAttribute('WIDTH',%1);this.setAttribute('HEIGHT',%2)" ).arg( width ).arg( height ) );
157  jsData( sl );
158 }
159 
160 void KJavaApplet::setAppletName( const QString& name )
161 {
162  d->appName = name;
163 }
164 
165 void KJavaApplet::setWindowName( const QString& title )
166 {
167  d->windowName = title;
168 }
169 
170 QString& KJavaApplet::getWindowName()
171 {
172  return d->windowName;
173 }
174 
175 QString& KJavaApplet::appletName()
176 {
177  return d->appName;
178 }
179 
180 void KJavaApplet::create( )
181 {
182  if ( !context->create( this ) )
183  setFailed();
184  d->reallyExists = true;
185 }
186 
187 void KJavaApplet::init()
188 {
189  context->init( this );
190 }
191 
192 void KJavaApplet::start()
193 {
194  context->start( this );
195 }
196 
197 void KJavaApplet::stop()
198 {
199  context->stop( this );
200 }
201 
202 int KJavaApplet::appletId()
203 {
204  return id;
205 }
206 
207 void KJavaApplet::setAppletId( int _id )
208 {
209  id = _id;
210 }
211 
212 void KJavaApplet::stateChange( const int newStateInt ) {
213  AppletState newState = (AppletState)newStateInt;
214  bool ok = false;
215  if (d->failed) {
216  return;
217  }
218  switch ( newState ) {
219  case CLASS_LOADED:
220  ok = (d->state == UNKNOWN);
221  break;
222  case INSTANCIATED:
223  ok = (d->state == CLASS_LOADED);
224  if (ok) {
225  showStatus(i18n("Initializing Applet \"%1\"...", appletName()));
226  }
227  break;
228  case INITIALIZED:
229  ok = (d->state == INSTANCIATED);
230  if (ok) {
231  showStatus(i18n("Starting Applet \"%1\"...", appletName()));
232  start();
233  }
234  break;
235  case STARTED:
236  ok = (d->state == INITIALIZED || d->state == STOPPED);
237  if (ok) {
238  showStatus(i18n("Applet \"%1\" started", appletName()));
239  }
240  break;
241  case STOPPED:
242  ok = (d->state == INITIALIZED || d->state == STARTED);
243  if (ok) {
244  showStatus(i18n("Applet \"%1\" stopped", appletName()));
245  }
246  break;
247  case DESTROYED:
248  ok = true;
249  break;
250  default:
251  break;
252  }
253  if (ok) {
254  d->state = newState;
255  } else {
256  kError(6100) << "KJavaApplet::stateChange : don't want to switch from state "
257  << d->state << " to " << newState << endl;
258  }
259 }
260 
261 void KJavaApplet::showStatus(const QString &msg) {
262  QStringList args;
263  args << msg;
264  context->processCmd("showstatus", args);
265 }
266 
267 void KJavaApplet::setFailed() {
268  d->failed = true;
269 }
270 
271 bool KJavaApplet::isAlive() const {
272  return (
273  !d->failed
274  && d->state >= INSTANCIATED
275  && d->state < STOPPED
276  );
277 }
278 
279 KJavaApplet::AppletState KJavaApplet::state() const {
280  return d->state;
281 }
282 
283 bool KJavaApplet::failed() const {
284  return d->failed;
285 }
286 
287 #include "kjavaapplet.moc"
i18n
QString i18n(const char *text)
KJavaApplet::setWindowName
void setWindowName(const QString &title)
Set the window title for swallowing.
Definition: kjavaapplet.cpp:165
KJavaApplet::UNKNOWN
Definition: kjavaapplet.h:58
kdebug.h
KJavaApplet::resizeAppletWidget
void resizeAppletWidget(int width, int height)
Interface for applets to resize themselves.
Definition: kjavaapplet.cpp:148
KJavaApplet::appletName
QString & appletName()
Get the name the applet should be called in its context.
Definition: kjavaapplet.cpp:175
KJavaApplet::parameter
QString & parameter(const QString &name)
Look up the parameter value for the given Parameter.
Definition: kjavaapplet.cpp:93
d
#define d
Definition: khtmlfind.cpp:42
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
KJavaApplet::appletId
int appletId()
Returns the unique ID this applet is given.
Definition: kjavaapplet.cpp:202
KJavaApplet::setAppletId
void setAppletId(int id)
Set the applet ID.
Definition: kjavaapplet.cpp:207
kError
static QDebug kError(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KJavaApplet::isCreated
bool isCreated()
Returns status of applet- whether it's been created or not.
Definition: kjavaapplet.cpp:72
KJavaApplet::setAppletContext
void setAppletContext(KJavaAppletContext *_context)
Set the applet context'.
Definition: kjavaapplet.cpp:77
QString
KJavaApplet::getWindowName
QString & getWindowName()
Get the window title this applet should use.
Definition: kjavaapplet.cpp:170
KJavaAppletWidget
Definition: kjavaappletwidget.h:82
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
KJavaApplet::state
AppletState state() const
Definition: kjavaapplet.cpp:279
KJavaApplet::setFailed
void setFailed()
Definition: kjavaapplet.cpp:267
KJavaApplet::jsData
void jsData(const QStringList &args)
JavaScript coming from Java.
Definition: kjavaapplet.h:237
KJavaApplet::setAppletName
void setAppletName(const QString &name)
Set the name the applet should be called in its context.
Definition: kjavaapplet.cpp:160
KJavaApplet::failed
bool failed() const
Definition: kjavaapplet.cpp:283
KJavaAppletContext::destroy
void destroy(KJavaApplet *)
Sends a message to destroy the applet.
Definition: kjavaappletcontext.cpp:108
KJavaApplet::KJavaApplet
KJavaApplet(KJavaAppletWidget *_parent, KJavaAppletContext *_context=0)
Definition: kjavaapplet.cpp:49
KJavaApplet::STOPPED
Definition: kjavaapplet.h:63
QStringList
KJavaApplet::archives
QString & archives()
Get the list of Archives that should be searched for class files and other resources.
Definition: kjavaapplet.cpp:143
KJavaApplet::~KJavaApplet
~KJavaApplet()
Definition: kjavaapplet.cpp:64
KJavaApplet::AppletState
AppletState
Definition: kjavaapplet.h:57
KParts::LiveConnectExtension::TypeString
KJavaApplet::isAlive
bool isAlive() const
Definition: kjavaapplet.cpp:271
KJavaApplet::create
void create()
Send message to AppletServer to create this applet's frame to be swallowed and download the applet cl...
Definition: kjavaapplet.cpp:180
KJavaApplet::start
void start()
Run the applet.
Definition: kjavaapplet.cpp:192
KJavaApplet::setSize
void setSize(QSize size)
Set the size of the applet.
Definition: kjavaapplet.cpp:128
KJavaApplet::STARTED
Definition: kjavaapplet.h:62
kjavaappletwidget.h
KJavaApplet::baseURL
QString & baseURL()
get the Base URL of the document embedding the applet
Definition: kjavaapplet.cpp:113
ok
KGuiItem ok()
KJavaApplet::size
QSize size()
Get the size of the applet.
Definition: kjavaapplet.cpp:133
KJavaAppletContext::init
void init(KJavaApplet *)
Sends a message to initialize the applet.
Definition: kjavaappletcontext.cpp:116
KJavaApplet::codeBase
QString & codeBase()
Get the codebase of the applet classes.
Definition: kjavaapplet.cpp:123
KJavaApplet::setBaseURL
void setBaseURL(const QString &base)
Set the URL of the document embedding the applet.
Definition: kjavaapplet.cpp:108
KJavaApplet::DESTROYED
Definition: kjavaapplet.h:64
KJavaApplet::init
void init()
Send message to AppletServer to Initialize and show this applet.
Definition: kjavaapplet.cpp:187
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::processCmd
void processCmd(QString cmd, QStringList args)
use this for applet call backs, the AppletServer calls this directly.
Definition: kjavaappletcontext.cpp:131
QSize
KJavaApplet::setAppletClass
void setAppletClass(const QString &clazzName)
Specify the name of the class file to run.
Definition: kjavaapplet.cpp:83
browserextension.h
KJavaAppletContext
Definition: kjavaappletcontext.h:45
KJavaApplet::INSTANCIATED
Definition: kjavaapplet.h:60
KJavaApplet::setArchives
void setArchives(const QString &_archives)
Set the list of archives at the Applet's codebase to search in for class files and other resources...
Definition: kjavaapplet.cpp:138
KJavaApplet::stop
void stop()
Pause the applet.
Definition: kjavaapplet.cpp:197
KJavaAppletContext::create
bool create(KJavaApplet *)
Sends a message to create the applet.
Definition: kjavaappletcontext.cpp:90
KJavaApplet::setCodeBase
void setCodeBase(const QString &codeBase)
Set the codebase of the applet classes.
Definition: kjavaapplet.cpp:118
KJavaApplet::setParameter
void setParameter(const QString &name, const QString &value)
Specify a parameter to be passed to the applet.
Definition: kjavaapplet.cpp:98
KJavaApplet::getParams
QMap< QString, QString > & getParams()
Get a reference to the Parameters and their values.
Definition: kjavaapplet.cpp:103
KJavaApplet::CLASS_LOADED
Definition: kjavaapplet.h:59
KJavaAppletContext::registerApplet
void registerApplet(KJavaApplet *)
registers applet
Definition: kjavaappletcontext.cpp:82
KJavaApplet::INITIALIZED
Definition: kjavaapplet.h:61
QMap< QString, QString >
kjavaappletcontext.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:51:21 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • 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