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