• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KHTML

khtml_settings.cpp

Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "khtml_settings.h"
00021 #include "khtmldefaults.h"
00022 
00023 #include <kconfig.h>
00024 #include <kconfiggroup.h>
00025 #include <kdebug.h>
00026 #include <kglobal.h>
00027 #include <kglobalsettings.h>
00028 #include <klocale.h>
00029 #include <kmessagebox.h>
00030 #include <khtml_filter_p.h>
00031 
00032 #include <QtGui/QFontDatabase>
00033 
00038 struct KPerDomainSettings {
00039     bool m_bEnableJava : 1;
00040     bool m_bEnableJavaScript : 1;
00041     bool m_bEnablePlugins : 1;
00042     // don't forget to maintain the bitfields as the enums grow
00043     KHTMLSettings::KJSWindowOpenPolicy m_windowOpenPolicy : 2;
00044     KHTMLSettings::KJSWindowStatusPolicy m_windowStatusPolicy : 1;
00045     KHTMLSettings::KJSWindowFocusPolicy m_windowFocusPolicy : 1;
00046     KHTMLSettings::KJSWindowMovePolicy m_windowMovePolicy : 1;
00047     KHTMLSettings::KJSWindowResizePolicy m_windowResizePolicy : 1;
00048 
00049 #ifdef DEBUG_SETTINGS
00050     void dump(const QString &infix = QString()) const {
00051       kDebug() << "KPerDomainSettings " << infix << " @" << this << ":";
00052       kDebug() << "  m_bEnableJava: " << m_bEnableJava;
00053       kDebug() << "  m_bEnableJavaScript: " << m_bEnableJavaScript;
00054       kDebug() << "  m_bEnablePlugins: " << m_bEnablePlugins;
00055       kDebug() << "  m_windowOpenPolicy: " << m_windowOpenPolicy;
00056       kDebug() << "  m_windowStatusPolicy: " << m_windowStatusPolicy;
00057       kDebug() << "  m_windowFocusPolicy: " << m_windowFocusPolicy;
00058       kDebug() << "  m_windowMovePolicy: " << m_windowMovePolicy;
00059       kDebug() << "  m_windowResizePolicy: " << m_windowResizePolicy;
00060     }
00061 #endif
00062 };
00063 
00064 QString *KHTMLSettings::avFamilies = 0;
00065 typedef QMap<QString,KPerDomainSettings> PolicyMap;
00066 
00067 class KHTMLSettingsPrivate
00068 {
00069 public:
00070     bool m_bChangeCursor : 1;
00071     bool m_bOpenMiddleClick : 1;
00072     bool m_bBackRightClick : 1;
00073     bool m_underlineLink : 1;
00074     bool m_hoverLink : 1;
00075     bool m_bEnableJavaScriptDebug : 1;
00076     bool m_bEnableJavaScriptErrorReporting : 1;
00077     bool enforceCharset : 1;
00078     bool m_bAutoLoadImages : 1;
00079     bool m_bUnfinishedImageFrame : 1;
00080     bool m_formCompletionEnabled : 1;
00081     bool m_autoDelayedActionsEnabled : 1;
00082     bool m_jsErrorsEnabled : 1;
00083     bool m_follow_system_colors : 1;
00084     bool m_allowTabulation : 1;
00085     bool m_autoSpellCheck : 1;
00086     bool m_adFilterEnabled : 1;
00087     bool m_hideAdsEnabled : 1;
00088     bool m_jsPopupBlockerPassivePopup : 1;
00089     bool m_accessKeysEnabled : 1;
00090 
00091     // the virtual global "domain"
00092     KPerDomainSettings global;
00093 
00094     int m_fontSize;
00095     int m_minFontSize;
00096     int m_maxFormCompletionItems;
00097     KHTMLSettings::KAnimationAdvice m_showAnimations;
00098     KHTMLSettings::KSmoothScrollingMode m_smoothScrolling;
00099     KHTMLSettings::KDNSPrefetch m_dnsPrefetch;
00100 
00101     QString m_encoding;
00102     QString m_userSheet;
00103 
00104     QColor m_textColor;
00105     QColor m_baseColor;
00106     QColor m_linkColor;
00107     QColor m_vLinkColor;
00108 
00109     PolicyMap domainPolicy;
00110     QStringList fonts;
00111     QStringList defaultFonts;
00112 
00113     khtml::FilterSet adBlackList;
00114     khtml::FilterSet adWhiteList;
00115     QList< QPair< QString, QChar > > m_fallbackAccessKeysAssignments;
00116 };
00117 
00118 
00122 static KPerDomainSettings &setup_per_domain_policy(
00123                 KHTMLSettingsPrivate* const d,
00124                 const QString &domain) {
00125   if (domain.isEmpty()) {
00126     kWarning() << "setup_per_domain_policy: domain is empty";
00127   }
00128   const QString ldomain = domain.toLower();
00129   PolicyMap::iterator it = d->domainPolicy.find(ldomain);
00130   if (it == d->domainPolicy.end()) {
00131     // simply copy global domain settings (they should have been initialized
00132     // by this time)
00133     it = d->domainPolicy.insert(ldomain,d->global);
00134   }
00135   return *it;
00136 }
00137 
00138 
00139 KHTMLSettings::KJavaScriptAdvice KHTMLSettings::strToAdvice(const QString& _str)
00140 {
00141   KJavaScriptAdvice ret = KJavaScriptDunno;
00142 
00143   if (_str.isNull())
00144         ret = KJavaScriptDunno;
00145 
00146   if (_str.toLower() == QLatin1String("accept"))
00147         ret = KJavaScriptAccept;
00148   else if (_str.toLower() == QLatin1String("reject"))
00149         ret = KJavaScriptReject;
00150 
00151   return ret;
00152 }
00153 
00154 const char* KHTMLSettings::adviceToStr(KJavaScriptAdvice _advice)
00155 {
00156     switch( _advice ) {
00157     case KJavaScriptAccept: return I18N_NOOP("Accept");
00158     case KJavaScriptReject: return I18N_NOOP("Reject");
00159     default: return 0;
00160     }
00161         return 0;
00162 }
00163 
00164 
00165 void KHTMLSettings::splitDomainAdvice(const QString& configStr, QString &domain,
00166                                       KJavaScriptAdvice &javaAdvice, KJavaScriptAdvice& javaScriptAdvice)
00167 {
00168     QString tmp(configStr);
00169     int splitIndex = tmp.indexOf(':');
00170     if ( splitIndex == -1)
00171     {
00172         domain = configStr.toLower();
00173         javaAdvice = KJavaScriptDunno;
00174         javaScriptAdvice = KJavaScriptDunno;
00175     }
00176     else
00177     {
00178         domain = tmp.left(splitIndex).toLower();
00179         QString adviceString = tmp.mid( splitIndex+1, tmp.length() );
00180         int splitIndex2 = adviceString.indexOf( ':' );
00181         if( splitIndex2 == -1 ) {
00182             // Java advice only
00183             javaAdvice = strToAdvice( adviceString );
00184             javaScriptAdvice = KJavaScriptDunno;
00185         } else {
00186             // Java and JavaScript advice
00187             javaAdvice = strToAdvice( adviceString.left( splitIndex2 ) );
00188             javaScriptAdvice = strToAdvice( adviceString.mid( splitIndex2+1,
00189                                                               adviceString.length() ) );
00190         }
00191     }
00192 }
00193 
00194 void KHTMLSettings::readDomainSettings(const KConfigGroup &config, bool reset,
00195     bool global, KPerDomainSettings &pd_settings) {
00196   QString jsPrefix = global ? QString()
00197                 : QString::fromLatin1("javascript.");
00198   QString javaPrefix = global ? QString()
00199                 : QString::fromLatin1("java.");
00200   QString pluginsPrefix = global ? QString()
00201                 : QString::fromLatin1("plugins.");
00202 
00203   // The setting for Java
00204   QString key = javaPrefix + QLatin1String("EnableJava");
00205   if ( (global && reset) || config.hasKey( key ) )
00206     pd_settings.m_bEnableJava = config.readEntry( key, false );
00207   else if ( !global )
00208     pd_settings.m_bEnableJava = d->global.m_bEnableJava;
00209 
00210   // The setting for Plugins
00211   key = pluginsPrefix + QLatin1String("EnablePlugins");
00212   if ( (global && reset) || config.hasKey( key ) )
00213     pd_settings.m_bEnablePlugins = config.readEntry( key, true );
00214   else if ( !global )
00215     pd_settings.m_bEnablePlugins = d->global.m_bEnablePlugins;
00216 
00217   // The setting for JavaScript
00218   key = jsPrefix + QLatin1String("EnableJavaScript");
00219   if ( (global && reset) || config.hasKey( key ) )
00220     pd_settings.m_bEnableJavaScript = config.readEntry( key, true );
00221   else if ( !global )
00222     pd_settings.m_bEnableJavaScript = d->global.m_bEnableJavaScript;
00223 
00224   // window property policies
00225   key = jsPrefix + QLatin1String("WindowOpenPolicy");
00226   if ( (global && reset) || config.hasKey( key ) )
00227     pd_settings.m_windowOpenPolicy = (KJSWindowOpenPolicy)
00228             config.readEntry( key, uint(KJSWindowOpenSmart) );
00229   else if ( !global )
00230     pd_settings.m_windowOpenPolicy = d->global.m_windowOpenPolicy;
00231 
00232   key = jsPrefix + QLatin1String("WindowMovePolicy");
00233   if ( (global && reset) || config.hasKey( key ) )
00234     pd_settings.m_windowMovePolicy = (KJSWindowMovePolicy)
00235             config.readEntry( key, uint(KJSWindowMoveAllow) );
00236   else if ( !global )
00237     pd_settings.m_windowMovePolicy = d->global.m_windowMovePolicy;
00238 
00239   key = jsPrefix + QLatin1String("WindowResizePolicy");
00240   if ( (global && reset) || config.hasKey( key ) )
00241     pd_settings.m_windowResizePolicy = (KJSWindowResizePolicy)
00242             config.readEntry( key, uint(KJSWindowResizeAllow) );
00243   else if ( !global )
00244     pd_settings.m_windowResizePolicy = d->global.m_windowResizePolicy;
00245 
00246   key = jsPrefix + QLatin1String("WindowStatusPolicy");
00247   if ( (global && reset) || config.hasKey( key ) )
00248     pd_settings.m_windowStatusPolicy = (KJSWindowStatusPolicy)
00249             config.readEntry( key, uint(KJSWindowStatusAllow) );
00250   else if ( !global )
00251     pd_settings.m_windowStatusPolicy = d->global.m_windowStatusPolicy;
00252 
00253   key = jsPrefix + QLatin1String("WindowFocusPolicy");
00254   if ( (global && reset) || config.hasKey( key ) )
00255     pd_settings.m_windowFocusPolicy = (KJSWindowFocusPolicy)
00256             config.readEntry( key, uint(KJSWindowFocusAllow) );
00257   else if ( !global )
00258     pd_settings.m_windowFocusPolicy = d->global.m_windowFocusPolicy;
00259 
00260 }
00261 
00262 
00263 KHTMLSettings::KHTMLSettings()
00264     :d (new KHTMLSettingsPrivate())
00265 {
00266   init();
00267 }
00268 
00269 KHTMLSettings::KHTMLSettings(const KHTMLSettings &other)
00270     :d(new KHTMLSettingsPrivate())
00271 {
00272   *d = *other.d;
00273 }
00274 
00275 KHTMLSettings::~KHTMLSettings()
00276 {
00277   delete d;
00278 }
00279 
00280 bool KHTMLSettings::changeCursor() const
00281 {
00282   return d->m_bChangeCursor;
00283 }
00284 
00285 bool KHTMLSettings::underlineLink() const
00286 {
00287   return d->m_underlineLink;
00288 }
00289 
00290 bool KHTMLSettings::hoverLink() const
00291 {
00292   return d->m_hoverLink;
00293 }
00294 
00295 void KHTMLSettings::init()
00296 {
00297   KConfig global( "khtmlrc", KConfig::NoGlobals );
00298   init( &global, true );
00299 
00300   KSharedConfig::Ptr local = KGlobal::config();
00301   if ( !local )
00302     return;
00303 
00304   init( local.data(), false );
00305 }
00306 
00307 void KHTMLSettings::init( KConfig * config, bool reset )
00308 {
00309   KConfigGroup cg( config, "MainView Settings" );
00310   if (reset || cg.exists() )
00311   {
00312     if ( reset || cg.hasKey( "OpenMiddleClick" ) )
00313         d->m_bOpenMiddleClick = cg.readEntry( "OpenMiddleClick", true );
00314 
00315     if ( reset || cg.hasKey( "BackRightClick" ) )
00316         d->m_bBackRightClick = cg.readEntry( "BackRightClick", false );
00317   }
00318 
00319   KConfigGroup cgAccess(config,"Access Keys" );
00320   if (reset || cgAccess.exists() ) {
00321       d->m_accessKeysEnabled = cgAccess.readEntry( "Enabled", true );
00322   }
00323 
00324   KConfigGroup cgFilter( config, "Filter Settings" );
00325 
00326   if (reset || cgFilter.exists() )
00327   {
00328       d->m_adFilterEnabled = cgFilter.readEntry("Enabled", false);
00329       d->m_hideAdsEnabled = cgFilter.readEntry("Shrink", false);
00330 
00331       d->adBlackList.clear();
00332       d->adWhiteList.clear();
00333 
00334       QMap<QString,QString> entryMap = cgFilter.entryMap();
00335       QMap<QString,QString>::ConstIterator it;
00336       for( it = entryMap.constBegin(); it != entryMap.constEnd(); ++it )
00337       {
00338           QString name = it.key();
00339           QString url = it.value();
00340 
00341           if (name.startsWith("Filter"))
00342           {
00343               if (url.startsWith(QLatin1String("@@")))
00344                   d->adWhiteList.addFilter(url);
00345               else
00346                   d->adBlackList.addFilter(url);
00347           }
00348       }
00349   }
00350 
00351   KConfigGroup cgHtml( config, "HTML Settings" );
00352   if (reset || cgHtml.exists() )
00353   {
00354     // Fonts and colors
00355     if( reset ) {
00356         d->defaultFonts = QStringList();
00357         d->defaultFonts.append( cgHtml.readEntry( "StandardFont", KGlobalSettings::generalFont().family() ) );
00358         d->defaultFonts.append( cgHtml.readEntry( "FixedFont", KGlobalSettings::fixedFont().family() ) );
00359         d->defaultFonts.append( cgHtml.readEntry( "SerifFont", HTML_DEFAULT_VIEW_SERIF_FONT ) );
00360         d->defaultFonts.append( cgHtml.readEntry( "SansSerifFont", HTML_DEFAULT_VIEW_SANSSERIF_FONT ) );
00361         d->defaultFonts.append( cgHtml.readEntry( "CursiveFont", HTML_DEFAULT_VIEW_CURSIVE_FONT ) );
00362         d->defaultFonts.append( cgHtml.readEntry( "FantasyFont", HTML_DEFAULT_VIEW_FANTASY_FONT ) );
00363         d->defaultFonts.append( QString( "0" ) ); // font size adjustment
00364     }
00365 
00366     if ( reset || cgHtml.hasKey( "MinimumFontSize" ) )
00367         d->m_minFontSize = cgHtml.readEntry( "MinimumFontSize", HTML_DEFAULT_MIN_FONT_SIZE );
00368 
00369     if ( reset || cgHtml.hasKey( "MediumFontSize" ) )
00370         d->m_fontSize = cgHtml.readEntry( "MediumFontSize", 12 );
00371 
00372     d->fonts = cgHtml.readEntry( "Fonts", QStringList() );
00373 
00374     if ( reset || cgHtml.hasKey( "DefaultEncoding" ) )
00375         d->m_encoding = cgHtml.readEntry( "DefaultEncoding", "" );
00376 
00377     if ( reset || cgHtml.hasKey( "EnforceDefaultCharset" ) )
00378         d->enforceCharset = cgHtml.readEntry( "EnforceDefaultCharset", false );
00379 
00380     // Behavior
00381     if ( reset || cgHtml.hasKey( "ChangeCursor" ) )
00382         d->m_bChangeCursor = cgHtml.readEntry( "ChangeCursor", KDE_DEFAULT_CHANGECURSOR );
00383 
00384     if ( reset || cgHtml.hasKey("UnderlineLinks") )
00385         d->m_underlineLink = cgHtml.readEntry( "UnderlineLinks", true );
00386 
00387     if ( reset || cgHtml.hasKey( "HoverLinks" ) )
00388     {
00389         if ( (d->m_hoverLink = cgHtml.readEntry( "HoverLinks", false )))
00390             d->m_underlineLink = false;
00391     }
00392 
00393     if ( reset || cgHtml.hasKey( "AllowTabulation" ) )
00394         d->m_allowTabulation = cgHtml.readEntry( "AllowTabulation", false );
00395 
00396     if ( reset || cgHtml.hasKey( "AutoSpellCheck" ) )
00397         d->m_autoSpellCheck = cgHtml.readEntry( "AutoSpellCheck", true );
00398 
00399     // Other
00400     if ( reset || cgHtml.hasKey( "AutoLoadImages" ) )
00401       d->m_bAutoLoadImages = cgHtml.readEntry( "AutoLoadImages", true );
00402 
00403     if ( reset || cgHtml.hasKey( "UnfinishedImageFrame" ) )
00404       d->m_bUnfinishedImageFrame = cgHtml.readEntry( "UnfinishedImageFrame", true );
00405 
00406     if ( reset || cgHtml.hasKey( "ShowAnimations" ) )
00407     {
00408       QString value = cgHtml.readEntry( "ShowAnimations").toLower();
00409       if (value == "disabled")
00410          d->m_showAnimations = KAnimationDisabled;
00411       else if (value == "looponce")
00412          d->m_showAnimations = KAnimationLoopOnce;
00413       else
00414          d->m_showAnimations = KAnimationEnabled;
00415     }
00416 
00417     if ( reset || cgHtml.hasKey( "SmoothScrolling" ) )
00418     {
00419       QString value = cgHtml.readEntry( "SmoothScrolling", "whenefficient" ).toLower();
00420       if (value == "disabled")
00421          d->m_smoothScrolling = KSmoothScrollingDisabled;
00422       else if (value == "whenefficient")
00423          d->m_smoothScrolling = KSmoothScrollingWhenEfficient;
00424       else
00425          d->m_smoothScrolling = KSmoothScrollingEnabled;
00426     }
00427 
00428     if ( reset || cgHtml.hasKey( "DNSPrefetch" ) )
00429     {
00430       // Enabled, Disabled, OnlyWWWAndSLD
00431       QString value = cgHtml.readEntry( "DNSPrefetch", "Enabled" ).toLower();
00432       if (value == "enabled")
00433          d->m_dnsPrefetch = KDNSPrefetchEnabled;
00434       else if (value == "onlywwwandsld")
00435          d->m_dnsPrefetch = KDNSPrefetchOnlyWWWAndSLD;
00436       else
00437          d->m_dnsPrefetch = KDNSPrefetchDisabled;
00438     }
00439 
00440     if ( cgHtml.readEntry( "UserStyleSheetEnabled", false ) == true ) {
00441         if ( reset || cgHtml.hasKey( "UserStyleSheet" ) )
00442             d->m_userSheet = cgHtml.readEntry( "UserStyleSheet", "" );
00443     }
00444 
00445     d->m_formCompletionEnabled = cgHtml.readEntry("FormCompletion", true);
00446     d->m_maxFormCompletionItems = cgHtml.readEntry("MaxFormCompletionItems", 10);
00447     d->m_autoDelayedActionsEnabled = cgHtml.readEntry ("AutoDelayedActions", true);
00448     d->m_jsErrorsEnabled = cgHtml.readEntry("ReportJSErrors", true);
00449     const QStringList accesskeys = cgHtml.readEntry("FallbackAccessKeysAssignments", QStringList());
00450     d->m_fallbackAccessKeysAssignments.clear();
00451     for( QStringList::ConstIterator it = accesskeys.begin(); it != accesskeys.end(); ++it )
00452         if( (*it).length() > 2 && (*it)[ 1 ] == ':' )
00453             d->m_fallbackAccessKeysAssignments.append( qMakePair( (*it).mid( 2 ), (*it)[ 0 ] ));
00454   }
00455 
00456   // Colors
00457   //In which group ?????
00458   if ( reset || cg.hasKey( "FollowSystemColors" ) )
00459       d->m_follow_system_colors = cg.readEntry( "FollowSystemColors", false );
00460 
00461   KConfigGroup cgGeneral( config, "General" );
00462   if ( reset || cgGeneral.exists( ) )
00463   {
00464     if ( reset || cgGeneral.hasKey( "foreground" ) ) {
00465       QColor def(HTML_DEFAULT_TXT_COLOR);
00466       d->m_textColor = cgGeneral.readEntry( "foreground", def );
00467     }
00468 
00469     if ( reset || cgGeneral.hasKey( "linkColor" ) ) {
00470       QColor def(HTML_DEFAULT_LNK_COLOR);
00471       d->m_linkColor = cgGeneral.readEntry( "linkColor", def );
00472     }
00473 
00474     if ( reset || cgGeneral.hasKey( "visitedLinkColor" ) ) {
00475       QColor def(HTML_DEFAULT_VLNK_COLOR);
00476       d->m_vLinkColor = cgGeneral.readEntry( "visitedLinkColor", def);
00477     }
00478 
00479     if ( reset || cgGeneral.hasKey( "background" ) ) {
00480       QColor def(HTML_DEFAULT_BASE_COLOR);
00481       d->m_baseColor = cgGeneral.readEntry( "background", def);
00482     }
00483   }
00484 
00485   KConfigGroup cgJava( config, "Java/JavaScript Settings" );
00486   if( reset || cgJava.exists() )
00487   {
00488     // The global setting for JavaScript debugging
00489     // This is currently always enabled by default
00490     if ( reset || cgJava.hasKey( "EnableJavaScriptDebug" ) )
00491       d->m_bEnableJavaScriptDebug = cgJava.readEntry( "EnableJavaScriptDebug", false );
00492 
00493     // The global setting for JavaScript error reporting
00494     if ( reset || cgJava.hasKey( "ReportJavaScriptErrors" ) )
00495       d->m_bEnableJavaScriptErrorReporting = cgJava.readEntry( "ReportJavaScriptErrors", false );
00496 
00497     // The global setting for popup block passive popup
00498     if ( reset || cgJava.hasKey( "PopupBlockerPassivePopup" ) )
00499       d->m_jsPopupBlockerPassivePopup = cgJava.readEntry("PopupBlockerPassivePopup", true );
00500 
00501     // Read options from the global "domain"
00502     readDomainSettings(cgJava,reset,true,d->global);
00503 #ifdef DEBUG_SETTINGS
00504     d->global.dump("init global");
00505 #endif
00506 
00507     // The domain-specific settings.
00508 
00509     static const char *const domain_keys[] = {  // always keep order of keys
00510         "ECMADomains", "JavaDomains", "PluginDomains"
00511     };
00512     bool check_old_ecma_settings = true;
00513     bool check_old_java_settings = true;
00514     // merge all domains into one list
00515     QMap<QString,int> domainList;   // why can't Qt have a QSet?
00516     for (unsigned i = 0; i < sizeof domain_keys/sizeof domain_keys[0]; ++i) {
00517       if ( reset || cgJava.hasKey(domain_keys[i]) ) {
00518         if (i == 0) check_old_ecma_settings = false;
00519     else if (i == 1) check_old_java_settings = false;
00520         const QStringList dl = cgJava.readEntry( domain_keys[i], QStringList() );
00521     const QMap<QString,int>::Iterator notfound = domainList.end();
00522     QStringList::ConstIterator it = dl.begin();
00523     const QStringList::ConstIterator itEnd = dl.end();
00524     for (; it != itEnd; ++it) {
00525       const QString domain = (*it).toLower();
00526       QMap<QString,int>::Iterator pos = domainList.find(domain);
00527       if (pos == notfound) domainList.insert(domain,0);
00528     }/*next it*/
00529       }
00530     }/*next i*/
00531 
00532     if (reset)
00533       d->domainPolicy.clear();
00534 
00535     {
00536       QMap<QString,int>::ConstIterator it = domainList.constBegin();
00537       const QMap<QString,int>::ConstIterator itEnd = domainList.constEnd();
00538       for ( ; it != itEnd; ++it)
00539       {
00540         const QString domain = it.key();
00541         KConfigGroup cg( config, domain );
00542         readDomainSettings(cg,reset,false,d->domainPolicy[domain]);
00543 #ifdef DEBUG_SETTINGS
00544         d->domainPolicy[domain].dump("init "+domain);
00545 #endif
00546       }
00547     }
00548 
00549     bool check_old_java = true;
00550     if( ( reset || cgJava.hasKey( "JavaDomainSettings" ) )
00551         && check_old_java_settings )
00552     {
00553       check_old_java = false;
00554       const QStringList domainList = cgJava.readEntry( "JavaDomainSettings", QStringList() );
00555       QStringList::ConstIterator it = domainList.constBegin();
00556       const QStringList::ConstIterator itEnd = domainList.constEnd();
00557       for ( ; it != itEnd; ++it)
00558       {
00559         QString domain;
00560         KJavaScriptAdvice javaAdvice;
00561         KJavaScriptAdvice javaScriptAdvice;
00562         splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice);
00563         setup_per_domain_policy(d,domain).m_bEnableJava =
00564         javaAdvice == KJavaScriptAccept;
00565 #ifdef DEBUG_SETTINGS
00566     setup_per_domain_policy(d,domain).dump("JavaDomainSettings 4 "+domain);
00567 #endif
00568       }
00569     }
00570 
00571     bool check_old_ecma = true;
00572     if( ( reset || cgJava.hasKey( "ECMADomainSettings" ) )
00573     && check_old_ecma_settings )
00574     {
00575       check_old_ecma = false;
00576       const QStringList domainList = cgJava.readEntry( "ECMADomainSettings", QStringList() );
00577       QStringList::ConstIterator it = domainList.constBegin();
00578       const QStringList::ConstIterator itEnd = domainList.constEnd();
00579       for ( ; it != itEnd; ++it)
00580       {
00581         QString domain;
00582         KJavaScriptAdvice javaAdvice;
00583         KJavaScriptAdvice javaScriptAdvice;
00584         splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice);
00585         setup_per_domain_policy(d,domain).m_bEnableJavaScript =
00586             javaScriptAdvice == KJavaScriptAccept;
00587 #ifdef DEBUG_SETTINGS
00588     setup_per_domain_policy(d,domain).dump("ECMADomainSettings 4 "+domain);
00589 #endif
00590       }
00591     }
00592 
00593     if( ( reset || cgJava.hasKey( "JavaScriptDomainAdvice" ) )
00594              && ( check_old_java || check_old_ecma )
00595          && ( check_old_ecma_settings || check_old_java_settings ) )
00596     {
00597       const QStringList domainList = cgJava.readEntry( "JavaScriptDomainAdvice", QStringList() );
00598       QStringList::ConstIterator it = domainList.constBegin();
00599       const QStringList::ConstIterator itEnd = domainList.constEnd();
00600       for ( ; it != itEnd; ++it)
00601       {
00602         QString domain;
00603         KJavaScriptAdvice javaAdvice;
00604         KJavaScriptAdvice javaScriptAdvice;
00605         splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice);
00606         if( check_old_java )
00607           setup_per_domain_policy(d,domain).m_bEnableJava =
00608             javaAdvice == KJavaScriptAccept;
00609         if( check_old_ecma )
00610           setup_per_domain_policy(d,domain).m_bEnableJavaScript =
00611             javaScriptAdvice == KJavaScriptAccept;
00612 #ifdef DEBUG_SETTINGS
00613     setup_per_domain_policy(d,domain).dump("JavaScriptDomainAdvice 4 "+domain);
00614 #endif
00615       }
00616 
00617       //save all the settings into the new keywords if they don't exist
00618 #if 0
00619       if( check_old_java )
00620       {
00621         QStringList domainConfig;
00622         PolicyMap::Iterator it;
00623         for( it = d->javaDomainPolicy.begin(); it != d->javaDomainPolicy.end(); ++it )
00624         {
00625           QByteArray javaPolicy = adviceToStr( it.value() );
00626           QByteArray javaScriptPolicy = adviceToStr( KJavaScriptDunno );
00627           domainConfig.append(QString::fromLatin1("%1:%2:%3").arg(it.key()).arg(javaPolicy).arg(javaScriptPolicy));
00628         }
00629         cg.writeEntry( "JavaDomainSettings", domainConfig );
00630       }
00631 
00632       if( check_old_ecma )
00633       {
00634         QStringList domainConfig;
00635         PolicyMap::Iterator it;
00636         for( it = d->javaScriptDomainPolicy.begin(); it != d->javaScriptDomainPolicy.end(); ++it )
00637         {
00638           QByteArray javaPolicy = adviceToStr( KJavaScriptDunno );
00639           QByteArray javaScriptPolicy = adviceToStr( it.value() );
00640           domainConfig.append(QString::fromLatin1("%1:%2:%3").arg(it.key()).arg(javaPolicy).arg(javaScriptPolicy));
00641         }
00642         cg.writeEntry( "ECMADomainSettings", domainConfig );
00643       }
00644 #endif
00645     }
00646   }
00647 }
00648 
00649 
00654 static const KPerDomainSettings &lookup_hostname_policy(
00655             const KHTMLSettingsPrivate* const d,
00656             const QString& hostname)
00657 {
00658 #ifdef DEBUG_SETTINGS
00659   kDebug() << "lookup_hostname_policy(" << hostname << ")";
00660 #endif
00661   if (hostname.isEmpty()) {
00662 #ifdef DEBUG_SETTINGS
00663     d->global.dump("global");
00664 #endif
00665     return d->global;
00666   }
00667 
00668   const PolicyMap::const_iterator notfound = d->domainPolicy.constEnd();
00669 
00670   // First check whether there is a perfect match.
00671   PolicyMap::const_iterator it = d->domainPolicy.find(hostname);
00672   if( it != notfound ) {
00673 #ifdef DEBUG_SETTINGS
00674     kDebug() << "perfect match";
00675     (*it).dump(hostname);
00676 #endif
00677     // yes, use it (unless dunno)
00678     return *it;
00679   }
00680 
00681   // Now, check for partial match.  Chop host from the left until
00682   // there's no dots left.
00683   QString host_part = hostname;
00684   int dot_idx = -1;
00685   while( (dot_idx = host_part.indexOf(QChar('.'))) >= 0 ) {
00686     host_part.remove(0,dot_idx);
00687     it = d->domainPolicy.find(host_part);
00688     Q_ASSERT(notfound == d->domainPolicy.end());
00689     if( it != notfound ) {
00690 #ifdef DEBUG_SETTINGS
00691       kDebug() << "partial match";
00692       (*it).dump(host_part);
00693 #endif
00694       return *it;
00695     }
00696     // assert(host_part[0] == QChar('.'));
00697     host_part.remove(0,1); // Chop off the dot.
00698   }
00699 
00700   // No domain-specific entry: use global domain
00701 #ifdef DEBUG_SETTINGS
00702   kDebug() << "no match";
00703   d->global.dump("global");
00704 #endif
00705   return d->global;
00706 }
00707 
00708 bool KHTMLSettings::isOpenMiddleClickEnabled()
00709 {
00710   return d->m_bOpenMiddleClick;
00711 }
00712 
00713 bool KHTMLSettings::isBackRightClickEnabled()
00714 {
00715   return d->m_bBackRightClick;
00716 }
00717 
00718 bool KHTMLSettings::accessKeysEnabled() const
00719 {
00720     return d->m_accessKeysEnabled;
00721 }
00722 
00723 bool KHTMLSettings::isAdFilterEnabled() const
00724 {
00725     return d->m_adFilterEnabled;
00726 }
00727 
00728 bool KHTMLSettings::isHideAdsEnabled() const
00729 {
00730     return d->m_hideAdsEnabled;
00731 }
00732 
00733 bool KHTMLSettings::isAdFiltered( const QString &url ) const
00734 {
00735     if (d->m_adFilterEnabled)
00736     {
00737         if (!url.startsWith("data:"))
00738         {
00739             // Check the blacklist, and only if that matches, the whitelist
00740             return d->adBlackList.isUrlMatched(url) && !d->adWhiteList.isUrlMatched(url);
00741         }
00742     }
00743     return false;
00744 }
00745 
00746 void KHTMLSettings::addAdFilter( const QString &url )
00747 {
00748     KConfigGroup config = KSharedConfig::openConfig( "khtmlrc", KConfig::NoGlobals )->group( "Filter Settings" );
00749 
00750     QRegExp rx;
00751     
00752     // Try compiling to avoid invalid stuff. Only support the basic syntax here...
00753     // ### refactor somewhat
00754     if (url.length()>2 && url[0]=='/' && url[url.length()-1] == '/')
00755     {
00756         QString inside = url.mid(1, url.length()-2);
00757         rx.setPattern(inside);
00758     }
00759     else
00760     {
00761         rx.setPatternSyntax(QRegExp::Wildcard);
00762         rx.setPattern(url);
00763     }
00764 
00765     if (rx.isValid())
00766     {
00767         int last=config.readEntry("Count", 0);
00768         QString key = "Filter-" + QString::number(last);
00769         config.writeEntry(key, url);
00770         config.writeEntry("Count",last+1);
00771         config.sync();
00772         if (url.startsWith(QLatin1String("@@")))
00773              d->adWhiteList.addFilter(url);
00774         else
00775              d->adBlackList.addFilter(url);
00776     }
00777     else
00778     {
00779         KMessageBox::error(0,
00780                            rx.errorString(),
00781                            i18n("Filter error"));
00782     }
00783 }
00784 
00785 bool KHTMLSettings::isJavaEnabled( const QString& hostname ) const
00786 {
00787   return lookup_hostname_policy(d,hostname.toLower()).m_bEnableJava;
00788 }
00789 
00790 bool KHTMLSettings::isJavaScriptEnabled( const QString& hostname ) const
00791 {
00792   return lookup_hostname_policy(d,hostname.toLower()).m_bEnableJavaScript;
00793 }
00794 
00795 bool KHTMLSettings::isJavaScriptDebugEnabled( const QString& /*hostname*/ ) const
00796 {
00797   // debug setting is global for now, but could change in the future
00798   return d->m_bEnableJavaScriptDebug;
00799 }
00800 
00801 bool KHTMLSettings::isJavaScriptErrorReportingEnabled( const QString& /*hostname*/ ) const
00802 {
00803   // error reporting setting is global for now, but could change in the future
00804   return d->m_bEnableJavaScriptErrorReporting;
00805 }
00806 
00807 bool KHTMLSettings::isPluginsEnabled( const QString& hostname ) const
00808 {
00809   return lookup_hostname_policy(d,hostname.toLower()).m_bEnablePlugins;
00810 }
00811 
00812 KHTMLSettings::KJSWindowOpenPolicy KHTMLSettings::windowOpenPolicy(
00813                 const QString& hostname) const {
00814   return lookup_hostname_policy(d,hostname.toLower()).m_windowOpenPolicy;
00815 }
00816 
00817 KHTMLSettings::KJSWindowMovePolicy KHTMLSettings::windowMovePolicy(
00818                 const QString& hostname) const {
00819   return lookup_hostname_policy(d,hostname.toLower()).m_windowMovePolicy;
00820 }
00821 
00822 KHTMLSettings::KJSWindowResizePolicy KHTMLSettings::windowResizePolicy(
00823                 const QString& hostname) const {
00824   return lookup_hostname_policy(d,hostname.toLower()).m_windowResizePolicy;
00825 }
00826 
00827 KHTMLSettings::KJSWindowStatusPolicy KHTMLSettings::windowStatusPolicy(
00828                 const QString& hostname) const {
00829   return lookup_hostname_policy(d,hostname.toLower()).m_windowStatusPolicy;
00830 }
00831 
00832 KHTMLSettings::KJSWindowFocusPolicy KHTMLSettings::windowFocusPolicy(
00833                 const QString& hostname) const {
00834   return lookup_hostname_policy(d,hostname.toLower()).m_windowFocusPolicy;
00835 }
00836 
00837 int KHTMLSettings::mediumFontSize() const
00838 {
00839     return d->m_fontSize;
00840 }
00841 
00842 int KHTMLSettings::minFontSize() const
00843 {
00844   return d->m_minFontSize;
00845 }
00846 
00847 QString KHTMLSettings::settingsToCSS() const
00848 {
00849     // lets start with the link properties
00850     QString str = "a:link {\ncolor: ";
00851     str += d->m_linkColor.name();
00852     str += ';';
00853     if(d->m_underlineLink)
00854         str += "\ntext-decoration: underline;";
00855 
00856     if( d->m_bChangeCursor )
00857     {
00858         str += "\ncursor: pointer;";
00859         str += "\n}\ninput[type=image] { cursor: pointer;";
00860     }
00861     str += "\n}\n";
00862     str += "a:visited {\ncolor: ";
00863     str += d->m_vLinkColor.name();
00864     str += ';';
00865     if(d->m_underlineLink)
00866         str += "\ntext-decoration: underline;";
00867 
00868     if( d->m_bChangeCursor )
00869         str += "\ncursor: pointer;";
00870     str += "\n}\n";
00871 
00872     if(d->m_hoverLink)
00873         str += "a:link:hover, a:visited:hover { text-decoration: underline; }\n";
00874 
00875     return str;
00876 }
00877 
00878 const QString &KHTMLSettings::availableFamilies()
00879 {
00880     if ( !avFamilies ) {
00881         avFamilies = new QString;
00882         QFontDatabase db;
00883         QStringList families = db.families();
00884         QStringList s;
00885         QRegExp foundryExp(" \\[.+\\]");
00886 
00887         //remove foundry info
00888         QStringList::Iterator f = families.begin();
00889         const QStringList::Iterator fEnd = families.end();
00890 
00891         for ( ; f != fEnd; ++f ) {
00892                 (*f).replace( foundryExp, "");
00893                 if (!s.contains(*f))
00894                         s << *f;
00895         }
00896         s.sort();
00897 
00898         *avFamilies = ',' + s.join(",") + ',';
00899     }
00900 
00901   return *avFamilies;
00902 }
00903 
00904 QString KHTMLSettings::lookupFont(int i) const
00905 {
00906     QString font;
00907     if (d->fonts.count() > i)
00908        font = d->fonts[i];
00909     if (font.isEmpty())
00910         font = d->defaultFonts[i];
00911     return font;
00912 }
00913 
00914 QString KHTMLSettings::stdFontName() const
00915 {
00916     return lookupFont(0);
00917 }
00918 
00919 QString KHTMLSettings::fixedFontName() const
00920 {
00921     return lookupFont(1);
00922 }
00923 
00924 QString KHTMLSettings::serifFontName() const
00925 {
00926     return lookupFont(2);
00927 }
00928 
00929 QString KHTMLSettings::sansSerifFontName() const
00930 {
00931     return lookupFont(3);
00932 }
00933 
00934 QString KHTMLSettings::cursiveFontName() const
00935 {
00936     return lookupFont(4);
00937 }
00938 
00939 QString KHTMLSettings::fantasyFontName() const
00940 {
00941     return lookupFont(5);
00942 }
00943 
00944 void KHTMLSettings::setStdFontName(const QString &n)
00945 {
00946     while(d->fonts.count() <= 0)
00947         d->fonts.append(QString());
00948     d->fonts[0] = n;
00949 }
00950 
00951 void KHTMLSettings::setFixedFontName(const QString &n)
00952 {
00953     while(d->fonts.count() <= 1)
00954         d->fonts.append(QString());
00955     d->fonts[1] = n;
00956 }
00957 
00958 QString KHTMLSettings::userStyleSheet() const
00959 {
00960     return d->m_userSheet;
00961 }
00962 
00963 bool KHTMLSettings::isFormCompletionEnabled() const
00964 {
00965   return d->m_formCompletionEnabled;
00966 }
00967 
00968 int KHTMLSettings::maxFormCompletionItems() const
00969 {
00970   return d->m_maxFormCompletionItems;
00971 }
00972 
00973 const QString &KHTMLSettings::encoding() const
00974 {
00975   return d->m_encoding;
00976 }
00977 
00978 bool KHTMLSettings::followSystemColors() const
00979 {
00980     return d->m_follow_system_colors;
00981 }
00982 
00983 const QColor& KHTMLSettings::textColor() const
00984 {
00985   return d->m_textColor;
00986 }
00987 
00988 const QColor& KHTMLSettings::baseColor() const
00989 {
00990   return d->m_baseColor;
00991 }
00992 
00993 const QColor& KHTMLSettings::linkColor() const
00994 {
00995   return d->m_linkColor;
00996 }
00997 
00998 const QColor& KHTMLSettings::vLinkColor() const
00999 {
01000   return d->m_vLinkColor;
01001 }
01002 
01003 bool KHTMLSettings::autoLoadImages() const
01004 {
01005   return d->m_bAutoLoadImages;
01006 }
01007 
01008 bool KHTMLSettings::unfinishedImageFrame() const
01009 {
01010   return d->m_bUnfinishedImageFrame;
01011 }
01012 
01013 KHTMLSettings::KAnimationAdvice KHTMLSettings::showAnimations() const
01014 {
01015   return d->m_showAnimations;
01016 }
01017 
01018 KHTMLSettings::KSmoothScrollingMode KHTMLSettings::smoothScrolling() const
01019 {
01020   return d->m_smoothScrolling;
01021 }
01022 
01023 KHTMLSettings::KDNSPrefetch KHTMLSettings::dnsPrefetch() const
01024 {
01025   return d->m_dnsPrefetch;
01026 }
01027 
01028 bool KHTMLSettings::isAutoDelayedActionsEnabled() const
01029 {
01030   return d->m_autoDelayedActionsEnabled;
01031 }
01032 
01033 bool KHTMLSettings::jsErrorsEnabled() const
01034 {
01035   return d->m_jsErrorsEnabled;
01036 }
01037 
01038 void KHTMLSettings::setJSErrorsEnabled(bool enabled)
01039 {
01040   d->m_jsErrorsEnabled = enabled;
01041   // save it
01042   KConfigGroup cg( KGlobal::config(), "HTML Settings");
01043   cg.writeEntry("ReportJSErrors", enabled);
01044   cg.sync();
01045 }
01046 
01047 bool KHTMLSettings::allowTabulation() const
01048 {
01049     return d->m_allowTabulation;
01050 }
01051 
01052 bool KHTMLSettings::autoSpellCheck() const
01053 {
01054     return d->m_autoSpellCheck;
01055 }
01056 
01057 QList< QPair< QString, QChar > > KHTMLSettings::fallbackAccessKeysAssignments() const
01058 {
01059     return d->m_fallbackAccessKeysAssignments;
01060 }
01061 
01062 void KHTMLSettings::setJSPopupBlockerPassivePopup(bool enabled)
01063 {
01064     d->m_jsPopupBlockerPassivePopup = enabled;
01065     // save it
01066     KConfigGroup cg( KGlobal::config(), "Java/JavaScript Settings");
01067     cg.writeEntry("PopupBlockerPassivePopup", enabled);
01068     cg.sync();
01069 }
01070 
01071 bool KHTMLSettings::jsPopupBlockerPassivePopup() const
01072 {
01073     return d->m_jsPopupBlockerPassivePopup;
01074 }

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal