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