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

KHTML

khtml_settings.cc

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

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
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
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