00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include <qfontdatabase.h>
00021
00022
#include "khtml_settings.h"
00023
#include "khtmldefaults.h"
00024
#include <kglobalsettings.h>
00025
#include <kconfig.h>
00026
#include <kglobal.h>
00027
#include <klocale.h>
00028
#include <kdebug.h>
00029
#include <qregexp.h>
00030
00035
struct KPerDomainSettings {
00036
bool m_bEnableJava : 1;
00037
bool m_bEnableJavaScript : 1;
00038
bool m_bEnablePlugins : 1;
00039
00040
KHTMLSettings::KJSWindowOpenPolicy m_windowOpenPolicy : 2;
00041
KHTMLSettings::KJSWindowStatusPolicy m_windowStatusPolicy : 1;
00042
KHTMLSettings::KJSWindowFocusPolicy m_windowFocusPolicy : 1;
00043
KHTMLSettings::KJSWindowMovePolicy m_windowMovePolicy : 1;
00044
KHTMLSettings::KJSWindowResizePolicy m_windowResizePolicy : 1;
00045
00046
#ifdef DEBUG_SETTINGS
00047
void dump(
const QString &infix = QString::null)
const {
00048
kdDebug() <<
"KPerDomainSettings " << infix <<
" @" <<
this <<
":" <<
endl;
00049
kdDebug() <<
" m_bEnableJava: " << m_bEnableJava <<
endl;
00050
kdDebug() <<
" m_bEnableJavaScript: " << m_bEnableJavaScript <<
endl;
00051
kdDebug() <<
" m_bEnablePlugins: " << m_bEnablePlugins <<
endl;
00052
kdDebug() <<
" m_windowOpenPolicy: " << m_windowOpenPolicy <<
endl;
00053
kdDebug() <<
" m_windowStatusPolicy: " << m_windowStatusPolicy <<
endl;
00054
kdDebug() <<
" m_windowFocusPolicy: " << m_windowFocusPolicy <<
endl;
00055
kdDebug() <<
" m_windowMovePolicy: " << m_windowMovePolicy <<
endl;
00056
kdDebug() <<
" m_windowResizePolicy: " << m_windowResizePolicy <<
endl;
00057 }
00058
#endif
00059
};
00060
00061
typedef QMap<QString,KPerDomainSettings> PolicyMap;
00062
00063
class KHTMLSettingsPrivate
00064 {
00065
public:
00066
bool m_bChangeCursor : 1;
00067
bool m_bOpenMiddleClick : 1;
00068
bool m_bBackRightClick : 1;
00069
bool m_underlineLink : 1;
00070
bool m_hoverLink : 1;
00071
bool m_bEnableJavaScriptDebug : 1;
00072
bool m_bEnableJavaScriptErrorReporting : 1;
00073
bool enforceCharset : 1;
00074
bool m_bAutoLoadImages : 1;
00075
bool m_formCompletionEnabled : 1;
00076
bool m_autoDelayedActionsEnabled : 1;
00077
bool m_jsErrorsEnabled : 1;
00078
00079
00080 KPerDomainSettings global;
00081
00082
int m_fontSize;
00083
int m_minFontSize;
00084
int m_maxFormCompletionItems;
00085 KHTMLSettings::KAnimationAdvice m_showAnimations;
00086
00087
QString m_encoding;
00088
QString m_userSheet;
00089
00090
QColor m_textColor;
00091
QColor m_linkColor;
00092
QColor m_vLinkColor;
00093
00094 PolicyMap domainPolicy;
00095
QStringList fonts;
00096
QStringList defaultFonts;
00097 };
00098
00099
00103
static KPerDomainSettings &setup_per_domain_policy(
00104 KHTMLSettingsPrivate *d,
00105
const QString &domain) {
00106
if (domain.isEmpty()) {
00107
kdWarning() <<
"setup_per_domain_policy: domain is empty" <<
endl;
00108 }
00109
QString ldomain = domain.lower();
00110 PolicyMap::iterator it = d->domainPolicy.find(ldomain);
00111
if (it == d->domainPolicy.end()) {
00112
00113
00114 it = d->domainPolicy.insert(ldomain,d->global);
00115 }
00116
return *it;
00117 }
00118
00119
00120
KHTMLSettings::KJavaScriptAdvice KHTMLSettings::strToAdvice(
const QString& _str)
00121 {
00122
KJavaScriptAdvice ret = KJavaScriptDunno;
00123
00124
if (!_str)
00125 ret = KJavaScriptDunno;
00126
00127
if (_str.lower() == QString::fromLatin1(
"accept"))
00128 ret = KJavaScriptAccept;
00129
else if (_str.lower() == QString::fromLatin1(
"reject"))
00130 ret = KJavaScriptReject;
00131
00132
return ret;
00133 }
00134
00135
const char* KHTMLSettings::adviceToStr(KJavaScriptAdvice _advice)
00136 {
00137
switch( _advice ) {
00138
case KJavaScriptAccept:
return I18N_NOOP(
"Accept");
00139
case KJavaScriptReject:
return I18N_NOOP(
"Reject");
00140
default:
return 0;
00141 }
00142
return 0;
00143 }
00144
00145
00146
void KHTMLSettings::splitDomainAdvice(
const QString& configStr,
QString &domain,
00147 KJavaScriptAdvice &javaAdvice, KJavaScriptAdvice& javaScriptAdvice)
00148 {
00149
QString tmp(configStr);
00150
int splitIndex = tmp.find(
':');
00151
if ( splitIndex == -1)
00152 {
00153 domain = configStr.lower();
00154 javaAdvice = KJavaScriptDunno;
00155 javaScriptAdvice = KJavaScriptDunno;
00156 }
00157
else
00158 {
00159 domain = tmp.left(splitIndex).lower();
00160
QString adviceString = tmp.mid( splitIndex+1, tmp.length() );
00161
int splitIndex2 = adviceString.find(
':' );
00162
if( splitIndex2 == -1 ) {
00163
00164 javaAdvice = strToAdvice( adviceString );
00165 javaScriptAdvice = KJavaScriptDunno;
00166 }
else {
00167
00168 javaAdvice = strToAdvice( adviceString.left( splitIndex2 ) );
00169 javaScriptAdvice = strToAdvice( adviceString.mid( splitIndex2+1,
00170 adviceString.length() ) );
00171 }
00172 }
00173 }
00174
00175 void KHTMLSettings::readDomainSettings(
KConfig *config,
bool reset,
00176
bool global, KPerDomainSettings &pd_settings) {
00177
QString jsPrefix = global ? QString::null
00178 : QString::fromLatin1(
"javascript.");
00179
QString javaPrefix = global ? QString::null
00180 : QString::fromLatin1(
"java.");
00181
QString pluginsPrefix = global ? QString::null
00182 : QString::fromLatin1(
"plugins.");
00183
00184
00185
QString key = javaPrefix + QString::fromLatin1(
"EnableJava");
00186
if ( (global && reset) || config->
hasKey( key ) )
00187 pd_settings.m_bEnableJava = config->
readBoolEntry( key,
false );
00188
else if ( !global )
00189 pd_settings.m_bEnableJava = d->global.m_bEnableJava;
00190
00191
00192 key = pluginsPrefix + QString::fromLatin1(
"EnablePlugins");
00193
if ( (global && reset) || config->
hasKey( key ) )
00194 pd_settings.m_bEnablePlugins = config->
readBoolEntry( key,
true );
00195
else if ( !global )
00196 pd_settings.m_bEnablePlugins = d->global.m_bEnablePlugins;
00197
00198
00199 key = jsPrefix + QString::fromLatin1(
"EnableJavaScript");
00200
if ( (global && reset) || config->
hasKey( key ) )
00201 pd_settings.m_bEnableJavaScript = config->
readBoolEntry( key,
true );
00202
else if ( !global )
00203 pd_settings.m_bEnableJavaScript = d->global.m_bEnableJavaScript;
00204
00205
00206 key = jsPrefix + QString::fromLatin1(
"WindowOpenPolicy");
00207
if ( (global && reset) || config->
hasKey( key ) )
00208 pd_settings.m_windowOpenPolicy = (
KJSWindowOpenPolicy)
00209 config->
readUnsignedNumEntry( key, KJSWindowOpenAllow );
00210
else if ( !global )
00211 pd_settings.m_windowOpenPolicy = d->global.m_windowOpenPolicy;
00212
00213 key = jsPrefix + QString::fromLatin1(
"WindowMovePolicy");
00214
if ( (global && reset) || config->
hasKey( key ) )
00215 pd_settings.m_windowMovePolicy = (
KJSWindowMovePolicy)
00216 config->
readUnsignedNumEntry( key, KJSWindowMoveAllow );
00217
else if ( !global )
00218 pd_settings.m_windowMovePolicy = d->global.m_windowMovePolicy;
00219
00220 key = jsPrefix + QString::fromLatin1(
"WindowResizePolicy");
00221
if ( (global && reset) || config->
hasKey( key ) )
00222 pd_settings.m_windowResizePolicy = (
KJSWindowResizePolicy)
00223 config->
readUnsignedNumEntry( key, KJSWindowResizeAllow );
00224
else if ( !global )
00225 pd_settings.m_windowResizePolicy = d->global.m_windowResizePolicy;
00226
00227 key = jsPrefix + QString::fromLatin1(
"WindowStatusPolicy");
00228
if ( (global && reset) || config->
hasKey( key ) )
00229 pd_settings.m_windowStatusPolicy = (
KJSWindowStatusPolicy)
00230 config->
readUnsignedNumEntry( key, KJSWindowStatusAllow );
00231
else if ( !global )
00232 pd_settings.m_windowStatusPolicy = d->global.m_windowStatusPolicy;
00233
00234 key = jsPrefix + QString::fromLatin1(
"WindowFocusPolicy");
00235
if ( (global && reset) || config->
hasKey( key ) )
00236 pd_settings.m_windowFocusPolicy = (
KJSWindowFocusPolicy)
00237 config->
readUnsignedNumEntry( key, KJSWindowFocusAllow );
00238
else if ( !global )
00239 pd_settings.m_windowFocusPolicy = d->global.m_windowFocusPolicy;
00240
00241 }
00242
00243
00244 KHTMLSettings::KHTMLSettings()
00245 {
00246 d =
new KHTMLSettingsPrivate();
00247
init();
00248 }
00249
00250 KHTMLSettings::KHTMLSettings(
const KHTMLSettings &other)
00251 {
00252 d =
new KHTMLSettingsPrivate();
00253 *d = *other.
d;
00254 }
00255
00256 KHTMLSettings::~KHTMLSettings()
00257 {
00258
delete d;
00259 }
00260
00261
bool KHTMLSettings::changeCursor()
const
00262
{
00263
return d->m_bChangeCursor;
00264 }
00265
00266
bool KHTMLSettings::underlineLink()
const
00267
{
00268
return d->m_underlineLink;
00269 }
00270
00271
bool KHTMLSettings::hoverLink()
const
00272
{
00273
return d->m_hoverLink;
00274 }
00275
00276 void KHTMLSettings::init()
00277 {
00278
KConfig global(
"khtmlrc",
true,
false );
00279
init( &global,
true );
00280
00281
KConfig *local =
KGlobal::config();
00282
if ( !local )
00283
return;
00284
00285
init( local,
false );
00286 }
00287
00288 void KHTMLSettings::init(
KConfig * config,
bool reset )
00289 {
00290
QString group_save = config->
group();
00291
if (reset || config->
hasGroup(
"MainView Settings"))
00292 {
00293 config->
setGroup(
"MainView Settings" );
00294
00295
if ( reset || config->
hasKey(
"OpenMiddleClick" ) )
00296 d->m_bOpenMiddleClick = config->
readBoolEntry(
"OpenMiddleClick",
true );
00297
00298
if ( reset || config->
hasKey(
"BackRightClick" ) )
00299 d->m_bBackRightClick = config->
readBoolEntry(
"BackRightClick",
false );
00300 }
00301
00302
if (reset || config->
hasGroup(
"HTML Settings"))
00303 {
00304 config->
setGroup(
"HTML Settings" );
00305
00306
if( reset ) {
00307 d->defaultFonts =
QStringList();
00308 d->defaultFonts.append( config->
readEntry(
"StandardFont", KGlobalSettings::generalFont().family() ) );
00309 d->defaultFonts.append( config->
readEntry(
"FixedFont", KGlobalSettings::fixedFont().family() ) );
00310 d->defaultFonts.append( config->
readEntry(
"SerifFont", HTML_DEFAULT_VIEW_SERIF_FONT ) );
00311 d->defaultFonts.append( config->
readEntry(
"SansSerifFont", HTML_DEFAULT_VIEW_SANSSERIF_FONT ) );
00312 d->defaultFonts.append( config->
readEntry(
"CursiveFont", HTML_DEFAULT_VIEW_CURSIVE_FONT ) );
00313 d->defaultFonts.append( config->
readEntry(
"FantasyFont", HTML_DEFAULT_VIEW_FANTASY_FONT ) );
00314 d->defaultFonts.append(
QString(
"0" ) );
00315 }
00316
00317
if ( reset || config->
hasKey(
"MinimumFontSize" ) )
00318 d->m_minFontSize = config->
readNumEntry(
"MinimumFontSize", HTML_DEFAULT_MIN_FONT_SIZE );
00319
00320
if ( reset || config->
hasKey(
"MediumFontSize" ) )
00321 d->m_fontSize = config->
readNumEntry(
"MediumFontSize", 12 );
00322
00323 d->fonts = config->
readListEntry(
"Fonts" );
00324
00325
if ( reset || config->
hasKey(
"DefaultEncoding" ) ) {
00326 d->m_encoding = config->
readEntry(
"DefaultEncoding",
"" );
00327
if ( d->m_encoding.isEmpty() )
00328 d->m_encoding =
KGlobal::locale()->
encoding();
00329 }
00330
00331
if ( reset || config->
hasKey(
"EnforceDefaultCharset" ) )
00332 d->enforceCharset = config->
readBoolEntry(
"EnforceDefaultCharset",
false );
00333
00334
00335
if ( reset || config->
hasKey(
"ChangeCursor" ) )
00336 d->m_bChangeCursor = config->
readBoolEntry(
"ChangeCursor", KDE_DEFAULT_CHANGECURSOR );
00337
00338
if ( reset || config->
hasKey(
"UnderlineLinks") )
00339 d->m_underlineLink = config->
readBoolEntry(
"UnderlineLinks",
true );
00340
00341
if ( reset || config->
hasKey(
"HoverLinks" ) )
00342 {
00343
if ( ( d->m_hoverLink = config->
readBoolEntry(
"HoverLinks",
false ) ) )
00344 d->m_underlineLink =
false;
00345 }
00346
00347
00348
if ( reset || config->
hasKey(
"AutoLoadImages" ) )
00349 d->m_bAutoLoadImages = config->
readBoolEntry(
"AutoLoadImages",
true );
00350
00351
if ( reset || config->
hasKey(
"ShowAnimations" ) )
00352 {
00353
QString value = config->
readEntry(
"ShowAnimations").lower();
00354
if (value ==
"disabled")
00355 d->m_showAnimations = KAnimationDisabled;
00356
else if (value ==
"looponce")
00357 d->m_showAnimations = KAnimationLoopOnce;
00358
else
00359 d->m_showAnimations = KAnimationEnabled;
00360 }
00361
00362
if ( config->
readBoolEntry(
"UserStyleSheetEnabled",
false ) ==
true ) {
00363
if ( reset || config->
hasKey(
"UserStyleSheet" ) )
00364 d->m_userSheet = config->
readEntry(
"UserStyleSheet",
"" );
00365 }
00366
00367 d->m_formCompletionEnabled = config->
readBoolEntry(
"FormCompletion",
true);
00368 d->m_maxFormCompletionItems = config->
readNumEntry(
"MaxFormCompletionItems", 10);
00369 d->m_autoDelayedActionsEnabled = config->
readBoolEntry (
"AutoDelayedActions",
true);
00370 d->m_jsErrorsEnabled = config->
readBoolEntry(
"ReportJSErrors",
true);
00371 }
00372
00373
00374
if ( reset || config->
hasGroup(
"General" ) )
00375 {
00376 config->
setGroup(
"General" );
00377
if ( reset || config->
hasKey(
"foreground" ) )
00378 d->m_textColor = config->
readColorEntry(
"foreground", &HTML_DEFAULT_TXT_COLOR );
00379
00380
if ( reset || config->
hasKey(
"linkColor" ) )
00381 d->m_linkColor = config->
readColorEntry(
"linkColor", &HTML_DEFAULT_LNK_COLOR );
00382
00383
if ( reset || config->
hasKey(
"visitedLinkColor" ) )
00384 d->m_vLinkColor = config->
readColorEntry(
"visitedLinkColor", &HTML_DEFAULT_VLNK_COLOR);
00385 }
00386
00387
00388
if( reset || config->
hasGroup(
"Java/JavaScript Settings" ) )
00389 {
00390 config->
setGroup(
"Java/JavaScript Settings" );
00391
00392
00393
00394
if ( reset || config->
hasKey(
"EnableJavaScriptDebug" ) )
00395 d->m_bEnableJavaScriptDebug = config->
readBoolEntry(
"EnableJavaScriptDebug",
false );
00396
00397
00398
if ( reset || config->
hasKey(
"ReportJavaScriptErrors" ) )
00399 d->m_bEnableJavaScriptErrorReporting = config->
readBoolEntry(
"ReportJavaScriptErrors",
false );
00400
00401
00402
readDomainSettings(config,reset,
true,d->global);
00403
#ifdef DEBUG_SETTINGS
00404
d->global.dump(
"init global");
00405
#endif
00406
00407
00408
00409
static const char *
const domain_keys[] = {
00410
"ECMADomains",
"JavaDomains",
"PluginDomains"
00411 };
00412
bool check_old_ecma_settings =
true;
00413
bool check_old_java_settings =
true;
00414
00415
QMap<QString,int> domainList;
00416
for (
unsigned i = 0; i <
sizeof domain_keys/
sizeof domain_keys[0]; i++) {
00417
if ( reset || config->
hasKey(domain_keys[i]) ) {
00418
if (i == 0) check_old_ecma_settings =
false;
00419
else if (i == 1) check_old_java_settings =
false;
00420
QStringList dl = config->
readListEntry( domain_keys[i] );
00421
QMap<QString,int>::Iterator notfound = domainList.end();
00422 QStringList::ConstIterator it;
00423
for (it = dl.begin(); it != dl.end(); ++it) {
00424
QString domain = (*it).lower();
00425
QMap<QString,int>::Iterator pos = domainList.find(domain);
00426
if (pos == notfound) domainList.insert(domain,0);
00427 }
00428 }
00429 }
00430
00431
if (reset)
00432 d->domainPolicy.clear();
00433
00434
QString js_group_save = config->
group();
00435
for (
QMap<QString,int>::ConstIterator it = domainList.begin();
00436 it != domainList.end(); ++it)
00437 {
00438
QString domain = it.key();
00439 config->
setGroup(domain);
00440
readDomainSettings(config,reset,
false,d->domainPolicy[domain]);
00441
#ifdef DEBUG_SETTINGS
00442
d->domainPolicy[domain].dump(
"init "+domain);
00443
#endif
00444
}
00445 config->
setGroup(js_group_save);
00446
00447
bool check_old_java =
true;
00448
if( ( reset || config->
hasKey(
"JavaDomainSettings" ) )
00449 && check_old_java_settings )
00450 {
00451 check_old_java =
false;
00452
QStringList domainList = config->
readListEntry(
"JavaDomainSettings" );
00453
for ( QStringList::ConstIterator it = domainList.begin();
00454 it != domainList.end(); ++it)
00455 {
00456
QString domain;
00457
KJavaScriptAdvice javaAdvice;
00458
KJavaScriptAdvice javaScriptAdvice;
00459 splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice);
00460 setup_per_domain_policy(d,domain).m_bEnableJava =
00461 javaAdvice == KJavaScriptAccept;
00462
#ifdef DEBUG_SETTINGS
00463
setup_per_domain_policy(d,domain).dump(
"JavaDomainSettings 4 "+domain);
00464
#endif
00465
}
00466 }
00467
00468
bool check_old_ecma =
true;
00469
if( ( reset || config->
hasKey(
"ECMADomainSettings" ) )
00470 && check_old_ecma_settings )
00471 {
00472 check_old_ecma =
false;
00473
QStringList domainList = config->
readListEntry(
"ECMADomainSettings" );
00474
for ( QStringList::ConstIterator it = domainList.begin();
00475 it != domainList.end(); ++it)
00476 {
00477
QString domain;
00478
KJavaScriptAdvice javaAdvice;
00479
KJavaScriptAdvice javaScriptAdvice;
00480 splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice);
00481 setup_per_domain_policy(d,domain).m_bEnableJavaScript =
00482 javaScriptAdvice == KJavaScriptAccept;
00483
#ifdef DEBUG_SETTINGS
00484
setup_per_domain_policy(d,domain).dump(
"ECMADomainSettings 4 "+domain);
00485
#endif
00486
}
00487 }
00488
00489
if( ( reset || config->
hasKey(
"JavaScriptDomainAdvice" ) )
00490 && ( check_old_java || check_old_ecma )
00491 && ( check_old_ecma_settings || check_old_java_settings ) )
00492 {
00493
QStringList domainList = config->
readListEntry(
"JavaScriptDomainAdvice" );
00494
for ( QStringList::ConstIterator it = domainList.begin();
00495 it != domainList.end(); ++it)
00496 {
00497
QString domain;
00498
KJavaScriptAdvice javaAdvice;
00499
KJavaScriptAdvice javaScriptAdvice;
00500 splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice);
00501
if( check_old_java )
00502 setup_per_domain_policy(d,domain).m_bEnableJava =
00503 javaAdvice == KJavaScriptAccept;
00504
if( check_old_ecma )
00505 setup_per_domain_policy(d,domain).m_bEnableJavaScript =
00506 javaScriptAdvice == KJavaScriptAccept;
00507
#ifdef DEBUG_SETTINGS
00508
setup_per_domain_policy(d,domain).dump(
"JavaScriptDomainAdvice 4 "+domain);
00509
#endif
00510
}
00511
00512
00513
#if 0
00514
if( check_old_java )
00515 {
00516
QStringList domainConfig;
00517 PolicyMap::Iterator it;
00518
for( it = d->javaDomainPolicy.begin(); it != d->javaDomainPolicy.end(); ++it )
00519 {
00520
QCString javaPolicy = adviceToStr( it.data() );
00521
QCString javaScriptPolicy = adviceToStr( KJavaScriptDunno );
00522 domainConfig.append(QString::fromLatin1(
"%1:%2:%3").arg(it.key()).arg(javaPolicy).arg(javaScriptPolicy));
00523 }
00524 config->
writeEntry(
"JavaDomainSettings", domainConfig );
00525 }
00526
00527
if( check_old_ecma )
00528 {
00529
QStringList domainConfig;
00530 PolicyMap::Iterator it;
00531
for( it = d->javaScriptDomainPolicy.begin(); it != d->javaScriptDomainPolicy.end(); ++it )
00532 {
00533
QCString javaPolicy = adviceToStr( KJavaScriptDunno );
00534
QCString javaScriptPolicy = adviceToStr( it.data() );
00535 domainConfig.append(QString::fromLatin1(
"%1:%2:%3").arg(it.key()).arg(javaPolicy).arg(javaScriptPolicy));
00536 }
00537 config->
writeEntry(
"ECMADomainSettings", domainConfig );
00538 }
00539
#endif
00540
}
00541 }
00542 config->
setGroup(group_save);
00543 }
00544
00545
00550
static const KPerDomainSettings &lookup_hostname_policy(
00551
const KHTMLSettingsPrivate *d,
00552
const QString& hostname)
00553 {
00554
#ifdef DEBUG_SETTINGS
00555
kdDebug() <<
"lookup_hostname_policy(" << hostname <<
")" <<
endl;
00556
#endif
00557
if (hostname.isEmpty()) {
00558
#ifdef DEBUG_SETTINGS
00559
d->global.dump(
"global");
00560
#endif
00561
return d->global;
00562 }
00563
00564 PolicyMap::const_iterator notfound = d->domainPolicy.end();
00565
00566
00567 PolicyMap::const_iterator it = d->domainPolicy.find(hostname);
00568
if( it != notfound ) {
00569
#ifdef DEBUG_SETTINGS
00570
kdDebug() <<
"perfect match" <<
endl;
00571 (*it).dump(hostname);
00572
#endif
00573
00574
return *it;
00575 }
00576
00577
00578
00579
QString host_part = hostname;
00580
int dot_idx = -1;
00581
while( (dot_idx = host_part.find(
QChar(
'.'))) >= 0 ) {
00582 host_part.remove(0,dot_idx);
00583 it = d->domainPolicy.find(host_part);
00584 Q_ASSERT(notfound == d->domainPolicy.end());
00585
if( it != notfound ) {
00586
#ifdef DEBUG_SETTINGS
00587
kdDebug() <<
"partial match" <<
endl;
00588 (*it).dump(host_part);
00589
#endif
00590
return *it;
00591 }
00592
00593 host_part.remove(0,1);
00594 }
00595
00596
00597
#ifdef DEBUG_SETTINGS
00598
kdDebug() <<
"no match" <<
endl;
00599 d->global.dump(
"global");
00600
#endif
00601
return d->global;
00602 }
00603
00604
bool KHTMLSettings::isOpenMiddleClickEnabled()
00605 {
00606
return d->m_bOpenMiddleClick;
00607 }
00608
00609
bool KHTMLSettings::isBackRightClickEnabled()
00610 {
00611
return d->m_bBackRightClick;
00612 }
00613
00614
bool KHTMLSettings::isJavaEnabled(
const QString& hostname )
00615 {
00616
return lookup_hostname_policy(d,hostname.lower()).m_bEnableJava;
00617 }
00618
00619
bool KHTMLSettings::isJavaScriptEnabled(
const QString& hostname )
00620 {
00621
return lookup_hostname_policy(d,hostname.lower()).m_bEnableJavaScript;
00622 }
00623
00624
bool KHTMLSettings::isJavaScriptDebugEnabled(
const QString& )
00625 {
00626
00627
return d->m_bEnableJavaScriptDebug;
00628 }
00629
00630
bool KHTMLSettings::isJavaScriptErrorReportingEnabled(
const QString& )
const
00631
{
00632
00633
return d->m_bEnableJavaScriptErrorReporting;
00634 }
00635
00636
bool KHTMLSettings::isPluginsEnabled(
const QString& hostname )
00637 {
00638
return lookup_hostname_policy(d,hostname.lower()).m_bEnablePlugins;
00639 }
00640
00641
KHTMLSettings::KJSWindowOpenPolicy KHTMLSettings::windowOpenPolicy(
00642
const QString& hostname)
const {
00643
return lookup_hostname_policy(d,hostname.lower()).m_windowOpenPolicy;
00644 }
00645
00646
KHTMLSettings::KJSWindowMovePolicy KHTMLSettings::windowMovePolicy(
00647
const QString& hostname)
const {
00648
return lookup_hostname_policy(d,hostname.lower()).m_windowMovePolicy;
00649 }
00650
00651
KHTMLSettings::KJSWindowResizePolicy KHTMLSettings::windowResizePolicy(
00652
const QString& hostname)
const {
00653
return lookup_hostname_policy(d,hostname.lower()).m_windowResizePolicy;
00654 }
00655
00656
KHTMLSettings::KJSWindowStatusPolicy KHTMLSettings::windowStatusPolicy(
00657
const QString& hostname)
const {
00658
return lookup_hostname_policy(d,hostname.lower()).m_windowStatusPolicy;
00659 }
00660
00661
KHTMLSettings::KJSWindowFocusPolicy KHTMLSettings::windowFocusPolicy(
00662
const QString& hostname)
const {
00663
return lookup_hostname_policy(d,hostname.lower()).m_windowFocusPolicy;
00664 }
00665
00666
int KHTMLSettings::mediumFontSize()
const
00667
{
00668
return d->m_fontSize;
00669 }
00670
00671
int KHTMLSettings::minFontSize()
const
00672
{
00673
return d->m_minFontSize;
00674 }
00675
00676
QString KHTMLSettings::settingsToCSS()
const
00677
{
00678
00679
QString str =
"a:link {\ncolor: ";
00680 str += d->m_linkColor.name();
00681 str +=
";";
00682
if(d->m_underlineLink)
00683 str +=
"\ntext-decoration: underline;";
00684
00685
if( d->m_bChangeCursor )
00686 {
00687 str +=
"\ncursor: pointer;";
00688 str +=
"\n}\ninput[type=image] { cursor: pointer;";
00689 }
00690 str +=
"\n}\n";
00691 str +=
"a:visited {\ncolor: ";
00692 str += d->m_vLinkColor.name();
00693 str +=
";";
00694
if(d->m_underlineLink)
00695 str +=
"\ntext-decoration: underline;";
00696
00697
if( d->m_bChangeCursor )
00698 str +=
"\ncursor: pointer;";
00699 str +=
"\n}\n";
00700
00701
if(d->m_hoverLink)
00702 str +=
"a:link:hover, a:visited:hover { text-decoration: underline; }\n";
00703
00704
return str;
00705 }
00706
00707
const QString &KHTMLSettings::availableFamilies()
00708 {
00709
if ( !avFamilies ) {
00710 avFamilies =
new QString;
00711
QFontDatabase db;
00712
QStringList families = db.families();
00713
QStringList s;
00714
QRegExp foundryExp(
" \\[.+\\]");
00715
00716
00717
for ( QStringList::Iterator f = families.begin(); f != families.end(); ++f ) {
00718 (*f).replace( foundryExp,
"");
00719
if (!s.contains(*f))
00720 s << *f;
00721 }
00722 s.sort();
00723
00724 *avFamilies =
',' + s.join(
",") +
',';
00725 }
00726
00727
return *avFamilies;
00728 }
00729
00730
QString KHTMLSettings::lookupFont(
int i)
const
00731
{
00732
QString font;
00733
if (d->fonts.count() > (uint) i)
00734 font = d->fonts[i];
00735
if (font.isEmpty())
00736 font = d->defaultFonts[i];
00737
return font;
00738 }
00739
00740
QString KHTMLSettings::stdFontName()
const
00741
{
00742
return lookupFont(0);
00743 }
00744
00745
QString KHTMLSettings::fixedFontName()
const
00746
{
00747
return lookupFont(1);
00748 }
00749
00750
QString KHTMLSettings::serifFontName()
const
00751
{
00752
return lookupFont(2);
00753 }
00754
00755
QString KHTMLSettings::sansSerifFontName()
const
00756
{
00757
return lookupFont(3);
00758 }
00759
00760
QString KHTMLSettings::cursiveFontName()
const
00761
{
00762
return lookupFont(4);
00763 }
00764
00765
QString KHTMLSettings::fantasyFontName()
const
00766
{
00767
return lookupFont(5);
00768 }
00769
00770
void KHTMLSettings::setStdFontName(
const QString &n)
00771 {
00772
while(d->fonts.count() <= 0)
00773 d->fonts.append(QString::null);
00774 d->fonts[0] = n;
00775 }
00776
00777
void KHTMLSettings::setFixedFontName(
const QString &n)
00778 {
00779
while(d->fonts.count() <= 1)
00780 d->fonts.append(QString::null);
00781 d->fonts[1] = n;
00782 }
00783
00784
QString KHTMLSettings::userStyleSheet()
const
00785
{
00786
return d->m_userSheet;
00787 }
00788
00789
bool KHTMLSettings::isFormCompletionEnabled()
const
00790
{
00791
return d->m_formCompletionEnabled;
00792 }
00793
00794
int KHTMLSettings::maxFormCompletionItems()
const
00795
{
00796
return d->m_maxFormCompletionItems;
00797 }
00798
00799
const QString &KHTMLSettings::encoding()
const
00800
{
00801
return d->m_encoding;
00802 }
00803
00804
const QColor& KHTMLSettings::textColor()
const
00805
{
00806
return d->m_textColor;
00807 }
00808
00809
const QColor& KHTMLSettings::linkColor()
const
00810
{
00811
return d->m_linkColor;
00812 }
00813
00814
const QColor& KHTMLSettings::vLinkColor()
const
00815
{
00816
return d->m_vLinkColor;
00817 }
00818
00819
bool KHTMLSettings::autoLoadImages()
const
00820
{
00821
return d->m_bAutoLoadImages;
00822 }
00823
00824 KHTMLSettings::KAnimationAdvice KHTMLSettings::showAnimations()
const
00825
{
00826
return d->m_showAnimations;
00827 }
00828
00829
bool KHTMLSettings::isAutoDelayedActionsEnabled()
const
00830
{
00831
return d->m_autoDelayedActionsEnabled;
00832 }
00833
00834
bool KHTMLSettings::jsErrorsEnabled()
const
00835
{
00836
return d->m_jsErrorsEnabled;
00837 }
00838
00839
void KHTMLSettings::setJSErrorsEnabled(
bool enabled)
00840 {
00841 d->m_jsErrorsEnabled = enabled;
00842
00843
KConfig *config =
KGlobal::config();
00844 config->
setGroup(
"HTML Settings");
00845 config->
writeEntry(
"ReportJSErrors", enabled);
00846 config->
sync();
00847 }
00848