2 * Copyright (c) Martin R. Jones 1996
3 * Copyright (c) Bernd Wuebben 1998
5 * Copyright (c) Torben Weis 1998
6 * KControl port & modifications
8 * Copyright (c) David Faure 1998
9 * End of the KControl port, added 'kfmclient configure' call.
11 * Copyright (c) Kalle Dalheimer 2000
12 * New configuration scheme for Java/JavaScript
14 * Copyright (c) Daniel Molkentin 2000
15 * Redesign and cleanup
17 * Copyright (c) Leo Savernik 2002-2003
18 * Big changes to accommodate per-domain settings
26 #include <QtGui/QFormLayout>
27 #include <QtGui/QGroupBox>
28 #include <QtGui/QLabel>
29 #include <QtGui/QTreeWidget>
32 #include <config-apps.h>
33 #include <kurlrequester.h>
35 #include <klineedit.h>
37 #include <khtml_settings.h>
38 #include <knuminput.h>
43 #include "policydlg.h"
45 // == class JavaPolicies =====
47 JavaPolicies::JavaPolicies(KSharedConfig::Ptr config
, const QString
&group
, bool global
,
48 const QString
&domain
) :
49 Policies(config
,group
,global
,domain
,"java.","EnableJava") {
53 JavaPolicies::JavaPolicies() : Policies(0,QString(),false,
54 QString(),QString(),QString()) {
58 JavaPolicies::~JavaPolicies() {
61 // == class KJavaOptions =====
63 KJavaOptions::KJavaOptions( KSharedConfig::Ptr config
, const QString
&group
,
64 const KComponentData
&componentData
, QWidget
*parent
)
65 : KCModule( componentData
, parent
),
66 _removeJavaScriptDomainAdvice(false),
69 java_global_policies(config
,group
,true),
70 _removeJavaDomainSettings(false)
72 QVBoxLayout
* toplevel
= new QVBoxLayout( this );
73 toplevel
->setMargin(KDialog::marginHint());
74 toplevel
->setSpacing(KDialog::spacingHint());
77 /***************************************************************************
78 ********************* Global Settings *************************************
79 **************************************************************************/
80 enableJavaGloballyCB
= new QCheckBox( i18n( "Enable Ja&va globally" ), this );
81 connect( enableJavaGloballyCB
, SIGNAL( clicked() ), this, SLOT( slotChanged() ) );
82 connect( enableJavaGloballyCB
, SIGNAL( clicked() ), this, SLOT( toggleJavaControls() ) );
83 toplevel
->addWidget(enableJavaGloballyCB
);
86 /***************************************************************************
87 ***************** Domain Specific Settings ********************************
88 **************************************************************************/
89 domainSpecific
= new JavaDomainListView(m_pConfig
,m_groupname
,this,this);
90 connect(domainSpecific
,SIGNAL(changed(bool)),SLOT(slotChanged()));
91 toplevel
->addWidget( domainSpecific
, 2 );
93 /***************************************************************************
94 ***************** Java Runtime Settings ***********************************
95 **************************************************************************/
96 QGroupBox
* javartGB
= new QGroupBox( i18n( "Java Runtime Settings" ), this );
97 QFormLayout
* laygroup1
= new QFormLayout(javartGB
);
98 laygroup1
->setSpacing(KDialog::spacingHint());
99 toplevel
->addWidget( javartGB
);
101 javaSecurityManagerCB
= new QCheckBox( i18n("&Use security manager" ), this);
102 laygroup1
->addRow( javaSecurityManagerCB
);
103 connect( javaSecurityManagerCB
, SIGNAL(toggled( bool )), this, SLOT(slotChanged()) );
105 useKioCB
= new QCheckBox( i18n("Use &KIO"), this );
106 laygroup1
->addRow( useKioCB
);
107 connect( useKioCB
, SIGNAL(toggled( bool )), this, SLOT(slotChanged()) );
109 enableShutdownCB
= new QCheckBox( i18n("Shu&tdown applet server when inactive for more than"), this);
110 connect( enableShutdownCB
, SIGNAL(toggled( bool )), this, SLOT(slotChanged()) );
111 connect( enableShutdownCB
, SIGNAL(clicked()), this, SLOT(toggleJavaControls()) );
112 KHBox
* secondsHB
= new KHBox( javartGB
);
113 laygroup1
->addWidget( secondsHB
);
114 serverTimeoutSB
= new KIntNumInput( secondsHB
);
115 serverTimeoutSB
->setRange( 0, 1000, 5 );
116 serverTimeoutSB
->setSuffix(i18n(" sec"));
117 connect(serverTimeoutSB
, SIGNAL(valueChanged(int)),this,SLOT(slotChanged()));
118 laygroup1
->addRow( enableShutdownCB
, serverTimeoutSB
);
120 pathED
= new KUrlRequester(this);
121 connect( pathED
, SIGNAL(textChanged( const QString
& )), this, SLOT(slotChanged()) );
122 laygroup1
->addRow(i18n( "&Path to Java executable, or 'java':" ), pathED
);
124 addArgED
= new QLineEdit( this );
125 connect( addArgED
, SIGNAL(textChanged( const QString
& )), this, SLOT(slotChanged()) );
126 laygroup1
->addRow(i18n( "Additional Java a&rguments:" ),addArgED
);
128 /***************************************************************************
129 ********************** WhatsThis? items ***********************************
130 **************************************************************************/
131 enableJavaGloballyCB
->setWhatsThis( i18n("Enables the execution of scripts written in Java "
132 "that can be contained in HTML pages. "
133 "Note that, as with any browser, enabling active contents can be a security problem.") );
134 QString wtstr
= i18n("<p>This box contains the domains and hosts you have set "
135 "a specific Java policy for. This policy will be used "
136 "instead of the default policy for enabling or disabling Java applets on pages sent by these "
137 "domains or hosts.</p><p>Select a policy and use the controls on "
138 "the right to modify it.</p>");
139 domainSpecific
->listView()->setWhatsThis( wtstr
);
141 domainSpecific
->importButton()->setWhatsThis( i18n("Click this button to choose the file that contains "
142 "the Java policies. These policies will be merged "
143 "with the existing ones. Duplicate entries are ignored.") );
144 domainSpecific
->exportButton()->setWhatsThis( i18n("Click this button to save the Java policy to a zipped "
145 "file. The file, named <b>java_policy.tgz</b>, will be "
146 "saved to a location of your choice." ) );
148 domainSpecific
->setWhatsThis( i18n("Here you can set specific Java policies for any particular "
149 "host or domain. To add a new policy, simply click the <i>New...</i> "
150 "button and supply the necessary information requested by the "
151 "dialog box. To change an existing policy, click on the <i>Change...</i> "
152 "button and choose the new policy from the policy dialog box. Clicking "
153 "on the <i>Delete</i> button will remove the selected policy, causing the default "
154 "policy setting to be used for that domain.") );
156 "The <i>Import</i> and <i>Export</i> "
157 "button allows you to easily share your policies with other people by allowing "
158 "you to save and retrieve them from a zipped file.") );
161 javaSecurityManagerCB
->setWhatsThis( i18n( "Enabling the security manager will cause the jvm to run with a Security "
162 "Manager in place. This will keep applets from being able to read and "
163 "write to your file system, creating arbitrary sockets, and other actions "
164 "which could be used to compromise your system. Disable this option at your "
165 "own risk. You can modify your $HOME/.java.policy file with the Java "
166 "policytool utility to give code downloaded from certain sites more "
169 useKioCB
->setWhatsThis( i18n( "Enabling this will cause the jvm to use KIO for network transport ") );
171 pathED
->setWhatsThis( i18n("Enter the path to the java executable. If you want to use the jre in "
172 "your path, simply leave it as 'java'. If you need to use a different jre, "
173 "enter the path to the java executable (e.g. /usr/lib/jdk/bin/java), "
174 "or the path to the directory that contains 'bin/java' (e.g. /opt/IBMJava2-13).") );
176 addArgED
->setWhatsThis( i18n("If you want special arguments to be passed to the virtual machine, enter them here.") );
178 QString shutdown
= i18n("When all the applets have been destroyed, the applet server should shut down. "
179 "However, starting the jvm takes a lot of time. If you would like to "
180 "keep the java process running while you are "
181 "browsing, you can set the timeout value to whatever you like. To keep "
182 "the java process running for the whole time that the konqueror process is, "
183 "leave the Shutdown Applet Server checkbox unchecked.");
184 serverTimeoutSB
->setWhatsThis(shutdown
);
185 enableShutdownCB
->setWhatsThis(shutdown
);
188 void KJavaOptions::load()
191 java_global_policies
.load();
192 bool bJavaGlobal
= java_global_policies
.isFeatureEnabled();
193 bool bSecurityManager
= m_pConfig
->group(m_groupname
).readEntry( "UseSecurityManager", true);
194 bool bUseKio
= m_pConfig
->group(m_groupname
).readEntry( "UseKio", false);
195 bool bServerShutdown
= m_pConfig
->group(m_groupname
).readEntry( "ShutdownAppletServer", true);
196 int serverTimeout
= m_pConfig
->group(m_groupname
).readEntry( "AppletServerTimeout", 60 );
197 #if defined(PATH_JAVA)
198 QString sJavaPath
= m_pConfig
->group(m_groupname
).readPathEntry( "JavaPath", PATH_JAVA
);
200 QString sJavaPath
= m_pConfig
->group(m_groupname
).readPathEntry( "JavaPath", "java" );
203 if( sJavaPath
== "/usr/lib/jdk" )
206 if( m_pConfig
->group(m_groupname
).hasKey( "JavaDomains" ) )
207 domainSpecific
->initialize(m_pConfig
->group(m_groupname
).readEntry("JavaDomains", QStringList() ));
208 else if( m_pConfig
->group(m_groupname
).hasKey( "JavaDomainSettings" ) ) {
209 domainSpecific
->updateDomainListLegacy( m_pConfig
->group(m_groupname
).readEntry("JavaDomainSettings", QStringList() ) );
210 _removeJavaDomainSettings
= true;
212 domainSpecific
->updateDomainListLegacy( m_pConfig
->group(m_groupname
).readEntry("JavaScriptDomainAdvice", QStringList() ) );
213 _removeJavaScriptDomainAdvice
= true;
216 // *** apply to GUI ***
217 enableJavaGloballyCB
->setChecked( bJavaGlobal
);
218 javaSecurityManagerCB
->setChecked( bSecurityManager
);
219 useKioCB
->setChecked( bUseKio
);
221 addArgED
->setText( m_pConfig
->group(m_groupname
).readEntry( "JavaArgs" ) );
222 pathED
->lineEdit()->setText( sJavaPath
);
224 enableShutdownCB
->setChecked( bServerShutdown
);
225 serverTimeoutSB
->setValue( serverTimeout
);
227 toggleJavaControls();
228 emit
changed( false );
231 void KJavaOptions::defaults()
233 java_global_policies
.defaults();
234 enableJavaGloballyCB
->setChecked( false );
235 javaSecurityManagerCB
->setChecked( true );
236 useKioCB
->setChecked( false );
237 pathED
->lineEdit()->setText( "java" );
238 addArgED
->setText( "" );
239 enableShutdownCB
->setChecked(true);
240 serverTimeoutSB
->setValue( 60 );
241 toggleJavaControls();
242 emit
changed( true );
245 void KJavaOptions::save()
247 java_global_policies
.save();
248 m_pConfig
->group(m_groupname
).writeEntry( "JavaArgs", addArgED
->text() );
249 m_pConfig
->group(m_groupname
).writePathEntry( "JavaPath", pathED
->lineEdit()->text() );
250 m_pConfig
->group(m_groupname
).writeEntry( "UseSecurityManager", javaSecurityManagerCB
->isChecked() );
251 m_pConfig
->group(m_groupname
).writeEntry( "UseKio", useKioCB
->isChecked() );
252 m_pConfig
->group(m_groupname
).writeEntry( "ShutdownAppletServer", enableShutdownCB
->isChecked() );
253 m_pConfig
->group(m_groupname
).writeEntry( "AppletServerTimeout", serverTimeoutSB
->value() );
255 domainSpecific
->save(m_groupname
,"JavaDomains");
257 if (_removeJavaDomainSettings
) {
258 m_pConfig
->group(m_groupname
).deleteEntry("JavaDomainSettings");
259 _removeJavaDomainSettings
= false;
262 // sync moved to KJSParts::save
263 // m_pConfig->sync();
264 emit
changed( false );
267 void KJavaOptions::slotChanged()
273 void KJavaOptions::toggleJavaControls()
275 bool isEnabled
= true; //enableJavaGloballyCB->isChecked();
277 java_global_policies
.setFeatureEnabled( enableJavaGloballyCB
->isChecked() );
278 javaSecurityManagerCB
->setEnabled( isEnabled
);
279 useKioCB
->setEnabled( isEnabled
);
280 addArgED
->setEnabled( isEnabled
);
281 pathED
->setEnabled( isEnabled
);
282 enableShutdownCB
->setEnabled( isEnabled
);
284 serverTimeoutSB
->setEnabled( enableShutdownCB
->isChecked() && isEnabled
);
287 // == class JavaDomainListView =====
289 JavaDomainListView::JavaDomainListView(KSharedConfig::Ptr config
,const QString
&group
,
290 KJavaOptions
*options
,QWidget
*parent
)
291 : DomainListView(config
,i18nc("@title:group", "Doma&in-Specific" ), parent
),
292 group(group
), options(options
) {
295 JavaDomainListView::~JavaDomainListView() {
298 void JavaDomainListView::updateDomainListLegacy(const QStringList
&domainConfig
)
300 domainSpecificLV
->clear();
301 JavaPolicies
pol(config
,group
,false);
303 for ( QStringList::ConstIterator it
= domainConfig
.begin();
304 it
!= domainConfig
.end(); ++it
)
307 KHTMLSettings::KJavaScriptAdvice javaAdvice
;
308 KHTMLSettings::KJavaScriptAdvice javaScriptAdvice
;
309 KHTMLSettings::splitDomainAdvice(*it
, domain
, javaAdvice
, javaScriptAdvice
);
310 if (javaAdvice
!= KHTMLSettings::KJavaScriptDunno
) {
311 QTreeWidgetItem
* index
= new QTreeWidgetItem( domainSpecificLV
, QStringList() << domain
<<
312 i18n(KHTMLSettings::adviceToStr(javaAdvice
)) );
313 pol
.setDomain(domain
);
314 pol
.setFeatureEnabled(javaAdvice
!= KHTMLSettings::KJavaScriptReject
);
315 domainPolicies
[index
] = new JavaPolicies(pol
);
320 void JavaDomainListView::setupPolicyDlg(PushButton trigger
,PolicyDialog
&pDlg
,
324 case AddButton
: caption
= i18n( "New Java Policy" );
325 pol
->setFeatureEnabled(!options
->enableJavaGloballyCB
->isChecked());
327 case ChangeButton
: caption
= i18n( "Change Java Policy" ); break;
328 default: ; // inhibit gcc warning
330 pDlg
.setCaption(caption
);
331 pDlg
.setFeatureEnabledLabel(i18n("&Java policy:"));
332 pDlg
.setFeatureEnabledWhatsThis(i18n("Select a Java policy for "
333 "the above host or domain."));
337 JavaPolicies
*JavaDomainListView::createPolicies() {
338 return new JavaPolicies(config
,group
,false);
341 JavaPolicies
*JavaDomainListView::copyPolicies(Policies
*pol
) {
342 return new JavaPolicies(*static_cast<JavaPolicies
*>(pol
));
345 #include "javaopts.moc"