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 const 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, true );
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
00328 if ( reset || config->hasKey( "EnforceDefaultCharset" ) )
00329 d->enforceCharset = config->readBoolEntry( "EnforceDefaultCharset", false );
00330
00331
00332 if ( reset || config->hasKey( "ChangeCursor" ) )
00333 d->m_bChangeCursor = config->readBoolEntry( "ChangeCursor", KDE_DEFAULT_CHANGECURSOR );
00334
00335 if ( reset || config->hasKey("UnderlineLinks") )
00336 d->m_underlineLink = config->readBoolEntry( "UnderlineLinks", true );
00337
00338 if ( reset || config->hasKey( "HoverLinks" ) )
00339 {
00340 if ( ( d->m_hoverLink = config->readBoolEntry( "HoverLinks", false ) ) )
00341 d->m_underlineLink = false;
00342 }
00343
00344
00345 if ( reset || config->hasKey( "AutoLoadImages" ) )
00346 d->m_bAutoLoadImages = config->readBoolEntry( "AutoLoadImages", true );
00347
00348 if ( reset || config->hasKey( "ShowAnimations" ) )
00349 {
00350 QString value = config->readEntry( "ShowAnimations").lower();
00351 if (value == "disabled")
00352 d->m_showAnimations = KAnimationDisabled;
00353 else if (value == "looponce")
00354 d->m_showAnimations = KAnimationLoopOnce;
00355 else
00356 d->m_showAnimations = KAnimationEnabled;
00357 }
00358
00359 if ( config->readBoolEntry( "UserStyleSheetEnabled", false ) == true ) {
00360 if ( reset || config->hasKey( "UserStyleSheet" ) )
00361 d->m_userSheet = config->readEntry( "UserStyleSheet", "" );
00362 }
00363
00364 d->m_formCompletionEnabled = config->readBoolEntry("FormCompletion", true);
00365 d->m_maxFormCompletionItems = config->readNumEntry("MaxFormCompletionItems", 10);
00366 d->m_autoDelayedActionsEnabled = config->readBoolEntry ("AutoDelayedActions", true);
00367 d->m_jsErrorsEnabled = config->readBoolEntry("ReportJSErrors", true);
00368 }
00369
00370
00371 if ( reset || config->hasGroup( "General" ) )
00372 {
00373 config->setGroup( "General" );
00374 if ( reset || config->hasKey( "foreground" ) )
00375 d->m_textColor = config->readColorEntry( "foreground", &HTML_DEFAULT_TXT_COLOR );
00376
00377 if ( reset || config->hasKey( "linkColor" ) )
00378 d->m_linkColor = config->readColorEntry( "linkColor", &HTML_DEFAULT_LNK_COLOR );
00379
00380 if ( reset || config->hasKey( "visitedLinkColor" ) )
00381 d->m_vLinkColor = config->readColorEntry( "visitedLinkColor", &HTML_DEFAULT_VLNK_COLOR);
00382 }
00383
00384
00385 if( reset || config->hasGroup( "Java/JavaScript Settings" ) )
00386 {
00387 config->setGroup( "Java/JavaScript Settings" );
00388
00389
00390
00391 if ( reset || config->hasKey( "EnableJavaScriptDebug" ) )
00392 d->m_bEnableJavaScriptDebug = config->readBoolEntry( "EnableJavaScriptDebug", false );
00393
00394
00395 if ( reset || config->hasKey( "ReportJavaScriptErrors" ) )
00396 d->m_bEnableJavaScriptErrorReporting = config->readBoolEntry( "ReportJavaScriptErrors", false );
00397
00398
00399 readDomainSettings(config,reset,true,d->global);
00400 #ifdef DEBUG_SETTINGS
00401 d->global.dump("init global");
00402 #endif
00403
00404
00405
00406 static const char *const domain_keys[] = {
00407 "ECMADomains", "JavaDomains", "PluginDomains"
00408 };
00409 bool check_old_ecma_settings = true;
00410 bool check_old_java_settings = true;
00411
00412 QMap<QString,int> domainList;
00413 for (unsigned i = 0; i < sizeof domain_keys/sizeof domain_keys[0]; ++i) {
00414 if ( reset || config->hasKey(domain_keys[i]) ) {
00415 if (i == 0) check_old_ecma_settings = false;
00416 else if (i == 1) check_old_java_settings = false;
00417 const QStringList dl = config->readListEntry( domain_keys[i] );
00418 const QMap<QString,int>::Iterator notfound = domainList.end();
00419 QStringList::ConstIterator it = dl.begin();
00420 const QStringList::ConstIterator itEnd = dl.end();
00421 for (; it != itEnd; ++it) {
00422 const QString domain = (*it).lower();
00423 QMap<QString,int>::Iterator pos = domainList.find(domain);
00424 if (pos == notfound) domainList.insert(domain,0);
00425 }
00426 }
00427 }
00428
00429 if (reset)
00430 d->domainPolicy.clear();
00431
00432 QString js_group_save = config->group();
00433 {
00434 QMap<QString,int>::ConstIterator it = domainList.begin();
00435 const QMap<QString,int>::ConstIterator itEnd = domainList.end();
00436 for ( ; it != itEnd; ++it)
00437 {
00438 const 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 }
00446 config->setGroup(js_group_save);
00447
00448 bool check_old_java = true;
00449 if( ( reset || config->hasKey( "JavaDomainSettings" ) )
00450 && check_old_java_settings )
00451 {
00452 check_old_java = false;
00453 const QStringList domainList = config->readListEntry( "JavaDomainSettings" );
00454 QStringList::ConstIterator it = domainList.begin();
00455 const QStringList::ConstIterator itEnd = domainList.end();
00456 for ( ; it != itEnd; ++it)
00457 {
00458 QString domain;
00459 KJavaScriptAdvice javaAdvice;
00460 KJavaScriptAdvice javaScriptAdvice;
00461 splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice);
00462 setup_per_domain_policy(d,domain).m_bEnableJava =
00463 javaAdvice == KJavaScriptAccept;
00464 #ifdef DEBUG_SETTINGS
00465 setup_per_domain_policy(d,domain).dump("JavaDomainSettings 4 "+domain);
00466 #endif
00467 }
00468 }
00469
00470 bool check_old_ecma = true;
00471 if( ( reset || config->hasKey( "ECMADomainSettings" ) )
00472 && check_old_ecma_settings )
00473 {
00474 check_old_ecma = false;
00475 const QStringList domainList = config->readListEntry( "ECMADomainSettings" );
00476 QStringList::ConstIterator it = domainList.begin();
00477 const QStringList::ConstIterator itEnd = domainList.end();
00478 for ( ; it != itEnd; ++it)
00479 {
00480 QString domain;
00481 KJavaScriptAdvice javaAdvice;
00482 KJavaScriptAdvice javaScriptAdvice;
00483 splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice);
00484 setup_per_domain_policy(d,domain).m_bEnableJavaScript =
00485 javaScriptAdvice == KJavaScriptAccept;
00486 #ifdef DEBUG_SETTINGS
00487 setup_per_domain_policy(d,domain).dump("ECMADomainSettings 4 "+domain);
00488 #endif
00489 }
00490 }
00491
00492 if( ( reset || config->hasKey( "JavaScriptDomainAdvice" ) )
00493 && ( check_old_java || check_old_ecma )
00494 && ( check_old_ecma_settings || check_old_java_settings ) )
00495 {
00496 const QStringList domainList = config->readListEntry( "JavaScriptDomainAdvice" );
00497 QStringList::ConstIterator it = domainList.begin();
00498 const QStringList::ConstIterator itEnd = domainList.end();
00499 for ( ; it != itEnd; ++it)
00500 {
00501 QString domain;
00502 KJavaScriptAdvice javaAdvice;
00503 KJavaScriptAdvice javaScriptAdvice;
00504 splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice);
00505 if( check_old_java )
00506 setup_per_domain_policy(d,domain).m_bEnableJava =
00507 javaAdvice == KJavaScriptAccept;
00508 if( check_old_ecma )
00509 setup_per_domain_policy(d,domain).m_bEnableJavaScript =
00510 javaScriptAdvice == KJavaScriptAccept;
00511 #ifdef DEBUG_SETTINGS
00512 setup_per_domain_policy(d,domain).dump("JavaScriptDomainAdvice 4 "+domain);
00513 #endif
00514 }
00515
00516
00517 #if 0
00518 if( check_old_java )
00519 {
00520 QStringList domainConfig;
00521 PolicyMap::Iterator it;
00522 for( it = d->javaDomainPolicy.begin(); it != d->javaDomainPolicy.end(); ++it )
00523 {
00524 QCString javaPolicy = adviceToStr( it.data() );
00525 QCString javaScriptPolicy = adviceToStr( KJavaScriptDunno );
00526 domainConfig.append(QString::fromLatin1("%1:%2:%3").arg(it.key()).arg(javaPolicy).arg(javaScriptPolicy));
00527 }
00528 config->writeEntry( "JavaDomainSettings", domainConfig );
00529 }
00530
00531 if( check_old_ecma )
00532 {
00533 QStringList domainConfig;
00534 PolicyMap::Iterator it;
00535 for( it = d->javaScriptDomainPolicy.begin(); it != d->javaScriptDomainPolicy.end(); ++it )
00536 {
00537 QCString javaPolicy = adviceToStr( KJavaScriptDunno );
00538 QCString javaScriptPolicy = adviceToStr( it.data() );
00539 domainConfig.append(QString::fromLatin1("%1:%2:%3").arg(it.key()).arg(javaPolicy).arg(javaScriptPolicy));
00540 }
00541 config->writeEntry( "ECMADomainSettings", domainConfig );
00542 }
00543 #endif
00544 }
00545 }
00546 config->setGroup(group_save);
00547 }
00548
00549
00554 static const KPerDomainSettings &lookup_hostname_policy(
00555 const KHTMLSettingsPrivate *d,
00556 const QString& hostname)
00557 {
00558 #ifdef DEBUG_SETTINGS
00559 kdDebug() << "lookup_hostname_policy(" << hostname << ")" << endl;
00560 #endif
00561 if (hostname.isEmpty()) {
00562 #ifdef DEBUG_SETTINGS
00563 d->global.dump("global");
00564 #endif
00565 return d->global;
00566 }
00567
00568 const PolicyMap::const_iterator notfound = d->domainPolicy.end();
00569
00570
00571 PolicyMap::const_iterator it = d->domainPolicy.find(hostname);
00572 if( it != notfound ) {
00573 #ifdef DEBUG_SETTINGS
00574 kdDebug() << "perfect match" << endl;
00575 (*it).dump(hostname);
00576 #endif
00577
00578 return *it;
00579 }
00580
00581
00582
00583 QString host_part = hostname;
00584 int dot_idx = -1;
00585 while( (dot_idx = host_part.find(QChar('.'))) >= 0 ) {
00586 host_part.remove(0,dot_idx);
00587 it = d->domainPolicy.find(host_part);
00588 Q_ASSERT(notfound == d->domainPolicy.end());
00589 if( it != notfound ) {
00590 #ifdef DEBUG_SETTINGS
00591 kdDebug() << "partial match" << endl;
00592 (*it).dump(host_part);
00593 #endif
00594 return *it;
00595 }
00596
00597 host_part.remove(0,1);
00598 }
00599
00600
00601 #ifdef DEBUG_SETTINGS
00602 kdDebug() << "no match" << endl;
00603 d->global.dump("global");
00604 #endif
00605 return d->global;
00606 }
00607
00608 bool KHTMLSettings::isOpenMiddleClickEnabled()
00609 {
00610 return d->m_bOpenMiddleClick;
00611 }
00612
00613 bool KHTMLSettings::isBackRightClickEnabled()
00614 {
00615 return d->m_bBackRightClick;
00616 }
00617
00618 bool KHTMLSettings::isJavaEnabled( const QString& hostname )
00619 {
00620 return lookup_hostname_policy(d,hostname.lower()).m_bEnableJava;
00621 }
00622
00623 bool KHTMLSettings::isJavaScriptEnabled( const QString& hostname )
00624 {
00625 return lookup_hostname_policy(d,hostname.lower()).m_bEnableJavaScript;
00626 }
00627
00628 bool KHTMLSettings::isJavaScriptDebugEnabled( const QString& )
00629 {
00630
00631 return d->m_bEnableJavaScriptDebug;
00632 }
00633
00634 bool KHTMLSettings::isJavaScriptErrorReportingEnabled( const QString& ) const
00635 {
00636
00637 return d->m_bEnableJavaScriptErrorReporting;
00638 }
00639
00640 bool KHTMLSettings::isPluginsEnabled( const QString& hostname )
00641 {
00642 return lookup_hostname_policy(d,hostname.lower()).m_bEnablePlugins;
00643 }
00644
00645 KHTMLSettings::KJSWindowOpenPolicy KHTMLSettings::windowOpenPolicy(
00646 const QString& hostname) const {
00647 return lookup_hostname_policy(d,hostname.lower()).m_windowOpenPolicy;
00648 }
00649
00650 KHTMLSettings::KJSWindowMovePolicy KHTMLSettings::windowMovePolicy(
00651 const QString& hostname) const {
00652 return lookup_hostname_policy(d,hostname.lower()).m_windowMovePolicy;
00653 }
00654
00655 KHTMLSettings::KJSWindowResizePolicy KHTMLSettings::windowResizePolicy(
00656 const QString& hostname) const {
00657 return lookup_hostname_policy(d,hostname.lower()).m_windowResizePolicy;
00658 }
00659
00660 KHTMLSettings::KJSWindowStatusPolicy KHTMLSettings::windowStatusPolicy(
00661 const QString& hostname) const {
00662 return lookup_hostname_policy(d,hostname.lower()).m_windowStatusPolicy;
00663 }
00664
00665 KHTMLSettings::KJSWindowFocusPolicy KHTMLSettings::windowFocusPolicy(
00666 const QString& hostname) const {
00667 return lookup_hostname_policy(d,hostname.lower()).m_windowFocusPolicy;
00668 }
00669
00670 int KHTMLSettings::mediumFontSize() const
00671 {
00672 return d->m_fontSize;
00673 }
00674
00675 int KHTMLSettings::minFontSize() const
00676 {
00677 return d->m_minFontSize;
00678 }
00679
00680 QString KHTMLSettings::settingsToCSS() const
00681 {
00682
00683 QString str = "a:link {\ncolor: ";
00684 str += d->m_linkColor.name();
00685 str += ";";
00686 if(d->m_underlineLink)
00687 str += "\ntext-decoration: underline;";
00688
00689 if( d->m_bChangeCursor )
00690 {
00691 str += "\ncursor: pointer;";
00692 str += "\n}\ninput[type=image] { cursor: pointer;";
00693 }
00694 str += "\n}\n";
00695 str += "a:visited {\ncolor: ";
00696 str += d->m_vLinkColor.name();
00697 str += ";";
00698 if(d->m_underlineLink)
00699 str += "\ntext-decoration: underline;";
00700
00701 if( d->m_bChangeCursor )
00702 str += "\ncursor: pointer;";
00703 str += "\n}\n";
00704
00705 if(d->m_hoverLink)
00706 str += "a:link:hover, a:visited:hover { text-decoration: underline; }\n";
00707
00708 return str;
00709 }
00710
00711 const QString &KHTMLSettings::availableFamilies()
00712 {
00713 if ( !avFamilies ) {
00714 avFamilies = new QString;
00715 QFontDatabase db;
00716 QStringList families = db.families();
00717 QStringList s;
00718 QRegExp foundryExp(" \\[.+\\]");
00719
00720
00721 QStringList::Iterator f = families.begin();
00722 const QStringList::Iterator fEnd = families.end();
00723
00724 for ( ; f != fEnd; ++f ) {
00725 (*f).replace( foundryExp, "");
00726 if (!s.contains(*f))
00727 s << *f;
00728 }
00729 s.sort();
00730
00731 *avFamilies = ',' + s.join(",") + ',';
00732 }
00733
00734 return *avFamilies;
00735 }
00736
00737 QString KHTMLSettings::lookupFont(int i) const
00738 {
00739 QString font;
00740 if (d->fonts.count() > (uint) i)
00741 font = d->fonts[i];
00742 if (font.isEmpty())
00743 font = d->defaultFonts[i];
00744 return font;
00745 }
00746
00747 QString KHTMLSettings::stdFontName() const
00748 {
00749 return lookupFont(0);
00750 }
00751
00752 QString KHTMLSettings::fixedFontName() const
00753 {
00754 return lookupFont(1);
00755 }
00756
00757 QString KHTMLSettings::serifFontName() const
00758 {
00759 return lookupFont(2);
00760 }
00761
00762 QString KHTMLSettings::sansSerifFontName() const
00763 {
00764 return lookupFont(3);
00765 }
00766
00767 QString KHTMLSettings::cursiveFontName() const
00768 {
00769 return lookupFont(4);
00770 }
00771
00772 QString KHTMLSettings::fantasyFontName() const
00773 {
00774 return lookupFont(5);
00775 }
00776
00777 void KHTMLSettings::setStdFontName(const QString &n)
00778 {
00779 while(d->fonts.count() <= 0)
00780 d->fonts.append(QString::null);
00781 d->fonts[0] = n;
00782 }
00783
00784 void KHTMLSettings::setFixedFontName(const QString &n)
00785 {
00786 while(d->fonts.count() <= 1)
00787 d->fonts.append(QString::null);
00788 d->fonts[1] = n;
00789 }
00790
00791 QString KHTMLSettings::userStyleSheet() const
00792 {
00793 return d->m_userSheet;
00794 }
00795
00796 bool KHTMLSettings::isFormCompletionEnabled() const
00797 {
00798 return d->m_formCompletionEnabled;
00799 }
00800
00801 int KHTMLSettings::maxFormCompletionItems() const
00802 {
00803 return d->m_maxFormCompletionItems;
00804 }
00805
00806 const QString &KHTMLSettings::encoding() const
00807 {
00808 return d->m_encoding;
00809 }
00810
00811 const QColor& KHTMLSettings::textColor() const
00812 {
00813 return d->m_textColor;
00814 }
00815
00816 const QColor& KHTMLSettings::linkColor() const
00817 {
00818 return d->m_linkColor;
00819 }
00820
00821 const QColor& KHTMLSettings::vLinkColor() const
00822 {
00823 return d->m_vLinkColor;
00824 }
00825
00826 bool KHTMLSettings::autoLoadImages() const
00827 {
00828 return d->m_bAutoLoadImages;
00829 }
00830
00831 KHTMLSettings::KAnimationAdvice KHTMLSettings::showAnimations() const
00832 {
00833 return d->m_showAnimations;
00834 }
00835
00836 bool KHTMLSettings::isAutoDelayedActionsEnabled() const
00837 {
00838 return d->m_autoDelayedActionsEnabled;
00839 }
00840
00841 bool KHTMLSettings::jsErrorsEnabled() const
00842 {
00843 return d->m_jsErrorsEnabled;
00844 }
00845
00846 void KHTMLSettings::setJSErrorsEnabled(bool enabled)
00847 {
00848 d->m_jsErrorsEnabled = enabled;
00849
00850 KConfig *config = KGlobal::config();
00851 config->setGroup("HTML Settings");
00852 config->writeEntry("ReportJSErrors", enabled);
00853 config->sync();
00854 }
00855