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