⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 khtml_settings.cc

📁 konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版本源码包.
💻 CC
📖 第 1 页 / 共 3 页
字号:
/* This file is part of the KDE project   Copyright (C) 1999 David Faure <faure@kde.org>   This library is free software; you can redistribute it and/or   modify it under the terms of the GNU Library General Public   License as published by the Free Software Foundation; either   version 2 of the License, or (at your option) any later version.   This library is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   Library General Public License for more details.   You should have received a copy of the GNU Library General Public License   along with this library; see the file COPYING.LIB.  If not, write to   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,   Boston, MA 02110-1301, USA.*/#include <qfontdatabase.h>#include "khtml_settings.h"#include "khtmldefaults.h"#include <kglobalsettings.h>#include <kconfig.h>#include <kglobal.h>#include <klocale.h>#include <kdebug.h>#include <qregexp.h>#include <qvaluevector.h>#include <kmessagebox.h>/** * @internal * Contains all settings which are both available globally and per-domain */struct KPerDomainSettings {    bool m_bEnableJava : 1;    bool m_bEnableJavaScript : 1;    bool m_bEnablePlugins : 1;    // don't forget to maintain the bitfields as the enums grow    KHTMLSettings::KJSWindowOpenPolicy m_windowOpenPolicy : 2;    KHTMLSettings::KJSWindowStatusPolicy m_windowStatusPolicy : 1;    KHTMLSettings::KJSWindowFocusPolicy m_windowFocusPolicy : 1;    KHTMLSettings::KJSWindowMovePolicy m_windowMovePolicy : 1;    KHTMLSettings::KJSWindowResizePolicy m_windowResizePolicy : 1;#ifdef DEBUG_SETTINGS    void dump(const QString &infix = QString::null) const {      kdDebug() << "KPerDomainSettings " << infix << " @" << this << ":" << endl;      kdDebug() << "  m_bEnableJava: " << m_bEnableJava << endl;      kdDebug() << "  m_bEnableJavaScript: " << m_bEnableJavaScript << endl;      kdDebug() << "  m_bEnablePlugins: " << m_bEnablePlugins << endl;      kdDebug() << "  m_windowOpenPolicy: " << m_windowOpenPolicy << endl;      kdDebug() << "  m_windowStatusPolicy: " << m_windowStatusPolicy << endl;      kdDebug() << "  m_windowFocusPolicy: " << m_windowFocusPolicy << endl;      kdDebug() << "  m_windowMovePolicy: " << m_windowMovePolicy << endl;      kdDebug() << "  m_windowResizePolicy: " << m_windowResizePolicy << endl;    }#endif};typedef QMap<QString,KPerDomainSettings> PolicyMap;class KHTMLSettingsPrivate{public:    bool m_bChangeCursor : 1;    bool m_bOpenMiddleClick : 1;    bool m_bBackRightClick : 1;    bool m_underlineLink : 1;    bool m_hoverLink : 1;    bool m_bEnableJavaScriptDebug : 1;    bool m_bEnableJavaScriptErrorReporting : 1;    bool enforceCharset : 1;    bool m_bAutoLoadImages : 1;    bool m_bUnfinishedImageFrame : 1;    bool m_formCompletionEnabled : 1;    bool m_autoDelayedActionsEnabled : 1;    bool m_jsErrorsEnabled : 1;    bool m_follow_system_colors : 1;    bool m_allowTabulation : 1;    bool m_autoSpellCheck : 1;    bool m_adFilterEnabled : 1;    bool m_hideAdsEnabled : 1;    bool m_jsPopupBlockerPassivePopup : 1;    bool m_accessKeysEnabled : 1;    // the virtual global "domain"    KPerDomainSettings global;    int m_fontSize;    int m_minFontSize;    int m_maxFormCompletionItems;    KHTMLSettings::KAnimationAdvice m_showAnimations;    QString m_encoding;    QString m_userSheet;    QColor m_textColor;    QColor m_baseColor;    QColor m_linkColor;    QColor m_vLinkColor;    PolicyMap domainPolicy;    QStringList fonts;    QStringList defaultFonts;    QValueVector<QRegExp> adFilters;    QValueList< QPair< QString, QChar > > m_fallbackAccessKeysAssignments;};/** Returns a writeable per-domains settings instance for the given domain  * or a deep copy of the global settings if not existent.  */static KPerDomainSettings &setup_per_domain_policy(				KHTMLSettingsPrivate *d,				const QString &domain) {  if (domain.isEmpty()) {    kdWarning() << "setup_per_domain_policy: domain is empty" << endl;  }  const QString ldomain = domain.lower();  PolicyMap::iterator it = d->domainPolicy.find(ldomain);  if (it == d->domainPolicy.end()) {    // simply copy global domain settings (they should have been initialized    // by this time)    it = d->domainPolicy.insert(ldomain,d->global);  }  return *it;}KHTMLSettings::KJavaScriptAdvice KHTMLSettings::strToAdvice(const QString& _str){  KJavaScriptAdvice ret = KJavaScriptDunno;  if (!_str)        ret = KJavaScriptDunno;  if (_str.lower() == QString::fromLatin1("accept"))        ret = KJavaScriptAccept;  else if (_str.lower() == QString::fromLatin1("reject"))        ret = KJavaScriptReject;  return ret;}const char* KHTMLSettings::adviceToStr(KJavaScriptAdvice _advice){    switch( _advice ) {    case KJavaScriptAccept: return I18N_NOOP("Accept");    case KJavaScriptReject: return I18N_NOOP("Reject");    default: return 0;    }        return 0;}void KHTMLSettings::splitDomainAdvice(const QString& configStr, QString &domain,                                      KJavaScriptAdvice &javaAdvice, KJavaScriptAdvice& javaScriptAdvice){    QString tmp(configStr);    int splitIndex = tmp.find(':');    if ( splitIndex == -1)    {        domain = configStr.lower();        javaAdvice = KJavaScriptDunno;        javaScriptAdvice = KJavaScriptDunno;    }    else    {        domain = tmp.left(splitIndex).lower();        QString adviceString = tmp.mid( splitIndex+1, tmp.length() );        int splitIndex2 = adviceString.find( ':' );        if( splitIndex2 == -1 ) {            // Java advice only            javaAdvice = strToAdvice( adviceString );            javaScriptAdvice = KJavaScriptDunno;        } else {            // Java and JavaScript advice            javaAdvice = strToAdvice( adviceString.left( splitIndex2 ) );            javaScriptAdvice = strToAdvice( adviceString.mid( splitIndex2+1,                                                              adviceString.length() ) );        }    }}void KHTMLSettings::readDomainSettings(KConfig *config, bool reset,	bool global, KPerDomainSettings &pd_settings) {  QString jsPrefix = global ? QString::null  				: QString::fromLatin1("javascript.");  QString javaPrefix = global ? QString::null  				: QString::fromLatin1("java.");  QString pluginsPrefix = global ? QString::null  				: QString::fromLatin1("plugins.");  // The setting for Java  QString key = javaPrefix + QString::fromLatin1("EnableJava");  if ( (global && reset) || config->hasKey( key ) )    pd_settings.m_bEnableJava = config->readBoolEntry( key, false );  else if ( !global )    pd_settings.m_bEnableJava = d->global.m_bEnableJava;  // The setting for Plugins  key = pluginsPrefix + QString::fromLatin1("EnablePlugins");  if ( (global && reset) || config->hasKey( key ) )    pd_settings.m_bEnablePlugins = config->readBoolEntry( key, true );  else if ( !global )    pd_settings.m_bEnablePlugins = d->global.m_bEnablePlugins;  // The setting for JavaScript  key = jsPrefix + QString::fromLatin1("EnableJavaScript");  if ( (global && reset) || config->hasKey( key ) )    pd_settings.m_bEnableJavaScript = config->readBoolEntry( key, true );  else if ( !global )    pd_settings.m_bEnableJavaScript = d->global.m_bEnableJavaScript;  // window property policies  key = jsPrefix + QString::fromLatin1("WindowOpenPolicy");  if ( (global && reset) || config->hasKey( key ) )    pd_settings.m_windowOpenPolicy = (KJSWindowOpenPolicy)    		config->readUnsignedNumEntry( key, KJSWindowOpenSmart );  else if ( !global )    pd_settings.m_windowOpenPolicy = d->global.m_windowOpenPolicy;  key = jsPrefix + QString::fromLatin1("WindowMovePolicy");  if ( (global && reset) || config->hasKey( key ) )    pd_settings.m_windowMovePolicy = (KJSWindowMovePolicy)    		config->readUnsignedNumEntry( key, KJSWindowMoveAllow );  else if ( !global )    pd_settings.m_windowMovePolicy = d->global.m_windowMovePolicy;  key = jsPrefix + QString::fromLatin1("WindowResizePolicy");  if ( (global && reset) || config->hasKey( key ) )    pd_settings.m_windowResizePolicy = (KJSWindowResizePolicy)    		config->readUnsignedNumEntry( key, KJSWindowResizeAllow );  else if ( !global )    pd_settings.m_windowResizePolicy = d->global.m_windowResizePolicy;  key = jsPrefix + QString::fromLatin1("WindowStatusPolicy");  if ( (global && reset) || config->hasKey( key ) )    pd_settings.m_windowStatusPolicy = (KJSWindowStatusPolicy)    		config->readUnsignedNumEntry( key, KJSWindowStatusAllow );  else if ( !global )    pd_settings.m_windowStatusPolicy = d->global.m_windowStatusPolicy;  key = jsPrefix + QString::fromLatin1("WindowFocusPolicy");  if ( (global && reset) || config->hasKey( key ) )    pd_settings.m_windowFocusPolicy = (KJSWindowFocusPolicy)    		config->readUnsignedNumEntry( key, KJSWindowFocusAllow );  else if ( !global )    pd_settings.m_windowFocusPolicy = d->global.m_windowFocusPolicy;}KHTMLSettings::KHTMLSettings(){  d = new KHTMLSettingsPrivate();  init();}KHTMLSettings::KHTMLSettings(const KHTMLSettings &other){  d = new KHTMLSettingsPrivate();  *d = *other.d;}KHTMLSettings::~KHTMLSettings(){  delete d;}bool KHTMLSettings::changeCursor() const{  return d->m_bChangeCursor;}bool KHTMLSettings::underlineLink() const{  return d->m_underlineLink;}bool KHTMLSettings::hoverLink() const{  return d->m_hoverLink;}void KHTMLSettings::init(){  KConfig global( "khtmlrc", true, false );  init( &global, true );  KConfig *local = KGlobal::config();  if ( !local )    return;  init( local, false );}void KHTMLSettings::init( KConfig * config, bool reset ){  QString group_save = config->group();  if (reset || config->hasGroup("MainView Settings"))  {    config->setGroup( "MainView Settings" );    if ( reset || config->hasKey( "OpenMiddleClick" ) )        d->m_bOpenMiddleClick = config->readBoolEntry( "OpenMiddleClick", true );    if ( reset || config->hasKey( "BackRightClick" ) )        d->m_bBackRightClick = config->readBoolEntry( "BackRightClick", false );  }  if (reset || config->hasGroup("Access Keys")) {      config->setGroup( "Access Keys" );      d->m_accessKeysEnabled = config->readBoolEntry( "Enabled", true );  }  if (reset || config->hasGroup("Filter Settings"))  {      config->setGroup( "Filter Settings" );      d->m_adFilterEnabled = config->readBoolEntry("Enabled", false);      d->m_hideAdsEnabled = config->readBoolEntry("Shrink", false);      d->adFilters.clear();      QMap<QString,QString> entryMap = config->entryMap("Filter Settings");      QMap<QString,QString>::ConstIterator it;      d->adFilters.reserve(entryMap.count());      for( it = entryMap.constBegin(); it != entryMap.constEnd(); ++it )      {          QString name = it.key();          QString url = it.data();          if (url.startsWith("!"))              continue;          if (name.startsWith("Filter"))          {              if (url.length()>2 && url[0]=='/' && url[url.length()-1] == '/')              {                  QString inside = url.mid(1, url.length()-2);                  QRegExp rx(inside);                  d->adFilters.append(rx);              }              else              {                  QRegExp rx;                  int left,right;                  for (right=url.length(); right>0 && url[right-1]=='*' ; --right);                  for (left=0; left<right && url[left]=='*' ; ++left);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -