1 /* This file is part of the KDE project
3 * Copyright (C) 2000 Richard Moore <rich@kde.org>
4 * 2000 Wynn Wilkes <wynnw@caldera.com>
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.
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.
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.
22 #include "kjavaappletserver.h"
24 #include "kjavaappletcontext.h"
25 #include "kjavaprocess.h"
26 #include "kjavadownloader.h"
32 #include <kconfiggroup.h>
34 #include <kparts/browserextension.h>
35 #include <kstandarddirs.h>
38 #include <kio/kprotocolmanager.h>
39 #include <ksslcertificate.h>
40 #include <ksslcertchain.h>
43 #include <QtCore/QTimer>
44 #include <QtCore/QPointer>
45 #include <QtCore/QDir>
46 #include <QtCore/QEventLoop>
47 #include <QtGui/QApplication>
48 #include <QtGui/QLabel>
49 #include <QtGui/QDialog>
50 #include <QtGui/QPushButton>
51 #include <QtGui/QLayout>
52 #include <QtCore/QRegExp>
56 #include <QtCore/QAbstractEventDispatcher>
58 #define KJAS_CREATE_CONTEXT (char)1
59 #define KJAS_DESTROY_CONTEXT (char)2
60 #define KJAS_CREATE_APPLET (char)3
61 #define KJAS_DESTROY_APPLET (char)4
62 #define KJAS_START_APPLET (char)5
63 #define KJAS_STOP_APPLET (char)6
64 #define KJAS_INIT_APPLET (char)7
65 #define KJAS_SHOW_DOCUMENT (char)8
66 #define KJAS_SHOW_URLINFRAME (char)9
67 #define KJAS_SHOW_STATUS (char)10
68 #define KJAS_RESIZE_APPLET (char)11
69 #define KJAS_GET_URLDATA (char)12
70 #define KJAS_URLDATA (char)13
71 #define KJAS_SHUTDOWN_SERVER (char)14
72 #define KJAS_JAVASCRIPT_EVENT (char)15
73 #define KJAS_GET_MEMBER (char)16
74 #define KJAS_CALL_MEMBER (char)17
75 #define KJAS_PUT_MEMBER (char)18
76 #define KJAS_DEREF_OBJECT (char)19
77 #define KJAS_AUDIOCLIP_PLAY (char)20
78 #define KJAS_AUDIOCLIP_LOOP (char)21
79 #define KJAS_AUDIOCLIP_STOP (char)22
80 #define KJAS_APPLET_STATE (char)23
81 #define KJAS_APPLET_FAILED (char)24
82 #define KJAS_DATA_COMMAND (char)25
83 #define KJAS_PUT_URLDATA (char)26
84 #define KJAS_PUT_DATA (char)27
85 #define KJAS_SECURITY_CONFIRM (char)28
86 #define KJAS_SHOW_CONSOLE (char)29
91 typedef QMap
< int, KJavaKIOJob
* > KIOJobMap
;
92 typedef QMap
< int, JSStackFrame
* > JSStack
;
96 JSStackFrame(JSStack
& stack
, QStringList
& a
)
97 : jsstack(stack
), args(a
), ticket(counter
++), ready(false), exit (false) {
98 jsstack
.insert( ticket
, this );
101 jsstack
.remove( ticket
);
111 int JSStackFrame::counter
= 0;
113 class KJavaAppletServerPrivate
115 friend class KJavaAppletServer
;
117 KJavaAppletServerPrivate() : kssl( 0L ) {}
118 ~KJavaAppletServerPrivate() {
122 QMap
< int, QPointer
<KJavaAppletContext
> > contexts
;
126 bool javaProcessFailed
;
129 //int locked_context;
130 //QValueList<QByteArray> java_requests;
133 static KJavaAppletServer
* self
= 0;
135 KJavaAppletServer::KJavaAppletServer()
136 : d(new KJavaAppletServerPrivate
)
138 process
= new KJavaProcess();
140 connect( process
, SIGNAL(received(const QByteArray
&)),
141 this, SLOT(slotJavaRequest(const QByteArray
&)) );
143 setupJava( process
);
145 if( process
->startJava() ) {
146 d
->appletLabel
= i18n( "Loading Applet" );
147 d
->javaProcessFailed
= false;
150 d
->appletLabel
= i18n( "Error: java executable not found" );
151 d
->javaProcessFailed
= true;
155 KJavaAppletServer::~KJavaAppletServer()
163 QString
KJavaAppletServer::getAppletLabel()
166 return self
->appletLabel();
171 QString
KJavaAppletServer::appletLabel()
173 return d
->appletLabel
;
176 KJavaAppletServer
* KJavaAppletServer::allocateJavaServer()
180 self
= new KJavaAppletServer();
181 self
->d
->counter
= 0;
184 ++(self
->d
->counter
);
188 void KJavaAppletServer::freeJavaServer()
190 --(self
->d
->counter
);
192 if( self
->d
->counter
== 0 )
194 //instead of immediately quitting here, set a timer to kill us
195 //if there are still no servers- give us one minute
196 //this is to prevent repeated loading and unloading of the jvm
197 KConfig
config( "konquerorrc" );
198 KConfigGroup group
= config
.group( "Java/JavaScript Settings" );
199 if( group
.readEntry( "ShutdownAppletServer", true ) )
201 const int value
= group
.readEntry( "AppletServerTimeout", 60 );
202 QTimer::singleShot( value
*1000, self
, SLOT( checkShutdown() ) );
207 void KJavaAppletServer::checkShutdown()
209 if( self
->d
->counter
== 0 )
216 void KJavaAppletServer::setupJava( KJavaProcess
*p
)
218 KConfig
configFile ( "konquerorrc" );
219 KConfigGroup
config(&configFile
, "Java/JavaScript Settings" );
221 QString jvm_path
= "java";
223 QString jPath
= config
.readPathEntry( "JavaPath", QString() );
224 if ( !jPath
.isEmpty() && jPath
!= "java" )
226 // Cut off trailing slash if any
227 if( jPath
[jPath
.length()-1] == '/' )
228 jPath
.remove(jPath
.length()-1, 1);
231 if( dir
.exists( "bin/java" ) )
233 jvm_path
= jPath
+ "/bin/java";
235 else if (dir
.exists( "/jre/bin/java" ) )
237 jvm_path
= jPath
+ "/jre/bin/java";
239 else if( QFile::exists(jPath
) )
241 //check here to see if they entered the whole path the java exe
246 //check to see if jvm_path is valid and set d->appletLabel accordingly
247 p
->setJVMPath( jvm_path
);
249 // Prepare classpath variable
250 QString kjava_class
= KStandardDirs::locate("data", "kjava/kjava.jar");
251 kDebug(6100) << "kjava_class = " << kjava_class
;
252 if( kjava_class
.isNull() ) // Should not happen
255 QDir
dir( kjava_class
);
257 kDebug(6100) << "dir = " << dir
.absolutePath();
259 const QStringList entries
= dir
.entryList(QDir::nameFiltersFromString( "*.jar" ));
260 kDebug(6100) << "entries = " << entries
.join( ":" );
264 QStringList::ConstIterator it
= entries
.begin();
265 const QStringList::ConstIterator itEnd
= entries
.end();
266 for( ; it
!= itEnd
; ++it
)
268 if( !classes
.isEmpty() )
270 classes
+= dir
.absoluteFilePath( *it
);
273 p
->setClasspath( classes
);
275 // Fix all the extra arguments
276 const QString extraArgs
= config
.readEntry( "JavaArgs" );
277 p
->setExtraArgs( extraArgs
);
279 if( config
.readEntry( "UseSecurityManager", true ) )
281 QString class_file
= KStandardDirs::locate( "data", "kjava/kjava.policy" );
282 p
->setSystemProperty( "java.security.policy", class_file
);
284 p
->setSystemProperty( "java.security.manager",
285 "org.kde.kjas.server.KJASSecurityManager" );
288 d
->useKIO
= config
.readEntry("UseKio", false);
291 p
->setSystemProperty( "kjas.useKio", QString() );
294 //check for http proxies...
295 if( KProtocolManager::useProxy() )
297 // only proxyForUrl honors automatic proxy scripts
298 // we do not know the applet url here so we just use a dummy url
299 // this is a workaround for now
301 const KUrl
dummyURL( "http://www.kde.org/" );
302 const QString httpProxy
= KProtocolManager::proxyForUrl(dummyURL
);
303 kDebug(6100) << "httpProxy is " << httpProxy
;
305 const KUrl
url( httpProxy
);
306 p
->setSystemProperty( "http.proxyHost", url
.host() );
307 p
->setSystemProperty( "http.proxyPort", QString::number( url
.port() ) );
310 //set the main class to run
311 p
->setMainClass( "org.kde.kjas.server.Main" );
314 void KJavaAppletServer::createContext( int contextId
, KJavaAppletContext
* context
)
316 // kDebug(6100) << "createContext: " << contextId;
317 if ( d
->javaProcessFailed
) return;
319 d
->contexts
.insert( contextId
, context
);
322 args
.append( QString::number( contextId
) );
323 process
->send( KJAS_CREATE_CONTEXT
, args
);
326 void KJavaAppletServer::destroyContext( int contextId
)
328 // kDebug(6100) << "destroyContext: " << contextId;
329 if ( d
->javaProcessFailed
) return;
330 d
->contexts
.remove( contextId
);
333 args
.append( QString::number( contextId
) );
334 process
->send( KJAS_DESTROY_CONTEXT
, args
);
337 bool KJavaAppletServer::createApplet( int contextId
, int appletId
,
338 const QString
& name
, const QString
& clazzName
,
339 const QString
& baseURL
, const QString
& user
,
340 const QString
& password
, const QString
& authname
,
341 const QString
& codeBase
, const QString
& jarFile
,
342 QSize size
, const QMap
<QString
,QString
>& params
,
343 const QString
& windowTitle
)
345 // kDebug(6100) << "createApplet: contextId = " << contextId << endl
346 // << " appletId = " << appletId << endl
347 // << " name = " << name << endl
348 // << " clazzName = " << clazzName << endl
349 // << " baseURL = " << baseURL << endl
350 // << " codeBase = " << codeBase << endl
351 // << " jarFile = " << jarFile << endl
352 // << " width = " << size.width() << endl
353 // << " height = " << size.height() << endl;
355 if ( d
->javaProcessFailed
) return false;
358 args
.append( QString::number( contextId
) );
359 args
.append( QString::number( appletId
) );
361 //it's ok if these are empty strings, I take care of it later...
363 args
.append( clazzName
);
364 args
.append( baseURL
);
366 args
.append( password
);
367 args
.append( authname
);
368 args
.append( codeBase
);
369 args
.append( jarFile
);
371 args
.append( QString::number( size
.width() ) );
372 args
.append( QString::number( size
.height() ) );
374 args
.append( windowTitle
);
376 //add on the number of parameter pairs...
377 const int num
= params
.count();
378 const QString num_params
= QString("%1").arg( num
, 8 );
379 args
.append( num_params
);
381 QMap
< QString
, QString
>::ConstIterator it
= params
.begin();
382 const QMap
< QString
, QString
>::ConstIterator itEnd
= params
.end();
384 for( ; it
!= itEnd
; ++it
)
386 args
.append( it
.key() );
387 args
.append( it
.value() );
390 process
->send( KJAS_CREATE_APPLET
, args
);
395 void KJavaAppletServer::initApplet( int contextId
, int appletId
)
397 if ( d
->javaProcessFailed
) return;
399 args
.append( QString::number( contextId
) );
400 args
.append( QString::number( appletId
) );
402 process
->send( KJAS_INIT_APPLET
, args
);
405 void KJavaAppletServer::destroyApplet( int contextId
, int appletId
)
407 if ( d
->javaProcessFailed
) return;
409 args
.append( QString::number(contextId
) );
410 args
.append( QString::number(appletId
) );
412 process
->send( KJAS_DESTROY_APPLET
, args
);
415 void KJavaAppletServer::startApplet( int contextId
, int appletId
)
417 if ( d
->javaProcessFailed
) return;
419 args
.append( QString::number(contextId
) );
420 args
.append( QString::number(appletId
) );
422 process
->send( KJAS_START_APPLET
, args
);
425 void KJavaAppletServer::stopApplet( int contextId
, int appletId
)
427 if ( d
->javaProcessFailed
) return;
429 args
.append( QString::number(contextId
) );
430 args
.append( QString::number(appletId
) );
432 process
->send( KJAS_STOP_APPLET
, args
);
435 void KJavaAppletServer::showConsole() {
436 if ( d
->javaProcessFailed
) return;
438 process
->send( KJAS_SHOW_CONSOLE
, args
);
441 void KJavaAppletServer::sendURLData( int loaderID
, int code
, const QByteArray
& data
)
444 args
.append( QString::number(loaderID
) );
445 args
.append( QString::number(code
) );
447 process
->send( KJAS_URLDATA
, args
, data
);
450 void KJavaAppletServer::removeDataJob( int loaderID
)
452 const KIOJobMap::iterator it
= d
->kiojobs
.find( loaderID
);
453 if (it
!= d
->kiojobs
.end()) {
454 it
.value()->deleteLater();
455 d
->kiojobs
.erase( it
);
459 void KJavaAppletServer::quit()
461 const QStringList args
;
463 process
->send( KJAS_SHUTDOWN_SERVER
, args
);
464 process
->waitForFinished( 10000 );
467 void KJavaAppletServer::slotJavaRequest( const QByteArray
& qb
)
469 // qb should be one command only without the length string,
470 // we parse out the command and it's meaning here...
474 const int qb_size
= qb
.size();
476 //get the command code
477 const char cmd_code
= qb
[ index
++ ];
478 ++index
; //skip the next sep
482 while( qb
[index
] != 0 && index
< qb_size
)
484 contextID
+= qb
[ index
++ ];
487 const int ID_num
= contextID
.toInt( &ok
); // context id or kio job id
488 /*if (d->locked_context > -1 &&
489 ID_num != d->locked_context &&
490 (cmd_code == KJAS_JAVASCRIPT_EVENT ||
491 cmd_code == KJAS_APPLET_STATE ||
492 cmd_code == KJAS_APPLET_FAILED))
494 / * Don't allow requests from other contexts if we're waiting
495 * on a return value that can trigger JavaScript events
497 d->java_requests.push_back(qb);
500 ++index
; //skip the sep
502 if (cmd_code
== KJAS_PUT_DATA
) {
503 // rest of the data is for kio put
505 KIOJobMap::iterator it
= d
->kiojobs
.find( ID_num
);
506 if (ok
&& it
!= d
->kiojobs
.end()) {
508 qba
= QByteArray::fromRawData(qb
.data() + index
, qb
.size() - index
- 1);
509 it
.value()->data(qba
);
510 qba
= QByteArray::fromRawData(qb
.data() + index
, qb
.size() - index
- 1);
512 kDebug(6100) << "PutData(" << ID_num
<< ") size=" << qb
.size() - index
;
514 kError(6100) << "PutData error " << ok
<< endl
;
517 //now parse out the arguments
518 while( index
< qb_size
)
520 int sep_pos
= qb
.indexOf( (char) 0, index
);
522 kError(6100) << "Missing separation byte" << endl
;
525 //kDebug(6100) << "KJavaAppletServer::slotJavaRequest: "<< QString::fromLocal8Bit( qb.data() + index, sep_pos - index );
526 args
.append( QString::fromLocal8Bit( qb
.data() + index
, sep_pos
- index
) );
527 index
= sep_pos
+ 1; //skip the sep
529 //here I should find the context and call the method directly
530 //instead of emitting signals
533 case KJAS_SHOW_DOCUMENT
:
534 cmd
= QLatin1String( "showdocument" );
537 case KJAS_SHOW_URLINFRAME
:
538 cmd
= QLatin1String( "showurlinframe" );
541 case KJAS_SHOW_STATUS
:
542 cmd
= QLatin1String( "showstatus" );
545 case KJAS_RESIZE_APPLET
:
546 cmd
= QLatin1String( "resizeapplet" );
549 case KJAS_GET_URLDATA
:
550 if (ok
&& !args
.empty() ) {
551 d
->kiojobs
.insert(ID_num
, new KJavaDownloader(ID_num
, args
.first()));
552 kDebug(6100) << "GetURLData(" << ID_num
<< ") url=" << args
.first();
554 kError(6100) << "GetURLData error " << ok
<< " args:" << args
.size() << endl
;
556 case KJAS_PUT_URLDATA
:
557 if (ok
&& !args
.empty()) {
558 KJavaUploader
* const job
= new KJavaUploader(ID_num
, args
.first());
559 d
->kiojobs
.insert(ID_num
, job
);
561 kDebug(6100) << "PutURLData(" << ID_num
<< ") url=" << args
.first();
563 kError(6100) << "PutURLData error " << ok
<< " args:" << args
.size() << endl
;
565 case KJAS_DATA_COMMAND
:
566 if (ok
&& !args
.empty()) {
567 const int cmd
= args
.first().toInt( &ok
);
568 KIOJobMap::iterator it
= d
->kiojobs
.find( ID_num
);
569 if (ok
&& it
!= d
->kiojobs
.end())
570 it
.value()->jobCommand( cmd
);
571 kDebug(6100) << "KIO Data command: " << ID_num
<< " " << args
.first();
573 kError(6100) << "KIO Data command error " << ok
<< " args:" << args
.size() << endl
;
575 case KJAS_JAVASCRIPT_EVENT
:
576 cmd
= QLatin1String( "JS_Event" );
579 kDebug(6100) << "Javascript request: "<< contextID
580 << " code: " << args
[0] << endl
;
582 kError(6100) << "Expected args not to be empty!" << endl
;
586 case KJAS_GET_MEMBER
:
587 case KJAS_PUT_MEMBER
:
588 case KJAS_CALL_MEMBER
: {
590 const int ticket
= args
[0].toInt();
591 JSStack::iterator it
= d
->jsstack
.find(ticket
);
592 if (it
!= d
->jsstack
.end()) {
593 kDebug(6100) << "slotJavaRequest: " << ticket
;
595 it
.value()->args
.operator=(args
); // just in case ..
596 it
.value()->ready
= true;
597 it
.value()->exit
= true;
599 kDebug(6100) << "Error: Missed return member data";
601 kError(6100) << "Expected args not to be empty!" << endl
;
605 case KJAS_AUDIOCLIP_PLAY
:
606 cmd
= QLatin1String( "audioclip_play" );
608 kDebug(6100) << "Audio Play: url=" << args
[0];
610 kError(6100) << "Expected args not to be empty!" << endl
;
613 case KJAS_AUDIOCLIP_LOOP
:
614 cmd
= QLatin1String( "audioclip_loop" );
616 kDebug(6100) << "Audio Loop: url=" << args
[0];
618 kError(6100) << "Expected args not to be empty!" << endl
;
621 case KJAS_AUDIOCLIP_STOP
:
622 cmd
= QLatin1String( "audioclip_stop" );
624 kDebug(6100) << "Audio Stop: url=" << args
[0];
626 kError(6100) << "Expected args not to be empty!" << endl
;
629 case KJAS_APPLET_STATE
:
631 kDebug(6100) << "Applet State Notification for Applet " << args
[0] << ". New state=" << args
[1];
633 kError(6100) << "Expected args not to be empty!" << endl
;
635 cmd
= QLatin1String( "AppletStateNotification" );
637 case KJAS_APPLET_FAILED
:
639 kDebug(6100) << "Applet " << args
[0] << " Failed: " << args
[1];
641 kError(6100) << "Expected args not to be empty!" << endl
;
643 cmd
= QLatin1String( "AppletFailed" );
645 case KJAS_SECURITY_CONFIRM
: {
646 if (KSSL::doesSSLWork() && !d
->kssl
)
649 QString
answer( "invalid" );
653 } else if (args
.size() > 2) {
654 const int certsnr
= args
[1].toInt();
655 Q_ASSERT(args
.size() > certsnr
+ 1);
657 QList
<KSSLCertificate
*> certs
;
658 for (int i
= certsnr
- 1; i
>= 0; --i
) {
659 const QByteArray
&arg
= args
[i
+ 2].toAscii();
660 KSSLCertificate
* cert
= KSSLCertificate::fromString(arg
.constData());
663 if (cert
->isSigner())
664 text
+= i18n("Signed by (validation: %1)", KSSLCertificate::verifyText(cert
->validate()));
666 text
+= i18n("Certificate (validation: %1)", KSSLCertificate::verifyText(cert
->validate()));
668 QString subject
= cert
->getSubject() + QChar('\n');
669 QRegExp
reg(QString("/[A-Z]+="));
671 while ((pos
= subject
.indexOf(reg
, pos
)) > -1)
672 subject
.replace(pos
, 1, QString("\n "));
673 text
+= subject
.mid(1);
676 kDebug(6100) << "Security confirm " << args
.first() << certs
.count();
677 if ( !certs
.isEmpty() ) {
679 chain
.setChain( certs
);
680 if ( chain
.isValid() )
681 answer
= PermissionDialog( qApp
->activeWindow() ).exec( text
, args
[0] );
685 sl
.push_front( answer
);
686 sl
.push_front( QString::number(ID_num
) );
687 process
->send( KJAS_SECURITY_CONFIRM
, sl
);
698 kError(6100) << "could not parse out contextID to call command on" << endl
;
702 KJavaAppletContext
* const context
= d
->contexts
[ ID_num
];
704 context
->processCmd( cmd
, args
);
705 else if (cmd
!= "AppletStateNotification")
706 kError(6100) << "no context object for this id" << endl
;
709 void KJavaAppletServer::killTimers()
711 QAbstractEventDispatcher::instance()->unregisterTimers(this);
714 void KJavaAppletServer::endWaitForReturnData() {
715 kDebug(6100) << "KJavaAppletServer::endWaitForReturnData";
717 JSStack::iterator it
= d
->jsstack
.begin();
718 JSStack::iterator itEnd
= d
->jsstack
.end();
719 for (; it
!= itEnd
; ++it
)
720 it
.value()->exit
= true;
723 void KJavaAppletServer::timerEvent(QTimerEvent
*) {
724 endWaitForReturnData();
725 kDebug(6100) << "KJavaAppletServer::timerEvent timeout";
728 void KJavaAppletServer::waitForReturnData(JSStackFrame
* frame
) {
729 kDebug(6100) << ">KJavaAppletServer::waitForReturnData";
732 while (!frame
->exit
) {
733 QAbstractEventDispatcher::instance()->processEvents (QEventLoop::AllEvents
| QEventLoop::WaitForMoreEvents
);
735 if (d
->jsstack
.size() <= 1)
737 kDebug(6100) << "<KJavaAppletServer::waitForReturnData stacksize:" << d
->jsstack
.size();
740 bool KJavaAppletServer::getMember(QStringList
& args
, QStringList
& ret_args
) {
741 JSStackFrame
frame( d
->jsstack
, ret_args
);
742 args
.push_front( QString::number(frame
.ticket
) );
744 process
->send( KJAS_GET_MEMBER
, args
);
745 waitForReturnData( &frame
);
750 bool KJavaAppletServer::putMember( QStringList
& args
) {
751 QStringList ret_args
;
752 JSStackFrame
frame( d
->jsstack
, ret_args
);
753 args
.push_front( QString::number(frame
.ticket
) );
755 process
->send( KJAS_PUT_MEMBER
, args
);
756 waitForReturnData( &frame
);
758 return frame
.ready
&& ret_args
.count() > 0 && ret_args
[0].toInt();
761 bool KJavaAppletServer::callMember(QStringList
& args
, QStringList
& ret_args
) {
762 JSStackFrame
frame( d
->jsstack
, ret_args
);
763 args
.push_front( QString::number(frame
.ticket
) );
765 process
->send( KJAS_CALL_MEMBER
, args
);
766 waitForReturnData( &frame
);
771 void KJavaAppletServer::derefObject( QStringList
& args
) {
772 process
->send( KJAS_DEREF_OBJECT
, args
);
775 bool KJavaAppletServer::usingKIO() {
780 PermissionDialog::PermissionDialog( QWidget
* parent
)
781 : QObject(parent
), m_button("no")
784 QString
PermissionDialog::exec( const QString
& cert
, const QString
& perm
) {
785 QPointer
<QDialog
> dialog
= new QDialog( static_cast<QWidget
*>(parent()) );
787 dialog
->setObjectName("PermissionDialog");
788 QSizePolicy
sizeplcy( QSizePolicy::Minimum
, QSizePolicy::Minimum
);
789 sizeplcy
.setHeightForWidth(dialog
->sizePolicy().hasHeightForWidth());
790 dialog
->setSizePolicy(sizeplcy
);
791 dialog
->setModal( true );
792 dialog
->setWindowTitle( i18n("Security Alert") );
794 QVBoxLayout
* const dialogLayout
= new QVBoxLayout( dialog
);
795 dialogLayout
->setMargin(11);
796 dialogLayout
->setSpacing(6);
797 dialogLayout
->setObjectName("dialogLayout");
799 dialogLayout
->addWidget( new QLabel( i18n("Do you grant Java applet with certificate(s):"), dialog
) );
800 dialogLayout
->addWidget( new QLabel( cert
, dialog
) );
801 dialogLayout
->addWidget( new QLabel( i18n("the following permission"), dialog
) );
802 dialogLayout
->addWidget( new QLabel( perm
, dialog
) );
803 QSpacerItem
* const spacer2
= new QSpacerItem( 20, 40, QSizePolicy::Minimum
, QSizePolicy::Expanding
);
804 dialogLayout
->addItem( spacer2
);
806 QHBoxLayout
* const buttonLayout
= new QHBoxLayout();
807 buttonLayout
->setMargin(0);
808 buttonLayout
->setSpacing(6);
809 buttonLayout
->setObjectName("buttonLayout");
811 QPushButton
* const no
= new QPushButton( i18n("&No"), dialog
);
812 no
->setDefault( true );
813 buttonLayout
->addWidget( no
);
815 QPushButton
* const reject
= new QPushButton( i18n("&Reject All"), dialog
);
816 buttonLayout
->addWidget( reject
);
818 QPushButton
* const yes
= new QPushButton( i18n("&Yes"), dialog
);
819 buttonLayout
->addWidget( yes
);
821 QPushButton
* const grant
= new QPushButton( i18n("&Grant All"), dialog
);
822 buttonLayout
->addWidget( grant
);
823 dialogLayout
->addLayout( buttonLayout
);
824 dialog
->resize( dialog
->minimumSizeHint() );
825 //clearWState( WState_Polished );
827 connect( no
, SIGNAL( clicked() ), this, SLOT( clicked() ) );
828 connect( reject
, SIGNAL( clicked() ), this, SLOT( clicked() ) );
829 connect( yes
, SIGNAL( clicked() ), this, SLOT( clicked() ) );
830 connect( grant
, SIGNAL( clicked() ), this, SLOT( clicked() ) );
838 PermissionDialog::~PermissionDialog()
841 void PermissionDialog::clicked()
843 m_button
= sender()->objectName();
844 static_cast<const QWidget
*>(sender())->parentWidget()->close();
847 #include "kjavaappletserver.moc"