khtml Library API Documentation

khtml_settings.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 1999 David Faure <faure@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
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     // don't forget to maintain the bitfields as the enums grow
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     // the virtual global "domain"
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     // simply copy global domain settings (they should have been initialized
00112     // by this time)
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             // Java advice only
00163             javaAdvice = strToAdvice( adviceString );
00164             javaScriptAdvice = KJavaScriptDunno;
00165         } else {
00166             // Java and JavaScript advice
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   // The setting for Java
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   // The setting for Plugins
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   // The setting for JavaScript
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   // window property policies
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     // Fonts and colors
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" ) ); // font size adjustment
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     // Behavior
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     // Other
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   // Colors
00369   if ( reset || config->hasGroup( "General" ) )
00370   {
00371     config->setGroup( "General" ); // group will be restored by cgs anyway
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     // The global setting for JavaScript debugging
00388     // This is currently always enabled by default
00389     if ( reset || config->hasKey( "EnableJavaScriptDebug" ) )
00390       d->m_bEnableJavaScriptDebug = config->readBoolEntry( "EnableJavaScriptDebug", false );
00391 
00392     // The global setting for JavaScript error reporting
00393     if ( reset || config->hasKey( "ReportJavaScriptErrors" ) )
00394       d->m_bEnableJavaScriptErrorReporting = config->readBoolEntry( "ReportJavaScriptErrors", false );
00395 
00396     // Read options from the global "domain"
00397     readDomainSettings(config,reset,true,d->global);
00398 #ifdef DEBUG_SETTINGS
00399     d->global.dump("init global");
00400 #endif
00401 
00402     // The domain-specific settings.
00403 
00404     static const char *const domain_keys[] = {  // always keep order of keys
00405         "ECMADomains", "JavaDomains", "PluginDomains"
00406     };
00407     bool check_old_ecma_settings = true;
00408     bool check_old_java_settings = true;
00409     // merge all domains into one list
00410     QMap<QString,int> domainList;   // why can't Qt have a QSet?
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     }/*next it*/
00423       }
00424     }/*next i*/
00425 
00426     QString js_group_save = config->group();
00427     for ( QMap<QString,int>::ConstIterator it = domainList.begin();
00428                 it != domainList.end(); ++it)
00429     {
00430       QString domain = it.key();
00431       config->setGroup(domain);
00432       readDomainSettings(config,reset,false,d->domainPolicy[domain]);
00433 #ifdef DEBUG_SETTINGS
00434       d->domainPolicy[domain].dump("init "+domain);
00435 #endif
00436     }
00437     config->setGroup(js_group_save);
00438 
00439     bool check_old_java = true;
00440     if( ( reset || config->hasKey( "JavaDomainSettings" ) )
00441         && check_old_java_settings )
00442     {
00443       check_old_java = false;
00444       QStringList domainList = config->readListEntry( "JavaDomainSettings" );
00445       for ( QStringList::ConstIterator it = domainList.begin();
00446                 it != domainList.end(); ++it)
00447       {
00448         QString domain;
00449         KJavaScriptAdvice javaAdvice;
00450         KJavaScriptAdvice javaScriptAdvice;
00451         splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice);
00452         setup_per_domain_policy(d,domain).m_bEnableJava =
00453         javaAdvice == KJavaScriptAccept;
00454 #ifdef DEBUG_SETTINGS
00455     setup_per_domain_policy(d,domain).dump("JavaDomainSettings 4 "+domain);
00456 #endif
00457       }
00458     }
00459 
00460     bool check_old_ecma = true;
00461     if( ( reset || config->hasKey( "ECMADomainSettings" ) )
00462     && check_old_ecma_settings )
00463     {
00464       check_old_ecma = false;
00465       QStringList domainList = config->readListEntry( "ECMADomainSettings" );
00466       for ( QStringList::ConstIterator it = domainList.begin();
00467                 it != domainList.end(); ++it)
00468       {
00469         QString domain;
00470         KJavaScriptAdvice javaAdvice;
00471         KJavaScriptAdvice javaScriptAdvice;
00472         splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice);
00473         setup_per_domain_policy(d,domain).m_bEnableJavaScript =
00474             javaScriptAdvice == KJavaScriptAccept;
00475 #ifdef DEBUG_SETTINGS
00476     setup_per_domain_policy(d,domain).dump("ECMADomainSettings 4 "+domain);
00477 #endif
00478       }
00479     }
00480 
00481     if( ( reset || config->hasKey( "JavaScriptDomainAdvice" ) )
00482              && ( check_old_java || check_old_ecma )
00483          && ( check_old_ecma_settings || check_old_java_settings ) )
00484     {
00485       QStringList domainList = config->readListEntry( "JavaScriptDomainAdvice" );
00486       for ( QStringList::ConstIterator it = domainList.begin();
00487                 it != domainList.end(); ++it)
00488       {
00489         QString domain;
00490         KJavaScriptAdvice javaAdvice;
00491         KJavaScriptAdvice javaScriptAdvice;
00492         splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice);
00493         if( check_old_java )
00494           setup_per_domain_policy(d,domain).m_bEnableJava =
00495             javaAdvice == KJavaScriptAccept;
00496         if( check_old_ecma )
00497           setup_per_domain_policy(d,domain).m_bEnableJavaScript =
00498             javaScriptAdvice == KJavaScriptAccept;
00499 #ifdef DEBUG_SETTINGS
00500     setup_per_domain_policy(d,domain).dump("JavaScriptDomainAdvice 4 "+domain);
00501 #endif
00502       }
00503 
00504       //save all the settings into the new keywords if they don't exist
00505 #if 0
00506       if( check_old_java )
00507       {
00508         QStringList domainConfig;
00509         PolicyMap::Iterator it;
00510         for( it = d->javaDomainPolicy.begin(); it != d->javaDomainPolicy.end(); ++it )
00511         {
00512           QCString javaPolicy = adviceToStr( it.data() );
00513           QCString javaScriptPolicy = adviceToStr( KJavaScriptDunno );
00514           domainConfig.append(QString::fromLatin1("%1:%2:%3").arg(it.key()).arg(javaPolicy).arg(javaScriptPolicy));
00515         }
00516         config->writeEntry( "JavaDomainSettings", domainConfig );
00517       }
00518 
00519       if( check_old_ecma )
00520       {
00521         QStringList domainConfig;
00522         PolicyMap::Iterator it;
00523         for( it = d->javaScriptDomainPolicy.begin(); it != d->javaScriptDomainPolicy.end(); ++it )
00524         {
00525           QCString javaPolicy = adviceToStr( KJavaScriptDunno );
00526           QCString javaScriptPolicy = adviceToStr( it.data() );
00527           domainConfig.append(QString::fromLatin1("%1:%2:%3").arg(it.key()).arg(javaPolicy).arg(javaScriptPolicy));
00528         }
00529         config->writeEntry( "ECMADomainSettings", domainConfig );
00530       }
00531 #endif
00532     }
00533   }
00534   config->setGroup(group_save);
00535 }
00536 
00537 
00542 static const KPerDomainSettings &lookup_hostname_policy(
00543             const KHTMLSettingsPrivate *d,
00544             const QString& hostname)
00545 {
00546 #ifdef DEBUG_SETTINGS
00547   kdDebug() << "lookup_hostname_policy(" << hostname << ")" << endl;
00548 #endif
00549   if (hostname.isEmpty()) {
00550 #ifdef DEBUG_SETTINGS
00551     d->global.dump("global");
00552 #endif
00553     return d->global;
00554   }
00555 
00556   PolicyMap::const_iterator notfound = d->domainPolicy.end();
00557 
00558   // First check whether there is a perfect match.
00559   PolicyMap::const_iterator it = d->domainPolicy.find(hostname);
00560   if( it != notfound ) {
00561 #ifdef DEBUG_SETTINGS
00562     kdDebug() << "perfect match" << endl;
00563     (*it).dump(hostname);
00564 #endif
00565     // yes, use it (unless dunno)
00566     return *it;
00567   }
00568 
00569   // Now, check for partial match.  Chop host from the left until
00570   // there's no dots left.
00571   QString host_part = hostname;
00572   int dot_idx = -1;
00573   while( (dot_idx = host_part.find(QChar('.'))) >= 0 ) {
00574     host_part.remove(0,dot_idx);
00575     it = d->domainPolicy.find(host_part);
00576     Q_ASSERT(notfound == d->domainPolicy.end());
00577     if( it != notfound ) {
00578 #ifdef DEBUG_SETTINGS
00579       kdDebug() << "partial match" << endl;
00580       (*it).dump(host_part);
00581 #endif
00582       return *it;
00583     }
00584     // assert(host_part[0] == QChar('.'));
00585     host_part.remove(0,1); // Chop off the dot.
00586   }
00587 
00588   // No domain-specific entry: use global domain
00589 #ifdef DEBUG_SETTINGS
00590   kdDebug() << "no match" << endl;
00591   d->global.dump("global");
00592 #endif
00593   return d->global;
00594 }
00595 
00596 bool KHTMLSettings::isBackRightClickEnabled()
00597 {
00598   return d->m_bBackRightClick;
00599 }
00600 
00601 bool KHTMLSettings::isJavaEnabled( const QString& hostname )
00602 {
00603   return lookup_hostname_policy(d,hostname.lower()).m_bEnableJava;
00604 }
00605 
00606 bool KHTMLSettings::isJavaScriptEnabled( const QString& hostname )
00607 {
00608   return lookup_hostname_policy(d,hostname.lower()).m_bEnableJavaScript;
00609 }
00610 
00611 bool KHTMLSettings::isJavaScriptDebugEnabled( const QString& /*hostname*/ )
00612 {
00613   // debug setting is global for now, but could change in the future
00614   return d->m_bEnableJavaScriptDebug;
00615 }
00616 
00617 bool KHTMLSettings::isJavaScriptErrorReportingEnabled( const QString& /*hostname*/ ) const
00618 {
00619   // error reporting setting is global for now, but could change in the future
00620   return d->m_bEnableJavaScriptErrorReporting;
00621 }
00622 
00623 bool KHTMLSettings::isPluginsEnabled( const QString& hostname )
00624 {
00625   return lookup_hostname_policy(d,hostname.lower()).m_bEnablePlugins;
00626 }
00627 
00628 KHTMLSettings::KJSWindowOpenPolicy KHTMLSettings::windowOpenPolicy(
00629                 const QString& hostname) const {
00630   return lookup_hostname_policy(d,hostname.lower()).m_windowOpenPolicy;
00631 }
00632 
00633 KHTMLSettings::KJSWindowMovePolicy KHTMLSettings::windowMovePolicy(
00634                 const QString& hostname) const {
00635   return lookup_hostname_policy(d,hostname.lower()).m_windowMovePolicy;
00636 }
00637 
00638 KHTMLSettings::KJSWindowResizePolicy KHTMLSettings::windowResizePolicy(
00639                 const QString& hostname) const {
00640   return lookup_hostname_policy(d,hostname.lower()).m_windowResizePolicy;
00641 }
00642 
00643 KHTMLSettings::KJSWindowStatusPolicy KHTMLSettings::windowStatusPolicy(
00644                 const QString& hostname) const {
00645   return lookup_hostname_policy(d,hostname.lower()).m_windowStatusPolicy;
00646 }
00647 
00648 KHTMLSettings::KJSWindowFocusPolicy KHTMLSettings::windowFocusPolicy(
00649                 const QString& hostname) const {
00650   return lookup_hostname_policy(d,hostname.lower()).m_windowFocusPolicy;
00651 }
00652 
00653 int KHTMLSettings::mediumFontSize() const
00654 {
00655     return d->m_fontSize;
00656 }
00657 
00658 int KHTMLSettings::minFontSize() const
00659 {
00660   return d->m_minFontSize;
00661 }
00662 
00663 QString KHTMLSettings::settingsToCSS() const
00664 {
00665     // lets start with the link properties
00666     QString str = "a:link {\ncolor: ";
00667     str += d->m_linkColor.name();
00668     str += ";";
00669     if(d->m_underlineLink)
00670         str += "\ntext-decoration: underline;";
00671 
00672     if( d->m_bChangeCursor )
00673     {
00674         str += "\ncursor: pointer;";
00675         str += "\n}\ninput[type=image] { cursor: pointer;";
00676     }
00677     str += "\n}\n";
00678     str += "a:visited {\ncolor: ";
00679     str += d->m_vLinkColor.name();
00680     str += ";";
00681     if(d->m_underlineLink)
00682         str += "\ntext-decoration: underline;";
00683 
00684     if( d->m_bChangeCursor )
00685         str += "\ncursor: pointer;";
00686     str += "\n}\n";
00687 
00688     if(d->m_hoverLink)
00689         str += "a:link:hover, a:visited:hover { text-decoration: underline; }\n";
00690 
00691     return str;
00692 }
00693 
00694 const QString &KHTMLSettings::availableFamilies()
00695 {
00696     if ( !avFamilies ) {
00697         avFamilies = new QString;
00698         QFontDatabase db;
00699         QStringList families = db.families();
00700         QStringList s;
00701         QRegExp foundryExp(" \\[.+\\]");
00702 
00703         //remove foundry info
00704         for ( QStringList::Iterator f = families.begin(); f != families.end(); ++f ) {
00705                 (*f).replace( foundryExp, "");
00706                 if (!s.contains(*f))
00707                         s << *f;
00708         }
00709         s.sort();
00710 
00711         *avFamilies = ',' + s.join(",") + ',';
00712     }
00713 
00714   return *avFamilies;
00715 }
00716 
00717 QString KHTMLSettings::lookupFont(int i) const
00718 {
00719     QString font;
00720     if (d->fonts.count() > (uint) i)
00721        font = d->fonts[i];
00722     if (font.isEmpty())
00723         font = d->defaultFonts[i];
00724     return font;
00725 }
00726 
00727 QString KHTMLSettings::stdFontName() const
00728 {
00729     return lookupFont(0);
00730 }
00731 
00732 QString KHTMLSettings::fixedFontName() const
00733 {
00734     return lookupFont(1);
00735 }
00736 
00737 QString KHTMLSettings::serifFontName() const
00738 {
00739     return lookupFont(2);
00740 }
00741 
00742 QString KHTMLSettings::sansSerifFontName() const
00743 {
00744     return lookupFont(3);
00745 }
00746 
00747 QString KHTMLSettings::cursiveFontName() const
00748 {
00749     return lookupFont(4);
00750 }
00751 
00752 QString KHTMLSettings::fantasyFontName() const
00753 {
00754     return lookupFont(5);
00755 }
00756 
00757 void KHTMLSettings::setStdFontName(const QString &n)
00758 {
00759     while(d->fonts.count() <= 0)
00760         d->fonts.append(QString::null);
00761     d->fonts[0] = n;
00762 }
00763 
00764 void KHTMLSettings::setFixedFontName(const QString &n)
00765 {
00766     while(d->fonts.count() <= 1)
00767         d->fonts.append(QString::null);
00768     d->fonts[1] = n;
00769 }
00770 
00771 QString KHTMLSettings::userStyleSheet() const
00772 {
00773     return d->m_userSheet;
00774 }
00775 
00776 bool KHTMLSettings::isFormCompletionEnabled() const
00777 {
00778   return d->m_formCompletionEnabled;
00779 }
00780 
00781 int KHTMLSettings::maxFormCompletionItems() const
00782 {
00783   return d->m_maxFormCompletionItems;
00784 }
00785 
00786 const QString &KHTMLSettings::encoding() const
00787 {
00788   return d->m_encoding;
00789 }
00790 
00791 const QColor& KHTMLSettings::textColor() const
00792 {
00793   return d->m_textColor;
00794 }
00795 
00796 const QColor& KHTMLSettings::linkColor() const
00797 {
00798   return d->m_linkColor;
00799 }
00800 
00801 const QColor& KHTMLSettings::vLinkColor() const
00802 {
00803   return d->m_vLinkColor;
00804 }
00805 
00806 bool KHTMLSettings::autoLoadImages() const
00807 {
00808   return d->m_bAutoLoadImages;
00809 }
00810 
00811 KHTMLSettings::KAnimationAdvice KHTMLSettings::showAnimations() const
00812 {
00813   return d->m_showAnimations;
00814 }
00815 
00816 bool KHTMLSettings::isAutoDelayedActionsEnabled() const
00817 {
00818   return d->m_autoDelayedActionsEnabled;
00819 }
00820 
00821 bool KHTMLSettings::jsErrorsEnabled() const
00822 {
00823   return d->m_jsErrorsEnabled;
00824 }
00825 
00826 void KHTMLSettings::setJSErrorsEnabled(bool enabled)
00827 {
00828   d->m_jsErrorsEnabled = enabled;
00829   // save it
00830   KConfig *config = KGlobal::config();
00831   config->setGroup("HTML Settings");
00832   config->writeEntry("ReportJSErrors", enabled);
00833   config->sync();
00834 }
00835 
KDE Logo
This file is part of the documentation for khtml Library Version 3.2.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Mar 4 22:45:42 2004 by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2003